Example usage for javax.swing.text BadLocationException printStackTrace

List of usage examples for javax.swing.text BadLocationException printStackTrace

Introduction

In this page you can find the example usage for javax.swing.text BadLocationException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.owasp.jbrofuzz.ui.viewers.WindowViewerFrame.java

private void search() {
    hilit.removeAllHighlights();//from   w  w w.ja v  a 2s .com

    final String s = entry.getText();
    if (s.length() <= 0) {
        message("Nothing to search");
        return;
    }

    try {
        final String content = listTextArea.getDocument().getText(0, listTextArea.getDocument().getLength());
        int index = content.indexOf(s, 0);

        if (lastIndex != 0 && lastIndex >= index) {
            final int tempIndex = content.indexOf(s, lastIndex + 1);
            index = tempIndex;
        }

        if (index >= 0) { // match found
            final int end = index + s.length();
            hilit.addHighlight(index, end, painter);
            listTextArea.setCaretPosition(index);
            entry.setBackground(entryBg);
            message("Phrase found: '" + s + "'");
            lastIndex = index;
        } else if (lastIndex > 0) {
            entry.setBackground(ERROR_COLOR);
            message("End reached. Starting from top again...");
            lastIndex = 0;
        } else {
            entry.setBackground(ERROR_COLOR);
            message("Phrase not found...");
        }

    } catch (final BadLocationException e) {
        e.printStackTrace();
    }

}

From source file:org.paxle.desktop.impl.event.MultipleChangesListener.java

