My Notepad

时间:2022-04-07 17:14:02

I have spent near more two weeks to write this Notepad application. At this moment, I want to share with you.

I wonder that do you know the Notepad in Windows XP/7. If you have no idea, I am pleasure to display the Notepad

in Windows 7 with you, and it displays as below:

My Notepad

It has large future and simple interface, so does my Notepad!

Well, I will introduce my Notepad.

First, Let's look at the structure of the my Notepad application:

My Notepad

My Notepad

=================================================
The structure of the project:
=================================================
  -src/main/java
       -com.b510.notepad
              -client
                   -Client.java
              -common
                   -Common.java
              -ui
                   -AboutUI.java
                   -FindManagerUI.java
                   -FontManagerUI.java
                   -FontSizeManagerUI.java
                   -JUI.java
                   -MainUI.java
                   -NotepadUI.java
                   -ReplaceManagerUI.java
                   -SkinManagerUI.java
             -util
                   -EditMenuUtil.java
                   -FileMenuUtil.java
                   -FormatMenuUtil.java
                   -HelpMenuUtil.java
                   -NotepadUtil.java
                   -ViewMenuUtil.java
            -log4j.properties
            -lib
                  -skin
                       -substance-1.0.jar
            -pom.xml

=================================================
Describe for all files:
=================================================

-Client.java --> The entry of the notepad application. It contains the main method.
-Common.java --> All constants in here.
-AboutUI.java --> About notepad page.
-FindManagerUI.java --> Find page.
-FontManagerUI.java --> Font setting page.
-FontSizeManagerUI.java --> Font sizt setting page.
-JUI.java --> The parent class for the NotepadUI, It extends JFrame.
-MainUI.java --> The main page of the notepad.
-NotepadUI.java --> The parent class for the MainUI, It extends JUI and implements ActionListener.
-ReplaceManagerUI.java --> Replace page.
-SkinManagerUI.java --> Skin setting page.
-EditMenuUtil.java --> Edit menu functions provider.
-FileMenuUtil.java --> File menu functions provider.
-FormatMenuUtil.java --> Format menu functions provider.
-HelpMenuUtil.java --> Help menu functions provider.
-NotepadUtil.java --> Common functions provider.
-ViewMenuUtil.java --> View menu functions provider.
-log4j.properties --> A properties for the log4j.
-substance-1.0.jar --> substance dependency.
-pom.xml --> pom.xml

=================================================
How to add substance to your project build path?
=================================================

NOTE:
Your computer should install the Maven(apache-maven-3.2.2 is good choice) before running this project!

There are TWO ways to provided.

1. Using eclipse tool to add the substance-1.0.jar to project build path.
  1.1.Finding the substance-1.0.jar with the path "notepad/lib/skin/substance-1.0.jar".
     Right Click --> Build Path --> Add to Build Path.

1.2.Then open the opm.xml(with the path "notepad/pom.xml")
      Deleting the substance dependency:
      <dependency>
      <groupId>org.jvnet.substance</groupId>
  <artifactId>substance</artifactId>
  <version>1.0</version>
  </dependency>

2. Copy the substance-1.0.jar to your repository.
  2.1.Finding the substance-1.0.jar with the path "notepad/lib/skin/substance-1.0.jar".
  Copying the substance-1.0.jar file to your repository.
  The default path of the repository is "${user.home}/.m2/repository/org/jvnet/substance/substance/1.0/substance-1.0.jar"

=================================================
How to run notepad project?
=================================================
Using the eclipse tool and finding the Client.java file with the path "notepad/src/main/java/com/b510/notepad/client/Client.java".
Right Click --> Run As --> Java Application

==================

Some UIs Show

==================

1. The Notepad Main UI

My Notepad

2. File Menu

My Notepad

3. Edit Menu

My Notepad

4. Format Menu

My Notepad

5. View Menu

My Notepad

6.Help Menu

My Notepad

7.Untitle Notepad

My Notepad

8. Open a File

My Notepad

9. About Notepad

My Notepad

10. Change Skin

My Notepad

=================================================
Source Code:
=================================================

/notepad/src/main/java/com/b510/notepad/client/Client.java

 /**
*
*/
package com.b510.notepad.client; import com.b510.notepad.common.Common;
import com.b510.notepad.ui.MainUI; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class Client { public static void main(String[] args) {
start();
} public static MainUI start() {
MainUI ui = new MainUI(Common.TITLE);
ui.init();
return ui;
}
}

/notepad/src/main/java/com/b510/notepad/common/Common.java

 package com.b510.notepad.common;

 /**
* @author Hongten
* @created Nov 19, 2014
*/
public class Common { public static final String HYPHEN = "-";
public static final String EMPTY = "";
public static final String NEW_LINE = "\r\n";
public static final String BLANK = " ";
public static final String QUESTION_MARK = "?";
public static final String POINT = ".";
public static final String COLOR = ":";
public static final String START = "*";
public static final String TXT = "txt";
public static final String TXT_FILE = START + POINT + TXT; public static final String UNTITLE = "Untitled";
public static final String NOTEPAD = "Notepad";
public static final String NOTEPAD_NOTEPAD = BLANK + HYPHEN + BLANK + NOTEPAD;
public static final String TITLE = UNTITLE + NOTEPAD_NOTEPAD;
public static final String SYSTEM_EXIT = "System exit";
public static final String SYSTEM_OPEN = "System open"; public static final String FILE = "File";
public static final String EDIT = "Edit";
public static final String FORMAT = "Format";
public static final String VIEW = "View";
public static final String Help = "Help"; // File Items
public static final String NEW = "New";
public static final String OPEN = "Open...";
public static final String SAVE = "Save";
public static final String SAVE_AS = "Save as...";
public static final String PROPERTIES = "Properties";
public static final String EXIT = "Exit"; // Edit Items
public static final String UNDO = "Undo";
public static final String COPY = "Copy";
public static final String PASTE = "Paste";
public static final String CUT = "Cut";
public static final String DELETE = "Delete";
public static final String FIND = "Find...";
public static final String FIND_NEXT = "Find Next";
public static final String REPLACE = "Replace";
public static final String GO_TO = "Go To...";
public static final String SELECT_ALL = "Select All";
public static final String TIME_DATE = "Time/Date"; // Format Items
public static final String WORD_WRAP = "Word Wrap";
public static final String RESET_FONT = "Reset Font";
public static final String FONT = "Font";
public static final String FONT_STYLE = "Font Style";
public static final String FONT_SIZE_TITLE = "Font Size"; // View
public static final String STATUS_BAR = "Status Bar";
public static final String SKIN = "Change Skin"; // Help Items
public static final String VIEW_HELP = "View Help";
public static final String ABOUT_NOTEPAD = "About NotePad"; // KeyStroke
public static final char A = 'A';
public static final char N = 'N';
public static final char O = 'O';
public static final char L = 'L';
public static final char Z = 'Z';
public static final char C = 'C';
public static final char D = 'D';
public static final char W = 'W';
public static final char H = 'H';
public static final char F = 'F';
public static final char V = 'V';
public static final char X = 'X';
public static final char G = 'G';
public static final char S = 'S';
public static final char P = 'P';
public static final char T = 'T';
public static final char SPACE = ' '; // notepad\src\main\resources\images
public static final String IMAGE_PATH = "images/"; public static final String HONGTEN_PIC = IMAGE_PATH + "hongten.png"; // About UI
public static final String AUTHOR = "Author";
public static final String AUTHOR_NAME = "Hongten";
public static final String AUTHOR_DESC = "I'm " + AUTHOR_NAME;
public static final String ITEM = "Item";
public static final String DESCRIPTION = "Desctiption";
public static final String APPLICATION = "Application";
public static final String NAME = "Name";
public static final String APPLICATION_NAME = APPLICATION + BLANK + NAME;
public static final String NOTEPAD_APP = NOTEPAD;
public static final String APPLICATION_DESCRIPTION = APPLICATION + BLANK + DESCRIPTION;
public static final String APPLICATION_DESCRIPTION_DETAIL = "A " + NOTEPAD;
public static final String VERSION = "Version";
public static final String VERSION_VALUE = "1.0";
public static final String BLOG = "Blog";
public static final String HOME_PAGE = "http://www.cnblogs.com/hongten";
public static final String NOTEPAD_PUBLISHED_PAGE = HOME_PAGE + "/p/hongten_notepad_index.html";
public static final String NOTEPAD_SUBSTANCE_SKINS_PAGE = HOME_PAGE + "/p/hongten_notepad_substance_skins.html";
public static final String SUBSTANCE_SKINS_PAGE = NOTEPAD_SUBSTANCE_SKINS_PAGE + "#";
public static final String NOTEPAD_PUBLISHED_BOOKMARK_PAGE = NOTEPAD_PUBLISHED_PAGE + "#"; public static final int TABLE_ROW_HEIGHT = 20; // Dialog messages and titles
public static final String CONFIM_EXIT = "Confim Exit";
public static final String ACCESS_URL_REQUEST = "Access URL Request";
public static final String ACCESS_URL = "Access URL : "; public static final String FONT_LUCIDA_CONSOLE = "Lucida Console";
public static final String FONT_TYPE = "宋体";
public static final int FONT_SIZE = 12;
public static final int FONT_NUM = 148;
public static final int FONT_SIZE_NUM = 4;
public static final int FONT_STYLE_NUM = 0;
public static final String FONT_STYLE_DEFAULT = "Regular";
public static final String DATE_FORMAT = "HH:mm MM/dd/yyyy";
public static final String THIS_IS_A_SIMPLE = "This is a Simple";
public static final String SIMPLE = "Simple"; public static final String CURRENT_SINK = "Current Skin" + BLANK + COLOR + BLANK;
public static final String DESCRIPTION_WITH_COLOR = DESCRIPTION + BLANK + COLOR + BLANK;
public static final String CURRENT_FONT = "Current Font" + BLANK + COLOR + BLANK;
public static final String CURRENT_FONT_SIZE = "Current Font Size" + BLANK + COLOR + BLANK;
public static final String CURRENT_FONT_STYLE = "Current Font Style" + BLANK + COLOR + BLANK; public static final String DO_YOU_WANT_TO_SAVE_CHANGES = "Do you want to save changes?";
public static final String WHAT_DO_YOU_WANT_TO_FIND = "Please type what do you want to find.";
public static final String CAN_NOT_FIND = "Cannot find ";
public static final String MATCHES_REPLACED = " matches replaced!"; public static final String FIND_WHAT = "Find What :";
public static final String REPLACE_TO = "Replace To :";
public static final String REPLACE_ALL = "Replace All";
public static final String CASE_SENSITIVE = "Case Sensitive";
public static final String FORWARD = "Forward";
public static final String BACKWARD = "Backward";
public static final String CANCEL = "Cancel";
public static final String GB2312 = "GB2312"; public static final String NOTEPAD_HOME_PAGE = "Home Page";
public static final String NOTEPAD_SKINS = "Notepad Skins";
public static final String SOURCE = "Source";
public static final String SOURCE_CODE = SOURCE + " Code";
public static final String SOURCE_CODE_DOWNLOAD = SOURCE_CODE + " Download";
public static final String NOTEPAD_API = "Notepad API"; public static final String SOURCE_CODE_BOOKMARK = "Source.Code";
public static final String SOURCE_CODE_DOWNLOAD_BOOKMARK = SOURCE_CODE_BOOKMARK + ".Download";
public static final String NOTEPAD_API_BOOKMARK = "Notepad.API";
}

/notepad/src/main/java/com/b510/notepad/ui/AboutUI.java

 package com.b510.notepad.ui;

 import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.util.HelpMenuUtil;
