1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-02 13:24:12 +01:00

Fix indent and typos on FindReplace.java

This commit is contained in:
Cristian Maglie 2014-07-25 12:10:42 +02:00
parent cd75cc24a2
commit 82401c84bb

View File

@ -44,6 +44,7 @@ import javax.swing.*;
* <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=244"> Bug 244</A> * <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=244"> Bug 244</A>
* should anyone have clues about how to fix. * should anyone have clues about how to fix.
*/ */
@SuppressWarnings("serial")
public class FindReplace extends JFrame implements ActionListener { public class FindReplace extends JFrame implements ActionListener {
static final int EDGE = Base.isMacOS() ? 20 : 13; static final int EDGE = Base.isMacOS() ? 20 : 13;
@ -76,39 +77,33 @@ public class FindReplace extends JFrame implements ActionListener {
super("Find"); super("Find");
setResizable(false); setResizable(false);
this.editor = editor; this.editor = editor;
FlowLayout searchLayout = new FlowLayout(FlowLayout.RIGHT,5,0); FlowLayout searchLayout = new FlowLayout(FlowLayout.RIGHT,5,0);
Container pain = getContentPane(); Container pane = getContentPane();
pain.setLayout(searchLayout); pane.setLayout(searchLayout);
JLabel findLabel = new JLabel(_("Find:")); JLabel findLabel = new JLabel(_("Find:"));
JLabel replaceLabel = new JLabel(_("Replace with:")); JLabel replaceLabel = new JLabel(_("Replace with:"));
Dimension labelDimension = replaceLabel.getPreferredSize(); Dimension labelDimension = replaceLabel.getPreferredSize();
JPanel find = new JPanel(); JPanel find = new JPanel();
find.add(findLabel); find.add(findLabel);
find.add(findField = new JTextField(20)); find.add(findField = new JTextField(20));
pane.add(find);
pain.add(find);
JPanel replace = new JPanel(); JPanel replace = new JPanel();
replace.add(replaceLabel); replace.add(replaceLabel);
replace.add(replaceField = new JTextField(20)); replace.add(replaceField = new JTextField(20));
pane.add(replace);
pain.add(replace);
int fieldHeight = findField.getPreferredSize().height; int fieldHeight = findField.getPreferredSize().height;
JPanel checkbox = new JPanel(); JPanel checkbox = new JPanel();
// Fill the findString with selected text if no previous value // Fill the findString with selected text if no previous value
if(editor.getSelectedText()!=null && editor.getSelectedText().length()>0) if (editor.getSelectedText() != null &&
findString = editor.getSelectedText(); editor.getSelectedText().length() > 0)
findString = editor.getSelectedText();
if (findString != null) findField.setText(findString); if (findString != null) findField.setText(findString);
if (replaceString != null) replaceField.setText(replaceString); if (replaceString != null) replaceField.setText(replaceString);
@ -142,11 +137,10 @@ public class FindReplace extends JFrame implements ActionListener {
searchAllFilesBox.setSelected(searchAllFiles); searchAllFilesBox.setSelected(searchAllFiles);
checkbox.add(searchAllFilesBox); checkbox.add(searchAllFilesBox);
pain.add(checkbox); pane.add(checkbox);
JPanel buttons = new JPanel(); JPanel buttons = new JPanel();
buttons.setLayout(new FlowLayout(FlowLayout.CENTER, BUTTONGAP, 0));
buttons.setLayout(new FlowLayout(FlowLayout.CENTER,BUTTONGAP,0));
// ordering is different on mac versus pc // ordering is different on mac versus pc
if (Base.isMacOS()) { if (Base.isMacOS()) {
@ -163,7 +157,7 @@ public class FindReplace extends JFrame implements ActionListener {
buttons.add(replaceButton = new JButton(_("Replace"))); buttons.add(replaceButton = new JButton(_("Replace")));
buttons.add(replaceAllButton = new JButton(_("Replace All"))); buttons.add(replaceAllButton = new JButton(_("Replace All")));
} }
pain.add(buttons); pane.add(buttons);
// to fix ugliness.. normally macosx java 1.3 puts an // to fix ugliness.. normally macosx java 1.3 puts an
// ugly white border around this object, so turn it off. // ugly white border around this object, so turn it off.
@ -369,45 +363,40 @@ public class FindReplace extends JFrame implements ActionListener {
} }
if (nextIndex == -1) { if (nextIndex == -1) {
//Nothing found on this tab: Search other tabs if required // Nothing found on this tab: Search other tabs if required
if(searchTabs) if (searchTabs) {
{ // editor.
//editor. Sketch sketch = editor.getSketch();
Sketch sketch = editor.getSketch(); if (sketch.getCodeCount() > 1) {
if(sketch.getCodeCount()>1) int realCurrentTab = sketch.getCodeIndex(sketch.getCurrentCode());
{
int realCurrentTab = sketch.getCodeIndex(sketch.getCurrentCode());
if(originTab!=realCurrentTab)
{
if(originTab <0)
originTab = realCurrentTab;
if(!wrap) if (originTab != realCurrentTab) {
if((!backwards && realCurrentTab+1 >= sketch.getCodeCount()) || (backwards && realCurrentTab-1 < 0)) if (originTab < 0)
return false; // Can't continue without wrap originTab = realCurrentTab;
if(backwards) if (!wrap)
{ if ((!backwards && realCurrentTab + 1 >= sketch.getCodeCount()) ||
sketch.handlePrevCode(); (backwards && realCurrentTab - 1 < 0))
this.setVisible(true); return false; // Can't continue without wrap
int l = editor.getText().length()-1;
editor.setSelection(l,l); if (backwards) {
} sketch.handlePrevCode();
else this.setVisible(true);
{ int l = editor.getText().length() - 1;
sketch.handleNextCode(); editor.setSelection(l, l);
this.setVisible(true); } else {
editor.setSelection(0,0); sketch.handleNextCode();
} this.setVisible(true);
editor.setSelection(0, 0);
return find(wrap,backwards,searchTabs,originTab); }
}
} return find(wrap, backwards, searchTabs, originTab);
}
}
} }
if(wrapNeeded) if (wrapNeeded)
nextIndex = backwards? text.lastIndexOf(search):text.indexOf(search, 0); nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0);
} }
if (nextIndex != -1) { if (nextIndex != -1) {
@ -424,24 +413,25 @@ public class FindReplace extends JFrame implements ActionListener {
* replacement text field. * replacement text field.
*/ */
public void replace() { public void replace() {
if(findField.getText().length()==0) if (findField.getText().length() == 0)
return; return;
int newpos = editor.getSelectionStart() - findField.getText().length(); int newpos = editor.getSelectionStart() - findField.getText().length();
if (newpos < 0) newpos = 0; if (newpos < 0)
editor.setSelection(newpos, newpos); newpos = 0;
editor.setSelection(newpos, newpos);
boolean foundAtLeastOne = false; boolean foundAtLeastOne = false;
if ( find(false,false,searchAllFiles,-1)) { if (find(false, false, searchAllFiles, -1)) {
foundAtLeastOne = true; foundAtLeastOne = true;
editor.setSelectedText(replaceField.getText()); editor.setSelectedText(replaceField.getText());
editor.getSketch().setModified(true); // TODO is this necessary? editor.getSketch().setModified(true); // TODO is this necessary?
} }
if ( !foundAtLeastOne ) { if (!foundAtLeastOne) {
Toolkit.getDefaultToolkit().beep(); Toolkit.getDefaultToolkit().beep();
} }
} }
@ -459,22 +449,22 @@ public class FindReplace extends JFrame implements ActionListener {
* alternately until nothing more found. * alternately until nothing more found.
*/ */
public void replaceAll() { public void replaceAll() {
if(findField.getText().length()==0) if (findField.getText().length() == 0)
return; return;
// move to the beginning // move to the beginning
editor.setSelection(0, 0); editor.setSelection(0, 0);
boolean foundAtLeastOne = false; boolean foundAtLeastOne = false;
while ( true ) { while (true) {
if ( find(false,false,searchAllFiles,-1)) { if (find(false, false, searchAllFiles, -1)) {
foundAtLeastOne = true; foundAtLeastOne = true;
editor.setSelectedText(replaceField.getText()); editor.setSelectedText(replaceField.getText());
editor.getSketch().setModified(true); // TODO is this necessary? editor.getSketch().setModified(true); // TODO is this necessary?
} else { } else {
break; break;
} }
} }
if ( !foundAtLeastOne ) { if (!foundAtLeastOne) {
Toolkit.getDefaultToolkit().beep(); Toolkit.getDefaultToolkit().beep();
} }
} }