Search in sources :

Example 51 with BadLocationException

use of javax.swing.text.BadLocationException in project antlrworks by antlr.

the class EditorTips method display.

public void display(Point relativePoint, Point absolutePoint) {
    if (window.getTokens() == null)
        return;
    int position = window.getTextPane().viewToModel(relativePoint);
    Point p = null;
    try {
        ATEToken token = window.getTokenAtPosition(position, false);
        if (token != null) {
            // Make sure the mouse is over the token because
            // Swing will return a valid position even if the mouse
            // is on the remaining blank part of the line
            Rectangle r1 = window.getTextPane().modelToView(token.getStartIndex());
            Rectangle r2 = window.getTextPane().modelToView(token.getEndIndex());
            if (r1.union(r2).contains(relativePoint)) {
                p = SwingUtilities.convertPoint(window.getTextPane(), new Point(relativePoint.x + 2, r2.y - 5), window.getJavaContainer());
            }
        }
    } catch (BadLocationException e) {
    // Ignore
    }
    tipsManager.displayAnyTipsAvailable(position, p);
}
Also used : ATEToken(org.antlr.works.ate.syntax.misc.ATEToken) BadLocationException(javax.swing.text.BadLocationException)

Example 52 with BadLocationException

use of javax.swing.text.BadLocationException in project groovy by apache.

the class LexerFrame method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    Token token = (Token) ((JComponent) ae.getSource()).getClientProperty("token");
    if (token.getType() == Token.EOF_TYPE) {
        scriptPane.select(0, 0);
        return;
    }
    try {
        int start = scriptPane.getLineStartOffset(token.getLine() - 1) + token.getColumn() - 1;
        scriptPane.select(start, start + token.getText().length());
        scriptPane.requestFocus();
    } catch (BadLocationException ex) {
    // IGNORE
    }
}
Also used : Token(antlr.Token) BadLocationException(javax.swing.text.BadLocationException)

Example 53 with BadLocationException

use of javax.swing.text.BadLocationException in project LogisticsPipes by RS485.

the class LogWindow method newLine.

public void newLine(String data) {
    SimpleAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attr, "SansSerif");
    StyleConstants.setFontSize(attr, 12);
    // StyleConstants.setForeground(attr, color);
    Document document = logArea.getDocument();
    if (document != null) {
        try {
            document.insertString(document.getLength(), data + "\n", attr);
        } catch (BadLocationException badlocationexception) {
        }
    }
    validate();
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 54 with BadLocationException

use of javax.swing.text.BadLocationException in project LogisticsPipes by RS485.

the class DebugWindow method showInfo.

public void showInfo(String data, Color color) {
    SimpleAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attr, "SansSerif");
    StyleConstants.setFontSize(attr, 12);
    StyleConstants.setForeground(attr, color);
    Document document = textArea.getDocument();
    if (document != null) {
        try {
            document.insertString(document.getLength(), data, attr);
        } catch (BadLocationException badlocationexception) {
        }
    }
    getContentPane().validate();
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 55 with BadLocationException

use of javax.swing.text.BadLocationException in project SKMCLauncher by SKCraft.

the class LimitLinesDocumentListener method removeFromEnd.

private void removeFromEnd(Document document, Element root) {
    // We use start minus 1 to make sure we remove the newline
    // character of the previous line
    Element line = root.getElement(root.getElementCount() - 1);
    int start = line.getStartOffset();
    int end = line.getEndOffset();
    try {
        document.remove(start - 1, end - start);
    } catch (BadLocationException ble) {
        System.out.println(ble);
    }
}
Also used : Element(javax.swing.text.Element) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

BadLocationException (javax.swing.text.BadLocationException)88 Document (javax.swing.text.Document)24 Element (javax.swing.text.Element)13 Point (java.awt.Point)10 IOException (java.io.IOException)9 DefaultHighlighter (javax.swing.text.DefaultHighlighter)8 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)7 Highlighter (javax.swing.text.Highlighter)7 ArrayList (java.util.ArrayList)6 DocumentEvent (javax.swing.event.DocumentEvent)6 StyledDocument (javax.swing.text.StyledDocument)6 HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)5 Dimension (java.awt.Dimension)4 Rectangle (java.awt.Rectangle)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 File (java.io.File)4 Date (java.util.Date)4 Style (javax.swing.text.Style)4 HTMLDocument (javax.swing.text.html.HTMLDocument)4