Search in sources :

Example 36 with StyledDocument

use of javax.swing.text.StyledDocument in project grafikon by jub77.

the class FreightCheckPanel method initializeStyles.

private void initializeStyles() {
    if (okStyle == null && errorStyle == null && textPane.getGraphics() != null) {
        FontMetrics metrics = textPane.getGraphics().getFontMetrics();
        int size = metrics.getAscent() * 5 / 6;
        // images
        StyledDocument document = (StyledDocument) textPane.getDocument();
        okStyle = document.addStyle("ok.style", null);
        ImageIcon okIcon = GuiComponentUtils.resizeIcon(ResourceLoader.createImageIcon(GuiIcon.OK), size, size);
        StyleConstants.setIcon(okStyle, okIcon);
        errorStyle = document.addStyle("error.style", null);
        ImageIcon errorIcon = GuiComponentUtils.resizeIcon(ResourceLoader.createImageIcon(GuiIcon.ERROR), size, size);
        StyleConstants.setIcon(errorStyle, errorIcon);
        StyleConstants.setSubscript(okStyle, true);
        boldUnderlineStyle = document.addStyle("bold.underline", null);
        StyleConstants.setUnderline(boldUnderlineStyle, true);
        StyleConstants.setBold(boldUnderlineStyle, true);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) FontMetrics(java.awt.FontMetrics) StyledDocument(javax.swing.text.StyledDocument)

Example 37 with StyledDocument

use of javax.swing.text.StyledDocument in project ffx by mjschnie.

the class ModelingShell method run.

/**
 * Configure the Swing GUI for the shell.
 */
@Override
public void run() {
    if (!headless) {
        try {
            super.run();
            // Output JTextPane
            JTextPane output = getOutputArea();
            output.setBackground(Color.BLACK);
            output.setForeground(Color.WHITE);
            // Input JTextPane
            JTextPane input = getInputArea();
            input.setBackground(Color.WHITE);
            input.setForeground(Color.BLACK);
            // Output StyledDocument Styles
            StyledDocument doc = output.getStyledDocument();
            Style defStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
            Style regular = doc.addStyle("regular", defStyle);
            Style prompt = doc.addStyle("prompt", regular);
            Style command = doc.addStyle("command", regular);
            Style result = doc.addStyle("result", regular);
            StyleConstants.setFontFamily(regular, "Monospaced");
            setPromptStyle(prompt);
            setCommandStyle(command);
            setResultStyle(result);
            StyleConstants.setForeground(prompt, Color.ORANGE);
            StyleConstants.setForeground(command, Color.GREEN);
            StyleConstants.setForeground(result, Color.GREEN);
            StyleConstants.setBackground(result, Color.BLACK);
            clearOutput();
            // initMenus();
            // Set labels and icon for Force Field X.
            getStatusLabel().setText("Welcome to the Force Field X Shell.");
            JFrame frame = (JFrame) this.getFrame();
            frame.setTitle("Force Field X Shell");
            URL iconURL = getClass().getClassLoader().getResource("ffx/ui/icons/icon64.png");
            ImageIcon icon = new ImageIcon(iconURL);
            frame.setIconImage(icon.getImage());
            frame.setSize(600, 600);
        } catch (Exception e) {
            logger.warning(e.toString());
        }
    }
}
Also used : JTextPane(javax.swing.JTextPane) ImageIcon(javax.swing.ImageIcon) JFrame(javax.swing.JFrame) StyledDocument(javax.swing.text.StyledDocument) Style(javax.swing.text.Style) URL(java.net.URL) IOException(java.io.IOException)

Example 38 with StyledDocument

use of javax.swing.text.StyledDocument in project GenericKnimeNodes by genericworkflownodes.

the class ParameterDialog method updateDocumentationSection.

private void updateDocumentationSection(String description) {
    StyledDocument doc = (StyledDocument) help.getDocument();
    Style style = doc.addStyle("StyleName", null);
    StyleConstants.setFontFamily(style, "SansSerif");
    try {
        doc.remove(0, doc.getLength());
        doc.insertString(0, description, style);
    } catch (BadLocationException e) {
        LOGGER.warn("Documentation update failed.", e);
    }
}
Also used : StyledDocument(javax.swing.text.StyledDocument) Style(javax.swing.text.Style) BadLocationException(javax.swing.text.BadLocationException)

Example 39 with StyledDocument

use of javax.swing.text.StyledDocument in project org.alloytools.alloy by AlloyTools.

the class SwingLogPanel method setFontName.

/**
 * Set the font name.
 */
public void setFontName(String fontName) {
    if (log == null)
        return;
    this.fontName = fontName;
    log.setFont(new Font(fontName, Font.PLAIN, fontSize));
    StyleConstants.setFontFamily(styleRegular, fontName);
    StyleConstants.setFontFamily(styleBold, fontName);
    StyleConstants.setFontFamily(styleRed, fontName);
    StyleConstants.setFontSize(styleRegular, fontSize);
    StyleConstants.setFontSize(styleBold, fontSize);
    StyleConstants.setFontSize(styleRed, fontSize);
    // Changes all existing text
    StyledDocument doc = log.getStyledDocument();
    Style temp = doc.addStyle("temp", null);
    StyleConstants.setFontFamily(temp, fontName);
    StyleConstants.setFontSize(temp, fontSize);
    doc.setCharacterAttributes(0, doc.getLength(), temp, false);
    // Changes all existing hyperlinks
    Font newFont = new Font(fontName, Font.BOLD, fontSize);
    for (JLabel link : links) {
        link.setFont(newFont);
    }
}
Also used : StyledDocument(javax.swing.text.StyledDocument) Style(javax.swing.text.Style) JLabel(javax.swing.JLabel) Font(java.awt.Font)

Example 40 with StyledDocument

use of javax.swing.text.StyledDocument in project org.alloytools.alloy by AlloyTools.

the class SwingLogPanel method reallyLog.

private void reallyLog(String text, Style style) {
    if (log == null || text.length() == 0)
        return;
    int i = text.lastIndexOf('\n'), j = text.lastIndexOf('\r');
    if (i >= 0 && i < j) {
        i = j;
    }
    StyledDocument doc = log.getStyledDocument();
    try {
        if (i < 0) {
            doc.insertString(doc.getLength(), text, style);
        } else {
            // Performs intelligent caret positioning
            doc.insertString(doc.getLength(), text.substring(0, i + 1), style);
            log.setCaretPosition(doc.getLength());
            if (i < text.length() - 1) {
                doc.insertString(doc.getLength(), text.substring(i + 1), style);
            }
        }
    } catch (BadLocationException e) {
    // Harmless
    }
    if (style != styleRed) {
        lastSize = doc.getLength();
    }
}
Also used : StyledDocument(javax.swing.text.StyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

StyledDocument (javax.swing.text.StyledDocument)63 BadLocationException (javax.swing.text.BadLocationException)29 Style (javax.swing.text.Style)18 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)12 Point (java.awt.Point)7 JTextPane (javax.swing.JTextPane)7 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)7 ArrayList (java.util.ArrayList)4 JLabel (javax.swing.JLabel)4 Test (org.junit.jupiter.api.Test)4 Font (java.awt.Font)3 LogRecord (java.util.logging.LogRecord)3 Matcher (java.util.regex.Matcher)3 ImageIcon (javax.swing.ImageIcon)3 JPanel (javax.swing.JPanel)3 PersistentArrayMap (clojure.lang.PersistentArrayMap)2 BorderLayout (java.awt.BorderLayout)2 Dimension (java.awt.Dimension)2 Rectangle (java.awt.Rectangle)2 IOException (java.io.IOException)2