From 32b7ea70ff20d3584f8021e598141c20c2200398 Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 22 Aug 2014 01:25:52 -0400 Subject: added show token effects --- src/cuchaz/enigma/gui/BoxHighlightPainter.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/cuchaz/enigma/gui/BoxHighlightPainter.java') 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 @@ -32,11 +32,24 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte @Override public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) + { + Rectangle bounds = getBounds( text, start, end ); + + // fill the area + g.setColor( m_fillColor ); + g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); + + // draw a box around the area + g.setColor( m_borderColor ); + g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); + } + + protected static Rectangle getBounds( JTextComponent text, int start, int end ) { try { // determine the bounds of the text - Rectangle bounds = text.getUI().modelToView( text, start ).union( text.getUI().modelToView( text, end ) ); + Rectangle bounds = text.modelToView( start ).union( text.modelToView( end ) ); // adjust the box so it looks nice bounds.x -= 2; @@ -44,13 +57,7 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte bounds.y += 1; bounds.height -= 2; - // fill the area - g.setColor( m_fillColor ); - g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); - - // draw a box around the area - g.setColor( m_borderColor ); - g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); + return bounds; } catch( BadLocationException ex ) { -- cgit v1.2.3