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 ActionStartPrevLinePlusBackup extends IndentRuleAction { 47 private String _suffix; 48 private int _position = 0; 49 50 59 public ActionStartPrevLinePlusBackup(String suffix, int position) { 60 _suffix = suffix; 61 62 if ((position >= 0) && (position <= suffix.length())) { 63 _position = position; 64 } 65 else { 66 throw new IllegalArgumentException 67 ("The specified position was not within the bounds of the suffix."); 68 } 69 } 70 71 78 public boolean indentLine(AbstractDJDocument doc, int reason) { 79 super.indentLine(doc, reason); 80 try { 81 int here = doc.getCurrentLocation(); 83 int startLine = doc.getLineStartPos(here); 84 85 if (startLine > AbstractDJDocument.DOCSTART) { 86 int startPrevLine = doc.getLineStartPos(startLine - 1); 88 int firstChar = doc.getLineFirstCharPos(startPrevLine); 89 String prefix = doc.getText(startPrevLine, firstChar - startPrevLine); 90 91 doc.setTab(prefix + _suffix, here); 93 94 doc.setCurrentLocation(startLine + prefix.length() + _position); 96 } 97 else { 98 doc.setTab(_suffix, here); 100 101 doc.setCurrentLocation(here + _position); 103 } 104 105 return false; 106 } 107 catch (BadLocationException e) { 108 throw new UnexpectedException(e); 110 } 111 } 112 } 113 | Popular Tags |