Example usage for javax.swing.text StyledDocument getLength

List of usage examples for javax.swing.text StyledDocument getLength

Introduction

In this page you can find the example usage for javax.swing.text StyledDocument getLength.

Prototype

public int getLength();

Source Link

Document

Returns number of characters of content currently in the document.

Usage

From source file:de.codesourcery.jasm16.utils.ASTInspector.java

private void clearCompilationErrors(ICompilationUnit unit) {
    StyledDocument doc = editorPane.getStyledDocument();
    disableDocumentListener();/*from  ww  w.j a va 2s  .  co m*/
    try {
        doc.setCharacterAttributes(0, doc.getLength(), defaultStyle, true);
    } finally {
        enableDocumentListener();
    }
}

From source file:dataviewer.DataViewer.java

private void cb_tableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_tableActionPerformed
    try {/* w  w  w  . jav  a  2  s.  c  o m*/
        table = cb_table.getSelectedItem().toString();
        DB db = new DB("./db/" + table + ".db");
        db.open();
        String[] cols = db.get_table_columns(table);
        db.close();

        DefaultTableModel model = new DefaultTableModel();
        //model.addColumn("Column Index");
        model.addColumn("Field");
        int i = 1;

        StyleContext sc = StyleContext.getDefaultStyleContext();
        TabSet tabs = new TabSet(new TabStop[] { new TabStop(20) });
        AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabs);
        tp_sql.setParagraphAttributes(paraSet, false);

        StyledDocument doc = tp_sql.getStyledDocument();

        doc.remove(0, doc.getLength());

        doc.insertString(doc.getLength(), "SELECT", null);
        doc.insertString(doc.getLength(), "\n", null);

        for (int j = 1; j < cols.length; ++j) {
            String s = cols[j];
            //model.addRow(new Object[]{i++, s});
            model.addRow(new Object[] { s });
            doc.insertString(doc.getLength(), "\t", null);
            doc.insertString(doc.getLength(), s, null);
            if (j < cols.length - 1) {
                doc.insertString(doc.getLength(), ",", null);
            }
            doc.insertString(doc.getLength(), "\n", null);
        }

        doc.insertString(doc.getLength(), "FROM", null);
        doc.insertString(doc.getLength(), "\n", null);
        doc.insertString(doc.getLength(), "\t", null);
        doc.insertString(doc.getLength(), table, null);
        /*doc.insertString(doc.getLength(), "\n", null);
         doc.insertString(doc.getLength(), "WHERE", null);
         doc.insertString(doc.getLength(), "\n", null);
         doc.insertString(doc.getLength(), "\t", null);
         doc.insertString(doc.getLength(), "_N_ <= " + N, null);
         doc.insertString(doc.getLength(), ";", null);*/

        tb_columns.setModel(model);

        TableRowSorter trs = new TableRowSorter(model);
        trs.setComparator(0, new IntComparator());
        tb_columns.setRowSorter(trs);

        //highline();
    } catch (Exception e) {
        txt_count.setText(e.getMessage());
    }
}

From source file:dylemator.DylematorUI.java