import com.b510.notepad.util.NotepadUtil; /**
* Location : MainUI --> Help --> About Notepad<br>
* <p>
* The <code>AboutUI</code> display the information about this application.<br>
* <p>
* i.e., Author, Application Name, Application description, Version, Blog.etc.<br>
* <p>
* If you have a try to double-click the row which name is 'Blog', then the dialog will be displaying in front of this page.<br>
* The dialog is a access URL request dialog, and you will access the URL(<a href='http://www.cnblogs.com/hongten'>http://www.cnblogs.com/hongten</a>) if you click 'Yes'.<br>
* <p>
* If you want to use this class, you should do as below:<br>
* <p><blockquote><pre>
* <code>AboutUI aboutUI = new AboutUI("About Notepad");</code>
* </pre></blockquote><p>
*
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 20, 2014
*/
public class AboutUI extends MainUI { private static final long serialVersionUID = 1L; static Logger log = Logger.getLogger(AboutUI.class); private JLabel descriptionLabel;
private JButton hongtenButton;
private JTable aboutUITable;
private JPanel mainPanel;
private JScrollPane rightScrollPane; private HelpMenuUtil help; public AboutUI(String title) {
super(title);
initComponents();
initSelf();
setAlwaysOnTop(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
AboutUI.this.setVisible(false);
help.distoryAboutUI();
}
});
} public void initSelf() {
this.setVisible(true);
setResizable(false);
this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150);
} private void initComponents() {
initElement();
initHongtenButton();
initAboutUITable();
initDescriptionLabel();
mainPanelLayout();
} private void initHongtenButton() {
hongtenButton.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource(Common.HONGTEN_PIC)));
hongtenButton.setToolTipText(Common.ABOUT_NOTEPAD);
} private void initAboutUITable() {
Object[][] values = new Object[][] { { Common.AUTHOR, Common.AUTHOR_NAME }, { Common.APPLICATION_NAME, Common.NOTEPAD_APP }, { Common.APPLICATION_DESCRIPTION, Common.APPLICATION_DESCRIPTION_DETAIL }, { Common.VERSION, Common.VERSION_VALUE }, { Common.BLOG, Common.HOME_PAGE } }; String[] titles = new String[] { Common.ITEM, Common.DESCRIPTION }; aboutUITable.setModel(new DefaultTableModel(values, titles) {
private static final long serialVersionUID = 1L;
boolean[] canEdit = new boolean[] { false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
}); aboutUITable.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
aboutUITable.setOpaque(false);
aboutUITable.setRowHeight(Common.TABLE_ROW_HEIGHT);
aboutUITable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
aboutUITable.setSurrendersFocusOnKeystroke(true);
aboutUITable.getTableHeader().setReorderingAllowed(false);
aboutUITable.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
matchUrlOperation();
}
} public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseClicked(MouseEvent e) { }
});
rightScrollPane.setViewportView(aboutUITable);
} private void matchUrlOperation() {
int id = aboutUITable.getSelectedRow();
String url = (String) aboutUITable.getValueAt(id, 1);
if (url.equals(Common.HOME_PAGE)) {
askAccessBlogOperation();
}
} // Show a dialog to access URL request.
// You will access the URL if you click 'Yes'.
protected void askAccessBlogOperation() {
int option = JOptionPane.showConfirmDialog(AboutUI.this, Common.ACCESS_URL + Common.HOME_PAGE + Common.BLANK + Common.QUESTION_MARK, Common.ACCESS_URL_REQUEST, JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
NotepadUtil.accessURL(Common.HOME_PAGE);
}
} private void initDescriptionLabel() {
descriptionLabel.setFont(new java.awt.Font(Common.FONT_LUCIDA_CONSOLE, 1, 18));
descriptionLabel.setHorizontalAlignment(SwingConstants.CENTER);
descriptionLabel.setText(Common.AUTHOR_DESC);
} private void initElement() {
mainPanel = new JPanel();
hongtenButton = new JButton();
rightScrollPane = new JScrollPane();
aboutUITable = new JTable();
descriptionLabel = new JLabel();
} public void setHelpMenuUtil(HelpMenuUtil helpMenuUtil){
this.help = helpMenuUtil;
} /**
* If not necessary, please do not change
*/
private void mainPanelLayout() {
GroupLayout mainPanelLayout = new GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING).addComponent(hongtenButton).addComponent(descriptionLabel, GroupLayout.PREFERRED_SIZE, 265, GroupLayout.PREFERRED_SIZE)).addGap(18, 18, 18).addComponent(rightScrollPane, GroupLayout.PREFERRED_SIZE, 243, GroupLayout.PREFERRED_SIZE).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
mainPanelLayout.setVerticalGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false).addComponent(rightScrollPane, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE).addGroup(mainPanelLayout.createSequentialGroup().addComponent(hongtenButton, GroupLayout.PREFERRED_SIZE, 256, GroupLayout.PREFERRED_SIZE).addGap(18, 18, 18).addComponent(descriptionLabel, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE))).addGap(0, 0, Short.MAX_VALUE))); GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap())); pack();
}
}

/notepad/src/main/java/com/b510/notepad/ui/FindManagerUI.java

 package com.b510.notepad.ui;

 import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.util.EditMenuUtil; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 20, 2014
*/
public class FindManagerUI extends MainUI {
private static final long serialVersionUID = 1L;
static Logger log = Logger.getLogger(FindManagerUI.class); private JPanel bGJPanel;
private JRadioButton backwardJRadioButton;
private JButton cancelJButton;
private JCheckBox caseSensitiveJCheckBox;
private JButton findNextJButton;
private JLabel findWhatJLabel;
private JRadioButton forwardJRadioButton;
private JTextField keyWordJTextField; public static boolean isForward = true;
public static boolean isCaseSensitive = false; private EditMenuUtil edit; public FindManagerUI(String title) {
super(title);
initComponents(); initSelf();
setAlwaysOnTop(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
distoryFindManagerUI();
}
});
} public void initSelf() {
this.setVisible(true);
setResizable(false);
this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150);
} /**
* If not necessary, do not change the order.
*/
private void initComponents() {
initElements();
initFindWhat();
initCaseSensitive();
initFindNext();
initCancle();
initDirection();
initLayout();
} private void initElements() {
bGJPanel = new JPanel();
findWhatJLabel = new JLabel();
keyWordJTextField = new JTextField();
caseSensitiveJCheckBox = new JCheckBox();
findNextJButton = new JButton();
cancelJButton = new JButton();
forwardJRadioButton = new JRadioButton();
backwardJRadioButton = new JRadioButton();
} private void initDirection() {
forwardJRadioButton.setSelected(true);
forwardJRadioButton.setText(Common.FORWARD);
forwardJRadioButton.addActionListener(this); backwardJRadioButton.setText(Common.BACKWARD);
backwardJRadioButton.addActionListener(this);
} private void initCancle() {
cancelJButton.setText(Common.CANCEL);
cancelJButton.setMaximumSize(new Dimension(87, 23));
cancelJButton.setMinimumSize(new Dimension(87, 23));
cancelJButton.setPreferredSize(new Dimension(87, 23));
cancelJButton.addActionListener(this);
} private void initFindNext() {
findNextJButton.setText(Common.FIND_NEXT);
findNextJButton.addActionListener(this);
} private void initCaseSensitive() {
caseSensitiveJCheckBox.setText(Common.CASE_SENSITIVE);
caseSensitiveJCheckBox.addActionListener(this);
} private void initFindWhat() {
findWhatJLabel.setText(Common.FIND_WHAT); if (null == textArea.getSelectedText() || Common.EMPTY.equals(textArea.getSelectedText().trim())) {
keyWordJTextField.setText(findWhat);
} else if(null != textArea.getSelectedText() && !Common.EMPTY.equals(textArea.getSelectedText().trim())){
keyWordJTextField.setText(textArea.getSelectedText());
}else{
keyWordJTextField.setText(findWhat);
}
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == backwardJRadioButton) {
directionOfOperation(false);
} else if (e.getSource() == forwardJRadioButton) {
directionOfOperation(true);
} else if (e.getSource() == findNextJButton) {
findNextOperation();
} else if (e.getSource() == cancelJButton) {
distoryFindManagerUI();
} else if (e.getSource() == caseSensitiveJCheckBox) {
caseSensitiveSwitch();
}
} private void findNextOperation() {
findWhat = keyWordJTextField.getText();
if (Common.EMPTY.equals(findWhat)) {
JOptionPane.showMessageDialog(FindManagerUI.this, Common.WHAT_DO_YOU_WANT_TO_FIND, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE);
keyWordJTextField.setFocusable(true);
}
edit.findNext();
} /**
* Operation for Cancel button
*/
private void distoryFindManagerUI() {
FindManagerUI.this.setVisible(false);
edit.distoryFindManagerUI();
} /**
* Case Sensitive Switch
*/
private void caseSensitiveSwitch() {
if (null == caseSensitiveJCheckBox.getSelectedObjects()) {
isCaseSensitive = false;
} else {
isCaseSensitive = true;
}
log.debug(isCaseSensitive);
} /**
* Direction of Operation<br>
* <li>Forward : <code>directionOfOperation(true);</code></li>
* <li>Backward : <code>directionOfOperation(false);</code></li>
* @param b <code>b = true;</code> Forward is selected; <code>b = false;</code> Backward is selected.<br>
*/
private void directionOfOperation(boolean b) {
isForward = b;
forwardJRadioButton.setSelected(b);
backwardJRadioButton.setSelected(!b);
log.debug(isForward);
} public void setEditMenuUtil(EditMenuUtil editMenuUtil) {
this.edit = editMenuUtil;
} /**
* If not necessary, do not change.
*/
private void initLayout() {
GroupLayout bGJPanelLayout = new GroupLayout(bGJPanel);
bGJPanel.setLayout(bGJPanelLayout);
bGJPanelLayout.setHorizontalGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(bGJPanelLayout.createSequentialGroup().addContainerGap().addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(bGJPanelLayout.createSequentialGroup().addComponent(findWhatJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(keyWordJTextField, GroupLayout.PREFERRED_SIZE, 221, GroupLayout.PREFERRED_SIZE)).addGroup(bGJPanelLayout.createSequentialGroup().addComponent(caseSensitiveJCheckBox).addGap(18, 18, 18).addComponent(forwardJRadioButton).addGap(18, 18, 18).addComponent(backwardJRadioButton))).addGap(18, 18, 18).addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(findNextJButton, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelJButton, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
bGJPanelLayout.setVerticalGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(bGJPanelLayout.createSequentialGroup().addGap(14, 14, 14).addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(findWhatJLabel).addComponent(keyWordJTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(findNextJButton)).addGap(18, 18, 18).addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(cancelJButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(caseSensitiveJCheckBox).addComponent(forwardJRadioButton).addComponent(backwardJRadioButton)).addContainerGap())); GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(bGJPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(bGJPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap()));
pack();
}
}

/notepad/src/main/java/com/b510/notepad/ui/FontManagerUI.java

 package com.b510.notepad.ui;

 import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.LayoutStyle; import com.b510.notepad.common.Common;
