summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/gui/GuiTricks.java
diff options
context:
space:
mode:
authorGravatar jeff2015-03-09 12:53:11 -0400
committerGravatar jeff2015-03-09 12:53:11 -0400
commitd6b2a223a7973941e5e4fb45c8ceec4885891496 (patch)
tree5728ab513d0b4ed85a720da7eb48c6591dd3f8b0 /src/cuchaz/enigma/gui/GuiTricks.java
parentadd tracking for mismatched fields/methods (diff)
downloadenigma-fork-d6b2a223a7973941e5e4fb45c8ceec4885891496.tar.gz
enigma-fork-d6b2a223a7973941e5e4fb45c8ceec4885891496.tar.xz
enigma-fork-d6b2a223a7973941e5e4fb45c8ceec4885891496.zip
starting on field matching gui
Diffstat (limited to 'src/cuchaz/enigma/gui/GuiTricks.java')
-rw-r--r--src/cuchaz/enigma/gui/GuiTricks.java58
1 files changed, 0 insertions, 58 deletions
diff --git a/src/cuchaz/enigma/gui/GuiTricks.java b/src/cuchaz/enigma/gui/GuiTricks.java
index 5a3a01d..df9e221 100644
--- a/src/cuchaz/enigma/gui/GuiTricks.java
+++ b/src/cuchaz/enigma/gui/GuiTricks.java
@@ -11,21 +11,11 @@
11package cuchaz.enigma.gui; 11package cuchaz.enigma.gui;
12 12
13import java.awt.Font; 13import java.awt.Font;
14import java.awt.Rectangle;
15import java.awt.event.ActionEvent;
16import java.awt.event.ActionListener;
17import java.awt.event.MouseEvent; 14import java.awt.event.MouseEvent;
18 15
19import javax.swing.JComponent; 16import javax.swing.JComponent;
20import javax.swing.JEditorPane;
21import javax.swing.JLabel; 17import javax.swing.JLabel;
22import javax.swing.SwingUtilities;
23import javax.swing.Timer;
24import javax.swing.ToolTipManager; 18import javax.swing.ToolTipManager;
25import javax.swing.text.BadLocationException;
26import javax.swing.text.Highlighter.HighlightPainter;
27
28import cuchaz.enigma.analysis.Token;
29 19
30public class GuiTricks { 20public class GuiTricks {
31 21
@@ -43,52 +33,4 @@ public class GuiTricks {
43 manager.mouseMoved(new MouseEvent(component, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 0, 0, 0, false)); 33 manager.mouseMoved(new MouseEvent(component, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 0, 0, 0, false));
44 manager.setInitialDelay(oldDelay); 34 manager.setInitialDelay(oldDelay);
45 } 35 }
46
47 public static void navigateToToken(final JEditorPane editor, final Token token, final HighlightPainter highlightPainter) {
48
49 // set the caret position to the token
50 editor.setCaretPosition(token.start);
51 editor.grabFocus();
52
53 try {
54 // make sure the token is visible in the scroll window
55 Rectangle start = editor.modelToView(token.start);
56 Rectangle end = editor.modelToView(token.end);
57 final Rectangle show = start.union(end);
58 show.grow(start.width * 10, start.height * 6);
59 SwingUtilities.invokeLater(new Runnable() {
60 @Override
61 public void run() {
62 editor.scrollRectToVisible(show);
63 }
64 });
65 } catch (BadLocationException ex) {
66 throw new Error(ex);
67 }
68
69 // highlight the token momentarily
70 final Timer timer = new Timer(200, new ActionListener() {
71 private int m_counter = 0;
72 private Object m_highlight = null;
73
74 @Override
75 public void actionPerformed(ActionEvent event) {
76 if (m_counter % 2 == 0) {
77 try {
78 m_highlight = editor.getHighlighter().addHighlight(token.start, token.end, highlightPainter);
79 } catch (BadLocationException ex) {
80 // don't care
81 }
82 } else if (m_highlight != null) {
83 editor.getHighlighter().removeHighlight(m_highlight);
84 }
85
86 if (m_counter++ > 6) {
87 Timer timer = (Timer)event.getSource();
88 timer.stop();
89 }
90 }
91 });
92 timer.start();
93 }
94} 36}