首页 > 代码库 > My Notepad
My Notepad
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:
<dependency>
<groupId>org.jvnet.substance</groupId>
<artifactId>substance</artifactId>
<version>1.0</version>
</dependency>
2. Copy the substance-1.0.jar to your repository.
2.1.Finding the substance-1.0.jar with the path "notepad/lib/skin/substance-1.0.jar".
Copying the substance-1.0.jar file to your repository.
The default path of the repository is "${user.home}/.m2/repository/org/jvnet/substance/substance/1.0/substance-1.0.jar"
=================================================
How to run notepad project?
=================================================
Using the eclipse tool and finding the Client.java file with the path "notepad/src/main/java/com/b510/notepad/client/Client.java".
Right Click --> Run As --> Java Application
==================
Some UIs Show
==================
1. The Notepad Main UI
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.html11 * @created Nov 19, 201412 */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 = "http://www.mamicode.com/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 titles117 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<br> 29 * <p> 30 * The <code>AboutUI</code> display the information about this application.<br> 31 * <p> 32 * i.e., Author, Application Name, Application description, Version, Blog.etc.<br> 33 * <p> 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.<br> 35 * The dialog is a access URL request dialog, and you will access the URL(<a href=http://www.mamicode.com/‘http://www.cnblogs.com/hongten‘>http://www.cnblogs.com/hongten</a>) if you click ‘Yes‘.<br> 36 * <p> 37 * If you want to use this class, you should do as below:<br> 38 * <p><blockquote><pre> 39 * <code>AboutUI aboutUI = new AboutUI("About Notepad");</code> 40 * </pre></blockquote><p> 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 change176 */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 button153 */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<br>173 * <li>Forward : <code>directionOfOperation(true);</code></li>174 * <li>Backward : <code>directionOfOperation(false);</code></li>175 * @param b <code>b = true;</code> Forward is selected; <code>b = false;</code> Backward is selected.<br>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 JComboBox<String> fontJComboBox; 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<String>(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<String>(); 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 change115 */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(layout137 .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 JComboBox<String> fontSizeJComboBox; 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<String>(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<String>(); 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 change109 */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(layout131 .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 JComboBox<String> fontStyleJComboBox; 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<String>(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<String>(); 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 change108 */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(layout130 .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 extends <code>java.awt.JFrame</code>, there are three methods provided:<br> 43 * <code>getSkin()</code> to change the frame skin.<br> 44 * and there are 21 skins to provided. And the<br> 45 * default skin is <code>MagmaSkin</code> .You can change value to change <br> 46 * skin if possible. and you should call the method <code>setJUI()</code> 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 the <code>skinNums</code> value, and the default skin is <code>MagmaSkin</code> 62 * @param num <code>skinNum</code> 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 listener336 textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {337 public void undoableEditHappened(UndoableEditEvent e) {338 undoManager.addEdit(e.getEdit());339 }340 });341 // add caret listener342 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 listener356 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 * The <code>NotepadUI</code> class extends <code>JUI</code> and implements11 * <code>ActionListener</code>.12 * 13 * @author Hongten - http://www.cnblogs.com/hongten/p/hongten_notepad_index.html14 * @created Nov 19, 201415 */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 button189 */190 private void distoryReplaceManagerUI() {191 ReplaceManagerUI.this.setVisible(false);192 edit.distoryReplaceeManagerUI();193 }194 195 /**196 * Case Sensitive Switch197 */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 JComboBox<String> sinkJComboBox; 32 33 private ViewMenuUtil view; 34 35 public String[][] skins = { { "AutumnSkin", "1", "<html><a href=http://www.mamicode.com/‘‘>What is the AutumnSkin skin?