Skip to content

Commit f19b098

Browse files
committed
FindAll acts as a dialog box, restores focus. Closes #40
Interrupt FindAll search thread in progress address #52
1 parent 64c2648 commit f19b098

File tree

3 files changed

+92
-94
lines changed

3 files changed

+92
-94
lines changed

src/us/deathmarine/luyten/FindAllBox.java

+85-91
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,31 @@
3030

3131
public class FindAllBox extends JDialog {
3232
private static final long serialVersionUID = -4125409760166690462L;
33-
private boolean cancel;
33+
3434
private boolean searching;
35+
3536
private JButton findButton;
3637
private JTextField textField;
37-
JProgressBar progressBar;
38-
private DefaultListModel<String> classesList = new DefaultListModel<String>();
38+
private JProgressBar progressBar;
3939
private JLabel statusLabel = new JLabel("");
4040

41-
public FindAllBox() {
41+
private DefaultListModel<String> classesList = new DefaultListModel<String>();
42+
43+
private Thread tmp_thread;
44+
private MainWindow mainWindow;
45+
46+
public FindAllBox(MainWindow mainWindow) {
47+
this.mainWindow = mainWindow;
48+
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
49+
this.setHideOnEscapeButton();
50+
4251
progressBar = new JProgressBar(0, 100);
52+
4353
JLabel label = new JLabel("Find What:");
4454
textField = new JTextField();
4555
findButton = new JButton("Find");
4656
findButton.addActionListener(new FindButton());
57+
4758
this.getRootPane().setDefaultButton(findButton);
4859

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

68-
JButton cancelButton = new JButton("Cancel");
69-
cancelButton.addActionListener(new ActionListener() {
70-
@Override
71-
public void actionPerformed(ActionEvent e) {
72-
if (isSearching())
73-
setCancel(true);
74-
}
75-
});
76-
7779
layout.setHorizontalGroup(layout
7880
.createSequentialGroup()
7981
.addComponent(label)
@@ -92,8 +94,7 @@ public void actionPerformed(ActionEvent e) {
9294
progressBar))))
9395
.addGroup(
9496
layout.createParallelGroup(Alignment.LEADING)
95-
.addComponent(findButton)
96-
.addComponent(cancelButton))
97+
.addComponent(findButton))
9798

9899
);
99100

@@ -109,15 +110,12 @@ public void actionPerformed(ActionEvent e) {
109110
layout.createSequentialGroup().addGroup(
110111
layout.createParallelGroup(
111112
Alignment.BASELINE)
112-
.addComponent(listScroller)
113-
.addComponent(cancelButton))))
113+
.addComponent(listScroller))))
114114
.addGroup(layout.createParallelGroup(Alignment.LEADING))
115115
.addComponent(statusLabel).addComponent(progressBar));
116-
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
117-
this.setHideOnEscapeButton();
118116
this.adjustWindowPositionBySavedState();
119117
this.setSaveWindowPositionOnClosing();
120-
this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
118+
//this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
121119

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

