diff options
| author | 2014-07-26 19:24:00 -0400 | |
|---|---|---|
| committer | 2014-07-26 19:24:00 -0400 | |
| commit | 295eceece371b516e771de93b6127bf728999483 (patch) | |
| tree | 20ff6a35de79997fc338d922cae934b8872b11a9 /src/cuchaz/enigma/gui/BoxHighlightPainter.java | |
| download | enigma-fork-295eceece371b516e771de93b6127bf728999483.tar.gz enigma-fork-295eceece371b516e771de93b6127bf728999483.tar.xz enigma-fork-295eceece371b516e771de93b6127bf728999483.zip | |
initial commit
so far source analysis is working. =)
Diffstat (limited to 'src/cuchaz/enigma/gui/BoxHighlightPainter.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/BoxHighlightPainter.java | 54 |
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 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.gui; | ||
| 12 | |||
| 13 | import java.awt.Color; | ||
| 14 | import java.awt.Graphics; | ||
| 15 | import java.awt.Rectangle; | ||
| 16 | import java.awt.Shape; | ||
| 17 | |||
| 18 | import javax.swing.text.BadLocationException; | ||
| 19 | import javax.swing.text.Highlighter; | ||
| 20 | import javax.swing.text.JTextComponent; | ||
| 21 | |||
| 22 | public 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 | } | ||