private void displayCenteredText(String text) {
    textArea.setText("");
    text = "\n\n\n" + text;
    SimpleAttributeSet attribs = new SimpleAttributeSet();
    if (sd == null)
        sd = new SettingsDialog(this, true);
    float fnt = sd.getFontSize();
    StyledDocument doc = (StyledDocument) textArea.getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);//doc.addStyle("MyStyle",null);
    StyleConstants.setFontSize(style, (int) fnt);
    StyleConstants.setLineSpacing(attribs, 0.5f);
    StyleConstants.setFontFamily(style, "Segoe UI");
    StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_CENTER);
    textArea.setParagraphAttributes(attribs, true);

    try {/*from ww w  .  j  a  va 2  s. c  om*/
        doc.insertString(doc.getLength(), text, style);
        doc.setParagraphAttributes(0, doc.getLength() - 1, attribs, false);
    } catch (BadLocationException ex) {
        Logger.getLogger(DylematorUI.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:gda.gui.BatonPanel.java

private void updateMessagePanel(final UserMessage message) {
    SwingUtilities.invokeLater(new Runnable() {

        private void addMessageHeader() throws BadLocationException {
            StyledDocument doc = (StyledDocument) logPanel.getDocument();

            Date date = new Date();
            Format formatter = new SimpleDateFormat("dd MMM HH:mm:ss");
            String newMessage = "\n" + formatter.format(date) + "\t";

            newMessage += "#" + message.getSourceClientNumber();
            newMessage += " " + message.getSourceUsername() + "";

            doc.insertString(doc.getLength(), newMessage, doc.getStyle("bold"));
        }//from   w  w w  . j a va  2 s  .  c o  m

        private void addMessageBody() throws BadLocationException {
            StyledDocument doc = (StyledDocument) logPanel.getDocument();
            String newMessage = "\n    ";
            newMessage += message.getMessage();
            doc.insertString(doc.getLength(), newMessage, doc.getStyle("regular"));
        }

        @Override
        public void run() {
            try {
                addMessageHeader();
                addMessageBody();
                // scroll down to display new message
                getLogPanel().getCaret().setDot(getLogPanel().getText().length());
                saveLog(logPanel.getStyledDocument());
            } catch (BadLocationException e) {
                //
            }
        }
    });
}

From source file:com.xilinx.kintex7.MainScreen.java

private void updateLog(String message, SimpleAttributeSet aset) {
    StyledDocument doc = textArea.getStyledDocument();
    String[] lines = Utils.wrapText(message, 60);
    try {//from  w  ww. jav  a2 s .c  o m
        for (int i = 0; i < lines.length; ++i)
            doc.insertString(doc.getLength(), "\n" + lines[i], aset);
    } catch (Exception e) {

    }
}

From source file:homenetapp.HomeNetAppGui.java

private void updateTextPane(final String text, final javax.swing.text.Style color) {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            javax.swing.text.StyledDocument doc = consoleTextPane.getStyledDocument();

            try {

                // consoleTextPane.se
                if (color != null) {
                    doc.setLogicalStyle(doc.getLength(), color);
                }//from   w  w  w .  j  a  va2  s  .  c o m
                doc.insertString(doc.getLength(), text, null);

                if (doc.getLength() > 10000) {
                    doc.remove(0, text.length());
                }
            } catch (javax.swing.text.BadLocationException e) {
                throw new RuntimeException(e);
            }
            consoleTextPane.setCaretPosition(doc.getLength() - 1);
        }
    });
}

From source file:de.codesourcery.jasm16.ide.ui.views.SourceCodeView.java

protected final void clearCompilationErrors() {
    disableDocumentListener();/* w  w  w  .  j  ava 2s. c  o  m*/
    try {
        final StyledDocument doc = editorPane.getStyledDocument();
        doc.setCharacterAttributes(0, doc.getLength(), defaultStyle, true);
    } finally {
        enableDocumentListener();
    }
}

From source file:com.hexidec.ekit.EkitCore.java

public String getRTFDocument() throws IOException, BadLocationException {
    StyledDocument doc = (StyledDocument) (jtpMain.getStyledDocument());
    StringWriter strwriter = new StringWriter();
    RTFEditorKit rtfKit = new RTFEditorKit();
    rtfKit.write(strwriter, doc, 0, doc.getLength());
    return strwriter.toString();
}

From source file:com.hexidec.ekit.EkitCore.java

/**
 * Method for saving text as an RTF document
 *//*from  ww  w.jav a 2 s .  com*/
public void writeOutRTF(StyledDocument doc, File rtfFile) throws IOException, BadLocationException {
    FileOutputStream fos = new FileOutputStream(rtfFile);
    RTFEditorKit rtfKit = new RTFEditorKit();
    rtfKit.write(fos, doc, 0, doc.getLength());
    fos.flush();
    fos.close();
    refreshOnUpdate();
}

From source file:ome.formats.importer.gui.GuiCommonElements.java

/**
 * Add a text pane to the parent container
 * //from   w ww .ja va 2s  .c om
 * @param container - parent container
 * @param text - text for new Text Pane
 * @param placement - TableLayout placement within the parent container
 * @param debug - turn on/off red debug borders
 * @return new JTextPane
 */
public static synchronized JTextPane addTextPane(Container container, String text, String placement,
        boolean debug) {
    StyleContext context = new StyleContext();
    StyledDocument document = new DefaultStyledDocument(context);

    Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT);

    try {
        document.insertString(document.getLength(), text, null);
    } catch (BadLocationException e) {
        log.error("BadLocationException inserting text to document.");
    }

    JTextPane textPane = new JTextPane(document);
    textPane.setOpaque(false);
    textPane.setEditable(false);
    textPane.setFocusable(false);
    container.add(textPane, placement);

    if (debug == true)
        textPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                textPane.getBorder()));

    return textPane;
}