Skip to content

Commit

Permalink
Resolved issues with FindAll dialog.
Browse files Browse the repository at this point in the history
Doubleclicking FindAll items decompiles.
  • Loading branch information
deathmarine committed Aug 25, 2016
1 parent f19b098 commit 7b35560
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 35 deletions.
31 changes: 27 additions & 4 deletions src/us/deathmarine/luyten/FindAllBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -41,10 +47,8 @@ public class FindAllBox extends JDialog {
private DefaultListModel<String> classesList = new DefaultListModel<String>();

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();

Expand All @@ -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<String> list = (JList<String>) 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();
Expand Down Expand Up @@ -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");
Expand Down
73 changes: 42 additions & 31 deletions src/us/deathmarine/luyten/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -229,7 +229,7 @@ public void run() {
}
}

private void openEntryByTreePath(TreePath trp) {
public void openEntryByTreePath(TreePath trp) {
String name = "";
String path = "";
try {
Expand Down Expand Up @@ -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);
}
Expand All @@ -282,34 +282,34 @@ 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 {
bar.setVisible(false);
}
}

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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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() {
Expand All @@ -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);
Expand Down Expand Up @@ -856,7 +853,7 @@ public File getOpenedFile() {
openedFile = file;
}
if (openedFile == null) {
label.setText("No open file");
getLabel().setText("No open file");
}
return openedFile;
}
Expand All @@ -872,7 +869,7 @@ public String getCurrentTabTitle() {
e1.printStackTrace();
}
if (tabTitle == null) {
label.setText("No open tab");
getLabel().setText("No open tab");
}
return tabTitle;
}
Expand All @@ -889,7 +886,7 @@ public RSyntaxTextArea getCurrentTextArea() {
e1.printStackTrace();
}
if (currentTextArea == null) {
label.setText("No open tab");
getLabel().setText("No open tab");
}
return currentTextArea;
}
Expand Down Expand Up @@ -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)
Expand All @@ -947,14 +944,28 @@ 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);
}
}
}).start();
}

public JLabel getLabel() {
return label;
}

public void setLabel(JLabel label) {
this.label = label;
}

public State getState(){
return state;
}


}

0 comments on commit 7b35560

Please sign in to comment.