Source Code Cross Referenced for MarkChain.java in  » Swing-Library » abeille-forms-designer » org » netbeans » editor » 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 » Swing Library » abeille forms designer » org.netbeans.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *                 Sun Public License Notice
003:         * 
004:         * The contents of this file are subject to the Sun Public License
005:         * Version 1.0 (the "License"). You may not use this file except in
006:         * compliance with the License. A copy of the License is available at
007:         * http://www.sun.com/
008:         * 
009:         * The Original Code is NetBeans. The Initial Developer of the Original
010:         * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011:         * Microsystems, Inc. All Rights Reserved.
012:         */
013:
014:        package org.netbeans.editor;
015:
016:        import javax.swing.text.BadLocationException;
017:
018:        /**
019:         * Support class for chain of MarkBlocks
020:         * 
021:         * @author Miloslav Metelka
022:         * @version 1.00
023:         */
024:
025:        public class MarkChain {
026:
027:            /** Chain of all marks */
028:            protected MarkFactory.ChainDrawMark chain;
029:
030:            /** Current mark to make checks faster */
031:            protected MarkFactory.ChainDrawMark curMark;
032:
033:            /** Document for this mark */
034:            protected BaseDocument doc;
035:
036:            /**
037:             * If this chain uses draw marks, then this is the name for the draw layer
038:             * that will be used for the marks
039:             */
040:            protected String layerName;
041:
042:            /**
043:             * The mark created by addMark() method is stored in this variable. In case
044:             * the mark was not created, because there already was some on this
045:             * position, the already existing mark is returned.
046:             */
047:            private MarkFactory.ChainDrawMark recentlyAddedMark;
048:
049:            /** Construct chain using draw marks */
050:            public MarkChain(BaseDocument doc, String layerName) {
051:                this .doc = doc;
052:                this .layerName = layerName;
053:            }
054:
055:            public final MarkFactory.ChainDrawMark getChain() {
056:                return chain;
057:            }
058:
059:            public final MarkFactory.ChainDrawMark getCurMark() {
060:                return curMark;
061:            }
062:
063:            /**
064:             * Tests whether the position range is partly or fully inside some mark
065:             * block from the chain.
066:             * 
067:             * @param pos
068:             *            compared position
069:             * @return relation of curMark to the given position
070:             */
071:            public int compareMark(int pos) {
072:                try {
073:                    if (curMark == null) {
074:                        curMark = chain;
075:                        if (curMark == null) {
076:                            return -1; // no marks yet
077:                        }
078:                    }
079:
080:                    int rel;
081:                    boolean after = false;
082:                    boolean before = false;
083:                    while ((rel = curMark.compare(pos)) != 0) { // just match
084:                        if (rel > 0) { // this mark after pos
085:                            if (before) {
086:                                return rel;
087:                            }
088:                            if (curMark.prev != null) {
089:                                after = true;
090:                                curMark = curMark.prev;
091:                            } else { // end of chain
092:                                return rel;
093:                            }
094:                        } else { // this mark before pos
095:                            if (after) {
096:                                return rel;
097:                            }
098:                            if (curMark.next != null) {
099:                                before = true;
100:                                curMark = curMark.next;
101:                            } else { // start of chain
102:                                return rel;
103:                            }
104:                        }
105:                    }
106:                    return 0; // match
107:                } catch (InvalidMarkException e) {
108:                    if (Boolean.getBoolean("netbeans.debug.exceptions")) { // NOI18N
109:                        e.printStackTrace();
110:                    }
111:                    return -1; // don't match, but what to return?
112:                }
113:            }
114:
115:            protected MarkFactory.ChainDrawMark createAndInsertNewMark(int pos)
116:                    throws BadLocationException {
117:                MarkFactory.ChainDrawMark mark = createMark();
118:                try {
119:                    doc.op.insertMark(mark, pos);
120:                } catch (InvalidMarkException e) {
121:                    if (Boolean.getBoolean("netbeans.debug.exceptions")) { // NOI18N
122:                        e.printStackTrace();
123:                    }
124:                }
125:                return mark;
126:            }
127:
128:            protected MarkFactory.ChainDrawMark createMark() {
129:                MarkFactory.ChainDrawMark mark = new MarkFactory.ChainDrawMark(
130:                        layerName, null);
131:                mark.backwardBias = true; // stay at line begining
132:                mark.activateLayer = true;
133:                return mark;
134:            }
135:
136:            /**
137:             * Add mark to the chain
138:             * 
139:             * @return true if the mark was added false if there's already mark at that
140:             *         pos
141:             */
142:            public boolean addMark(int pos) throws BadLocationException {
143:                int rel = compareMark(pos);
144:                if (rel == 0) {
145:                    recentlyAddedMark = curMark;
146:                    return false; // already exists
147:                } else if (rel > 0) { // curMark after pos
148:                    MarkFactory.ChainDrawMark mark = createAndInsertNewMark(pos);
149:                    recentlyAddedMark = mark;
150:                    if (curMark != null) {
151:                        if (curMark == chain) { // curMark is first mark
152:                            chain = curMark.insertChain(mark);
153:                        } else { // curMark is not first mark
154:                            curMark.insertChain(mark);
155:                        }
156:                    } else { // no marks in chain
157:                        chain = mark;
158:                    }
159:                } else { // curMark before pos
160:                    MarkFactory.ChainDrawMark mark = createAndInsertNewMark(pos);
161:                    recentlyAddedMark = mark;
162:                    if (curMark != null) {
163:                        if (curMark.next != null) {
164:                            curMark.next.insertChain(mark);
165:                        } else { // last mark in chain
166:                            curMark.setNextChain(mark);
167:                        }
168:                    } else { // no marks in chain
169:                        chain = mark;
170:                    }
171:                }
172:                return true;
173:            }
174:
175:            /**
176:             * The mark created by addMark() method is returned by this method. In case
177:             * the mark was not created, because there already was some on requested
178:             * position, the already existing mark is returned.
179:             */
180:            public MarkFactory.ChainDrawMark getAddedMark() {
181:                return recentlyAddedMark;
182:            }
183:
184:            /** Remove non-empty block from area covered by blocks from chain */
185:            public boolean removeMark(int pos) {
186:                int rel = compareMark(pos);
187:                if (rel == 0) {
188:                    boolean first = (curMark == chain);
189:                    curMark = curMark.removeChain();
190:                    if (first) {
191:                        chain = curMark;
192:                    }
193:                    return true;
194:                } else { // not found
195:                    return false;
196:                }
197:            }
198:
199:            /** Is there mark at given position? */
200:            public boolean isMark(int pos) {
201:                return (compareMark(pos) == 0);
202:            }
203:
204:            /**
205:             * Toggle the mark so that if it didn't exist it is created and if it
206:             * existed it's removed
207:             * 
208:             * @return true if the new mark was added false if the existing mark was
209:             *         removed
210:             */
211:            public boolean toggleMark(int pos) throws BadLocationException {
212:                int rel = compareMark(pos);
213:                if (rel == 0) { // exists
214:                    removeMark(pos);
215:                    return false;
216:                } else { // didn't exist
217:                    addMark(pos);
218:                    return true;
219:                }
220:            }
221:
222:            public String toString() {
223:                return "MarkChain: curMark=" + curMark
224:                        + ", mark chain: " // NOI18N
225:                        + (chain != null ? ("\n" + chain.toStringChain())
226:                                : "Empty"); // NOI18N
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.