diff options
Diffstat (limited to 'src/main/java')
6 files changed, 23 insertions, 30 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java b/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java index a069bcac..e8136881 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java +++ b/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java | |||
| @@ -128,7 +128,7 @@ public class ClassMatchingGui { | |||
| 128 | sourceTypePanel.add(button); | 128 | sourceTypePanel.add(button); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | this.sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | 131 | this.sourceClasses = new ClassSelector(ClassSelector.DEOBF_CLASS_COMPARATOR); |
| 132 | this.sourceClasses.setListener(this::setSourceClass); | 132 | this.sourceClasses.setListener(this::setSourceClass); |
| 133 | JScrollPane sourceScroller = new JScrollPane(this.sourceClasses); | 133 | JScrollPane sourceScroller = new JScrollPane(this.sourceClasses); |
| 134 | sourcePanel.add(sourceScroller); | 134 | sourcePanel.add(sourceScroller); |
| @@ -144,7 +144,7 @@ public class ClassMatchingGui { | |||
| 144 | destPanel.add(this.top10Matches); | 144 | destPanel.add(this.top10Matches); |
| 145 | this.top10Matches.addActionListener(event -> toggleTop10Matches()); | 145 | this.top10Matches.addActionListener(event -> toggleTop10Matches()); |
| 146 | 146 | ||
| 147 | this.destClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | 147 | this.destClasses = new ClassSelector(ClassSelector.DEOBF_CLASS_COMPARATOR); |
| 148 | this.destClasses.setListener(this::setDestClass); | 148 | this.destClasses.setListener(this::setDestClass); |
| 149 | JScrollPane destScroller = new JScrollPane(this.destClasses); | 149 | JScrollPane destScroller = new JScrollPane(this.destClasses); |
| 150 | destPanel.add(destScroller); | 150 | destPanel.add(destScroller); |
diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelector.java b/src/main/java/cuchaz/enigma/gui/ClassSelector.java index f6abd51e..2ee3b2ae 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelector.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelector.java | |||
| @@ -29,35 +29,17 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 29 | public class ClassSelector extends JTree { | 29 | public class ClassSelector extends JTree { |
| 30 | 30 | ||
| 31 | private static final long serialVersionUID = -7632046902384775977L; | 31 | private static final long serialVersionUID = -7632046902384775977L; |
| 32 | public static final Comparator<ClassEntry> DEOBF_CLASS_COMPARATOR = (a, b) -> { | ||
| 33 | if (a instanceof ScoredClassEntry && b instanceof ScoredClassEntry) { | ||
| 34 | return Float.compare(((ScoredClassEntry) b).getScore(), ((ScoredClassEntry) a).getScore()); | ||
| 35 | } | ||
| 36 | return a.getName().compareTo(b.getName()); | ||
| 37 | }; | ||
| 32 | 38 | ||
| 33 | public interface ClassSelectionListener { | 39 | public interface ClassSelectionListener { |
| 34 | void onSelectClass(ClassEntry classEntry); | 40 | void onSelectClass(ClassEntry classEntry); |
| 35 | } | 41 | } |
| 36 | 42 | ||
| 37 | public static Comparator<ClassEntry> ObfuscatedClassEntryComparator; | ||
| 38 | public static Comparator<ClassEntry> DeobfuscatedClassEntryComparator; | ||
| 39 | |||
| 40 | static { | ||
| 41 | ObfuscatedClassEntryComparator = (a, b) -> { | ||
| 42 | String aname = a.getName(); | ||
| 43 | String bname = a.getName(); | ||
| 44 | if (aname.length() != bname.length()) { | ||
| 45 | return aname.length() - bname.length(); | ||
| 46 | } | ||
| 47 | return aname.compareTo(bname); | ||
| 48 | }; | ||
| 49 | |||
| 50 | DeobfuscatedClassEntryComparator = (a, b) -> { | ||
| 51 | if (a instanceof ScoredClassEntry && b instanceof ScoredClassEntry) { | ||
| 52 | return Float.compare( | ||
| 53 | ((ScoredClassEntry) b).getScore(), | ||
| 54 | ((ScoredClassEntry) a).getScore() | ||
| 55 | ); | ||
| 56 | } | ||
| 57 | return a.getName().compareTo(b.getName()); | ||
| 58 | }; | ||
| 59 | } | ||
| 60 | |||
| 61 | private ClassSelectionListener listener; | 43 | private ClassSelectionListener listener; |
| 62 | private Comparator<ClassEntry> comparator; | 44 | private Comparator<ClassEntry> comparator; |
| 63 | 45 | ||
diff --git a/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java b/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java index f083e50f..0713ad58 100644 --- a/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java +++ b/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java | |||
| @@ -129,7 +129,7 @@ public class MemberMatchingGui<T extends Entry> { | |||
| 129 | sourceTypePanel.add(button); | 129 | sourceTypePanel.add(button); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | m_sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | 132 | m_sourceClasses = new ClassSelector(ClassSelector.DEOBF_CLASS_COMPARATOR); |
| 133 | m_sourceClasses.setListener(this::setSourceClass); | 133 | m_sourceClasses.setListener(this::setSourceClass); |
| 134 | JScrollPane sourceScroller = new JScrollPane(m_sourceClasses); | 134 | JScrollPane sourceScroller = new JScrollPane(m_sourceClasses); |
| 135 | classesPanel.add(sourceScroller); | 135 | classesPanel.add(sourceScroller); |
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelDeobf.java b/src/main/java/cuchaz/enigma/gui/panels/PanelDeobf.java index d89de36e..2cc8b76a 100644 --- a/src/main/java/cuchaz/enigma/gui/panels/PanelDeobf.java +++ b/src/main/java/cuchaz/enigma/gui/panels/PanelDeobf.java | |||
| @@ -17,7 +17,7 @@ public class PanelDeobf extends JPanel { | |||
| 17 | public PanelDeobf(Gui gui) { | 17 | public PanelDeobf(Gui gui) { |
| 18 | this.gui = gui; | 18 | this.gui = gui; |
| 19 | 19 | ||
| 20 | this.deobfClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | 20 | this.deobfClasses = new ClassSelector(ClassSelector.DEOBF_CLASS_COMPARATOR); |
| 21 | this.deobfClasses.setListener(gui::navigateTo); | 21 | this.deobfClasses.setListener(gui::navigateTo); |
| 22 | 22 | ||
| 23 | this.setLayout(new BorderLayout()); | 23 | this.setLayout(new BorderLayout()); |
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelObf.java b/src/main/java/cuchaz/enigma/gui/panels/PanelObf.java index 745cb2e4..3e0374e7 100644 --- a/src/main/java/cuchaz/enigma/gui/panels/PanelObf.java +++ b/src/main/java/cuchaz/enigma/gui/panels/PanelObf.java | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | package cuchaz.enigma.gui.panels; | 1 | package cuchaz.enigma.gui.panels; |
| 2 | 2 | ||
| 3 | import java.awt.BorderLayout; | 3 | import java.awt.BorderLayout; |
| 4 | import java.util.Comparator; | ||
| 4 | 5 | ||
| 5 | import javax.swing.JLabel; | 6 | import javax.swing.JLabel; |
| 6 | import javax.swing.JPanel; | 7 | import javax.swing.JPanel; |
| @@ -8,6 +9,7 @@ import javax.swing.JScrollPane; | |||
| 8 | 9 | ||
| 9 | import cuchaz.enigma.gui.ClassSelector; | 10 | import cuchaz.enigma.gui.ClassSelector; |
| 10 | import cuchaz.enigma.gui.Gui; | 11 | import cuchaz.enigma.gui.Gui; |
| 12 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 11 | 13 | ||
| 12 | public class PanelObf extends JPanel { | 14 | public class PanelObf extends JPanel { |
| 13 | 15 | ||
| @@ -17,7 +19,16 @@ public class PanelObf extends JPanel { | |||
| 17 | public PanelObf(Gui gui) { | 19 | public PanelObf(Gui gui) { |
| 18 | this.gui = gui; | 20 | this.gui = gui; |
| 19 | 21 | ||
| 20 | this.obfClasses = new ClassSelector(ClassSelector.ObfuscatedClassEntryComparator); | 22 | Comparator<ClassEntry> obfClassComparator = (a, b) -> { |
| 23 | String aname = a.getName(); | ||
| 24 | String bname = b.getName(); | ||
| 25 | if (aname.length() != bname.length()) { | ||
| 26 | return aname.length() - bname.length(); | ||
| 27 | } | ||
| 28 | return aname.compareTo(bname); | ||
| 29 | }; | ||
| 30 | |||
| 31 | this.obfClasses = new ClassSelector(obfClassComparator); | ||
| 21 | this.obfClasses.setListener(gui::navigateTo); | 32 | this.obfClasses.setListener(gui::navigateTo); |
| 22 | 33 | ||
| 23 | this.setLayout(new BorderLayout()); | 34 | this.setLayout(new BorderLayout()); |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java index 3b06e926..7aedc5b1 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java | |||
| @@ -34,7 +34,7 @@ public class MappingsReader { | |||
| 34 | File[] fList = in.listFiles(); | 34 | File[] fList = in.listFiles(); |
| 35 | if (fList != null) { | 35 | if (fList != null) { |
| 36 | for (File file : fList) { | 36 | for (File file : fList) { |
| 37 | if (file.isFile()&& Files.getFileExtension(file.getName()).equalsIgnoreCase("json")) { | 37 | if (file.isFile() && Files.getFileExtension(file.getName()).equalsIgnoreCase("json")) { |
| 38 | readFile(mappings, new BufferedReader(new FileReader(file))); | 38 | readFile(mappings, new BufferedReader(new FileReader(file))); |
| 39 | } else if (file.isDirectory()) { | 39 | } else if (file.isDirectory()) { |
| 40 | readDirectory(mappings, file.getAbsoluteFile()); | 40 | readDirectory(mappings, file.getAbsoluteFile()); |