import com.b510.notepad.util.FormatMenuUtil; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 20, 2014
*/
public class FontManagerUI extends MainUI {
private static final long serialVersionUID = -37011351219515242L; private JLabel currentFontDescJLabel;
private JLabel currentFontJLabel;
private JLabel descJlabel;
private JSeparator line;
private JComboBox<String> fontJComboBox; private FormatMenuUtil format; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String fontNames[] = ge.getAvailableFontFamilyNames(); public static String FONT_TYPE = Common.FONT_TYPE;
public static int FONT_SIZE = Common.FONT_SIZE;
public static String FONT_STYPLE = Common.FONT_STYLE_DEFAULT; public FontManagerUI(String title) {
super(title);
initComponents(); initSelf();
setAlwaysOnTop(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
FontManagerUI.this.setVisible(false);
format.distoryFontManagerUI();
}
});
} public void initSelf() {
this.setVisible(true);
setResizable(false);
this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150);
} private void initComponents() {
initElement();
currentFontJLabel.setText(Common.CURRENT_FONT); fontJComboBox.setModel(new DefaultComboBoxModel<String>(fontNames));
int i = 0;
for(String name : fontNames){
if(FontManagerUI.FONT_TYPE.equals(name)){
fontNum = i;
}
i++;
}
fontJComboBox.setSelectedIndex(fontNum);
fontJComboBox.addActionListener(this); descJlabel.setText(Common.DESCRIPTION_WITH_COLOR); currentFontDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE));
currentFontDescJLabel.setText(Common.THIS_IS_A_SIMPLE);
pageGourpLayout();
} private void initElement() {
currentFontJLabel = new JLabel();
fontJComboBox = new JComboBox<String>();
descJlabel = new JLabel();
currentFontDescJLabel = new JLabel();
line = new JSeparator();
} @Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == fontJComboBox) {
updateSkin();
}
} public synchronized void updateSkin() {
fontNum = fontJComboBox.getSelectedIndex();
log.debug(fontJComboBox.getSelectedItem().toString());
FontManagerUI.FONT_TYPE = fontJComboBox.getSelectedItem().toString();
currentFontDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE));
currentFontDescJLabel.setText(Common.THIS_IS_A_SIMPLE);
textArea.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE));
setJUI();
} public void setFormatMenuUtil(FormatMenuUtil formatMenuUtil){
this.format = formatMenuUtil;
} /**
* If not necessary, please do not change
*/
private void pageGourpLayout() {
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
horizontalGroupLayout(layout);
verticalGroupLayout(layout);
pack();
} private void verticalGroupLayout(GroupLayout layout) {
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(currentFontJLabel)
.addComponent(fontJComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(26, 26, 26)
.addComponent(line, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(descJlabel).addGap(18, 18, 18).addComponent(currentFontDescJLabel).addContainerGap(47, Short.MAX_VALUE)));
} private void horizontalGroupLayout(GroupLayout layout) {
layout.setHorizontalGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(currentFontDescJLabel)
.addComponent(descJlabel)
.addGroup(
layout.createSequentialGroup().addComponent(currentFontJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(fontJComboBox, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup().addComponent(line, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE)));
}
}

/notepad/src/main/java/com/b510/notepad/ui/FontSizeManagerUI.java

 package com.b510.notepad.ui;

 import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.LayoutStyle; import com.b510.notepad.common.Common;
import com.b510.notepad.util.FormatMenuUtil; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 20, 2014
*/
public class FontSizeManagerUI extends MainUI {
private static final long serialVersionUID = -37011351219515242L; private JLabel currentFontSizeDescJLabel;
private JLabel currentFontSizeJLabel;
private JLabel descJlabel;
private JSeparator line;
private JComboBox<String> fontSizeJComboBox; private FormatMenuUtil format; String fontSizes[] = {"8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"}; public FontSizeManagerUI(String title) {
super(title);
initComponents(); initSelf();
setAlwaysOnTop(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
FontSizeManagerUI.this.setVisible(false);
format.distoryFontSizeManagerUI();
}
});
} public void initSelf() {
this.setVisible(true);
setResizable(false);
this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150);
} private void initComponents() {
initElement();
currentFontSizeJLabel.setText(Common.CURRENT_FONT_SIZE); fontSizeJComboBox.setModel(new DefaultComboBoxModel<String>(fontSizes));
int i = 0;
for(String size : fontSizes){
if(Integer.valueOf(size) == FontManagerUI.FONT_SIZE){
fontSizeNum = i;
}
i++;
}
fontSizeJComboBox.setSelectedIndex(fontSizeNum);
fontSizeJComboBox.addActionListener(this); descJlabel.setText(Common.DESCRIPTION_WITH_COLOR); currentFontSizeDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE));
currentFontSizeDescJLabel.setText(Common.SIMPLE);
pageGourpLayout();
} private void initElement() {
currentFontSizeJLabel = new JLabel();
fontSizeJComboBox = new JComboBox<String>();
descJlabel = new JLabel();
currentFontSizeDescJLabel = new JLabel();
line = new JSeparator();
} @Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == fontSizeJComboBox) {
updateSkin();
}
} public synchronized void updateSkin() {
fontNum = fontSizeJComboBox.getSelectedIndex();
log.debug(fontSizeJComboBox.getSelectedItem().toString());
FontManagerUI.FONT_SIZE = Integer.valueOf((String) fontSizeJComboBox.getSelectedItem());
currentFontSizeDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, Font.PLAIN, FontManagerUI.FONT_SIZE));
currentFontSizeDescJLabel.setText(Common.SIMPLE);
textArea.setFont(new Font(FontManagerUI.FONT_TYPE, Font.PLAIN, FontManagerUI.FONT_SIZE));
setJUI();
} public void setFormatMenuUtil(FormatMenuUtil formatMenuUtil){
this.format = formatMenuUtil;
} /**
* If not necessary, please do not change
*/
private void pageGourpLayout() {
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
horizontalGroupLayout(layout);
verticalGroupLayout(layout);
pack();
} private void verticalGroupLayout(GroupLayout layout) {
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(currentFontSizeJLabel)
.addComponent(fontSizeJComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(26, 26, 26)
.addComponent(line, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(descJlabel).addGap(18, 18, 18).addComponent(currentFontSizeDescJLabel).addContainerGap(47, Short.MAX_VALUE)));
} private void horizontalGroupLayout(GroupLayout layout) {
layout.setHorizontalGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(currentFontSizeDescJLabel)
.addComponent(descJlabel)
.addGroup(
layout.createSequentialGroup().addComponent(currentFontSizeJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(fontSizeJComboBox, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup().addComponent(line, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE)));
}
}

/notepad/src/main/java/com/b510/notepad/ui/FontStyleManagerUI.java

 package com.b510.notepad.ui;

 import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.LayoutStyle; import com.b510.notepad.common.Common;
import com.b510.notepad.util.FormatMenuUtil; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 20, 2014
*/
public class FontStyleManagerUI extends MainUI {
private static final long serialVersionUID = -37011351219515242L; private JLabel currentFontStyleDescJLabel;
private JLabel currentFontStyleJLabel;
private JLabel descJlabel;
private JSeparator line;
private JComboBox<String> fontStyleJComboBox; private FormatMenuUtil format; String fontStyles[] = {"Regular", "Italic", "Bold", "Bold Italic"}; public FontStyleManagerUI(String title) {
super(title);
initComponents(); initSelf();
setAlwaysOnTop(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
FontStyleManagerUI.this.setVisible(false);
format.distoryFontSizeManagerUI();
}
});
} public void initSelf() {
this.setVisible(true);
setResizable(false);
this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150);
} private void initComponents() {
initElement();
currentFontStyleJLabel.setText(Common.CURRENT_FONT_STYLE); fontStyleJComboBox.setModel(new DefaultComboBoxModel<String>(fontStyles));
int i = 0;
for(String style : fontStyles){
if(style.equals(FontManagerUI.FONT_STYPLE)){
fontStyleNum = i;
}
i++;
}
fontStyleJComboBox.setSelectedIndex(fontStyleNum);
fontStyleJComboBox.addActionListener(this); descJlabel.setText(Common.DESCRIPTION_WITH_COLOR);
// do here...
currentFontStyleDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE));
currentFontStyleDescJLabel.setText(Common.SIMPLE);
pageGourpLayout();
} private void initElement() {
currentFontStyleJLabel = new JLabel();
fontStyleJComboBox = new JComboBox<String>();
descJlabel = new JLabel();
currentFontStyleDescJLabel = new JLabel();
line = new JSeparator();
} @Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == fontStyleJComboBox) {
updateSkin();
}
} public synchronized void updateSkin() {
fontStyleNum = fontStyleJComboBox.getSelectedIndex();
FontManagerUI.FONT_STYPLE = (String) fontStyleJComboBox.getSelectedItem();
currentFontStyleDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE));
currentFontStyleDescJLabel.setText(Common.SIMPLE);
textArea.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE));
setJUI();
} public void setFormatMenuUtil(FormatMenuUtil formatMenuUtil){
this.format = formatMenuUtil;
} /**
* If not necessary, please do not change
*/
private void pageGourpLayout() {
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
horizontalGroupLayout(layout);
verticalGroupLayout(layout);
pack();
} private void verticalGroupLayout(GroupLayout layout) {
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(currentFontStyleJLabel)
.addComponent(fontStyleJComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(26, 26, 26)
.addComponent(line, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(descJlabel).addGap(18, 18, 18).addComponent(currentFontStyleDescJLabel).addContainerGap(47, Short.MAX_VALUE)));
} private void horizontalGroupLayout(GroupLayout layout) {
layout.setHorizontalGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(currentFontStyleDescJLabel)
.addComponent(descJlabel)
.addGroup(
layout.createSequentialGroup().addComponent(currentFontStyleJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(fontStyleJComboBox, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup().addComponent(line, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE)));
}
}

/notepad/src/main/java/com/b510/notepad/ui/JUI.java

 /**
*
*/
package com.b510.notepad.ui; import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException; import org.apache.log4j.Logger;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.border.StandardBorderPainter;
import org.jvnet.substance.button.ClassicButtonShaper;
import org.jvnet.substance.painter.StandardGradientPainter;
import org.jvnet.substance.skin.AutumnSkin;
import org.jvnet.substance.skin.BusinessBlackSteelSkin;
import org.jvnet.substance.skin.ChallengerDeepSkin;
import org.jvnet.substance.skin.CremeCoffeeSkin;
import org.jvnet.substance.skin.CremeSkin;
import org.jvnet.substance.skin.EbonyHighContrastSkin;
import org.jvnet.substance.skin.EmeraldDuskSkin;
import org.jvnet.substance.skin.FieldOfWheatSkin;
import org.jvnet.substance.skin.FindingNemoSkin;
import org.jvnet.substance.skin.GreenMagicSkin;
import org.jvnet.substance.skin.MagmaSkin;
import org.jvnet.substance.skin.MangoSkin;
import org.jvnet.substance.skin.MistSilverSkin;
import org.jvnet.substance.skin.ModerateSkin;
import org.jvnet.substance.skin.NebulaBrickWallSkin;
import org.jvnet.substance.skin.NebulaSkin;
import org.jvnet.substance.skin.OfficeBlue2007Skin;
import org.jvnet.substance.skin.RavenGraphiteGlassSkin;
import org.jvnet.substance.skin.RavenGraphiteSkin;
import org.jvnet.substance.skin.RavenSkin;
import org.jvnet.substance.skin.SaharaSkin;
import org.jvnet.substance.skin.SubstanceAbstractSkin;
import org.jvnet.substance.theme.SubstanceAquaTheme;
import org.jvnet.substance.watermark.SubstanceBubblesWatermark; /**
* The basic class extends <code>java.awt.JFrame</code>, there are three methods provided:<br>
* <code>getSkin()</code> to change the frame skin.<br>
* and there are 21 skins to provided. And the<br>
* default skin is <code>MagmaSkin</code> .You can change value to change <br>
* skin if possible. and you should call the method <code>setJUI()</code> to refresh the page when you change the value.
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class JUI extends JFrame { private static final long serialVersionUID = 1L; Logger log = Logger.getLogger(JUI.class); static SubstanceAbstractSkin skin;
static int skinNum = 11;
String title; /**
* Total skins : 21. Get the skin according to the <code>skinNums</code> value, and the default skin is <code>MagmaSkin</code>
* @param num <code>skinNum</code> value
* @return
*/
public SubstanceAbstractSkin getSkin(int num) {
switch (num) {
case 1:
skin = new AutumnSkin();
break;
case 2:
skin = new BusinessBlackSteelSkin();
break;
case 3:
skin = new ChallengerDeepSkin();
break;
case 4:
skin = new CremeCoffeeSkin();
break;
case 5:
skin = new CremeSkin();
break;
case 6:
skin = new EbonyHighContrastSkin();
break;
case 7:
skin = new EmeraldDuskSkin();
break;
case 8:
skin = new FieldOfWheatSkin();
break;
case 9:
skin = new FindingNemoSkin();
break;
case 10:
skin = new GreenMagicSkin();
break;
case 11:
skin = new MagmaSkin();
break;
case 12:
skin = new MangoSkin();
break;
case 13:
skin = new MistSilverSkin();
break;
case 14:
skin = new ModerateSkin();
break;
case 15:
skin = new NebulaBrickWallSkin();
break;
case 16:
skin = new NebulaSkin();
break;
case 17:
skin = new OfficeBlue2007Skin();
break;
case 18:
skin = new RavenGraphiteGlassSkin();
break;
case 19:
skin = new RavenGraphiteSkin();
break;
case 20:
skin = new RavenSkin();
break;
case 21:
skin = new SaharaSkin();
break;
default:
skin = new FieldOfWheatSkin();
break;
}
return skin;
} /**
* Set the page UI. including the theme, skin, watermark.etc.
*/
public void setJUI() {
try {
UIManager.setLookAndFeel(new SubstanceLookAndFeel());
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
SubstanceLookAndFeel.setCurrentTheme(new SubstanceAquaTheme());
SubstanceLookAndFeel.setSkin(getSkin(skinNum));
SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper());
SubstanceLookAndFeel.setCurrentWatermark(new SubstanceBubblesWatermark());
SubstanceLookAndFeel.setCurrentBorderPainter(new StandardBorderPainter());
SubstanceLookAndFeel.setCurrentGradientPainter(new StandardGradientPainter());
} catch (UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
} public JUI(String title) {
this.title = title;
setJUI();
} public void init() { }
}

