1 22 23 package org.gjt.sp.jedit.indent; 24 25 import org.gjt.sp.jedit.buffer.JEditBuffer; 26 import org.gjt.sp.jedit.TextUtilities; 27 import org.gjt.sp.util.StandardUtilities; 28 29 33 public interface IndentAction 34 { 35 43 int calculateIndent(JEditBuffer buffer, int line, int oldIndent, 44 int newIndent); 45 46 50 boolean keepChecking(); 51 52 57 class Collapse implements IndentAction 58 { 59 63 public int calculateIndent(JEditBuffer buffer, int line, int oldIndent, 64 int newIndent) 65 { 66 return newIndent; 67 } 68 69 public boolean keepChecking() 70 { 71 return true; 72 } 73 74 public boolean equals(Object o) 75 { 76 return (o instanceof Collapse); 77 } 78 } 79 80 class Reset implements IndentAction 81 { 82 public int calculateIndent(JEditBuffer buffer, int line, int oldIndent, 83 int newIndent) 84 { 85 return oldIndent; 86 } 87 88 public boolean keepChecking() 89 { 90 return true; 91 } 92 } 93 94 class Increase implements IndentAction 95 { 96 private int amount; 97 98 public Increase() 99 { 100 amount = 1; 101 } 102 103 public Increase(int amount) 104 { 105 this.amount = amount; 106 } 107 108 public int calculateIndent(JEditBuffer buffer, int line, int oldIndent, 109 int newIndent) 110 { 111 return newIndent + buffer.getIndentSize() * amount; 112 } 113 114 public boolean keepChecking() 115 { 116 return true; 117 } 118 119 public boolean equals(Object o) 120 { 121 if(o instanceof Increase) 122 return ((Increase)o).amount == amount; 123 else 124 return false; 125 } 126 } 127 128 class Decrease implements IndentAction 129 { 130 public int calculateIndent(JEditBuffer buffer, int line, int oldIndent, 131 int newIndent) 132 { 133 return newIndent - buffer.getIndentSize(); 134 } 135 136 public boolean keepChecking() 137 { 138 return true; 139 } 140 } 141 142 class AlignBracket implements IndentAction 143 { 144 private int line, offset; 145 private int openBracketLine; 146 private int openBracketColumn; 147 private String openBracketLineText; 148 private int extraIndent; 149 150 public AlignBracket(JEditBuffer buffer, int line, int offset) 151 { 152 this.line = line; 153 this.offset = offset; 154 155 int openBracketIndex = TextUtilities.findMatchingBracket( 156 buffer,this.line,this.offset); 157 if(openBracketIndex == -1) 158 openBracketLine = -1; 159 else 160 { 161 openBracketLine = buffer.getLineOfOffset(openBracketIndex); 162 openBracketColumn = openBracketIndex - 163 buffer.getLineStartOffset(openBracketLine); 164 openBracketLineText = buffer.getLineText(openBracketLine); 165 } 166 } 167 168 public int getExtraIndent() 169 { 170 return extraIndent; 171 } 172 173 public void setExtraIndent(int extraIndent) 174 { 175 this.extraIndent = extraIndent; 176 } 177 178 public int getOpenBracketColumn() 179 { 180 return openBracketColumn; 181 } 182 183 public String getOpenBracketLine() 184 { 185 return openBracketLineText; 186 } 187 188 public int calculateIndent(JEditBuffer buffer, int line, int oldIndent, 189 int newIndent) 190 { 191 if(openBracketLineText == null) 192 return newIndent; 193 else 194 { 195 return StandardUtilities.getLeadingWhiteSpaceWidth( 196 openBracketLineText,buffer.getTabSize()) 197 + (extraIndent * buffer.getIndentSize()); 198 } 199 } 200 201 public boolean keepChecking() 202 { 203 return false; 204 } 205 } 206 207 210 class AlignOffset implements IndentAction 211 { 212 private int offset; 213 214 public AlignOffset(int offset) 215 { 216 this.offset = offset; 217 } 218 219 public int calculateIndent(JEditBuffer buffer, int line, int oldIndent, 220 int newIndent) 221 { 222 return offset; 223 } 224 225 public boolean keepChecking() 226 { 227 return false; 228 } 229 } 230 231 235 class AlignParameter implements IndentAction 236 { 237 private int openParensColumn; 238 private String openParensLineText; 239 240 public AlignParameter(int openParensColumn, String openParensLineText) 241 { 242 this.openParensLineText = openParensLineText; 243 this.openParensColumn = openParensColumn; 244 } 245 246 public int calculateIndent(JEditBuffer buffer, int line, int oldIndent, 247 int newIndent) 248 { 249 return openParensLineText == null ? newIndent : openParensColumn + 1; 250 } 251 252 public boolean keepChecking() 253 { 254 return false; 255 } 256 } 257 } 258 | Popular Tags |