List of usage examples for javax.swing.text StyleConstants setForeground
public static void setForeground(MutableAttributeSet a, Color fg)
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:net.team2xh.crt.gui.editor.EditorTextPane.java
private void initAttributeSets() { Theme theme = Theme.getTheme();//from www . ja v a2 s . c o m StyleConstants.setForeground(OPERATORS, theme.COLOR_10); StyleConstants.setForeground(NAME, theme.COLOR_11); StyleConstants.setItalic(NAME, true); StyleConstants.setForeground(NUMBER, theme.COLOR_09); StyleConstants.setForeground(COMMENT, theme.COLOR_16); StyleConstants.setForeground(BLOCK, theme.COLOR_06); StyleConstants.setItalic(BLOCK, true); StyleConstants.setForeground(NORMAL, theme.COLOR_11); StyleConstants.setForeground(IDENTIFIER, theme.COLOR_11); StyleConstants.setForeground(TRANSFORM, theme.COLOR_08); StyleConstants.setForeground(STRING, theme.COLOR_12); }
From source file:ome.formats.importer.gui.GuiImporter.java
/** * This method appends data to the output window * //from w w w. j a va 2s. c om * @param s - text to append */ public void appendToOutput(String s) { try { StyledDocument doc = (StyledDocument) outputTextPane.getDocument(); Style style = doc.addStyle("StyleName", null); StyleConstants.setForeground(style, Color.black); StyleConstants.setFontFamily(style, "SansSerif"); StyleConstants.setFontSize(style, 12); StyleConstants.setBold(style, false); doc.insertString(doc.getLength(), s, style); //trim the document size so it doesn't grow to big int maxChars = 200000; if (doc.getLength() > maxChars) doc.remove(0, doc.getLength() - maxChars); //outputTextPane.setDocument(doc); } catch (BadLocationException e) { } }
From source file:ome.formats.importer.gui.GuiImporter.java
/** * This method appends data to the output window. * /* w ww . j ava 2 s .c om*/ * @param s - string to append */ public void appendToDebug(String s) { log.debug(s); try { StyledDocument doc = (StyledDocument) debugTextPane.getDocument(); Style style = doc.addStyle("StyleName", null); StyleConstants.setForeground(style, Color.black); StyleConstants.setFontFamily(style, "SansSerif"); StyleConstants.setFontSize(style, 12); StyleConstants.setBold(style, false); doc.insertString(doc.getLength(), s, style); //trim the document size so it doesn't grow to big int maxChars = 200000; if (doc.getLength() > maxChars) doc.remove(0, doc.getLength() - maxChars); //debugTextPane.setDocument(doc); } catch (BadLocationException e) { } }
From source file:org.apache.ftpserver.gui.LoggerPanel.java
/** * Constructor - set the container./*from w ww. j a v a 2 s. c o m*/ */ public LoggerPanel(PluginPanelContainer container) { super(container); // create style attributes m_debugAttr = new SimpleAttributeSet(); StyleConstants.setForeground(m_debugAttr, COLOR_DEBUG); m_infoAttr = new SimpleAttributeSet(); StyleConstants.setForeground(m_infoAttr, COLOR_INFO); m_warnAttr = new SimpleAttributeSet(); StyleConstants.setForeground(m_warnAttr, COLOR_WARN); m_errorAttr = new SimpleAttributeSet(); StyleConstants.setForeground(m_errorAttr, COLOR_ERROR); initComponents(); }
From source file:org.astrojournal.logging.JTextPaneAppender.java
/** * Add the graphical JTextPane to capture the logging information. * /*from www.j a v a 2 s. co m*/ * @param textPane */ public static void addJTextPane(final JTextPane textPane) { // The application graphical output jTextPane = textPane; // Define JTextPane styles StyledDocument doc = jTextPane.getStyledDocument(); styleRegular = doc.addStyle("regular", null); StyleConstants.setForeground(styleRegular, Color.BLACK); StyleConstants.setFontSize(styleRegular, 12); StyleConstants.setFontFamily(styleRegular, "Arial"); styleBold = doc.addStyle("bold", styleRegular); StyleConstants.setBold(styleBold, true); styleItalic = doc.addStyle("italic", styleRegular); StyleConstants.setItalic(styleItalic, true); styleSmall = doc.addStyle("small", styleRegular); StyleConstants.setFontSize(styleSmall, 11); styleSmallItalic = doc.addStyle("smallItalic", styleSmall); StyleConstants.setItalic(styleSmallItalic, true); styleRed = doc.addStyle("red", styleBold); StyleConstants.setForeground(styleRed, Color.RED); styleBlue = doc.addStyle("blue", styleSmall); StyleConstants.setForeground(styleBlue, Color.BLUE); // Remove the Appender Console as the GUI is being initialised and // therefore having this information twice is not desirable. Logger logger = LogManager.getLogger("Console"); org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) logger; LoggerContext context = coreLogger.getContext(); coreLogger.removeAppender(context.getConfiguration().getAppender("Console")); }
From source file:org.nuxeo.launcher.gui.ColoredTextPane.java
/** * Append text at the end of document, choosing foreground and background colors, and bold attribute. * * @param text Text to append//w w w .j a v a 2 s . c o m * @param color Foreground color * @param bgColor Background color * @param isBold Is the text bold ? */ public void append(String text, Color color, Color bgColor, boolean isBold) { StyleConstants.setForeground(style, color); StyleConstants.setBackground(style, bgColor); StyleConstants.setBold(style, isBold); int len = doc.getLength(); try { doc.insertString(len, text + "\n", style); if (maxSize > 0 && len > maxSize) { doc.remove(0, len - maxSize); } } catch (BadLocationException e) { log.error(e); } if (follow) { setCaretPosition(doc.getLength()); } }
From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI.java
/** * Creates the component hosting the debug text. * /*from ww w . j a va 2 s .com*/ * @return See above. */ private JComponent createDebugTab() { debugTextPane = new JTextPane(); debugTextPane.setEditable(false); StyledDocument doc = (StyledDocument) debugTextPane.getDocument(); Style style = doc.addStyle(STYLE, null); StyleConstants.setForeground(style, Color.black); StyleConstants.setFontFamily(style, "SansSerif"); StyleConstants.setFontSize(style, 12); StyleConstants.setBold(style, false); JScrollPane sp = new JScrollPane(debugTextPane); sp.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { try { debugTextPane.setCaretPosition(debugTextPane.getDocument().getLength()); } catch (IllegalArgumentException ex) { // } } }); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(sp, BorderLayout.CENTER); return panel; }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Formats the text and displays it in a {@link JTextPane}. * //from w w w . j a v a2 s. c o m * @param text The text to display. * @param foreground The foreground color. * @return See above. */ public static JTextPane buildTextPane(String text, Color foreground) { if (text == null) text = ""; StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT); if (foreground != null) StyleConstants.setForeground(style, foreground); try { document.insertString(document.getLength(), text, style); } catch (BadLocationException e) { } JTextPane textPane = new JTextPane(document); textPane.setOpaque(false); textPane.setEditable(false); textPane.setFocusable(false); return textPane; }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** Builds the UI component displaying the exception.*/ public static JTextPane buildExceptionArea() { StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); JTextPane textPane = new JTextPane(document); textPane.setOpaque(false);/*www. ja va2 s. c om*/ textPane.setEditable(false); // Create one of each type of tab stop List<TabStop> list = new ArrayList<TabStop>(); // Create a left-aligned tab stop at 100 pixels from the left margin float pos = 15; int align = TabStop.ALIGN_LEFT; int leader = TabStop.LEAD_NONE; TabStop tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a right-aligned tab stop at 200 pixels from the left margin pos = 15; align = TabStop.ALIGN_RIGHT; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a center-aligned tab stop at 300 pixels from the left margin pos = 15; align = TabStop.ALIGN_CENTER; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a decimal-aligned tab stop at 400 pixels from the left margin pos = 15; align = TabStop.ALIGN_DECIMAL; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a tab set from the tab stops TabSet tabs = new TabSet(list.toArray(new TabStop[0])); // Add the tab set to the logical style; // the logical style is inherited by all paragraphs Style style = textPane.getLogicalStyle(); StyleConstants.setTabSet(style, tabs); textPane.setLogicalStyle(style); Style debugStyle = document.addStyle("StyleName", null); StyleConstants.setForeground(debugStyle, Color.BLACK); StyleConstants.setFontFamily(debugStyle, "SansSerif"); StyleConstants.setFontSize(debugStyle, 12); StyleConstants.setBold(debugStyle, false); return textPane; }