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:
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:
=================================================
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:
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
2. File Menu
3. Edit Menu
4. Format Menu
5. View Menu
6.Help Menu
7.Untitle Notepad
8. Open a File
9. About Notepad
10. Change Skin
=================================================
Source Code:
=================================================
/notepad/src/main/java/com/b510/notepad/client/Client.java
1 /** 2 * 3 */ 4 package com.b510.notepad.client; 5 6 import com.b510.notepad.common.Common; 7 import com.b510.notepad.ui.MainUI; 8 9 /** 10 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 11 * @created Nov 19, 2014 12 */ 13 public class Client { 14 15 public static void main(String[] args) { 16 start(); 17 } 18 19 public static MainUI start() { 20 MainUI ui = new MainUI(Common.TITLE); 21 ui.init(); 22 return ui; 23 } 24 }
/notepad/src/main/java/com/b510/notepad/common/Common.java
1 package com.b510.notepad.common; 2 3 /** 4 * @author Hongten 5 * @created Nov 19, 2014 6 */ 7 public class Common { 8 9 public static final String HYPHEN = "-"; 10 public static final String EMPTY = ""; 11 public static final String NEW_LINE = "\r\n"; 12 public static final String BLANK = " "; 13 public static final String QUESTION_MARK = "?"; 14 public static final String POINT = "."; 15 public static final String COLOR = ":"; 16 public static final String START = "*"; 17 public static final String TXT = "txt"; 18 public static final String TXT_FILE = START + POINT + TXT; 19 20 public static final String UNTITLE = "Untitled"; 21 public static final String NOTEPAD = "Notepad"; 22 public static final String NOTEPAD_NOTEPAD = BLANK + HYPHEN + BLANK + NOTEPAD; 23 public static final String TITLE = UNTITLE + NOTEPAD_NOTEPAD; 24 public static final String SYSTEM_EXIT = "System exit"; 25 public static final String SYSTEM_OPEN = "System open"; 26 27 public static final String FILE = "File"; 28 public static final String EDIT = "Edit"; 29 public static final String FORMAT = "Format"; 30 public static final String VIEW = "View"; 31 public static final String Help = "Help"; 32 33 // File Items 34 public static final String NEW = "New"; 35 public static final String OPEN = "Open..."; 36 public static final String SAVE = "Save"; 37 public static final String SAVE_AS = "Save as..."; 38 public static final String PROPERTIES = "Properties"; 39 public static final String EXIT = "Exit"; 40 41 // Edit Items 42 public static final String UNDO = "Undo"; 43 public static final String COPY = "Copy"; 44 public static final String PASTE = "Paste"; 45 public static final String CUT = "Cut"; 46 public static final String DELETE = "Delete"; 47 public static final String FIND = "Find..."; 48 public static final String FIND_NEXT = "Find Next"; 49 public static final String REPLACE = "Replace"; 50 public static final String GO_TO = "Go To..."; 51 public static final String SELECT_ALL = "Select All"; 52 public static final String TIME_DATE = "Time/Date"; 53 54 // Format Items 55 public static final String WORD_WRAP = "Word Wrap"; 56 public static final String RESET_FONT = "Reset Font"; 57 public static final String FONT = "Font"; 58 public static final String FONT_STYLE = "Font Style"; 59 public static final String FONT_SIZE_TITLE = "Font Size"; 60 61 // View 62 public static final String STATUS_BAR = "Status Bar"; 63 public static final String SKIN = "Change Skin"; 64 65 // Help Items 66 public static final String VIEW_HELP = "View Help"; 67 public static final String ABOUT_NOTEPAD = "About NotePad"; 68 69 // KeyStroke 70 public static final char A = 'A'; 71 public static final char N = 'N'; 72 public static final char O = 'O'; 73 public static final char L = 'L'; 74 public static final char Z = 'Z'; 75 public static final char C = 'C'; 76 public static final char D = 'D'; 77 public static final char W = 'W'; 78 public static final char H = 'H'; 79 public static final char F = 'F'; 80 public static final char V = 'V'; 81 public static final char X = 'X'; 82 public static final char G = 'G'; 83 public static final char S = 'S'; 84 public static final char P = 'P'; 85 public static final char T = 'T'; 86 public static final char SPACE = ' '; 87 88 // notepad\src\main\resources\images 89 public static final String IMAGE_PATH = "images/"; 90 91 public static final String HONGTEN_PIC = IMAGE_PATH + "hongten.png"; 92 93 // About UI 94 public static final String AUTHOR = "Author"; 95 public static final String AUTHOR_NAME = "Hongten"; 96 public static final String AUTHOR_DESC = "I'm " + AUTHOR_NAME; 97 public static final String ITEM = "Item"; 98 public static final String DESCRIPTION = "Desctiption"; 99 public static final String APPLICATION = "Application"; 100 public static final String NAME = "Name"; 101 public static final String APPLICATION_NAME = APPLICATION + BLANK + NAME; 102 public static final String NOTEPAD_APP = NOTEPAD; 103 public static final String APPLICATION_DESCRIPTION = APPLICATION + BLANK + DESCRIPTION; 104 public static final String APPLICATION_DESCRIPTION_DETAIL = "A " + NOTEPAD; 105 public static final String VERSION = "Version"; 106 public static final String VERSION_VALUE = "1.0"; 107 public static final String BLOG = "Blog"; 108 public static final String HOME_PAGE = "http://www.cnblogs.com/hongten"; 109 public static final String NOTEPAD_PUBLISHED_PAGE = HOME_PAGE + "/p/hongten_notepad_index.html"; 110 public static final String NOTEPAD_SUBSTANCE_SKINS_PAGE = HOME_PAGE + "/p/hongten_notepad_substance_skins.html"; 111 public static final String SUBSTANCE_SKINS_PAGE = NOTEPAD_SUBSTANCE_SKINS_PAGE + "#"; 112 public static final String NOTEPAD_PUBLISHED_BOOKMARK_PAGE = NOTEPAD_PUBLISHED_PAGE + "#"; 113 114 public static final int TABLE_ROW_HEIGHT = 20; 115 116 // Dialog messages and titles 117 public static final String CONFIM_EXIT = "Confim Exit"; 118 public static final String ACCESS_URL_REQUEST = "Access URL Request"; 119 public static final String ACCESS_URL = "Access URL : "; 120 121 public static final String FONT_LUCIDA_CONSOLE = "Lucida Console"; 122 public static final String FONT_TYPE = "宋体"; 123 public static final int FONT_SIZE = 12; 124 public static final int FONT_NUM = 148; 125 public static final int FONT_SIZE_NUM = 4; 126 public static final int FONT_STYLE_NUM = 0; 127 public static final String FONT_STYLE_DEFAULT = "Regular"; 128 public static final String DATE_FORMAT = "HH:mm MM/dd/yyyy"; 129 public static final String THIS_IS_A_SIMPLE = "This is a Simple"; 130 public static final String SIMPLE = "Simple"; 131 132 public static final String CURRENT_SINK = "Current Skin" + BLANK + COLOR + BLANK; 133 public static final String DESCRIPTION_WITH_COLOR = DESCRIPTION + BLANK + COLOR + BLANK; 134 public static final String CURRENT_FONT = "Current Font" + BLANK + COLOR + BLANK; 135 public static final String CURRENT_FONT_SIZE = "Current Font Size" + BLANK + COLOR + BLANK; 136 public static final String CURRENT_FONT_STYLE = "Current Font Style" + BLANK + COLOR + BLANK; 137 138 public static final String DO_YOU_WANT_TO_SAVE_CHANGES = "Do you want to save changes?"; 139 public static final String WHAT_DO_YOU_WANT_TO_FIND = "Please type what do you want to find."; 140 public static final String CAN_NOT_FIND = "Cannot find "; 141 public static final String MATCHES_REPLACED = " matches replaced!"; 142 143 public static final String FIND_WHAT = "Find What :"; 144 public static final String REPLACE_TO = "Replace To :"; 145 public static final String REPLACE_ALL = "Replace All"; 146 public static final String CASE_SENSITIVE = "Case Sensitive"; 147 public static final String FORWARD = "Forward"; 148 public static final String BACKWARD = "Backward"; 149 public static final String CANCEL = "Cancel"; 150 public static final String GB2312 = "GB2312"; 151 152 public static final String NOTEPAD_HOME_PAGE = "Home Page"; 153 public static final String NOTEPAD_SKINS = "Notepad Skins"; 154 public static final String SOURCE = "Source"; 155 public static final String SOURCE_CODE = SOURCE + " Code"; 156 public static final String SOURCE_CODE_DOWNLOAD = SOURCE_CODE + " Download"; 157 public static final String NOTEPAD_API = "Notepad API"; 158 159 public static final String SOURCE_CODE_BOOKMARK = "Source.Code"; 160 public static final String SOURCE_CODE_DOWNLOAD_BOOKMARK = SOURCE_CODE_BOOKMARK + ".Download"; 161 public static final String NOTEPAD_API_BOOKMARK = "Notepad.API"; 162 }
/notepad/src/main/java/com/b510/notepad/ui/AboutUI.java
1 package com.b510.notepad.ui; 2 3 import java.awt.Cursor; 4 import java.awt.event.MouseEvent; 5 import java.awt.event.MouseListener; 6 import java.awt.event.WindowAdapter; 7 import java.awt.event.WindowEvent; 8 9 import javax.swing.GroupLayout; 10 import javax.swing.ImageIcon; 11 import javax.swing.JButton; 12 import javax.swing.JLabel; 13 import javax.swing.JOptionPane; 14 import javax.swing.JPanel; 15 import javax.swing.JScrollPane; 16 import javax.swing.JTable; 17 import javax.swing.ListSelectionModel; 18 import javax.swing.SwingConstants; 19 import javax.swing.table.DefaultTableModel; 20 21 import org.apache.log4j.Logger; 22 23 import com.b510.notepad.common.Common; 24 import com.b510.notepad.util.HelpMenuUtil; 25 import com.b510.notepad.util.NotepadUtil; 26 27 /** 28 * Location : MainUI --> Help --> About Notepad
29 *30 * The
AboutUI
display the information about this application.
31 *32 * i.e., Author, Application Name, Application description, Version, Blog.etc.
33 *34 * 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.
35 * The dialog is a access URL request dialog, and you will access the URL(http://www.cnblogs.com/hongten) if you click 'Yes'.
36 *37 * If you want to use this class, you should do as below:
38 *39 *AboutUI aboutUI = new AboutUI("About Notepad");
40 *
41 * 42 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 43 * @created Nov 20, 2014 44 */ 45 public class AboutUI extends MainUI { 46 47 private static final long serialVersionUID = 1L; 48 49 static Logger log = Logger.getLogger(AboutUI.class); 50 51 private JLabel descriptionLabel; 52 private JButton hongtenButton; 53 private JTable aboutUITable; 54 private JPanel mainPanel; 55 private JScrollPane rightScrollPane; 56 57 private HelpMenuUtil help; 58 59 public AboutUI(String title) { 60 super(title); 61 initComponents(); 62 initSelf(); 63 setAlwaysOnTop(true); 64 addWindowListener(new WindowAdapter() { 65 @Override 66 public void windowClosing(WindowEvent e) { 67 AboutUI.this.setVisible(false); 68 help.distoryAboutUI(); 69 } 70 }); 71 } 72 73 public void initSelf() { 74 this.setVisible(true); 75 setResizable(false); 76 this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150); 77 } 78 79 private void initComponents() { 80 initElement(); 81 initHongtenButton(); 82 initAboutUITable(); 83 initDescriptionLabel(); 84 mainPanelLayout(); 85 } 86 87 private void initHongtenButton() { 88 hongtenButton.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource(Common.HONGTEN_PIC))); 89 hongtenButton.setToolTipText(Common.ABOUT_NOTEPAD); 90 } 91 92 private void initAboutUITable() { 93 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 } }; 94 95 String[] titles = new String[] { Common.ITEM, Common.DESCRIPTION }; 96 97 aboutUITable.setModel(new DefaultTableModel(values, titles) { 98 private static final long serialVersionUID = 1L; 99 boolean[] canEdit = new boolean[] { false, false }; 100 101 public boolean isCellEditable(int rowIndex, int columnIndex) { 102 return canEdit[columnIndex]; 103 } 104 }); 105 106 aboutUITable.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 107 aboutUITable.setOpaque(false); 108 aboutUITable.setRowHeight(Common.TABLE_ROW_HEIGHT); 109 aboutUITable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 110 aboutUITable.setSurrendersFocusOnKeystroke(true); 111 aboutUITable.getTableHeader().setReorderingAllowed(false); 112 aboutUITable.addMouseListener(new MouseListener() { 113 114 public void mouseReleased(MouseEvent e) { 115 116 } 117 118 public void mousePressed(MouseEvent e) { 119 if (e.getClickCount() == 2) { 120 matchUrlOperation(); 121 } 122 } 123 124 public void mouseExited(MouseEvent e) { 125 126 } 127 128 public void mouseEntered(MouseEvent e) { 129 130 } 131 132 public void mouseClicked(MouseEvent e) { 133 134 } 135 }); 136 rightScrollPane.setViewportView(aboutUITable); 137 } 138 139 private void matchUrlOperation() { 140 int id = aboutUITable.getSelectedRow(); 141 String url = (String) aboutUITable.getValueAt(id, 1); 142 if (url.equals(Common.HOME_PAGE)) { 143 askAccessBlogOperation(); 144 } 145 } 146 147 // Show a dialog to access URL request. 148 // You will access the URL if you click 'Yes'. 149 protected void askAccessBlogOperation() { 150 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); 151 if (option == JOptionPane.YES_OPTION) { 152 NotepadUtil.accessURL(Common.HOME_PAGE); 153 } 154 } 155 156 private void initDescriptionLabel() { 157 descriptionLabel.setFont(new java.awt.Font(Common.FONT_LUCIDA_CONSOLE, 1, 18)); 158 descriptionLabel.setHorizontalAlignment(SwingConstants.CENTER); 159 descriptionLabel.setText(Common.AUTHOR_DESC); 160 } 161 162 private void initElement() { 163 mainPanel = new JPanel(); 164 hongtenButton = new JButton(); 165 rightScrollPane = new JScrollPane(); 166 aboutUITable = new JTable(); 167 descriptionLabel = new JLabel(); 168 } 169 170 public void setHelpMenuUtil(HelpMenuUtil helpMenuUtil){ 171 this.help = helpMenuUtil; 172 } 173 174 /** 175 * If not necessary, please do not change 176 */ 177 private void mainPanelLayout() { 178 GroupLayout mainPanelLayout = new GroupLayout(mainPanel); 179 mainPanel.setLayout(mainPanelLayout); 180 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))); 181 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))); 182 183 GroupLayout layout = new GroupLayout(getContentPane()); 184 getContentPane().setLayout(layout); 185 layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap())); 186 layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap())); 187 188 pack(); 189 } 190 }
/notepad/src/main/java/com/b510/notepad/ui/FindManagerUI.java
1 package com.b510.notepad.ui; 2 3 import java.awt.Dimension; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.WindowAdapter; 6 import java.awt.event.WindowEvent; 7 8 import javax.swing.GroupLayout; 9 import javax.swing.JButton; 10 import javax.swing.JCheckBox; 11 import javax.swing.JLabel; 12 import javax.swing.JOptionPane; 13 import javax.swing.JPanel; 14 import javax.swing.JRadioButton; 15 import javax.swing.JTextField; 16 import javax.swing.LayoutStyle; 17 18 import org.apache.log4j.Logger; 19 20 import com.b510.notepad.common.Common; 21 import com.b510.notepad.util.EditMenuUtil; 22 23 /** 24 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 25 * @created Nov 20, 2014 26 */ 27 public class FindManagerUI extends MainUI { 28 private static final long serialVersionUID = 1L; 29 static Logger log = Logger.getLogger(FindManagerUI.class); 30 31 private JPanel bGJPanel; 32 private JRadioButton backwardJRadioButton; 33 private JButton cancelJButton; 34 private JCheckBox caseSensitiveJCheckBox; 35 private JButton findNextJButton; 36 private JLabel findWhatJLabel; 37 private JRadioButton forwardJRadioButton; 38 private JTextField keyWordJTextField; 39 40 public static boolean isForward = true; 41 public static boolean isCaseSensitive = false; 42 43 private EditMenuUtil edit; 44 45 public FindManagerUI(String title) { 46 super(title); 47 initComponents(); 48 49 initSelf(); 50 setAlwaysOnTop(true); 51 addWindowListener(new WindowAdapter() { 52 @Override 53 public void windowClosing(WindowEvent e) { 54 distoryFindManagerUI(); 55 } 56 }); 57 } 58 59 public void initSelf() { 60 this.setVisible(true); 61 setResizable(false); 62 this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150); 63 } 64 65 /** 66 * If not necessary, do not change the order. 67 */ 68 private void initComponents() { 69 initElements(); 70 initFindWhat(); 71 initCaseSensitive(); 72 initFindNext(); 73 initCancle(); 74 initDirection(); 75 initLayout(); 76 } 77 78 private void initElements() { 79 bGJPanel = new JPanel(); 80 findWhatJLabel = new JLabel(); 81 keyWordJTextField = new JTextField(); 82 caseSensitiveJCheckBox = new JCheckBox(); 83 findNextJButton = new JButton(); 84 cancelJButton = new JButton(); 85 forwardJRadioButton = new JRadioButton(); 86 backwardJRadioButton = new JRadioButton(); 87 } 88 89 private void initDirection() { 90 forwardJRadioButton.setSelected(true); 91 forwardJRadioButton.setText(Common.FORWARD); 92 forwardJRadioButton.addActionListener(this); 93 94 backwardJRadioButton.setText(Common.BACKWARD); 95 backwardJRadioButton.addActionListener(this); 96 } 97 98 private void initCancle() { 99 cancelJButton.setText(Common.CANCEL); 100 cancelJButton.setMaximumSize(new Dimension(87, 23)); 101 cancelJButton.setMinimumSize(new Dimension(87, 23)); 102 cancelJButton.setPreferredSize(new Dimension(87, 23)); 103 cancelJButton.addActionListener(this); 104 } 105 106 private void initFindNext() { 107 findNextJButton.setText(Common.FIND_NEXT); 108 findNextJButton.addActionListener(this); 109 } 110 111 private void initCaseSensitive() { 112 caseSensitiveJCheckBox.setText(Common.CASE_SENSITIVE); 113 caseSensitiveJCheckBox.addActionListener(this); 114 } 115 116 private void initFindWhat() { 117 findWhatJLabel.setText(Common.FIND_WHAT); 118 119 if (null == textArea.getSelectedText() || Common.EMPTY.equals(textArea.getSelectedText().trim())) { 120 keyWordJTextField.setText(findWhat); 121 } else if(null != textArea.getSelectedText() && !Common.EMPTY.equals(textArea.getSelectedText().trim())){ 122 keyWordJTextField.setText(textArea.getSelectedText()); 123 }else{ 124 keyWordJTextField.setText(findWhat); 125 } 126 } 127 128 public void actionPerformed(ActionEvent e) { 129 if (e.getSource() == backwardJRadioButton) { 130 directionOfOperation(false); 131 } else if (e.getSource() == forwardJRadioButton) { 132 directionOfOperation(true); 133 } else if (e.getSource() == findNextJButton) { 134 findNextOperation(); 135 } else if (e.getSource() == cancelJButton) { 136 distoryFindManagerUI(); 137 } else if (e.getSource() == caseSensitiveJCheckBox) { 138 caseSensitiveSwitch(); 139 } 140 } 141 142 private void findNextOperation() { 143 findWhat = keyWordJTextField.getText(); 144 if (Common.EMPTY.equals(findWhat)) { 145 JOptionPane.showMessageDialog(FindManagerUI.this, Common.WHAT_DO_YOU_WANT_TO_FIND, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE); 146 keyWordJTextField.setFocusable(true); 147 } 148 edit.findNext(); 149 } 150 151 /** 152 * Operation for Cancel button 153 */ 154 private void distoryFindManagerUI() { 155 FindManagerUI.this.setVisible(false); 156 edit.distoryFindManagerUI(); 157 } 158 159 /** 160 * Case Sensitive Switch 161 */ 162 private void caseSensitiveSwitch() { 163 if (null == caseSensitiveJCheckBox.getSelectedObjects()) { 164 isCaseSensitive = false; 165 } else { 166 isCaseSensitive = true; 167 } 168 log.debug(isCaseSensitive); 169 } 170 171 /** 172 * Direction of Operation
173 *Forward : 174 *directionOfOperation(true);
Backward : 175 * @param bdirectionOfOperation(false);
b = true;
Forward is selected;b = false;
Backward is selected.
176 */ 177 private void directionOfOperation(boolean b) { 178 isForward = b; 179 forwardJRadioButton.setSelected(b); 180 backwardJRadioButton.setSelected(!b); 181 log.debug(isForward); 182 } 183 184 185 public void setEditMenuUtil(EditMenuUtil editMenuUtil) { 186 this.edit = editMenuUtil; 187 } 188 189 /** 190 * If not necessary, do not change. 191 */ 192 private void initLayout() { 193 GroupLayout bGJPanelLayout = new GroupLayout(bGJPanel); 194 bGJPanel.setLayout(bGJPanelLayout); 195 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())); 196 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())); 197 198 GroupLayout layout = new GroupLayout(getContentPane()); 199 getContentPane().setLayout(layout); 200 layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(bGJPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap())); 201 layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(bGJPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap())); 202 pack(); 203 } 204 }
/notepad/src/main/java/com/b510/notepad/ui/FontManagerUI.java
1 package com.b510.notepad.ui; 2 3 import java.awt.Font; 4 import java.awt.GraphicsEnvironment; 5 import java.awt.event.ActionEvent; 6 import java.awt.event.WindowAdapter; 7 import java.awt.event.WindowEvent; 8 9 import javax.swing.DefaultComboBoxModel; 10 import javax.swing.GroupLayout; 11 import javax.swing.JComboBox; 12 import javax.swing.JLabel; 13 import javax.swing.JSeparator; 14 import javax.swing.LayoutStyle; 15 16 import com.b510.notepad.common.Common; 17 import com.b510.notepad.util.FormatMenuUtil; 18 19 /** 20 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 21 * @created Nov 20, 2014 22 */ 23 public class FontManagerUI extends MainUI { 24 private static final long serialVersionUID = -37011351219515242L; 25 26 private JLabel currentFontDescJLabel; 27 private JLabel currentFontJLabel; 28 private JLabel descJlabel; 29 private JSeparator line; 30 private JComboBoxfontJComboBox; 31 32 private FormatMenuUtil format; 33 34 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 35 String fontNames[] = ge.getAvailableFontFamilyNames(); 36 37 public static String FONT_TYPE = Common.FONT_TYPE; 38 public static int FONT_SIZE = Common.FONT_SIZE; 39 public static String FONT_STYPLE = Common.FONT_STYLE_DEFAULT; 40 41 public FontManagerUI(String title) { 42 super(title); 43 initComponents(); 44 45 initSelf(); 46 setAlwaysOnTop(true); 47 addWindowListener(new WindowAdapter() { 48 @Override 49 public void windowClosing(WindowEvent e) { 50 FontManagerUI.this.setVisible(false); 51 format.distoryFontManagerUI(); 52 } 53 }); 54 } 55 56 public void initSelf() { 57 this.setVisible(true); 58 setResizable(false); 59 this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150); 60 } 61 62 private void initComponents() { 63 initElement(); 64 currentFontJLabel.setText(Common.CURRENT_FONT); 65 66 fontJComboBox.setModel(new DefaultComboBoxModel (fontNames)); 67 int i = 0; 68 for(String name : fontNames){ 69 if(FontManagerUI.FONT_TYPE.equals(name)){ 70 fontNum = i; 71 } 72 i++; 73 } 74 fontJComboBox.setSelectedIndex(fontNum); 75 fontJComboBox.addActionListener(this); 76 77 descJlabel.setText(Common.DESCRIPTION_WITH_COLOR); 78 79 currentFontDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE)); 80 currentFontDescJLabel.setText(Common.THIS_IS_A_SIMPLE); 81 pageGourpLayout(); 82 } 83 84 private void initElement() { 85 currentFontJLabel = new JLabel(); 86 fontJComboBox = new JComboBox (); 87 descJlabel = new JLabel(); 88 currentFontDescJLabel = new JLabel(); 89 line = new JSeparator(); 90 } 91 92 @Override 93 public void actionPerformed(ActionEvent e) { 94 if (e.getSource() == fontJComboBox) { 95 updateSkin(); 96 } 97 } 98 99 public synchronized void updateSkin() { 100 fontNum = fontJComboBox.getSelectedIndex(); 101 log.debug(fontJComboBox.getSelectedItem().toString()); 102 FontManagerUI.FONT_TYPE = fontJComboBox.getSelectedItem().toString(); 103 currentFontDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE)); 104 currentFontDescJLabel.setText(Common.THIS_IS_A_SIMPLE); 105 textArea.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE)); 106 setJUI(); 107 } 108 109 public void setFormatMenuUtil(FormatMenuUtil formatMenuUtil){ 110 this.format = formatMenuUtil; 111 } 112 113 /** 114 * If not necessary, please do not change 115 */ 116 private void pageGourpLayout() { 117 GroupLayout layout = new GroupLayout(getContentPane()); 118 getContentPane().setLayout(layout); 119 horizontalGroupLayout(layout); 120 verticalGroupLayout(layout); 121 pack(); 122 } 123 124 private void verticalGroupLayout(GroupLayout layout) { 125 layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( 126 layout.createSequentialGroup() 127 .addGap(40, 40, 40) 128 .addGroup( 129 layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(currentFontJLabel) 130 .addComponent(fontJComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(26, 26, 26) 131 .addComponent(line, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 132 .addComponent(descJlabel).addGap(18, 18, 18).addComponent(currentFontDescJLabel).addContainerGap(47, Short.MAX_VALUE))); 133 } 134 135 private void horizontalGroupLayout(GroupLayout layout) { 136 layout.setHorizontalGroup(layout 137 .createParallelGroup(GroupLayout.Alignment.LEADING) 138 .addGroup( 139 layout.createSequentialGroup() 140 .addGap(21, 21, 21) 141 .addGroup( 142 layout.createParallelGroup(GroupLayout.Alignment.LEADING) 143 .addComponent(currentFontDescJLabel) 144 .addComponent(descJlabel) 145 .addGroup( 146 layout.createSequentialGroup().addComponent(currentFontJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) 147 .addComponent(fontJComboBox, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE))) 148 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 149 .addGroup(layout.createSequentialGroup().addComponent(line, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE))); 150 } 151 }
/notepad/src/main/java/com/b510/notepad/ui/FontSizeManagerUI.java
1 package com.b510.notepad.ui; 2 3 import java.awt.Font; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.WindowAdapter; 6 import java.awt.event.WindowEvent; 7 8 import javax.swing.DefaultComboBoxModel; 9 import javax.swing.GroupLayout; 10 import javax.swing.JComboBox; 11 import javax.swing.JLabel; 12 import javax.swing.JSeparator; 13 import javax.swing.LayoutStyle; 14 15 import com.b510.notepad.common.Common; 16 import com.b510.notepad.util.FormatMenuUtil; 17 18 /** 19 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 20 * @created Nov 20, 2014 21 */ 22 public class FontSizeManagerUI extends MainUI { 23 private static final long serialVersionUID = -37011351219515242L; 24 25 private JLabel currentFontSizeDescJLabel; 26 private JLabel currentFontSizeJLabel; 27 private JLabel descJlabel; 28 private JSeparator line; 29 private JComboBoxfontSizeJComboBox; 30 31 private FormatMenuUtil format; 32 33 String fontSizes[] = {"8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"}; 34 35 public FontSizeManagerUI(String title) { 36 super(title); 37 initComponents(); 38 39 initSelf(); 40 setAlwaysOnTop(true); 41 addWindowListener(new WindowAdapter() { 42 @Override 43 public void windowClosing(WindowEvent e) { 44 FontSizeManagerUI.this.setVisible(false); 45 format.distoryFontSizeManagerUI(); 46 } 47 }); 48 } 49 50 public void initSelf() { 51 this.setVisible(true); 52 setResizable(false); 53 this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150); 54 } 55 56 private void initComponents() { 57 initElement(); 58 currentFontSizeJLabel.setText(Common.CURRENT_FONT_SIZE); 59 60 fontSizeJComboBox.setModel(new DefaultComboBoxModel (fontSizes)); 61 int i = 0; 62 for(String size : fontSizes){ 63 if(Integer.valueOf(size) == FontManagerUI.FONT_SIZE){ 64 fontSizeNum = i; 65 } 66 i++; 67 } 68 fontSizeJComboBox.setSelectedIndex(fontSizeNum); 69 fontSizeJComboBox.addActionListener(this); 70 71 descJlabel.setText(Common.DESCRIPTION_WITH_COLOR); 72 73 currentFontSizeDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE)); 74 currentFontSizeDescJLabel.setText(Common.SIMPLE); 75 pageGourpLayout(); 76 } 77 78 private void initElement() { 79 currentFontSizeJLabel = new JLabel(); 80 fontSizeJComboBox = new JComboBox (); 81 descJlabel = new JLabel(); 82 currentFontSizeDescJLabel = new JLabel(); 83 line = new JSeparator(); 84 } 85 86 @Override 87 public void actionPerformed(ActionEvent e) { 88 if (e.getSource() == fontSizeJComboBox) { 89 updateSkin(); 90 } 91 } 92 93 public synchronized void updateSkin() { 94 fontNum = fontSizeJComboBox.getSelectedIndex(); 95 log.debug(fontSizeJComboBox.getSelectedItem().toString()); 96 FontManagerUI.FONT_SIZE = Integer.valueOf((String) fontSizeJComboBox.getSelectedItem()); 97 currentFontSizeDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, Font.PLAIN, FontManagerUI.FONT_SIZE)); 98 currentFontSizeDescJLabel.setText(Common.SIMPLE); 99 textArea.setFont(new Font(FontManagerUI.FONT_TYPE, Font.PLAIN, FontManagerUI.FONT_SIZE)); 100 setJUI(); 101 } 102 103 public void setFormatMenuUtil(FormatMenuUtil formatMenuUtil){ 104 this.format = formatMenuUtil; 105 } 106 107 /** 108 * If not necessary, please do not change 109 */ 110 private void pageGourpLayout() { 111 GroupLayout layout = new GroupLayout(getContentPane()); 112 getContentPane().setLayout(layout); 113 horizontalGroupLayout(layout); 114 verticalGroupLayout(layout); 115 pack(); 116 } 117 118 private void verticalGroupLayout(GroupLayout layout) { 119 layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( 120 layout.createSequentialGroup() 121 .addGap(40, 40, 40) 122 .addGroup( 123 layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(currentFontSizeJLabel) 124 .addComponent(fontSizeJComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(26, 26, 26) 125 .addComponent(line, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 126 .addComponent(descJlabel).addGap(18, 18, 18).addComponent(currentFontSizeDescJLabel).addContainerGap(47, Short.MAX_VALUE))); 127 } 128 129 private void horizontalGroupLayout(GroupLayout layout) { 130 layout.setHorizontalGroup(layout 131 .createParallelGroup(GroupLayout.Alignment.LEADING) 132 .addGroup( 133 layout.createSequentialGroup() 134 .addGap(21, 21, 21) 135 .addGroup( 136 layout.createParallelGroup(GroupLayout.Alignment.LEADING) 137 .addComponent(currentFontSizeDescJLabel) 138 .addComponent(descJlabel) 139 .addGroup( 140 layout.createSequentialGroup().addComponent(currentFontSizeJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) 141 .addComponent(fontSizeJComboBox, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE))) 142 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 143 .addGroup(layout.createSequentialGroup().addComponent(line, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE))); 144 } 145 }
/notepad/src/main/java/com/b510/notepad/ui/FontStyleManagerUI.java
1 package com.b510.notepad.ui; 2 3 import java.awt.Font; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.WindowAdapter; 6 import java.awt.event.WindowEvent; 7 8 import javax.swing.DefaultComboBoxModel; 9 import javax.swing.GroupLayout; 10 import javax.swing.JComboBox; 11 import javax.swing.JLabel; 12 import javax.swing.JSeparator; 13 import javax.swing.LayoutStyle; 14 15 import com.b510.notepad.common.Common; 16 import com.b510.notepad.util.FormatMenuUtil; 17 18 /** 19 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 20 * @created Nov 20, 2014 21 */ 22 public class FontStyleManagerUI extends MainUI { 23 private static final long serialVersionUID = -37011351219515242L; 24 25 private JLabel currentFontStyleDescJLabel; 26 private JLabel currentFontStyleJLabel; 27 private JLabel descJlabel; 28 private JSeparator line; 29 private JComboBoxfontStyleJComboBox; 30 31 private FormatMenuUtil format; 32 33 String fontStyles[] = {"Regular", "Italic", "Bold", "Bold Italic"}; 34 35 public FontStyleManagerUI(String title) { 36 super(title); 37 initComponents(); 38 39 initSelf(); 40 setAlwaysOnTop(true); 41 addWindowListener(new WindowAdapter() { 42 @Override 43 public void windowClosing(WindowEvent e) { 44 FontStyleManagerUI.this.setVisible(false); 45 format.distoryFontSizeManagerUI(); 46 } 47 }); 48 } 49 50 public void initSelf() { 51 this.setVisible(true); 52 setResizable(false); 53 this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150); 54 } 55 56 private void initComponents() { 57 initElement(); 58 currentFontStyleJLabel.setText(Common.CURRENT_FONT_STYLE); 59 60 fontStyleJComboBox.setModel(new DefaultComboBoxModel (fontStyles)); 61 int i = 0; 62 for(String style : fontStyles){ 63 if(style.equals(FontManagerUI.FONT_STYPLE)){ 64 fontStyleNum = i; 65 } 66 i++; 67 } 68 fontStyleJComboBox.setSelectedIndex(fontStyleNum); 69 fontStyleJComboBox.addActionListener(this); 70 71 descJlabel.setText(Common.DESCRIPTION_WITH_COLOR); 72 // do here... 73 currentFontStyleDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE)); 74 currentFontStyleDescJLabel.setText(Common.SIMPLE); 75 pageGourpLayout(); 76 } 77 78 private void initElement() { 79 currentFontStyleJLabel = new JLabel(); 80 fontStyleJComboBox = new JComboBox (); 81 descJlabel = new JLabel(); 82 currentFontStyleDescJLabel = new JLabel(); 83 line = new JSeparator(); 84 } 85 86 @Override 87 public void actionPerformed(ActionEvent e) { 88 if (e.getSource() == fontStyleJComboBox) { 89 updateSkin(); 90 } 91 } 92 93 public synchronized void updateSkin() { 94 fontStyleNum = fontStyleJComboBox.getSelectedIndex(); 95 FontManagerUI.FONT_STYPLE = (String) fontStyleJComboBox.getSelectedItem(); 96 currentFontStyleDescJLabel.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE)); 97 currentFontStyleDescJLabel.setText(Common.SIMPLE); 98 textArea.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE)); 99 setJUI(); 100 } 101 102 public void setFormatMenuUtil(FormatMenuUtil formatMenuUtil){ 103 this.format = formatMenuUtil; 104 } 105 106 /** 107 * If not necessary, please do not change 108 */ 109 private void pageGourpLayout() { 110 GroupLayout layout = new GroupLayout(getContentPane()); 111 getContentPane().setLayout(layout); 112 horizontalGroupLayout(layout); 113 verticalGroupLayout(layout); 114 pack(); 115 } 116 117 private void verticalGroupLayout(GroupLayout layout) { 118 layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( 119 layout.createSequentialGroup() 120 .addGap(40, 40, 40) 121 .addGroup( 122 layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(currentFontStyleJLabel) 123 .addComponent(fontStyleJComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(26, 26, 26) 124 .addComponent(line, GroupLayout.PREFERRED_SIZE, 11, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) 125 .addComponent(descJlabel).addGap(18, 18, 18).addComponent(currentFontStyleDescJLabel).addContainerGap(47, Short.MAX_VALUE))); 126 } 127 128 private void horizontalGroupLayout(GroupLayout layout) { 129 layout.setHorizontalGroup(layout 130 .createParallelGroup(GroupLayout.Alignment.LEADING) 131 .addGroup( 132 layout.createSequentialGroup() 133 .addGap(21, 21, 21) 134 .addGroup( 135 layout.createParallelGroup(GroupLayout.Alignment.LEADING) 136 .addComponent(currentFontStyleDescJLabel) 137 .addComponent(descJlabel) 138 .addGroup( 139 layout.createSequentialGroup().addComponent(currentFontStyleJLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) 140 .addComponent(fontStyleJComboBox, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE))) 141 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 142 .addGroup(layout.createSequentialGroup().addComponent(line, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE).addGap(0, 0, Short.MAX_VALUE))); 143 } 144 }
/notepad/src/main/java/com/b510/notepad/ui/JUI.java
1 /** 2 * 3 */ 4 package com.b510.notepad.ui; 5 6 import javax.swing.JDialog; 7 import javax.swing.JFrame; 8 import javax.swing.UIManager; 9 import javax.swing.UnsupportedLookAndFeelException; 10 11 import org.apache.log4j.Logger; 12 import org.jvnet.substance.SubstanceLookAndFeel; 13 import org.jvnet.substance.border.StandardBorderPainter; 14 import org.jvnet.substance.button.ClassicButtonShaper; 15 import org.jvnet.substance.painter.StandardGradientPainter; 16 import org.jvnet.substance.skin.AutumnSkin; 17 import org.jvnet.substance.skin.BusinessBlackSteelSkin; 18 import org.jvnet.substance.skin.ChallengerDeepSkin; 19 import org.jvnet.substance.skin.CremeCoffeeSkin; 20 import org.jvnet.substance.skin.CremeSkin; 21 import org.jvnet.substance.skin.EbonyHighContrastSkin; 22 import org.jvnet.substance.skin.EmeraldDuskSkin; 23 import org.jvnet.substance.skin.FieldOfWheatSkin; 24 import org.jvnet.substance.skin.FindingNemoSkin; 25 import org.jvnet.substance.skin.GreenMagicSkin; 26 import org.jvnet.substance.skin.MagmaSkin; 27 import org.jvnet.substance.skin.MangoSkin; 28 import org.jvnet.substance.skin.MistSilverSkin; 29 import org.jvnet.substance.skin.ModerateSkin; 30 import org.jvnet.substance.skin.NebulaBrickWallSkin; 31 import org.jvnet.substance.skin.NebulaSkin; 32 import org.jvnet.substance.skin.OfficeBlue2007Skin; 33 import org.jvnet.substance.skin.RavenGraphiteGlassSkin; 34 import org.jvnet.substance.skin.RavenGraphiteSkin; 35 import org.jvnet.substance.skin.RavenSkin; 36 import org.jvnet.substance.skin.SaharaSkin; 37 import org.jvnet.substance.skin.SubstanceAbstractSkin; 38 import org.jvnet.substance.theme.SubstanceAquaTheme; 39 import org.jvnet.substance.watermark.SubstanceBubblesWatermark; 40 41 /** 42 * The basic class extendsjava.awt.JFrame
, there are three methods provided:
43 *getSkin()
to change the frame skin.
44 * and there are 21 skins to provided. And the
45 * default skin isMagmaSkin
.You can change value to change
46 * skin if possible. and you should call the methodsetJUI()
to refresh the page when you change the value. 47 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 48 * @created Nov 19, 2014 49 */ 50 public class JUI extends JFrame { 51 52 private static final long serialVersionUID = 1L; 53 54 Logger log = Logger.getLogger(JUI.class); 55 56 static SubstanceAbstractSkin skin; 57 static int skinNum = 11; 58 String title; 59 60 /** 61 * Total skins : 21. Get the skin according to theskinNums
value, and the default skin isMagmaSkin
62 * @param numskinNum
value 63 * @return 64 */ 65 public SubstanceAbstractSkin getSkin(int num) { 66 switch (num) { 67 case 1: 68 skin = new AutumnSkin(); 69 break; 70 case 2: 71 skin = new BusinessBlackSteelSkin(); 72 break; 73 case 3: 74 skin = new ChallengerDeepSkin(); 75 break; 76 case 4: 77 skin = new CremeCoffeeSkin(); 78 break; 79 case 5: 80 skin = new CremeSkin(); 81 break; 82 case 6: 83 skin = new EbonyHighContrastSkin(); 84 break; 85 case 7: 86 skin = new EmeraldDuskSkin(); 87 break; 88 case 8: 89 skin = new FieldOfWheatSkin(); 90 break; 91 case 9: 92 skin = new FindingNemoSkin(); 93 break; 94 case 10: 95 skin = new GreenMagicSkin(); 96 break; 97 case 11: 98 skin = new MagmaSkin(); 99 break; 100 case 12: 101 skin = new MangoSkin(); 102 break; 103 case 13: 104 skin = new MistSilverSkin(); 105 break; 106 case 14: 107 skin = new ModerateSkin(); 108 break; 109 case 15: 110 skin = new NebulaBrickWallSkin(); 111 break; 112 case 16: 113 skin = new NebulaSkin(); 114 break; 115 case 17: 116 skin = new OfficeBlue2007Skin(); 117 break; 118 case 18: 119 skin = new RavenGraphiteGlassSkin(); 120 break; 121 case 19: 122 skin = new RavenGraphiteSkin(); 123 break; 124 case 20: 125 skin = new RavenSkin(); 126 break; 127 case 21: 128 skin = new SaharaSkin(); 129 break; 130 default: 131 skin = new FieldOfWheatSkin(); 132 break; 133 } 134 return skin; 135 } 136 137 /** 138 * Set the page UI. including the theme, skin, watermark.etc. 139 */ 140 public void setJUI() { 141 try { 142 UIManager.setLookAndFeel(new SubstanceLookAndFeel()); 143 JFrame.setDefaultLookAndFeelDecorated(true); 144 JDialog.setDefaultLookAndFeelDecorated(true); 145 SubstanceLookAndFeel.setCurrentTheme(new SubstanceAquaTheme()); 146 SubstanceLookAndFeel.setSkin(getSkin(skinNum)); 147 SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper()); 148 SubstanceLookAndFeel.setCurrentWatermark(new SubstanceBubblesWatermark()); 149 SubstanceLookAndFeel.setCurrentBorderPainter(new StandardBorderPainter()); 150 SubstanceLookAndFeel.setCurrentGradientPainter(new StandardGradientPainter()); 151 } catch (UnsupportedLookAndFeelException e1) { 152 e1.printStackTrace(); 153 } 154 } 155 156 public JUI(String title) { 157 this.title = title; 158 setJUI(); 159 } 160 161 public void init() { 162 163 } 164 }
/notepad/src/main/java/com/b510/notepad/ui/MainUI.java
1 /** 2 * 3 */ 4 package com.b510.notepad.ui; 5 6 import java.awt.Font; 7 import java.awt.Rectangle; 8 import java.awt.event.ActionEvent; 9 import java.awt.event.InputEvent; 10 import java.awt.event.MouseEvent; 11 import java.awt.event.MouseMotionListener; 12 import java.awt.event.WindowAdapter; 13 import java.awt.event.WindowEvent; 14 15 import javax.swing.JMenu; 16 import javax.swing.JMenuBar; 17 import javax.swing.JMenuItem; 18 import javax.swing.JScrollPane; 19 import javax.swing.JSeparator; 20 import javax.swing.JTextArea; 21 import javax.swing.KeyStroke; 22 import javax.swing.event.CaretEvent; 23 import javax.swing.event.CaretListener; 24 import javax.swing.event.UndoableEditEvent; 25 import javax.swing.event.UndoableEditListener; 26 import javax.swing.undo.UndoManager; 27 28 import org.apache.log4j.Logger; 29 30 import com.b510.notepad.common.Common; 31 import com.b510.notepad.util.EditMenuUtil; 32 import com.b510.notepad.util.FileMenuUtil; 33 import com.b510.notepad.util.FormatMenuUtil; 34 import com.b510.notepad.util.HelpMenuUtil; 35 import com.b510.notepad.util.NotepadUtil; 36 import com.b510.notepad.util.ViewMenuUtil; 37 38 /** 39 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 40 * @created Nov 19, 2014 41 */ 42 public class MainUI extends NotepadUI { 43 44 private static final long serialVersionUID = 1L; 45 46 static Logger log = Logger.getLogger(MainUI.class); 47 48 JMenuBar menuBar; 49 JSeparator line; 50 // Menus 51 JMenu file, edit, format, view, help, viewHelp, source; 52 // File Items 53 JMenuItem news, open, save, saveAs, properties, exit; 54 // Edit Items 55 JMenuItem undo, copy, paste, cut, find, findNext, replace, selectAll, timeDate; 56 // Format Items 57 JMenuItem wordWrap, resetFont, font, fontSize, fontStyle; 58 // View Items 59 JMenuItem skin; 60 // Help Items 61 JMenuItem about, homePage, skinPage, sourceCode, sourceCodeDownload, api; 62 // textArea 63 public static JTextArea textArea; 64 // textArea font 65 Font textAreaFont; 66 // textArea scroll 67 JScrollPane textAreaScroll; 68 69 public static UndoManager undoManager; 70 71 public static String filePath = Common.EMPTY; 72 boolean saved = false; 73 public static boolean lineWrap = true; 74 // Default position is (0, 0) 75 public static int pointX = 0; 76 public static int pointY = 0; 77 public static String savedText = Common.EMPTY; 78 public static int fontNum = Common.FONT_NUM; 79 public static int fontSizeNum = Common.FONT_SIZE_NUM; 80 public static int fontStyleNum = Common.FONT_STYLE_NUM; 81 public static String findWhat = Common.EMPTY; 82 83 private void setMainUIXY() { 84 pointX = getMainUIX(); 85 pointY = getMainUIY(); 86 } 87 88 private int getMainUIY() { 89 return (int) getLocation().getY(); 90 } 91 92 private int getMainUIX() { 93 return (int) getLocation().getX(); 94 } 95 96 public MainUI(String title) { 97 super(title); 98 setTitle(title); 99 } 100 101 public void init() { 102 initMenu(); 103 initTextArea(); 104 this.setResizable(true); 105 this.setBounds(new Rectangle(150, 100, 800, 550)); 106 this.setVisible(true); 107 addWindowListener(new WindowAdapter() { 108 public void windowClosing(WindowEvent e) { 109 FileMenuUtil file = new FileMenuUtil(Common.EMPTY); 110 file.exit(MainUI.this); 111 } 112 }); 113 114 setMainUIXY(); 115 } 116 117 private void initMenu() { 118 menuBar(); 119 menuFile(); 120 menuEdit(); 121 menuFormat(); 122 menuView(); 123 menuHelp(); 124 setJMenuBar(menuBar); 125 setDisabledMenuAtCreating(false); 126 } 127 128 private void menuBar() { 129 menuBar = new JMenuBar(); 130 } 131 132 private void menuFile() { 133 file = new JMenu(Common.FILE); 134 135 news = new JMenuItem(Common.NEW); 136 news.addActionListener(this); 137 news.setAccelerator(KeyStroke.getKeyStroke(Common.N, InputEvent.CTRL_MASK)); 138 file.add(news); 139 140 open = new JMenuItem(Common.OPEN); 141 open.addActionListener(this); 142 open.setAccelerator(KeyStroke.getKeyStroke(Common.O, InputEvent.CTRL_MASK)); 143 file.add(open); 144 145 save = new JMenuItem(Common.SAVE); 146 save.addActionListener(this); 147 save.setAccelerator(KeyStroke.getKeyStroke(Common.S, InputEvent.CTRL_MASK)); 148 file.add(save); 149 150 saveAs = new JMenuItem(Common.SAVE_AS); 151 saveAs.addActionListener(this); 152 saveAs.setAccelerator(KeyStroke.getKeyStroke(Common.S, InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK)); 153 file.add(saveAs); 154 155 line = new JSeparator(); 156 file.add(line); 157 158 properties = new JMenuItem(Common.PROPERTIES); 159 properties.addActionListener(this); 160 file.add(properties); 161 162 line = new JSeparator(); 163 file.add(line); 164 165 exit = new JMenuItem(Common.EXIT); 166 exit.addActionListener(this); 167 file.add(exit); 168 169 menuBar.add(file); 170 } 171 172 private void menuEdit() { 173 edit = new JMenu(Common.EDIT); 174 175 undo = new JMenuItem(Common.UNDO); 176 undo.addActionListener(this); 177 undo.setAccelerator(KeyStroke.getKeyStroke(Common.Z, InputEvent.CTRL_MASK)); 178 edit.add(undo); 179 180 line = new JSeparator(); 181 edit.add(line); 182 183 cut = new JMenuItem(Common.CUT); 184 cut.addActionListener(this); 185 cut.setAccelerator(KeyStroke.getKeyStroke(Common.X, InputEvent.CTRL_MASK)); 186 edit.add(cut); 187 188 copy = new JMenuItem(Common.COPY); 189 copy.addActionListener(this); 190 copy.setAccelerator(KeyStroke.getKeyStroke(Common.C, InputEvent.CTRL_MASK)); 191 edit.add(copy); 192 193 paste = new JMenuItem(Common.PASTE); 194 paste.addActionListener(this); 195 paste.setAccelerator(KeyStroke.getKeyStroke(Common.V, InputEvent.CTRL_MASK)); 196 edit.add(paste); 197 198 line = new JSeparator(); 199 edit.add(line); 200 201 find = new JMenuItem(Common.FIND); 202 find.addActionListener(this); 203 find.setAccelerator(KeyStroke.getKeyStroke(Common.F, InputEvent.CTRL_MASK)); 204 edit.add(find); 205 206 findNext = new JMenuItem(Common.FIND_NEXT); 207 findNext.addActionListener(this); 208 findNext.setAccelerator(KeyStroke.getKeyStroke(Common.F, InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK)); 209 edit.add(findNext); 210 211 replace = new JMenuItem(Common.REPLACE); 212 replace.addActionListener(this); 213 replace.setAccelerator(KeyStroke.getKeyStroke(Common.H, InputEvent.CTRL_MASK)); 214 edit.add(replace); 215 216 line = new JSeparator(); 217 edit.add(line); 218 219 selectAll = new JMenuItem(Common.SELECT_ALL); 220 selectAll.addActionListener(this); 221 selectAll.setAccelerator(KeyStroke.getKeyStroke(Common.A, InputEvent.CTRL_MASK)); 222 edit.add(selectAll); 223 224 timeDate = new JMenuItem(Common.TIME_DATE); 225 timeDate.addActionListener(this); 226 timeDate.setAccelerator(KeyStroke.getKeyStroke(Common.T, InputEvent.CTRL_MASK)); 227 edit.add(timeDate); 228 229 menuBar.add(edit); 230 } 231 232 private void menuFormat() { 233 format = new JMenu(Common.FORMAT); 234 235 wordWrap = new JMenuItem(Common.WORD_WRAP); 236 wordWrap.addActionListener(this); 237 wordWrap.setAccelerator(KeyStroke.getKeyStroke(Common.W, InputEvent.CTRL_MASK)); 238 format.add(wordWrap); 239 240 resetFont = new JMenuItem(Common.RESET_FONT); 241 resetFont.addActionListener(this); 242 format.add(resetFont); 243 244 line = new JSeparator(); 245 format.add(line); 246 247 font = new JMenuItem(Common.FONT); 248 font.addActionListener(this); 249 format.add(font); 250 251 fontSize = new JMenuItem(Common.FONT_SIZE_TITLE); 252 fontSize.addActionListener(this); 253 format.add(fontSize); 254 255 fontStyle = new JMenuItem(Common.FONT_STYLE); 256 fontStyle.addActionListener(this); 257 format.add(fontStyle); 258 259 menuBar.add(format); 260 } 261 262 private void menuView() { 263 view = new JMenu(Common.VIEW); 264 265 skin = new JMenuItem(Common.SKIN); 266 skin.addActionListener(this); 267 view.add(skin); 268 269 menuBar.add(view); 270 } 271 272 private void menuHelp() { 273 help = new JMenu(Common.Help); 274 275 viewHelp = new JMenu(Common.VIEW_HELP); 276 help.add(viewHelp); 277 278 homePage = new JMenuItem(Common.NOTEPAD_HOME_PAGE); 279 homePage.addActionListener(this); 280 viewHelp.add(homePage); 281 282 skinPage = new JMenuItem(Common.NOTEPAD_SKINS); 283 skinPage.addActionListener(this); 284 viewHelp.add(skinPage); 285 286 source = new JMenu(Common.SOURCE); 287 viewHelp.add(source); 288 289 sourceCode = new JMenuItem(Common.SOURCE_CODE); 290 sourceCode.addActionListener(this); 291 source.add(sourceCode); 292 293 sourceCodeDownload = new JMenuItem(Common.SOURCE_CODE_DOWNLOAD); 294 sourceCodeDownload.addActionListener(this); 295 source.add(sourceCodeDownload); 296 297 api = new JMenuItem(Common.NOTEPAD_API); 298 api.addActionListener(this); 299 viewHelp.add(api); 300 301 line = new JSeparator(); 302 help.add(line); 303 304 about = new JMenuItem(Common.ABOUT_NOTEPAD); 305 about.addActionListener(this); 306 help.add(about); 307 308 menuBar.add(help); 309 } 310 311 private void initUndoManager(){ 312 undoManager = new UndoManager(); 313 } 314 315 private void setDisabledMenuAtCreating(boolean b){ 316 undo.setEnabled(b); 317 cut.setEnabled(b); 318 copy.setEnabled(b); 319 find.setEnabled(b); 320 findNext.setEnabled(b); 321 } 322 323 private void setDisabledMenuAtSelecting(boolean b){ 324 cut.setEnabled(b); 325 copy.setEnabled(b); 326 } 327 328 private void initTextArea() { 329 textArea = new JTextArea(Common.EMPTY); 330 textArea.setLineWrap(true); 331 lineWrap = true; 332 textAreaFont = new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE); 333 textArea.setFont(textAreaFont); 334 initUndoManager(); 335 // add Undoable edit listener 336 textArea.getDocument().addUndoableEditListener(new UndoableEditListener() { 337 public void undoableEditHappened(UndoableEditEvent e) { 338 undoManager.addEdit(e.getEdit()); 339 } 340 }); 341 // add caret listener 342 textArea.addCaretListener(new CaretListener() { 343 public void caretUpdate(CaretEvent e) { 344 if (null != savedText && null != textArea.getText()) { 345 if (savedText.equals(textArea.getText())) { 346 setSaved(true); 347 } else { 348 setSaved(false); 349 } 350 } 351 textArea.setFocusable(true); 352 setDisabledMenuAtCreating(true); 353 } 354 }); 355 // add mouse motion listener 356 textArea.addMouseMotionListener(new MouseMotionListener() { 357 public void mouseMoved(MouseEvent e) { 358 isSelectedText(); 359 } 360 361 public void mouseDragged(MouseEvent e) { 362 isSelectedText(); 363 } 364 365 }); 366 textAreaScroll = new JScrollPane(textArea); 367 this.add(textAreaScroll); 368 } 369 370 private void isSelectedText() { 371 textArea.setFocusable(true); 372 String selectText = textArea.getSelectedText(); 373 if(null != selectText){ 374 setDisabledMenuAtSelecting(true); 375 }else{ 376 setDisabledMenuAtSelecting(false); 377 } 378 } 379 380 public void actionPerformed(ActionEvent e) { 381 actionForFileItem(e); 382 actionForEditItem(e); 383 actionForFormatItem(e); 384 actionForViewItem(e); 385 actionForHelpItem(e); 386 } 387 388 private void actionForFileItem(ActionEvent e) { 389 if (e.getSource() == news) { 390 FileMenuUtil.news(MainUI.this); 391 } else if (e.getSource() == open) { 392 FileMenuUtil file = new FileMenuUtil(Common.EMPTY); 393 file.open(MainUI.this); 394 } else if (e.getSource() == save) { 395 FileMenuUtil.save(MainUI.this); 396 } else if (e.getSource() == saveAs) { 397 FileMenuUtil.saveAs(MainUI.this); 398 } else if (e.getSource() == properties) { 399 FileMenuUtil file = new FileMenuUtil(Common.EMPTY); 400 file.readProperties(MainUI.this); 401 } else if (e.getSource() == exit) { 402 FileMenuUtil file = new FileMenuUtil(Common.EMPTY); 403 file.exit(MainUI.this); 404 } 405 } 406 407 private void actionForEditItem(ActionEvent e) { 408 if (e.getSource() == undo) { 409 EditMenuUtil.undo(); 410 } else if (e.getSource() == copy) { 411 EditMenuUtil.copy(); 412 } else if (e.getSource() == paste) { 413 EditMenuUtil.paste(); 414 } else if (e.getSource() == cut) { 415 EditMenuUtil.cut(); 416 } else if (e.getSource() == find) { 417 setMainUIXY(); 418 EditMenuUtil edit = new EditMenuUtil(Common.EMPTY); 419 edit.find(); 420 } else if (e.getSource() == findNext) { 421 EditMenuUtil edit = new EditMenuUtil(Common.EMPTY); 422 edit.findNext(); 423 } else if (e.getSource() == replace) { 424 setMainUIXY(); 425 EditMenuUtil edit = new EditMenuUtil(Common.EMPTY); 426 edit.replace(); 427 } else if (e.getSource() == selectAll) { 428 EditMenuUtil.selectAll(); 429 } else if (e.getSource() == timeDate) { 430 EditMenuUtil.timeDate(); 431 } 432 } 433 434 private void actionForFormatItem(ActionEvent e) { 435 if (e.getSource() == wordWrap) { 436 FormatMenuUtil.wordWrap(); 437 } else if(e.getSource() == resetFont){ 438 FormatMenuUtil format = new FormatMenuUtil(Common.EMPTY); 439 format.resetFont(MainUI.this); 440 }else if (e.getSource() == font) { 441 setMainUIXY(); 442 FormatMenuUtil format = new FormatMenuUtil(Common.EMPTY); 443 format.font(MainUI.this); 444 } else if (e.getSource() == fontSize) { 445 setMainUIXY(); 446 FormatMenuUtil format = new FormatMenuUtil(Common.EMPTY); 447 format.fontSize(MainUI.this); 448 }else if(e.getSource() == fontStyle){ 449 setMainUIXY(); 450 FormatMenuUtil format = new FormatMenuUtil(Common.EMPTY); 451 format.fontStyle(MainUI.this); 452 } 453 } 454 455 private void actionForViewItem(ActionEvent e) { 456 if (e.getSource() == skin) { 457 setMainUIXY(); 458 ViewMenuUtil view = new ViewMenuUtil(Common.EMPTY); 459 view.skin(MainUI.this); 460 } 461 } 462 463 private void actionForHelpItem(ActionEvent e) { 464 if (e.getSource() == homePage) { 465 log.debug(Common.NOTEPAD_HOME_PAGE); 466 NotepadUtil.accessURL(Common.NOTEPAD_PUBLISHED_PAGE); 467 } else if(e.getSource() == skinPage){ 468 log.debug(Common.NOTEPAD_SKINS); 469 NotepadUtil.accessURL(Common.NOTEPAD_SUBSTANCE_SKINS_PAGE); 470 }else if(e.getSource() == sourceCode){ 471 log.debug(Common.SOURCE_CODE); 472 NotepadUtil.accessURL(Common.NOTEPAD_PUBLISHED_BOOKMARK_PAGE + Common.SOURCE_CODE_BOOKMARK); 473 }else if(e.getSource() == sourceCodeDownload){ 474 log.debug(Common.SOURCE_CODE_DOWNLOAD); 475 NotepadUtil.accessURL(Common.NOTEPAD_PUBLISHED_BOOKMARK_PAGE + Common.SOURCE_CODE_DOWNLOAD_BOOKMARK); 476 }else if(e.getSource() == api){ 477 log.debug(Common.NOTEPAD_API); 478 NotepadUtil.accessURL(Common.NOTEPAD_PUBLISHED_BOOKMARK_PAGE + Common.NOTEPAD_API_BOOKMARK); 479 }else if (e.getSource() == about) { 480 setMainUIXY(); 481 HelpMenuUtil help = new HelpMenuUtil(Common.EMPTY); 482 help.about(MainUI.this); 483 } 484 } 485 486 public boolean isSaved() { 487 return saved; 488 } 489 490 public void setSaved(boolean saved) { 491 this.saved = saved; 492 } 493 }
/notepad/src/main/java/com/b510/notepad/ui/NotepadUI.java
1 /** 2 * 3 */ 4 package com.b510.notepad.ui; 5 6 import java.awt.event.ActionEvent; 7 import java.awt.event.ActionListener; 8 9 /** 10 * TheNotepadUI
class extendsJUI
and implements 11 *ActionListener
. 12 * 13 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 14 * @created Nov 19, 2014 15 */ 16 public class NotepadUI extends JUI implements ActionListener { 17 18 private static final long serialVersionUID = 1L; 19 20 private MainUI mainUI; 21 22 public NotepadUI(String title) { 23 super(title); 24 } 25 26 public void init() { 27 if (null == mainUI) { 28 mainUI = new MainUI(title); 29 } 30 mainUI.init(); 31 } 32 33 public void actionPerformed(ActionEvent e) { 34 } 35 }
/notepad/src/main/java/com/b510/notepad/ui/ReplaceManagerUI.java
1 package com.b510.notepad.ui; 2 3 import java.awt.Dimension; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.WindowAdapter; 6 import java.awt.event.WindowEvent; 7 8 import javax.swing.GroupLayout; 9 import javax.swing.JButton; 10 import javax.swing.JCheckBox; 11 import javax.swing.JLabel; 12 import javax.swing.JOptionPane; 13 import javax.swing.JPanel; 14 import javax.swing.JTextField; 15 import javax.swing.LayoutStyle; 16 17 import org.apache.log4j.Logger; 18 19 import com.b510.notepad.common.Common; 20 import com.b510.notepad.util.EditMenuUtil; 21 22 public class ReplaceManagerUI extends MainUI { 23 private static final long serialVersionUID = 1L; 24 25 static Logger log = Logger.getLogger(ReplaceManagerUI.class); 26 27 private JPanel bGJPanel; 28 private JButton cancelJButton; 29 private JCheckBox caseSensitiveJCheckBox; 30 private JButton findNextJButton; 31 private JLabel findWhatJLabel; 32 private JTextField findWordJTextField; 33 private JButton replaceAllJButton; 34 private JLabel replaceToJLabel; 35 private JTextField replaceToJTextField; 36 private JButton replaceJButton; 37 38 public static boolean isCaseSensitive = false; 39 40 private EditMenuUtil edit; 41 public static String replaceWord = Common.EMPTY; 42 public static int replaceCount = 0; 43 44 public ReplaceManagerUI(String title) { 45 super(title); 46 initComponents(); 47 48 initSelf(); 49 setAlwaysOnTop(true); 50 addWindowListener(new WindowAdapter() { 51 @Override 52 public void windowClosing(WindowEvent e) { 53 distoryReplaceManagerUI(); 54 } 55 }); 56 } 57 58 public void initSelf() { 59 this.setVisible(true); 60 setResizable(false); 61 this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150); 62 } 63 64 /** 65 * If not necessary, please do not change the order. 66 */ 67 private void initComponents() { 68 initElement(); 69 initLabel(); 70 initFindWordTextField(); 71 initReplaceToTextField(); 72 initCaseSensitiveCheckBox(); 73 initFindNextButton(); 74 initReplaceButton(); 75 initReplaceAllButton(); 76 initCancleButton(); 77 initLayout(); 78 } 79 80 private void initElement() { 81 bGJPanel = new JPanel(); 82 findWhatJLabel = new JLabel(); 83 replaceToJLabel = new JLabel(); 84 findWordJTextField = new JTextField(); 85 replaceToJTextField = new JTextField(); 86 caseSensitiveJCheckBox = new JCheckBox(); 87 findNextJButton = new JButton(); 88 replaceJButton = new JButton(); 89 replaceAllJButton = new JButton(); 90 cancelJButton = new JButton(); 91 } 92 93 private void initLabel() { 94 findWhatJLabel.setText(Common.FIND_WHAT); 95 replaceToJLabel.setText(Common.REPLACE_TO); 96 } 97 98 private void initFindWordTextField() { 99 if (null == textArea.getSelectedText() || Common.EMPTY.equals(textArea.getSelectedText().trim())) { 100 findWordJTextField.setText(findWhat); 101 } else if(null != textArea.getSelectedText() && !Common.EMPTY.equals(textArea.getSelectedText().trim())){ 102 findWordJTextField.setText(textArea.getSelectedText()); 103 }else{ 104 findWordJTextField.setText(findWhat); 105 } 106 } 107 108 private void initReplaceToTextField() { 109 replaceToJTextField.setText(Common.EMPTY); 110 } 111 112 private void initCaseSensitiveCheckBox() { 113 caseSensitiveJCheckBox.setText(Common.CASE_SENSITIVE); 114 caseSensitiveJCheckBox.addActionListener(this); 115 } 116 117 private void initFindNextButton() { 118 findNextJButton.setText(Common.FIND_NEXT); 119 findNextJButton.setMaximumSize(new Dimension(99, 23)); 120 findNextJButton.setMinimumSize(new Dimension(99, 23)); 121 findNextJButton.setPreferredSize(new Dimension(99, 23)); 122 findNextJButton.addActionListener(this); 123 } 124 125 private void initReplaceButton() { 126 replaceJButton.setText(Common.REPLACE); 127 replaceJButton.setMaximumSize(new Dimension(99, 23)); 128 replaceJButton.setMinimumSize(new Dimension(99, 23)); 129 replaceJButton.setPreferredSize(new Dimension(99, 23)); 130 replaceJButton.addActionListener(this); 131 } 132 133 private void initReplaceAllButton() { 134 replaceAllJButton.setText(Common.REPLACE_ALL); 135 replaceAllJButton.addActionListener(this); 136 } 137 138 private void initCancleButton() { 139 cancelJButton.setText(Common.CANCEL); 140 cancelJButton.setMaximumSize(new Dimension(99, 23)); 141 cancelJButton.setMinimumSize(new Dimension(99, 23)); 142 cancelJButton.setPreferredSize(new Dimension(99, 23)); 143 cancelJButton.addActionListener(this); 144 } 145 146 public void actionPerformed(ActionEvent e) { 147 if (e.getSource() == findNextJButton) { 148 if(!isEmptyForFindWordJTextField()){ 149 edit.findNext(); 150 }else{ 151 typingFindWhat(); 152 } 153 } else if (e.getSource() == replaceAllJButton) { 154 if(!isEmptyForFindWordJTextField()){ 155 edit.replaceAllOperation(); 156 }else{ 157 typingFindWhat(); 158 } 159 } else if (e.getSource() == replaceJButton) { 160 if(!isEmptyForFindWordJTextField()){ 161 edit.replaceOperation(); 162 }else{ 163 typingFindWhat(); 164 } 165 } else if (e.getSource() == cancelJButton) { 166 distoryReplaceManagerUI(); 167 } else if (e.getSource() == caseSensitiveJCheckBox) { 168 caseSensitiveSwitch(); 169 } 170 } 171 172 private void typingFindWhat() { 173 JOptionPane.showMessageDialog(ReplaceManagerUI.this, Common.WHAT_DO_YOU_WANT_TO_FIND, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE); 174 findWordJTextField.setFocusable(true); 175 } 176 177 private boolean isEmptyForFindWordJTextField(){ 178 findWhat = findWordJTextField.getText(); 179 replaceWord = replaceToJTextField.getText(); 180 if(!Common.EMPTY.equals(findWordJTextField.getText())){ 181 return false; 182 }else{ 183 return true; 184 } 185 } 186 187 /** 188 * Operation for Cancel button 189 */ 190 private void distoryReplaceManagerUI() { 191 ReplaceManagerUI.this.setVisible(false); 192 edit.distoryReplaceeManagerUI(); 193 } 194 195 /** 196 * Case Sensitive Switch 197 */ 198 private void caseSensitiveSwitch() { 199 if (null == caseSensitiveJCheckBox.getSelectedObjects()) { 200 isCaseSensitive = false; 201 } else { 202 isCaseSensitive = true; 203 } 204 log.debug(isCaseSensitive); 205 } 206 207 public void setEditMenuUtil(EditMenuUtil editMenuUtil) { 208 this.edit = editMenuUtil; 209 } 210 211 /** 212 * If not necessary, please do not change. 213 */ 214 private void initLayout() { 215 GroupLayout bGJPanelLayout = new GroupLayout(bGJPanel); 216 bGJPanel.setLayout(bGJPanelLayout); 217 bGJPanelLayout.setHorizontalGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( 218 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())); 219 bGJPanelLayout.setVerticalGroup(bGJPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( 220 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) 221 .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))); 222 223 GroupLayout layout = new GroupLayout(getContentPane()); 224 getContentPane().setLayout(layout); 225 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))); 226 layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(bGJPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addContainerGap())); 227 228 pack(); 229 } 230 }
/notepad/src/main/java/com/b510/notepad/ui/SkinManagerUI.java
1 package com.b510.notepad.ui; 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.MouseEvent; 5 import java.awt.event.MouseListener; 6 import java.awt.event.WindowAdapter; 7 import java.awt.event.WindowEvent; 8 import java.io.IOException; 9 10 import javax.swing.DefaultComboBoxModel; 11 import javax.swing.GroupLayout; 12 import javax.swing.JComboBox; 13 import javax.swing.JLabel; 14 import javax.swing.JSeparator; 15 import javax.swing.LayoutStyle; 16 17 import com.b510.notepad.common.Common; 18 import com.b510.notepad.util.ViewMenuUtil; 19 20 /** 21 * @author Hongten 22 * @created Nov 20, 2014 23 */ 24 public class SkinManagerUI extends MainUI { 25 private static final long serialVersionUID = 1L; 26 27 private JLabel currentSkinDescJLabel; 28 private JLabel currentSkinJLabel; 29 private JLabel descJlabel; 30 private JSeparator line; 31 private JComboBoxsinkJComboBox; 32 33 private ViewMenuUtil view; 34 35 public String[][] skins = { { "AutumnSkin", "1", "What is the AutumnSkin skin?" }, { "BusinessBlackSteelSkin", "2", "What is the BusinessBlackSteelSkin skin?" }, { "ChallengerDeepSkin", "3", "What is the ChallengerDeepSkin skin?" }, { "CremeCoffeeSkin", "4", "What is the CremeCoffeeSkin skin?" }, { "CremeSkin", "5", "What is the CremeSkin skin?" }, { "EbonyHighContrastSkin", "6", "What is the EbonyHighContrastSkin skin?" }, { "EmeraldDuskSkin", "7", "What is the EmeraldDuskSkin skin?" }, { "FieldOfWheatSkin", "8", "What is the FieldOfWheatSkin skin?" }, { "FindingNemoSkin", "9", "What is the FindingNemoSkin skin?" }, { "GreenMagicSkin", "10", "What is the GreenMagicSkin skin?" }, { "MagmaSkin", "11", "What is the MagmaSkin skin?" }, { "MangoSkin", "12", "What is the MangoSkin skin?" }, { "MistSilverSkin", "13", "What is the MistSilverSkin skin?" }, 36 { "ModerateSkin", "14", "What is the ModerateSkin skin?" }, { "NebulaBrickWallSkin", "15", "What is the NebulaBrickWallSkin skin?" }, { "NebulaSkin", "16", "What is the NebulaSkin skin?" }, { "OfficeBlue2007Skin", "17", "What is the OfficeBlue2007Skin skin?" }, { "RavenGraphiteGlassSkin", "18", "What is the RavenGraphiteGlassSkin skin?" }, { "RavenGraphiteSkin", "19", "What is the RavenGraphiteSkin skin?" }, { "RavenSkin", "20", "What is the RavenSkin skin?" }, { "SaharaSkin", "21", "What is the SaharaSkin skin?" } }; 37 38 private String[] skinNames() { 39 String[] os = new String[skins.length]; 40 for (int i = 0; i < skins.length; i++) { 41 os[i] = skins[i][0]; 42 } 43 return os; 44 } 45 46 private Object[] getSkinDetails(Object obj) { 47 for (int i = 0; i < skins.length; i++) { 48 if (skins[i][0].equals(obj)) { 49 Object[] os = new Object[skins[i].length - 1]; 50 for (int j = 0; j < os.length; j++) { 51 os[j] = skins[i][j + 1]; 52 } 53 return os; 54 } 55 } 56 return new Object[] {}; 57 } 58 59 public SkinManagerUI(String title) { 60 super(title); 61 initComponents(); 62 63 initSelf(); 64 setAlwaysOnTop(true); 65 addWindowListener(new WindowAdapter() { 66 @Override 67 public void windowClosing(WindowEvent e) { 68 SkinManagerUI.this.setVisible(false); 69 view.distorySkinManagerUI(); 70 } 71 }); 72 } 73 74 public void initSelf() { 75 this.setVisible(true); 76 setResizable(false); 77 this.setLocation(MainUI.pointX + 100, MainUI.pointY + 150); 78 } 79 80 private void initComponents() { 81 initElement(); 82 currentSkinJLabel.setText(Common.CURRENT_SINK); 83 84 String[] skinNames = skinNames(); 85 sinkJComboBox.setModel(new DefaultComboBoxModel (skinNames)); 86 sinkJComboBox.setSelectedIndex(skinNum - 1); 87 sinkJComboBox.addActionListener(this); 88 89 descJlabel.setText(Common.DESCRIPTION_WITH_COLOR); 90 91 currentSkinDescJLabel.setText(skins[skinNum][2]); 92 currentSkinDescJLabel.addMouseListener(new MouseListener() { 93 public void mouseClicked(MouseEvent e) { 94 try { 95 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + Common.SUBSTANCE_SKINS_PAGE + sinkJComboBox.getSelectedItem()); 96 } catch (IOException e1) { 97 e1.printStackTrace(); 98 } 99 } 100 101 public void mousePressed(MouseEvent e) { 102 103 } 104 105 public void mouseReleased(MouseEvent e) { 106 107 } 108 109 public void mouseEntered(MouseEvent e) { 110 111 } 112 113 public void mouseExited(MouseEvent e) { 114 115 } 116 }); 117 pageGourpLayout(); 118 } 119 120 private void initElement() { 121 currentSkinJLabel = new JLabel(); 122 sinkJComboBox = new JComboBox (); 123 descJlabel = new JLabel(); 124 currentSkinDescJLabel = new JLabel(); 125 line = new JSeparator(); 126 } 127 128 @Override 129 public void actionPerformed(ActionEvent e) { 130 if (e.getSource() == sinkJComboBox) { 131 updateSkin(); 132 } 133 } 134 135 public synchronized void updateSkin() { 136 Object[] os = getSkinDetails(sinkJComboBox.getSelectedItem()); 137 String index = (String) os[0]; 138 String desc = (String) os[1]; 139 skinNum = Integer.valueOf(index); 140 currentSkinDescJLabel.setText(desc); 141 setJUI(); 142 } 143 144 public void setViewMenuUtil(ViewMenuUtil viewMenuUtil) { 145 this.view = viewMenuUtil; 146 } 147 148 /** 149 * If not necessary, please do not change 150 */ 151 private void pageGourpLayout() { 152 GroupLayout layout = new GroupLayout(getContentPane()); 153 getContentPane().setLayout(layout); 154 horizontalGroupLayout(layout); 155 verticalGroupLayout(layout); 156 pack(); 157 } 158 159 private void verticalGroupLayout(GroupLayout layout) { 160 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))); 161 } 162 163 private void horizontalGroupLayout(GroupLayout layout) { 164 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))); 165 } 166 }
/notepad/src/main/java/com/b510/notepad/util/EditMenuUtil.java
1 /** 2 * 3 */ 4 package com.b510.notepad.util; 5 6 import javax.swing.JOptionPane; 7 8 import org.apache.log4j.Logger; 9 10 import com.b510.notepad.common.Common; 11 import com.b510.notepad.ui.FindManagerUI; 12 import com.b510.notepad.ui.MainUI; 13 import com.b510.notepad.ui.ReplaceManagerUI; 14 15 /** 16 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 17 * @created Nov 19, 2014 18 */ 19 public class EditMenuUtil extends MainUI { 20 21 private static final long serialVersionUID = 1L; 22 23 static Logger log = Logger.getLogger(EditMenuUtil.class); 24 25 private static FindManagerUI findManagerUI; 26 private static ReplaceManagerUI replaceeManagerUI; 27 28 public EditMenuUtil(String title) { 29 super(title); 30 } 31 32 public static void undo() { 33 log.debug(Common.UNDO); 34 if(undoManager.canUndo()){ 35 undoManager.undo(); 36 } 37 } 38 39 public static void copy() { 40 log.debug(Common.COPY); 41 textArea.copy(); 42 } 43 44 public static void paste() { 45 log.debug(Common.PASTE); 46 textArea.paste(); 47 } 48 49 public static void cut() { 50 log.debug(Common.CUT); 51 textArea.cut(); 52 } 53 54 /** 55 * Showing theFindManagerUI
window. 56 */ 57 public void find() { 58 log.debug(Common.FIND); 59 if (null == findManagerUI) { 60 findManagerUI = new FindManagerUI(Common.FIND); 61 findManagerUI.setEditMenuUtil(EditMenuUtil.this); 62 } else { 63 findManagerUI.setVisible(true); 64 findManagerUI.setFocusable(true); 65 } 66 } 67 68 /** 69 * The directory : isForward(true : Forward and false : Backward)
70 * The Case Sensitive : isCaseSensitive(true : Case Sensitive and false : Not Case Sensitive) 71 */ 72 public void findNext() { 73 log.debug(Common.FIND_NEXT); 74 if (Common.EMPTY.equals(findWhat)) { 75 JOptionPane.showMessageDialog(EditMenuUtil.this, Common.WHAT_DO_YOU_WANT_TO_FIND, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE); 76 } else if (findWhat.length() > textArea.getText().length()) { 77 canNotFindKeyWord(); 78 } else { 79 String content = textArea.getText(); 80 String temp = Common.EMPTY; 81 int position = textArea.getSelectionEnd() - findWhat.length() + 1; 82 if (FindManagerUI.isForward) { 83 if(position > content.length() - findWhat.length()){ 84 canNotFindKeyWordOperation(content.length(), content.length()); 85 } 86 for (; position <= content.length() - findWhat.length(); position++) { 87 temp = content.substring(position, position + findWhat.length()); 88 if (FindManagerUI.isCaseSensitive) { 89 if (temp.equals(findWhat)) { 90 setTextAreaSelection(position, position + findWhat.length()); 91 break; 92 } else if (position >= content.length() - findWhat.length()) { 93 canNotFindKeyWordOperation(content.length(), content.length()); 94 break; 95 } 96 } else { 97 if (temp.equalsIgnoreCase(findWhat)) { 98 setTextAreaSelection(position, position + findWhat.length()); 99 break; 100 } else if (position >= content.length() - findWhat.length()) { 101 canNotFindKeyWordOperation(content.length(), content.length()); 102 break; 103 } 104 } 105 } 106 } else {// Backward 107 if(null != textArea.getSelectedText() && !Common.EMPTY.equals(textArea.getSelectedText().trim())){ 108 position = textArea.getSelectionStart(); 109 } 110 if(position < findWhat.length()){ 111 canNotFindKeyWordOperation(0, 0); 112 } 113 for (; position - findWhat.length() >= 0; position--) { 114 temp = content.substring(position - findWhat.length(), position); 115 if (FindManagerUI.isCaseSensitive) {//Case Sensitive 116 if (temp.equals(findWhat)) { 117 setTextAreaSelection(position - findWhat.length(), position); 118 break; 119 } else if (position - findWhat.length() == 0) { 120 canNotFindKeyWordOperation(0, 0); 121 break; 122 } 123 } else { 124 if (temp.equalsIgnoreCase(findWhat)) { 125 setTextAreaSelection(position - findWhat.length(), position); 126 break; 127 } else if (position - findWhat.length() == 0) { 128 canNotFindKeyWordOperation(0, 0); 129 break; 130 } 131 } 132 } 133 } 134 } 135 } 136 137 138 private void canNotFindKeyWordOperation(int start, int end){ 139 setTextAreaSelection(start, end); 140 canNotFindKeyWord(); 141 } 142 143 private void canNotFindKeyWord() { 144 JOptionPane.showMessageDialog(this, Common.CAN_NOT_FIND + findWhat, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE); 145 } 146 147 private void setTextAreaSelection(int start, int end){ 148 textArea.setSelectionStart(start); 149 textArea.setSelectionEnd(end); 150 } 151 152 /** 153 * Showing theReplaceManagerUI
window. 154 */ 155 public void replace() { 156 log.debug(Common.REPLACE); 157 if (null == replaceeManagerUI) { 158 replaceeManagerUI = new ReplaceManagerUI(Common.REPLACE); 159 replaceeManagerUI.setEditMenuUtil(EditMenuUtil.this); 160 } else { 161 replaceeManagerUI.setVisible(true); 162 replaceeManagerUI.setFocusable(true); 163 } 164 } 165 166 167 /** 168 * Default direction is Forward. ThereplaceOperation
method can NOT be called when
169 *null == textArea.getSelectedText();
OrCommon.EMPTY.equals(textArea.getSelectedText().trim());
170 */ 171 public void replaceOperation(){ 172 FindManagerUI.isForward = true; 173 findNext(); 174 if (null != textArea.getSelectedText() && !Common.EMPTY.equals(textArea.getSelectedText().trim())) { 175 textArea.replaceRange(ReplaceManagerUI.replaceWord, textArea.getSelectionStart(), textArea.getSelectionEnd()); 176 } 177 } 178 179 /** 180 * When user want to call Replace_All method, the application will replace all with case sensitive.
181 * A information window will display after replacing all words.
Finally, the application will set
182 *ReplaceManagerUI.replaceCount = 0;
183 */ 184 public void replaceAllOperation() { 185 String replaceWord = ReplaceManagerUI.replaceWord; 186 String content = textArea.getText(); 187 String temp; 188 for (int i = 0; i <= content.length() - findWhat.length(); i++) { 189 temp = content.substring(i, i + findWhat.length()); 190 if (ReplaceManagerUI.isCaseSensitive) { 191 if (temp.equals(findWhat)) { 192 replaceRangeOperation(findWhat, replaceWord, i); 193 } 194 } else { 195 if (temp.equalsIgnoreCase(findWhat)) { 196 replaceRangeOperation(findWhat, replaceWord, i); 197 } 198 } 199 } 200 JOptionPane.showMessageDialog(this, ReplaceManagerUI.replaceCount + Common.MATCHES_REPLACED, Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE); 201 ReplaceManagerUI.replaceCount = 0; 202 } 203 204 private void replaceRangeOperation(String findWhat, String replaceWord, int i) { 205 ReplaceManagerUI.replaceCount++; 206 textArea.setSelectionStart(i); 207 textArea.setSelectionEnd(i + findWhat.length()); 208 textArea.replaceRange(replaceWord, textArea.getSelectionStart(), textArea.getSelectionEnd()); 209 } 210 211 public static void selectAll() { 212 log.debug(Common.SELECT_ALL); 213 textArea.selectAll(); 214 } 215 216 public static void timeDate() { 217 log.debug(Common.TIME_DATE); 218 textArea.replaceRange(NotepadUtil.getTimeDate(), textArea.getSelectionStart(), textArea.getSelectionEnd()); 219 } 220 221 public void distoryFindManagerUI() { 222 if (null != findManagerUI) { 223 findManagerUI = null; 224 } 225 } 226 227 public void distoryReplaceeManagerUI() { 228 if (null != replaceeManagerUI) { 229 replaceeManagerUI = null; 230 } 231 } 232 233 }
/notepad/src/main/java/com/b510/notepad/util/FileMenuUtil.java
1 /** 2 * 3 */ 4 package com.b510.notepad.util; 5 6 import java.awt.FileDialog; 7 import java.io.BufferedReader; 8 import java.io.File; 9 import java.io.FileInputStream; 10 import java.io.FileOutputStream; 11 import java.io.InputStreamReader; 12 import java.io.OutputStreamWriter; 13 14 import javax.swing.JFileChooser; 15 import javax.swing.JOptionPane; 16 import javax.swing.filechooser.FileNameExtensionFilter; 17 18 import org.apache.log4j.Logger; 19 20 import com.b510.notepad.common.Common; 21 import com.b510.notepad.ui.MainUI; 22 23 /** 24 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 25 * @created Nov 19, 2014 26 */ 27 public class FileMenuUtil extends MainUI { 28 29 private static final long serialVersionUID = 1L; 30 31 static Logger log = Logger.getLogger(FileMenuUtil.class); 32 33 public FileMenuUtil(String title) { 34 super(title); 35 } 36 37 /** 38 * Create a new Notepad.
39 * 1. If the content of the Notepad is empty, then, create a new Notepad is 40 * itself.
41 * 2. If the content of the Notepad is NOT empty, then, we want to create a 42 * new Notepad:
43 * 2.1. If the Notepad is saved, then, create a new Notepad and let the 44 * parentsetVisible(false)
45 * 2.2. If the Notepad is NOT saved
46 * 2.2.1. If the user want to save the content, "YES",save()
, 47 * go to step 2.1
48 * 2.2.2. If the user do NOT want to save the content, "NO", clean the 49 * textArea, go to step 1
50 * 2.2.3. If the user select the "Cancel" option, nothing to do and return 51 * to textArea.
52 * 53 * @param mainUI 54 */ 55 public static void news(MainUI mainUI) { 56 log.debug(Common.NEW); 57 if (!Common.EMPTY.equals(filePath)) { 58 if (savedText.equals(textArea.getText())) { 59 createMainUI(mainUI); 60 } else { 61 confirmSave(mainUI); 62 } 63 } else { 64 if (Common.EMPTY.equals(textArea.getText())) { 65 createMainUI(mainUI); 66 } else { 67 confirmSave(mainUI); 68 } 69 } 70 } 71 72 /** 73 * @param mainUI 74 */ 75 private static void confirmSave(MainUI mainUI) { 76 int option = JOptionPane.showConfirmDialog(mainUI, Common.DO_YOU_WANT_TO_SAVE_CHANGES, Common.NOTEPAD, JOptionPane.YES_NO_CANCEL_OPTION); 77 if (option == JOptionPane.YES_OPTION) { 78 save(mainUI); 79 createMainUI(mainUI); 80 } else if (option == JOptionPane.NO_OPTION) { 81 createMainUI(mainUI); 82 } else if (option == JOptionPane.CANCEL_OPTION) { 83 textArea.setFocusable(true); 84 } 85 } 86 87 /** 88 * Open a text file:
89 * 1. If the textArea is empty, then, click the "Open" menu to open a text 90 * file.
91 * 2. If the textArea is NOT empty, then, we want to open a text file:
92 * 2.1. If the content of textArea was saved, then we click the "Open" menu 93 * to open a text file.
94 * 2.2. If the content of textArea was NOT saved. There is a dialog display.
95 * 2.2.1. Selecting "Yes" to save content, and open a text file.
96 * 2.2.2. Selecting "No", then do NOT save the content, and open a text 97 * file.
98 * 2.2.3. Selecting "Cancel", nothing to do and return to textArea.
99 * 100 * @param mainUI 101 * @see com.b510.notepad.util.FileMenuUtil#openOperation() 102 */ 103 public void open(MainUI mainUI) { 104 log.debug(Common.OPEN); 105 if (!Common.EMPTY.equals(filePath)) { 106 if (savedText.equals(textArea.getText())) { 107 openOperation(mainUI); 108 } else { 109 confirmOpen(mainUI); 110 } 111 } else { 112 if (Common.EMPTY.equals(textArea.getText())) { 113 openOperation(mainUI); 114 } else { 115 confirmOpen(mainUI); 116 } 117 } 118 } 119 120 private void confirmOpen(MainUI mainUI) { 121 int option = JOptionPane.showConfirmDialog(FileMenuUtil.this, Common.DO_YOU_WANT_TO_SAVE_CHANGES, Common.CONFIM_EXIT, JOptionPane.YES_NO_CANCEL_OPTION); 122 if (option == JOptionPane.YES_OPTION) { 123 save(mainUI); 124 openOperation(mainUI); 125 } else if (option == JOptionPane.NO_OPTION) { 126 openOperation(mainUI); 127 } else if (option == JOptionPane.CANCEL_OPTION) { 128 textArea.setFocusable(true); 129 } 130 } 131 132 /** 133 * The operation of the open
134 * When the user want to open a TXT file, this method will be called.
135 * 136 * @param mainUI 137 * @see com.b510.notepad.util.FileMenuUtil#open() 138 */ 139 private static void openOperation(MainUI mainUI) { 140 String path; 141 JFileChooser chooser = new JFileChooser(); 142 FileNameExtensionFilter filter; 143 filter = new FileNameExtensionFilter(Common.TXT_FILE, Common.TXT); 144 chooser.setFileFilter(filter); 145 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 146 chooser.setDialogTitle(Common.OPEN); 147 int ret = chooser.showOpenDialog(null); 148 if (ret == JFileChooser.APPROVE_OPTION) { 149 path = chooser.getSelectedFile().getAbsolutePath(); 150 String name = chooser.getSelectedFile().getName(); 151 try { 152 BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), Common.GB2312)); 153 StringBuffer buffer = new StringBuffer(); 154 String line = null; 155 while ((line = reader.readLine()) != null) { 156 buffer.append(line).append(Common.NEW_LINE); 157 } 158 reader.close(); 159 textArea.setText(String.valueOf(buffer)); 160 mainUI.setTitle(name + Common.NOTEPAD_NOTEPAD); 161 savedText = textArea.getText(); 162 mainUI.setSaved(true); 163 filePath = path; 164 } catch (Exception e) { 165 e.printStackTrace(); 166 } 167 } 168 } 169 170 /** 171 * Saving a TXT file.
172 * 1. If the user want to create a new TXT file, and type the content(empty 173 * is allowed) to save. In this case, a dialog will display.
174 * 2. If the user want to save a existing file. then call 175 *save()
method to save content.
176 * 3. A existing file with some changes, then the user want to save it. The 177 * operation as same as step 2.
178 * 179 * @param mainUI 180 */ 181 public static void save(MainUI mainUI) { 182 log.debug(Common.SAVE); 183 try { 184 if (null != filePath && !Common.EMPTY.equals(filePath)) { 185 OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(filePath)); 186 out.write(textArea.getText()); 187 out.close(); 188 mainUI.setSaved(true); 189 savedText = textArea.getText(); 190 } else { 191 FileDialog fileDialog = new FileDialog(mainUI, Common.SAVE, FileDialog.SAVE); 192 fileDialog.setVisible(true); 193 if (fileDialog.getDirectory() != null && fileDialog.getFile() != null) { 194 String fileName = fileDialog.getFile(); 195 if (!Common.TXT.equalsIgnoreCase(NotepadUtil.getPostfix(fileName))) { 196 fileName = fileName + Common.POINT + Common.TXT; 197 } 198 String path = fileDialog.getDirectory() + fileName; 199 OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path)); 200 out.write(textArea.getText()); 201 out.close(); 202 mainUI.setTitle(fileName + Common.NOTEPAD_NOTEPAD); 203 filePath = path; 204 mainUI.setSaved(true); 205 savedText = textArea.getText(); 206 } 207 } 208 } catch (Exception e) { 209 log.debug(e); 210 } 211 } 212 213 public static void saveAs(MainUI mainUI) { 214 log.debug(Common.SAVE_AS); 215 String path = filePath; 216 filePath = Common.EMPTY; 217 save(mainUI); 218 if (Common.EMPTY.equals(filePath)) { 219 filePath = path; 220 } 221 } 222 223 public void readProperties(MainUI mainUI) { 224 log.debug(Common.PROPERTIES); 225 if (!Common.EMPTY.equals(filePath) && mainUI.isSaved()) { 226 File file = new File(filePath); 227 JOptionPane.showMessageDialog(FileMenuUtil.this, NotepadUtil.fileProperties(file), Common.NOTEPAD, JOptionPane.INFORMATION_MESSAGE); 228 } else { 229 confirmSave(mainUI); 230 } 231 } 232 233 public void exit(MainUI mainUI) { 234 log.debug(Common.EXIT); 235 if (!Common.EMPTY.equals(filePath)) { 236 if (savedText.equals(textArea.getText())) { 237 NotepadUtil.exit(); 238 } else { 239 confirmExit(mainUI); 240 } 241 } else { 242 if (Common.EMPTY.equals(textArea.getText())) { 243 NotepadUtil.exit(); 244 } else { 245 confirmExit(mainUI); 246 } 247 } 248 } 249 250 private void confirmExit(MainUI mainUI) { 251 int option = JOptionPane.showConfirmDialog(FileMenuUtil.this, Common.DO_YOU_WANT_TO_SAVE_CHANGES, Common.CONFIM_EXIT, JOptionPane.YES_NO_CANCEL_OPTION); 252 if (option == JOptionPane.YES_OPTION) { 253 save(mainUI); 254 NotepadUtil.exit(); 255 } else if (option == JOptionPane.NO_OPTION) { 256 NotepadUtil.exit(); 257 } else if (option == JOptionPane.CANCEL_OPTION) { 258 textArea.setFocusable(true); 259 } 260 } 261 262 private static void createMainUI(MainUI mainUI) { 263 mainUI.setTitle(Common.UNTITLE + Common.NOTEPAD_NOTEPAD); 264 textArea.setText(Common.EMPTY); 265 filePath = Common.EMPTY; 266 savedText = Common.EMPTY; 267 mainUI.setSaved(false); 268 } 269 270 }
/notepad/src/main/java/com/b510/notepad/util/FormatMenuUtil.java
1 /** 2 * 3 */ 4 package com.b510.notepad.util; 5 6 import java.awt.Font; 7 8 import org.apache.log4j.Logger; 9 10 import com.b510.notepad.common.Common; 11 import com.b510.notepad.ui.FontManagerUI; 12 import com.b510.notepad.ui.FontSizeManagerUI; 13 import com.b510.notepad.ui.FontStyleManagerUI; 14 import com.b510.notepad.ui.MainUI; 15 16 /** 17 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 18 * @created Nov 19, 2014 19 */ 20 public class FormatMenuUtil extends MainUI { 21 22 private static final long serialVersionUID = 1L; 23 24 static Logger log = Logger.getLogger(FormatMenuUtil.class); 25 26 private static FontManagerUI fontManagerUI; 27 private static FontSizeManagerUI fontSizeManagerUI; 28 private static FontStyleManagerUI fontStyleManagerUI; 29 30 public FormatMenuUtil(String title) { 31 super(title); 32 } 33 34 public static void wordWrap() { 35 log.debug(Common.WORD_WRAP); 36 if (lineWrap) { 37 textArea.setLineWrap(false); 38 lineWrap = false; 39 } else { 40 textArea.setLineWrap(true); 41 lineWrap = true; 42 } 43 } 44 45 public void resetFont(MainUI mainUI) { 46 log.debug(Common.RESET_FONT); 47 fontNum = Common.FONT_NUM; 48 FontManagerUI.FONT_TYPE = Common.FONT_LUCIDA_CONSOLE; 49 fontSizeNum = Common.FONT_SIZE_NUM; 50 FontManagerUI.FONT_SIZE = Common.FONT_SIZE; 51 FontManagerUI.FONT_STYPLE = Common.FONT_STYLE_DEFAULT; 52 fontStyleNum = Common.FONT_STYLE_NUM; 53 textArea.setFont(new Font(FontManagerUI.FONT_TYPE, fontStyleNum, FontManagerUI.FONT_SIZE)); 54 setJUI(); 55 } 56 57 public void font(MainUI mainUI) { 58 log.debug(Common.FONT); 59 if (null == fontManagerUI) { 60 fontManagerUI = new FontManagerUI(Common.FONT); 61 fontManagerUI.setFormatMenuUtil(FormatMenuUtil.this); 62 } else { 63 fontManagerUI.setVisible(true); 64 fontManagerUI.setFocusable(true); 65 } 66 } 67 68 public void fontSize(MainUI mainUI) { 69 log.debug(Common.FONT_SIZE_TITLE); 70 if (null == fontSizeManagerUI) { 71 fontSizeManagerUI = new FontSizeManagerUI(Common.FONT); 72 fontSizeManagerUI.setFormatMenuUtil(FormatMenuUtil.this); 73 } else { 74 fontSizeManagerUI.setVisible(true); 75 fontSizeManagerUI.setFocusable(true); 76 } 77 } 78 79 public void fontStyle(MainUI mainUI) { 80 log.debug(Common.FONT_SIZE_TITLE); 81 if (null == fontStyleManagerUI) { 82 fontStyleManagerUI = new FontStyleManagerUI(Common.FONT_STYLE); 83 fontStyleManagerUI.setFormatMenuUtil(FormatMenuUtil.this); 84 } else { 85 fontStyleManagerUI.setVisible(true); 86 fontStyleManagerUI.setFocusable(true); 87 } 88 } 89 90 public void distoryFontManagerUI() { 91 if (null != fontManagerUI) { 92 fontManagerUI = null; 93 } 94 } 95 96 public void distoryFontSizeManagerUI() { 97 if (null != fontSizeManagerUI) { 98 fontSizeManagerUI = null; 99 } 100 } 101 102 public void distoryFontStyleManagerUI() { 103 if (null != fontSizeManagerUI) { 104 fontSizeManagerUI = null; 105 } 106 } 107 }
/notepad/src/main/java/com/b510/notepad/util/HelpMenuUtil.java
1 /** 2 * 3 */ 4 package com.b510.notepad.util; 5 6 import org.apache.log4j.Logger; 7 8 import com.b510.notepad.common.Common; 9 import com.b510.notepad.ui.AboutUI; 10 import com.b510.notepad.ui.MainUI; 11 12 /** 13 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 14 * @created Nov 19, 2014 15 */ 16 public class HelpMenuUtil extends MainUI { 17 18 private static final long serialVersionUID = 1L; 19 20 static Logger log = Logger.getLogger(HelpMenuUtil.class); 21 22 private static AboutUI aboutUI; 23 24 public HelpMenuUtil(String title) { 25 super(title); 26 } 27 28 public void about(MainUI mainUI) { 29 log.debug(Common.ABOUT_NOTEPAD); 30 if (null == aboutUI) { 31 aboutUI = new AboutUI(Common.ABOUT_NOTEPAD); 32 aboutUI.setHelpMenuUtil(HelpMenuUtil.this); 33 } else { 34 aboutUI.setVisible(true); 35 aboutUI.setFocusable(true); 36 } 37 } 38 39 public void distoryAboutUI() { 40 if (null != aboutUI) { 41 aboutUI = null; 42 } 43 } 44 }
/notepad/src/main/java/com/b510/notepad/util/NotepadUtil.java
1 /** 2 * 3 */ 4 package com.b510.notepad.util; 5 6 import java.io.File; 7 import java.io.IOException; 8 import java.text.SimpleDateFormat; 9 import java.util.Date; 10 11 import org.apache.log4j.Logger; 12 13 import com.b510.notepad.common.Common; 14 15 /** 16 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 17 * @created Nov 19, 2014 18 */ 19 public class NotepadUtil { 20 21 static Logger log = Logger.getLogger(NotepadUtil.class); 22 23 public static void exit() { 24 log.debug(Common.SYSTEM_EXIT); 25 System.exit(0); 26 } 27 28 public static void accessURL(String url) { 29 if (null == url || Common.EMPTY.equals(url)) { 30 return; 31 } 32 try { 33 Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); 34 } catch (IOException e1) { 35 e1.printStackTrace(); 36 } 37 } 38 39 /** 40 * @return i.e. 3:49 PM 11/20/2014 41 */ 42 public static String getTimeDate(){ 43 SimpleDateFormat sdf = new SimpleDateFormat(Common.DATE_FORMAT); 44 Date date = new Date(); 45 String timeDate = sdf.format(date); 46 return timeDate; 47 } 48 49 /** 50 * @param path i.e. com/b510/resources/images/hongten.png 51 * @return i.e. png 52 */ 53 public static String getPostfix(String path) { 54 if (path == null || Common.EMPTY.equals(path.trim())) { 55 return Common.EMPTY; 56 } 57 if (path.contains(Common.POINT)) { 58 return path.substring(path.lastIndexOf(Common.POINT) + 1, path.length()); 59 } 60 return Common.EMPTY; 61 } 62 63 public static String fileProperties(File file) { 64 return "" 65 + "File Name : " + file.getName() + "
" 66 + "File Type : "+ getPostfix(file.getAbsolutePath()) +" file
" 67 + "File Size : " + file.length()/1024 +" KB
" 68 + "Modify Date : " + new SimpleDateFormat().format(file.lastModified()) + "
" 69 + "Location : " + file.getParent() + "
" 70 + "CanRead : " + file.canRead() + "
" 71 + "CanWrite : " + file.canWrite() + ""; 72 } 73 }
/notepad/src/main/java/com/b510/notepad/util/ViewMenuUtil.java
1 /** 2 * 3 */ 4 package com.b510.notepad.util; 5 6 import org.apache.log4j.Logger; 7 8 import com.b510.notepad.common.Common; 9 import com.b510.notepad.ui.MainUI; 10 import com.b510.notepad.ui.SkinManagerUI; 11 12 /** 13 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html 14 * @created Nov 19, 2014 15 */ 16 public class ViewMenuUtil extends MainUI { 17 18 private static final long serialVersionUID = 1L; 19 20 static Logger log = Logger.getLogger(ViewMenuUtil.class); 21 22 private static SkinManagerUI skinManagerUI; 23 24 public ViewMenuUtil(String title) { 25 super(title); 26 } 27 28 public void skin(MainUI mainUI) { 29 log.debug(Common.SKIN); 30 if (null == skinManagerUI) { 31 skinManagerUI = new SkinManagerUI(Common.SKIN); 32 skinManagerUI.setViewMenuUtil(ViewMenuUtil.this); 33 } else { 34 skinManagerUI.setVisible(true); 35 skinManagerUI.setFocusable(true); 36 } 37 } 38 39 public void distorySkinManagerUI() { 40 if (null != skinManagerUI) { 41 skinManagerUI = null; 42 } 43 } 44 45 }
/notepad/src/main/java/log4j.properties
1 log4j.appender.stdout=org.apache.log4j.ConsoleAppender 2 log4j.appender.stdout.Target=System.out 3 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 4 log4j.appender.stdout.layout.ConversionPattern=[Notepad] %d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c:%L - %m%n 5 6 log4j.appender.notepad=org.apache.log4j.DailyRollingFileAppender 7 log4j.appender.notepad.File=C:\\log4j\\log4j-notepad 8 log4j.appender.notepad.DatePattern='_'yyyy-MM-dd'.log' 9 log4j.appender.notepad.layout=org.apache.log4j.PatternLayout 10 log4j.appender.notepad.layout.ConversionPattern=[Notepad] %d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c:%L - %m%n 11 12 log4j.rootLogger=debug,stdout,notepad
/notepad/pom.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3 <modelVersion>4.0.0modelVersion> 4 5 <groupId>com.b510.notepadgroupId> 6 <artifactId>notepadartifactId> 7 <version>1.0version> 8 <packaging>jarpackaging> 9 10 <name>notepadname> 11 <url>http://maven.apache.orgurl> 12 13 <properties> 14 <project.build.sourceEncoding>UTF-8project.build.sourceEncoding> 15 properties> 16 17 <dependencies> 18 <dependency> 19 <groupId>junitgroupId> 20 <artifactId>junitartifactId> 21 <version>4.10version> 22 <scope>testscope> 23 dependency> 24 25 <dependency> 26 <groupId>log4jgroupId> 27 <artifactId>log4jartifactId> 28 <version>1.2.16version> 29 dependency> 30 31 32 <dependency> 33 <groupId>org.jvnet.substancegroupId> 34 <artifactId>substanceartifactId> 35 <version>1.0version> 36 dependency> 37 38 dependencies> 39 project>
=================================================
More Information About Notepad:
=================================================
Author : Hongten
E-mail : [email protected]
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
大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。
Hongten博客排名在100名以内。粉丝过千。
Hongten出品,必是精品。
E | [email protected] B | http://www.cnblogs.com/hongten
========================================================