@@ -80,28 +80,16 @@ public FindReplace(Editor editor) {
8080 if (replaceString != null ) replaceField .setText (replaceString );
8181
8282 ignoreCaseBox = new JCheckBox (Language .text ("find.ignore_case" ));
83- ignoreCaseBox .addActionListener (new ActionListener () {
84- public void actionPerformed (ActionEvent e ) {
85- ignoreCase = ignoreCaseBox .isSelected ();
86- }
87- });
83+ ignoreCaseBox .addActionListener (e -> ignoreCase = ignoreCaseBox .isSelected ());
8884 ignoreCaseBox .setSelected (ignoreCase );
8985
9086 allTabsBox = new JCheckBox (Language .text ("find.all_tabs" ));
91- allTabsBox .addActionListener (new ActionListener () {
92- public void actionPerformed (ActionEvent e ) {
93- allTabs = allTabsBox .isSelected ();
94- }
95- });
87+ allTabsBox .addActionListener (e -> allTabs = allTabsBox .isSelected ());
9688 allTabsBox .setSelected (allTabs );
9789 allTabsBox .setEnabled (true );
9890
9991 wrapAroundBox = new JCheckBox (Language .text ("find.wrap_around" ));
100- wrapAroundBox .addActionListener (new ActionListener () {
101- public void actionPerformed (ActionEvent e ) {
102- wrapAround = wrapAroundBox .isSelected ();
103- }
104- });
92+ wrapAroundBox .addActionListener (e -> wrapAround = wrapAroundBox .isSelected ());
10593 wrapAroundBox .setSelected (wrapAround );
10694
10795 GroupLayout layout = new GroupLayout (pain );
@@ -135,96 +123,68 @@ public void actionPerformed(ActionEvent e) {
135123 }
136124 setFound (false );
137125
138- Group buttonsVerticalGroup = layout .createParallelGroup (); // Creates group for arranging buttons vertically
139- buttonsVerticalGroup .addComponent (findButton )
140- .addComponent (previousButton )
141- .addComponent (replaceAndFindButton )
142- .addComponent (replaceButton )
143- .addComponent (replaceAllButton );
144-
145- layout .setHorizontalGroup (layout
146- .createSequentialGroup ()
147- .addGap (BORDER )
148- .addGroup (layout .createParallelGroup ()
149- .addGroup (GroupLayout .Alignment .TRAILING , // TRAILING makes everything right alinged
150- layout .createSequentialGroup ()
151- .addGap (replaceLabel .getPreferredSize ().width
152- - findLabel .getPreferredSize ().width )
153- .addComponent (findLabel )
154- .addComponent (findField ))
155- .addGroup (GroupLayout .Alignment .TRAILING ,
156- layout .createSequentialGroup ()
157- .addComponent (replaceLabel )
158- .addGroup (layout .createParallelGroup ()
159- .addComponent (replaceField )
160- .addGroup (GroupLayout .Alignment .LEADING ,
161- layout .createSequentialGroup ()
162- .addComponent (ignoreCaseBox )
163- .addComponent (allTabsBox )
164- .addComponent (wrapAroundBox )
165- .addGap (0 ))))
166- .addGroup (GroupLayout .Alignment .CENTER ,buttonsHorizontalGroup ))
167- .addGap (BORDER )
126+ // Creates group for arranging buttons vertically
127+ Group buttonsVerticalGroup = layout .createParallelGroup ()
128+ .addComponent (findButton )
129+ .addComponent (previousButton )
130+ .addComponent (replaceAndFindButton )
131+ .addComponent (replaceButton )
132+ .addComponent (replaceAllButton );
133+
134+ layout .setHorizontalGroup (layout .createSequentialGroup ()
135+ .addGap (BORDER )
136+ .addGroup (layout .createParallelGroup ()
137+ // TRAILING makes everything right aligned
138+ .addGroup (GroupLayout .Alignment .TRAILING , layout .createSequentialGroup ()
139+ .addGap (replaceLabel .getPreferredSize ().width - findLabel .getPreferredSize ().width )
140+ .addComponent (findLabel )
141+ .addComponent (findField ))
142+ .addGroup (GroupLayout .Alignment .TRAILING , layout .createSequentialGroup ()
143+ .addComponent (replaceLabel )
144+ .addGroup (layout .createParallelGroup ()
145+ .addComponent (replaceField )
146+ .addGroup (GroupLayout .Alignment .LEADING , layout .createSequentialGroup ()
147+ .addComponent (ignoreCaseBox )
148+ .addComponent (allTabsBox )
149+ .addComponent (wrapAroundBox )
150+ .addGap (0 ))))
151+ .addGroup (GroupLayout .Alignment .CENTER ,buttonsHorizontalGroup ))
152+ .addGap (BORDER )
168153 );
169154
170155// layout.linkSize(SwingConstants.HORIZONTAL, findButton, replaceButton, replaceAllButton, replaceAndFindButton, previousButton);
171156
172157 layout .setVerticalGroup (layout .createSequentialGroup ()
173158 .addGap (BORDER )
174159 .addGroup (layout .createParallelGroup (GroupLayout .Alignment .CENTER )
175- .addComponent (findLabel )
176- .addComponent (findField ))
160+ .addComponent (findLabel )
161+ .addComponent (findField ))
177162 .addGroup (layout .createParallelGroup (GroupLayout .Alignment .CENTER )
178- .addComponent (replaceLabel )
179- .addComponent (replaceField ))
163+ .addComponent (replaceLabel )
164+ .addComponent (replaceField ))
180165 .addGroup (layout .createParallelGroup (GroupLayout .Alignment .CENTER )
181- .addComponent (ignoreCaseBox )
182- .addComponent (allTabsBox )
183- .addComponent (wrapAroundBox ))
184- .addGroup (buttonsVerticalGroup )
185- .addGap (BORDER )
186- );
166+ .addComponent (ignoreCaseBox )
167+ .addComponent (allTabsBox )
168+ .addComponent (wrapAroundBox ))
169+ .addGroup (buttonsVerticalGroup )
170+ .addGap (BORDER ));
187171
188172 setLocationRelativeTo (null ); // center
189173 Dimension size = layout .preferredLayoutSize (pain );
190174 setSize (size .width , size .height );
191175 Dimension screen = Toolkit .getScreenSize ();
192176 setLocation ((screen .width - size .width ) / 2 ,
193- (screen .height - size .height ) / 2 );
177+ (screen .height - size .height ) / 2 );
194178
195- replaceButton .addActionListener (new ActionListener () {
196- public void actionPerformed (ActionEvent e ) {
197- replace ();
198- }
199- });
200-
201- replaceAllButton .addActionListener (new ActionListener () {
202- public void actionPerformed (ActionEvent e ) {
203- replaceAll ();
204- }
205- });
206-
207- replaceAndFindButton .addActionListener (new ActionListener () {
208- public void actionPerformed (ActionEvent e ) {
209- replaceAndFindNext ();
210- }
211- });
212-
213- findButton .addActionListener (new ActionListener () {
214- public void actionPerformed (ActionEvent e ) {
215- findNext ();
216- }
217- });
218-
219- previousButton .addActionListener (new ActionListener () {
220- public void actionPerformed (ActionEvent e ) {
221- findPrevious ();
222- }
223- });
179+ replaceButton .addActionListener (e -> replace ());
180+ replaceAllButton .addActionListener (e -> replaceAll ());
181+ replaceAndFindButton .addActionListener (e -> replaceAndFindNext ());
182+ findButton .addActionListener (e -> findNext ());
183+ previousButton .addActionListener (e -> findPrevious ());
224184
225185 // you mustn't replace what you haven't found, my son
226186 // semantics of replace are "replace the current selection with the replace field"
227- // so whether we have found before or not is irrelevent
187+ // so whether we have found before or not is irrelevant
228188 // replaceButton.setEnabled(false);
229189 // replaceFindButton.setEnabled(false);
230190
@@ -237,14 +197,10 @@ public void windowClosing(WindowEvent e) {
237197 handleClose ();
238198 }
239199 });
240- Toolkit .registerWindowCloseKeys (getRootPane (), new ActionListener () {
241- public void actionPerformed (ActionEvent actionEvent ) {
242- handleClose ();
243- }
244- });
200+ Toolkit .registerWindowCloseKeys (getRootPane (), actionEvent -> handleClose ());
245201 Toolkit .setIcon (this );
246202
247- // hack to to get first field to focus properly on osx
203+ // hack to get first field to focus properly on osx
248204 addWindowListener (new WindowAdapter () {
249205 public void windowActivated (WindowEvent e ) {
250206 //System.out.println("activating");
@@ -260,11 +216,10 @@ public void windowActivated(WindowEvent e) {
260216
261217
262218 public void handleClose () {
263- //System.out.println("handling close now");
264219 findString = findField .getText ();
265220 replaceString = replaceField .getText ();
266221
267- // this object should eventually become dereferenced
222+ // this object should eventually become de-referenced
268223 setVisible (false );
269224 }
270225
@@ -299,13 +254,13 @@ private boolean find(boolean wrap, boolean backwards) {
299254 nextIndex = text .indexOf (searchTerm , selectionEnd );
300255 if (nextIndex == -1 && wrap && !allTabs ) {
301256 // if wrapping, a second chance is ok, start from beginning
302- nextIndex = text .indexOf (searchTerm , 0 );
257+ nextIndex = text .indexOf (searchTerm );
303258
304259 } else if (nextIndex == -1 && allTabs ) {
305260 // For searching in all tabs, wrapping always happens.
306261
307262 int tempIndex = tabIndex ;
308- // Look for searchterm in all tabs.
263+ // Look for search term in all tabs.
309264 while (tabIndex <= sketch .getCodeCount () - 1 ) {
310265 if (tabIndex == sketch .getCodeCount () - 1 ) {
311266 // System.out.println("wrapping.");
@@ -329,14 +284,14 @@ private boolean find(boolean wrap, boolean backwards) {
329284 if (ignoreCase ) {
330285 text = text .toLowerCase ();
331286 }
332- nextIndex = text .indexOf (searchTerm , 0 );
287+ nextIndex = text .indexOf (searchTerm );
333288
334289 if (nextIndex != -1 || tabIndex == tempIndex ) {
335290 break ;
336291 }
337292 }
338293
339- // searchterm wasn't found in any of the tabs.
294+ // search term wasn't found in any of the tabs.
340295 // No tab switching should happen, restore tabIndex
341296 if (nextIndex == -1 ) {
342297 tabIndex = tempIndex ;
@@ -400,7 +355,7 @@ private boolean find(boolean wrap, boolean backwards) {
400355 sketch .setCurrentCode (tabIndex );
401356 }
402357 editor .setSelection (nextIndex , nextIndex + searchTerm .length ());
403- } else {
358+ // } else {
404359 //Toolkit.getDefaultToolkit().beep();
405360 }
406361 if (nextIndex != -1 ) {
@@ -418,23 +373,24 @@ protected void setFound(boolean found) {
418373 replaceAndFindButton .setEnabled (found );
419374 }
420375
421- /**
422- * Replace the current selection with whatever's in the
376+
377+ /**
378+ * Replace the current selection with whatever is in the
423379 * replacement text field.
424- * @param isCompoundEdit True if the action is to be marked as a copmound edit
425- */
380+ */
426381 public void replace (boolean isCompoundEdit ) {
427382 editor .setSelectedText (replaceField .getText (), isCompoundEdit );
428383
429- editor . getSketch (). setModified ( true ); // This necessary- calling replace()
384+ // This necessary because calling replace()
430385 // doesn't seem to mark a sketch as modified
386+ editor .getSketch ().setModified (true );
431387
432388 setFound (false );
433389 }
434390
435391
436392 /**
437- * Replace the current selection with whatever's in the
393+ * Replace the current selection with whatever is in the
438394 * replacement text field, marking the action as a compound edit.
439395 */
440396 public void replace () {
@@ -443,7 +399,7 @@ public void replace() {
443399
444400
445401 /**
446- * Replace the current selection with whatever's in the
402+ * Replace the current selection with whatever is in the
447403 * replacement text field, and then find the next match
448404 */
449405 public void replaceAndFindNext () {
@@ -472,7 +428,7 @@ public void replaceAll() {
472428 int stopIndex = startIndex + replaceField .getText ().length ();
473429 if (editor .getSketch ().getCurrentCodeIndex () == startTab &&
474430 (caret >= startIndex && (caret <= stopIndex ))) {
475- // we've reached where we started, so stop the replace
431+ // we've reached where we started, so stop the replacement
476432 Toolkit .beep ();
477433 editor .statusNotice ("Reached beginning of search!" );
478434 break ;
@@ -516,8 +472,7 @@ public void findPrevious() {
516472
517473
518474 /**
519- * Returns true if find next/previous will work, for graying-
520- * out of menu items.
475+ * Returns true if Find Next/Previous will work. Used to disable menu items.
521476 */
522477 public boolean canFindNext () {
523478 return findField .getText ().length () != 0 ;
0 commit comments