Example usage for javax.swing.text StyleContext getDefaultStyleContext

List of usage examples for javax.swing.text StyleContext getDefaultStyleContext

Introduction

In this page you can find the example usage for javax.swing.text StyleContext getDefaultStyleContext.

Prototype

public static final StyleContext getDefaultStyleContext() 

Source Link

Document

Returns default AttributeContext shared by all documents that don't bother to define/supply their own context.

Usage

From source file:me.mayo.telnetkek.MainPanel.java

private void writeToConsoleImmediately(final ConsoleMessage message, final boolean isTelnetError) {
    SwingUtilities.invokeLater(() -> {
        if (isTelnetError && chkIgnoreErrors.isSelected()) {
            return;
        }/*from  ww  w .  ja  v  a 2 s  . co  m*/

        final StyledDocument styledDocument = mainOutput.getStyledDocument();

        int startLength = styledDocument.getLength();

        try {
            styledDocument.insertString(styledDocument.getLength(),
                    message.getMessage() + System.lineSeparator(),
                    StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY,
                            StyleConstants.Foreground, message.getColor()));
        } catch (BadLocationException ex) {
            throw new RuntimeException(ex);
        }

        if (MainPanel.this.chkAutoScroll.isSelected() && MainPanel.this.mainOutput.getSelectedText() == null) {
            final JScrollBar vScroll = mainOutputScoll.getVerticalScrollBar();

            if (!vScroll.getValueIsAdjusting()) {
                if (vScroll.getValue() + vScroll.getModel().getExtent() >= (vScroll.getMaximum() - 50)) {
                    MainPanel.this.mainOutput.setCaretPosition(startLength);

                    final Timer timer = new Timer(10, (ActionEvent ae) -> {
                        vScroll.setValue(vScroll.getMaximum());
                    });
                    timer.setRepeats(false);
                    timer.start();
                }
            }
        }
    });
}

From source file:TextSamplerDemo.java

protected void addStylesToDocument(StyledDocument doc) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style s = doc.addStyle("italic", regular);
    StyleConstants.setItalic(s, true);

    s = doc.addStyle("bold", regular);
    StyleConstants.setBold(s, true);

    s = doc.addStyle("small", regular);
    StyleConstants.setFontSize(s, 10);

    s = doc.addStyle("large", regular);
    StyleConstants.setFontSize(s, 16);

    s = doc.addStyle("icon", regular);
    StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);
    ImageIcon pigIcon = createImageIcon("images/Pig.gif", "a cute pig");
    if (pigIcon != null) {
        StyleConstants.setIcon(s, pigIcon);
    }//from  w  w  w. ja va  2 s .c  o m

    s = doc.addStyle("button", regular);
    StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);
    ImageIcon soundIcon = createImageIcon("images/sound.gif", "sound icon");
    JButton button = new JButton();
    if (soundIcon != null) {
        button.setIcon(soundIcon);
    } else {
        button.setText("BEEP");
    }
    button.setCursor(Cursor.getDefaultCursor());
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setActionCommand(buttonString);
    button.addActionListener(this);
    StyleConstants.setComponent(s, button);
}

From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java

private void addStylesToDocument() {
    //Initialize some styles.
    Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regularStyle = document.addStyle("regular", defaultStyle);
    StyleConstants.setFontFamily(defaultStyle, "SansSerif");
    StyleConstants.setFontSize(defaultStyle, Globals.prefs.getInt(JabRefPreferences.FONT_SIZE));

    Style s = document.addStyle("used", regularStyle);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.blue);

    s = document.addStyle("marked", regularStyle);
    StyleConstants.setBold(s, true);
    StyleConstants.setForeground(s, Color.red);
}

From source file:com.NewJFrame.java

private void appendToPane(JTextPane tp, String msg, Color c) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    //        aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
    //        aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
    int len = tp.getDocument().getLength();
    tp.setCaretPosition(len);/*from w  ww.  ja  v a  2  s .  c o  m*/
    tp.setCharacterAttributes(aset, false);
    tp.replaceSelection(msg);

}

From source file:dataviewer.DataViewer.java

private void cb_tableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_tableActionPerformed
    try {/* ww w .j ava  2 s . com*/
        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:gda.gui.BatonPanel.java

private JTextPane getLogPanel() {
    if (logPanel == null) {
        logPanel = new JTextPane();
        logPanel.setEditable(false);//from ww w. j  a  v  a  2  s .  c om
        StyledDocument doc = logPanel.getStyledDocument();

        Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

        Style regular = doc.addStyle("regular", def);
        StyleConstants.setFontFamily(def, "SansSerif");

        Style s = doc.addStyle("italic", regular);
        StyleConstants.setItalic(s, true);

        s = doc.addStyle("bold", regular);
        StyleConstants.setBold(s, true);
    }
    return logPanel;
}

From source file:org.drugis.addis.gui.wizard.AddStudyWizard.java

public static void addStylesToDoc(StyledDocument doc) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);

    Style bold = doc.addStyle("bold", regular);
    StyleConstants.setBold(bold, true);

    // The image must first be wrapped in a style
    Style style = doc.addStyle("tip", null);
    StyleConstants.setIcon(style, Main.IMAGELOADER.getIcon(FileNames.ICON_TIP));
}

From source file:org.smart.migrate.ui.ImportThread.java

private void addStylesToDocument(StyledDocument doc) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style s = doc.addStyle("italic", regular);
    StyleConstants.setItalic(s, true);

    s = doc.addStyle("bold", regular);
    StyleConstants.setBold(s, true);

    s = doc.addStyle("small", regular);
    StyleConstants.setFontSize(s, 10);

    s = doc.addStyle("large", regular);
    StyleConstants.setFontSize(s, 16);

    s = doc.addStyle("icon", regular);
    StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);

    s = doc.addStyle("info", regular);
    StyleConstants.setForeground(s, Color.blue);

    s = doc.addStyle("error", regular);
    StyleConstants.setForeground(s, Color.red);

    s = doc.addStyle("warning", regular);
    StyleConstants.setForeground(s, Color.orange);

    s = doc.addStyle("gray", regular);
    StyleConstants.setForeground(s, Color.gray);

    s = doc.addStyle("success", regular);
    StyleConstants.setForeground(s, Color.green);
}

From source file:processing.app.Theme.java

/**
 * Returns the default font for text areas.
 *
 * @return The default font./*from w  ww  .  j a  v a  2 s.  co  m*/
 */
public static final Font getDefaultFont() {

    // Use StyleContext to get a composite font for better Asian language
    // support; see Sun bug S282887.
    StyleContext sc = StyleContext.getDefaultStyleContext();
    Font font = null;

    if (OSUtils.isMacOS()) {
        // Snow Leopard (1.6) uses Menlo as default monospaced font,
        // pre-Snow Leopard used Monaco.
        font = sc.getFont("Menlo", Font.PLAIN, 12);
        if (!"Menlo".equals(font.getFamily())) {
            font = sc.getFont("Monaco", Font.PLAIN, 12);
            if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen
                font = sc.getFont("Monospaced", Font.PLAIN, 13);
            }
        }
    } else {
        // Consolas added in Vista, used by VS2010+.
        font = sc.getFont("Consolas", Font.PLAIN, 13);
        if (!"Consolas".equals(font.getFamily())) {
            font = sc.getFont("Monospaced", Font.PLAIN, 13);
        }
    }

    // System.out.println(font.getFamily() + ", " + font.getName());
    return font;
}