/notepad/src/main/java/com/b510/notepad/ui/MainUI.java

 /**
*
*/
package com.b510.notepad.ui; import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.undo.UndoManager; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.util.EditMenuUtil;
import com.b510.notepad.util.FileMenuUtil;
import com.b510.notepad.util.FormatMenuUtil;
import com.b510.notepad.util.HelpMenuUtil;
import com.b510.notepad.util.NotepadUtil;
import com.b510.notepad.util.ViewMenuUtil; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class MainUI extends NotepadUI { private static final long serialVersionUID = 1L; static Logger log = Logger.getLogger(MainUI.class); JMenuBar menuBar;
JSeparator line;
// Menus
JMenu file, edit, format, view, help, viewHelp, source;
// File Items
JMenuItem news, open, save, saveAs, properties, exit;
// Edit Items
JMenuItem undo, copy, paste, cut, find, findNext, replace, selectAll, timeDate;
// Format Items
JMenuItem wordWrap, resetFont, font, fontSize, fontStyle;
// View Items
JMenuItem skin;
// Help Items
JMenuItem about, homePage, skinPage, sourceCode, sourceCodeDownload, api;
// textArea
public static JTextArea textArea;
// textArea font
Font textAreaFont;
// textArea scroll
JScrollPane textAreaScroll; public static UndoManager undoManager; public static String filePath = Common.EMPTY;
boolean saved = false;
public static boolean lineWrap = true;
// Default position is (0, 0)
public static int pointX = 0;
public static int pointY = 0;
public static String savedText = Common.EMPTY;
public static int fontNum = Common.FONT_NUM;
public static int fontSizeNum = Common.FONT_SIZE_NUM;
public static int fontStyleNum = Common.FONT_STYLE_NUM;
public static String findWhat = Common.EMPTY; private void setMainUIXY() {
pointX = getMainUIX();
pointY = getMainUIY();
} private int getMainUIY() {
return (int) getLocation().getY();
} private int getMainUIX() {
return (int) getLocation().getX();
} public MainUI(String title) {
super(title);
setTitle(title);
} public void init() {
initMenu();
initTextArea();
this.setResizable(true);
this.setBounds(new Rectangle(150, 100, 800, 550));
this.setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
FileMenuUtil file = new FileMenuUtil(Common.EMPTY);
file.exit(MainUI.this);
}
}); setMainUIXY();
} private void initMenu() {
menuBar();
menuFile();
menuEdit();
menuFormat();
menuView();
menuHelp();
setJMenuBar(menuBar);
setDisabledMenuAtCreating(false);
} private void menuBar() {
menuBar = new JMenuBar();
} private void menuFile() {
file = new JMenu(Common.FILE); news = new JMenuItem(Common.NEW);
news.addActionListener(this);
news.setAccelerator(KeyStroke.getKeyStroke(Common.N, InputEvent.CTRL_MASK));
file.add(news); open = new JMenuItem(Common.OPEN);
open.addActionListener(this);
open.setAccelerator(KeyStroke.getKeyStroke(Common.O, InputEvent.CTRL_MASK));
file.add(open); save = new JMenuItem(Common.SAVE);
save.addActionListener(this);
save.setAccelerator(KeyStroke.getKeyStroke(Common.S, InputEvent.CTRL_MASK));
file.add(save); saveAs = new JMenuItem(Common.SAVE_AS);
saveAs.addActionListener(this);
saveAs.setAccelerator(KeyStroke.getKeyStroke(Common.S, InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK));
file.add(saveAs); line = new JSeparator();
file.add(line); properties = new JMenuItem(Common.PROPERTIES);
properties.addActionListener(this);
file.add(properties); line = new JSeparator();
file.add(line); exit = new JMenuItem(Common.EXIT);
exit.addActionListener(this);
file.add(exit); menuBar.add(file);
} private void menuEdit() {
edit = new JMenu(Common.EDIT); undo = new JMenuItem(Common.UNDO);
undo.addActionListener(this);
undo.setAccelerator(KeyStroke.getKeyStroke(Common.Z, InputEvent.CTRL_MASK));
edit.add(undo); line = new JSeparator();
edit.add(line); cut = new JMenuItem(Common.CUT);
cut.addActionListener(this);
cut.setAccelerator(KeyStroke.getKeyStroke(Common.X, InputEvent.CTRL_MASK));
edit.add(cut); copy = new JMenuItem(Common.COPY);
copy.addActionListener(this);
copy.setAccelerator(KeyStroke.getKeyStroke(Common.C, InputEvent.CTRL_MASK));
edit.add(copy); paste = new JMenuItem(Common.PASTE);
paste.addActionListener(this);
paste.setAccelerator(KeyStroke.getKeyStroke(Common.V, InputEvent.CTRL_MASK));
edit.add(paste); line = new JSeparator();
edit.add(line); find = new JMenuItem(Common.FIND);
find.addActionListener(this);
find.setAccelerator(KeyStroke.getKeyStroke(Common.F, InputEvent.CTRL_MASK));
edit.add(find); findNext = new JMenuItem(Common.FIND_NEXT);
findNext.addActionListener(this);
findNext.setAccelerator(KeyStroke.getKeyStroke(Common.F, InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK));
edit.add(findNext); replace = new JMenuItem(Common.REPLACE);
replace.addActionListener(this);
replace.setAccelerator(KeyStroke.getKeyStroke(Common.H, InputEvent.CTRL_MASK));
edit.add(replace); line = new JSeparator();
edit.add(line); selectAll = new JMenuItem(Common.SELECT_ALL);
selectAll.addActionListener(this);
selectAll.setAccelerator(KeyStroke.getKeyStroke(Common.A, InputEvent.CTRL_MASK));
edit.add(selectAll); timeDate = new JMenuItem(Common.TIME_DATE);
timeDate.addActionListener(this);
timeDate.setAccelerator(KeyStroke.getKeyStroke(Common.T, InputEvent.CTRL_MASK));
edit.add(timeDate); menuBar.add(edit);
} private void menuFormat() {
format = new JMenu(Common.FORMAT); wordWrap = new JMenuItem(Common.WORD_WRAP);
wordWrap.addActionListener(this);
wordWrap.setAccelerator(KeyStroke.getKeyStroke(Common.W, InputEvent.CTRL_MASK));
format.add(wordWrap); resetFont = new JMenuItem(Common.RESET_FONT);
resetFont.addActionListener(this);
format.add(resetFont); line = new JSeparator();
format.add(line); font = new JMenuItem(Common.FONT);
font.addActionListener(this);
format.add(font); fontSize = new JMenuItem(Common.FONT_SIZE_TITLE);
fontSize.addActionListener(this);
format.add(fontSize); fontStyle = new JMenuItem(Common.FONT_STYLE);
fontStyle.addActionListener(this);
format.add(fontStyle); menuBar.add(format);
} private void menuView() {
view = new JMenu(Common.VIEW); skin = new JMenuItem(Common.SKIN);
skin.addActionListener(this);
view.add(skin); menuBar.add(view);
} private void menuHelp() {
help = new JMenu(Common.Help); viewHelp = new JMenu(Common.VIEW_HELP);
help.add(viewHelp); homePage = new JMenuItem(Common.NOTEPAD_HOME_PAGE);
homePage.addActionListener(this);
viewHelp.add(homePage); skinPage = new JMenuItem(Common.NOTEPAD_SKINS);
skinPage.addActionListener(this);
viewHelp.add(skinPage); source = new JMenu(Common.SOURCE);
viewHelp.add(source); sourceCode = new JMenuItem(Common.SOURCE_CODE);
sourceCode.addActionListener(this);
source.add(sourceCode); sourceCodeDownload = new JMenuItem(Common.SOURCE_CODE_DOWNLOAD);
sourceCodeDownload.addActionListener(this);
source.add(sourceCodeDownload); api = new JMenuItem(Common.NOTEPAD_API);
api.addActionListener(this);
viewHelp.add(api); line = new JSeparator();
help.add(line); about = new JMenuItem(Common.ABOUT_NOTEPAD);
about.addActionListener(this);
help.add(about); menuBar.add(help);
} private void initUndoManager(){
undoManager = new UndoManager();
} private void setDisabledMenuAtCreating(boolean b){
undo.setEnabled(b);
cut.setEnabled(b);
copy.setEnabled(b);
find.setEnabled(b);
findNext.setEnabled(b);
} private void setDisabledMenuAtSelecting(boolean b){
cut.setEnabled(b);
copy.setEnabled(b);
} private void initTextArea() {
textArea = new JTextArea(Common.EMPTY);
textArea.setLineWrap(true);
lineWrap = true;
textAreaFont = new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE);
textArea.setFont(textAreaFont);
initUndoManager();
// add Undoable edit listener
textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent e) {
undoManager.addEdit(e.getEdit());
}
});
// add caret listener
textArea.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
if (null != savedText && null != textArea.getText()) {
if (savedText.equals(textArea.getText())) {
setSaved(true);
} else {
setSaved(false);
}
}
textArea.setFocusable(true);
setDisabledMenuAtCreating(true);
}
});
// add mouse motion listener
textArea.addMouseMotionListener(new MouseMotionListener() {
public void mouseMoved(MouseEvent e) {
isSelectedText();
} public void mouseDragged(MouseEvent e) {
isSelectedText();
} });
textAreaScroll = new JScrollPane(textArea);
this.add(textAreaScroll);
} private void isSelectedText() {
textArea.setFocusable(true);
String selectText = textArea.getSelectedText();
if(null != selectText){
setDisabledMenuAtSelecting(true);
}else{
setDisabledMenuAtSelecting(false);
}
} public void actionPerformed(ActionEvent e) {
actionForFileItem(e);
actionForEditItem(e);
actionForFormatItem(e);
actionForViewItem(e);
actionForHelpItem(e);
} private void actionForFileItem(ActionEvent e) {
if (e.getSource() == news) {
FileMenuUtil.news(MainUI.this);
} else if (e.getSource() == open) {
FileMenuUtil file = new FileMenuUtil(Common.EMPTY);
file.open(MainUI.this);
} else if (e.getSource() == save) {
FileMenuUtil.save(MainUI.this);
} else if (e.getSource() == saveAs) {
FileMenuUtil.saveAs(MainUI.this);
} else if (e.getSource() == properties) {
FileMenuUtil file = new FileMenuUtil(Common.EMPTY);
file.readProperties(MainUI.this);
} else if (e.getSource() == exit) {
FileMenuUtil file = new FileMenuUtil(Common.EMPTY);
file.exit(MainUI.this);
}
} private void actionForEditItem(ActionEvent e) {
if (e.getSource() == undo) {
EditMenuUtil.undo();
} else if (e.getSource() == copy) {
EditMenuUtil.copy();
} else if (e.getSource() == paste) {
EditMenuUtil.paste();
} else if (e.getSource() == cut) {
EditMenuUtil.cut();
} else if (e.getSource() == find) {
setMainUIXY();
EditMenuUtil edit = new EditMenuUtil(Common.EMPTY);
edit.find();
} else if (e.getSource() == findNext) {
EditMenuUtil edit = new EditMenuUtil(Common.EMPTY);
edit.findNext();
} else if (e.getSource() == replace) {
setMainUIXY();
EditMenuUtil edit = new EditMenuUtil(Common.EMPTY);
edit.replace();
} else if (e.getSource() == selectAll) {
EditMenuUtil.selectAll();
} else if (e.getSource() == timeDate) {
EditMenuUtil.timeDate();
}
} private void actionForFormatItem(ActionEvent e) {
if (e.getSource() == wordWrap) {
FormatMenuUtil.wordWrap();
} else if(e.getSource() == resetFont){
FormatMenuUtil format = new FormatMenuUtil(Common.EMPTY);
format.resetFont(MainUI.this);
}else if (e.getSource() == font) {
setMainUIXY();
FormatMenuUtil format = new FormatMenuUtil(Common.EMPTY);
format.font(MainUI.this);
} else if (e.getSource() == fontSize) {
setMainUIXY();
FormatMenuUtil format = new FormatMenuUtil(Common.EMPTY);
format.fontSize(MainUI.this);
}else if(e.getSource() == fontStyle){
setMainUIXY();
FormatMenuUtil format = new FormatMenuUtil(Common.EMPTY);
format.fontStyle(MainUI.this);
}
} private void actionForViewItem(ActionEvent e) {
if (e.getSource() == skin) {
setMainUIXY();
ViewMenuUtil view = new ViewMenuUtil(Common.EMPTY);
view.skin(MainUI.this);
}
} private void actionForHelpItem(ActionEvent e) {
if (e.getSource() == homePage) {
log.debug(Common.NOTEPAD_HOME_PAGE);
NotepadUtil.accessURL(Common.NOTEPAD_PUBLISHED_PAGE);
} else if(e.getSource() == skinPage){
log.debug(Common.NOTEPAD_SKINS);
NotepadUtil.accessURL(Common.NOTEPAD_SUBSTANCE_SKINS_PAGE);
}else if(e.getSource() == sourceCode){
log.debug(Common.SOURCE_CODE);
NotepadUtil.accessURL(Common.NOTEPAD_PUBLISHED_BOOKMARK_PAGE + Common.SOURCE_CODE_BOOKMARK);
}else if(e.getSource() == sourceCodeDownload){
log.debug(Common.SOURCE_CODE_DOWNLOAD);
NotepadUtil.accessURL(Common.NOTEPAD_PUBLISHED_BOOKMARK_PAGE + Common.SOURCE_CODE_DOWNLOAD_BOOKMARK);
}else if(e.getSource() == api){
log.debug(Common.NOTEPAD_API);
NotepadUtil.accessURL(Common.NOTEPAD_PUBLISHED_BOOKMARK_PAGE + Common.NOTEPAD_API_BOOKMARK);
}else if (e.getSource() == about) {
setMainUIXY();
HelpMenuUtil help = new HelpMenuUtil(Common.EMPTY);
help.about(MainUI.this);
}
} public boolean isSaved() {
return saved;
} public void setSaved(boolean saved) {
this.saved = saved;
}
}

