summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/gui/BoxHighlightPainter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuchaz/enigma/gui/BoxHighlightPainter.java')
-rw-r--r--src/cuchaz/enigma/gui/BoxHighlightPainter.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/gui/BoxHighlightPainter.java b/src/cuchaz/enigma/gui/BoxHighlightPainter.java
new file mode 100644
index 0000000..22db28b
--- /dev/null
+++ b/src/cuchaz/enigma/gui/BoxHighlightPainter.java
@@ -0,0 +1,54 @@
1/*******************************************************************************
2 * Copyright (c) 2014 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Public License v3.0
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/gpl.html
7 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.gui;
12
13import java.awt.Color;
14import java.awt.Graphics;
15import java.awt.Rectangle;
16import java.awt.Shape;
17
18import javax.swing.text.BadLocationException;
19import javax.swing.text.Highlighter;
20import javax.swing.text.JTextComponent;
21
22public class BoxHighlightPainter implements Highlighter.HighlightPainter
23{
24 private static final Color FillColor = new Color( 230, 230, 230 );
25 private static final Color BorderColor = new Color( 100, 100, 100 );
26
27 @Override
28 public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text )
29 {
30 try
31 {
32 // determine the bounds of the text
33 Rectangle bounds = text.getUI().modelToView( text, start ).union( text.getUI().modelToView( text, end ) );
34
35 // adjust the box so it looks nice
36 bounds.x -= 2;
37 bounds.width += 2;
38 bounds.y += 1;
39 bounds.height -= 2;
40
41 // fill the area
42 g.setColor( FillColor );
43 g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 );
44
45 // draw a box around the area
46 g.setColor( BorderColor );
47 g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 );
48 }
49 catch( BadLocationException ex )
50 {
51 throw new Error( ex );
52 }
53 }
54}