Example #1
1
    // 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);
    }
 /**
  * Inserting text into end of the an element with the same attributes; the following element has
  * different attributes.
  *
  * <p>This test is equivalent to <code>doc.insertString(insertOffset, newLine, bold)</code>, where
  * 2 is added to default value of <code>insertOffset</code>.
  */
 public void testInsertSameAttrsEnd() throws Exception {
   insertOffset += 2;
   // doc.insertString(insertOffset, newLine, bold);
   content.insertString(insertOffset, newLine);
   event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
   ElementSpec[] specs = {
     new ElementSpec(null, ElementSpec.ContentType, newLineLen),
     new ElementSpec(null, ElementSpec.EndTagType),
     new ElementSpec(null, ElementSpec.StartTagType)
   };
   specs[0].setDirection(ElementSpec.JoinPreviousDirection);
   specs[2].setDirection(ElementSpec.JoinFractureDirection);
   // Spec [0] has wrong attributes (should be bold) but everything works
   // the way it supposed to.
   buf.insert(insertOffset, newLineLen, specs, event);
   List<?> edits = getEdits(event);
   assertEquals(2, edits.size());
   assertChange(edits.get(0), new int[] {10, 16, 16, 17}, new int[] {});
   assertChange(edits.get(1), new int[] {}, new int[] {10, 17});
   assertChildren(root.getElement(0), new int[] {0, 5, 5, 10}, new AttributeSet[] {null, bold});
   assertChildren(
       root.getElement(1), new int[] {10, 16, 16, 17}, new AttributeSet[] {italic, null});
   assertEquals("bold\n", getText(doc.getCharacterElement(insertOffset)));
   assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
 }
 /**
  * Inserting text into the start of a paragraph with different attributes.
  *
  * <p>This test is equivalent to <code>doc.insertString(insertOffset, newLine, italic)</code>,
  * where <code>insertOffset = paragraph.getEndOffset()</code>.
  */
 public void testInsertDiffAttrsParStart() throws Exception {
   insertOffset = paragraph.getEndOffset();
   // doc.insertString(insertOffset, newLine, italic);
   content.insertString(insertOffset, newLine);
   event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
   ElementSpec[] specs = {
     new ElementSpec(null, ElementSpec.EndTagType),
     new ElementSpec(null, ElementSpec.StartTagType),
     new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
     new ElementSpec(null, ElementSpec.EndTagType),
     new ElementSpec(null, ElementSpec.StartTagType)
   };
   specs[4].setDirection(ElementSpec.JoinNextDirection);
   buf.insert(insertOffset, newLineLen, specs, event);
   List<?> edits = getEdits(event);
   assertEquals(3, edits.size());
   assertChange(edits.get(0), new int[] {15, 17}, new int[] {15, 16});
   assertChange(edits.get(1), new int[] {}, new int[] {16, 17});
   assertChange(edits.get(2), new int[] {}, new int[] {16, 17});
   assertChildren(
       root.getElement(0),
       new int[] {0, 5, 5, 9, 9, 15, 15, 16},
       new AttributeSet[] {null, bold, italic, null});
   assertChildren(root.getElement(1), new int[] {16, 17}, new AttributeSet[] {italic});
   assertChildren(root.getElement(2), new int[] {17, 22}, new AttributeSet[] {null});
   assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
   assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
 }
 /**
  * Inserting text with the same attributes into the beginning of the document.
  *
  * <p>This test is equivalent to <code>doc.insertString(insertOffset, newLine, null)</code>, where
  * <code>insertOffset = 0</code>.
  */
 public void testInsertSameAttrsDocStart() throws Exception {
   insertOffset = 0;
   // doc.insertString(insertOffset, newLine, null);
   content.insertString(insertOffset, newLine);
   event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
   ElementSpec[] specs = {
     new ElementSpec(null, ElementSpec.ContentType, newLineLen),
     new ElementSpec(null, ElementSpec.EndTagType),
     new ElementSpec(null, ElementSpec.StartTagType)
   };
   specs[0].setDirection(ElementSpec.JoinPreviousDirection);
   specs[2].setDirection(ElementSpec.JoinFractureDirection);
   buf.insert(insertOffset, newLineLen, specs, event);
   List<?> edits = getEdits(event);
   assertEquals(2, edits.size());
   assertChange(edits.get(0), new int[] {0, 6, 6, 10, 10, 16, 16, 17}, new int[] {0, 1});
   assertChange(edits.get(1), new int[] {}, new int[] {1, 17});
   assertChildren(root.getElement(0), new int[] {0, 1}, new AttributeSet[] {null});
   assertChildren(
       root.getElement(1),
       new int[] {1, 6, 6, 10, 10, 16, 16, 17},
       new AttributeSet[] {null, bold, italic, null});
   assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
   assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLineLen)));
 }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   doc = new DefaultStyledDocument();
   root = doc.getDefaultRootElement();
   buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
   doc.buffer = buf;
   paragraph = root.getElement(0);
   content = doc.getContent();
   content.insertString(0, "plainbolditalic\ntext");
   // Create the structure equivalent to this sequence:
   // doc.insertString(doc.getLength(), "plain", null);    // 5 chars
   // doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
   // doc.insertString(doc.getLength(), "italic", italic); // 6 chars
   // doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
   doc.writeLock(); // Write lock needed to modify document structure
   Element[] leaves = new Element[4];
   leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
   leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
   leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
   leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
   ((BranchElement) paragraph).replace(0, 1, leaves);
   BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
   leaves = new Element[1];
   leaves[0] = doc.createLeafElement(branch, null, 16, 21);
   branch.replace(0, 0, leaves);
   // Add this branch to the root
   ((BranchElement) root).replace(1, 0, new Element[] {branch});
   insertOffset = 5 + 2;
 }
