From 7b355607eb3360db053d05db4f3d500d79032b17 Mon Sep 17 00:00:00 2001 From: deathmarine Date: Thu, 25 Aug 2016 09:21:26 -0400 Subject: [PATCH] Resolved issues with FindAll dialog. Doubleclicking FindAll items decompiles. --- src/us/deathmarine/luyten/FindAllBox.java | 31 ++++++++-- src/us/deathmarine/luyten/Model.java | 73 +++++++++++++---------- 2 files changed, 69 insertions(+), 35 deletions(-) diff --git a/src/us/deathmarine/luyten/FindAllBox.java b/src/us/deathmarine/luyten/FindAllBox.java index 2596e98..721ceca 100644 --- a/src/us/deathmarine/luyten/FindAllBox.java +++ b/src/us/deathmarine/luyten/FindAllBox.java @@ -10,15 +10,19 @@ import us.deathmarine.luyten.ConfigSaver; import us.deathmarine.luyten.MainWindow; import us.deathmarine.luyten.Model; +import us.deathmarine.luyten.Model.State; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.StringWriter; import java.util.Collections; import java.util.Enumeration; @@ -27,6 +31,8 @@ import javax.swing.*; import javax.swing.GroupLayout.Alignment; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreePath; public class FindAllBox extends JDialog { private static final long serialVersionUID = -4125409760166690462L; @@ -41,10 +47,8 @@ public class FindAllBox extends JDialog { private DefaultListModel classesList = new DefaultListModel(); private Thread tmp_thread; - private MainWindow mainWindow; - public FindAllBox(MainWindow mainWindow) { - this.mainWindow = mainWindow; + public FindAllBox(final MainWindow mainWindow) { this.setDefaultCloseOperation(HIDE_ON_CLOSE); this.setHideOnEscapeButton(); @@ -61,6 +65,26 @@ public FindAllBox(MainWindow mainWindow) { list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); list.setLayoutOrientation(JList.VERTICAL_WRAP); list.setVisibleRowCount(-1); + list.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent evt) { + @SuppressWarnings("unchecked") + JList list = (JList) evt.getSource(); + if (evt.getClickCount() == 2) { + int index = list.locationToIndex(evt.getPoint()); + String entryName = (String) list.getModel().getElementAt(index); + String[] array = entryName.split("/"); + String internalName = StringUtilities.removeRight(entryName, ".class"); + TypeReference type = Model.metadataSystem.lookupType(internalName); + try { + mainWindow.getModel().extractClassToTextPane(type, array[array.length-1], entryName, null); + } catch (Exception e) { + e.printStackTrace(); + } + + + } + } + }); JScrollPane listScroller = new JScrollPane(list); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); @@ -115,7 +139,6 @@ public FindAllBox(MainWindow mainWindow) { .addComponent(statusLabel).addComponent(progressBar)); this.adjustWindowPositionBySavedState(); this.setSaveWindowPositionOnClosing(); - //this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); this.setName("Find All"); this.setTitle("Find All"); diff --git a/src/us/deathmarine/luyten/Model.java b/src/us/deathmarine/luyten/Model.java index ff1df58..63ff353 100644 --- a/src/us/deathmarine/luyten/Model.java +++ b/src/us/deathmarine/luyten/Model.java @@ -90,7 +90,7 @@ public class Model extends JSplitPane { public Model(MainWindow mainWindow) { this.mainWindow = mainWindow; this.bar = mainWindow.getBar(); - this.label = mainWindow.getLabel(); + this.setLabel(mainWindow.getLabel()); configSaver = ConfigSaver.getLoadedInstance(); settings = configSaver.getDecompilerSettings(); @@ -229,7 +229,7 @@ public void run() { } } - private void openEntryByTreePath(TreePath trp) { + public void openEntryByTreePath(TreePath trp) { String name = ""; String path = ""; try { @@ -264,12 +264,12 @@ private void openEntryByTreePath(TreePath trp) { } String entryName = entry.getName(); if (entryName.endsWith(".class")) { - label.setText("Extracting: " + name); + getLabel().setText("Extracting: " + name); String internalName = StringUtilities.removeRight(entryName, ".class"); TypeReference type = metadataSystem.lookupType(internalName); extractClassToTextPane(type, name, path, null); } else { - label.setText("Opening: " + name); + getLabel().setText("Opening: " + name); try (InputStream in = state.jarFile.getInputStream(entry);) { extractSimpleFileEntryToTextPane(in, name, path); } @@ -282,26 +282,26 @@ private void openEntryByTreePath(TreePath trp) { throw new TooLargeFileException(file.length()); } if (name.endsWith(".class")) { - label.setText("Extracting: " + name); + getLabel().setText("Extracting: " + name); TypeReference type = metadataSystem.lookupType(path); extractClassToTextPane(type, name, path, null); } else { - label.setText("Opening: " + name); + getLabel().setText("Opening: " + name); try (InputStream in = new FileInputStream(file);) { extractSimpleFileEntryToTextPane(in, name, path); } } } - label.setText("Complete"); + getLabel().setText("Complete"); } catch (FileEntryNotFoundException e) { - label.setText("File not found: " + name); + getLabel().setText("File not found: " + name); } catch (FileIsBinaryException e) { - label.setText("Binary resource: " + name); + getLabel().setText("Binary resource: " + name); } catch (TooLargeFileException e) { - label.setText("File is too large: " + name + " - size: " + e.getReadableFileSize()); + getLabel().setText("File is too large: " + name + " - size: " + e.getReadableFileSize()); } catch (Exception e) { - label.setText("Cannot open: " + name); + getLabel().setText("Cannot open: " + name); e.printStackTrace(); JOptionPane.showMessageDialog(null, e.toString(), "Error!", JOptionPane.ERROR_MESSAGE); } finally { @@ -309,7 +309,7 @@ private void openEntryByTreePath(TreePath trp) { } } - private void extractClassToTextPane(TypeReference type, String tabTitle, String path, + void extractClassToTextPane(TypeReference type, String tabTitle, String path, String navigatonLink) throws Exception { if (tabTitle == null || tabTitle.trim().length() < 1 || path == null) { throw new FileEntryNotFoundException(); @@ -355,7 +355,7 @@ private void extractClassToTextPane(TypeReference type, String tabTitle, String } } - private void extractSimpleFileEntryToTextPane(InputStream inputStream, String tabTitle, String path) + public void extractSimpleFileEntryToTextPane(InputStream inputStream, String tabTitle, String path) throws Exception { if (inputStream == null || tabTitle == null || tabTitle.trim().length() < 1 || path == null) { throw new FileEntryNotFoundException(); @@ -434,9 +434,6 @@ public void stateChanged(ChangeEvent e) { } } - public void openFileFromPath(){ - - } public void updateOpenClasses() { // invalidate all open classes (update will hapen at tab change) for (OpenFile open : hmap) { @@ -462,12 +459,12 @@ private void updateOpenClass(final OpenFile open) { public void run() { try { bar.setVisible(true); - label.setText("Extracting: " + open.name); + getLabel().setText("Extracting: " + open.name); open.invalidateContent(); open.decompile(); - label.setText("Complete"); + getLabel().setText("Complete"); } catch (Exception e) { - label.setText("Error, cannot update: " + open.name); + getLabel().setText("Error, cannot update: " + open.name); } finally { bar.setVisible(false); } @@ -481,7 +478,7 @@ private boolean isTabInForeground(OpenFile open) { return (selectedIndex >= 0 && selectedIndex == house.indexOfTab(title)); } - private final class State implements AutoCloseable { + final class State implements AutoCloseable { private final String key; private final File file; final JarFile jarFile; @@ -621,7 +618,7 @@ public void run() { if (file.getName().endsWith(".zip") || file.getName().endsWith(".jar")) { JarFile jfile; jfile = new JarFile(file); - label.setText("Loading: " + jfile.getName()); + getLabel().setText("Loading: " + jfile.getName()); bar.setVisible(true); JarEntryFilter jarEntryFilter = new JarEntryFilter(jfile); @@ -639,14 +636,14 @@ public void run() { state = new State(file.getCanonicalPath(), file, jfile, jarLoader); } open = true; - label.setText("Complete"); + getLabel().setText("Complete"); } else { TreeNodeUserObject topNodeUserObject = new TreeNodeUserObject(getName(file.getName())); final DefaultMutableTreeNode top = new DefaultMutableTreeNode(topNodeUserObject); tree.setModel(new DefaultTreeModel(top)); settings.setTypeLoader(new InputTypeLoader()); open = true; - label.setText("Complete"); + getLabel().setText("Complete"); // open it automatically new Thread() { @@ -666,11 +663,11 @@ public void run() { } } } catch (TooLargeFileException e) { - label.setText("File is too large: " + file.getName() + " - size: " + e.getReadableFileSize()); + getLabel().setText("File is too large: " + file.getName() + " - size: " + e.getReadableFileSize()); closeFile(); } catch (Exception e1) { e1.printStackTrace(); - label.setText("Cannot open: " + file.getName()); + getLabel().setText("Cannot open: " + file.getName()); closeFile(); } finally { mainWindow.onFileLoadEnded(file, open); @@ -856,7 +853,7 @@ public File getOpenedFile() { openedFile = file; } if (openedFile == null) { - label.setText("No open file"); + getLabel().setText("No open file"); } return openedFile; } @@ -872,7 +869,7 @@ public String getCurrentTabTitle() { e1.printStackTrace(); } if (tabTitle == null) { - label.setText("No open tab"); + getLabel().setText("No open tab"); } return tabTitle; } @@ -889,7 +886,7 @@ public RSyntaxTextArea getCurrentTextArea() { e1.printStackTrace(); } if (currentTextArea == null) { - label.setText("No open tab"); + getLabel().setText("No open tab"); } return currentTextArea; } @@ -935,7 +932,7 @@ public void run() { String destinationTypeStr = linkParts[1]; try { bar.setVisible(true); - label.setText("Navigating: " + destinationTypeStr.replaceAll("/", ".")); + getLabel().setText("Navigating: " + destinationTypeStr.replaceAll("/", ".")); TypeReference type = metadataSystem.lookupType(destinationTypeStr); if (type == null) @@ -947,9 +944,9 @@ public void run() { String tabTitle = typeDef.getName() + ".class"; extractClassToTextPane(typeDef, tabTitle, destinationTypeStr, uniqueStr); - label.setText("Complete"); + getLabel().setText("Complete"); } catch (Exception e) { - label.setText("Cannot navigate: " + destinationTypeStr.replaceAll("/", ".")); + getLabel().setText("Cannot navigate: " + destinationTypeStr.replaceAll("/", ".")); e.printStackTrace(); } finally { bar.setVisible(false); @@ -957,4 +954,18 @@ public void run() { } }).start(); } + + public JLabel getLabel() { + return label; + } + + public void setLabel(JLabel label) { + this.label = label; + } + + public State getState(){ + return state; + } + + }