Source Code Cross Referenced for MoeCaret.java in  » IDE » bluej-editor » bluej » editor » moe » 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 » bluej editor » bluej.editor.moe 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
002:        //
003:        // This software is made available under the terms of the "MIT License"
004:        // A copy of this license is included with this source distribution
005:        // in "license.txt" and is also available at:
006:        // http://www.opensource.org/licenses/mit-license.html 
007:        // Any queries should be directed to Michael Kolling mik@bluej.org
008:
009:        package bluej.editor.moe;
010:
011:        import bluej.utility.Debug;
012:
013:        import java.awt.*;
014:        import java.awt.event.*;
015:
016:        import javax.swing.text.*;
017:
018:        /**
019:         * A customised caret for Moe. It gets most of its bahaviour from
020:         * Swing's "DefaultCaret" and adds some functionality.
021:         *
022:         * @author  Michael Kolling
023:         */
024:
025:        public class MoeCaret extends DefaultCaret {
026:            private static final Color bracketHighlightColour = new Color(196,
027:                    196, 196);
028:
029:            private static final LayeredHighlighter.LayerPainter bracketPainter = new BracketMatchPainter(
030:                    bracketHighlightColour);
031:
032:            private MoeEditor editor;
033:
034:            private boolean persistentHighlight = false;
035:
036:            // matching bracket highlight holder
037:            private Object matchingBracketHighlight;
038:
039:            /**
040:             * Constructs a Moe Caret
041:             */
042:            public MoeCaret(MoeEditor editor) {
043:                super ();
044:                this .editor = editor;
045:                setBlinkRate(0);
046:            }
047:
048:            /**
049:             * Redefinition of caret positioning (after mouse click). Here, we
050:             * first check whether the click was in the tag line. If it was, we
051:             * toggle the breakpoint, if not we just position the caret as usual.
052:             */
053:            protected void positionCaret(MouseEvent e) {
054:                editor.caretMoved();
055:                Point pt = new Point(e.getX(), e.getY());
056:                Position.Bias[] biasRet = new Position.Bias[1];
057:                int pos = getComponent().getUI().viewToModel(getComponent(),
058:                        pt, biasRet);
059:
060:                if (e.getX() > BlueJSyntaxView.TAG_WIDTH) {
061:                    if (biasRet[0] == null)
062:                        biasRet[0] = Position.Bias.Forward;
063:                    if (pos >= 0) {
064:                        setDot(pos);
065:                        //                setMagicCaretPosition(null);
066:                    }
067:                } else {
068:                    editor.toggleBreakpoint(pos);
069:                }
070:            }
071:
072:            /**
073:             * Tries to move the position of the caret from
074:             * the coordinates of a mouse event, using viewToModel(). 
075:             * This will cause a selection if the dot and mark
076:             * are different.
077:             *
078:             * @param e the mouse event
079:             */
080:            protected void moveCaret(MouseEvent e) {
081:                if (e.getX() > BlueJSyntaxView.TAG_WIDTH) {
082:                    super .moveCaret(e);
083:                }
084:            }
085:
086:            /**
087:             * Set the dot and mark position
088:             */
089:            public void setDot(int pos) {
090:                persistentHighlight = false;
091:                super .setDot(pos);
092:            }
093:
094:            /**
095:             * Set the dot position (leave the mark where it is).
096:             */
097:            public void moveDot(int pos) {
098:                persistentHighlight = false;
099:                super .moveDot(pos);
100:            }
101:
102:            /**
103:             * Fire a state canged event.
104:             */
105:            protected void fireStateChanged() {
106:                editor.caretMoved();
107:                super .fireStateChanged();
108:            }
109:
110:            /**
111:             * Target text component lost focus.
112:             */
113:            public void focusLost(FocusEvent e) {
114:                super .focusLost(e);
115:                if (persistentHighlight)
116:                    setSelectionVisible(true);
117:            }
118:
119:            /**
120:             * Set the highlight (of the selection) as persistent - that is, it won't
121:             * become invisible if the component loses focus. This lasts until the
122:             * caret position is changed.
123:             */
124:            public void setPersistentHighlight() {
125:                setSelectionVisible(true);
126:                persistentHighlight = true;
127:            }
128:
129:            /**
130:             * paint matching bracket if caret is directly after a bracket  
131:             *
132:             */
133:            public void paintMatchingBracket() {
134:                int matchBracket = editor.getBracketMatch();
135:                // remove existing bracket if needed
136:                removeBracket();
137:                if (matchBracket != -1) {
138:                    try {
139:                        matchingBracketHighlight = getComponent()
140:                                .getHighlighter().addHighlight(matchBracket,
141:                                        matchBracket + 1, bracketPainter);
142:                    } catch (BadLocationException ble) {
143:                        Debug.reportError("bad location exception thrown");
144:                        ble.printStackTrace();
145:                    }
146:                }
147:            }
148:
149:            /**
150:             * remove the existing matching bracket if it exists
151:             */
152:            public void removeBracket() {
153:                if (matchingBracketHighlight != null) {
154:                    getComponent().getHighlighter().removeHighlight(
155:                            matchingBracketHighlight);
156:                    matchingBracketHighlight = null;
157:                }
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.