Source Code Cross Referenced for ListOccurrences.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:         * ListOccurrences.java
003:         *
004:         * Copyright (C) 2000-2004 Peter Graves
005:         * $Id: ListOccurrences.java,v 1.8 2004/04/26 19:51:03 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 java.awt.AWTEvent;
025:        import java.awt.event.MouseEvent;
026:
027:        public class ListOccurrences extends Buffer {
028:            protected final Search search;
029:            private final Buffer sourceBuffer;
030:
031:            protected ListOccurrences(Search search) {
032:                this .search = search;
033:                sourceBuffer = null;
034:                init();
035:            }
036:
037:            private ListOccurrences(Search search, Buffer sourceBuffer) {
038:                this .search = search;
039:                this .sourceBuffer = sourceBuffer;
040:                init();
041:                if (sourceBuffer.getFile() != null)
042:                    title = sourceBuffer.getFile().getName() + " \""
043:                            + search.getPattern() + "\"";
044:                else
045:                    title = sourceBuffer.getTitle() + " \""
046:                            + search.getPattern() + "\"";
047:                setTabWidth(sourceBuffer.getTabWidth());
048:                if (sourceBuffer.getFile() != null)
049:                    appendLine("File: " + sourceBuffer.getFile().netPath());
050:                else
051:                    appendLine("Buffer: " + sourceBuffer.getTitle());
052:            }
053:
054:            private void init() {
055:                initializeUndo();
056:                type = TYPE_LIST_OCCURRENCES;
057:                mode = ListOccurrencesMode.getMode();
058:                formatter = mode.getFormatter(this );
059:                readOnly = true;
060:                setTransient(true);
061:                try {
062:                    lockWrite();
063:                } catch (InterruptedException e) {
064:                    Log.debug(e);
065:                    return;
066:                }
067:                try {
068:                    if (search.isRegularExpression())
069:                        appendLine("Regular expression: \""
070:                                + search.getPattern() + '"');
071:                    else
072:                        appendLine("Pattern: \"" + search.getPattern() + '"');
073:                    if (search instanceof  Replacement) {
074:                        String replaceWith = ((Replacement) search)
075:                                .getReplaceWith();
076:                        if (replaceWith != null)
077:                            appendLine("Replace with: \"" + replaceWith + '"');
078:                    }
079:                    appendLine("Options: " + getOptions());
080:                } finally {
081:                    unlockWrite();
082:                }
083:                setInitialized(true);
084:            }
085:
086:            public Mode getParentMode() {
087:                if (search instanceof  FindInFiles)
088:                    return ((FindInFiles) search).getMode();
089:                if (sourceBuffer != null)
090:                    return sourceBuffer.getMode();
091:                return null;
092:            }
093:
094:            public static ListOccurrences findBuffer(Buffer sourceBuffer,
095:                    Search search) {
096:                for (BufferIterator it = new BufferIterator(); it.hasNext();) {
097:                    Buffer buf = it.nextBuffer();
098:                    if (buf instanceof  ListOccurrences) {
099:                        ListOccurrences lo = (ListOccurrences) buf;
100:                        if (lo.search.equals(search)
101:                                && lo.sourceBuffer == sourceBuffer)
102:                            return lo;
103:                    }
104:                }
105:                return null;
106:            }
107:
108:            private static ListOccurrences createBuffer(Buffer sourceBuffer,
109:                    Search search) {
110:                ListOccurrences listOccurrences = null;
111:                Position pos = new Position(sourceBuffer.getFirstLine(), 0);
112:                while ((pos = search.find(sourceBuffer.getMode(), pos)) != null) {
113:                    if (listOccurrences == null)
114:                        listOccurrences = new ListOccurrences(search,
115:                                sourceBuffer);
116:                    listOccurrences.appendOccurrenceLine(pos.getLine());
117:                    Line next = pos.getNextLine();
118:                    if (next != null)
119:                        pos.moveTo(next, 0);
120:                    else
121:                        break;
122:                }
123:                if (listOccurrences != null) {
124:                    listOccurrences.renumber();
125:                    listOccurrences.setLoaded(true);
126:                }
127:                return listOccurrences;
128:            }
129:
130:            public static ListOccurrences getBuffer(Buffer sourceBuffer,
131:                    Search search) {
132:                ListOccurrences lo = findBuffer(sourceBuffer, search);
133:                if (lo != null)
134:                    return lo;
135:                else
136:                    return createBuffer(sourceBuffer, search);
137:            }
138:
139:            public final Buffer getSourceBuffer() {
140:                return sourceBuffer;
141:            }
142:
143:            public File getCurrentDirectory() {
144:                if (sourceBuffer != null)
145:                    return sourceBuffer.getCurrentDirectory();
146:                else
147:                    return Directories.getUserHomeDirectory();
148:            }
149:
150:            public void findOccurrenceAtDot(Editor editor, boolean killList) {
151:                Position pos = editor.getDotCopy();
152:                if (pos == null)
153:                    return;
154:                final Line line = pos.getLine();
155:                if (!(line instanceof  OccurrenceLine))
156:                    return;
157:                Buffer buf = null;
158:                for (BufferIterator it = new BufferIterator(); it.hasNext();) {
159:                    Buffer b = it.nextBuffer();
160:                    if (b == sourceBuffer) {
161:                        buf = b;
162:                        break;
163:                    }
164:                }
165:                if (buf == null) {
166:                    sourceBuffer.relink();
167:                    buf = sourceBuffer;
168:                }
169:                if (!buf.isLoaded()) {
170:                    Log.debug("findOccurrence reloading source buffer");
171:                    buf.load();
172:                    if (!buf.isLoaded()) {
173:                        editor.status("Unable to load buffer");
174:                        return;
175:                    }
176:                }
177:                final Line sourceLine = ((OccurrenceLine) line).getSourceLine();
178:                Debug.assertTrue(sourceLine != null);
179:                Line target;
180:                if (buf.contains(sourceLine))
181:                    target = sourceLine;
182:                else
183:                    target = buf.getLine(sourceLine.lineNumber());
184:                if (target != null)
185:                    gotoSource(editor, buf, target, killList);
186:            }
187:
188:            protected void gotoSource(Editor editor, Buffer buf, Line target,
189:                    boolean killList) {
190:                if (target != null) {
191:                    Editor ed;
192:                    if (editor.getFrame().getEditorCount() > 1) {
193:                        editor.getOtherEditor().makeNext(buf);
194:                        ed = editor.activateInOtherWindow(buf);
195:                    } else {
196:                        ed = editor;
197:                        ed.makeNext(buf);
198:                        ed.activate(buf);
199:                    }
200:                    ed.setLastSearch(search);
201:                    ed.addUndo(SimpleEdit.MOVE);
202:                    ed.unmark();
203:                    ed.update(ed.getDotLine());
204:                    ed.setDot(target, 0);
205:                    Position found = search.find(buf.getMode(), ed.getDot());
206:                    if (found != null) {
207:                        ed.setDot(found);
208:                        ed.markFoundPattern(search);
209:                    } else {
210:                        ed.moveCaretToDotCol();
211:                    }
212:                    ed.update(ed.getDotLine());
213:                    ed.updateDisplay();
214:
215:                    if (killList) {
216:                        if (ed.getFrame().getEditorCount() > 1) {
217:                            Editor otherEditor = ed.getOtherEditor();
218:                            if (otherEditor != null)
219:                                ed.getFrame().closeEditor(otherEditor);
220:                            kill();
221:                        }
222:                    }
223:                }
224:            }
225:
226:            public final void appendOccurrenceLine(Line sourceLine) {
227:                appendLine(new OccurrenceLine(sourceLine));
228:            }
229:
230:            public final void appendOccurrenceLine(String s, int lineNumber) {
231:                appendLine(new OccurrenceLine(s, lineNumber));
232:            }
233:
234:            protected String getOptions() {
235:                FastStringBuffer sb = new FastStringBuffer(
236:                        search.ignoreCase() ? "ignore case" : "case sensitive");
237:                if (search.wholeWordsOnly())
238:                    sb.append(", whole words only");
239:                return sb.toString();
240:            }
241:
242:            public final Search getSearch() {
243:                return search;
244:            }
245:
246:            public Position getInitialDotPos() {
247:                for (Line line = getFirstLine(); line != null; line = line
248:                        .next()) {
249:                    if (line instanceof  OccurrenceLine)
250:                        return new Position(line, 0);
251:                }
252:                return new Position(getFirstLine(), 0);
253:            }
254:
255:            public Position getInitialDotPos(Line sourceLine, int sourceOffs) {
256:                for (Line line = getFirstLine(); line != null; line = line
257:                        .next()) {
258:                    if (line instanceof  OccurrenceLine) {
259:                        if (((OccurrenceLine) line).getSourceLine() == sourceLine) {
260:                            int index = line.getText().indexOf(':');
261:                            if (index >= 0)
262:                                return new Position(line, index + 1
263:                                        + sourceOffs);
264:                            else
265:                                return new Position(line, sourceOffs);
266:                        }
267:                    }
268:                }
269:                return getInitialDotPos();
270:            }
271:
272:            public String getFileNameForDisplay() {
273:                if (sourceBuffer == null || sourceBuffer.getFile() == null)
274:                    return "";
275:                else
276:                    return sourceBuffer.getFile().getName();
277:            }
278:
279:            public static final void listOccurrences() {
280:                listOccurrences(Editor.currentEditor());
281:            }
282:
283:            public static void listOccurrences(Editor editor) {
284:                final Search search = editor.getLastSearch();
285:                if (search != null) {
286:                    editor.setWaitCursor();
287:                    ListOccurrences buf = getBuffer(editor.getBuffer(), search);
288:                    editor.setDefaultCursor();
289:                    if (buf != null) {
290:                        editor.makeNext(buf);
291:                        Editor otherEditor = editor.getOtherEditor();
292:                        if (otherEditor != null) {
293:                            buf.setUnsplitOnClose(otherEditor.getBuffer()
294:                                    .unsplitOnClose());
295:                            otherEditor.makeNext(buf);
296:                        } else
297:                            buf.setUnsplitOnClose(true);
298:                        Editor ed = editor.activateInOtherWindow(buf);
299:
300:                        ed.setDot(buf.getInitialDotPos());
301:                        ed.moveCaretToDotCol();
302:                        ed.updateDisplay();
303:                    } else
304:                        search.notFound(editor);
305:                }
306:            }
307:
308:            public static void listOccurrencesOfPatternAtDot() {
309:                final Editor editor = Editor.currentEditor();
310:                final Search search = editor.getSearchAtDot();
311:                if (search != null) {
312:                    editor.setLastSearch(search);
313:                    editor.setWaitCursor();
314:                    ListOccurrences buf = getBuffer(editor.getBuffer(), search);
315:                    editor.setDefaultCursor();
316:                    if (buf != null) {
317:                        editor.makeNext(buf);
318:                        Editor otherEditor = editor.getOtherEditor();
319:                        if (otherEditor != null) {
320:                            buf.setUnsplitOnClose(otherEditor.getBuffer()
321:                                    .unsplitOnClose());
322:                            otherEditor.makeNext(buf);
323:                        } else
324:                            buf.setUnsplitOnClose(true);
325:                        Editor ed = editor.activateInOtherWindow(buf);
326:
327:                        ed.setDot(buf.getInitialDotPos(editor.getDotLine(),
328:                                editor.getDotOffset()));
329:                        ed.moveCaretToDotCol();
330:                        ed.updateDisplay();
331:                    } else
332:                        search.notFound(editor);
333:                }
334:            }
335:
336:            public static void findOccurrenceAtDot() {
337:                final Editor editor = Editor.currentEditor();
338:                final Buffer buffer = editor.getBuffer();
339:                if (buffer instanceof  ListOccurrences)
340:                    ((ListOccurrences) buffer).findOccurrenceAtDot(editor,
341:                            false);
342:            }
343:
344:            public static void findOccurrenceAtDotAndKillList() {
345:                final Editor editor = Editor.currentEditor();
346:                final Buffer buffer = editor.getBuffer();
347:                if (buffer instanceof  ListOccurrences)
348:                    ((ListOccurrences) buffer)
349:                            .findOccurrenceAtDot(editor, true);
350:            }
351:
352:            public static void mouseFindOccurrence() {
353:                final Editor editor = Editor.currentEditor();
354:                final Buffer buffer = editor.getBuffer();
355:                if (buffer instanceof  ListOccurrences) {
356:                    AWTEvent e = editor.getDispatcher().getLastEvent();
357:                    if (e instanceof  MouseEvent) {
358:                        editor.mouseMoveDotToPoint((MouseEvent) e);
359:                        ((ListOccurrences) buffer).findOccurrenceAtDot(editor,
360:                                false);
361:                    }
362:                }
363:            }
364:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.