Example #6
0
  /**
   * Searches for a quote token.
   *
   * @param content the content to search
   * @param startOffset the start of the search
   * @param endOffset the end of the search
   * @return the new position
   */
  protected int getQuoteToken(String content, int startOffset, int endOffset) {
    String quoteDelimiter = content.substring(startOffset, startOffset + 1);
    String escapeString = escapeQuote(quoteDelimiter);

    int index;
    int endOfQuote = startOffset;

    // skip over the escape quotes in this quote

    index = content.indexOf(escapeString, endOfQuote + 1);

    while ((index > -1) && (index < endOffset)) {
      endOfQuote = index + 1;
      index = content.indexOf(escapeString, endOfQuote);
    }

    // now find the matching delimiter

    index = content.indexOf(quoteDelimiter, endOfQuote + 1);

    if ((index < 0) || (index > endOffset)) endOfQuote = endOffset;
    else endOfQuote = index;

    m_Self.setCharacterAttributes(startOffset, endOfQuote - startOffset + 1, DEFAULT_STRING, false);

    return endOfQuote + 1;
  }
Example #7
0
  /**
   * Highlight lines to start or end delimiter.
   *
   * @param content the content to parse
   * @param line the line number
   * @throws BadLocationException if offsets are wrong
   */
  protected void highlightLinesAfter(String content, int line) throws BadLocationException {
    int offset = m_RootElement.getElement(line).getEndOffset();

    // Start/End delimiter not found, nothing to do

    int startDelimiter = -1;
    int endDelimiter = -1;
    if (getMultiLineComment()) {
      startDelimiter = indexOf(content, getMultiLineCommentStart(), offset);
      endDelimiter = indexOf(content, getMultiLineCommentEnd(), offset);
    }

    if (startDelimiter < 0) startDelimiter = content.length();

    if (endDelimiter < 0) endDelimiter = content.length();

    int delimiter = Math.min(startDelimiter, endDelimiter);

    if (delimiter < offset) return;

    // Start/End delimiter found, reapply highlighting

    int endLine = m_RootElement.getElementIndex(delimiter);

    for (int i = line + 1; i < endLine; i++) {
      Element branch = m_RootElement.getElement(i);
      Element leaf = m_Self.getCharacterElement(branch.getStartOffset());
      AttributeSet as = leaf.getAttributes();

      if (as.isEqual(DEFAULT_COMMENT)) applyHighlighting(content, i);
    }
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    doc =
        new DefaultStyledDocument(
            new StyleContext() {
              private static final long serialVersionUID = 1L;

              @Override
              public Color getBackground(AttributeSet as) {
                getBackground = true;
                return super.getBackground(as);
              }

              @Override
              public Font getFont(AttributeSet as) {
                getFont = true;
                return super.getFont(as);
              }

              @Override
              public Color getForeground(AttributeSet as) {
                getForeground = true;
                return super.getForeground(as);
              }
            });
    styles = (StyleContext) doc.getAttributeContext();
    attrSet = styles.getEmptySet();
  }