129127
@Override
130128
public void actionPerformed(ActionEvent event) {
131-
Thread tmp_thread = new Thread() {
129+
tmp_thread = new Thread() {
132130
public void run() {
133-
setSearching(true);
134-
classesList.clear();
135-
ConfigSaver configSaver = ConfigSaver.getLoadedInstance();
136-
DecompilerSettings settings = configSaver
137-
.getDecompilerSettings();
138-
File inFile = MainWindow.model.getOpenedFile();
139-
try {
140-
JarFile jfile = new JarFile(inFile);
141-
Enumeration<JarEntry> entLength = jfile.entries();
142-
initProgressBar(Collections.list(entLength).size());
143-
Enumeration<JarEntry> ent = jfile.entries();
144-
while (ent.hasMoreElements() && !isCancel()) {
145-
JarEntry entry = ent.nextElement();
146-
setStatus(entry.getName());
147-
if (entry.getName().endsWith(".class")) {
148-
synchronized (settings) {
149-
String internalName = StringUtilities
150-
.removeRight(entry.getName(),
151-
".class");
152-
TypeReference type = Model.metadataSystem
153-
.lookupType(internalName);
154-
TypeDefinition resolvedType = null;
155-
if (type == null
156-
|| ((resolvedType = type.resolve()) == null)) {
157-
throw new Exception(
158-
"Unable to resolve type.");
159-
}
160-
StringWriter stringwriter = new StringWriter();
161-
DecompilationOptions decompilationOptions;
162-
decompilationOptions = new DecompilationOptions();
163-
decompilationOptions.setSettings(settings);
164-
decompilationOptions
165-
.setFullDecompilation(true);
166-
PlainTextOutput plainTextOutput =
167-
new PlainTextOutput(stringwriter);
168-
plainTextOutput.setUnicodeOutputEnabled(
169-
decompilationOptions.getSettings()
170-
.isUnicodeOutputEnabled());
171-
settings.getLanguage().decompileType(
172-
resolvedType,
173-
plainTextOutput,
174-
decompilationOptions);
175-
String decompiledSource = stringwriter
176-
.toString().toLowerCase();
177-
if (decompiledSource.contains(textField
178-
.getText().toLowerCase())) {
179-
addClassName(entry.getName());
131+
if(findButton.getText().equals("Stop")){
132+
if (tmp_thread != null)
133+
tmp_thread.interrupt();
134+
setStatus("Stopped.");
135+
findButton.setText("Find");
136+
} else {
137+
findButton.setText("Stop");
138+
classesList.clear();
139+
ConfigSaver configSaver = ConfigSaver.getLoadedInstance();
140+
DecompilerSettings settings = configSaver
141+
.getDecompilerSettings();
142+
File inFile = MainWindow.model.getOpenedFile();
143+
try {
144+
JarFile jfile = new JarFile(inFile);
145+
Enumeration<JarEntry> entLength = jfile.entries();
146+
initProgressBar(Collections.list(entLength).size());
147+
Enumeration<JarEntry> ent = jfile.entries();
148+
while (ent.hasMoreElements() && findButton.getText().equals("Stop")) {
149+
JarEntry entry = ent.nextElement();
150+
setStatus(entry.getName());
151+
if (entry.getName().endsWith(".class")) {
152+
synchronized (settings) {
153+
String internalName = StringUtilities
154+
.removeRight(entry.getName(),
155+
".class");
156+
TypeReference type = Model.metadataSystem
157+
.lookupType(internalName);
158+
TypeDefinition resolvedType = null;
159+
if (type == null
160+
|| ((resolvedType = type.resolve()) == null)) {
161+
throw new Exception(
162+
"Unable to resolve type.");
163+
}
164+
StringWriter stringwriter = new StringWriter();
165+
DecompilationOptions decompilationOptions;
166+
decompilationOptions = new DecompilationOptions();
167+
decompilationOptions.setSettings(settings);
168+
decompilationOptions
169+
.setFullDecompilation(true);
170+
PlainTextOutput plainTextOutput =
171+
new PlainTextOutput(stringwriter);
172+
plainTextOutput.setUnicodeOutputEnabled(
173+
decompilationOptions.getSettings()
174+
.isUnicodeOutputEnabled());
175+
settings.getLanguage().decompileType(
176+
resolvedType,
177+
plainTextOutput,
178+
decompilationOptions);
179+
String decompiledSource = stringwriter
180+
.toString().toLowerCase();
181+
if (decompiledSource.contains(textField
182+
.getText().toLowerCase())) {
183+
addClassName(entry.getName());
184+
}
180185
}
181186
}
182187
}
188+
setSearching(false);
189+
if (findButton.getText().equals("Stop")){
190+
setStatus("Done.");
191+
findButton.setText("Find");
192+
}
193+
jfile.close();
194+
} catch (IOException e1) {
195+
e1.printStackTrace();
196+
} catch (Exception e1) {
197+
e1.printStackTrace();
183198
}
184-
setSearching(false);
185-
if (isCancel()) {
186-
setCancel(false);
187-
setStatus("Cancelled.");
188-
} else {
189-
setStatus("Done.");
190-
}
191-
jfile.close();
192-
} catch (IOException e1) {
193-
e1.printStackTrace();
194-
} catch (Exception e1) {
195-
e1.printStackTrace();
199+
196200
}
197201
}
198202
};
@@ -236,8 +240,6 @@ public void windowDeactivated(WindowEvent e) {
236240
WindowPosition windowPosition = ConfigSaver.getLoadedInstance()
237241
.getFindWindowPosition();
238242
windowPosition.readPositionFromDialog(FindAllBox.this);
239-
if (isSearching())
240-
setCancel(true);
241243
}
242244
});
243245
}
@@ -271,15 +273,7 @@ public void initProgressBar(Integer length) {
271273
progressBar.setValue(0);
272274
progressBar.setStringPainted(true);
273275
}
274-
275-
public boolean isCancel() {
276-
return cancel;
277-
}
278-
279-
public void setCancel(boolean cancel) {
280-
this.cancel = cancel;
281-
}
282-
276+
283277
public boolean isSearching() {
284278
return searching;
285279
}

src/us/deathmarine/luyten/MainWindow.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void onFindMenu() {
218218
public void onFindAllMenu() {
219219
try {
220220
if (findAllBox == null)
221-
findAllBox = new FindAllBox();
221+
findAllBox = new FindAllBox(this);
222222
findAllBox.showFindBox();
223223

224224
} catch (Exception e) {
@@ -394,7 +394,7 @@ private void setShowFindAllBoxOnMainWindowFocus() {
394394
@Override
395395
public void windowGainedFocus(WindowEvent e) {
396396
if (findAllBox != null && findAllBox.isVisible()) {
397-
findAllBox.requestFocus();
397+
findAllBox.setVisible(false);
398398
}
399399
}
400400
});

src/us/deathmarine/luyten/Model.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ private void openEntryByTreePath(TreePath trp) {
292292
}
293293
}
294294
}
295+
295296
label.setText("Complete");
296297
} catch (FileEntryNotFoundException e) {
297298
label.setText("File not found: " + name);
@@ -432,7 +433,10 @@ public void stateChanged(ChangeEvent e) {
432433
}
433434
}
434435
}
435-
436+
437+
public void openFileFromPath(){
438+
439+
}
436440
public void updateOpenClasses() {
437441
// invalidate all open classes (update will hapen at tab change)
438442
for (OpenFile open : hmap) {

0 commit comments

Comments
 (0)