/notepad/src/main/java/com/b510/notepad/ui/NotepadUI.java

 /**
*
*/
package com.b510.notepad.ui; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; /**
* The <code>NotepadUI</code> class extends <code>JUI</code> and implements
* <code>ActionListener</code>.
*
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class NotepadUI extends JUI implements ActionListener { private static final long serialVersionUID = 1L; private MainUI mainUI; public NotepadUI(String title) {
super(title);
} public void init() {
if (null == mainUI) {
mainUI = new MainUI(title);
}
mainUI.init();
} public void actionPerformed(ActionEvent e) {
}
}

/notepad/src/main/java/com/b510/notepad/ui/ReplaceManagerUI.java

 package com.b510.notepad.ui;

 import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.util.EditMenuUtil; public class ReplaceManagerUI extends MainUI {
private static final long serialVersionUID = 1L; static Logger log = Logger.getLogger(ReplaceManagerUI.class); private JPanel bGJPanel;
private JButton cancelJButton;
private JCheckBox caseSensitiveJCheckBox;
private JButton findNextJButton;
private JLabel findWhatJLabel;
private JTextField findWordJTextField;
private JButton replaceAllJButton;
private JLabel replaceToJLabel;
private JTextField replaceToJTextField;
private JButton replaceJButton; public static boolean isCaseSensitive = false; private EditMenuUtil edit;
public static String replaceWord = Common.EMPTY;
public static int replaceCount = 0; public ReplaceManagerUI(String title) {
super(title);
initComponents(); initSelf();
setAlwaysOnTop(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
distoryReplaceManagerUI();
}
});
} public void initSelf() {
this.setVisible(true);
setResizable(false);
this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150);
} /**
* If not necessary, please do not change the order.
*/
private void initComponents() {
initElement();
initLabel();
initFindWordTextField();
initReplaceToTextField();
initCaseSensitiveCheckBox();
initFindNextButton();
initReplaceButton();
initReplaceAllButton();
initCancleButton();
initLayout();
} private void initElement() {
bGJPanel = new JPanel();
findWhatJLabel = new JLabel();
replaceToJLabel = new JLabel();
findWordJTextField = new JTextField();
replaceToJTextField = new JTextField();
caseSensitiveJCheckBox = new JCheckBox();
findNextJButton = new JButton();
replaceJButton = new JButton();
replaceAllJButton = new JButton();
cancelJButton = new JButton();
} private void initLabel() {
findWhatJLabel.setText(Common.FIND_WHAT);
replaceToJLabel.setText(Common.REPLACE_TO);
} private void initFindWordTextField() {
if (null == textArea.getSelectedText() || Common.EMPTY.equals(textArea.getSelectedText().trim())) {
findWordJTextField.setText(findWhat);
} else if(null != textArea.getSelectedText() && !Common.EMPTY.equals(textArea.getSelectedText().trim())){
findWordJTextField.setText(textArea.getSelectedText());
}else{
findWordJTextField.setText(findWhat);
}
} private void initReplaceToTextField() {
replaceToJTextField.setText(Common.EMPTY);
} private void initCaseSensitiveCheckBox() {
caseSensitiveJCheckBox.setText(Common.CASE_SENSITIVE);
caseSensitiveJCheckBox.addActionListener(this);
} private void initFindNextButton() {
findNextJButton.setText(Common.FIND_NEXT);
findNextJButton.setMaximumSize(new Dimension(99, 23));
findNextJButton.setMinimumSize(new Dimension(99, 23));
findNextJButton.setPreferredSize(new Dimension(99, 23));
findNextJButton.addActionListener(this);
} private void initReplaceButton() {
replaceJButton.setText(Common.REPLACE);
replaceJButton.setMaximumSize(new Dimension(99, 23));
replaceJButton.setMinimumSize(new Dimension(99, 23));
replaceJButton.setPreferredSize(new Dimension(99, 23));
replaceJButton.addActionListener(this);
} private void initReplaceAllButton() {
replaceAllJButton.setText(Common.REPLACE_ALL);
replaceAllJButton.addActionListener(this);
} private void initCancleButton() {
cancelJButton.setText(Common.CANCEL);
cancelJButton.setMaximumSize(new Dimension(99, 23));
cancelJButton.setMinimumSize(new Dimension(99, 23));
cancelJButton.setPreferredSize(new Dimension(99, 23));
cancelJButton.addActionListener(this);
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == findNextJButton) {
if(!isEmptyForFindWordJTextField()){
edit.findNext();
}else{
typingFindWhat();
}
} else if (e.getSource() == replaceAllJButton) {
if(!isEmptyForFindWordJTextField()){
edit.replaceAllOperation();
}else{
typingFindWhat();
}
} else if (e.getSource() == replaceJButton) {
if(!isEmptyForFindWordJTextField()){
edit.replaceOperation();
}else{
typingFindWhat();
}
} else if (e.getSource() == cancelJButton) {
distoryReplaceManagerUI();
} else if (e.getSource() == caseSensitiveJCheckBox) {
caseSensitiveSwitch();
}
} private void typingFindWhat() {
JOptionPane.showMessageDialog(ReplaceManagerUI.this, Common.WHAT_DO_YOU_WANT_TO_FIND, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE);
findWordJTextField.setFocusable(true);
} private boolean isEmptyForFindWordJTextField(){
findWhat = findWordJTextField.getText();
replaceWord = replaceToJTextField.getText();
if(!Common.EMPTY.equals(findWordJTextField.getText())){
return false;
}else{
return true;
}
} /**
* Operation for Cancel button
*/
private void distoryReplaceManagerUI() {
ReplaceManagerUI.this.setVisible(false);
edit.distoryReplaceeManagerUI();
} /**
* Case Sensitive Switch
*/
private void caseSensitiveSwitch() {
if (null == caseSensitiveJCheckBox.getSelectedObjects()) {
isCaseSensitive = false;
} else {
isCaseSensitive = true;
}
log.debug(isCaseSensitive);
} public void setEditMenuUtil(EditMenuUtil editMenuUtil) {
this.edit = editMenuUtil;
} /**
* If not necessary, please do not change.
*/
private void initLayout() {
GroupLayout bGJPanelLayout = new GroupLayout(bGJPanel);
bGJPanel.setLayout(bGJPanelLayout);
bGJPanelLayout.setHorizontalGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
bGJPanelLayout.createSequentialGroup().addContainerGap().addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false).addGroup(bGJPanelLayout.createSequentialGroup().addComponent(findWhatJLabel).addGap(18, 18, 18).addComponent(findWordJTextField, GroupLayout.PREFERRED_SIZE, 227, GroupLayout.PREFERRED_SIZE)).addGroup(bGJPanelLayout.createSequentialGroup().addComponent(replaceToJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(replaceToJTextField))).addComponent(caseSensitiveJCheckBox)).addGap(18, 18, 18).addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(findNextJButton, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(replaceJButton, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(replaceAllJButton, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelJButton, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
bGJPanelLayout.setVerticalGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
bGJPanelLayout.createSequentialGroup().addGap(17, 17, 17).addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(bGJPanelLayout.createSequentialGroup().addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(findWhatJLabel).addComponent(findWordJTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(12, 12, 12).addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(replaceToJLabel).addComponent(replaceToJTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(replaceJButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))).addComponent(findNextJButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(replaceAllJButton)
.addGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(bGJPanelLayout.createSequentialGroup().addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(cancelJButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGroup(bGJPanelLayout.createSequentialGroup().addGap(2, 2, 2).addComponent(caseSensitiveJCheckBox))).addContainerGap(8, Short.MAX_VALUE))); GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(bGJPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(bGJPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap())); pack();
}
}

/notepad/src/main/java/com/b510/notepad/ui/SkinManagerUI.java

 package com.b510.notepad.ui;

 import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException; import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.LayoutStyle; import com.b510.notepad.common.Common;
import com.b510.notepad.util.ViewMenuUtil; /**
* @author Hongten
* @created Nov 20, 2014
*/
public class SkinManagerUI extends MainUI {
private static final long serialVersionUID = 1L; private JLabel currentSkinDescJLabel;
private JLabel currentSkinJLabel;
private JLabel descJlabel;
private JSeparator line;
private JComboBox<String> sinkJComboBox; private ViewMenuUtil view; public String[][] skins = { { "AutumnSkin", "1", "<html><a href=''>What is the AutumnSkin skin?</a></html>" }, { "BusinessBlackSteelSkin", "2", "<html><a href=''>What is the BusinessBlackSteelSkin skin?</a></html>" }, { "ChallengerDeepSkin", "3", "<html><a href=''>What is the ChallengerDeepSkin skin?</a></html>" }, { "CremeCoffeeSkin", "4", "<html><a href=''>What is the CremeCoffeeSkin skin?</a></html>" }, { "CremeSkin", "5", "<html><a href=''>What is the CremeSkin skin?</a></html>" }, { "EbonyHighContrastSkin", "6", "<html><a href=''>What is the EbonyHighContrastSkin skin?</a></html>" }, { "EmeraldDuskSkin", "7", "<html><a href=''>What is the EmeraldDuskSkin skin?</a></html>" }, { "FieldOfWheatSkin", "8", "<html><a href=''>What is the FieldOfWheatSkin skin?</a></html>" }, { "FindingNemoSkin", "9", "<html><a href=''>What is the FindingNemoSkin skin?</a></html>" }, { "GreenMagicSkin", "10", "<html><a href=''>What is the GreenMagicSkin skin?</a></html>" }, { "MagmaSkin", "11", "<html><a href=''>What is the MagmaSkin skin?</a></html>" }, { "MangoSkin", "12", "<html><a href=''>What is the MangoSkin skin?</a></html>" }, { "MistSilverSkin", "13", "<html><a href=''>What is the MistSilverSkin skin?</a></html>" },
{ "ModerateSkin", "14", "<html><a href=''>What is the ModerateSkin skin?</a></html>" }, { "NebulaBrickWallSkin", "15", "<html><a href=''>What is the NebulaBrickWallSkin skin?</a></html>" }, { "NebulaSkin", "16", "<html><a href=''>What is the NebulaSkin skin?</a></html>" }, { "OfficeBlue2007Skin", "17", "<html><a href=''>What is the OfficeBlue2007Skin skin?</a></html>" }, { "RavenGraphiteGlassSkin", "18", "<html><a href=''>What is the RavenGraphiteGlassSkin skin?</a></html>" }, { "RavenGraphiteSkin", "19", "<html><a href=''>What is the RavenGraphiteSkin skin?</a></html>" }, { "RavenSkin", "20", "<html><a href=''>What is the RavenSkin skin?</a></html>" }, { "SaharaSkin", "21", "<html><a href=''>What is the SaharaSkin skin?</a></html>" } }; private String[] skinNames() {
String[] os = new String[skins.length];
for (int i = 0; i < skins.length; i++) {
os[i] = skins[i][0];
}
return os;
} private Object[] getSkinDetails(Object obj) {
for (int i = 0; i < skins.length; i++) {
if (skins[i][0].equals(obj)) {
Object[] os = new Object[skins[i].length - 1];
for (int j = 0; j < os.length; j++) {
os[j] = skins[i][j + 1];
}
return os;
}
}
return new Object[] {};
} public SkinManagerUI(String title) {
super(title);
initComponents(); initSelf();
setAlwaysOnTop(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
SkinManagerUI.this.setVisible(false);
view.distorySkinManagerUI();
}
});
} public void initSelf() {
this.setVisible(true);
setResizable(false);
this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150);
} private void initComponents() {
initElement();
currentSkinJLabel.setText(Common.CURRENT_SINK); String[] skinNames = skinNames();
sinkJComboBox.setModel(new DefaultComboBoxModel<String>(skinNames));
sinkJComboBox.setSelectedIndex(skinNum - 1);
sinkJComboBox.addActionListener(this); descJlabel.setText(Common.DESCRIPTION_WITH_COLOR); currentSkinDescJLabel.setText(skins[skinNum][2]);
currentSkinDescJLabel.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
try {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + Common.SUBSTANCE_SKINS_PAGE + sinkJComboBox.getSelectedItem());
} catch (IOException e1) {
e1.printStackTrace();
}
} public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { }
});
pageGourpLayout();
} private void initElement() {
currentSkinJLabel = new JLabel();
sinkJComboBox = new JComboBox<String>();
descJlabel = new JLabel();
currentSkinDescJLabel = new JLabel();
line = new JSeparator();
} @Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == sinkJComboBox) {
updateSkin();
}
} public synchronized void updateSkin() {
Object[] os = getSkinDetails(sinkJComboBox.getSelectedItem());
String index = (String) os[0];
String desc = (String) os[1];
skinNum = Integer.valueOf(index);
currentSkinDescJLabel.setText(desc);
setJUI();
} public void setViewMenuUtil(ViewMenuUtil viewMenuUtil) {
this.view = viewMenuUtil;
} /**
* If not necessary, please do not change
*/
private void pageGourpLayout() {
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
horizontalGroupLayout(layout);
verticalGroupLayout(layout);
pack();
} private void verticalGroupLayout(GroupLayout layout) {
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(40, 40, 40).addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(currentSkinJLabel).addComponent(sinkJComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(26, 26, 26).addComponent(line, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(descJlabel).addGap(18, 18, 18).addComponent(currentSkinDescJLabel).addContainerGap(47, Short.MAX_VALUE)));
} private void horizontalGroupLayout(GroupLayout layout) {
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(21, 21, 21).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(currentSkinDescJLabel).addComponent(descJlabel).addGroup(layout.createSequentialGroup().addComponent(currentSkinJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(sinkJComboBox, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE))).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addComponent(line, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE)));
}
}

