Source Code Cross Referenced for FindReplaceDialog.java in  » Mail-Clients » columba-1.4 » org » columba » core » gui » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Mail Clients » columba 1.4 » org.columba.core.gui.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.columba.core.gui.util;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.event.ActionEvent;
005:        import java.awt.event.ActionListener;
006:
007:        import javax.swing.BorderFactory;
008:        import javax.swing.JDialog;
009:        import javax.swing.JOptionPane;
010:        import javax.swing.JPanel;
011:        import javax.swing.JTextField;
012:
013:        import org.columba.core.gui.base.ButtonWithMnemonic;
014:        import org.columba.core.gui.base.CheckBoxWithMnemonic;
015:        import org.columba.core.gui.base.LabelWithMnemonic;
016:        import org.columba.core.resourceloader.GlobalResourceLoader;
017:        import org.columba.core.resourceloader.IconKeys;
018:        import org.columba.core.resourceloader.ImageLoader;
019:        import org.columba.core.util.FindReplace;
020:        import org.columba.core.util.IEditableText;
021:
022:        import com.jgoodies.forms.layout.CellConstraints;
023:        import com.jgoodies.forms.layout.FormLayout;
024:
025:        @SuppressWarnings("serial")
026:        public class FindReplaceDialog extends JDialog implements 
027:                ActionListener {
028:            private static final String RESOURCE_PATH = "org.columba.core.i18n.dialog";
029:
030:            private LabelWithMnemonic findLabel;
031:            private LabelWithMnemonic replaceLabel;
032:
033:            private ButtonWithMnemonic findButton;
034:            private ButtonWithMnemonic replaceButton;
035:            private ButtonWithMnemonic replaceAllButton;
036:            private ButtonWithMnemonic closeButton;
037:
038:            private CheckBoxWithMnemonic wholeWordCheckBox;
039:            private CheckBoxWithMnemonic caseSensCheckBox;
040:            private CheckBoxWithMnemonic findBackCheckBox;
041:
042:            private JTextField findTextField;
043:            private JTextField replaceWithTextField;
044:
045:            private IEditableText text;
046:            private FindReplace finder = new FindReplace();
047:
048:            public FindReplaceDialog(IEditableText text) {
049:                setTitle(GlobalResourceLoader.getString(RESOURCE_PATH,
050:                        "findreplace", "findreplace.title"));
051:                this .text = text;
052:                initComponents();
053:                setResizable(false);
054:                pack();
055:                setVisible(true);
056:            }
057:
058:            private void createComponents() {
059:
060:                findLabel = new LabelWithMnemonic(GlobalResourceLoader
061:                        .getString(RESOURCE_PATH, "findreplace", "findlabel"));
062:                replaceLabel = new LabelWithMnemonic(GlobalResourceLoader
063:                        .getString(RESOURCE_PATH, "findreplace",
064:                                "replacewithlabel"));
065:
066:                findTextField = new JTextField(16);
067:                replaceWithTextField = new JTextField(16);
068:
069:                wholeWordCheckBox = new CheckBoxWithMnemonic(
070:                        GlobalResourceLoader.getString(RESOURCE_PATH,
071:                                "findreplace", "matchword"));
072:                caseSensCheckBox = new CheckBoxWithMnemonic(
073:                        GlobalResourceLoader.getString(RESOURCE_PATH,
074:                                "findreplace", "matchcase"));
075:                findBackCheckBox = new CheckBoxWithMnemonic(
076:                        GlobalResourceLoader.getString(RESOURCE_PATH,
077:                                "findreplace", "findbackwards"));
078:
079:                findButton = new ButtonWithMnemonic(GlobalResourceLoader
080:                        .getString(RESOURCE_PATH, "findreplace", "find"));
081:                replaceButton = new ButtonWithMnemonic(GlobalResourceLoader
082:                        .getString(RESOURCE_PATH, "findreplace", "replace"));
083:                replaceAllButton = new ButtonWithMnemonic(GlobalResourceLoader
084:                        .getString(RESOURCE_PATH, "findreplace", "replaceall"));
085:                closeButton = new ButtonWithMnemonic(GlobalResourceLoader
086:                        .getString(RESOURCE_PATH, "findreplace", "close"));
087:
088:            }
089:
090:            private void initComponents() {
091:
092:                FormLayout layout = new FormLayout("pref, 6dlu, pref", // columns 
093:                        "pref, 3dlu, pref"); // rows
094:
095:                CellConstraints cc = new CellConstraints();
096:
097:                createComponents();
098:
099:                JPanel panelMain = new JPanel(layout);
100:                panelMain.setBorder(BorderFactory.createEmptyBorder(12, 12, 12,
101:                        12));
102:
103:                panelMain.add(createInputPanel(), cc.xy(1, 1));
104:                panelMain.add(createButtonPanel(), cc.xywh(3, 1, 1, 3));
105:                panelMain.add(createOptionPanel(), cc.xy(1, 3));
106:
107:                getContentPane().add(panelMain, BorderLayout.SOUTH);
108:                getContentPane().add(
109:                        new DialogHeaderPanel(GlobalResourceLoader.getString(
110:                                RESOURCE_PATH, "findreplace", "header_title"),
111:                                GlobalResourceLoader.getString(RESOURCE_PATH,
112:                                        "findreplace", "header_description"),
113:                                ImageLoader.getIcon(IconKeys.SEARCH)),
114:                        BorderLayout.NORTH);
115:            }
116:
117:            private JPanel createInputPanel() {
118:                FormLayout layout = new FormLayout(
119:                        "left:pref, 6dlu, left:pref", "pref, 3dlu, pref");
120:                CellConstraints cc = new CellConstraints();
121:                JPanel inputPanel = new JPanel(layout);
122:
123:                inputPanel.add(findLabel, cc.xy(1, 1));
124:                findLabel.setLabelFor(findTextField);
125:                inputPanel.add(findTextField, cc.xy(3, 1));
126:
127:                inputPanel.add(replaceLabel, cc.xy(1, 3));
128:                replaceLabel.setLabelFor(replaceWithTextField);
129:                inputPanel.add(replaceWithTextField, cc.xy(3, 3));
130:
131:                return inputPanel;
132:            }
133:
134:            private JPanel createOptionPanel() {
135:                // create a panel with a border and 3 options
136:                FormLayout layout = new FormLayout(
137:                        "3dlu, left:pref, 30dlu, right:pref, 3dlu", // columns 
138:                        "pref, 3dlu, pref"); // rows
139:
140:                CellConstraints cc = new CellConstraints();
141:
142:                JPanel optionPanel = new JPanel(layout);
143:                optionPanel.setBorder(BorderFactory
144:                        .createTitledBorder(GlobalResourceLoader.getString(
145:                                RESOURCE_PATH, "findreplace", "options")));
146:
147:                optionPanel.add(caseSensCheckBox, cc.xy(2, 1));
148:                optionPanel.add(wholeWordCheckBox, cc.xywh(2, 3, 3, 1));
149:                optionPanel.add(findBackCheckBox, cc.xy(4, 1));
150:
151:                return optionPanel;
152:            }
153:
154:            private JPanel createButtonPanel() {
155:                // create a panel with all 4 buttons of the window
156:                FormLayout layout = new FormLayout("fill:pref", // columns 
157:                        "pref, 3dlu, pref, 3dlu, pref, 3dlu, pref"); // rows
158:                CellConstraints cc = new CellConstraints();
159:                JPanel buttonPanel = new JPanel(layout);
160:
161:                findButton.addActionListener(this );
162:                findButton.setActionCommand("FIND");
163:                this .getRootPane().setDefaultButton(findButton);
164:
165:                replaceButton.addActionListener(this );
166:                replaceButton.setActionCommand("REPLACE");
167:
168:                replaceAllButton.addActionListener(this );
169:                replaceAllButton.setActionCommand("REPLACEALL");
170:
171:                closeButton.addActionListener(this );
172:                closeButton.setActionCommand("CLOSE");
173:
174:                buttonPanel.add(findButton, cc.xy(1, 1));
175:                buttonPanel.add(replaceButton, cc.xy(1, 3));
176:                buttonPanel.add(replaceAllButton, cc.xy(1, 5));
177:                buttonPanel.add(closeButton, cc.xy(1, 7));
178:
179:                return buttonPanel;
180:            }
181:
182:            public void actionPerformed(ActionEvent e) {
183:                // if some action was performed
184:                String action = e.getActionCommand();
185:
186:                String source = text.getText();
187:
188:                // setup the finder
189:                finder.setPattern(findTextField.getText());
190:                finder.setSource(source);
191:                finder.setCaseSensitive(caseSensCheckBox.isSelected());
192:                finder.setMatchWholeWord(wholeWordCheckBox.isSelected());
193:                finder.setBackwards(findBackCheckBox.isSelected());
194:                finder.setReplaceWith(replaceWithTextField.getText());
195:
196:                // find action performed
197:                if (action.equals("FIND")) {
198:                    int position = finder.findnext();
199:                    if (position >= 0) {
200:                        // mark found pattern
201:                        mark(position, position
202:                                + findTextField.getText().length());
203:                        //text.grabFocus();
204:                    } else {
205:                        // delete marks
206:                        mark(0, 0);
207:                        JOptionPane.showMessageDialog(this ,
208:                                GlobalResourceLoader.getString(RESOURCE_PATH,
209:                                        "findreplace", "string_not_found"));
210:                    }
211:                }
212:                //replace action performed
213:                else if (action.equals("REPLACE")) {
214:                    int position = finder.replace();
215:                    if (position >= 0) {
216:                        //text.grabFocus();
217:                        text.setText(finder.getSource());
218:                        mark(position, position
219:                                + replaceWithTextField.getText().length());
220:                    } else {
221:                        mark(0, 0);
222:                        JOptionPane.showMessageDialog(this ,
223:                                GlobalResourceLoader.getString(RESOURCE_PATH,
224:                                        "findreplace", "string_not_found"));
225:                    }
226:                }
227:                //replaceall action performed
228:                else if (action.equals("REPLACEALL")) {
229:                    finder.replaceAll();
230:                    if (finder.getSource().equals(text.getText())) {
231:                        //text.grabFocus();
232:                        text.setText(finder.getSource());
233:                        JOptionPane.showMessageDialog(this ,
234:                                GlobalResourceLoader.getString(RESOURCE_PATH,
235:                                        "findreplace", "string_not_found"));
236:                    } else
237:                        text.setText(finder.getSource());
238:                } else if (action.equals("CLOSE")) {
239:                    this .dispose();
240:                }
241:            }
242:
243:            // to mark a text in the JTextPane
244:            private void mark(int start, int end) {
245:                text.setCaretPosition(start);
246:                text.moveCaretPosition(end);
247:            }
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.