Skip to content

Commit 82401c8

Browse files
committed
Fix indent and typos on FindReplace.java
1 parent cd75cc2 commit 82401c8

File tree

1 file changed

+65
-75
lines changed

1 file changed

+65
-75
lines changed

app/src/processing/app/FindReplace.java

Lines changed: 65 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=244"> Bug 244</A>
4545
* should anyone have clues about how to fix.
4646
*/
47+
@SuppressWarnings("serial")
4748
public class FindReplace extends JFrame implements ActionListener {
4849

4950
static final int EDGE = Base.isMacOS() ? 20 : 13;
@@ -76,39 +77,33 @@ public FindReplace(Editor editor) {
7677
super("Find");
7778
setResizable(false);
7879
this.editor = editor;
79-
8080

8181
FlowLayout searchLayout = new FlowLayout(FlowLayout.RIGHT,5,0);
82-
Container pain = getContentPane();
83-
pain.setLayout(searchLayout);
82+
Container pane = getContentPane();
83+
pane.setLayout(searchLayout);
8484

8585
JLabel findLabel = new JLabel(_("Find:"));
8686
JLabel replaceLabel = new JLabel(_("Replace with:"));
8787
Dimension labelDimension = replaceLabel.getPreferredSize();
8888

8989
JPanel find = new JPanel();
90-
9190
find.add(findLabel);
92-
9391
find.add(findField = new JTextField(20));
94-
95-
pain.add(find);
92+
pane.add(find);
9693

9794
JPanel replace = new JPanel();
98-
9995
replace.add(replaceLabel);
100-
10196
replace.add(replaceField = new JTextField(20));
102-
103-
pain.add(replace);
97+
pane.add(replace);
10498

10599
int fieldHeight = findField.getPreferredSize().height;
106100

107101
JPanel checkbox = new JPanel();
108102

109103
// 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();
112107

113108
if (findString != null) findField.setText(findString);
114109
if (replaceString != null) replaceField.setText(replaceString);
@@ -142,11 +137,10 @@ public void actionPerformed(ActionEvent e) {
142137
searchAllFilesBox.setSelected(searchAllFiles);
143138
checkbox.add(searchAllFilesBox);
144139

145-
pain.add(checkbox);
140+
pane.add(checkbox);
146141

147142
JPanel buttons = new JPanel();
148-
149-
buttons.setLayout(new FlowLayout(FlowLayout.CENTER,BUTTONGAP,0));
143+
buttons.setLayout(new FlowLayout(FlowLayout.CENTER, BUTTONGAP, 0));
150144

151145
// ordering is different on mac versus pc
152146
if (Base.isMacOS()) {
@@ -163,7 +157,7 @@ public void actionPerformed(ActionEvent e) {
163157
buttons.add(replaceButton = new JButton(_("Replace")));
164158
buttons.add(replaceAllButton = new JButton(_("Replace All")));
165159
}
166-
pain.add(buttons);
160+
pane.add(buttons);
167161

168162
// to fix ugliness.. normally macosx java 1.3 puts an
169163
// 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
369363
}
370364

371365
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+
}
407396
}
408397

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);
411400
}
412401

413402
if (nextIndex != -1) {
@@ -424,24 +413,25 @@ private boolean find(boolean wrap,boolean backwards,boolean searchTabs,int origi
424413
* replacement text field.
425414
*/
426415
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);
433423

434424
boolean foundAtLeastOne = false;
435425

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) {
443433
Toolkit.getDefaultToolkit().beep();
444-
}
434+
}
445435

446436
}
447437

@@ -459,22 +449,22 @@ public void replaceAndFindNext() {
459449
* alternately until nothing more found.
460450
*/
461451
public void replaceAll() {
462-
if(findField.getText().length()==0)
463-
return;
452+
if (findField.getText().length() == 0)
453+
return;
464454
// move to the beginning
465455
editor.setSelection(0, 0);
466456

467457
boolean foundAtLeastOne = false;
468-
while ( true ) {
469-
if ( find(false,false,searchAllFiles,-1)) {
458+
while (true) {
459+
if (find(false, false, searchAllFiles, -1)) {
470460
foundAtLeastOne = true;
471461
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 {
474464
break;
475465
}
476466
}
477-
if ( !foundAtLeastOne ) {
467+
if (!foundAtLeastOne) {
478468
Toolkit.getDefaultToolkit().beep();
479469
}
480470
}

0 commit comments

Comments
 (0)