/notepad/src/main/java/com/b510/notepad/util/EditMenuUtil.java

 /**
*
*/
package com.b510.notepad.util; import javax.swing.JOptionPane; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.ui.FindManagerUI;
import com.b510.notepad.ui.MainUI;
import com.b510.notepad.ui.ReplaceManagerUI; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class EditMenuUtil extends MainUI { private static final long serialVersionUID = 1L; static Logger log = Logger.getLogger(EditMenuUtil.class); private static FindManagerUI findManagerUI;
private static ReplaceManagerUI replaceeManagerUI; public EditMenuUtil(String title) {
super(title);
} public static void undo() {
log.debug(Common.UNDO);
if(undoManager.canUndo()){
undoManager.undo();
}
} public static void copy() {
log.debug(Common.COPY);
textArea.copy();
} public static void paste() {
log.debug(Common.PASTE);
textArea.paste();
} public static void cut() {
log.debug(Common.CUT);
textArea.cut();
} /**
* Showing the <code>FindManagerUI</code> window.
*/
public void find() {
log.debug(Common.FIND);
if (null == findManagerUI) {
findManagerUI = new FindManagerUI(Common.FIND);
findManagerUI.setEditMenuUtil(EditMenuUtil.this);
} else {
findManagerUI.setVisible(true);
findManagerUI.setFocusable(true);
}
} /**
* The directory : isForward(true : Forward and false : Backward)<br>
* The Case Sensitive : isCaseSensitive(true : Case Sensitive and false : Not Case Sensitive)</br>
*/
public void findNext() {
log.debug(Common.FIND_NEXT);
if (Common.EMPTY.equals(findWhat)) {
JOptionPane.showMessageDialog(EditMenuUtil.this, Common.WHAT_DO_YOU_WANT_TO_FIND, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE);
} else if (findWhat.length() > textArea.getText().length()) {
canNotFindKeyWord();
} else {
String content = textArea.getText();
String temp = Common.EMPTY;
int position = textArea.getSelectionEnd() - findWhat.length() + 1;
if (FindManagerUI.isForward) {
if(position > content.length() - findWhat.length()){
canNotFindKeyWordOperation(content.length(), content.length());
}
for (; position <= content.length() - findWhat.length(); position++) {
temp = content.substring(position, position + findWhat.length());
if (FindManagerUI.isCaseSensitive) {
if (temp.equals(findWhat)) {
setTextAreaSelection(position, position + findWhat.length());
break;
} else if (position >= content.length() - findWhat.length()) {
canNotFindKeyWordOperation(content.length(), content.length());
break;
}
} else {
if (temp.equalsIgnoreCase(findWhat)) {
setTextAreaSelection(position, position + findWhat.length());
break;
} else if (position >= content.length() - findWhat.length()) {
canNotFindKeyWordOperation(content.length(), content.length());
break;
}
}
}
} else {// Backward
if(null != textArea.getSelectedText() && !Common.EMPTY.equals(textArea.getSelectedText().trim())){
position = textArea.getSelectionStart();
}
if(position < findWhat.length()){
canNotFindKeyWordOperation(0, 0);
}
for (; position - findWhat.length() >= 0; position--) {
temp = content.substring(position - findWhat.length(), position);
if (FindManagerUI.isCaseSensitive) {//Case Sensitive
if (temp.equals(findWhat)) {
setTextAreaSelection(position - findWhat.length(), position);
break;
} else if (position - findWhat.length() == 0) {
canNotFindKeyWordOperation(0, 0);
break;
}
} else {
if (temp.equalsIgnoreCase(findWhat)) {
setTextAreaSelection(position - findWhat.length(), position);
break;
} else if (position - findWhat.length() == 0) {
canNotFindKeyWordOperation(0, 0);
break;
}
}
}
}
}
} private void canNotFindKeyWordOperation(int start, int end){
setTextAreaSelection(start, end);
canNotFindKeyWord();
} private void canNotFindKeyWord() {
JOptionPane.showMessageDialog(this, Common.CAN_NOT_FIND + findWhat, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE);
} private void setTextAreaSelection(int start, int end){
textArea.setSelectionStart(start);
textArea.setSelectionEnd(end);
} /**
* Showing the <code>ReplaceManagerUI</code> window.
*/
public void replace() {
log.debug(Common.REPLACE);
if (null == replaceeManagerUI) {
replaceeManagerUI = new ReplaceManagerUI(Common.REPLACE);
replaceeManagerUI.setEditMenuUtil(EditMenuUtil.this);
} else {
replaceeManagerUI.setVisible(true);
replaceeManagerUI.setFocusable(true);
}
} /**
* Default direction is Forward. The <code>replaceOperation</code> method can NOT be called when <br>
* <code>null == textArea.getSelectedText();</code> <br>Or <br><code>Common.EMPTY.equals(textArea.getSelectedText().trim());</code><br>
*/
public void replaceOperation(){
FindManagerUI.isForward = true;
findNext();
if (null != textArea.getSelectedText() && !Common.EMPTY.equals(textArea.getSelectedText().trim())) {
textArea.replaceRange(ReplaceManagerUI.replaceWord, textArea.getSelectionStart(), textArea.getSelectionEnd());
}
} /**
* When user want to call Replace_All method, the application will replace all with case sensitive.<br>
* A information window will display after replacing all words.<br>Finally, the application will set <br>
* <code>ReplaceManagerUI.replaceCount = 0;</code>
*/
public void replaceAllOperation() {
String replaceWord = ReplaceManagerUI.replaceWord;
String content = textArea.getText();
String temp;
for (int i = 0; i <= content.length() - findWhat.length(); i++) {
temp = content.substring(i, i + findWhat.length());
if (ReplaceManagerUI.isCaseSensitive) {
if (temp.equals(findWhat)) {
replaceRangeOperation(findWhat, replaceWord, i);
}
} else {
if (temp.equalsIgnoreCase(findWhat)) {
replaceRangeOperation(findWhat, replaceWord, i);
}
}
}
JOptionPane.showMessageDialog(this, ReplaceManagerUI.replaceCount + Common.MATCHES_REPLACED, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE);
ReplaceManagerUI.replaceCount = 0;
} private void replaceRangeOperation(String findWhat, String replaceWord, int i) {
ReplaceManagerUI.replaceCount++;
textArea.setSelectionStart(i);
textArea.setSelectionEnd(i + findWhat.length());
textArea.replaceRange(replaceWord, textArea.getSelectionStart(), textArea.getSelectionEnd());
} public static void selectAll() {
log.debug(Common.SELECT_ALL);
textArea.selectAll();
} public static void timeDate() {
log.debug(Common.TIME_DATE);
textArea.replaceRange(NotepadUtil.getTimeDate(), textArea.getSelectionStart(), textArea.getSelectionEnd());
} public void distoryFindManagerUI() {
if (null != findManagerUI) {
findManagerUI = null;
}
} public void distoryReplaceeManagerUI() {
if (null != replaceeManagerUI) {
replaceeManagerUI = null;
}
} }

