Skip to content
This repository was archived by the owner on Nov 28, 2020. It is now read-only.

Commit 41ac47b

Browse files
committed
Fix clicking anywhere on the class tree opening the last selected class
1 parent 8b5819a commit 41ac47b

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/me/coley/jremapper/Main.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public static void main(String[] args) {
1414
}
1515
Program program = new Program();
1616
program.showGui();
17-
program.onFileSelect(new java.io.File("JRemapper.jar"));
18-
program.onClassSelect(program.getJarReader().getMapping().getOrCreateClassMapping("me/coley/bmf/FieldNode"));
17+
//program.onFileSelect(new java.io.File("JRemapper.jar"));
18+
//program.onClassSelect(program.getJarReader().getMapping().getOrCreateClassMapping("me/coley/bmf/FieldNode"));
1919
}
2020

2121
}

src/me/coley/jremapper/gui/component/tree/FileTree.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void setup() {
4545
String jarName = read.getFile().getName();
4646
MappingTreeNode root = new MappingTreeNode(jarName, null);
4747
DefaultTreeModel model = new DefaultTreeModel(root);
48-
FileSelectionListener sel = new FileSelectionListener(callback);
48+
FileSelectionListener sel = new FileSelectionListener(tree, callback);
4949
tree.addTreeSelectionListener(sel);
5050
tree.addMouseListener(sel);
5151
tree.setModel(model);
@@ -58,7 +58,7 @@ public void setup() {
5858
ClassMapping mapping = read.getMapping().getMapping(className);
5959
String curName = mapping.name.getValue();
6060
// Create directory path based on current mapping stored name.
61-
ArrayList<String> dirPath = new ArrayList<String>(Arrays.asList(curName.split("/")));
61+
List<String> dirPath = new ArrayList<>(Arrays.asList(curName.split("/")));
6262
// Create directory of nodes
6363
generateTreePath(root, dirPath, mapping, model);
6464
}
@@ -75,8 +75,8 @@ public void setup() {
7575
public void update(JarReader read, String originalName, String newPathName) {
7676
ClassMapping mapping = read.getMapping().getMapping(originalName);
7777
String curPathName = mapping.name.getValue();
78-
ArrayList<String> curPath = new ArrayList<String>(Arrays.asList(curPathName.split("/")));
79-
ArrayList<String> newPath = new ArrayList<String>(Arrays.asList(newPathName.split("/")));
78+
List<String> curPath = new ArrayList<>(Arrays.asList(curPathName.split("/")));
79+
List<String> newPath = new ArrayList<>(Arrays.asList(newPathName.split("/")));
8080
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
8181
//
8282
MappingTreeNode root = (MappingTreeNode) tree.getModel().getRoot();
@@ -93,7 +93,7 @@ public void update(JarReader read, String originalName, String newPathName) {
9393
* @param dirPath
9494
* @param model
9595
*/
96-
private void removeTreePath(MappingTreeNode parent, ArrayList<String> dirPath, DefaultTreeModel model) {
96+
private void removeTreePath(MappingTreeNode parent, List<String> dirPath, DefaultTreeModel model) {
9797
while (dirPath.size() > 0) {
9898
String section = dirPath.get(0);
9999
MappingTreeNode node = parent.getChild(section);
@@ -122,7 +122,7 @@ private void removeTreePath(MappingTreeNode parent, ArrayList<String> dirPath, D
122122
* @param mapping
123123
* @param model
124124
*/
125-
private void generateTreePath(MappingTreeNode parent, ArrayList<String> dirPath, ClassMapping mapping, DefaultTreeModel model) {
125+
private void generateTreePath(MappingTreeNode parent, List<String> dirPath, ClassMapping mapping, DefaultTreeModel model) {
126126
while (dirPath.size() > 0) {
127127
String section = dirPath.get(0);
128128
MappingTreeNode node;

src/me/coley/jremapper/gui/listener/FileSelectionListener.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.event.MouseEvent;
44
import java.awt.event.MouseListener;
55

6+
import javax.swing.JTree;
67
import javax.swing.event.TreeSelectionEvent;
78
import javax.swing.event.TreeSelectionListener;
89
import javax.swing.tree.TreeNode;
@@ -13,9 +14,11 @@
1314
public class FileSelectionListener implements TreeSelectionListener, MouseListener {
1415
private final Program callback;
1516
private TreeNode lastNode;
17+
private JTree tree;
1618

17-
public FileSelectionListener(Program callback) {
19+
public FileSelectionListener(JTree tree, Program callback) {
1820
this.callback = callback;
21+
this.tree = tree;
1922
}
2023

2124
@Override
@@ -28,8 +31,11 @@ public void valueChanged(TreeSelectionEvent e) {
2831
public void mouseClicked(MouseEvent e) {
2932
TreeNode node = lastNode;
3033
if (node != null && node.isLeaf() && (node instanceof MappingTreeNode)) {
31-
MappingTreeNode mtn = (MappingTreeNode) node;
32-
callback.onClassSelect(mtn.getMapping());
34+
if (tree.getSelectionPath().getLastPathComponent().equals(node)) {
35+
MappingTreeNode mtn = (MappingTreeNode) node;
36+
callback.onClassSelect(mtn.getMapping());
37+
}
38+
3339
}
3440
}
3541

src/me/coley/jremapper/parse/Context.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import me.coley.jremapper.Program;
1313

1414
public class Context {
15-
private final static List<String> ID_FLOW = Arrays.asList("if ", "else", "do", "while", "for", "continue", "break");
15+
//private final static List<String> ID_FLOW = Arrays.asList("if ", "else", "do", "while", "for", "continue", "break");
1616
private final static List<String> ID_MODIFIERS = Arrays.asList("abstract", "final", "interface", "native", "private", "protected", "public", "static", "strict", "synchronized", "transient",
1717
"volatile");
1818
private final static List<String> ID_PRIMITIVES = Arrays.asList("void", "boolean", "byte", "char", "short", "int", "long", "float", "double");

0 commit comments

Comments
 (0)