44
44
* <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=244"> Bug 244</A>
45
45
* should anyone have clues about how to fix.
46
46
*/
47
+ @ SuppressWarnings ("serial" )
47
48
public class FindReplace extends JFrame implements ActionListener {
48
49
49
50
static final int EDGE = Base .isMacOS () ? 20 : 13 ;
@@ -76,39 +77,33 @@ public FindReplace(Editor editor) {
76
77
super ("Find" );
77
78
setResizable (false );
78
79
this .editor = editor ;
79
-
80
80
81
81
FlowLayout searchLayout = new FlowLayout (FlowLayout .RIGHT ,5 ,0 );
82
- Container pain = getContentPane ();
83
- pain .setLayout (searchLayout );
82
+ Container pane = getContentPane ();
83
+ pane .setLayout (searchLayout );
84
84
85
85
JLabel findLabel = new JLabel (_ ("Find:" ));
86
86
JLabel replaceLabel = new JLabel (_ ("Replace with:" ));
87
87
Dimension labelDimension = replaceLabel .getPreferredSize ();
88
88
89
89
JPanel find = new JPanel ();
90
-
91
90
find .add (findLabel );
92
-
93
91
find .add (findField = new JTextField (20 ));
94
-
95
- pain .add (find );
92
+ pane .add (find );
96
93
97
94
JPanel replace = new JPanel ();
98
-
99
95
replace .add (replaceLabel );
100
-
101
96
replace .add (replaceField = new JTextField (20 ));
102
-
103
- pain .add (replace );
97
+ pane .add (replace );
104
98
105
99
int fieldHeight = findField .getPreferredSize ().height ;
106
100
107
101
JPanel checkbox = new JPanel ();
108
102
109
103
// Fill the findString with selected text if no previous value
110
- if (editor .getSelectedText ()!=null && editor .getSelectedText ().length ()>0 )
111
- findString = editor .getSelectedText ();
104
+ if (editor .getSelectedText () != null &&
105
+ editor .getSelectedText ().length () > 0 )
106
+ findString = editor .getSelectedText ();
112
107
113
108
if (findString != null ) findField .setText (findString );
114
109
if (replaceString != null ) replaceField .setText (replaceString );
@@ -142,11 +137,10 @@ public void actionPerformed(ActionEvent e) {
142
137
searchAllFilesBox .setSelected (searchAllFiles );
143
138
checkbox .add (searchAllFilesBox );
144
139
145
- pain .add (checkbox );
140
+ pane .add (checkbox );
146
141
147
142
JPanel buttons = new JPanel ();
148
-
149
- buttons .setLayout (new FlowLayout (FlowLayout .CENTER ,BUTTONGAP ,0 ));
143
+ buttons .setLayout (new FlowLayout (FlowLayout .CENTER , BUTTONGAP , 0 ));
150
144
151
145
// ordering is different on mac versus pc
152
146
if (Base .isMacOS ()) {
@@ -163,7 +157,7 @@ public void actionPerformed(ActionEvent e) {
163
157
buttons .add (replaceButton = new JButton (_ ("Replace" )));
164
158
buttons .add (replaceAllButton = new JButton (_ ("Replace All" )));
165
159
}
166
- pain .add (buttons );
160
+ pane .add (buttons );
167
161
168
162
// to fix ugliness.. normally macosx java 1.3 puts an
169
163
// ugly white border around this object, so turn it off.
@@ -369,45 +363,40 @@ private boolean find(boolean wrap,boolean backwards,boolean searchTabs,int origi
369
363
}
370
364
371
365
if (nextIndex == -1 ) {
372
- //Nothing found on this tab: Search other tabs if required
373
- if (searchTabs )
374
- {
375
- //editor.
376
- Sketch sketch = editor .getSketch ();
377
- if (sketch .getCodeCount ()>1 )
378
- {
379
- int realCurrentTab = sketch .getCodeIndex (sketch .getCurrentCode ());
380
-
381
- if (originTab !=realCurrentTab )
382
- {
383
- if (originTab <0 )
384
- originTab = realCurrentTab ;
385
-
386
- if (!wrap )
387
- if ((!backwards && realCurrentTab +1 >= sketch .getCodeCount ()) || (backwards && realCurrentTab -1 < 0 ))
388
- return false ; // Can't continue without wrap
389
-
390
- if (backwards )
391
- {
392
- sketch .handlePrevCode ();
393
- this .setVisible (true );
394
- int l = editor .getText ().length ()-1 ;
395
- editor .setSelection (l ,l );
396
- }
397
- else
398
- {
399
- sketch .handleNextCode ();
400
- this .setVisible (true );
401
- editor .setSelection (0 ,0 );
402
- }
403
-
404
- return find (wrap ,backwards ,searchTabs ,originTab );
405
- }
406
- }
366
+ // Nothing found on this tab: Search other tabs if required
367
+ if (searchTabs ) {
368
+ // editor.
369
+ Sketch sketch = editor .getSketch ();
370
+ if (sketch .getCodeCount () > 1 ) {
371
+ int realCurrentTab = sketch .getCodeIndex (sketch .getCurrentCode ());
372
+
373
+ if (originTab != realCurrentTab ) {
374
+ if (originTab < 0 )
375
+ originTab = realCurrentTab ;
376
+
377
+ if (!wrap )
378
+ if ((!backwards && realCurrentTab + 1 >= sketch .getCodeCount ()) ||
379
+ (backwards && realCurrentTab - 1 < 0 ))
380
+ return false ; // Can't continue without wrap
381
+
382
+ if (backwards ) {
383
+ sketch .handlePrevCode ();
384
+ this .setVisible (true );
385
+ int l = editor .getText ().length () - 1 ;
386
+ editor .setSelection (l , l );
387
+ } else {
388
+ sketch .handleNextCode ();
389
+ this .setVisible (true );
390
+ editor .setSelection (0 , 0 );
391
+ }
392
+
393
+ return find (wrap , backwards , searchTabs , originTab );
394
+ }
395
+ }
407
396
}
408
397
409
- if (wrapNeeded )
410
- nextIndex = backwards ? text .lastIndexOf (search ): text .indexOf (search , 0 );
398
+ if (wrapNeeded )
399
+ nextIndex = backwards ? text .lastIndexOf (search ) : text .indexOf (search , 0 );
411
400
}
412
401
413
402
if (nextIndex != -1 ) {
@@ -424,24 +413,25 @@ private boolean find(boolean wrap,boolean backwards,boolean searchTabs,int origi
424
413
* replacement text field.
425
414
*/
426
415
public void replace () {
427
- if (findField .getText ().length ()==0 )
428
- return ;
429
-
430
- int newpos = editor .getSelectionStart () - findField .getText ().length ();
431
- if (newpos < 0 ) newpos = 0 ;
432
- editor .setSelection (newpos , newpos );
416
+ if (findField .getText ().length () == 0 )
417
+ return ;
418
+
419
+ int newpos = editor .getSelectionStart () - findField .getText ().length ();
420
+ if (newpos < 0 )
421
+ newpos = 0 ;
422
+ editor .setSelection (newpos , newpos );
433
423
434
424
boolean foundAtLeastOne = false ;
435
425
436
- if ( find (false ,false ,searchAllFiles ,-1 )) {
437
- foundAtLeastOne = true ;
438
- editor .setSelectedText (replaceField .getText ());
439
- editor .getSketch ().setModified (true ); // TODO is this necessary?
440
- }
441
-
442
- if ( !foundAtLeastOne ) {
426
+ if (find (false , false , searchAllFiles , -1 )) {
427
+ foundAtLeastOne = true ;
428
+ editor .setSelectedText (replaceField .getText ());
429
+ editor .getSketch ().setModified (true ); // TODO is this necessary?
430
+ }
431
+
432
+ if (!foundAtLeastOne ) {
443
433
Toolkit .getDefaultToolkit ().beep ();
444
- }
434
+ }
445
435
446
436
}
447
437
@@ -459,22 +449,22 @@ public void replaceAndFindNext() {
459
449
* alternately until nothing more found.
460
450
*/
461
451
public void replaceAll () {
462
- if (findField .getText ().length ()== 0 )
463
- return ;
452
+ if (findField .getText ().length () == 0 )
453
+ return ;
464
454
// move to the beginning
465
455
editor .setSelection (0 , 0 );
466
456
467
457
boolean foundAtLeastOne = false ;
468
- while ( true ) {
469
- if ( find (false ,false ,searchAllFiles ,-1 )) {
458
+ while (true ) {
459
+ if (find (false , false , searchAllFiles , -1 )) {
470
460
foundAtLeastOne = true ;
471
461
editor .setSelectedText (replaceField .getText ());
472
- editor .getSketch ().setModified (true ); // TODO is this necessary?
473
- } else {
462
+ editor .getSketch ().setModified (true ); // TODO is this necessary?
463
+ } else {
474
464
break ;
475
465
}
476
466
}
477
- if ( !foundAtLeastOne ) {
467
+ if (!foundAtLeastOne ) {
478
468
Toolkit .getDefaultToolkit ().beep ();
479
469
}
480
470
}
0 commit comments