summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/highlight
diff options
context:
space:
mode:
authorGravatar Runemoro2020-06-03 13:39:42 -0400
committerGravatar GitHub2020-06-03 18:39:42 +0100
commit0f47403d0220757fed189b76e2071e25b1025cb8 (patch)
tree879bf72c4476f0a5e0d82da99d7ff2b2276bcaca /src/main/java/cuchaz/enigma/gui/highlight
parentFix search dialog hanging for a short time sometimes (#250) (diff)
downloadenigma-fork-0f47403d0220757fed189b76e2071e25b1025cb8.tar.gz
enigma-fork-0f47403d0220757fed189b76e2071e25b1025cb8.tar.xz
enigma-fork-0f47403d0220757fed189b76e2071e25b1025cb8.zip
Split GUI code to separate module (#242)
* Split into modules * Post merge compile fixes Co-authored-by: modmuss50 <modmuss50@gmail.com>
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/highlight')
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java69
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java31
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/TokenHighlightType.java7
3 files changed, 0 insertions, 107 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java
deleted file mode 100644
index cef6494..0000000
--- a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java
+++ /dev/null
@@ -1,69 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.gui.highlight;
13
14import cuchaz.enigma.config.Config;
15
16import javax.swing.text.BadLocationException;
17import javax.swing.text.Highlighter;
18import javax.swing.text.JTextComponent;
19import java.awt.*;
20
21public class BoxHighlightPainter implements Highlighter.HighlightPainter {
22 private Color fillColor;
23 private Color borderColor;
24
25 protected BoxHighlightPainter(Color fillColor, Color borderColor) {
26 this.fillColor = fillColor;
27 this.borderColor = borderColor;
28 }
29
30 public static BoxHighlightPainter create(Config.AlphaColorEntry entry, Config.AlphaColorEntry entryOutline) {
31 return new BoxHighlightPainter(entry != null ? entry.get() : null, entryOutline != null ? entryOutline.get() : null);
32 }
33
34 public static Rectangle getBounds(JTextComponent text, int start, int end) {
35 try {
36 // determine the bounds of the text
37 Rectangle startRect = text.modelToView(start);
38 Rectangle endRect = text.modelToView(end);
39 Rectangle bounds = startRect.union(endRect);
40
41 // adjust the box so it looks nice
42 bounds.x -= 2;
43 bounds.width += 2;
44 bounds.y += 1;
45 bounds.height -= 2;
46
47 return bounds;
48 } catch (BadLocationException ex) {
49 // don't care... just return something
50 return new Rectangle(0, 0, 0, 0);
51 }
52 }
53
54 @Override
55 public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) {
56 Rectangle bounds = getBounds(text, start, end);
57
58 // fill the area
59 if (this.fillColor != null) {
60 g.setColor(this.fillColor);
61 g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
62 }
63
64 // draw a box around the area
65 g.setColor(this.borderColor);
66 g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
67 }
68
69}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java
deleted file mode 100644
index 81a70a9..0000000
--- a/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java
+++ /dev/null
@@ -1,31 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.gui.highlight;
13
14import cuchaz.enigma.config.Config;
15
16import javax.swing.text.Highlighter;
17import javax.swing.text.JTextComponent;
18import java.awt.*;
19
20public class SelectionHighlightPainter implements Highlighter.HighlightPainter {
21
22 @Override
23 public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) {
24 // draw a thick border
25 Graphics2D g2d = (Graphics2D) g;
26 Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end);
27 g2d.setColor(new Color(Config.getInstance().selectionHighlightColor));
28 g2d.setStroke(new BasicStroke(2.0f));
29 g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
30 }
31}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/TokenHighlightType.java b/src/main/java/cuchaz/enigma/gui/highlight/TokenHighlightType.java
deleted file mode 100644
index ae23f32..0000000
--- a/src/main/java/cuchaz/enigma/gui/highlight/TokenHighlightType.java
+++ /dev/null
@@ -1,7 +0,0 @@
1package cuchaz.enigma.gui.highlight;
2
3public enum TokenHighlightType {
4 OBFUSCATED,
5 DEOBFUSCATED,
6 PROPOSED
7}