01: /*
02: * OpenBracketIndentRule.java
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 2005 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * 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;
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 9524 2007-05-10 14:51:01Z k_satoda $
32: */
33: public class OpenBracketIndentRule extends BracketIndentRule {
34: //{{{ OpenBracketIndentRule constructor
35: public OpenBracketIndentRule(char openBracket, boolean aligned) {
36: super (openBracket, TextUtilities.getComplementaryBracket(
37: openBracket, null));
38: this .aligned = aligned;
39: } //}}}
40:
41: //{{{ apply() method
42: public void apply(JEditBuffer buffer, int this LineIndex,
43: int prevLineIndex, int prevPrevLineIndex,
44: List<IndentAction> indentActions) {
45: int prevOpenBracketCount = getOpenBracketCount(buffer,
46: prevLineIndex);
47: if (prevOpenBracketCount != 0) {
48: handleCollapse(indentActions, true);
49: boolean multiple = buffer
50: .getBooleanProperty("multipleBracketIndent");
51: IndentAction increase = new IndentAction.Increase(
52: multiple ? prevOpenBracketCount : 1);
53: indentActions.add(increase);
54: } else if (getOpenBracketCount(buffer, this LineIndex) != 0) {
55: handleCollapse(indentActions, false);
56: }
57: } //}}}
58:
59: //{{{ getOpenBracketCount() method
60: private int getOpenBracketCount(JEditBuffer buffer, int line) {
61: if (line == -1)
62: return 0;
63: else
64: return getBrackets(buffer, line).openCount;
65: } //}}}
66:
67: //{{{ handleCollapse() method
68: private static void handleCollapse(
69: List<IndentAction> indentActions,
70: boolean delPrevPrevCollapse) {
71: if (indentActions.contains(IndentAction.PrevCollapse)) {
72: indentActions.clear();
73: return;
74: }
75:
76: if (delPrevPrevCollapse
77: && indentActions
78: .contains(IndentAction.PrevPrevCollapse)) {
79: indentActions.clear();
80: return;
81: }
82: } //}}}
83:
84: private boolean aligned;
85: }
|