示例#1
0
    // ----------------------------------------------------
    // return last location found
    public int searchBackward(String lastFindStr) {
      try { // backward
        if (isFindAgain) { // otherwise you find same string
          int foo = lastFindIndex; // begining of word
          if (foo >= 0) {
            editor1.setCaretPosition(foo);
          }
          // System.out.println("Debug:TextViewer:searchBackward: lastFindIndex: "+foo);
        }

        int carPos = editor1.getCaretPosition();
        // search backward
        // todo: should we use the getText(pos,len,segment);
        String chunk1 = editor1.getDocument().getText(0, carPos);
        int lastFindIndexTemp = chunk1.lastIndexOf(lastFindStr);
        if (lastFindIndexTemp == -1) {
          boolean okPressed = okCancelPopup.display("TextViewer:string not found. Try forward?");
          // handle forward
          if (okPressed) {
            forwardFindDirection = true;
            lastFindIndex = searchForward(lastFindStr);
          }
        } else {
          lastFindIndex = lastFindIndexTemp;
          editor1.setCaretPosition(lastFindIndex); // ready to type in body
          editor1.moveCaretPosition(lastFindIndex + lastFindStr.length()); // ready to type in body
        }
      } catch (BadLocationException badexception) {
        String errstr = "TextViewer:searchBackward: " + badexception.getMessage();
        warningPopup.display(errstr);
        return (-1);
      }
      return (lastFindIndex);
    }
示例#2
0
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum((int) f2.length());
        status.add(progress);
        status.revalidate();

        // try to start reading
        Reader in = new FileReader(f2);
        char[] buff = new char[4096];
        int nch;
        while ((nch = in.read(buff, 0, buff.length)) != -1) {
          doc2.insertString(doc2.getLength(), new String(buff, 0, nch), null);
          progress.setValue(progress.getValue() + nch);
        }

        // we are done... get rid of progressbar
        // doc2.addUndoableEditListener(undoHandler);
        status.removeAll();
        status.revalidate();

        // resetUndoManager();
      } catch (IOException e) {
        System.err.println("TextViewer:FileLoader " + e.toString());
      } catch (BadLocationException e) {
        System.err.println("TextViewer:FileLoader " + e.getMessage());
      }
      /* aa
         if (elementTreePanel != null) {
         SwingUtilities.invokeLater(new Runnable() {
         public void run() {
         elementTreePanel.setEditor(getEditor());
         }
         });
         }
      */
    }
示例#3
0
    // ----------------------
    // return last location found
    public int searchForward(String lastFindStr) {
      try { // forward
        // System.out.println("Debug:TextViewer:in searchForward");
        int carPos = editor1.getCaretPosition();
        // System.out.println("Debug:TextViewer: carPos "+carPos);
        // int strLength=editor1.getDocument().getEndPosition().getOffset();
        int strLength = editor1.getDocument().getLength();
        // if ((strLength-carPos)<0) {
        // System.out.println("Debug:TextViewer: carPos "+carPos);
        // System.out.println("Debug:TextViewer: strLength "+strLength);
        // }
        // search Forward
        // todo: should we use the getText(pos,len,segment);
        String chunk1 =
            editor1.getDocument().getText(carPos, (strLength - carPos)); // offset,length

        int lastFindIndexTemp = chunk1.indexOf(lastFindStr);

        if (lastFindIndexTemp == -1) {
          boolean okPressed = okCancelPopup.display("TextViewer:string not found. Try backward?");
          // handle backward
          if (okPressed) {
            forwardFindDirection = false;
            lastFindIndex = searchBackward(lastFindStr);
            // System.out.println("Debug:TextViewer: lastFindIndex "+lastFindIndex);
          }
        } else {
          lastFindIndex = carPos + lastFindIndexTemp;
          // System.out.println("Debug:TextViewer: lastFindIndex "+lastFindIndex);
          editor1.setCaretPosition(lastFindIndex); // ready to type in body
          editor1.moveCaretPosition(lastFindIndex + lastFindStr.length()); // ready to type in body
        }
      } catch (BadLocationException badexception) {
        String errstr = "TextViewer:searchForward: " + badexception.getMessage();
        warningPopup.display(errstr);
        return (-1);
      }
      return (lastFindIndex);
    }