diff options
| author | 2015-03-09 12:53:11 -0400 | |
|---|---|---|
| committer | 2015-03-09 12:53:11 -0400 | |
| commit | d6b2a223a7973941e5e4fb45c8ceec4885891496 (patch) | |
| tree | 5728ab513d0b4ed85a720da7eb48c6591dd3f8b0 /src/cuchaz/enigma/gui/FieldMatchingGui.java | |
| parent | add tracking for mismatched fields/methods (diff) | |
| download | enigma-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/FieldMatchingGui.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/FieldMatchingGui.java | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/gui/FieldMatchingGui.java b/src/cuchaz/enigma/gui/FieldMatchingGui.java new file mode 100644 index 0000000..de9ba14 --- /dev/null +++ b/src/cuchaz/enigma/gui/FieldMatchingGui.java | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | package cuchaz.enigma.gui; | ||
| 2 | |||
| 3 | import java.awt.BorderLayout; | ||
| 4 | import java.awt.Container; | ||
| 5 | import java.awt.Dimension; | ||
| 6 | import java.awt.FlowLayout; | ||
| 7 | import java.util.Map; | ||
| 8 | |||
| 9 | import javax.swing.BoxLayout; | ||
| 10 | import javax.swing.JFrame; | ||
| 11 | import javax.swing.JLabel; | ||
| 12 | import javax.swing.JPanel; | ||
| 13 | import javax.swing.JScrollPane; | ||
| 14 | import javax.swing.JSplitPane; | ||
| 15 | import javax.swing.WindowConstants; | ||
| 16 | |||
| 17 | import cuchaz.enigma.Constants; | ||
| 18 | import cuchaz.enigma.Deobfuscator; | ||
| 19 | import cuchaz.enigma.convert.ClassMatches; | ||
| 20 | import cuchaz.enigma.convert.FieldMatches; | ||
| 21 | import cuchaz.enigma.gui.ClassSelector.ClassSelectionListener; | ||
| 22 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 23 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 24 | import cuchaz.enigma.mapping.FieldMapping; | ||
| 25 | import de.sciss.syntaxpane.DefaultSyntaxKit; | ||
| 26 | |||
| 27 | |||
| 28 | public class FieldMatchingGui { | ||
| 29 | |||
| 30 | public static interface SaveListener { | ||
| 31 | public void save(FieldMatches matches); | ||
| 32 | } | ||
| 33 | |||
| 34 | // controls | ||
| 35 | private JFrame m_frame; | ||
| 36 | private ClassSelector m_sourceClasses; | ||
| 37 | private CodeReader m_sourceReader; | ||
| 38 | private CodeReader m_destReader; | ||
| 39 | |||
| 40 | private ClassMatches m_classMatches; | ||
| 41 | private FieldMatches m_fieldMatches; | ||
| 42 | private Map<FieldEntry,FieldMapping> m_droppedFieldMappings; | ||
| 43 | private Deobfuscator m_sourceDeobfuscator; | ||
| 44 | private Deobfuscator m_destDeobfuscator; | ||
| 45 | private SaveListener m_saveListener; | ||
| 46 | |||
| 47 | public FieldMatchingGui(ClassMatches classMatches, FieldMatches fieldMatches, Map<FieldEntry,FieldMapping> droppedFieldMappings, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) { | ||
| 48 | |||
| 49 | m_classMatches = classMatches; | ||
| 50 | m_fieldMatches = fieldMatches; | ||
| 51 | m_droppedFieldMappings = droppedFieldMappings; | ||
| 52 | m_sourceDeobfuscator = sourceDeobfuscator; | ||
| 53 | m_destDeobfuscator = destDeobfuscator; | ||
| 54 | |||
| 55 | // init frame | ||
| 56 | m_frame = new JFrame(Constants.Name + " - Field Matcher"); | ||
| 57 | final Container pane = m_frame.getContentPane(); | ||
| 58 | pane.setLayout(new BorderLayout()); | ||
| 59 | |||
| 60 | // init classes side | ||
| 61 | JPanel classesPanel = new JPanel(); | ||
| 62 | classesPanel.setLayout(new BoxLayout(classesPanel, BoxLayout.PAGE_AXIS)); | ||
| 63 | classesPanel.setPreferredSize(new Dimension(200, 0)); | ||
| 64 | pane.add(classesPanel, BorderLayout.WEST); | ||
| 65 | classesPanel.add(new JLabel("Classes")); | ||
| 66 | |||
| 67 | m_sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | ||
| 68 | m_sourceClasses.setListener(new ClassSelectionListener() { | ||
| 69 | @Override | ||
| 70 | public void onSelectClass(ClassEntry classEntry) { | ||
| 71 | setSourceClass(classEntry); | ||
| 72 | } | ||
| 73 | }); | ||
| 74 | JScrollPane sourceScroller = new JScrollPane(m_sourceClasses); | ||
| 75 | classesPanel.add(sourceScroller); | ||
| 76 | |||
| 77 | // init fields side | ||
| 78 | JPanel fieldsPanel = new JPanel(); | ||
| 79 | fieldsPanel.setLayout(new BoxLayout(fieldsPanel, BoxLayout.PAGE_AXIS)); | ||
| 80 | fieldsPanel.setPreferredSize(new Dimension(200, 0)); | ||
| 81 | pane.add(fieldsPanel, BorderLayout.WEST); | ||
| 82 | fieldsPanel.add(new JLabel("Destination Fields")); | ||
| 83 | |||
| 84 | // init readers | ||
| 85 | DefaultSyntaxKit.initKit(); | ||
| 86 | m_sourceReader = new CodeReader(); | ||
| 87 | m_destReader = new CodeReader(); | ||
| 88 | |||
| 89 | // init all the splits | ||
| 90 | JSplitPane splitLeft = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, classesPanel, new JScrollPane(m_sourceReader)); | ||
| 91 | splitLeft.setResizeWeight(0); // let the right side take all the slack | ||
| 92 | JSplitPane splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, new JScrollPane(m_destReader), fieldsPanel); | ||
| 93 | splitRight.setResizeWeight(1); // let the left side take all the slack | ||
| 94 | JSplitPane splitCenter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, splitRight); | ||
| 95 | splitCenter.setResizeWeight(0.5); // resize 50:50 | ||
| 96 | pane.add(splitCenter, BorderLayout.CENTER); | ||
| 97 | splitCenter.resetToPreferredSizes(); | ||
| 98 | |||
| 99 | // init bottom panel | ||
| 100 | JPanel bottomPanel = new JPanel(); | ||
| 101 | bottomPanel.setLayout(new FlowLayout()); | ||
| 102 | |||
| 103 | // show the frame | ||
| 104 | pane.doLayout(); | ||
| 105 | m_frame.setSize(1024, 576); | ||
| 106 | m_frame.setMinimumSize(new Dimension(640, 480)); | ||
| 107 | m_frame.setVisible(true); | ||
| 108 | m_frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); | ||
| 109 | |||
| 110 | // init state | ||
| 111 | m_saveListener = null; | ||
| 112 | m_fieldMatches.addUnmatchedSourceFields(droppedFieldMappings.keySet()); | ||
| 113 | m_sourceClasses.setClasses(m_fieldMatches.getSourceClassesWithUnmatchedFields()); | ||
| 114 | } | ||
| 115 | |||
| 116 | public void setSaveListener(SaveListener val) { | ||
| 117 | m_saveListener = val; | ||
| 118 | } | ||
| 119 | |||
| 120 | protected void setSourceClass(ClassEntry obfSourceClass) { | ||
| 121 | |||
| 122 | // get the matched dest class | ||
| 123 | final ClassEntry obfDestClass = m_classMatches.getUniqueMatches().get(obfSourceClass); | ||
| 124 | if (obfDestClass == null) { | ||
| 125 | throw new Error("No matching dest class for source class: " + obfSourceClass); | ||
| 126 | } | ||
| 127 | |||
| 128 | m_sourceReader.decompileClass(obfSourceClass, m_sourceDeobfuscator); | ||
| 129 | m_destReader.decompileClass(obfDestClass, m_destDeobfuscator); | ||
| 130 | } | ||
| 131 | } | ||