diff options
Diffstat (limited to 'src/cuchaz/enigma/gui/BoxHighlightPainter.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/BoxHighlightPainter.java | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/cuchaz/enigma/gui/BoxHighlightPainter.java b/src/cuchaz/enigma/gui/BoxHighlightPainter.java index b9474ff..2c11834 100644 --- a/src/cuchaz/enigma/gui/BoxHighlightPainter.java +++ b/src/cuchaz/enigma/gui/BoxHighlightPainter.java | |||
| @@ -33,10 +33,23 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte | |||
| 33 | @Override | 33 | @Override |
| 34 | public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) | 34 | public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) |
| 35 | { | 35 | { |
| 36 | Rectangle bounds = getBounds( text, start, end ); | ||
| 37 | |||
| 38 | // fill the area | ||
| 39 | g.setColor( m_fillColor ); | ||
| 40 | g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 41 | |||
| 42 | // draw a box around the area | ||
| 43 | g.setColor( m_borderColor ); | ||
| 44 | g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 45 | } | ||
| 46 | |||
| 47 | protected static Rectangle getBounds( JTextComponent text, int start, int end ) | ||
| 48 | { | ||
| 36 | try | 49 | try |
| 37 | { | 50 | { |
| 38 | // determine the bounds of the text | 51 | // determine the bounds of the text |
| 39 | Rectangle bounds = text.getUI().modelToView( text, start ).union( text.getUI().modelToView( text, end ) ); | 52 | Rectangle bounds = text.modelToView( start ).union( text.modelToView( end ) ); |
| 40 | 53 | ||
| 41 | // adjust the box so it looks nice | 54 | // adjust the box so it looks nice |
| 42 | bounds.x -= 2; | 55 | bounds.x -= 2; |
| @@ -44,13 +57,7 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte | |||
| 44 | bounds.y += 1; | 57 | bounds.y += 1; |
| 45 | bounds.height -= 2; | 58 | bounds.height -= 2; |
| 46 | 59 | ||
| 47 | // fill the area | 60 | return bounds; |
| 48 | g.setColor( m_fillColor ); | ||
| 49 | g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 50 | |||
| 51 | // draw a box around the area | ||
| 52 | g.setColor( m_borderColor ); | ||
| 53 | g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 54 | } | 61 | } |
| 55 | catch( BadLocationException ex ) | 62 | catch( BadLocationException ex ) |
| 56 | { | 63 | { |