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:TextFieldDemo.java

public void search() {
    hilit.removeAllHighlights();/*from w  w  w .  ja v a2 s . c  o  m*/

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

    String content = textArea.getText();
    int index = content.indexOf(s, 0);
    if (index >= 0) { // match found
        try {
            int end = index + s.length();
            hilit.addHighlight(index, end, painter);
            textArea.setCaretPosition(end);
            entry.setBackground(entryBg);
            message("'" + s + "' found. Press ESC to end search");
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    } else {
        entry.setBackground(ERROR_COLOR);
        message("'" + s + "' not found. Press ESC to start a new search");
    }
}

From source file:com.mirth.connect.client.ui.components.rsta.ac.js.MirthSourceCompletionProvider.java

@Override
public List<Completion> getCompletionsAt(JTextComponent tc, Point p) {
    Set<Completion> completions = new HashSet<Completion>();
    List<Completion> parentCompletions = super.getCompletionsAt(tc, p);
    if (CollectionUtils.isNotEmpty(parentCompletions)) {
        completions.addAll(parentCompletions);
    }/*ww w .  j a  v a 2  s  .  co  m*/

    int offset = tc.viewToModel(p);
    if (offset < 0 || offset >= tc.getDocument().getLength()) {
        lastCompletionsAtText = null;
        lastParameterizedCompletionsAt = null;
        return new ArrayList<Completion>(completions);
    }

    Segment s = new Segment();
    Document doc = tc.getDocument();
    Element root = doc.getDefaultRootElement();
    int line = root.getElementIndex(offset);
    Element elem = root.getElement(line);
    int start = elem.getStartOffset();
    int end = elem.getEndOffset() - 1;

    try {

        doc.getText(start, end - start, s);

        // Get the valid chars before the specified offset.
        int startOffs = s.offset + (offset - start) - 1;
        while (startOffs >= s.offset && Character.isLetterOrDigit(s.array[startOffs])) {
            startOffs--;
        }

        // Get the valid chars at and after the specified offset.
        int endOffs = s.offset + (offset - start);
        while (endOffs < s.offset + s.count && Character.isLetterOrDigit(s.array[endOffs])) {
            endOffs++;
        }

        int len = endOffs - startOffs - 1;
        if (len <= 0) {
            lastParameterizedCompletionsAt = null;
            return new ArrayList<Completion>(completions);
        }
        String text = new String(s.array, startOffs + 1, len);

        if (text.equals(lastCompletionsAtText)) {
            if (CollectionUtils.isNotEmpty(lastParameterizedCompletionsAt)) {
                completions.addAll(lastParameterizedCompletionsAt);
            }
            return new ArrayList<Completion>(completions);
        }

        lastCompletionsAtText = text;
        lastParameterizedCompletionsAt = completionCache.getClassCompletions(tc, text);

        if (CollectionUtils.isNotEmpty(lastParameterizedCompletionsAt)) {
            completions.addAll(lastParameterizedCompletionsAt);
        }
        return new ArrayList<Completion>(completions);

    } catch (BadLocationException ble) {
        ble.printStackTrace(); // Never happens
    }

    lastCompletionsAtText = null;
    lastParameterizedCompletionsAt = null;

    return new ArrayList<Completion>(completions);
}

From source file:com.fedroot.dacs.swing.DacsNoticePresentationDialog.java

/**
 * Sets the HTML content to be displayed.
 *
 * @param content an HTML document string
 *///from w ww . ja va 2s.  co m
private void setDocumentContent(String contenttype, String content) {
    HTMLDocument doc = new HTMLDocument();
    try {
        doc.remove(0, doc.getLength());
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    // doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

    try {
        htmlpane.setContentType(contenttype);
        htmlpane.read(new ByteArrayInputStream(content.getBytes()), doc);
        htmlpane.setDocument(doc);
        htmlpane.setCaretPosition(0);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:es.uvigo.ei.sing.adops.views.TextFileViewer.java

private void updateSearch() {
    textArea.getHighlighter().removeAllHighlights();

    final String textToFind = txtSearch.getText();

    if (!textToFind.isEmpty()) {
        final String text = textArea.getText();

        if (this.chkRegularExpression.isSelected()) {
            try {
                final Pattern pattern = Pattern.compile(textToFind);
                this.txtSearch.setBackground(Color.WHITE);

                final Matcher matcher = pattern.matcher(text);

                while (matcher.find()) {
                    try {
                        textArea.getHighlighter().addHighlight(matcher.start(), matcher.end(),
                                highlightPatiner);
                    } catch (BadLocationException e1) {
                        e1.printStackTrace();
                    }/* w w w  .  j  a  v a2 s. c o  m*/
                }
            } catch (PatternSyntaxException pse) {
                this.txtSearch.setBackground(Color.RED);
            }
        } else {
            final int textToFindLength = textToFind.length();

            int index = 0;
            while ((index = text.indexOf(textToFind, index)) != -1) {
                try {
                    textArea.getHighlighter().addHighlight(index, index + textToFindLength, highlightPatiner);
                    index += textToFindLength + 1;
                } catch (BadLocationException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
}

From source file:licorice.gui.MainPanel.java

public void appendLog(String message) {
    SwingUtilities.invokeLater(() -> {
        try {//from www  .  j a v  a  2 s.c  om
            doc.insertString(doc.getLength(), message, null);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
        logPane.setCaretPosition(doc.getLength());
    });
}

From source file:hr.fer.zemris.vhdllab.applets.texteditor.TextEditor.java

@Override
public void highlightLine(int line) {
    int caret = textPane.getCaretPosition();
    Highlighter h = textPane.getHighlighter();
    h.removeAllHighlights();//ww  w . j av  a  2s .  c  o  m
    String content = textPane.getText();
    textPane.setCaretPosition(caret);

    int pos = 0;
    line--;
    while (line > 0) {
        pos = content.indexOf('\n', pos) + 1;
        line--;
    }
    int last = content.indexOf('\n', pos) + 1;
    if (last == 0) {
        last = content.length();
    }
    try {
        highlighted = h.addHighlight(pos, last,
                new DefaultHighlighter.DefaultHighlightPainter(new Color(180, 210, 238)));
    } catch (BadLocationException e) {
        e.printStackTrace();
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        JOptionPane.showMessageDialog(null, sw.toString());
    }
}

From source file:fedroot.dacs.swingdemo.DacsClientFrame.java

/**
 * Sets the HTML content to be displayed.
 *
 * @param content an HTML document string
 *//*  ww w  . j a  v a2  s . co m*/
private void setDocumentContent(String contenttype, String content) {
    HTMLDocument doc = new HTMLDocument();
    try {
        doc.remove(0, doc.getLength());
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

    try {
        htmlPane.setContentType(contenttype);
        htmlPane.read(new ByteArrayInputStream(content.getBytes()), doc);
        htmlPane.setDocument(doc);
        htmlPane.setCaretPosition(0);
    } catch (IOException e) {
        e.printStackTrace();
    }

    responseTextArea.setText(content);
    responseTextArea.setCaretPosition(0);
    responseTextArea.requestFocus();
}

From source file:br.com.RatosDePC.Brpp.IDEui.CodeDocument.java

public void highlight(int offset, String str) {
    String text = "";
    try {// w w  w.  j a  va 2  s  .c o m
        text = getText(0, getLength());
    } catch (BadLocationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    int before = findLastNonWordChar(text, offset);
    if (before < 0)
        before = 0;
    int after = findFirstNonWordChar(text, offset + str.length());
    int wordL = before;
    int wordR = before;
    // boolean comment = false;
    while (wordR <= after) {
        if (wordR == after || String.valueOf(text.charAt(wordR)).matches("\\W")) {
            if (text.substring(wordL, wordR).matches(KEYWORDS_1)) {
                if (text.substring(wordL, wordR).contains("}"))
                    setCharacterAttributes(wordL + 1, wordR - wordL, attrAzul, false);
                else
                    setCharacterAttributes(wordL, wordR - wordL, attrAzul, false);

            } else if (text.substring(wordL, wordR).matches(KEYWORDS_2)) {
                if (text.substring(wordL, wordR).contains("}"))
                    setCharacterAttributes(wordL + 1, wordR - wordL, attrLaranja, false);
                else
                    setCharacterAttributes(wordL, wordR - wordL, attrLaranja, false);
            } else if (text.substring(wordL, wordR).matches(KEYWORDS_3)) {
                if (text.substring(wordL, wordR).contains("}"))
                    setCharacterAttributes(wordL + 1, wordR - wordL, attrVermelho, false);
                else
                    setCharacterAttributes(wordL, wordR - wordL, attrVermelho, false);
            } else if (text.substring(wordL, wordR).matches(KEYWORDS_4)) {
                if (text.substring(wordL, wordR).contains("}")) {
                    setCharacterAttributes(wordL + 1, wordR - wordL, attrVermelho, false);
                    setCharacterAttributes(wordL + 1, wordR - wordL, attrBold, false);
                } else {
                    setCharacterAttributes(wordL + 1, wordR - wordL, attrVermelho, false);
                    setCharacterAttributes(wordL + 1, wordR - wordL, attrBold, false);
                }
            } else {
                setCharacterAttributes(wordL, wordR - wordL, attrBlack, true);
                setCharacterAttributes(wordL, wordR - wordL, attrNoBold, true);
            }
            wordL = wordR;
        }
        wordR++;
    }

    try {
        int beforeC = 0;
        int afterC = 0;
        int off = 0;
        do {
            beforeC = text.indexOf("//", beforeC + off);
            afterC = text.indexOf("\n", beforeC);
            if (beforeC != -1)
                setCharacterAttributes(beforeC, afterC - beforeC, attrVerde, true);
            off = 2;
        } while (beforeC != -1);
        beforeC = 0;
        afterC = 0;
        off = 0;
        do {
            beforeC = text.indexOf("/* ", beforeC + off);
            afterC = text.indexOf("*/", beforeC) + 2;
            if (beforeC != -1)
                setCharacterAttributes(beforeC, afterC - beforeC, attrVerde, true);
            off = 2;
        } while (beforeC != -1);
        beforeC = 0;
        afterC = 0;
        off = 0;
        do {
            beforeC = text.indexOf("\"", afterC + off);
            afterC = text.indexOf("\"", beforeC + 1);
            if (afterC != -1) {
                afterC += 1;
                System.out.println("entrei");
            }
            if (beforeC != -1 && afterC != -1) {
                String string = text.substring(beforeC, afterC);
                if (!string.contains("\n"))
                    setCharacterAttributes(beforeC, afterC - beforeC, attrAzul, true);
            }
            off = 1;
        } while (beforeC > 0 && afterC > 0);
        beforeC = 0;
        afterC = 0;
        off = 0;
        do {
            beforeC = text.indexOf("'", beforeC + off);
            afterC = text.indexOf("'", beforeC + 1);
            if (afterC != -1)
                afterC += 1;
            if (beforeC != -1 && afterC != -1)
                setCharacterAttributes(beforeC, afterC - beforeC, attrAzul, true);
            off = 2;
        } while (beforeC > 0 && afterC > 0);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Console.java

void returnPressed() {
    Document doc = getDocument();
    int len = doc.getLength();
    Segment segment = new Segment();
    try {//from  w ww .ja  v  a2  s . co  m
        synchronized (doc) {
            doc.getText(outputMark, len - outputMark, segment);
        }
    } catch (javax.swing.text.BadLocationException ignored) {
        ignored.printStackTrace();
    }
    if (segment.count > 0) {
        history.addElement(segment.toString());
    }
    historyIndex = history.size();
    inPipe.write(segment.array, segment.offset, segment.count);
    append("\n");
    synchronized (doc) {
        outputMark = doc.getLength();
    }
    inPipe.write("\n");
    inPipe.flush();
    console1.flush();
}

From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java

public void toggleBreakPoint() {
    try {/*from  ww  w . j  av a 2s.com*/
        if (multiSelect) {
            for (int line = multiSelectStart; line <= multiSelectEnd; line++) {
                scriptEditorScrollPane.getGutter().toggleBookmark(line);
            }
        } else {
            int line = scriptEditorTA.getCaretLineNumber();
            scriptEditorScrollPane.getGutter().toggleBookmark(line);
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}