Source Code Cross Referenced for ExtCaret.java in  » IDE-Netbeans » editor » org » netbeans » editor » ext » 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 Netbeans » editor » org.netbeans.editor.ext 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.editor.ext;
043:
044:        import java.awt.event.MouseEvent;
045:        import javax.swing.text.JTextComponent;
046:        import org.netbeans.editor.BaseCaret;
047:        import org.netbeans.editor.Utilities;
048:        import org.netbeans.editor.SettingsUtil;
049:        import org.netbeans.editor.SettingsChangeEvent;
050:
051:        /**
052:         * Extended caret implementation
053:         *
054:         * @author Miloslav Metelka
055:         * @version 1.00
056:         */
057:
058:        public class ExtCaret extends BaseCaret {
059:
060:            /** 
061:             * Highlight row draw layer name.
062:             * 
063:             * <p>Using <code>DrawLayer</code>s has been deprecated and this constant
064:             * has no longer any meaning.
065:             * 
066:             * @deprecated Please use Highlighting SPI instead, for details see
067:             *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
068:             */
069:            public static final String HIGHLIGHT_ROW_LAYER_NAME = "highlight-row-layer"; // NOI18N
070:
071:            /**
072:             * Highlight row draw layer visibility.
073:             * 
074:             * <p>Using <code>DrawLayer</code>s has been deprecated and this constant
075:             * has no longer any meaning.
076:             * 
077:             * @deprecated Please use Highlighting SPI instead, for details see
078:             *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
079:             */
080:            public static final int HIGHLIGHT_ROW_LAYER_VISIBILITY = 2050;
081:
082:            /** 
083:             * Highlight matching brace draw layer name
084:             * 
085:             * @deprecated Please use Braces Matching SPI instead, for details see
086:             *   <a href="@org-netbeans-modules-editor-bracesmatching@/overview-summary.html">Editor Braces Matching</a>.
087:             */
088:            public static final String HIGHLIGHT_BRACE_LAYER_NAME = "highlight-brace-layer"; // NOI18N
089:
090:            /** 
091:             * Highlight matching brace draw layer visibility 
092:             * 
093:             * @deprecated Please use Braces Matching SPI instead, for details see
094:             *   <a href="@org-netbeans-modules-editor-bracesmatching@/overview-summary.html">Editor Braces Matching</a>.
095:             */
096:            public static final int HIGHLIGHT_BRACE_LAYER_VISIBILITY = 11000;
097:
098:            // XXX: remove
099:            //    /** Highlight a brace matching character before the caret */
100:            //    public static final int MATCH_BRACE_BEFORE = -1;
101:            //    
102:            //    /** Highlight a brace matching character after (at) the caret */
103:            //    public static final int MATCH_BRACE_AFTER = 0;
104:            //    
105:            //    /** Highlight a brace matching character either before or after caret;
106:            //        the character before takes precedence. */
107:            //    public static final int MATCH_BRACE_EITHER = java.lang.Integer.MAX_VALUE;
108:            //
109:            //    /** Whether to hightlight the matching brace */
110:            //    boolean highlightBrace;
111:            //
112:            //    /** Coloring used for highlighting the matching brace */
113:            //    Coloring highlightBraceColoring;
114:            //
115:            //    /** Mark holding the starting position of the matching brace. */
116:            //    MarkFactory.DrawMark highlightBraceStartMark;
117:            //
118:            //    /** Mark holding the ending position of the matching brace. */
119:            //    MarkFactory.DrawMark highlightBraceEndMark;
120:            //
121:            //    /** Timer that fires when the matching brace should be displayed */
122:            //    private Timer braceTimer;
123:            //    private ActionListener braceTimerListener; // because of unwanted GC
124:            //
125:            //    /** Signal that the next matching brace update
126:            //    * will be immediate without waiting for the brace
127:            //    * timer to fire the action.
128:            //    */
129:            //    private boolean matchBraceUpdateSync;
130:            //
131:            //    /** Whether the brace starting and ending marks are currently valid or not.
132:            //     * If they are not valid the block they delimit is not highlighted.
133:            //     */
134:            //    boolean braceMarksValid;
135:            //
136:            //    boolean simpleMatchBrace;
137:            //
138:            //    private int matchBraceOffset = MATCH_BRACE_EITHER;
139:
140:            static final long serialVersionUID = -4292670043122577690L;
141:
142:            // XXX: remove    
143:            //    protected void modelChanged(BaseDocument oldDoc, BaseDocument newDoc) {
144:            //        // Fix for #7108
145:            //        braceMarksValid = false; // brace marks are out of date - new document
146:            //        if (highlightBraceStartMark != null) {
147:            //            try {
148:            //                highlightBraceStartMark.remove();
149:            //            } catch (InvalidMarkException e) {
150:            //            }
151:            //            highlightBraceStartMark = null;
152:            //        }
153:            //
154:            //        if (highlightBraceEndMark != null) {
155:            //            try {
156:            //                highlightBraceEndMark.remove();
157:            //            } catch (InvalidMarkException e) {
158:            //            }
159:            //            highlightBraceEndMark = null;
160:            //        }
161:            //
162:            //        super.modelChanged( oldDoc, newDoc );
163:            //    }
164:
165:            /** Called when settings were changed. The method is called
166:             * also in constructor, so the code must count with the evt being null.
167:             */
168:            public void settingsChange(SettingsChangeEvent evt) {
169:                super .settingsChange(evt);
170:                JTextComponent c = component;
171:                if (c != null) {
172:                    Class kitClass = Utilities.getKitClass(c);
173:                    // XXX: remove
174:                    //            EditorUI editorUI = Utilities.getEditorUI(c);
175:                    //            highlightBraceColoring = editorUI.getColoring(
176:                    //                                           ExtSettingsNames.HIGHLIGHT_MATCH_BRACE_COLORING);
177:                    //
178:                    //            highlightBrace = SettingsUtil.getBoolean(kitClass,
179:                    //                               ExtSettingsNames.HIGHLIGHT_MATCH_BRACE,
180:                    //                               ExtSettingsDefaults.defaultHighlightMatchBrace);
181:                    //            int highlightBraceDelay = SettingsUtil.getInteger(kitClass,
182:                    //                                        ExtSettingsNames.HIGHLIGHT_MATCH_BRACE_DELAY,
183:                    //                                        ExtSettingsDefaults.defaultHighlightMatchBraceDelay);
184:                    //
185:                    //            if (highlightBrace) {
186:                    //                if (highlightBraceDelay > 0) {
187:                    //                    // jdk12 compiler doesn't allow inside run()
188:                    //                    final JTextComponent c2 = component;
189:                    //
190:                    //                    braceTimer = new Timer(highlightBraceDelay, null);
191:                    //                    braceTimerListener = 
192:                    //                         new ActionListener() {
193:                    //                             public void actionPerformed(ActionEvent evt2) {
194:                    //                                 SwingUtilities.invokeLater(
195:                    //                                     new Runnable() {
196:                    //                                         public void run() {
197:                    //                                             if (c2 != null) {
198:                    //                                                 BaseDocument doc = Utilities.getDocument(c2);
199:                    //                                                 if( doc != null ) {
200:                    //                                                     doc.readLock();
201:                    //                                                     try {
202:                    //                                                         updateMatchBrace();
203:                    //                                                     } finally {
204:                    //                                                         doc.readUnlock();
205:                    //                                                     }
206:                    //                                                 }
207:                    //                                             }
208:                    //                                         }
209:                    //                                     }
210:                    //                                 );
211:                    //                             }
212:                    //                         };
213:                    //                         
214:                    //                    braceTimer.addActionListener(new WeakTimerListener(braceTimerListener));
215:                    //                    braceTimer.setRepeats(false);
216:                    //                } else {
217:                    //                    braceTimer = null; // signal no delay
218:                    //                }
219:                    //                c.repaint();
220:                    //            }
221:                    //
222:                    //            simpleMatchBrace = SettingsUtil.getBoolean(kitClass,
223:                    //                                    ExtSettingsNames.CARET_SIMPLE_MATCH_BRACE,
224:                    //                                    ExtSettingsDefaults.defaultCaretSimpleMatchBrace);
225:                    //            
226:                }
227:            }
228:
229:            // XXX: remove
230:            //    public void install(JTextComponent c) {
231:            //        EditorUI editorUI = Utilities.getEditorUI(c);
232:            //        editorUI.addLayer(new HighlightBraceLayer(), HIGHLIGHT_BRACE_LAYER_VISIBILITY);
233:            //        super.install(c);
234:            //    }
235:            //
236:            //    public void deinstall(JTextComponent c) {
237:            //        EditorUI editorUI = Utilities.getEditorUI(c);
238:            //        editorUI.removeLayer(HIGHLIGHT_BRACE_LAYER_NAME);
239:            //        super.deinstall(c);
240:            //    }
241:            //    
242:            //    /** Set the match brace offset.
243:            //     * @param offset One of <code>MATCH_BRACE_BEFORE</code>,
244:            //     * <code>MATCH_BRACE_AFTER</code> * or <code>MATCH_BRACE_EITHER</code>.
245:            //     */
246:            //    public void setMatchBraceOffset(int offset) {
247:            //        if(offset != MATCH_BRACE_BEFORE && offset != MATCH_BRACE_AFTER
248:            //           && offset != MATCH_BRACE_EITHER) {
249:            //            throw new IllegalArgumentException("Offset "+ offset + " not allowed\n");
250:            //        }
251:            //        matchBraceOffset = offset;
252:            //        BaseDocument doc = Utilities.getDocument(component);
253:            //        if( doc != null ) {
254:            //            doc.readLock();
255:            //            try {
256:            //                updateMatchBrace();
257:            //            } finally {
258:            //                doc.readUnlock();
259:            //            }
260:            //        }
261:            //    }
262:            //    
263:            //    /** Fetch the match brace offset. */
264:            //    public int getMatchBraceOffset() {
265:            //        return matchBraceOffset;
266:            //    }
267:
268:            /** 
269:             * Update the matching brace of the caret. The document is read-locked
270:             * while this method is called.
271:             * 
272:             * @deprecated Please use Braces Matching SPI instead, for details see
273:             *   <a href="@org-netbeans-modules-editor-bracesmatching@/overview-summary.html">Editor Braces Matching</a>.
274:             */
275:            protected void updateMatchBrace() {
276:                // XXX: remove
277:                //        JTextComponent c = component;
278:                //        if (c != null && highlightBrace) {
279:                //            try {
280:                //                EditorUI editorUI = Utilities.getEditorUI(c);
281:                //                BaseDocument doc = (BaseDocument)c.getDocument();
282:                //                int dotPos = getDot();
283:                //                ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport();
284:                //                boolean madeValid = false; // whether brace marks display were validated
285:                //                int[] matchBlk = null;
286:                //                if(dotPos > 0 && (matchBraceOffset == MATCH_BRACE_BEFORE
287:                //                                  || matchBraceOffset == MATCH_BRACE_EITHER)) {
288:                //                    matchBlk = sup.findMatchingBlock(dotPos - 1, simpleMatchBrace);
289:                //                }
290:                //                if(matchBlk == null && (matchBraceOffset == MATCH_BRACE_AFTER
291:                //                                        || matchBraceOffset == MATCH_BRACE_EITHER)) {
292:                //                    matchBlk = sup.findMatchingBlock(dotPos, simpleMatchBrace);
293:                //                }
294:                //                if (matchBlk != null) {
295:                //                    if (highlightBraceStartMark != null) {
296:                //                        int markStartPos = highlightBraceStartMark.getOffset();
297:                //                        int markEndPos = highlightBraceEndMark.getOffset();
298:                //                        if (markStartPos != matchBlk[0] || markEndPos != matchBlk[1]) {
299:                //                            editorUI.repaintBlock(markStartPos, markEndPos);
300:                //                            Utilities.moveMark(doc, highlightBraceStartMark, matchBlk[0]);
301:                //                            Utilities.moveMark(doc, highlightBraceEndMark, matchBlk[1]);
302:                //                            editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
303:                //                        } else { // on the same position
304:                //                            if (!braceMarksValid) { // was not valid, must repaint
305:                //                                editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
306:                //                            }
307:                //                        }
308:                //                    } else { // highlight mark is null
309:                //                        highlightBraceStartMark = new MarkFactory.DrawMark(
310:                //                                                    HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
311:                //                        highlightBraceEndMark = new MarkFactory.DrawMark(
312:                //                                                    HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
313:                //                        highlightBraceStartMark.setActivateLayer(true);
314:                //                        Utilities.insertMark(doc, highlightBraceStartMark, matchBlk[0]);
315:                //                        Utilities.insertMark(doc, highlightBraceEndMark, matchBlk[1]);
316:                //                        editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
317:                //                    }
318:                //                    braceMarksValid = true;
319:                //                    madeValid = true;
320:                //                }
321:                //
322:                //                if (!madeValid) {
323:                //                    if (braceMarksValid) {
324:                //                        braceMarksValid = false;
325:                //                        editorUI.repaintBlock(highlightBraceStartMark.getOffset(),
326:                //                                highlightBraceEndMark.getOffset());
327:                //                    }
328:                //                }
329:                //            } catch (BadLocationException e) {
330:                //                Utilities.annotateLoggable(e);
331:                //                highlightBrace = false;
332:                //            } catch (InvalidMarkException e) {
333:                //                Utilities.annotateLoggable(e);
334:                //                highlightBrace = false;
335:                //            }
336:                //        }
337:            }
338:
339:            // XXX: remove
340:            //    protected void update(boolean scrollViewToCaret) {
341:            //        if (highlightBrace) {
342:            //            if (matchBraceUpdateSync || braceTimer == null) {
343:            //                updateMatchBrace();
344:            //                matchBraceUpdateSync = false;
345:            //
346:            //            } else { // delay the brace update
347:            //                braceTimer.restart();
348:            //            }
349:            //        }
350:            //
351:            //        super.update(scrollViewToCaret);
352:            //    }
353:
354:            /** 
355:             * Signal that the next matching brace update
356:             * will be immediate without waiting for the brace
357:             * timer to fire the action. This is usually done
358:             * for the key-typed action.
359:             * 
360:             * @deprecated Please use Braces Matching SPI instead, for details see
361:             *   <a href="@org-netbeans-modules-editor-bracesmatching@/overview-summary.html">Editor Braces Matching</a>.
362:             */
363:            public void requestMatchBraceUpdateSync() {
364:                // XXX: remove
365:                //        matchBraceUpdateSync = true;
366:            }
367:
368:            // XXX: remove
369:            //    /* package */ static boolean NO_HIGHLIGHT_BRACE_LAYER = Boolean.getBoolean("nbeditor-no-HighlightBraceLayer");
370:            //    
371:            //    /** 
372:            //     * Draw layer to highlight the matching brace.
373:            //     * 
374:            //     * XXX: The HighlightBraceLayer needs to be rewritten using the new Highlighting SPI.
375:            //     */
376:            //    class HighlightBraceLayer extends DrawLayer.AbstractLayer {
377:            //
378:            //        public HighlightBraceLayer() {
379:            //            super(HIGHLIGHT_BRACE_LAYER_NAME);
380:            //        }
381:            //
382:            //        public void init(DrawContext ctx) {
383:            //        }
384:            //
385:            //        public boolean isActive(DrawContext ctx, MarkFactory.DrawMark mark) {
386:            //            if (!NO_HIGHLIGHT_BRACE_LAYER && braceMarksValid) {
387:            //                if (mark != null)
388:            //                    return mark.getActivateLayer();
389:            //                try {
390:            //                    if (ctx.getStartOffset() > highlightBraceEndMark.getOffset())
391:            //                        return highlightBraceEndMark.getActivateLayer();
392:            //                    if (ctx.getStartOffset() > highlightBraceStartMark.getOffset())
393:            //                        return highlightBraceStartMark.getActivateLayer();
394:            //                } catch (InvalidMarkException ex) {                    
395:            //                }
396:            //            }
397:            //
398:            //            return false;
399:            //        }
400:            //
401:            //        public void updateContext(DrawContext ctx) {
402:            //            if (!NO_HIGHLIGHT_BRACE_LAYER && highlightBraceColoring != null) {
403:            //                highlightBraceColoring.apply(ctx);
404:            //            }
405:            //        }
406:            //
407:            //    }
408:
409:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.