1 33 34 package edu.rice.cs.drjava.ui; 35 36 import edu.rice.cs.drjava.DrJava; 37 import edu.rice.cs.drjava.config.*; 38 import edu.rice.cs.drjava.model.*; 39 import edu.rice.cs.drjava.model.definitions.indent.Indenter; 40 41 import edu.rice.cs.util.swing.*; 42 import edu.rice.cs.util.swing.Utilities; 43 import edu.rice.cs.util.text.SwingDocument; 44 45 import java.awt.*; 46 import javax.swing.*; 47 import javax.swing.event.*; 48 import javax.swing.text.*; 49 50 52 public abstract class AbstractDJPane extends JTextPane implements OptionConstants { 53 54 56 57 private static final double SCROLL_UNIT = .05; 58 59 60 static ReverseHighlighter.DefaultHighlightPainter MATCH_PAINTER; 61 62 static { 63 Color highColor = DrJava.getConfig().getSetting(DEFINITIONS_MATCH_COLOR); 64 MATCH_PAINTER = new ReverseHighlighter.DefaultHighlightPainter(highColor); 65 } 66 67 68 static ReverseHighlighter.DefaultHighlightPainter ERROR_PAINTER = 69 new ReverseHighlighter.DefaultHighlightPainter(DrJava.getConfig().getSetting(COMPILER_ERROR_COLOR)); 70 71 protected volatile HighlightManager _highlightManager; 72 73 74 protected final CaretListener _matchListener = new CaretListener() { 75 76 82 public void caretUpdate(CaretEvent e) { 83 getDJDocument().setCurrentLocation(getCaretPosition()); 84 _removePreviousHighlight(); 85 _updateMatchHighlight(); 86 } 87 }; 88 89 90 protected volatile HighlightManager.HighlightInfo _matchHighlight = null; 91 92 protected final SwingDocument NULL_DOCUMENT = new SwingDocument(); 93 94 96 AbstractDJPane(SwingDocument doc) { 97 super(doc); 98 setContentType("text/java"); 99 100 addCaretListener(_matchListener); 102 } 103 104 106 110 protected void _addHighlight(int from, int to) { 111 _matchHighlight = _highlightManager.addHighlight(from, to, MATCH_PAINTER); 112 } 113 114 protected abstract void _updateMatchHighlight(); 115 116 118 protected void _removePreviousHighlight() { 119 if (_matchHighlight != null) { 120 _matchHighlight.remove(); 121 _matchHighlight = null; 123 } 124 } 125 126 129 public void setCaretPosition(int pos) { 130 super.setCaretPosition(pos); 131 getDJDocument().setCurrentLocation(pos); 132 } 134 135 public int getScrollableUnitIncrement(Rectangle visibleRectangle, int orientation, int direction) { 136 return (int) (visibleRectangle.getHeight() * SCROLL_UNIT); 137 } 138 139 140 public void moveCaretPosition(int pos) { super.moveCaretPosition(pos); } 141 142 143 public void indent() { indent(Indenter.OTHER); } 144 145 152 public void indent(final int reason) { 153 154 159 160 getDJDocument().setCurrentLocation(getCaretPosition()); 162 163 165 final int selStart = getSelectionStart(); 166 final int selEnd = getSelectionEnd(); 167 168 ProgressMonitor pm = null; 169 172 176 if (shouldIndent(selStart,selEnd)) { indentLines(selStart, selEnd, reason, pm); } 179 180 } 181 182 188 protected abstract void indentLines(int selStart, int selEnd, int reason, ProgressMonitor pm); 189 190 195 protected abstract boolean shouldIndent(int selStart, int selEnd); 196 197 198 public abstract DJDocument getDJDocument(); 199 } | Popular Tags |