Search in sources :

Example 41 with BadLocationException

use of javax.swing.text.BadLocationException 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 42 with BadLocationException

use of javax.swing.text.BadLocationException 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 43 with BadLocationException

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

the class DisplayArea method displaySharkey.

@Override
public void displaySharkey() {
    displayDataState = DisplayDataState.SHARKEY;
    clearText();
    style = jTextPane.addStyle("STYLE", null);
    Document doc = jTextPane.getStyledDocument();
    try {
        StyleConstants.setForeground(style, theme.getIdentifiersColor());
        StyleConstants.setFontSize(style, 13);
        StyleConstants.setFontFamily(style, "Menlo");
        doc.insertString(doc.getLength(), Doodle.get(), style);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    jTextPane.setDocument(doc);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 44 with BadLocationException

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

the class DisplayArea method displaySearchResults.

@Override
public void displaySearchResults(List<String> filteredClassNames, List<Translator.ELEMENT> displayedManifestSearchResultsTokens, String textFromTypingArea) {
    displayDataState = DisplayDataState.CLASSES_LIST;
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, theme.getIdentifiersColor());
    clearText();
    Document doc = new DefaultStyledDocument();
    jTextPane.setDocument(doc);
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setBackground(style, theme.getBackgroundColor());
    fillTokensToDoc(displayedManifestSearchResultsTokens, doc, true);
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, theme.getIdentifiersColor());
    StyleConstants.setBackground(style, theme.getBackgroundColor());
    int displayedClassLimit = 50;
    if (filteredClassNames.size() < displayedClassLimit) {
        displayedClassLimit = filteredClassNames.size();
    }
    for (int i = 0; i < displayedClassLimit; i++) {
        try {
            doc.insertString(doc.getLength(), filteredClassNames.get(i) + "\n", style);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
    jTextPane.setDocument(doc);
    jTextPane.setCaretPosition(1);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 45 with BadLocationException

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

the class DisplayArea method displayClassNames.

@Override
public void displayClassNames(List<String> classNamesToShow, String inputText) {
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, theme.getIdentifiersColor());
    StyleConstants.setBackground(style, theme.getBackgroundColor());
    if (classNamesToShow.size() > 50) {
        displayAllClassesNames(classNamesToShow);
        return;
    }
    displayDataState = DisplayDataState.CLASSES_LIST;
    clearText();
    int matchIndex;
    String beforeMatch = "";
    String match;
    String afterMatch = "";
    Document doc = jTextPane.getDocument();
    for (String className : classNamesToShow) {
        matchIndex = className.indexOf(inputText);
        if (matchIndex > -1) {
            beforeMatch = className.substring(0, matchIndex);
            match = className.substring(matchIndex, matchIndex + inputText.length());
            afterMatch = className.substring(matchIndex + inputText.length(), className.length());
        } else {
            // we are here by camel match
            // i.e. 2-3 letters that fits
            // to class name
            match = className;
        }
        try {
            doc.insertString(doc.getLength(), beforeMatch, style);
            StyleConstants.setBackground(style, theme.getSelectionBgColor());
            doc.insertString(doc.getLength(), match, style);
            StyleConstants.setBackground(style, theme.getBackgroundColor());
            doc.insertString(doc.getLength(), afterMatch + "\n", style);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }
    jTextPane.setDocument(doc);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) 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