1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import javax.swing.text.*; 37 import edu.rice.cs.util.UnexpectedException; 38 import edu.rice.cs.drjava.model.AbstractDJDocument; 39 40 46 class ActionStartPrevLinePlusMultiline extends IndentRuleAction { 47 private String [] _suffices; 48 private int _line = 0; 49 private int _offset = 0; 51 52 65 public ActionStartPrevLinePlusMultiline(String suffices[], 66 int line, int position) { 67 _suffices = suffices; 68 69 if ((line >= 0) && (line < suffices.length)) { 71 _line = line; 72 } 73 else { 74 throw new IllegalArgumentException 75 ("The specified line was outside the bounds of the specified array."); 76 } 77 78 if ((position < 0) || (position > suffices[line].length())) { 79 throw new IllegalArgumentException 80 ("The specified position was not within the bounds of the specified line."); 81 } 82 86 87 for (int i = 0; i < line; i++) { 89 _offset += _suffices[i].length(); 90 } 91 _offset += position; 92 } 93 94 101 public boolean indentLine(AbstractDJDocument doc, int reason) { 102 super.indentLine(doc, reason); 103 try { 104 int here = doc.getCurrentLocation(); 106 int startLine = doc.getLineStartPos(here); 107 108 if (startLine > AbstractDJDocument.DOCSTART) { 109 int startPrevLine = doc.getLineStartPos(startLine - 1); 111 int firstChar = doc.getLineFirstCharPos(startPrevLine); 112 String prefix = doc.getText(startPrevLine, firstChar - startPrevLine); 113 114 for (int i = 0; i < _suffices.length; i++) { 116 doc.setTab(prefix + _suffices[i], here); 117 here += prefix.length() + _suffices[i].length(); 118 } 119 120 int newPos = startLine + _offset + (prefix.length() * (_line + 1)); 122 doc.setCurrentLocation(newPos); 123 } 124 else { 125 for (int i = 0; i < _suffices.length; i++) { 127 doc.setTab(_suffices[i], here); 128 here += _suffices[i].length(); 129 } 130 } 131 return false; 132 } 133 catch (BadLocationException e) { 134 throw new UnexpectedException(e); 136 } 137 } 138 } 139 | Popular Tags |