Example #9
0
  /**
   * Adds the matching block end.
   *
   * @param offset the offset
   * @return the string after adding the matching block end
   * @throws BadLocationException if the offset is invalid
   */
  protected String addMatchingBlockEnd(int offset) throws BadLocationException {
    StringBuffer result;
    StringBuffer whiteSpace = new StringBuffer();
    int line = m_RootElement.getElementIndex(offset);
    int i = m_RootElement.getElement(line).getStartOffset();

    while (true) {
      String temp = m_Self.getText(i, 1);

      if (temp.equals(" ") || temp.equals("\t")) {
        whiteSpace.append(temp);
        i++;
      } else {
        break;
      }
    }

    // assemble string
    result = new StringBuffer();
    result.append(m_BlockStart);
    result.append("\n");
    result.append(whiteSpace.toString());
    if (m_UseBlanks) result.append(m_Indentation);
    else result.append("\t");
    result.append("\n");
    result.append(whiteSpace.toString());
    result.append(m_BlockEnd);

    return result.toString();
  }
Example #10
0
  /**
   * Override to apply syntax highlighting after the document has been updated.
   *
   * @param offset the offset
   * @param str the string to insert
   * @param a the attribute set, can be null
   * @throws BadLocationException if offset is invalid
   */
  public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
    if (m_AddMatchingEndBlocks && (m_BlockStart.length() > 0) && str.equals(m_BlockStart))
      str = addMatchingBlockEnd(offset);
    else if (m_UseBlanks && str.equals("\t")) str = m_Indentation;

    super.insertString(offset, str, a);
    processChangedLines(offset, str.length());
  }
Example #11
0
  /**
   * Initializes the document.
   *
   * @param props the properties to obtain the setup from
   */
  public SyntaxDocument(Properties props) {
    m_Self = this;
    m_RootElement = m_Self.getDefaultRootElement();
    m_Keywords = new HashMap<String, MutableAttributeSet>();
    m_FontSize = DEFAULT_FONT_SIZE;
    m_FontName = DEFAULT_FONT_FAMILY;
    putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n");

    setup(props);
  }
 public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
   if ((getLength() + str.length()) <= size) {
     super.insertString(offs, str, a);
   } else {
     System.err.println(
         "Tried to make field "
             + (getLength() + str.length())
             + " characters long when max length is "
             + size);
     Toolkit.getDefaultToolkit().beep();
   }
 }
Example #13
0
  /**
   * Parse the line to determine the appropriate highlighting.
   *
   * @param content the content to parse
   * @param line the line number
   * @throws BadLocationException if offsets are invalid
   */
  protected void applyHighlighting(String content, int line) throws BadLocationException {
    int startOffset = m_RootElement.getElement(line).getStartOffset();
    int endOffset = m_RootElement.getElement(line).getEndOffset() - 1;

    int lineLength = endOffset - startOffset;
    int contentLength = content.length();

    if (endOffset >= contentLength) endOffset = contentLength - 1;

    // check for multi line comments
    // (always set the comment attribute for the entire line)

    if (getMultiLineComment()) {
      if (endingMultiLineComment(content, startOffset, endOffset)
          || isMultiLineComment()
          || startingMultiLineComment(content, startOffset, endOffset)) {
        m_Self.setCharacterAttributes(
            startOffset, endOffset - startOffset + 1, DEFAULT_COMMENT, false);
        return;
      }
    }

    // set normal attributes for the line

    m_Self.setCharacterAttributes(startOffset, lineLength, DEFAULT_NORMAL, true);

    // check for single line comment

    int index = content.indexOf(getSingleLineCommentStart(), startOffset);

    if ((index > -1) && (index < endOffset)) {
      m_Self.setCharacterAttributes(index, endOffset - index + 1, DEFAULT_COMMENT, false);
      endOffset = index - 1;
    }

    // check for tokens

    checkForTokens(content, startOffset, endOffset);
  }
  public void testStyleChanged() {
    final Style[] changed = new Style[1];
    doc =
        new DefaultStyledDocument() {
          private static final long serialVersionUID = 1L;

          @Override
          protected void styleChanged(final Style style) {
            changed[0] = style;
            super.styleChanged(style);
          }
        };
    styles = (StyleContext) doc.getAttributeContext();
    final NamedStyle aStyle = (NamedStyle) doc.addStyle(STYLE_NAME, null);
    assertEquals(0, styles.getChangeListeners().length);
    assertEquals(0, aStyle.listenerList.getListenerCount());
    final DocumentListener listener =
        new DocumentListener() {
          public void insertUpdate(DocumentEvent e) {}

          public void removeUpdate(DocumentEvent e) {}

          public void changedUpdate(DocumentEvent e) {}
        };
    doc.addDocumentListener(listener);
    assertEquals(1, styles.getChangeListeners().length);
    assertEquals(1, aStyle.listenerList.getListenerCount());
    final NamedStyle anotherStyle = (NamedStyle) styles.addStyle("otherStyle", aStyle);
    assertEquals(1, anotherStyle.listenerList.getListenerCount());
    final NamedStyle nullStyle = (NamedStyle) styles.addStyle(null, null);
    assertEquals(0, nullStyle.listenerList.getListenerCount());
    assertNull(changed[0]);
    aStyle.addAttribute("key", "value");
    assertSame(aStyle, changed[0]);
    doc.removeDocumentListener(listener);
    assertEquals(0, styles.getChangeListeners().length);
    assertEquals(0, aStyle.listenerList.getListenerCount());
    assertEquals(0, anotherStyle.listenerList.getListenerCount());
  }
