73 |
/** A ViewFactory that creates WrappedLines **/ |
/** A ViewFactory that creates WrappedLines **/ |
74 |
ViewFactory viewFactory = new WrappedLineCreator(); |
ViewFactory viewFactory = new WrappedLineCreator(); |
75 |
|
|
76 |
|
/** The start of the selected text **/ |
77 |
|
int selectionStart; |
78 |
|
|
79 |
|
/** The end of the selected text **/ |
80 |
|
int selectionEnd; |
81 |
|
|
82 |
/** |
/** |
83 |
* The instance returned by {@link #getLineBuffer()}. |
* The instance returned by {@link #getLineBuffer()}. |
84 |
*/ |
*/ |
150 |
{ |
{ |
151 |
try |
try |
152 |
{ |
{ |
153 |
drawUnselectedText(g, x, y, p0, p1); |
// We have to draw both selected and unselected text. There are |
154 |
|
// several cases: |
155 |
|
// - entire range is unselected |
156 |
|
// - entire range is selected |
157 |
|
// - start of range is selected, end of range is unselected |
158 |
|
// - start of range is unselected, end of range is selected |
159 |
|
// - middle of range is selected, start and end of range is unselected |
160 |
|
|
161 |
|
// entire range unselected: |
162 |
|
if ((selectionStart == selectionEnd) || |
163 |
|
(p0 > selectionEnd || p1 < selectionStart)) |
164 |
|
drawUnselectedText(g, x, y, p0, p1); |
165 |
|
|
166 |
|
// entire range selected |
167 |
|
else if (p0 >= selectionStart && p1 <= selectionEnd) |
168 |
|
drawSelectedText(g, x, y, p0, p1); |
169 |
|
|
170 |
|
// start of range selected, end of range unselected |
171 |
|
else if (p0 >= selectionStart) |
172 |
|
{ |
173 |
|
x = drawSelectedText(g, x, y, p0, selectionEnd); |
174 |
|
drawUnselectedText(g, x, y, selectionEnd, p1); |
175 |
|
} |
176 |
|
|
177 |
|
// start of range unselected, end of range selected |
178 |
|
else if (selectionStart > p0 && selectionEnd > p1) |
179 |
|
{ |
180 |
|
x = drawUnselectedText(g, x, y, p0, selectionStart); |
181 |
|
drawSelectedText(g, x, y, selectionStart, p1); |
182 |
|
} |
183 |
|
|
184 |
|
// middle of range selected |
185 |
|
else if (selectionStart > p0) |
186 |
|
{ |
187 |
|
x = drawUnselectedText(g, x, y, p0, selectionStart); |
188 |
|
x = drawSelectedText(g, x, y, selectionStart, selectionEnd); |
189 |
|
drawUnselectedText(g, x, y, selectionEnd, p1); |
190 |
|
} |
191 |
} |
} |
192 |
catch (BadLocationException ble) |
catch (BadLocationException ble) |
193 |
{ |
{ |
228 |
*/ |
*/ |
229 |
protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) |
protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) |
230 |
throws BadLocationException |
throws BadLocationException |
231 |
{ |
{ |
232 |
JTextComponent textComponent = (JTextComponent) getContainer(); |
JTextComponent textComponent = (JTextComponent) getContainer(); |
233 |
if (textComponent.isEnabled()) |
if (textComponent.isEnabled()) |
234 |
g.setColor(unselectedColor); |
g.setColor(unselectedColor); |
363 |
*/ |
*/ |
364 |
public void paint(Graphics g, Shape a) |
public void paint(Graphics g, Shape a) |
365 |
{ |
{ |
366 |
|
JTextComponent comp = (JTextComponent)getContainer(); |
367 |
|
selectionStart = comp.getSelectionStart(); |
368 |
|
selectionEnd = comp.getSelectionEnd(); |
369 |
updateMetrics(); |
updateMetrics(); |
370 |
super.paint(g, a); |
super.paint(g, a); |
371 |
} |
} |
406 |
unselectedColor = textComponent.getForeground(); |
unselectedColor = textComponent.getForeground(); |
407 |
disabledColor = textComponent.getDisabledTextColor(); |
disabledColor = textComponent.getDisabledTextColor(); |
408 |
|
|
409 |
|
// FIXME: this is a hack, for some reason textComponent.getSelectedColor |
410 |
|
// was returning black, which is not visible against a black background |
411 |
|
selectedColor = Color.WHITE; |
412 |
|
|
413 |
Rectangle rect = s.getBounds(); |
Rectangle rect = s.getBounds(); |
414 |
int lineHeight = metrics.getHeight(); |
int lineHeight = metrics.getHeight(); |
415 |
|
|