private void setState(final Object comp, final long when, final boolean init) {
    if (comp instanceof Document) {
        final Document doc = (Document) comp;
        try {/*  w  ww  .  j  a va 2  s  .  c o  m*/
            setState(doc, doc.getText(0, doc.getLength()), when, init);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    } else {
        final Class<?> clazz = comp.getClass();
        final int eidx = getEntryIndex(clazz);
        if (eidx < 0)
            throw new RuntimeException(
                    "component '" + comp.getClass().getName() + "' not supported for monitoring");
        try {
            setState(comp, clazz.getMethod(GET_VALUES[eidx]).invoke(comp), when, init);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.rdv.ui.ConsoleDialog.java

private void pruneOldMessages() {
    // prune old messages
    try {//from w w w.j  a  v  a  2 s.  c o  m
        String textString = textArea.getDocument().getText(0, textArea.getDocument().getLength());
        int lineCount = 0;
        for (int i = textString.length() - 1; i >= 0; i--) {
            if (textString.charAt(i) == '\n') {
                if (++lineCount > messageLimit) {
                    // delete old lines
                    textArea.replaceRange("", 0, i + 1);
                    break;
                }
            }
        }
    } catch (BadLocationException ble) {
        ble.printStackTrace();
    }
}

From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java

private JButton getRemoveCustomButton() {
    if (removeCustomButton == null) {
        removeCustomButton = new JButton(Constant.messages.getString("customFire.custom.button.pt.rem"));
        removeCustomButton.setEnabled(false);

        removeCustomButton.addActionListener(new java.awt.event.ActionListener() {
            @Override//w  w  w  . j ava  2  s.c  o  m
            public void actionPerformed(java.awt.event.ActionEvent e) {
                // Remove any selected injection points
                int userDefStart = getRequestField().getSelectionStart();
                if (userDefStart >= 0) {
                    int userDefEnd = getRequestField().getSelectionEnd();
                    Highlighter hltr = getRequestField().getHighlighter();
                    Highlight[] hls = hltr.getHighlights();

                    if (hls != null && hls.length > 0) {
                        for (Highlight hl : hls) {
                            if (selectionIncludesHighlight(userDefStart, userDefEnd, hl)) {
                                try {
                                    int i = list.indexOf(
                                            "[" + userDefStart + "," + userDefEnd + "]:" + getRequestField()
                                                    .getText(userDefStart, userDefEnd - userDefStart));
                                    list.remove(i);
                                } catch (BadLocationException e1) {
                                    e1.printStackTrace();
                                }
                                hltr.removeHighlight(hl);
                                injectionPointModel.removeElement(hl);
                            }
                        }
                    }

                    // Unselect the text
                    getRequestField().setSelectionStart(userDefEnd);
                    getRequestField().setSelectionEnd(userDefEnd);
                    getRequestField().getCaret().setVisible(true);
                }
            }
        });
    }

    return removeCustomButton;
}

From source file:pl.otros.logview.gui.actions.search.SearchAction.java

private void scrollToSearchResult(ArrayList<String> toHighlight, JTextPane textPane) {
    if (toHighlight.size() == 0) {
        return;//  w w  w. j av a  2  s. co  m
    }
    try {
        StyledDocument logDetailsDocument = textPane.getStyledDocument();
        String text = logDetailsDocument.getText(0, logDetailsDocument.getLength());
        String string = toHighlight.get(0);
        textPane.setCaretPosition(Math.max(text.indexOf(string), 0));
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}

From source file:processing.app.Editor.java

/**
 * Switch between tabs, this swaps out the Document object
 * that's currently being manipulated.//www.j  a  v  a  2 s . co  m
 */
protected void setCode(final SketchCodeDocument codeDoc) {
    RSyntaxDocument document = (RSyntaxDocument) codeDoc.getDocument();

    if (document == null) { // this document not yet inited
        document = new RSyntaxDocument(new ArduinoTokenMakerFactory(base.getPdeKeywords()),
                RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS);
        document.putProperty(PlainDocument.tabSizeAttribute, PreferencesData.getInteger("editor.tabs.size"));

        // insert the program text into the document object
        try {
            document.insertString(0, codeDoc.getCode().getProgram(), null);
        } catch (BadLocationException bl) {
            bl.printStackTrace();
        }
        // set up this guy's own undo manager
        //      code.undo = new UndoManager();

        codeDoc.setDocument(document);
    }

    if (codeDoc.getUndo() == null) {
        codeDoc.setUndo(new LastUndoableEditAwareUndoManager(textarea, this));
        document.addUndoableEditListener(codeDoc.getUndo());
    }

    // Update the document object that's in use
    textarea.switchDocument(document, codeDoc.getUndo());

    // HACK multiple tabs: for update Listeners of Gutter, forcin call: Gutter.setTextArea(RTextArea)
    // BUG: https://github.com/bobbylight/RSyntaxTextArea/issues/84
    scrollPane.setViewportView(textarea);

    textarea.select(codeDoc.getSelectionStart(), codeDoc.getSelectionStop());
    textarea.requestFocus(); // get the caret blinking

    final int position = codeDoc.getScrollPosition();

    // invokeLater: Expect the document to be rendered correctly to set the new position
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            scrollPane.getVerticalScrollBar().setValue(position);
            undoAction.updateUndoState();
            redoAction.updateRedoState();
        }
    });

}

From source file:processing.app.Editor.java

protected String getCurrentKeyword() {
    String text = "";
    if (textarea.getSelectedText() != null)
        text = textarea.getSelectedText().trim();

    try {/*  www .  j a  va  2 s.  c  o m*/
        int current = textarea.getCaretPosition();
        int startOffset = 0;
        int endIndex = current;
        String tmp = textarea.getDocument().getText(current, 1);
        // TODO probably a regexp that matches Arduino lang special chars
        // already exists.
        String regexp = "[\\s\\n();\\\\.!='\\[\\]{}]";

        while (!tmp.matches(regexp)) {
            endIndex++;
            tmp = textarea.getDocument().getText(endIndex, 1);
        }
        // For some reason document index start at 2.
        // if( current - start < 2 ) return;

        tmp = "";
        while (!tmp.matches(regexp)) {
            startOffset++;
            if (current - startOffset < 0) {
                tmp = textarea.getDocument().getText(0, 1);
                break;
            } else
                tmp = textarea.getDocument().getText(current - startOffset, 1);
        }
        startOffset--;

        int length = endIndex - current + startOffset;
        text = textarea.getDocument().getText(current - startOffset, length);

    } catch (BadLocationException bl) {
        bl.printStackTrace();
    }
    return text;
}

From source file:processing.app.Editor.java

/**
 * Show an exception in the editor status bar.
 *///from  www .  j  a  va2 s.co m
public void statusError(Exception e) {
    e.printStackTrace();
    //    if (e == null) {
    //      System.err.println("Editor.statusError() was passed a null exception.");
    //      return;
    //    }

    if (e instanceof RunnerException) {
        RunnerException re = (RunnerException) e;
        if (re.hasCodeIndex()) {
            sketch.setCurrentCode(re.getCodeIndex());
        }
        if (re.hasCodeLine()) {
            int line = re.getCodeLine();
            // subtract one from the end so that the \n ain't included
            if (line >= textarea.getLineCount()) {
                // The error is at the end of this current chunk of code,
                // so the last line needs to be selected.
                line = textarea.getLineCount() - 1;
                if (getLineText(line).length() == 0) {
                    // The last line may be zero length, meaning nothing to select.
                    // If so, back up one more line.
                    line--;
                }
            }
            if (line < 0 || line >= textarea.getLineCount()) {
                System.err.println(I18n.format(_("Bad error line: {0}"), line));
            } else {
                try {
                    textarea.addLineHighlight(line, new Color(1, 0, 0, 0.2f));
                    textarea.setCaretPosition(textarea.getLineStartOffset(line));
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }

    // Since this will catch all Exception types, spend some time figuring
    // out which kind and try to give a better error message to the user.
    String mess = e.getMessage();
    if (mess != null) {
        String javaLang = "java.lang.";
        if (mess.indexOf(javaLang) == 0) {
            mess = mess.substring(javaLang.length());
        }
        String rxString = "RuntimeException: ";
        if (mess.indexOf(rxString) == 0) {
            mess = mess.substring(rxString.length());
        }
        statusError(mess);
    }
    //    e.printStackTrace();
}

From source file:processing.app.EditorTab.java

private RSyntaxDocument createDocument(String contents) {
    RSyntaxDocument document = new RSyntaxDocument(new ArduinoTokenMakerFactory(editor.base.getPdeKeywords()),
            RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS);
    document.putProperty(PlainDocument.tabSizeAttribute, PreferencesData.getInteger("editor.tabs.size"));

    // insert the program text into the document object
    try {/*from   w  ww . ja  va  2s . com*/
        document.insertString(0, contents, null);
    } catch (BadLocationException bl) {
        bl.printStackTrace();
    }
    document.addDocumentListener(new DocumentTextChangeListener(() -> setModified(true)));
    return document;
}

From source file:processing.app.EditorTab.java

public String getCurrentKeyword() {
    String text = "";
    if (textarea.getSelectedText() != null)
        text = textarea.getSelectedText().trim();

    try {/*from  w  ww  .  j  a v a  2  s. c  o m*/
        int current = textarea.getCaretPosition();
        int startOffset = 0;
        int endIndex = current;
        String tmp = textarea.getDocument().getText(current, 1);
        // TODO probably a regexp that matches Arduino lang special chars
        // already exists.
        String regexp = "[\\s\\n();\\\\.!='\\[\\]{}]";

        while (!tmp.matches(regexp)) {
            endIndex++;
            tmp = textarea.getDocument().getText(endIndex, 1);
        }
        // For some reason document index start at 2.
        // if( current - start < 2 ) return;

        tmp = "";
        while (!tmp.matches(regexp)) {
            startOffset++;
            if (current - startOffset < 0) {
                tmp = textarea.getDocument().getText(0, 1);
                break;
            } else
                tmp = textarea.getDocument().getText(current - startOffset, 1);
        }
        startOffset--;

        int length = endIndex - current + startOffset;
        text = textarea.getDocument().getText(current - startOffset, length);

    } catch (BadLocationException bl) {
        bl.printStackTrace();
    }
    return text;
}