예제 #1
0
 private void insertString(int pos, String str) {
   Document doc = getDocument();
   try {
     doc.insertString(pos, str, null);
   } catch (Exception e) {
     Debug.error(me + "insertString: Problem while trying to insert at pos\n%s", e.getMessage());
   }
 }
예제 #2
0
 private void checkCompletion(java.awt.event.KeyEvent ke) throws BadLocationException {
   Document doc = getDocument();
   Element root = doc.getDefaultRootElement();
   int pos = getCaretPosition();
   int lineIdx = root.getElementIndex(pos);
   Element line = root.getElement(lineIdx);
   int start = line.getStartOffset(), len = line.getEndOffset() - start;
   String strLine = doc.getText(start, len - 1);
   Debug.log(9, "[" + strLine + "]");
   if (strLine.endsWith("find") && ke.getKeyChar() == '(') {
     ke.consume();
     doc.insertString(pos, "(", null);
     ButtonCapture btnCapture = new ButtonCapture(this, line);
     insertComponent(btnCapture);
     doc.insertString(pos + 2, ")", null);
   }
 }
 private void addText(String str, String styleName, JTextPane pane) {
   Document doc = pane.getDocument();
   int len = doc.getLength();
   try {
     doc.insertString(len, str, pane.getStyle(styleName));
   } catch (javax.swing.text.BadLocationException e) {
   }
 }
예제 #4
0
 // TODO not used
 public void appendString(String str) {
   Document doc = getDocument();
   try {
     int start = doc.getLength();
     doc.insertString(doc.getLength(), str, null);
     int end = doc.getLength();
     // end = parseLine(start, end, patHistoryBtnStr);
   } catch (Exception e) {
     Debug.error(me + "appendString: Problem while trying to append\n%s", e.getMessage());
   }
 }
  /** Resets the value of the JFormattedTextField to be <code>value</code>. */
  void resetValue(Object value) throws BadLocationException, ParseException {
    Document doc = getFormattedTextField().getDocument();
    String string = valueToString(value);

    try {
      ignoreDocumentMutate = true;
      doc.remove(0, doc.getLength());
      doc.insertString(0, string, null);
    } finally {
      ignoreDocumentMutate = false;
    }
    updateValue(value);
  }
예제 #6
0
    public void actionPerformed(JTextComponent text) {
      indentationLogic = ((EditorPane) text).getIndentationLogic();
      boolean indentError = false;
      Document doc = text.getDocument();
      Element map = doc.getDefaultRootElement();
      String tabWhitespace = PreferencesUser.getInstance().getTabWhitespace();
      Caret c = text.getCaret();
      int dot = c.getDot();
      int mark = c.getMark();
      int dotLine = map.getElementIndex(dot);
      int markLine = map.getElementIndex(mark);

      if (dotLine != markLine) {
        int first = Math.min(dotLine, markLine);
        int last = Math.max(dotLine, markLine);
        Element elem;
        int start;
        try {
          for (int i = first; i < last; i++) {
            elem = map.getElement(i);
            start = elem.getStartOffset();
            doc.insertString(start, tabWhitespace, null);
          }
          elem = map.getElement(last);
          start = elem.getStartOffset();
          if (Math.max(c.getDot(), c.getMark()) != start) {
            doc.insertString(start, tabWhitespace, null);
          }
        } catch (BadLocationException ble) {
          Debug.error(me + "Problem while indenting line\n%s", ble.getMessage());
          UIManager.getLookAndFeel().provideErrorFeedback(text);
        }
      } else {
        text.replaceSelection(tabWhitespace);
      }
    }
예제 #7
0
 private void indent(int startLine, int endLine, int level) {
   Document doc = getDocument();
   String strIndent = "";
   if (level > 0) {
     for (int i = 0; i < level; i++) {
       strIndent += "  ";
     }
   } else {
     Debug.error("negative indentation not supported yet!!");
   }
   for (int i = startLine; i < endLine; i++) {
     try {
       int off = getLineStartOffset(i);
       if (level > 0) {
         doc.insertString(off, strIndent, null);
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
예제 #8
0
 private void expandTab() throws BadLocationException {
   int pos = getCaretPosition();
   Document doc = getDocument();
   doc.remove(pos - 1, 1);
   doc.insertString(pos - 1, _tabString, null);
 }