Source Code Cross Referenced for FindDialog.java in  » IDE » J » org » armedbear » j » 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 » IDE » J » org.armedbear.j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * FindDialog.java
003:         *
004:         * Copyright (C) 1998-2003 Peter Graves
005:         * $Id: FindDialog.java,v 1.4 2003/10/13 23:52:56 piso Exp $
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:
022:        package org.armedbear.j;
023:
024:        import gnu.regexp.REException;
025:        import java.awt.event.ActionEvent;
026:        import java.awt.event.ActionListener;
027:        import java.awt.event.TextEvent;
028:        import java.awt.event.TextListener;
029:        import javax.swing.Box;
030:        import javax.swing.BoxLayout;
031:        import javax.swing.JLabel;
032:        import javax.swing.JPanel;
033:
034:        public final class FindDialog extends AbstractDialog implements 
035:                ActionListener, TextListener {
036:            private static final String patternKey = "find.pattern";
037:            private static final String searchFromStartKey = "find.searchFromStart";
038:
039:            private static boolean wholeWordsOnly;
040:            private static boolean regularExpression;
041:            private static boolean isMultilinePattern;
042:
043:            private Search search;
044:            private final Editor editor;
045:            private HistoryTextField patternControl;
046:            private History patternHistory;
047:            private CheckBox ignoreCaseCheckBox;
048:            private CheckBox wholeWordsCheckBox;
049:            private CheckBox regularExpressionCheckBox;
050:            private CheckBox multilinePatternCheckBox;
051:            private CheckBox listOccurrencesCheckBox;
052:            private CheckBox searchFromStartCheckBox;
053:            private boolean listOccurrences;
054:            private boolean searchFromStart;
055:
056:            public FindDialog(Editor editor) {
057:                super (editor, "Find", true);
058:                this .editor = editor;
059:                search = new Search();
060:                patternControl = new HistoryTextField(20);
061:                patternHistory = new History(patternKey);
062:                patternControl.setHistory(patternHistory);
063:                // Pre-fill pattern control.
064:                String s = editor.getCurrentText();
065:                if (s != null)
066:                    patternControl.setText(s);
067:                else
068:                    patternControl.recallLast();
069:                Label label = new Label("Pattern:");
070:                label.setDisplayedMnemonic('P');
071:                addLabelAndTextField(label, patternControl);
072:                addVerticalStrut();
073:                ignoreCaseCheckBox = new CheckBox("Ignore case");
074:                ignoreCaseCheckBox.setMnemonic('I');
075:                setIgnoreCaseDefault();
076:                addCheckBox(ignoreCaseCheckBox);
077:                wholeWordsCheckBox = new CheckBox("Whole words only",
078:                        wholeWordsOnly);
079:                wholeWordsCheckBox.setMnemonic('W');
080:                addCheckBox(wholeWordsCheckBox);
081:                regularExpressionCheckBox = new CheckBox("Regular expression",
082:                        regularExpression);
083:                regularExpressionCheckBox.setMnemonic('X');
084:                regularExpressionCheckBox.addActionListener(this );
085:                addCheckBox(regularExpressionCheckBox);
086:                if (Editor.checkExperimental()) {
087:                    JPanel panel = new JPanel();
088:                    panel.setAlignmentX(LEFT_ALIGNMENT);
089:                    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
090:                    panel.add(Box.createHorizontalStrut(17));
091:                    multilinePatternCheckBox = new CheckBox(
092:                            "Multiline pattern (experimental)",
093:                            isMultilinePattern);
094:                    multilinePatternCheckBox.setMnemonic('M');
095:                    panel.add(multilinePatternCheckBox);
096:                    multilinePatternCheckBox.addKeyListener(this );
097:                    multilinePatternCheckBox
098:                            .setEnabled(regularExpressionCheckBox.isSelected());
099:                    mainPanel.add(panel);
100:                }
101:                listOccurrencesCheckBox = new CheckBox("List occurrences",
102:                        listOccurrences);
103:                listOccurrencesCheckBox.setMnemonic('L');
104:                addCheckBox(listOccurrencesCheckBox);
105:                searchFromStart = Editor.getSessionProperties()
106:                        .getBooleanProperty(searchFromStartKey, false);
107:                searchFromStartCheckBox = new CheckBox(
108:                        "Search from start of document", searchFromStart);
109:                searchFromStartCheckBox.setMnemonic('S');
110:                addCheckBox(searchFromStartCheckBox);
111:                addVerticalStrut();
112:                addOKCancel();
113:                patternControl.addTextListener(this );
114:                patternControl.addActionListener(this );
115:                pack();
116:                patternControl.requestFocus();
117:            }
118:
119:            public Search getSearch() {
120:                return search;
121:            }
122:
123:            public boolean getListOccurrences() {
124:                return listOccurrences;
125:            }
126:
127:            public boolean searchFromStart() {
128:                return searchFromStart;
129:            }
130:
131:            protected void ok() {
132:                search.setPattern(patternControl.getText());
133:                search.setIgnoreCase(ignoreCaseCheckBox.isSelected());
134:                wholeWordsOnly = wholeWordsCheckBox.isSelected();
135:                search.setWholeWordsOnly(wholeWordsOnly);
136:                regularExpression = regularExpressionCheckBox.isSelected();
137:                search.setRegularExpression(regularExpression);
138:                if (multilinePatternCheckBox != null) {
139:                    isMultilinePattern = multilinePatternCheckBox.isSelected();
140:                    search.setMultiline(isMultilinePattern);
141:                }
142:                if (regularExpression) {
143:                    try {
144:                        search.setREFromPattern();
145:                    } catch (REException e) {
146:                        MessageDialog.showMessageDialog(editor, e.getMessage(),
147:                                "Error");
148:                        patternControl.requestFocus();
149:                        return;
150:                    }
151:                }
152:                listOccurrences = listOccurrencesCheckBox.isSelected();
153:                searchFromStart = searchFromStartCheckBox.isSelected();
154:                Editor.getSessionProperties().setBooleanProperty(
155:                        searchFromStartKey, searchFromStart);
156:                patternHistory.append(search.getPattern());
157:                patternHistory.save();
158:                dispose();
159:            }
160:
161:            protected void cancel() {
162:                cancelled = true;
163:                search = null;
164:                dispose();
165:            }
166:
167:            public void textValueChanged(TextEvent e) {
168:                setIgnoreCaseDefault();
169:            }
170:
171:            public void actionPerformed(ActionEvent e) {
172:                String cmd = e.getActionCommand();
173:                if (cmd != null
174:                        && cmd.equals(regularExpressionCheckBox.getText())) {
175:                    if (multilinePatternCheckBox != null) {
176:                        boolean isRegExp = regularExpressionCheckBox
177:                                .isSelected();
178:                        if (!isRegExp)
179:                            multilinePatternCheckBox.setSelected(false);
180:                        multilinePatternCheckBox.setEnabled(isRegExp);
181:                    }
182:                } else
183:                    super .actionPerformed(e);
184:            }
185:
186:            private void setIgnoreCaseDefault() {
187:                String pattern = patternControl.getText();
188:                ignoreCaseCheckBox.setSelected(pattern == null
189:                        || Utilities.isLowerCase(pattern));
190:            }
191:
192:            public static void find() {
193:                find(Editor.currentEditor());
194:            }
195:
196:            // Also called from IncrementalTextFieldHandler.finish() if the user hits
197:            // Enter with an empty search string.
198:            public static void find(Editor editor) {
199:                if (editor.getDot() == null)
200:                    return;
201:                FindDialog d = new FindDialog(editor);
202:                editor.centerDialog(d);
203:                d.show();
204:                Search search = d.getSearch();
205:                if (search == null)
206:                    return;
207:                editor.setLastSearch(search);
208:                if (d.getListOccurrences()) {
209:                    ListOccurrences.listOccurrences(editor);
210:                } else {
211:                    editor.setWaitCursor();
212:                    final Position start;
213:                    if (d.searchFromStart())
214:                        start = new Position(editor.getBuffer().getFirstLine(),
215:                                0);
216:                    else
217:                        start = editor.getDot();
218:                    Position pos = search.find(editor.getBuffer(), start);
219:                    editor.setDefaultCursor();
220:                    if (pos != null) {
221:                        editor.moveDotTo(pos);
222:                        editor.markFoundPattern(search);
223:                    } else
224:                        search.notFound(editor);
225:                }
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.