Search in sources :

Example 16 with BadLocationException

use of javax.swing.text.BadLocationException in project zaproxy by zaproxy.

the class HttpPanelSyntaxHighlightTextArea method highlight.

protected void highlight(int start, int end) {
    Highlighter hilite = this.getHighlighter();
    HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY);
    try {
        // DOBIN
        removeAllHighlights();
        hilite.addHighlight(start, end, painter);
        this.setCaretPosition(start);
    } catch (BadLocationException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : HighlightPainter(javax.swing.text.Highlighter.HighlightPainter) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 17 with BadLocationException

use of javax.swing.text.BadLocationException in project pcgen by PCGen.

the class InfoPane method setText.

public void setText(String text) {
    //This is done so the vertical scroll bar goes back up to the top when the text is changed
    EditorKit kit = textPane.getEditorKit();
    Document newDoc = kit.createDefaultDocument();
    try {
        kit.read(new StringReader(text), newDoc, 0);
    } catch (IOException | BadLocationException ex) {
        throw new UnreachableError(ex);
    }
    textPane.setDocument(newDoc);
}
Also used : EditorKit(javax.swing.text.EditorKit) StringReader(java.io.StringReader) IOException(java.io.IOException) UnreachableError(pcgen.base.lang.UnreachableError) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Example 18 with BadLocationException

use of javax.swing.text.BadLocationException in project yyl_example by Relucent.

the class Command method registerListener.

private void registerListener() {
    txtDebug.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == 8 && execOffset >= doc.getLength()) {
                e.setKeyCode(27);
            }
            if (e.getKeyCode() == 10 && execOffset < doc.getLength()) {
                try {
                    String str = doc.getText(execOffset, doc.getLength() - execOffset);
                    exec(str + "\n");
                } catch (BadLocationException ex) {
                    ex.printStackTrace();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }

        public void keyTyped(KeyEvent e) {
        // System.out.println(e.getKeyChar());
        }
    });
    doc.addDocumentListener(new DocumentListener() {

        public void changedUpdate(DocumentEvent e) {
        }

        public void insertUpdate(DocumentEvent e) {
        }

        public void removeUpdate(DocumentEvent e) {
        }
    });
    txtDebug.addCaretListener(new CaretListener() {

        public void caretUpdate(CaretEvent e) {
            if (execOffset > caret.getMark() || execOffset > caret.getDot()) {
                caret.setDot(execOffset);
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) CaretEvent(javax.swing.event.CaretEvent) DocumentListener(javax.swing.event.DocumentListener) CaretListener(javax.swing.event.CaretListener) KeyAdapter(java.awt.event.KeyAdapter) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent) BadLocationException(javax.swing.text.BadLocationException)

Example 19 with BadLocationException

use of javax.swing.text.BadLocationException in project pcgen by PCGen.

the class NotesView method handleEnter.

private void handleEnter() {
    // TODO: this sucks.  clean it up
    Element elem;
    int pos = editor.getCaretPosition();
    ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument();
    try {
        if (ExtendedHTMLEditorKit.checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.UL) || ExtendedHTMLEditorKit.checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.OL)) {
            elem = ExtendedHTMLEditorKit.getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition()));
            int so = elem.getStartOffset();
            int eo = elem.getEndOffset();
            char[] temp = editor.getText(so, eo - so).toCharArray();
            boolean content = false;
            for (char aTemp : temp) {
                if (!Character.isWhitespace(aTemp)) {
                    content = true;
                }
            }
            int repos = -1;
            if (content) {
                int end = -1;
                int j = temp.length;
                do {
                    j--;
                    if (Character.isLetterOrDigit(temp[j])) {
                        end = j;
                    }
                } while ((end == -1) && (j >= 0));
                j = end;
                do {
                    j++;
                    if (!Character.isSpaceChar(temp[j])) {
                        repos = j - end - 1;
                    }
                } while ((repos == -1) && (j < temp.length));
                if (repos == -1) {
                    repos = 0;
                }
            }
            if ((elem.getStartOffset() == elem.getEndOffset()) || !content) {
                manageListElement(htmlDoc);
            } else {
                if ((editor.getCaretPosition() + 1) == elem.getEndOffset()) {
                    ExtendedHTMLEditorKit.insertListElement(editor, "");
                    editor.setCaretPosition(pos - repos);
                } else {
                    int caret = editor.getCaretPosition();
                    String tempString = editor.getText(caret, eo - caret);
                    editor.select(caret, eo - 1);
                    editor.replaceSelection("");
                    ExtendedHTMLEditorKit.insertListElement(editor, tempString);
                    Element newLi = ExtendedHTMLEditorKit.getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition()));
                    editor.setCaretPosition(newLi.getEndOffset());
                }
            }
        }
    } catch (BadLocationException ble) {
        Logging.errorPrint(ble.getMessage(), ble);
    }
}
Also used : ExtendedHTMLDocument(gmgen.gui.ExtendedHTMLDocument) Element(javax.swing.text.Element) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Example 20 with BadLocationException

use of javax.swing.text.BadLocationException in project intellij-community by JetBrains.

the class RequiredAttributesInspection method createOptionsPanel.

@Override
@Nullable
public JComponent createOptionsPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    FieldPanel additionalAttributesPanel = new FieldPanel(InspectionsBundle.message("inspection.javadoc.html.not.required.label.text"), InspectionsBundle.message("inspection.javadoc.html.not.required.dialog.title"), null, null);
    panel.add(additionalAttributesPanel, BorderLayout.NORTH);
    additionalAttributesPanel.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            final Document document = e.getDocument();
            try {
                final String text = document.getText(0, document.getLength());
                if (text != null) {
                    myAdditionalRequiredHtmlAttributes = text.trim();
                }
            } catch (BadLocationException e1) {
                LOG.error(e1);
            }
        }
    });
    additionalAttributesPanel.setText(myAdditionalRequiredHtmlAttributes);
    return panel;
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) Document(javax.swing.text.Document) FieldPanel(com.intellij.ui.FieldPanel) BadLocationException(javax.swing.text.BadLocationException) Nullable(org.jetbrains.annotations.Nullable)

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