diff options
| author | 2016-07-04 18:14:22 +1000 | |
|---|---|---|
| committer | 2016-07-04 18:14:22 +1000 | |
| commit | 59e189bef2b5e6d129fb7c2c988ed0b2130e36ac (patch) | |
| tree | 2b638e60905251de85a4917152d6fc39a4112194 /src/main/java/cuchaz/enigma/gui/highlight | |
| parent | Fixed Obf Class list order (diff) | |
| download | enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.gz enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.xz enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.zip | |
Reformat
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/highlight')
5 files changed, 153 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java new file mode 100644 index 0000000..0a73088 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java | |||
| @@ -0,0 +1,64 @@ | |||
| 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 | package cuchaz.enigma.gui.highlight; | ||
| 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 abstract class BoxHighlightPainter implements Highlighter.HighlightPainter { | ||
| 23 | |||
| 24 | private Color fillColor; | ||
| 25 | private Color borderColor; | ||
| 26 | |||
| 27 | protected BoxHighlightPainter(Color fillColor, Color borderColor) { | ||
| 28 | this.fillColor = fillColor; | ||
| 29 | this.borderColor = borderColor; | ||
| 30 | } | ||
| 31 | |||
| 32 | @Override | ||
| 33 | public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) { | ||
| 34 | Rectangle bounds = getBounds(text, start, end); | ||
| 35 | |||
| 36 | // fill the area | ||
| 37 | if (this.fillColor != null) { | ||
| 38 | g.setColor(this.fillColor); | ||
| 39 | g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); | ||
| 40 | } | ||
| 41 | |||
| 42 | // draw a box around the area | ||
| 43 | g.setColor(this.borderColor); | ||
| 44 | g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); | ||
| 45 | } | ||
| 46 | |||
| 47 | public static Rectangle getBounds(JTextComponent text, int start, int end) { | ||
| 48 | try { | ||
| 49 | // determine the bounds of the text | ||
| 50 | Rectangle bounds = text.modelToView(start).union(text.modelToView(end)); | ||
| 51 | |||
| 52 | // adjust the box so it looks nice | ||
| 53 | bounds.x -= 2; | ||
| 54 | bounds.width += 2; | ||
| 55 | bounds.y += 1; | ||
| 56 | bounds.height -= 2; | ||
| 57 | |||
| 58 | return bounds; | ||
| 59 | } catch (BadLocationException ex) { | ||
| 60 | // don't care... just return something | ||
| 61 | return new Rectangle(0, 0, 0, 0); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java new file mode 100644 index 0000000..5d57203 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java | |||
| @@ -0,0 +1,20 @@ | |||
| 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 | package cuchaz.enigma.gui.highlight; | ||
| 12 | |||
| 13 | import java.awt.Color; | ||
| 14 | |||
| 15 | public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { | ||
| 16 | |||
| 17 | public DeobfuscatedHighlightPainter() { | ||
| 18 | super(new Color(220, 255, 220), new Color(80, 160, 80)); | ||
| 19 | } | ||
| 20 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java new file mode 100644 index 0000000..ee64d86 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java | |||
| @@ -0,0 +1,20 @@ | |||
| 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 | package cuchaz.enigma.gui.highlight; | ||
| 12 | |||
| 13 | import java.awt.Color; | ||
| 14 | |||
| 15 | public class ObfuscatedHighlightPainter extends BoxHighlightPainter { | ||
| 16 | |||
| 17 | public ObfuscatedHighlightPainter() { | ||
| 18 | super(new Color(255, 220, 220), new Color(160, 80, 80)); | ||
| 19 | } | ||
| 20 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java new file mode 100644 index 0000000..43d8352 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java | |||
| @@ -0,0 +1,20 @@ | |||
| 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 | package cuchaz.enigma.gui.highlight; | ||
| 12 | |||
| 13 | import java.awt.Color; | ||
| 14 | |||
| 15 | public class OtherHighlightPainter extends BoxHighlightPainter { | ||
| 16 | |||
| 17 | public OtherHighlightPainter() { | ||
| 18 | super(null, new Color(180, 180, 180)); | ||
| 19 | } | ||
| 20 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java new file mode 100644 index 0000000..f772284 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/highlight/SelectionHighlightPainter.java | |||
| @@ -0,0 +1,29 @@ | |||
| 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 | package cuchaz.enigma.gui.highlight; | ||
| 12 | |||
| 13 | import java.awt.*; | ||
| 14 | |||
| 15 | import javax.swing.text.Highlighter; | ||
| 16 | import javax.swing.text.JTextComponent; | ||
| 17 | |||
| 18 | public class SelectionHighlightPainter implements Highlighter.HighlightPainter { | ||
| 19 | |||
| 20 | @Override | ||
| 21 | public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) { | ||
| 22 | // draw a thick border | ||
| 23 | Graphics2D g2d = (Graphics2D) g; | ||
| 24 | Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end); | ||
| 25 | g2d.setColor(Color.black); | ||
| 26 | g2d.setStroke(new BasicStroke(2.0f)); | ||
| 27 | g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); | ||
| 28 | } | ||
| 29 | } | ||