OSDN Git Service

change history of the search text field a little
authormshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Fri, 28 May 2010 22:47:26 +0000 (22:47 +0000)
committermshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Fri, 28 May 2010 22:47:26 +0000 (22:47 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/sawarabi-fonts/trunk@8 54a90f34-5e62-402c-8eae-46c47f0b2e07

chartool/src/jp/sourceforge/sawarabifonts/chartool/HistoryBuffer.java
chartool/src/jp/sourceforge/sawarabifonts/chartool/SearchPanel.java

index 24d99cc..eabb924 100644 (file)
@@ -30,13 +30,13 @@ public class HistoryBuffer {
        public void add(String buf) {
                buffer.add(buf);
                if (buffer.size() >= MAX_LENGTH) { buffer.removeFirst(); }
        public void add(String buf) {
                buffer.add(buf);
                if (buffer.size() >= MAX_LENGTH) { buffer.removeFirst(); }
-               iterator = buffer.listIterator(buffer.size() - 1);
+               iterator = null;
                prev = true;
        }
 
        public String getPrev() {
                String ret = null;
                prev = true;
        }
 
        public String getPrev() {
                String ret = null;
-               if (! buffer.isEmpty() && iterator.hasPrevious()) {
+               if (! isBufferEmpty() && iterator.hasPrevious()) {
                        ret = iterator.previous();
                        if (! prev && iterator.hasPrevious()) { ret = iterator.previous(); }
                        prev = true;
                        ret = iterator.previous();
                        if (! prev && iterator.hasPrevious()) { ret = iterator.previous(); }
                        prev = true;
@@ -46,7 +46,7 @@ public class HistoryBuffer {
 
        public String getNext() {
                String ret = null;
 
        public String getNext() {
                String ret = null;
-               if (! buffer.isEmpty() && iterator.hasNext()) {
+               if (! isBufferEmpty() && iterator.hasNext()) {
                        ret = iterator.next();
                        if (prev && iterator.hasNext()) { ret = iterator.next(); }
                        prev = false;
                        ret = iterator.next();
                        if (prev && iterator.hasNext()) { ret = iterator.next(); }
                        prev = false;
@@ -57,4 +57,12 @@ public class HistoryBuffer {
        public String getCurrent() {
                return buffer.isEmpty() ? null : buffer.getLast();
        }
        public String getCurrent() {
                return buffer.isEmpty() ? null : buffer.getLast();
        }
+
+       private boolean isBufferEmpty() {
+               boolean ret = buffer.isEmpty();
+               if (! ret && iterator == null) { 
+                       iterator = buffer.listIterator(buffer.size() - 1); 
+               }
+               return ret;
+       }
 }
 }
index 97b51f9..9d9041d 100644 (file)
@@ -141,14 +141,14 @@ public class SearchPanel extends JPanel {
        private void setupSearchKeymap(final GuiController controller) {
                KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
                Action a = new TextAction("search") {
        private void setupSearchKeymap(final GuiController controller) {
                KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
                Action a = new TextAction("search") {
-                       private static final long serialVersionUID = 7670487950463928408L;
+                       private static final long serialVersionUID = 118797095359988885L;
                        public void actionPerformed(ActionEvent e) {
                                String st = searchField.getSelectedText();
                                int p = searchField.getCaretPosition();
                                controller.onSearch(searchField.getText(), p, st);
                                String s = buffer.getCurrent();
                                String t = searchField.getText();
                        public void actionPerformed(ActionEvent e) {
                                String st = searchField.getSelectedText();
                                int p = searchField.getCaretPosition();
                                controller.onSearch(searchField.getText(), p, st);
                                String s = buffer.getCurrent();
                                String t = searchField.getText();
-                               if (s == null || ! s.equals(t)) {
+                               if ((s == null || ! s.equals(t)) && t.length() != 0) {
                                        buffer.add(t);
                                }
                        }
                                        buffer.add(t);
                                }
                        }