/notepad/src/main/java/com/b510/notepad/util/FileMenuUtil.java

 /**
*
*/
package com.b510.notepad.util; import java.awt.FileDialog;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.ui.MainUI; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class FileMenuUtil extends MainUI { private static final long serialVersionUID = 1L; static Logger log = Logger.getLogger(FileMenuUtil.class); public FileMenuUtil(String title) {
super(title);
} /**
* Create a new Notepad. <br>
* 1. If the content of the Notepad is empty, then, create a new Notepad is
* itself.<br>
* 2. If the content of the Notepad is NOT empty, then, we want to create a
* new Notepad:<br>
* 2.1. If the Notepad is saved, then, create a new Notepad and let the
* parent <code>setVisible(false)</code><br>
* 2.2. If the Notepad is NOT saved<br>
* 2.2.1. If the user want to save the content, "YES", <code>save()</code>,
* go to step 2.1<br>
* 2.2.2. If the user do NOT want to save the content, "NO", clean the
* textArea, go to step 1<br>
* 2.2.3. If the user select the "Cancel" option, nothing to do and return
* to textArea.<br>
*
* @param mainUI
*/
public static void news(MainUI mainUI) {
log.debug(Common.NEW);
if (!Common.EMPTY.equals(filePath)) {
if (savedText.equals(textArea.getText())) {
createMainUI(mainUI);
} else {
confirmSave(mainUI);
}
} else {
if (Common.EMPTY.equals(textArea.getText())) {
createMainUI(mainUI);
} else {
confirmSave(mainUI);
}
}
} /**
* @param mainUI
*/
private static void confirmSave(MainUI mainUI) {
int option = JOptionPane.showConfirmDialog(mainUI, Common.DO_YOU_WANT_TO_SAVE_CHANGES, Common.NOTEPAD, JOptionPane.YES_NO_CANCEL_OPTION);
if (option == JOptionPane.YES_OPTION) {
save(mainUI);
createMainUI(mainUI);
} else if (option == JOptionPane.NO_OPTION) {
createMainUI(mainUI);
} else if (option == JOptionPane.CANCEL_OPTION) {
textArea.setFocusable(true);
}
} /**
* Open a text file:<br>
* 1. If the textArea is empty, then, click the "Open" menu to open a text
* file.<br>
* 2. If the textArea is NOT empty, then, we want to open a text file:<br>
* 2.1. If the content of textArea was saved, then we click the "Open" menu
* to open a text file.<br>
* 2.2. If the content of textArea was NOT saved. There is a dialog display.<br>
* 2.2.1. Selecting "Yes" to save content, and open a text file.<br>
* 2.2.2. Selecting "No", then do NOT save the content, and open a text
* file.<br>
* 2.2.3. Selecting "Cancel", nothing to do and return to textArea.<br>
*
* @param mainUI
* @see com.b510.notepad.util.FileMenuUtil#openOperation()
*/
public void open(MainUI mainUI) {
log.debug(Common.OPEN);
if (!Common.EMPTY.equals(filePath)) {
if (savedText.equals(textArea.getText())) {
openOperation(mainUI);
} else {
confirmOpen(mainUI);
}
} else {
if (Common.EMPTY.equals(textArea.getText())) {
openOperation(mainUI);
} else {
confirmOpen(mainUI);
}
}
} private void confirmOpen(MainUI mainUI) {
int option = JOptionPane.showConfirmDialog(FileMenuUtil.this, Common.DO_YOU_WANT_TO_SAVE_CHANGES, Common.CONFIM_EXIT, JOptionPane.YES_NO_CANCEL_OPTION);
if (option == JOptionPane.YES_OPTION) {
save(mainUI);
openOperation(mainUI);
} else if (option == JOptionPane.NO_OPTION) {
openOperation(mainUI);
} else if (option == JOptionPane.CANCEL_OPTION) {
textArea.setFocusable(true);
}
} /**
* The operation of the open<br>
* When the user want to open a TXT file, this method will be called.<br>
*
* @param mainUI
* @see com.b510.notepad.util.FileMenuUtil#open()
*/
private static void openOperation(MainUI mainUI) {
String path;
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter;
filter = new FileNameExtensionFilter(Common.TXT_FILE, Common.TXT);
chooser.setFileFilter(filter);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setDialogTitle(Common.OPEN);
int ret = chooser.showOpenDialog(null);
if (ret == JFileChooser.APPROVE_OPTION) {
path = chooser.getSelectedFile().getAbsolutePath();
String name = chooser.getSelectedFile().getName();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), Common.GB2312));
StringBuffer buffer = new StringBuffer();
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line).append(Common.NEW_LINE);
}
reader.close();
textArea.setText(String.valueOf(buffer));
mainUI.setTitle(name + Common.NOTEPAD_NOTEPAD);
savedText = textArea.getText();
mainUI.setSaved(true);
filePath = path;
} catch (Exception e) {
e.printStackTrace();
}
}
} /**
* Saving a TXT file.<br>
* 1. If the user want to create a new TXT file, and type the content(empty
* is allowed) to save. In this case, a dialog will display.<br>
* 2. If the user want to save a existing file. then call
* <code>save()</code> method to save content.<br>
* 3. A existing file with some changes, then the user want to save it. The
* operation as same as step 2.<br>
*
* @param mainUI
*/
public static void save(MainUI mainUI) {
log.debug(Common.SAVE);
try {
if (null != filePath && !Common.EMPTY.equals(filePath)) {
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(filePath));
out.write(textArea.getText());
out.close();
mainUI.setSaved(true);
savedText = textArea.getText();
} else {
FileDialog fileDialog = new FileDialog(mainUI, Common.SAVE, FileDialog.SAVE);
fileDialog.setVisible(true);
if (fileDialog.getDirectory() != null && fileDialog.getFile() != null) {
String fileName = fileDialog.getFile();
if (!Common.TXT.equalsIgnoreCase(NotepadUtil.getPostfix(fileName))) {
fileName = fileName + Common.POINT + Common.TXT;
}
String path = fileDialog.getDirectory() + fileName;
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path));
out.write(textArea.getText());
out.close();
mainUI.setTitle(fileName + Common.NOTEPAD_NOTEPAD);
filePath = path;
mainUI.setSaved(true);
savedText = textArea.getText();
}
}
} catch (Exception e) {
log.debug(e);
}
} public static void saveAs(MainUI mainUI) {
log.debug(Common.SAVE_AS);
String path = filePath;
filePath = Common.EMPTY;
save(mainUI);
if (Common.EMPTY.equals(filePath)) {
filePath = path;
}
} public void readProperties(MainUI mainUI) {
log.debug(Common.PROPERTIES);
if (!Common.EMPTY.equals(filePath) && mainUI.isSaved()) {
File file = new File(filePath);
JOptionPane.showMessageDialog(FileMenuUtil.this, NotepadUtil.fileProperties(file), Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE);
} else {
confirmSave(mainUI);
}
} public void exit(MainUI mainUI) {
log.debug(Common.EXIT);
if (!Common.EMPTY.equals(filePath)) {
if (savedText.equals(textArea.getText())) {
NotepadUtil.exit();
} else {
confirmExit(mainUI);
}
} else {
if (Common.EMPTY.equals(textArea.getText())) {
NotepadUtil.exit();
} else {
confirmExit(mainUI);
}
}
} private void confirmExit(MainUI mainUI) {
int option = JOptionPane.showConfirmDialog(FileMenuUtil.this, Common.DO_YOU_WANT_TO_SAVE_CHANGES, Common.CONFIM_EXIT, JOptionPane.YES_NO_CANCEL_OPTION);
if (option == JOptionPane.YES_OPTION) {
save(mainUI);
NotepadUtil.exit();
} else if (option == JOptionPane.NO_OPTION) {
NotepadUtil.exit();
} else if (option == JOptionPane.CANCEL_OPTION) {
textArea.setFocusable(true);
}
} private static void createMainUI(MainUI mainUI) {
mainUI.setTitle(Common.UNTITLE + Common.NOTEPAD_NOTEPAD);
textArea.setText(Common.EMPTY);
filePath = Common.EMPTY;
savedText = Common.EMPTY;
mainUI.setSaved(false);
} }

/notepad/src/main/java/com/b510/notepad/util/FormatMenuUtil.java

 /**
*
*/
package com.b510.notepad.util; import java.awt.Font; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.ui.FontManagerUI;
import com.b510.notepad.ui.FontSizeManagerUI;
import com.b510.notepad.ui.FontStyleManagerUI;
import com.b510.notepad.ui.MainUI; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class FormatMenuUtil extends MainUI { private static final long serialVersionUID = 1L; static Logger log = Logger.getLogger(FormatMenuUtil.class); private static FontManagerUI fontManagerUI;
private static FontSizeManagerUI fontSizeManagerUI;
private static FontStyleManagerUI fontStyleManagerUI; public FormatMenuUtil(String title) {
super(title);
} public static void wordWrap() {
log.debug(Common.WORD_WRAP);
if (lineWrap) {
textArea.setLineWrap(false);
lineWrap = false;
} else {
textArea.setLineWrap(true);
lineWrap = true;
}
} public void resetFont(MainUI mainUI) {
log.debug(Common.RESET_FONT);
fontNum = Common.FONT_NUM;
FontManagerUI.FONT_TYPE = Common.FONT_LUCIDA_CONSOLE;
fontSizeNum = Common.FONT_SIZE_NUM;
FontManagerUI.FONT_SIZE = Common.FONT_SIZE;
FontManagerUI.FONT_STYPLE = Common.FONT_STYLE_DEFAULT;
fontStyleNum = Common.FONT_STYLE_NUM;
textArea.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE));
setJUI();
} public void font(MainUI mainUI) {
log.debug(Common.FONT);
if (null == fontManagerUI) {
fontManagerUI = new FontManagerUI(Common.FONT);
fontManagerUI.setFormatMenuUtil(FormatMenuUtil.this);
} else {
fontManagerUI.setVisible(true);
fontManagerUI.setFocusable(true);
}
} public void fontSize(MainUI mainUI) {
log.debug(Common.FONT_SIZE_TITLE);
if (null == fontSizeManagerUI) {
fontSizeManagerUI = new FontSizeManagerUI(Common.FONT);
fontSizeManagerUI.setFormatMenuUtil(FormatMenuUtil.this);
} else {
fontSizeManagerUI.setVisible(true);
fontSizeManagerUI.setFocusable(true);
}
} public void fontStyle(MainUI mainUI) {
log.debug(Common.FONT_SIZE_TITLE);
if (null == fontStyleManagerUI) {
fontStyleManagerUI = new FontStyleManagerUI(Common.FONT_STYLE);
fontStyleManagerUI.setFormatMenuUtil(FormatMenuUtil.this);
} else {
fontStyleManagerUI.setVisible(true);
fontStyleManagerUI.setFocusable(true);
}
} public void distoryFontManagerUI() {
if (null != fontManagerUI) {
fontManagerUI = null;
}
} public void distoryFontSizeManagerUI() {
if (null != fontSizeManagerUI) {
fontSizeManagerUI = null;
}
} public void distoryFontStyleManagerUI() {
if (null != fontSizeManagerUI) {
fontSizeManagerUI = null;
}
}
}

