diff options
| author | 2014-08-22 01:25:52 -0400 | |
|---|---|---|
| committer | 2014-08-22 01:25:52 -0400 | |
| commit | 32b7ea70ff20d3584f8021e598141c20c2200398 (patch) | |
| tree | bb5b26427c76b9e31ff146e952e765c9c36b3383 | |
| parent | fixed constructor references in call graph searches (diff) | |
| download | enigma-32b7ea70ff20d3584f8021e598141c20c2200398.tar.gz enigma-32b7ea70ff20d3584f8021e598141c20c2200398.tar.xz enigma-32b7ea70ff20d3584f8021e598141c20c2200398.zip | |
added show token effects
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourceIndex.java | 2 | ||||
| -rw-r--r-- | src/cuchaz/enigma/gui/BoxHighlightPainter.java | 23 | ||||
| -rw-r--r-- | src/cuchaz/enigma/gui/Gui.java | 61 | ||||
| -rw-r--r-- | src/cuchaz/enigma/gui/SelectionHighlightPainter.java | 35 |
4 files changed, 109 insertions, 12 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndex.java b/src/cuchaz/enigma/analysis/SourceIndex.java index 960ec36f..1a5a80d6 100644 --- a/src/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/cuchaz/enigma/analysis/SourceIndex.java | |||
| @@ -117,7 +117,7 @@ public class SourceIndex | |||
| 117 | public Token getReferenceToken( int pos ) | 117 | public Token getReferenceToken( int pos ) |
| 118 | { | 118 | { |
| 119 | Token token = m_tokenToReference.floorKey( new Token( pos, pos ) ); | 119 | Token token = m_tokenToReference.floorKey( new Token( pos, pos ) ); |
| 120 | if( token.contains( pos ) ) | 120 | if( token != null && token.contains( pos ) ) |
| 121 | { | 121 | { |
| 122 | return token; | 122 | return token; |
| 123 | } | 123 | } |
diff --git a/src/cuchaz/enigma/gui/BoxHighlightPainter.java b/src/cuchaz/enigma/gui/BoxHighlightPainter.java index b9474ff8..2c118340 100644 --- a/src/cuchaz/enigma/gui/BoxHighlightPainter.java +++ b/src/cuchaz/enigma/gui/BoxHighlightPainter.java | |||
| @@ -33,10 +33,23 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte | |||
| 33 | @Override | 33 | @Override |
| 34 | public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) | 34 | public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) |
| 35 | { | 35 | { |
| 36 | Rectangle bounds = getBounds( text, start, end ); | ||
| 37 | |||
| 38 | // fill the area | ||
| 39 | g.setColor( m_fillColor ); | ||
| 40 | g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 41 | |||
| 42 | // draw a box around the area | ||
| 43 | g.setColor( m_borderColor ); | ||
| 44 | g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 45 | } | ||
| 46 | |||
| 47 | protected static Rectangle getBounds( JTextComponent text, int start, int end ) | ||
| 48 | { | ||
| 36 | try | 49 | try |
| 37 | { | 50 | { |
| 38 | // determine the bounds of the text | 51 | // determine the bounds of the text |
| 39 | Rectangle bounds = text.getUI().modelToView( text, start ).union( text.getUI().modelToView( text, end ) ); | 52 | Rectangle bounds = text.modelToView( start ).union( text.modelToView( end ) ); |
| 40 | 53 | ||
| 41 | // adjust the box so it looks nice | 54 | // adjust the box so it looks nice |
| 42 | bounds.x -= 2; | 55 | bounds.x -= 2; |
| @@ -44,13 +57,7 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte | |||
| 44 | bounds.y += 1; | 57 | bounds.y += 1; |
| 45 | bounds.height -= 2; | 58 | bounds.height -= 2; |
| 46 | 59 | ||
| 47 | // fill the area | 60 | return bounds; |
| 48 | g.setColor( m_fillColor ); | ||
| 49 | g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 50 | |||
| 51 | // draw a box around the area | ||
| 52 | g.setColor( m_borderColor ); | ||
| 53 | g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 54 | } | 61 | } |
| 55 | catch( BadLocationException ex ) | 62 | catch( BadLocationException ex ) |
| 56 | { | 63 | { |
diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java index cd0fac76..914359b4 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 | { |
diff --git a/src/cuchaz/enigma/gui/SelectionHighlightPainter.java b/src/cuchaz/enigma/gui/SelectionHighlightPainter.java new file mode 100644 index 00000000..35f94518 --- /dev/null +++ b/src/cuchaz/enigma/gui/SelectionHighlightPainter.java | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.gui; | ||
| 12 | |||
| 13 | import java.awt.BasicStroke; | ||
| 14 | import java.awt.Color; | ||
| 15 | import java.awt.Graphics; | ||
| 16 | import java.awt.Graphics2D; | ||
| 17 | import java.awt.Rectangle; | ||
| 18 | import java.awt.Shape; | ||
| 19 | |||
| 20 | import javax.swing.text.Highlighter; | ||
| 21 | import javax.swing.text.JTextComponent; | ||
| 22 | |||
| 23 | public class SelectionHighlightPainter implements Highlighter.HighlightPainter | ||
| 24 | { | ||
| 25 | @Override | ||
| 26 | public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) | ||
| 27 | { | ||
| 28 | // draw a thick border | ||
| 29 | Graphics2D g2d = (Graphics2D)g; | ||
| 30 | Rectangle bounds = BoxHighlightPainter.getBounds( text, start, end ); | ||
| 31 | g2d.setColor( Color.black ); | ||
| 32 | g2d.setStroke( new BasicStroke( 2.0f ) ); | ||
| 33 | g2d.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 34 | } | ||
| 35 | } | ||