Search in sources :

Example 81 with Document

use of javax.swing.text.Document in project Spark by igniterealtime.

the class ChatInputEditor method insertText.

/**
 * Inserts text into the current document at the current caret position.
 *
 * @param text the text to insert
 * @throws BadLocationException if the location is not available for insertion.
 */
public void insertText(String text) throws BadLocationException {
    final Document doc = getDocument();
    doc.insertString(this.getCaret().getDot(), text, null);
}
Also used : Document(javax.swing.text.Document)

Example 82 with Document

use of javax.swing.text.Document in project Spark by igniterealtime.

the class HorizontalLineEntry method addTo.

@Override
protected void addTo(ChatArea chatArea) throws BadLocationException {
    final Document doc = chatArea.getDocument();
    chatArea.insertComponent(new JSeparator());
    doc.insertString(doc.getLength(), "\n", null);
// Enabling the 'setCaretPosition' line below causes Spark to freeze (often, not always) when trying to print the subject of a chatroom that's just being loaded.
// chatArea.setCaretPosition( doc.getLength() );
}
Also used : Document(javax.swing.text.Document)

Example 83 with Document

use of javax.swing.text.Document in project processing by processing.

the class DetailPanel method setSelectionStyle.

static void setSelectionStyle(JTextPane textPane, boolean selected) {
    Document doc = textPane.getDocument();
    if (doc instanceof HTMLDocument) {
        HTMLDocument html = (HTMLDocument) doc;
        StyleSheet styleSheet = html.getStyleSheet();
        if (selected) {
            styleSheet.addRule("a { text-decoration:underline } ");
        } else {
            styleSheet.addRule("a { text-decoration:none }");
        }
    }
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document)

Example 84 with Document

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

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 85 with Document

use of javax.swing.text.Document in project android by JetBrains.

the class SelectionEditors method createDocumentListener.

/**
   * Create a document listener that will update the {@link MockupViewPanel} selection
   * when the attached document is updated.
   *
   * @return the new document listener
   */
private DocumentListener createDocumentListener() {
    return new DocumentListener() {

        private void processChange(@NotNull DocumentEvent e) {
            if (myBoundsUpdating) {
                return;
            }
            try {
                Document document = e.getDocument();
                int value;
                if (document.getLength() <= 0) {
                    value = 0;
                } else {
                    value = Integer.parseInt(document.getText(0, document.getLength()));
                }
                SelectionLayer selectionLayer = myMockupViewPanel.getSelectionLayer();
                Rectangle selection = selectionLayer.getSelection();
                if (document == myBoundsDocuments[W]) {
                    selectionLayer.setSelection(selection.x, selection.y, value, selection.height);
                } else if (document == myBoundsDocuments[H]) {
                    selectionLayer.setSelection(selection.x, selection.y, selection.width, value);
                } else if (document == myBoundsDocuments[X]) {
                    selectionLayer.setSelection(value, selection.y, selection.width, selection.height);
                } else if (document == myBoundsDocuments[Y]) {
                    selectionLayer.setSelection(selection.x, value, selection.width, selection.height);
                }
            } catch (BadLocationException | NumberFormatException ex) {
            // Do nothing
            }
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            processChange(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            processChange(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    };
}
Also used : DocumentListener(javax.swing.event.DocumentListener) SelectionLayer(com.android.tools.idea.uibuilder.mockup.editor.SelectionLayer) DocumentEvent(javax.swing.event.DocumentEvent) Document(javax.swing.text.Document) NotNull(org.jetbrains.annotations.NotNull) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

Document (javax.swing.text.Document)170 BadLocationException (javax.swing.text.BadLocationException)85 DocumentEvent (javax.swing.event.DocumentEvent)15 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)15 HTMLDocument (javax.swing.text.html.HTMLDocument)15 Element (javax.swing.text.Element)14 AbstractDocument (javax.swing.text.AbstractDocument)11 StringReader (java.io.StringReader)10 PlainDocument (javax.swing.text.PlainDocument)10 DocumentAdapter (com.intellij.ui.DocumentAdapter)8 Matcher (java.util.regex.Matcher)8 JTextComponent (javax.swing.text.JTextComponent)8 ActionEvent (java.awt.event.ActionEvent)7 DocumentListener (javax.swing.event.DocumentListener)7 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)7 IOException (java.io.IOException)6 PatternSyntaxException (java.util.regex.PatternSyntaxException)6 Highlighter (javax.swing.text.Highlighter)5 FieldDefinition (com.revolsys.record.schema.FieldDefinition)4 Point (java.awt.Point)4