Example #15
0
 public void write(Writer out, Document doc, int pos, int len, Map<String, String> copiedImgs)
     throws IOException, BadLocationException {
   Debug.log(9, "SikuliEditorKit.write %d %d", pos, len);
   DefaultStyledDocument sdoc = (DefaultStyledDocument) doc;
   int i = pos;
   String absPath;
   while (i < pos + len) {
     Element e = sdoc.getCharacterElement(i);
     int start = e.getStartOffset(), end = e.getEndOffset();
     if (e.getName().equals(StyleConstants.ComponentElementName)) {
       // A image argument to be filled
       AttributeSet attr = e.getAttributes();
       Component com = StyleConstants.getComponent(attr);
       out.write(com.toString());
       if (copiedImgs != null
           && (com instanceof EditorPatternButton || com instanceof EditorPatternLabel)) {
         if (com instanceof EditorPatternButton) {
           absPath = ((EditorPatternButton) com).getFilename();
         } else {
           absPath = ((EditorPatternLabel) com).getFile();
         }
         String fname = (new File(absPath)).getName();
         copiedImgs.put(fname, absPath);
         Debug.log(3, "save image for copy&paste: " + fname + " -> " + absPath);
       }
     } else {
       if (start < pos) {
         start = pos;
       }
       if (end > pos + len) {
         end = pos + len;
       }
       out.write(doc.getText(start, end - start));
     }
     i = end;
   }
   out.close();
 }
 /**
  * Inserting text into the end of the document with different attributes.
  *
  * <p>This test is equivalent to <code>doc.insertString(insertOffset, newLine, italic)</code>,
  * where <code>insertOffset = doc.getLength()</code>.
  */
 public void testInsertDiffAttrsDocEnd() throws Exception {
   insertOffset = doc.getLength();
   // doc.insertString(insertOffset, newLine, italic);
   content.insertString(insertOffset, newLine);
   event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
   ElementSpec[] specs = {
     new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
     new ElementSpec(null, ElementSpec.EndTagType),
     new ElementSpec(null, ElementSpec.StartTagType)
   };
   specs[2].setDirection(ElementSpec.JoinFractureDirection);
   buf.insert(insertOffset, newLineLen, specs, event);
   List<?> edits = getEdits(event);
   assertEquals(2, edits.size());
   assertChange(edits.get(0), new int[] {16, 22}, new int[] {16, 20, 20, 21});
   assertChange(edits.get(1), new int[] {}, new int[] {21, 22});
   assertChildren(
       root.getElement(1), new int[] {16, 20, 20, 21}, new AttributeSet[] {null, italic});
   assertChildren(root.getElement(2), new int[] {21, 22}, new AttributeSet[] {null});
   assertEquals("text", getText(doc.getCharacterElement(insertOffset - 1)));
   assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
   assertEquals("\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
 }
Example #17
0
  /**
   * Determine how many lines have been changed, then apply highlighting to each line.
   *
   * @param offset the offset of the changed lines
   * @param length the length of the change
   * @throws BadLocationException if offset is invalid
   */
  public void processChangedLines(int offset, int length) throws BadLocationException {
    String content = m_Self.getText(0, m_Self.getLength());

    // The lines affected by the latest document update

    int startLine = m_RootElement.getElementIndex(offset);
    int endLine = m_RootElement.getElementIndex(offset + length);

    // Make sure all comment lines prior to the start line are commented
    // and determine if the start line is still in a multi line comment

    if (getMultiLineComment()) setInsideMultiLineComment(commentLinesBefore(content, startLine));

    // Do the actual highlighting

    for (int i = startLine; i <= endLine; i++) {
      applyHighlighting(content, i);
    }

    // Resolve highlighting to the next end multi line delimiter

    if (isMultiLineComment()) commentLinesAfter(content, endLine);
    else highlightLinesAfter(content, endLine);
  }
Example #18
0
  /**
   * Searches for a keyword token.
   *
   * @param content the content to search in
   * @param startOffset the position to start the search fromm
   * @param endOffset the position to end the search
   * @return the new position
   */
  protected int getOtherToken(String content, int startOffset, int endOffset) {
    int endOfToken = startOffset + 1;

    while (endOfToken <= endOffset) {
      if (isDelimiter(content.substring(endOfToken, endOfToken + 1))) break;
      endOfToken++;
    }

    String token = content.substring(startOffset, endOfToken);

    // see if this token has a highlighting format associated with it
    MutableAttributeSet attr = getKeywordFormatting(token);
    if (attr != null)
      m_Self.setCharacterAttributes(startOffset, endOfToken - startOffset, attr, false);

    return endOfToken + 1;
  }
 public void testGetStyleNames() {
   final String[] names = new String[] {"one", "two", "three"};
   for (int i = 0; i < names.length; i++) {
     styles.addStyle(names[i], null);
   }
   boolean[] found = new boolean[names.length];
   Enumeration<?> styleNames = doc.getStyleNames();
   while (styleNames.hasMoreElements()) {
     Object name = styleNames.nextElement();
     for (int i = 0; i < names.length; i++) {
       found[i] = found[i] || name.equals(names[i]);
     }
   }
   for (int i = 0; i < found.length; i++) {
     assertTrue("@ " + i, found[i]);
   }
 }
Example #20
0
  /**
   * Highlight comment lines to matching end delimiter.
   *
   * @param content the content to parse
   * @param line the line number
   */
  protected void commentLinesAfter(String content, int line) {
    int offset = m_RootElement.getElement(line).getEndOffset();

    // End of comment not found, nothing to do

    int endDelimiter = -1;
    if (getMultiLineComment()) endDelimiter = indexOf(content, getMultiLineCommentEnd(), offset);

    if (endDelimiter < 0) return;

    // Matching start/end of comment found, comment the lines

    int startDelimiter = lastIndexOf(content, getMultiLineCommentStart(), endDelimiter);

    if (startDelimiter < 0 || startDelimiter <= offset) {
      m_Self.setCharacterAttributes(offset, endDelimiter - offset + 1, DEFAULT_COMMENT, false);
    }
  }
Example #21
0
  /**
   * Highlight lines when a multi line comment is still 'open' (ie. matching end delimiter has not
   * yet been encountered).
   *
   * @param content the content to check
   * @param line the line number
   * @return true if there are comment lines before
   */
  protected boolean commentLinesBefore(String content, int line) {
    int offset = m_RootElement.getElement(line).getStartOffset();

    // Start of comment not found, nothing to do

    int startDelimiter = -1;
    if (getMultiLineComment())
      startDelimiter = lastIndexOf(content, getMultiLineCommentStart(), offset - 2);

    if (startDelimiter < 0) return false;

    // Matching start/end of comment found, nothing to do

    int endDelimiter = indexOf(content, getMultiLineCommentEnd(), startDelimiter);

    if (endDelimiter < offset & endDelimiter != -1) return false;

    // End of comment not found, highlight the lines

    m_Self.setCharacterAttributes(
        startDelimiter, offset - startDelimiter + 1, DEFAULT_COMMENT, false);
    return true;
  }
 public void testRemoveStyle() {
   doc.addStyle(STYLE_NAME, null);
   assertNotNull(doc.getStyle(STYLE_NAME));
   doc.removeStyle(STYLE_NAME);
   assertNull(doc.getStyle(STYLE_NAME));
 }
 public void testGetStyle() {
   Style aStyle = styles.addStyle(STYLE_NAME, null);
   assertSame(aStyle, doc.getStyle(STYLE_NAME));
 }
 public void testGetForeground() {
   assertFalse(getForeground);
   doc.getForeground(attrSet);
   assertTrue(getForeground);
 }
 public void testGetFont() {
   assertFalse(getFont);
   doc.getFont(attrSet);
   assertTrue(getFont);
 }
 public void testAddStyle() {
   Style aStyle = doc.addStyle(STYLE_NAME, null);
   assertSame(styles.getStyle(STYLE_NAME), aStyle);
 }
Example #27
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);
 }
Example #28
0
 private void highlightArea(int pos, int len, String col) {
   SimpleAttributeSet attrs = new SimpleAttributeSet();
   StyleConstants.setForeground(attrs, getColour(col));
   document.setCharacterAttributes(pos, len, attrs, true);
 }
 private String getText(final int offset, final int length) throws BadLocationException {
   return doc.getText(offset, length);
 }
 @Override
 protected void tearDown() throws Exception {
   super.tearDown();
   doc.writeUnlock();
 }