Source Code Cross Referenced for CloseBracketIndentRule.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:         * CloseBracketIndentRule.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 java.util.List;
026:        import org.gjt.sp.jedit.buffer.JEditBuffer;
027:        import org.gjt.sp.jedit.TextUtilities;
028:        import org.gjt.sp.util.StandardUtilities;
029:
030:        /**
031:         * @author Slava Pestov
032:         * @version $Id: CloseBracketIndentRule.java 9524 2007-05-10 14:51:01Z k_satoda $
033:         */
034:        public class CloseBracketIndentRule extends BracketIndentRule {
035:            //{{{ CloseBracketIndentRule constructor
036:            public CloseBracketIndentRule(char closeBracket, boolean aligned) {
037:                super (
038:                        TextUtilities.getComplementaryBracket(closeBracket,
039:                                null), closeBracket);
040:                this .aligned = aligned;
041:            } //}}}
042:
043:            //{{{ apply() method
044:            public void apply(JEditBuffer buffer, int this LineIndex,
045:                    int prevLineIndex, int prevPrevLineIndex,
046:                    List<IndentAction> indentActions) {
047:                int index;
048:                if (aligned)
049:                    index = this LineIndex;
050:                else
051:                    index = prevLineIndex;
052:
053:                if (index == -1)
054:                    return;
055:
056:                int offset = buffer.getLineText(index)
057:                        .lastIndexOf(closeBracket);
058:                if (offset == -1)
059:                    return;
060:
061:                int closeCount = getBrackets(buffer, index).closeCount;
062:                if (closeCount != 0) {
063:                    AlignBracket alignBracket = new AlignBracket(buffer, index,
064:                            offset);
065:                    /*
066:                    Consider the following Common Lisp code (with one more opening
067:                    bracket than closing):
068:
069:                    (defun emit-push-long (arg)
070:                      (cond ((eql arg 0)
071:                          (emit 'lconst_0))
072:                        ((eql arg 1)
073:                          (emit 'lconst_1)))
074:
075:                    even though we have a closing bracket match on line 3,
076:                    the next line must be indented relative to the
077:                    corresponding opening bracket from line 1.
078:                     */
079:                    int openLine = alignBracket.getOpenBracketLine();
080:                    if (openLine != -1) {
081:                        int column = alignBracket.getOpenBracketColumn();
082:                        alignBracket.setExtraIndent(getBrackets(buffer,
083:                                openLine, 0, column).openCount);
084:                    }
085:
086:                    indentActions.add(alignBracket);
087:                }
088:            } //}}}
089:
090:            //{{{ isMatch() method
091:            /**
092:             * @deprecated
093:             *   This method calls BracketIndentRule#getBrackets(String)
094:             *   which has been deprecated.
095:             */
096:            @Deprecated
097:            public boolean isMatch(String line) {
098:                return getBrackets(line).closeCount != 0;
099:            } //}}}
100:
101:            private boolean aligned;
102:
103:            //{{{ AlignBracket class
104:            private static class AlignBracket implements  IndentAction {
105:                private int line, offset;
106:                private int openBracketLine;
107:                private int openBracketColumn;
108:                private String openBracketLineText;
109:                private int extraIndent;
110:
111:                public AlignBracket(JEditBuffer buffer, int line, int offset) {
112:                    this .line = line;
113:                    this .offset = offset;
114:
115:                    int openBracketIndex = TextUtilities.findMatchingBracket(
116:                            buffer, this .line, this .offset);
117:                    if (openBracketIndex == -1)
118:                        openBracketLine = -1;
119:                    else {
120:                        openBracketLine = buffer
121:                                .getLineOfOffset(openBracketIndex);
122:                        openBracketColumn = openBracketIndex
123:                                - buffer.getLineStartOffset(openBracketLine);
124:                        openBracketLineText = buffer
125:                                .getLineText(openBracketLine);
126:                    }
127:                }
128:
129:                public int getExtraIndent() {
130:                    return extraIndent;
131:                }
132:
133:                public void setExtraIndent(int extraIndent) {
134:                    this .extraIndent = extraIndent;
135:                }
136:
137:                public int getOpenBracketColumn() {
138:                    return openBracketColumn;
139:                }
140:
141:                public int getOpenBracketLine() {
142:                    return openBracketLine;
143:                }
144:
145:                public int calculateIndent(JEditBuffer buffer, int line,
146:                        int oldIndent, int newIndent) {
147:                    if (openBracketLineText == null)
148:                        return newIndent;
149:                    else {
150:                        return StandardUtilities.getLeadingWhiteSpaceWidth(
151:                                openBracketLineText, buffer.getTabSize())
152:                                + (extraIndent * buffer.getIndentSize());
153:                    }
154:                }
155:
156:                public boolean keepChecking() {
157:                    return false;
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.