Skip to content

Commit

Permalink
FindAll acts as a dialog box, restores focus. Closes #40
Browse files Browse the repository at this point in the history
Interrupt FindAll search thread in progress address #52
  • Loading branch information
deathmarine committed Aug 25, 2016
1 parent 64c2648 commit f19b098
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 94 deletions.
176 changes: 85 additions & 91 deletions src/us/deathmarine/luyten/FindAllBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,31 @@

public class FindAllBox extends JDialog {
private static final long serialVersionUID = -4125409760166690462L;
private boolean cancel;

private boolean searching;

private JButton findButton;
private JTextField textField;
JProgressBar progressBar;
private DefaultListModel<String> classesList = new DefaultListModel<String>();
private JProgressBar progressBar;
private JLabel statusLabel = new JLabel("");

public FindAllBox() {
private DefaultListModel<String> classesList = new DefaultListModel<String>();

private Thread tmp_thread;
private MainWindow mainWindow;

public FindAllBox(MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
this.setHideOnEscapeButton();

progressBar = new JProgressBar(0, 100);

JLabel label = new JLabel("Find What:");
textField = new JTextField();
findButton = new JButton("Find");
findButton.addActionListener(new FindButton());

this.getRootPane().setDefaultButton(findButton);

JList<String> list = new JList<String>(classesList);
Expand All @@ -65,15 +76,6 @@ public FindAllBox() {
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);

JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (isSearching())
setCancel(true);
}
});

layout.setHorizontalGroup(layout
.createSequentialGroup()
.addComponent(label)
Expand All @@ -92,8 +94,7 @@ public void actionPerformed(ActionEvent e) {
progressBar))))
.addGroup(
layout.createParallelGroup(Alignment.LEADING)
.addComponent(findButton)
.addComponent(cancelButton))
.addComponent(findButton))

);

Expand All @@ -109,15 +110,12 @@ public void actionPerformed(ActionEvent e) {
layout.createSequentialGroup().addGroup(
layout.createParallelGroup(
Alignment.BASELINE)
.addComponent(listScroller)
.addComponent(cancelButton))))
.addComponent(listScroller))))
.addGroup(layout.createParallelGroup(Alignment.LEADING))
.addComponent(statusLabel).addComponent(progressBar));
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
this.setHideOnEscapeButton();
this.adjustWindowPositionBySavedState();
this.setSaveWindowPositionOnClosing();
this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
//this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);

