コード例 #1
1
ファイル: EditorKit.java プロジェクト: niknah/SikuliX-2014
    // TODO: make this a method of SikuliDocument, no need to pass document as argument
    private void changeIndentation(DefaultStyledDocument doc, int linenum, int columns)
        throws BadLocationException {
      PreferencesUser pref = PreferencesUser.getInstance();
      boolean expandTab = pref.getExpandTab();
      int tabWidth = pref.getTabWidth();

      if (linenum < 0) {
        throw new BadLocationException("Negative line", -1);
      }
      Element map = doc.getDefaultRootElement();
      if (linenum >= map.getElementCount()) {
        throw new BadLocationException("No such line", doc.getLength() + 1);
      }
      if (columns == 0) {
        return;
      }

      Element lineElem = map.getElement(linenum);
      int lineStart = lineElem.getStartOffset();
      int lineLength = lineElem.getEndOffset() - lineStart;
      String line = doc.getText(lineStart, lineLength);

      // determine current indentation and number of whitespace characters
      int wsChars;
      int indentation = 0;
      for (wsChars = 0; wsChars < line.length(); wsChars++) {
        char c = line.charAt(wsChars);
        if (c == ' ') {
          indentation++;
        } else if (c == '\t') {
          indentation += tabWidth;
        } else {
          break;
        }
      }

      int newIndentation = indentation + columns;
      if (newIndentation <= 0) {
        doc.remove(lineStart, wsChars);
        return;
      }

      // build whitespace string for new indentation
      StringBuilder newWs = new StringBuilder(newIndentation / tabWidth + tabWidth - 1);
      int ind = 0;
      if (!expandTab) {
        for (; ind + tabWidth <= newIndentation; ind += tabWidth) {
          newWs.append('\t');
        }
      }
      for (; ind < newIndentation; ind++) {
        newWs.append(' ');
      }
      doc.replace(lineStart, wsChars, newWs.toString(), null);
    }
コード例 #2
0
 @Override
 public void remove(final int offs, final int len) throws BadLocationException {
   synchronized (doclock) {
     super.remove(offs, len);
     color(offs, -len);
     documentReader.update(offs, -len);
   }
 }
コード例 #3
0
  private void clean() { // TODO Minor Bug last ln is not colored right
    Element root = document.getDefaultRootElement();
    while (root.getElementCount() > maxLines) {
      try {
        parnum -= document.getText(0, root.getElement(0).getEndOffset()).length();
        document.remove(0, root.getElement(0).getEndOffset());

      } catch (BadLocationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
コード例 #4
0
ファイル: TerminalPanel.java プロジェクト: npk/lcmc
    /** Is called while characters is removed. */
    @Override
    public void remove(final int offs, final int len) throws BadLocationException {
      mPosLock.lock();
      if (offs >= commandOffset) {

        for (final String cheat : CHEATS_MAP.keySet()) {
          final int cheatPos = CHEATS_MAP.get(cheat);
          if (cheatPos > 0) {
            CHEATS_MAP.put(cheat, cheatPos - 1);
          }
        }
        if (editEnabled) {
          super.remove(offs, len);
        }
      }
      mPosLock.unlock();
    }
コード例 #5
0
 /**
  * Applies syntax highlighting after the document has been updated.
  *
  * @param offset the offset of the deletion
  * @param length the length of the deletion
  * @throws BadLocationException if offsets are invalid
  */
 public void remove(int offset, int length) throws BadLocationException {
   super.remove(offset, length);
   processChangedLines(offset, 0);
 }
コード例 #6
0
 @Override
 public void remove(int offs, int len) throws BadLocationException {
   super.remove(offs, len);
   checkDocument();
 }
コード例 #7
0
ファイル: TerminalPanel.java プロジェクト: npk/lcmc
 /** Same as remove. */
 void removeForced(final int offs, final int len) throws BadLocationException {
   super.remove(offs, len);
 }