Source Code Cross Referenced for IndentAction.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » indent » 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 » jEdit » org.gjt.sp.jedit.indent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IndentAction.java
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2005 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.indent;
024:
025:        import org.gjt.sp.jedit.buffer.JEditBuffer;
026:        import org.gjt.sp.jedit.TextUtilities;
027:        import org.gjt.sp.util.StandardUtilities;
028:
029:        /**
030:         * @author Slava Pestov
031:         * @version $Id: IndentAction.java 9524 2007-05-10 14:51:01Z k_satoda $
032:         */
033:        public interface IndentAction {
034:            /**
035:             * @param buffer The buffer
036:             * @param line The line number that matched the rule; not necessarily
037:             * the line being indented.
038:             * @param oldIndent Original indent.
039:             * @param newIndent The new indent -- ie, indent returned by previous
040:             * indent action.
041:             */
042:            int calculateIndent(JEditBuffer buffer, int line, int oldIndent,
043:                    int newIndent);
044:
045:            /**
046:             * @return true if the indent engine should keep processing after
047:             * this rule.
048:             */
049:            boolean keepChecking();
050:
051:            /** See comments for each instance of this class below. */
052:            class Collapse implements  IndentAction {
053:                /**
054:                 * This does nothing; it is merely a sentinel for the
055:                 * <code>OpenBracketIndentRule</code>.
056:                 */
057:                public int calculateIndent(JEditBuffer buffer, int line,
058:                        int oldIndent, int newIndent) {
059:                    return newIndent;
060:                }
061:
062:                public boolean keepChecking() {
063:                    return true;
064:                }
065:
066:                private Collapse() {
067:                }
068:            }
069:
070:            class Reset implements  IndentAction {
071:                public int calculateIndent(JEditBuffer buffer, int line,
072:                        int oldIndent, int newIndent) {
073:                    return oldIndent;
074:                }
075:
076:                public boolean keepChecking() {
077:                    return true;
078:                }
079:            }
080:
081:            class Increase implements  IndentAction {
082:                private int amount;
083:
084:                public Increase() {
085:                    amount = 1;
086:                }
087:
088:                public Increase(int amount) {
089:                    this .amount = amount;
090:                }
091:
092:                public int calculateIndent(JEditBuffer buffer, int line,
093:                        int oldIndent, int newIndent) {
094:                    return newIndent + buffer.getIndentSize() * amount;
095:                }
096:
097:                public boolean keepChecking() {
098:                    return true;
099:                }
100:
101:                public boolean equals(Object o) {
102:                    if (o instanceof  Increase)
103:                        return ((Increase) o).amount == amount;
104:                    else
105:                        return false;
106:                }
107:            }
108:
109:            class Decrease implements  IndentAction {
110:                public int calculateIndent(JEditBuffer buffer, int line,
111:                        int oldIndent, int newIndent) {
112:                    return newIndent - buffer.getIndentSize();
113:                }
114:
115:                public boolean keepChecking() {
116:                    return true;
117:                }
118:            }
119:
120:            /**
121:             * @author Matthieu Casanova
122:             */
123:            class AlignOffset implements  IndentAction {
124:                private int offset;
125:
126:                public AlignOffset(int offset) {
127:                    this .offset = offset;
128:                }
129:
130:                public int calculateIndent(JEditBuffer buffer, int line,
131:                        int oldIndent, int newIndent) {
132:                    return offset;
133:                }
134:
135:                public boolean keepChecking() {
136:                    return false;
137:                }
138:            }
139:
140:            /**
141:             * Indent action used for deep indent.
142:             * @author Matthieu Casanova
143:             */
144:            class AlignParameter implements  IndentAction {
145:                private int openParensColumn;
146:                private String openParensLineText;
147:
148:                public AlignParameter(int openParensColumn,
149:                        String openParensLineText) {
150:                    this .openParensLineText = openParensLineText;
151:                    this .openParensColumn = openParensColumn;
152:                }
153:
154:                public int calculateIndent(JEditBuffer buffer, int line,
155:                        int oldIndent, int newIndent) {
156:                    return openParensLineText == null ? newIndent
157:                            : openParensColumn + 1;
158:                }
159:
160:                public boolean keepChecking() {
161:                    return false;
162:                }
163:            }
164:
165:            /**
166:             * Used to cancel increases in indentation.
167:             *
168:             * @author Marcelo Vanzin
169:             */
170:            class NoIncrease implements  IndentAction {
171:                public int calculateIndent(JEditBuffer buffer, int line,
172:                        int oldIndent, int newIndent) {
173:                    int current = StandardUtilities.getLeadingWhiteSpaceWidth(
174:                            buffer.getLineText(line), buffer.getTabSize());
175:                    return (current < newIndent) ? current : newIndent;
176:                }
177:
178:                public boolean keepChecking() {
179:                    return true;
180:                }
181:            }
182:
183:            /**
184:             * This handles the following Java code:
185:             * if(something)
186:             * { // no indentation on this line, even though previous matches a rule
187:             */
188:            Collapse PrevCollapse = new Collapse();
189:            /**
190:             * This handles cases like:
191:             * if (foo)
192:             *     bar;
193:             * for (something; condition; action) {
194:             * }
195:             * Without this the "for" line would be incorrectly indented.
196:             */
197:            Collapse PrevPrevCollapse = new Collapse();
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.