this.setName("Find All");
this.setTitle("Find All");
Expand All @@ -128,71 +126,77 @@ private class FindButton extends AbstractAction {

@Override
public void actionPerformed(ActionEvent event) {
Thread tmp_thread = new Thread() {
tmp_thread = new Thread() {
public void run() {
setSearching(true);
classesList.clear();
ConfigSaver configSaver = ConfigSaver.getLoadedInstance();
DecompilerSettings settings = configSaver
.getDecompilerSettings();
File inFile = MainWindow.model.getOpenedFile();
try {
JarFile jfile = new JarFile(inFile);
Enumeration<JarEntry> entLength = jfile.entries();
initProgressBar(Collections.list(entLength).size());
Enumeration<JarEntry> ent = jfile.entries();
while (ent.hasMoreElements() && !isCancel()) {
JarEntry entry = ent.nextElement();
setStatus(entry.getName());
if (entry.getName().endsWith(".class")) {
synchronized (settings) {
String internalName = StringUtilities
.removeRight(entry.getName(),
".class");
TypeReference type = Model.metadataSystem
.lookupType(internalName);
TypeDefinition resolvedType = null;
if (type == null
|| ((resolvedType = type.resolve()) == null)) {
throw new Exception(
"Unable to resolve type.");
}
StringWriter stringwriter = new StringWriter();
DecompilationOptions decompilationOptions;
decompilationOptions = new DecompilationOptions();
decompilationOptions.setSettings(settings);
decompilationOptions
.setFullDecompilation(true);
PlainTextOutput plainTextOutput =
new PlainTextOutput(stringwriter);
plainTextOutput.setUnicodeOutputEnabled(
decompilationOptions.getSettings()
.isUnicodeOutputEnabled());
settings.getLanguage().decompileType(
resolvedType,
plainTextOutput,
decompilationOptions);
String decompiledSource = stringwriter
.toString().toLowerCase();
if (decompiledSource.contains(textField
.getText().toLowerCase())) {
addClassName(entry.getName());
if(findButton.getText().equals("Stop")){
if (tmp_thread != null)
tmp_thread.interrupt();
setStatus("Stopped.");
findButton.setText("Find");
} else {
findButton.setText("Stop");
classesList.clear();
ConfigSaver configSaver = ConfigSaver.getLoadedInstance();
DecompilerSettings settings = configSaver
.getDecompilerSettings();
File inFile = MainWindow.model.getOpenedFile();
try {
JarFile jfile = new JarFile(inFile);
Enumeration<JarEntry> entLength = jfile.entries();
initProgressBar(Collections.list(entLength).size());
Enumeration<JarEntry> ent = jfile.entries();
while (ent.hasMoreElements() && findButton.getText().equals("Stop")) {
JarEntry entry = ent.nextElement();
setStatus(entry.getName());
if (entry.getName().endsWith(".class")) {
synchronized (settings) {
String internalName = StringUtilities
.removeRight(entry.getName(),
".class");
TypeReference type = Model.metadataSystem
.lookupType(internalName);
TypeDefinition resolvedType = null;
if (type == null
|| ((resolvedType = type.resolve()) == null)) {
throw new Exception(
"Unable to resolve type.");
}
StringWriter stringwriter = new StringWriter();
DecompilationOptions decompilationOptions;
decompilationOptions = new DecompilationOptions();
decompilationOptions.setSettings(settings);
decompilationOptions
.setFullDecompilation(true);
PlainTextOutput plainTextOutput =
new PlainTextOutput(stringwriter);
plainTextOutput.setUnicodeOutputEnabled(
decompilationOptions.getSettings()
.isUnicodeOutputEnabled());
settings.getLanguage().decompileType(
resolvedType,
plainTextOutput,
decompilationOptions);
String decompiledSource = stringwriter
.toString().toLowerCase();
if (decompiledSource.contains(textField
.getText().toLowerCase())) {
addClassName(entry.getName());
}
}
}
}
setSearching(false);
if (findButton.getText().equals("Stop")){
setStatus("Done.");
findButton.setText("Find");
}
jfile.close();
} catch (IOException e1) {
e1.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
setSearching(false);
if (isCancel()) {
setCancel(false);
setStatus("Cancelled.");
} else {
setStatus("Done.");
}
jfile.close();
} catch (IOException e1) {
e1.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();

}
}
};
Expand Down Expand Up @@ -236,8 +240,6 @@ public void windowDeactivated(WindowEvent e) {
WindowPosition windowPosition = ConfigSaver.getLoadedInstance()
.getFindWindowPosition();
windowPosition.readPositionFromDialog(FindAllBox.this);
if (isSearching())
setCancel(true);
}
});
}
Expand Down Expand Up @@ -271,15 +273,7 @@ public void initProgressBar(Integer length) {
progressBar.setValue(0);
progressBar.setStringPainted(true);
}

public boolean isCancel() {
return cancel;
}

public void setCancel(boolean cancel) {
this.cancel = cancel;
}


public boolean isSearching() {
return searching;
}
Expand Down
4 changes: 2 additions & 2 deletions src/us/deathmarine/luyten/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void onFindMenu() {
public void onFindAllMenu() {
try {
if (findAllBox == null)
findAllBox = new FindAllBox();
findAllBox = new FindAllBox(this);
findAllBox.showFindBox();

} catch (Exception e) {
Expand Down Expand Up @@ -394,7 +394,7 @@ private void setShowFindAllBoxOnMainWindowFocus() {
@Override
public void windowGainedFocus(WindowEvent e) {
if (findAllBox != null && findAllBox.isVisible()) {
findAllBox.requestFocus();
findAllBox.setVisible(false);
}
}
});
Expand Down
6 changes: 5 additions & 1 deletion src/us/deathmarine/luyten/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ private void openEntryByTreePath(TreePath trp) {
}
}
}

label.setText("Complete");
} catch (FileEntryNotFoundException e) {
label.setText("File not found: " + name);
Expand Down Expand Up @@ -432,7 +433,10 @@ 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 Down

0 comments on commit f19b098

Please sign in to comment.