1 45 46 package edu.rice.cs.drjava.model.definitions.indent; 47 48 import javax.swing.text.*; 49 import edu.rice.cs.util.UnexpectedException; 50 import edu.rice.cs.drjava.model.AbstractDJDocument; 51 52 58 class ActionStartPrevLinePlusMultilinePreserve extends IndentRuleAction { 59 private String [] _suffices; 60 private int _cursorLine, _cursorPos, _psrvLine, _psrvPos; 61 62 73 public ActionStartPrevLinePlusMultilinePreserve(String suffices[], 74 int cursorLine, int cursorPos, 75 int psrvLine, int psrvPos) { 76 _suffices = suffices; 77 _cursorLine = cursorLine; 78 _cursorPos = cursorPos; 79 _psrvLine = psrvLine; 80 _psrvPos = psrvPos; 81 } 82 83 88 public boolean indentLine(AbstractDJDocument doc, int reason) { 89 try { 90 String [] suffices = new String [_suffices.length]; 92 for(int i = 0; i < _suffices.length; i++) 93 suffices[i] = _suffices[i]; 94 95 int here = doc.getCurrentLocation(); 97 int lineStart = doc.getLineStartPos(here); 98 int lineEnd = doc.getLineEndPos(here); 99 100 int lineLength = lineEnd-lineStart; 102 String preserved = doc.getText(lineStart, lineLength); 103 doc.remove(lineStart, lineLength); 104 105 String prefix = suffices[_psrvLine].substring(0,_psrvPos); 107 String suffix = suffices[_psrvLine].substring(_psrvPos); 108 suffices[_psrvLine] = prefix + preserved + suffix; 109 110 ActionStartPrevLinePlusMultiline a; 112 a = new ActionStartPrevLinePlusMultiline(suffices, _cursorLine, _cursorPos); 115 return a.indentLine(doc, reason); 116 } 117 catch (BadLocationException e) { 118 throw new UnexpectedException(e); 120 } 121 } 122 } 123 | Popular Tags |