Source Code Cross Referenced for MoeSyntaxDocument.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 javax.swing.text.*;
012:
013:        import java.awt.Color;
014:        import bluej.Config;
015:
016:        import org.syntax.jedit.*;
017:        import org.syntax.jedit.tokenmarker.*;
018:
019:        /**
020:         * A simple implementation of <code>SyntaxDocument</code> that 
021:         * inherits from SyntaxDocument. It takes
022:         * care of inserting and deleting lines from the token marker's state.
023:         * It adds the ability to handle paragraph attributes on a per line basis.
024:         *
025:         * @author Bruce Quig
026:         * @author Jo Wood (Modified to allow user-defined colours, March 2001)
027:         *
028:         */
029:        public class MoeSyntaxDocument extends SyntaxDocument {
030:            public static final String OUTPUT = "output";
031:            public static final String ERROR = "error";
032:
033:            private static Color[] colors = null;
034:
035:            private static Color defaultColour = null;
036:            private static Color backgroundColour = null;
037:
038:            public MoeSyntaxDocument() {
039:                super (getUserColors());
040:                // defaults to 4 if cannot read property
041:                int tabSize = Config.getPropInteger("bluej.editor.tabsize", 4);
042:                putProperty(tabSizeAttribute, new Integer(tabSize));
043:            }
044:
045:            /**
046:             * Sets attributes for a paragraph.  This method was added to 
047:             * provide the ability to replicate DefaultStyledDocument's ability to 
048:             * set each lines attributes easily.
049:             * This is an added method for the BlueJ adaption of jedit's Syntax
050:             * package   
051:             *
052:             * @param offset the offset into the paragraph >= 0
053:             * @param length the number of characters affected >= 0
054:             * @param s the attributes
055:             * @param replace whether to replace existing attributes, or merge them
056:             */
057:            public void setParagraphAttributes(int offset, AttributeSet s) {
058:                // modified version of method from DefaultStyleDocument
059:                try {
060:                    writeLock();
061:
062:                    Element paragraph = getParagraphElement(offset);
063:                    MutableAttributeSet attr = (MutableAttributeSet) paragraph
064:                            .getAttributes();
065:                    attr.addAttributes(s);
066:                } finally {
067:                    writeUnlock();
068:                }
069:            }
070:
071:            /**
072:             * Get the default colour for MoeSyntaxDocuments.
073:             */
074:            public static Color getDefaultColor() {
075:                return defaultColour;
076:            }
077:
078:            /**
079:             * Get the background colour for MoeSyntaxDocuments.
080:             */
081:            public static Color getBackgroundColor() {
082:                return backgroundColour;
083:            }
084:
085:            /**
086:             * Allows user-defined colours to be set for synax highlighting. The file
087:             * containing the colour values is 'lib/moe.defs'. If this file is
088:             * not found, or not all colours are defined, the BlueJ default colours are
089:             * used.
090:             * 
091:             * @author This method was added by Jo Wood (jwo@soi.city.ac.uk), 9th March,
092:             *         2001.
093:             */
094:            private static Color[] getUserColors() {
095:                if (colors == null) {
096:                    // Replace with user-defined colours.
097:                    int colorInt;
098:
099:                    // First determine default colour and background colour
100:                    colorInt = getPropHexInt("other", 0x000000);
101:                    defaultColour = new Color(colorInt);
102:
103:                    colorInt = getPropHexInt("background", 0x000000);
104:                    backgroundColour = new Color(colorInt);
105:
106:                    // Build colour table.	   
107:                    colors = new Color[Token.ID_COUNT];
108:
109:                    // Comments.
110:                    colorInt = getPropHexInt("comment", 0x1a1a80);
111:                    colors[Token.COMMENT1] = new Color(colorInt);
112:
113:                    // Javadoc comments.
114:                    colorInt = getPropHexInt("javadoc", 0x1a1a80);
115:                    colors[Token.COMMENT2] = new Color(colorInt);
116:
117:                    // Stand-out comments (/*#).
118:                    colorInt = getPropHexInt("stand-out", 0xee00bb);
119:                    colors[Token.COMMENT3] = new Color(colorInt);
120:
121:                    // Java keywords.
122:                    colorInt = getPropHexInt("keyword1", 0x660033);
123:                    colors[Token.KEYWORD1] = new Color(colorInt);
124:
125:                    // Class-based keywords.
126:                    colorInt = getPropHexInt("keyword2", 0xcc8033);
127:                    colors[Token.KEYWORD2] = new Color(colorInt);
128:
129:                    // Other Java keywords (true, false, this, super).
130:                    colorInt = getPropHexInt("keyword3", 0x006699);
131:                    colors[Token.KEYWORD3] = new Color(colorInt);
132:
133:                    // Primitives.
134:                    colorInt = getPropHexInt("primitive", 0xcc0000);
135:                    colors[Token.PRIMITIVE] = new Color(colorInt);
136:
137:                    // String literals.
138:                    colorInt = getPropHexInt("string", 0x339933);
139:                    colors[Token.LITERAL1] = new Color(colorInt);
140:
141:                    // Labels
142:                    colorInt = getPropHexInt("label", 0x999999);
143:                    colors[Token.LABEL] = new Color(colorInt);
144:
145:                    // Invalid (eg unclosed string literal)
146:                    colorInt = getPropHexInt("invalid", 0xff3300);
147:                    colors[Token.INVALID] = new Color(colorInt);
148:
149:                    // Operator is not produced by token marker
150:                    colors[Token.OPERATOR] = new Color(0xcc9900);
151:                }
152:                return colors;
153:            }
154:
155:            /**
156:             * Get an integer value from a property whose value is hex-encoded.
157:             * @param propName  The name of the property
158:             * @param def       The default value if the property is undefined or
159:             *                  not parseable as a hexadecimal
160:             * @return  The value
161:             */
162:            private static int getPropHexInt(String propName, int def) {
163:                String strVal = Config.getPropString(propName, null,
164:                        Config.moeUserProps);
165:                try {
166:                    return Integer.parseInt(strVal, 16);
167:                } catch (NumberFormatException nfe) {
168:                    return def;
169:                }
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.