Search in sources :

Example 21 with Element

use of javax.swing.text.Element in project binnavi by google.

the class ConsoleCodeDocument method setCurrentLine.

/**
   * Insert a line in the text element containing the passed position skipping a number of character
   * from the beginning of the element. The function of the skipping of characters is to "jump" over
   * the prompt in the beginning of a line.
   * 
   * @param pos the position from which to retrieve the element that contains it
   * @param skip how many characters are skipped from the beginning of the element when inserting
   *        the string
   * @param line the line to insert
   */
public void setCurrentLine(final int pos, final int skip, final String line) {
    final Element element = getParagraphElement(pos);
    final int start = element.getStartOffset();
    final int end = element.getEndOffset();
    try {
        remove(start + skip, end - (start + skip + 1));
        super.insertString(start + skip, line, normal);
    } catch (final BadLocationException e) {
        System.out.println("Bad location!");
        e.printStackTrace();
    }
}
Also used : Element(javax.swing.text.Element) BadLocationException(javax.swing.text.BadLocationException)

Example 22 with Element

use of javax.swing.text.Element in project binnavi by google.

the class ConsoleHelpers method getCurrentLine.

/**
   * Get the text of the element containing the given position.
   * 
   * @param pos the global document position at which to find the element containing it.
   * @return the text contained within the element
   */
public String getCurrentLine(final int pos) {
    final Element element = document.getParagraphElement(pos);
    String line = "";
    try {
        line = document.getText(element.getStartOffset(), element.getEndOffset() - element.getStartOffset());
    } catch (final BadLocationException e) {
        System.out.println("Bad location!");
        e.printStackTrace();
    }
    return line;
}
Also used : Element(javax.swing.text.Element) BadLocationException(javax.swing.text.BadLocationException)

Example 23 with Element

use of javax.swing.text.Element in project binnavi by google.

the class TextHelpers method getLineAtCaret.

public static int getLineAtCaret(final JTextComponent component) {
    final int caretPosition = component.getCaretPosition();
    final Element root = component.getDocument().getDefaultRootElement();
    return root.getElementIndex(caretPosition) + 1;
}
Also used : Element(javax.swing.text.Element)

Example 24 with Element

use of javax.swing.text.Element in project android-classyshark by google.

the class BatchDocument method appendBatchLineFeed.

public void appendBatchLineFeed(AttributeSet a) {
    batch.add(new ElementSpec(a, ElementSpec.ContentType, EOL_ARRAY, 0, 1));
    Element paragraph = getParagraphElement(0);
    AttributeSet pattern = paragraph.getAttributes();
    batch.add(new ElementSpec(null, ElementSpec.EndTagType));
    batch.add(new ElementSpec(pattern, ElementSpec.StartTagType));
}
Also used : AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element)

Example 25 with Element

use of javax.swing.text.Element in project languagetool by languagetool-org.

the class ResultAreaHelper method appendMain.

private void appendMain(String html) {
    HTMLDocument d = (HTMLDocument) statusPane.getDocument();
    Element e = d.getElement(MAIN);
    try {
        d.insertBeforeEnd(e, html);
    } catch (BadLocationException ex) {
        Tools.showError(ex);
    } catch (IOException ex) {
        Tools.showError(ex);
    }
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Element(javax.swing.text.Element) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

Element (javax.swing.text.Element)40 BadLocationException (javax.swing.text.BadLocationException)15 Point (java.awt.Point)13 AttributeSet (javax.swing.text.AttributeSet)6 HTMLDocument (javax.swing.text.html.HTMLDocument)6 FontMetrics (java.awt.FontMetrics)4 Dimension (java.awt.Dimension)3 IOException (java.io.IOException)3 Document (javax.swing.text.Document)3 TreePath (javax.swing.tree.TreePath)3 ExtendedHTMLDocument (gmgen.gui.ExtendedHTMLDocument)2 Font (java.awt.Font)2 Insets (java.awt.Insets)2 Rectangle (java.awt.Rectangle)2 Accessible (javax.accessibility.Accessible)2 JTextComponent (javax.swing.text.JTextComponent)2 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1