/notepad/src/main/java/com/b510/notepad/util/HelpMenuUtil.java

 /**
*
*/
package com.b510.notepad.util; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.ui.AboutUI;
import com.b510.notepad.ui.MainUI; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class HelpMenuUtil extends MainUI { private static final long serialVersionUID = 1L; static Logger log = Logger.getLogger(HelpMenuUtil.class); private static AboutUI aboutUI; public HelpMenuUtil(String title) {
super(title);
} public void about(MainUI mainUI) {
log.debug(Common.ABOUT_NOTEPAD);
if (null == aboutUI) {
aboutUI = new AboutUI(Common.ABOUT_NOTEPAD);
aboutUI.setHelpMenuUtil(HelpMenuUtil.this);
} else {
aboutUI.setVisible(true);
aboutUI.setFocusable(true);
}
} public void distoryAboutUI() {
if (null != aboutUI) {
aboutUI = null;
}
}
}

/notepad/src/main/java/com/b510/notepad/util/NotepadUtil.java

 /**
*
*/
package com.b510.notepad.util; import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date; import org.apache.log4j.Logger; import com.b510.notepad.common.Common; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class NotepadUtil { static Logger log = Logger.getLogger(NotepadUtil.class); public static void exit() {
log.debug(Common.SYSTEM_EXIT);
System.exit(0);
} public static void accessURL(String url) {
if (null == url || Common.EMPTY.equals(url)) {
return;
}
try {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e1) {
e1.printStackTrace();
}
} /**
* @return i.e. 3:49 PM 11/20/2014
*/
public static String getTimeDate(){
SimpleDateFormat sdf = new SimpleDateFormat(Common.DATE_FORMAT);
Date date = new Date();
String timeDate = sdf.format(date);
return timeDate;
} /**
* @param path i.e. com/b510/resources/images/hongten.png
* @return i.e. png
*/
public static String getPostfix(String path) {
if (path == null || Common.EMPTY.equals(path.trim())) {
return Common.EMPTY;
}
if (path.contains(Common.POINT)) {
return path.substring(path.lastIndexOf(Common.POINT) + 1, path.length());
}
return Common.EMPTY;
} public static String fileProperties(File file) {
return "<html>"
+ "File Name : " + file.getName() + "<br/>"
+ "File Type : "+ getPostfix(file.getAbsolutePath()) +" file<br/>"
+ "File Size : " + file.length()/1024 +" KB<br/>"
+ "Modify Date : " + new SimpleDateFormat().format(file.lastModified()) + "<br/>"
+ "Location : " + file.getParent() + "<br/>"
+ "CanRead : " + file.canRead() + "<br/>"
+ "CanWrite : " + file.canWrite() + "<html>";
}
}

/notepad/src/main/java/com/b510/notepad/util/ViewMenuUtil.java

 /**
*
*/
package com.b510.notepad.util; import org.apache.log4j.Logger; import com.b510.notepad.common.Common;
import com.b510.notepad.ui.MainUI;
import com.b510.notepad.ui.SkinManagerUI; /**
* @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
* @created Nov 19, 2014
*/
public class ViewMenuUtil extends MainUI { private static final long serialVersionUID = 1L; static Logger log = Logger.getLogger(ViewMenuUtil.class); private static SkinManagerUI skinManagerUI; public ViewMenuUtil(String title) {
super(title);
} public void skin(MainUI mainUI) {
log.debug(Common.SKIN);
if (null == skinManagerUI) {
skinManagerUI = new SkinManagerUI(Common.SKIN);
skinManagerUI.setViewMenuUtil(ViewMenuUtil.this);
} else {
skinManagerUI.setVisible(true);
skinManagerUI.setFocusable(true);
}
} public void distorySkinManagerUI() {
if (null != skinManagerUI) {
skinManagerUI = null;
}
} }

/notepad/src/main/java/log4j.properties

 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[Notepad] %d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c:%L - %m%n log4j.appender.notepad=org.apache.log4j.DailyRollingFileAppender
log4j.appender.notepad.File=C:\\log4j\\log4j-notepad
log4j.appender.notepad.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.notepad.layout=org.apache.log4j.PatternLayout
log4j.appender.notepad.layout.ConversionPattern=[Notepad] %d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c:%L - %m%n log4j.rootLogger=debug,stdout,notepad

/notepad/pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.b510.notepad</groupId>
<artifactId>notepad</artifactId>
<version>1.0</version>
<packaging>jar</packaging> <name>notepad</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency> <!-- substance dependency start-->
<dependency>
<groupId>org.jvnet.substance</groupId>
<artifactId>substance</artifactId>
<version>1.0</version>
</dependency>
<!-- substance dependency end-->
</dependencies>
</project>

=================================================
More Information About Notepad:
=================================================

Author : Hongten
E-mail : hongtenzone@foxmail.com
Home Page : http://www.cnblogs.com
Notepad Page : http://www.cnblogs.com/hongten/p/hongten_notepad_index.html
Notepad Skin Page : http://www.cnblogs.com/hongten/p/hongten_notepad_substance_skins.html
Windows Notepad : http://windows.microsoft.com/en-us/windows/notepad-faq#1TC=windows-7

=================================================
Download:
=================================================

Source Code Download :

http://files.cnblogs.com/hongten/notepad_src.rar    

http://pan.baidu.com/s/1o6wU49k

Notepad API :

http://files.cnblogs.com/hongten/notepad_API.rar

http://pan.baidu.com/s/1o6wU49k

Notepad_1.1 :  Updating My Notepad_1.1

========================================================

More reading,and english is important.

I'm Hongten

My Notepad

大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。
Hongten博客排名在100名以内。粉丝过千。
Hongten出品,必是精品。

E | hongtenzone@foxmail.com  B | http://www.cnblogs.com/hongten

========================================================

My Notepad的更多相关文章

  1. notepad&plus;&plus;设置默认打开txt文件失效的解决方法

    1.系统环境 win10企业版,64位系统 2.初步设置 设置txt默认为notepad++打开,菜单:设置->首选项->文件关联 选择对应的文件扩展,点击"关闭"按钮 ...

  2. NotePad&plus;&plus;中JSLint的使用

    1.第一步下载Notepad++ 2.安装JSLint插件 3.运行JSlint 4.前提是你设置了当前语言或者本身文件就是js 5.JSLint的作用主要就是检查你的JS的规则正确性(至少是绝大部分 ...

  3. Notepad&plus;&plus; 实用技巧

    Notepad++是一款开源的文本编辑器,功能强大.很适合用于编辑.注释代码.它支持绝大部分主流的编程语言. 本文主要列举了本人在实际使用中遇到的一些技巧. 快捷键 自定义快捷键 首先,需要知道的是: ...

  4. 我喜欢的Notepad&plus;&plus;插件

    Notepad++插件 HEX-Editor 文本转16进制,查看编辑. NppExport 导出已着色代码为其他格式的文件. 将彩色代码,导出为word文档(RFT)或网页(HTML)文件,或者将彩 ...

  5. Notepad&plus;&plus;源码编译及其分析

    Notepad++是一个小巧精悍的编辑器,其使用方法我就不多说了,由于notepad++是使用c++封装的windows句柄以及api来实现的,因此对于其源码的研究有助于学习如何封装自己简单的库(当然 ...

  6. Reverse Core 第二部分 - 14&amp&semi;15章 - 运行时压缩&amp&semi;调试UPX压缩的notepad

    @date: 2016/11/29 @author: dlive 0x00 前言 周六周日两天在打HCTF2016线上赛,没时间看书,打完比赛接着看~~ 0x01 运行时压缩 对比upx压缩前后的no ...

  7. Notepad&plus;&plus; 使用nppexec插件配置简易开发环境

    notepad++  采用nppexec插件来配置简易开发环境,而不需要笨重的IDE以及麻烦.重复的命令行.控制台输入: 以下为本人最近用到的脚本配置: //编程语言脚本中$(NAME_PART).x ...

  8. notepad&plus;&plus;快捷键

    notepad++现在是我最常用的文本编辑工具,其中使用的列模式编辑,也是很好使用的. 基本的快捷键: Ctrl-C,Ctrl-X,Ctrl-V,Ctrl-Y,Ctrl-A,Ctrl-F,Ctrl-S ...

  9. 设置NotePad&plus;&plus;设置&quot&semi;不打开上次关闭的文件&quot&semi;

    notepad++是一个很好的记事本工具,但是默认会记录上次打开时未关闭的文件,但是实际上用起来并不方便, 可以按照下面的方式去除,notepad++版本:v6.6.2,os:win7 64位 按照以 ...

  10. 给notepad&plus;&plus;添加右键菜单

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\Shell\NotePad++] [HKEY_CLASSES_ROOT\*\Shel ...

随机推荐

  1. Visual Studio Code 代理设置

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...

  2. org&period;artofsolving&period;jodconverter&period;office&period;OfficeException&colon; failed to start and connect

    org.artofsolving.jodconverter.office.OfficeException: failed to start and connect docviewer 调用 openo ...

  3. c&num;绘制表格

    //绘制表格 //定义绘制表格的参数 Pen _Pen = new Pen(Brushes.Black); // VBConversions Note: Initial value cannot be ...

  4. JS对象的写法

    写法1: <script> var database = function () { function add(){ console.info("add"); } fu ...

  5. ubuntu 彻底删除软件包

    找到此软件名称,然后sudo apt-get purge ......(点点为为程序名称),purge参数为彻底删除文件,然后sudo apt-get autoremove,sudo apt-get ...

  6. Android studio启动后无法更新

    I'm trying to run android-studio 1.0 on ubuntu using start up script but as i'm behind proxy the and ...

  7. DDL 和DML 区别

    DML(Data Manipulation Language)数据操纵语言: 适用范围:对数据库中的数据进行一些简单操作,如insert,delete,update,select等. DDL(Data ...

  8. &lbrack;js高手之路&rsqb;设计模式系列课程-组合模式&plus;寄生组合继承实战新闻列表

    所谓组合模式,就是把一堆结构分解出来,组成在一起,现实中很多这样的例子,如: 1.肯德基套餐就是一种组合模式, 比如鸡腿堡套餐,一般是是由一个鸡腿堡,一包薯条,一杯可乐等组成的 2.组装的台式机同理, ...

  9. Lua中string&period;format占位符的使用

    虽然lua中字符串拼接"string.format"相对于".."消耗较大,但有时为了代码的可读性,项目中还是经常用到"string.format&q ...

  10. &lbrack;luogu2822&rsqb;&lbrack;组合数问题&rsqb;

    题目链接 题解: 对于上面和下面的式子进行分解质因数,然后看看上面的质因数个数减去下面的质因数个数能不能达到k的质因数的要求即可. 分解质因数的时候用对于阶乘分解质因数的常用方法:比如要求1999!中 ...