4444import javax .swing .JCheckBox ;
4545
4646import com .projectswg .tools .stf .StfTable .Pair ;
47- import javax .swing .border .SoftBevelBorder ;
48- import javax .swing .border .BevelBorder ;
4947import javax .swing .border .EtchedBorder ;
5048
5149public class StfSearcher {
@@ -60,6 +58,7 @@ public class StfSearcher {
6058
6159 private Preferences prefs = Preferences .userRoot ().node (this .getClass ().getName ());
6260 private JCheckBox chckbxRecursive ;
61+ private JCheckBox chckbxFindAll ;
6362
6463 public StfSearcher () {
6564 searcher = this ;
@@ -87,7 +86,7 @@ private void initialize() {
8786 frmPswgTools = new JFrame ();
8887 frmPswgTools .setResizable (false );
8988 frmPswgTools .setTitle ("PSWG Tools - Stf Searcher" );
90- frmPswgTools .setBounds (100 , 100 , 560 , 514 );
89+ frmPswgTools .setBounds (100 , 100 , 571 , 511 );
9190 frmPswgTools .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
9291 frmPswgTools .getContentPane ().setLayout (null );
9392
@@ -114,12 +113,12 @@ public void windowOpened(WindowEvent e) {}
114113 panelSettings .setLayout (null );
115114
116115 JLabel lblSearchDirectory = new JLabel ("Search Directory" );
117- lblSearchDirectory .setBounds (10 , 11 , 114 , 14 );
116+ lblSearchDirectory .setBounds (10 , 11 , 89 , 14 );
118117 panelSettings .add (lblSearchDirectory );
119118
120119 tfDirectory = new JTextField ();
121120 tfDirectory .setEditable (false );
122- tfDirectory .setBounds (124 , 8 , 322 , 20 );
121+ tfDirectory .setBounds (103 , 8 , 336 , 23 );
123122 panelSettings .add (tfDirectory );
124123 tfDirectory .setColumns (10 );
125124
@@ -152,19 +151,22 @@ public void actionPerformed(ActionEvent arg0) {
152151 panelSettings .add (btnChangeDir );
153152
154153 JLabel lblSearchTerm = new JLabel ("Find Value" );
155- lblSearchTerm .setBounds (10 , 39 , 89 , 14 );
154+ lblSearchTerm .setBounds (10 , 52 , 61 , 14 );
156155 panelSettings .add (lblSearchTerm );
157156
158157 tfValue = new JTextField ();
159158 tfValue .setColumns (10 );
160- tfValue .setBounds (84 , 36 , 454 , 20 );
159+ tfValue .setBounds (81 , 49 , 453 , 23 );
161160 panelSettings .add (tfValue );
162161
163162 JPanel panelButtons = new JPanel ();
164163 panelButtons .setBorder (new EtchedBorder (EtchedBorder .LOWERED , null , null ));
165164 panelButtons .setBounds (10 , 80 , 528 , 57 );
166165 panelSettings .add (panelButtons );
167166
167+ chckbxFindAll = new JCheckBox ("Find All" );
168+ panelButtons .add (chckbxFindAll );
169+
168170 chckbxRecursive = new JCheckBox ("Recursive" );
169171 panelButtons .add (chckbxRecursive );
170172
@@ -180,7 +182,7 @@ public void actionPerformed(ActionEvent arg0) {
180182 panelButtons .add (btnClearConsole );
181183 btnSearch .addActionListener (new ActionListener () {
182184 public void actionPerformed (ActionEvent arg0 ) {
183- search (tfValue .getText (), chckbxRecursive .isSelected ());
185+ search (tfValue .getText (), chckbxRecursive .isSelected (), chckbxFindAll . isSelected () );
184186 }
185187 });
186188
@@ -199,7 +201,7 @@ public void actionPerformed(ActionEvent arg0) {
199201
200202 }
201203
202- public void search (String term , boolean recursive ) {
204+ public void search (String term , boolean recursive , boolean findAll ) {
203205 printConsole ("Looking for value: " + term );
204206 File directory = Paths .get (searchDirectory ).toFile ();
205207 if (!directory .exists ()) {
@@ -212,26 +214,36 @@ public void search(String term, boolean recursive) {
212214 return ;
213215 }
214216
215- boolean found = searchDirectory (directory , term , recursive );
217+ boolean found = searchDirectory (directory , term , recursive , findAll );
216218
217219 if (!found )
218220 printConsole ("No results were found." );
219221 else
220- printConsole ("Found a file with the search term." );
222+ printConsole ("Found the search term." );
221223 }
222224
223- public boolean searchDirectory (File directory , String term , boolean recursive ) {
225+ public boolean searchDirectory (File directory , String term , boolean recursive , boolean findAll ) {
224226 boolean found = false ;
225- for (File f : directory .listFiles ()) {
226- if (found )
227- break ;
228-
229- if (f .isFile ())
230- found = searchFile (f , term );
231- else if (f .isDirectory () && recursive )
232- found = searchDirectory (f , term , recursive );
233- }
234227
228+ if (!findAll ) {
229+ for (File f : directory .listFiles ()) {
230+ if (found )
231+ break ;
232+
233+ if (f .isFile ())
234+ found = searchFile (f , term );
235+ else if (f .isDirectory () && recursive )
236+ found = searchDirectory (f , term , recursive , findAll );
237+ }
238+ } else {
239+ for (File f : directory .listFiles ()) {
240+ if (f .isFile ())
241+ found = searchFile (f , term );
242+ else if (f .isDirectory () && recursive )
243+ found = searchDirectory (f , term , recursive , findAll );
244+ }
245+ }
246+
235247 return found ;
236248 }
237249
@@ -248,7 +260,6 @@ public boolean searchFile(File file, String term) {
248260 printConsole ("Found Value in " + file .getName ());
249261 return true ;
250262 }
251- //printConsole(pair.getKey() + " " + pair.getValue());
252263 }
253264 } catch (IOException e ) {
254265 e .printStackTrace ();
0 commit comments