Example usage for javax.swing.text BadLocationException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.minelord.gui.panes.IRCPane.java

synchronized public static void addHTML(String html) {
    synchronized (kit) {
        try {//from  www .j  a  va2s  .  com
            kit.insertHTML(doc, doc.getLength(), html, 0, 0, null);
        } catch (BadLocationException ignored) {
            Logger.logError(ignored.getMessage(), ignored);
        } catch (IOException ignored) {
            Logger.logError(ignored.getMessage(), ignored);
        }
        text.setCaretPosition(text.getDocument().getLength());
        /*scroller.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener()
        {
           @Override
           public void adjustmentValueChanged(AdjustmentEvent arg0)
           {
              if((scrollValue+scroller.getVerticalScrollBar().getModel().getExtent())<=4)
              {
          scroller.getVerticalScrollBar().setValue(scrollValue+scroller.getVerticalScrollBar().getModel().getExtent());
          bottom=true;
              }
              else
              {
          scroller.getVerticalScrollBar().setValue(scrollValue);
          bottom=false;
              }
              scrollValue=scroller.getVerticalScrollBar().getValue();
           }
        });*/
    }
}

From source file:DoubleDocument.java

public double getValue() {
    try {//from  w w  w.j  a  v  a 2 s.com
        String t = getText(0, getLength());
        if (t != null && t.length() > 0) {
            return Double.parseDouble(t);
        } else {
            return 0;
        }
    } catch (BadLocationException e) {
        // Will not happen because we are sure
        // we use the proper range
        throw new Error(e.getMessage());
    }
}

From source file:de.unidue.inf.is.ezdl.gframedl.components.checkboxlist.CheckBoxListCellRenderer.java

private void shortenDescription() {
    List<String> lines = new ArrayList<String>();

    int length = description.getDocument().getLength();
    int offset = 0;

    try {/*from   w ww .  jav a2s  . c o  m*/
        while (offset < length) {
            int end = Utilities.getRowEnd(description, offset);

            if (end < 0) {
                break;
            }

            // Include the last character on the line
            end = Math.min(end + 1, length);

            String line = description.getDocument().getText(offset, end - offset);

            // Remove the line break character
            if (line.endsWith("\n")) {
                line = line.substring(0, line.length() - 1);
            }

            lines.add(line);

            offset = end;
        }
    } catch (BadLocationException e) {
        logger.error(e.getMessage(), e);
    }

    makeDescriptionText(lines);

    makeTooltipText(lines);
}

From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java

public JTextPane createJTextPane() {
    String newline = "\n";
    String[] description = { "PubChem XML Tool (Version: " + version + ")" + newline,
            "By: S. Canny (scanny@scripps.edu) and M. Southern (southern@scripps.edu)" + newline, "" + newline,
            "PubChem XML Tool main functions:" + newline,
            "1. Create a PubChem XML that can include Assay, Result TIDs, Xrefs, Panel, and Categorized Comments."
                    + newline,/*  ww w .j  a v  a  2  s  .  c om*/
            "2. Extract Assay, Result TID, Xref, Panel, and Categorized Comment information from a PubChem XML."
                    + newline,
            "3. Create a report from an Excel workbook or PubChem XMLs." + newline, "" + newline,
            "Other features:" + newline,
            "1. Automatically adds reference section to description of PubChem XML or a report if placeholder is used."
                    + newline,
            "2. Checks proteins, genes, omims, and taxonomies for connections when creating PubChem XML or a report."
                    + newline,
            "3. Can retrieve on-hold and newly deposited assays from deposition system to extract or create report."
                    + newline,
            "" + newline, "\t\t\t(c) 2010, The Scripps Research Institute- Florida" };
    String[] styles = { "bold", "regular", "regular", "regular", "regular", "regular", "regular", "regular",
            "regular", "regular", "regular", "regular", "regular", "regular", "right" };

    JTextPane jtp = new JTextPane();
    StyledDocument doc = jtp.getStyledDocument();
    addStylesToDocument(doc);

    try {
        for (int ii = 0; ii < description.length; ii++)
            doc.insertString(doc.getLength(), description[ii], doc.getStyle(styles[ii]));
    } catch (BadLocationException ble) {
        log.error(ble.getMessage(), ble);
    }
    jtp.setOpaque(false);
    jtp.setEditable(false);
    jtp.setPreferredSize(new Dimension(640, 230));

    return jtp;
}

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

/**
 * Sets the HTML content to be displayed.
 *
 * @param content an HTML document string
 *//*  w  ww.j  av  a 2 s.  com*/
