summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/highlight
diff options
context:
space:
mode:
authorGravatar Thog2017-03-08 08:17:04 +0100
committerGravatar Thog2017-03-08 08:17:04 +0100
commit6e464ea251cab63c776ece0b2a356f1498ffa294 (patch)
tree5ed30c03f5ac4cd2d6877874f5ede576049954f7 /src/main/java/cuchaz/enigma/gui/highlight
parentDrop unix case style and implement hashCode when equals is overrided (diff)
downloadenigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.gz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.xz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.zip
Follow Fabric guidelines
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/highlight')
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java87
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java9
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java9
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java9
-rw-r--r--src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java22
5 files changed, 68 insertions, 68 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java
index 0a73088..0f64927 100644
--- a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java
+++ b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java
@@ -8,57 +8,54 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma.gui.highlight;
12 11
13import java.awt.Color; 12package cuchaz.enigma.gui.highlight;
14import java.awt.Graphics;
15import java.awt.Rectangle;
16import java.awt.Shape;
17 13
18import javax.swing.text.BadLocationException; 14import javax.swing.text.BadLocationException;
19import javax.swing.text.Highlighter; 15import javax.swing.text.Highlighter;
20import javax.swing.text.JTextComponent; 16import javax.swing.text.JTextComponent;
17import java.awt.*;
21 18
22public abstract class BoxHighlightPainter implements Highlighter.HighlightPainter { 19public abstract class BoxHighlightPainter implements Highlighter.HighlightPainter {
23 20
24 private Color fillColor; 21 private Color fillColor;
25 private Color borderColor; 22 private Color borderColor;
26 23
27 protected BoxHighlightPainter(Color fillColor, Color borderColor) { 24 protected BoxHighlightPainter(Color fillColor, Color borderColor) {
28 this.fillColor = fillColor; 25 this.fillColor = fillColor;
29 this.borderColor = borderColor; 26 this.borderColor = borderColor;
30 } 27 }
31 28
32 @Override 29 public static Rectangle getBounds(JTextComponent text, int start, int end) {
33 public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) { 30 try {
34 Rectangle bounds = getBounds(text, start, end); 31 // determine the bounds of the text
35 32 Rectangle bounds = text.modelToView(start).union(text.modelToView(end));
36 // fill the area 33
37 if (this.fillColor != null) { 34 // adjust the box so it looks nice
38 g.setColor(this.fillColor); 35 bounds.x -= 2;
39 g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); 36 bounds.width += 2;
40 } 37 bounds.y += 1;
41 38 bounds.height -= 2;
42 // draw a box around the area 39
43 g.setColor(this.borderColor); 40 return bounds;
44 g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); 41 } catch (BadLocationException ex) {
45 } 42 // don't care... just return something
46 43 return new Rectangle(0, 0, 0, 0);
47 public static Rectangle getBounds(JTextComponent text, int start, int end) { 44 }
48 try { 45 }
49 // determine the bounds of the text 46
50 Rectangle bounds = text.modelToView(start).union(text.modelToView(end)); 47 @Override
51 48 public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) {
52 // adjust the box so it looks nice 49 Rectangle bounds = getBounds(text, start, end);
53 bounds.x -= 2; 50
54 bounds.width += 2; 51 // fill the area
55 bounds.y += 1; 52 if (this.fillColor != null) {
56 bounds.height -= 2; 53 g.setColor(this.fillColor);
57 54 g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
58 return bounds; 55 }
59 } catch (BadLocationException ex) { 56
60 // don't care... just return something 57 // draw a box around the area
61 return new Rectangle(0, 0, 0, 0); 58 g.setColor(this.borderColor);
62 } 59 g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
63 } 60 }
64} 61}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java
index 5d57203..a2d2884 100644
--- a/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java
+++ b/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java
@@ -8,13 +8,14 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11
11package cuchaz.enigma.gui.highlight; 12package cuchaz.enigma.gui.highlight;
12 13
13import java.awt.Color; 14import java.awt.*;
14 15
15public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { 16public class DeobfuscatedHighlightPainter extends BoxHighlightPainter {
16 17
17 public DeobfuscatedHighlightPainter() { 18 public DeobfuscatedHighlightPainter() {
18 super(new Color(220, 255, 220), new Color(80, 160, 80)); 19 super(new Color(220, 255, 220), new Color(80, 160, 80));
19 } 20 }
20} 21}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java
index ee64d86..0947d4b 100644
--- a/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java
+++ b/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java
@@ -8,13 +8,14 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11
11package cuchaz.enigma.gui.highlight; 12package cuchaz.enigma.gui.highlight;
12 13
13import java.awt.Color; 14import java.awt.*;
14 15
15public class ObfuscatedHighlightPainter extends BoxHighlightPainter { 16public class ObfuscatedHighlightPainter extends BoxHighlightPainter {
16 17
17 public ObfuscatedHighlightPainter() { 18 public ObfuscatedHighlightPainter() {
18 super(new Color(255, 220, 220), new Color(160, 80, 80)); 19 super(new Color(255, 220, 220), new Color(160, 80, 80));
19 } 20 }
20} 21}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java
index 43d8352..74e7273 100644
--- a/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java
+++ b/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java
@@ -8,13 +8,14 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11
11package cuchaz.enigma.gui.highlight; 12package cuchaz.enigma.gui.highlight;
12 13
13import java.awt.Color; 14import java.awt.*;
14 15
15public class OtherHighlightPainter extends BoxHighlightPainter { 16public class OtherHighlightPainter extends BoxHighlightPainter {
16 17
17 public OtherHighlightPainter() { 18 public OtherHighlightPainter() {
18 super(null, new Color(180, 180, 180)); 19 super(null, new Color(180, 180, 180));
19 } 20 }
20} 21}
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java
index f772284..5cbeabc 100644
--- a/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java
+++ b/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java
@@ -8,22 +8,22 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma.gui.highlight;
12 11
13import java.awt.*; 12package cuchaz.enigma.gui.highlight;
14 13
15import javax.swing.text.Highlighter; 14import javax.swing.text.Highlighter;
16import javax.swing.text.JTextComponent; 15import javax.swing.text.JTextComponent;
16import java.awt.*;
17 17
18public class SelectionHighlightPainter implements Highlighter.HighlightPainter { 18public class SelectionHighlightPainter implements Highlighter.HighlightPainter {
19 19
20 @Override 20 @Override
21 public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) { 21 public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) {
22 // draw a thick border 22 // draw a thick border
23 Graphics2D g2d = (Graphics2D) g; 23 Graphics2D g2d = (Graphics2D) g;
24 Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end); 24 Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end);
25 g2d.setColor(Color.black); 25 g2d.setColor(Color.black);
26 g2d.setStroke(new BasicStroke(2.0f)); 26 g2d.setStroke(new BasicStroke(2.0f));
27 g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); 27 g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
28 } 28 }
29} 29}