30
30
31
31
public class FindAllBox extends JDialog {
32
32
private static final long serialVersionUID = -4125409760166690462L ;
33
- private boolean cancel ;
33
+
34
34
private boolean searching ;
35
+
35
36
private JButton findButton ;
36
37
private JTextField textField ;
37
- JProgressBar progressBar ;
38
- private DefaultListModel <String > classesList = new DefaultListModel <String >();
38
+ private JProgressBar progressBar ;
39
39
private JLabel statusLabel = new JLabel ("" );
40
40
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
+
42
51
progressBar = new JProgressBar (0 , 100 );
52
+
43
53
JLabel label = new JLabel ("Find What:" );
44
54
textField = new JTextField ();
45
55
findButton = new JButton ("Find" );
46
56
findButton .addActionListener (new FindButton ());
57
+
47
58
this .getRootPane ().setDefaultButton (findButton );
48
59
49
60
JList <String > list = new JList <String >(classesList );
@@ -65,15 +76,6 @@ public FindAllBox() {
65
76
layout .setAutoCreateGaps (true );
66
77
layout .setAutoCreateContainerGaps (true );
67
78
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
-
77
79
layout .setHorizontalGroup (layout
78
80
.createSequentialGroup ()
79
81
.addComponent (label )
@@ -92,8 +94,7 @@ public void actionPerformed(ActionEvent e) {
92
94
progressBar ))))
93
95
.addGroup (
94
96
layout .createParallelGroup (Alignment .LEADING )
95
- .addComponent (findButton )
96
- .addComponent (cancelButton ))
97
+ .addComponent (findButton ))
97
98
98
99
);
99
100
@@ -109,15 +110,12 @@ public void actionPerformed(ActionEvent e) {
109
110
layout .createSequentialGroup ().addGroup (
110
111
layout .createParallelGroup (
111
112
Alignment .BASELINE )
112
- .addComponent (listScroller )
113
- .addComponent (cancelButton ))))
113
+ .addComponent (listScroller ))))
114
114
.addGroup (layout .createParallelGroup (Alignment .LEADING ))
115
115
.addComponent (statusLabel ).addComponent (progressBar ));
116
- this .setDefaultCloseOperation (HIDE_ON_CLOSE );
117
- this .setHideOnEscapeButton ();
118
116
this .adjustWindowPositionBySavedState ();
119
117
this .setSaveWindowPositionOnClosing ();
120
- this .setModalityType (Dialog .ModalityType .APPLICATION_MODAL );
118
+ // this.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
121
119
122
120
this .setName ("Find All" );
123
121
this .setTitle ("Find All" );
@@ -128,71 +126,77 @@ private class FindButton extends AbstractAction {
128
126
129
127
@ Override
130
128
public void actionPerformed (ActionEvent event ) {
131
- Thread tmp_thread = new Thread () {
129
+ tmp_thread = new Thread () {
132
130
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
+ }
180
185
}
181
186
}
182
187
}
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 ();
183
198
}
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
+
196
200
}
197
201
}
198
202
};
@@ -236,8 +240,6 @@ public void windowDeactivated(WindowEvent e) {
236
240
WindowPosition windowPosition = ConfigSaver .getLoadedInstance ()
237
241
.getFindWindowPosition ();
238
242
windowPosition .readPositionFromDialog (FindAllBox .this );
239
- if (isSearching ())
240
- setCancel (true );
241
243
}
242
244
});
243
245
}
@@ -271,15 +273,7 @@ public void initProgressBar(Integer length) {
271
273
progressBar .setValue (0 );
272
274
progressBar .setStringPainted (true );
273
275
}
274
-
275
- public boolean isCancel () {
276
- return cancel ;
277
- }
278
-
279
- public void setCancel (boolean cancel ) {
280
- this .cancel = cancel ;
281
- }
282
-
276
+
283
277
public boolean isSearching () {
284
278
return searching ;
285
279
}
0 commit comments