From d6db2611afa52b2f00fd32c41501220fdc8d42e4 Mon Sep 17 00:00:00 2001 From: Fitoh Date: Fri, 23 Oct 2015 15:46:14 +0300 Subject: [PATCH 1/4] Made search function non case-sensitive Search function (find, find next, replace, replace all) now doesn't differentiate between lower-cases and upper-cases. Previously couldn't find the word "Example" when "example" was typed into the search field. --- src/simplejavatexteditor/Find.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/simplejavatexteditor/Find.java b/src/simplejavatexteditor/Find.java index 29f9ca3..cf963f2 100644 --- a/src/simplejavatexteditor/Find.java +++ b/src/simplejavatexteditor/Find.java @@ -100,14 +100,14 @@ public Find(JTextArea text) { } public void find() { - int select_start = txt.getText().indexOf(textF.getText()); + int select_start = txt.getText().toLowerCase().indexOf(textF.getText().toLowerCase()); if(select_start == -1) { startIndex = 0; JOptionPane.showMessageDialog(null, "Could not find \"" + textF.getText() + "\"!"); return; } - if(select_start == txt.getText().lastIndexOf(textF.getText())) + if(select_start == txt.getText().toLowerCase().lastIndexOf(textF.getText().toLowerCase())) { startIndex = 0; } @@ -136,12 +136,12 @@ public void findNext() { } try { - int select_start = txt.getText().indexOf(selection, startIndex); + int select_start = txt.getText().toLowerCase().indexOf(selection.toLowerCase(), startIndex); int select_end = select_start+selection.length(); txt.select(select_start, select_end); startIndex = select_end+1; - if(select_start == txt.getText().lastIndexOf(selection)) + if(select_start == txt.getText().toLowerCase().lastIndexOf(selection.toLowerCase())) { startIndex = 0; } @@ -163,9 +163,9 @@ public void replace() { } public void replaceAll() { - txt.setText(txt.getText().replaceAll(textF.getText(), textR.getText())); + txt.setText(txt.getText().toLowerCase().replaceAll(textF.getText().toLowerCase(), textR.getText())); } - + public void actionPerformed(ActionEvent e) { if(e.getSource() == findBtn) { From a466f1ab1ce47c678c9c9d76d7c8c23ac91d3474 Mon Sep 17 00:00:00 2001 From: Fitoh Date: Sat, 24 Oct 2015 08:57:04 +0300 Subject: [PATCH 2/4] Fixed a bug in replace function Fixed a bug where replace function simply added the replace word to the end of the text when it failed to find the original word that was to be replaced. --- nbproject/project.properties | 9 ++++++--- src/simplejavatexteditor/Find.java | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index 4ef3cdb..b0537b4 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,9 +1,10 @@ annotation.processing.enabled=true annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=SimpleJavaTextEditor +application.vendor=Ossi build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: @@ -26,6 +27,7 @@ dist.archive.excludes= dist.dir=dist dist.jar=${dist.dir}/SimpleJavaTextEditor.jar dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= excludes= includes=** jar.compress=false @@ -33,10 +35,11 @@ javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false +javac.external.vm=false javac.processorpath=\ ${javac.classpath} -javac.source=1.8 -javac.target=1.8 +javac.source=1.7 +javac.target=1.7 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff --git a/src/simplejavatexteditor/Find.java b/src/simplejavatexteditor/Find.java index cf963f2..6e726a2 100644 --- a/src/simplejavatexteditor/Find.java +++ b/src/simplejavatexteditor/Find.java @@ -28,11 +28,13 @@ public class Find extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; int startIndex=0; + int select_start=-1; JLabel lab1, lab2; JTextField textF, textR; JButton findBtn, findNext, replace, replaceAll, cancel; private JTextArea txt; + public Find(JTextArea text) { this.txt = text; @@ -100,7 +102,7 @@ public Find(JTextArea text) { } public void find() { - int select_start = txt.getText().toLowerCase().indexOf(textF.getText().toLowerCase()); + select_start = txt.getText().toLowerCase().indexOf(textF.getText().toLowerCase()); if(select_start == -1) { startIndex = 0; @@ -154,6 +156,7 @@ public void replace() { try { find(); + if (select_start != -1) txt.replaceSelection(textR.getText()); } catch(NullPointerException e) From dce27e1655db179050697a6f9a781ded05f8bfe5 Mon Sep 17 00:00:00 2001 From: Fitoh Date: Sat, 24 Oct 2015 09:00:17 +0300 Subject: [PATCH 3/4] Revert "Fixed a bug in replace function" This reverts commit a466f1ab1ce47c678c9c9d76d7c8c23ac91d3474. --- nbproject/project.properties | 9 +++------ src/simplejavatexteditor/Find.java | 5 +---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index b0537b4..4ef3cdb 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,10 +1,9 @@ annotation.processing.enabled=true annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=SimpleJavaTextEditor -application.vendor=Ossi build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: @@ -27,7 +26,6 @@ dist.archive.excludes= dist.dir=dist dist.jar=${dist.dir}/SimpleJavaTextEditor.jar dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= excludes= includes=** jar.compress=false @@ -35,11 +33,10 @@ javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false -javac.external.vm=false javac.processorpath=\ ${javac.classpath} -javac.source=1.7 -javac.target=1.7 +javac.source=1.8 +javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff --git a/src/simplejavatexteditor/Find.java b/src/simplejavatexteditor/Find.java index 6e726a2..cf963f2 100644 --- a/src/simplejavatexteditor/Find.java +++ b/src/simplejavatexteditor/Find.java @@ -28,13 +28,11 @@ public class Find extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; int startIndex=0; - int select_start=-1; JLabel lab1, lab2; JTextField textF, textR; JButton findBtn, findNext, replace, replaceAll, cancel; private JTextArea txt; - public Find(JTextArea text) { this.txt = text; @@ -102,7 +100,7 @@ public Find(JTextArea text) { } public void find() { - select_start = txt.getText().toLowerCase().indexOf(textF.getText().toLowerCase()); + int select_start = txt.getText().toLowerCase().indexOf(textF.getText().toLowerCase()); if(select_start == -1) { startIndex = 0; @@ -156,7 +154,6 @@ public void replace() { try { find(); - if (select_start != -1) txt.replaceSelection(textR.getText()); } catch(NullPointerException e) From 703d563ab2813356bec2b9f82082f20b6ab07baa Mon Sep 17 00:00:00 2001 From: Fitoh Date: Sat, 24 Oct 2015 09:06:43 +0300 Subject: [PATCH 4/4] Fixed the bug in replace function Fixed a bug where replace function simply added the replace word to the end of the text when it failed to find the original word that was to be replaced. --- src/simplejavatexteditor/Find.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/simplejavatexteditor/Find.java b/src/simplejavatexteditor/Find.java index cf963f2..6e726a2 100644 --- a/src/simplejavatexteditor/Find.java +++ b/src/simplejavatexteditor/Find.java @@ -28,11 +28,13 @@ public class Find extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; int startIndex=0; + int select_start=-1; JLabel lab1, lab2; JTextField textF, textR; JButton findBtn, findNext, replace, replaceAll, cancel; private JTextArea txt; + public Find(JTextArea text) { this.txt = text; @@ -100,7 +102,7 @@ public Find(JTextArea text) { } public void find() { - int select_start = txt.getText().toLowerCase().indexOf(textF.getText().toLowerCase()); + select_start = txt.getText().toLowerCase().indexOf(textF.getText().toLowerCase()); if(select_start == -1) { startIndex = 0; @@ -154,6 +156,7 @@ public void replace() { try { find(); + if (select_start != -1) txt.replaceSelection(textR.getText()); } catch(NullPointerException e)