private void setDocumentContent(String contenttype, String content) {
    HTMLDocument doc = new HTMLDocument();
    try {
        doc.remove(0, doc.getLength());
    } catch (BadLocationException ex) {
        logger.log(Level.WARNING, ex.getMessage());
    }
    doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

    try {
        htmlPane.setContentType(contenttype);
        htmlPane.read(new ByteArrayInputStream(content.getBytes()), doc);
        htmlPane.setDocument(doc);
        htmlPane.setCaretPosition(0);
    } catch (IOException ex) {
        logger.log(Level.WARNING, ex.getMessage());
    }

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

From source file:com.mirth.connect.client.ui.components.rsta.MirthRSyntaxTextArea.java

public String getEOLFixedSelectedText() {
    String txt = null;/*from  www .  j  a v  a2 s  .  com*/
    int p0 = Math.min(getCaret().getDot(), getCaret().getMark());
    int p1 = Math.max(getCaret().getDot(), getCaret().getMark());
    if (p0 != p1) {
        try {
            MirthRSyntaxDocument doc = (MirthRSyntaxDocument) getDocument();
            txt = doc.getEOLFixedText(p0, p1 - p0);
        } catch (BadLocationException e) {
            throw new IllegalArgumentException(e.getMessage());
        }
    }
    return txt;
}

From source file:net.pandoragames.far.ui.swing.component.UndoHistory.java

private String stringValue(UndoableEdit edit) {
    if (edit instanceof AbstractDocument.DefaultDocumentEvent) {
        AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) edit;

        String change = null;/*  w  w  w.ja v a 2s  .c o  m*/
        if (event.getType() == DocumentEvent.EventType.REMOVE) {
            change = "DEL";
        } else {
            try {
                change = event.getDocument().getText(event.getOffset(), event.getLength());
                if (event.getType() == DocumentEvent.EventType.CHANGE)
                    change = change + " (c)";
            } catch (BadLocationException blx) {
                change = "EXC: " + blx.getMessage();
            }
        }
        return change;
    } else {
        return edit.getPresentationName();
    }
}

From source file:EditorPaneExample16.java

public HTMLDocument loadDocument(HTMLDocument doc, URL url, String charSet) throws IOException {
    doc.putProperty(Document.StreamDescriptionProperty, url);

    /*// w  w  w. j av a2 s. c  o m
     * This loop allows the document read to be retried if the character
     * encoding changes during processing.
     */
    InputStream in = null;
    boolean ignoreCharSet = false;

    for (;;) {
        try {
            // Remove any document content
            doc.remove(0, doc.getLength());

            URLConnection urlc = url.openConnection();
            in = urlc.getInputStream();
            Reader reader = (charSet == null) ? new InputStreamReader(in) : new InputStreamReader(in, charSet);

            HTMLEditorKit.Parser parser = getParser();
            HTMLEditorKit.ParserCallback htmlReader = getParserCallback(doc);
            parser.parse(reader, htmlReader, ignoreCharSet);
            htmlReader.flush();

            // All done
            break;
        } catch (BadLocationException ex) {
            // Should not happen - throw an IOException
            throw new IOException(ex.getMessage());
        } catch (ChangedCharSetException e) {
            // The character set has changed - restart
            charSet = getNewCharSet(e);

            // Prevent recursion by suppressing further exceptions
            ignoreCharSet = true;

            // Close original input stream
            in.close();

            // Continue the loop to read with the correct encoding
        }
    }

    return doc;
}

From source file:ch.zhaw.iamp.rct.ui.GrammarWindow.java

private void insertTabAsSpace(KeyEvent event, JTextComponent component) {
    try {/*from   ww w . j a  v a 2  s .  co m*/
        int caretPostion = component.getCaretPosition() - 1;
        component.getDocument().remove(caretPostion, 1);
        component.getDocument().insertString(caretPostion, "    ", null);
        event.consume();
    } catch (BadLocationException ex) {
        System.out.println("Could not insert a tab: " + ex.getMessage());
    }
}

From source file:ch.zhaw.iamp.rct.ui.GrammarWindow.java

private void removeTabIfPossilbe(KeyEvent event, JTextComponent component) {
    try {/*  ww w .  j a v  a  2 s.c o  m*/
        Document doc = component.getDocument();
        int caretPostion = component.getCaretPosition();
        int lineStartIndex = doc.getText(0, caretPostion).lastIndexOf('\n') + 1;
        lineStartIndex = lineStartIndex < 0 ? 0 : lineStartIndex;
        lineStartIndex = lineStartIndex >= doc.getLength() ? doc.getLength() - 1 : lineStartIndex;
        int scanEndIndex = lineStartIndex + 4 <= doc.getLength() ? lineStartIndex + 4 : doc.getLength();

        for (int i = 0; i < 4 && i + lineStartIndex < scanEndIndex; i++) {
            if (doc.getText(lineStartIndex, 1).matches(" ")) {
                doc.remove(lineStartIndex, 1);
            } else if (doc.getText(lineStartIndex, 1).matches("\t")) {
                doc.remove(lineStartIndex, 1);
                break;
            } else {
                break;
            }
        }

        event.consume();
    } catch (BadLocationException ex) {
        System.out.println("Could not insert a tab: " + ex.getMessage());
    }
}