KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > indent > OpenBracketIndentRule


1 /*
2  * OpenBracketIndentRule.java
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2005 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.indent;
24
25 import java.util.List JavaDoc;
26 import org.gjt.sp.jedit.buffer.JEditBuffer;
27 import org.gjt.sp.jedit.TextUtilities;
28
29 /**
30  * @author Slava Pestov
31  * @version $Id: OpenBracketIndentRule.java 5579 2006-07-13 10:53:15Z kpouer $
32  */

33 public class OpenBracketIndentRule extends BracketIndentRule
34 {
35     //{{{ OpenBracketIndentRule constructor
36
public OpenBracketIndentRule(char openBracket, boolean aligned)
37     {
38         super(openBracket,
39             TextUtilities.getComplementaryBracket(openBracket,
40             new boolean[1]));
41         this.aligned = aligned;
42     } //}}}
43

44     //{{{ apply() method
45
public void apply(JEditBuffer buffer, int thisLineIndex,
46         int prevLineIndex, int prevPrevLineIndex,
47         List JavaDoc<IndentAction> indentActions)
48     {
49         int prevOpenBracketCount = getOpenBracketCount(buffer,prevLineIndex);
50         if(prevOpenBracketCount != 0)
51         {
52             handleCollapse(indentActions);
53             boolean multiple = buffer.getBooleanProperty(
54                 "multipleBracketIndent");
55             IndentAction increase = new IndentAction.Increase(
56                 multiple ? prevOpenBracketCount : 1);
57             indentActions.add(increase);
58         }
59         else if(getOpenBracketCount(buffer,thisLineIndex) != 0)
60         {
61             handleCollapse(indentActions);
62         }
63     } //}}}
64

65     //{{{ getOpenBracketCount() method
66
private int getOpenBracketCount(JEditBuffer buffer, int line)
67     {
68         if(line == -1)
69             return 0;
70         else
71             return getBrackets(buffer.getLineText(line)).openCount;
72     } //}}}
73

74     //{{{ handleCollapse() method
75
private static void handleCollapse(List JavaDoc<IndentAction> indentActions)
76     {
77         if(indentActions.contains(new IndentAction.Collapse()))
78             indentActions.clear();
79     } //}}}
80

81     private boolean aligned;
82 }
83
Popular Tags