diff options
| author | 2014-08-22 01:25:52 -0400 | |
|---|---|---|
| committer | 2014-08-22 01:25:52 -0400 | |
| commit | 32b7ea70ff20d3584f8021e598141c20c2200398 (patch) | |
| tree | bb5b26427c76b9e31ff146e952e765c9c36b3383 /src/cuchaz/enigma/gui/Gui.java | |
| parent | fixed constructor references in call graph searches (diff) | |
| download | enigma-fork-32b7ea70ff20d3584f8021e598141c20c2200398.tar.gz enigma-fork-32b7ea70ff20d3584f8021e598141c20c2200398.tar.xz enigma-fork-32b7ea70ff20d3584f8021e598141c20c2200398.zip | |
added show token effects
Diffstat (limited to 'src/cuchaz/enigma/gui/Gui.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/Gui.java | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java index cd0fac7..914359b 100644 --- a/src/cuchaz/enigma/gui/Gui.java +++ b/src/cuchaz/enigma/gui/Gui.java | |||
| @@ -17,6 +17,7 @@ import java.awt.Dimension; | |||
| 17 | import java.awt.FlowLayout; | 17 | import java.awt.FlowLayout; |
| 18 | import java.awt.Font; | 18 | import java.awt.Font; |
| 19 | import java.awt.GridLayout; | 19 | import java.awt.GridLayout; |
| 20 | import java.awt.Rectangle; | ||
| 20 | import java.awt.event.ActionEvent; | 21 | import java.awt.event.ActionEvent; |
| 21 | import java.awt.event.ActionListener; | 22 | import java.awt.event.ActionListener; |
| 22 | import java.awt.event.InputEvent; | 23 | import java.awt.event.InputEvent; |
| @@ -53,6 +54,7 @@ import javax.swing.JTextField; | |||
| 53 | import javax.swing.JTree; | 54 | import javax.swing.JTree; |
| 54 | import javax.swing.KeyStroke; | 55 | import javax.swing.KeyStroke; |
| 55 | import javax.swing.ListSelectionModel; | 56 | import javax.swing.ListSelectionModel; |
| 57 | import javax.swing.Timer; | ||
| 56 | import javax.swing.WindowConstants; | 58 | import javax.swing.WindowConstants; |
| 57 | import javax.swing.event.CaretEvent; | 59 | import javax.swing.event.CaretEvent; |
| 58 | import javax.swing.event.CaretListener; | 60 | import javax.swing.event.CaretListener; |
| @@ -142,8 +144,9 @@ public class Gui | |||
| 142 | private JList<String> m_deobfClasses; | 144 | private JList<String> m_deobfClasses; |
| 143 | private JEditorPane m_editor; | 145 | private JEditorPane m_editor; |
| 144 | private JPanel m_infoPanel; | 146 | private JPanel m_infoPanel; |
| 145 | private BoxHighlightPainter m_obfuscatedHighlightPainter; | 147 | private ObfuscatedHighlightPainter m_obfuscatedHighlightPainter; |
| 146 | private BoxHighlightPainter m_deobfuscatedHighlightPainter; | 148 | private DeobfuscatedHighlightPainter m_deobfuscatedHighlightPainter; |
| 149 | private SelectionHighlightPainter m_selectionHighlightPainter; | ||
| 147 | private JTree m_inheritanceTree; | 150 | private JTree m_inheritanceTree; |
| 148 | private JTree m_callsTree; | 151 | private JTree m_callsTree; |
| 149 | private JList<Token> m_tokens; | 152 | private JList<Token> m_tokens; |
| @@ -250,6 +253,7 @@ public class Gui | |||
| 250 | DefaultSyntaxKit.initKit(); | 253 | DefaultSyntaxKit.initKit(); |
| 251 | m_obfuscatedHighlightPainter = new ObfuscatedHighlightPainter(); | 254 | m_obfuscatedHighlightPainter = new ObfuscatedHighlightPainter(); |
| 252 | m_deobfuscatedHighlightPainter = new DeobfuscatedHighlightPainter(); | 255 | m_deobfuscatedHighlightPainter = new DeobfuscatedHighlightPainter(); |
| 256 | m_selectionHighlightPainter = new SelectionHighlightPainter(); | ||
| 253 | m_editor = new JEditorPane(); | 257 | m_editor = new JEditorPane(); |
| 254 | m_editor.setEditable( false ); | 258 | m_editor.setEditable( false ); |
| 255 | m_editor.setCaret( new BrowserCaret() ); | 259 | m_editor.setCaret( new BrowserCaret() ); |
| @@ -756,14 +760,64 @@ public class Gui | |||
| 756 | m_editor.setText( source ); | 760 | m_editor.setText( source ); |
| 757 | } | 761 | } |
| 758 | 762 | ||
| 759 | public void showToken( Token token ) | 763 | public void showToken( final Token token ) |
| 760 | { | 764 | { |
| 761 | if( token == null ) | 765 | if( token == null ) |
| 762 | { | 766 | { |
| 763 | throw new IllegalArgumentException( "Token cannot be null!" ); | 767 | throw new IllegalArgumentException( "Token cannot be null!" ); |
| 764 | } | 768 | } |
| 769 | |||
| 770 | // set the caret position to the token | ||
| 765 | m_editor.setCaretPosition( token.start ); | 771 | m_editor.setCaretPosition( token.start ); |
| 766 | m_editor.grabFocus(); | 772 | m_editor.grabFocus(); |
| 773 | |||
| 774 | try | ||
| 775 | { | ||
| 776 | // make sure the token is visible in the scroll window | ||
| 777 | Rectangle start = m_editor.modelToView( token.start ); | ||
| 778 | Rectangle end = m_editor.modelToView( token.end ); | ||
| 779 | Rectangle show = start.union( end ); | ||
| 780 | show.grow( 0, start.height*6 ); | ||
| 781 | m_editor.scrollRectToVisible( show ); | ||
| 782 | } | ||
| 783 | catch( BadLocationException ex ) | ||
| 784 | { | ||
| 785 | throw new Error( ex ); | ||
| 786 | } | ||
| 787 | |||
| 788 | // highlight the token momentarily | ||
| 789 | final Timer timer = new Timer( 200, new ActionListener( ) | ||
| 790 | { | ||
| 791 | private int m_counter = 0; | ||
| 792 | private Object m_highlight = null; | ||
| 793 | |||
| 794 | @Override | ||
| 795 | public void actionPerformed( ActionEvent event ) | ||
| 796 | { | ||
| 797 | if( m_counter % 2 == 0 ) | ||
| 798 | { | ||
| 799 | try | ||
| 800 | { | ||
| 801 | m_highlight = m_editor.getHighlighter().addHighlight( token.start, token.end, m_selectionHighlightPainter ); | ||
| 802 | } | ||
| 803 | catch( BadLocationException ex ) | ||
| 804 | { | ||
| 805 | // don't care | ||
| 806 | } | ||
| 807 | } | ||
| 808 | else if( m_highlight != null ) | ||
| 809 | { | ||
| 810 | m_editor.getHighlighter().removeHighlight( m_highlight ); | ||
| 811 | } | ||
| 812 | |||
| 813 | if( m_counter++ > 6 ) | ||
| 814 | { | ||
| 815 | Timer timer = (Timer)event.getSource(); | ||
| 816 | timer.stop(); | ||
| 817 | } | ||
| 818 | } | ||
| 819 | } ); | ||
| 820 | timer.start(); | ||
| 767 | } | 821 | } |
| 768 | 822 | ||
| 769 | public void showTokens( Collection<Token> tokens ) | 823 | public void showTokens( Collection<Token> tokens ) |
| @@ -790,6 +844,7 @@ public class Gui | |||
| 790 | // remove any old highlighters | 844 | // remove any old highlighters |
| 791 | m_editor.getHighlighter().removeAllHighlights(); | 845 | m_editor.getHighlighter().removeAllHighlights(); |
| 792 | 846 | ||
| 847 | |||
| 793 | // color things based on the index | 848 | // color things based on the index |
| 794 | if( obfuscatedTokens != null ) | 849 | if( obfuscatedTokens != null ) |
| 795 | { | 850 | { |