/** Creates the error area component. */ private void initErrorArea() { SimpleAttributeSet attribs = new SimpleAttributeSet(); StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontFamily(attribs, errorPane.getFont().getFamily()); StyleConstants.setForeground(attribs, Color.RED); errorPane.setParagraphAttributes(attribs, true); errorPane.setPreferredSize(new Dimension(100, 50)); errorPane.setMinimumSize(new Dimension(100, 50)); errorPane.setOpaque(false); }
private void loadStyles(StyledDocument doc) { Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(def, "Courier New"); // Add normal style Style normal = doc.addStyle("normal", def); StyleConstants.setForeground(def, Color.LIGHT_GRAY); // Add highlighted style from normal Style red = doc.addStyle("red", normal); StyleConstants.setForeground(red, Color.RED); }
public JConsole() { super(); setBackground(new Color(70, 70, 70)); setForeground(Color.WHITE); text = new MyJTextPane(); text.setAutoscrolls(true); final Font lFont = new Font("Monospaced", Font.PLAIN, 15); text.setText(""); text.setFont(lFont); text.setMargin(new Insets(5, 3, 5, 3)); text.addKeyListener(new MyKeyListener()); setViewportView(text); contextMenu = new JPopupMenu(); final ActionListener lActionListener = new MyActionListener(); contextMenu.add(new JMenuItem(CMD_CUT)).addActionListener(lActionListener); contextMenu.add(new JMenuItem(CMD_COPY)).addActionListener(lActionListener); contextMenu.add(new JMenuItem(CMD_PASTE)).addActionListener(lActionListener); text.addMouseListener(new MyMouseListener()); MutableAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.BLACK); attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.WHITE); attrOut = attr; attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.RED); StyleConstants.setItalic(attr, true); StyleConstants.setBold(attr, true); attrError = attr; try { fromConsoleStream = new PipedOutputStream(); in = new PipedInputStream((PipedOutputStream) fromConsoleStream); final PipedOutputStream lOutPipe = new PipedOutputStream(); out = new PrintStream(lOutPipe); final PipedOutputStream lErrPipe = new PipedOutputStream(); err = new PrintStream(lErrPipe); } catch (IOException e) { e.printStackTrace(); } requestFocus(); }
private void initializeStyles() { errorStyle = doc.addStyle( "errorStyle", StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE)); errorStyleRed = doc.addStyle("errorStyleRed", errorStyle); StyleConstants.setForeground(errorStyleRed, Color.RED); errorStyleMono = doc.addStyle("errorStyleMono", errorStyle); StyleConstants.setFontFamily(errorStyleMono, "Monospaced"); }
static { DEFAULT_NORMAL = new SimpleAttributeSet(); StyleConstants.setForeground(DEFAULT_NORMAL, Color.BLACK); StyleConstants.setFontFamily(DEFAULT_NORMAL, DEFAULT_FONT_FAMILY); StyleConstants.setFontSize(DEFAULT_NORMAL, DEFAULT_FONT_SIZE); DEFAULT_COMMENT = new SimpleAttributeSet(); StyleConstants.setForeground(DEFAULT_COMMENT, Color.GRAY); StyleConstants.setFontFamily(DEFAULT_COMMENT, DEFAULT_FONT_FAMILY); StyleConstants.setFontSize(DEFAULT_COMMENT, DEFAULT_FONT_SIZE); DEFAULT_STRING = new SimpleAttributeSet(); StyleConstants.setForeground(DEFAULT_STRING, Color.RED); StyleConstants.setFontFamily(DEFAULT_STRING, DEFAULT_FONT_FAMILY); StyleConstants.setFontSize(DEFAULT_STRING, DEFAULT_FONT_SIZE); // default style for new keyword types DEFAULT_KEYWORD = new SimpleAttributeSet(); StyleConstants.setForeground(DEFAULT_KEYWORD, Color.BLUE); StyleConstants.setBold(DEFAULT_KEYWORD, false); StyleConstants.setFontFamily(DEFAULT_KEYWORD, DEFAULT_FONT_FAMILY); StyleConstants.setFontSize(DEFAULT_KEYWORD, DEFAULT_FONT_SIZE); }
/** * Update the color in the default style of the document. * * @param color the new color to use or null to remove the color attribute from the document's * style */ private void updateForeground(Color color) { StyledDocument doc = (StyledDocument) getComponent().getDocument(); Style style = doc.getStyle(StyleContext.DEFAULT_STYLE); if (style == null) { return; } if (color == null) { style.removeAttribute(StyleConstants.Foreground); } else { StyleConstants.setForeground(style, color); } }
public void coloration() { String text = editor.getTextPaneEditor().getText().replaceAll("\n", " "); final StyledDocument doc = editor.getTextPaneEditor().getStyledDocument(); final MutableAttributeSet normal = new SimpleAttributeSet(); StyleConstants.setForeground(normal, Color.black); StyleConstants.setBold(normal, false); SwingUtilities.invokeLater( new Runnable() { public void run() { doc.setCharacterAttributes(0, doc.getLength(), normal, true); } }); colorationPrimitives(text, doc); colorationPolicyScript(text, doc); }
public void colorationPolicyScript(String text, final StyledDocument doc) { Pattern p = Pattern.compile("(GraphOScript)"); Matcher m = p.matcher(text); while (m.find() == true) { MutableAttributeSet attri = new SimpleAttributeSet(); StyleConstants.setForeground(attri, Color.orange); StyleConstants.setBold(attri, true); final int start = m.start(0); final int end = m.end(0); final int length = end - start; final MutableAttributeSet style = attri; SwingUtilities.invokeLater( new Runnable() { public void run() { doc.setCharacterAttributes(start, length, style, true); } }); } }
private void highlightArea(int pos, int len, String col) { SimpleAttributeSet attrs = new SimpleAttributeSet(); StyleConstants.setForeground(attrs, getColour(col)); document.setCharacterAttributes(pos, len, attrs, true); }
/** * Sets the foreground (font) color of the specified attribute. * * @param attr attribute to apply this color to * @param c the color to use */ public static void setAttributeColor(MutableAttributeSet attr, Color c) { StyleConstants.setForeground(attr, c); }
static { StyleConstants.setForeground(PLAIN_ATTR, Color.black); StyleConstants.setBold(PLAIN_ATTR, false); StyleConstants.setFontFamily(PLAIN_ATTR, "Helvetica"); StyleConstants.setFontSize(PLAIN_ATTR, 14); }