Search in sources :

Example 6 with Document

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

the class AutoCompletionMenu method completePartialWord.

public void completePartialWord(String word) {
    try {
        Document doc = getTextComponent().getDocument();
        doc.remove(insertionStartIndex, insertionEndIndex - insertionStartIndex);
        doc.insertString(insertionStartIndex, word, null);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
Also used : Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 7 with Document

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

the class DisplayArea method displayClass.

// TODO add here logic fo highlighter
// TODO by adding flag to Translator.ELEMENT
@Override
public void displayClass(List<Translator.ELEMENT> elements, String key) {
    displayDataState = DisplayDataState.INSIDE_CLASS;
    clearText();
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setBackground(style, theme.getBackgroundColor());
    Document doc = new DefaultStyledDocument();
    fillTokensToDoc(elements, doc, false);
    StyleConstants.setForeground(style, theme.getIdentifiersColor());
    jTextPane.setDocument(doc);
    int i = calcScrollingPosition(key);
    jTextPane.setCaretPosition(i);
}
Also used : DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument)

Example 8 with Document

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

the class DisplayArea method displayClass.

@Override
public void displayClass(String classString) {
    displayDataState = DisplayDataState.INSIDE_CLASS;
    try {
        String currentText = jTextPane.getDocument().getText(0, jTextPane.getDocument().getLength());
        if (currentText.equals(getOneColorFormattedOutput(classString))) {
            return;
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    clearText();
    StyleConstants.setFontSize(style, 18);
    Document doc = new DefaultStyledDocument();
    try {
        doc.insertString(doc.getLength(), getOneColorFormattedOutput(classString), 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 9 with Document

use of javax.swing.text.Document in project groovy-core by groovy.

the class FindReplaceUtility method findNext.

/**
     * Find and select the next searchable matching text.
     *
     * @param reverse look forwards or backwards
     * @param pos     the starting index to start finding from
     * @return the location of the next selected, or -1 if not found
     */
private static int findNext(boolean reverse, int pos) {
    boolean backwards = IS_BACKWARDS_CHECKBOX.isSelected();
    backwards = backwards ? !reverse : reverse;
    String pattern = (String) FIND_FIELD.getSelectedItem();
    if (pattern != null && pattern.length() > 0) {
        try {
            Document doc = textComponent.getDocument();
            doc.getText(0, doc.getLength(), SEGMENT);
        } catch (Exception e) {
            // should NEVER reach here
            e.printStackTrace();
        }
        pos += textComponent.getSelectedText() == null ? (backwards ? -1 : 1) : 0;
        char first = backwards ? pattern.charAt(pattern.length() - 1) : pattern.charAt(0);
        char oppFirst = Character.isUpperCase(first) ? Character.toLowerCase(first) : Character.toUpperCase(first);
        int start = pos;
        boolean wrapped = WRAP_SEARCH_CHECKBOX.isSelected();
        int end = backwards ? 0 : SEGMENT.getEndIndex();
        pos += backwards ? -1 : 1;
        int length = textComponent.getDocument().getLength();
        if (pos > length) {
            pos = wrapped ? 0 : length;
        }
        boolean found = false;
        while (!found && (backwards ? pos > end : pos < end)) {
            found = !MATCH_CASE_CHECKBOX.isSelected() && SEGMENT.array[pos] == oppFirst;
            found = found ? found : SEGMENT.array[pos] == first;
            if (found) {
                pos += backwards ? -(pattern.length() - 1) : 0;
                for (int i = 0; found && i < pattern.length(); i++) {
                    char c = pattern.charAt(i);
                    found = SEGMENT.array[pos + i] == c;
                    if (!MATCH_CASE_CHECKBOX.isSelected() && !found) {
                        c = Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c);
                        found = SEGMENT.array[pos + i] == c;
                    }
                }
            }
            if (!found) {
                pos += backwards ? -1 : 1;
                if (pos == end && wrapped) {
                    pos = backwards ? SEGMENT.getEndIndex() : 0;
                    end = start;
                    wrapped = false;
                }
            }
        }
        pos = found ? pos : -1;
    }
    return pos;
}
Also used : Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 10 with Document

use of javax.swing.text.Document in project OpenAM by OpenRock.

the class TableJPanel method clearAll.

public void clearAll() {
    testsjTable.setEnabled(false);
    TestsTableModel model = (TestsTableModel) testsjTable.getModel();
    model.removeAll();
    Document doc = messagejEditorPane.getDocument();
    try {
        doc.remove(0, doc.getLength());
    } catch (Exception ex) {
        //ex.printStackTrace();
        System.out.println("Exception in TableJPanel :" + ex.getMessage());
    }
    testsjTable.setEnabled(true);
}
Also used : TestsTableModel(com.sun.identity.diagnostic.base.core.ui.gui.table.TestsTableModel) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document)

Aggregations

Document (javax.swing.text.Document)64 BadLocationException (javax.swing.text.BadLocationException)29 DocumentEvent (javax.swing.event.DocumentEvent)10 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)8 DocumentAdapter (com.intellij.ui.DocumentAdapter)7 HTMLDocument (javax.swing.text.html.HTMLDocument)7 ActionEvent (java.awt.event.ActionEvent)5 PlainDocument (javax.swing.text.PlainDocument)5 ActionListener (java.awt.event.ActionListener)4 File (java.io.File)3 IOException (java.io.IOException)3 DocumentListener (javax.swing.event.DocumentListener)3 Element (javax.swing.text.Element)3 FieldPanel (com.intellij.ui.FieldPanel)2 CheckBox (com.intellij.util.ui.CheckBox)2 NumberFormat (java.text.NumberFormat)2 ParseException (java.text.ParseException)2 AbstractAction (javax.swing.AbstractAction)2 AbstractDocument (javax.swing.text.AbstractDocument)2 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2