首页 > 学院 > 开发设计 > 正文

My Notepad

2019-11-14 22:03:41
字体:
来源:转载
供稿:网友
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.VEVb.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 = "1.0";107     public static final String BLOG = "Blog";108     public static final String HOME_PAGE = "http://www.VEVb.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.VEVb.com/hongten'>http://www.VEVb.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.VEVb.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.VEVb.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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表