/** 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); }
public JWrapLabel(String txt) { super(); setEditable(false); setText(txt); SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setAlignment(set, StyleConstants.ALIGN_CENTER); StyleConstants.setFontFamily(set, "Arial"); StyleConstants.setFontSize(set, 13); setParagraphAttributes(set, true); }
/** * Returns StyledDocument object containing preformatted LEM Class description, followed by the * list of attributes that the Class has. * * @return the StyledDocument of the ClassNode. */ public StyledDocument getStyledDocument() { StyledDocument doc = new StyledDocument(); SimpleAttributeSet s = new SimpleAttributeSet(); StyleConstants.setFontFamily(s, "Times New Roman"); StyleConstants.setFontSize(s, 14); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.blue); StyledElement element = new StyledElement(toString() + "\n", s); doc.addStyle(element); SimpleAttributeSet s1 = new SimpleAttributeSet(); StyleConstants.setFontFamily(s1, "Times New Roman"); StyleConstants.setFontSize(s1, 14); StyleConstants.setBold(s1, false); StyleConstants.setForeground(s1, Color.black); StyledElement element1 = new StyledElement(getDescription(), s1); doc.addStyle(element1); StyledElement element2 = new StyledElement("\n-------------- Attributes ----------------\n", s1); doc.addStyle(element2); doc.append(attributeListing); return doc; }
private void initAttributeSets() { conRegular = new SimpleAttributeSet(); StyleConstants.setFontFamily(conRegular, prefs.mainFont); StyleConstants.setFontSize(conRegular, prefs.statusFontSize); StyleConstants.setForeground(conRegular, Color.white); conIrregular = new SimpleAttributeSet(); StyleConstants.setFontFamily(conIrregular, prefs.mainFont); StyleConstants.setFontSize(conIrregular, prefs.statusFontSize); StyleConstants.setForeground(conIrregular, Color.white); StyleConstants.setBold(conIrregular, true); }
public void addStylesToDocument(StyledDocument doc) { Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "Norasi"); Style s = doc.addStyle("black", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.BLACK); StyleConstants.setFontSize(s, 15); s = doc.addStyle("orange", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.ORANGE); StyleConstants.setFontSize(s, 14); s = doc.addStyle("blue", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.BLUE); StyleConstants.setFontSize(s, 14); s = doc.addStyle("red", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.RED); StyleConstants.setFontSize(s, 14); s = doc.addStyle("magenta", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.MAGENTA); StyleConstants.setFontSize(s, 14); }
public SimpleAttributeSet getAttrSet() { attrSet = new SimpleAttributeSet(); if (fontName != null) { StyleConstants.setFontFamily(attrSet, fontName); } switch (fontStyle) { case MessageWithAttrib.GENERAL: StyleConstants.setBold(attrSet, false); StyleConstants.setItalic(attrSet, false); break; case MessageWithAttrib.BOLD: StyleConstants.setBold(attrSet, true); StyleConstants.setItalic(attrSet, false); break; case MessageWithAttrib.ITALIC: StyleConstants.setBold(attrSet, false); StyleConstants.setItalic(attrSet, true); break; case MessageWithAttrib.BOLD_ITALIC: StyleConstants.setBold(attrSet, true); StyleConstants.setItalic(attrSet, true); break; } StyleConstants.setFontSize(attrSet, fontSize); if (fontColor != null) { StyleConstants.setForeground(attrSet, fontColor); } return attrSet; }
private void initStyles() { sc = new StyleContext(); Style parent = sc.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(parent, "courier"); StyleConstants.setFontSize(parent, 13); styleElementName = sc.addStyle("elementName", parent); StyleConstants.setForeground(styleElementName, new Color(128, 0, 0)); styleAttribtuteName = sc.addStyle("attributeName", parent); StyleConstants.setForeground(styleAttribtuteName, Color.RED); styleAttribtuteValue = sc.addStyle("attributeValue", parent); styleContent = sc.addStyle("content", parent); StyleConstants.setBackground(styleContent, new Color(200, 255, 100)); styleOperator = sc.addStyle("operator", parent); StyleConstants.setForeground(styleOperator, Color.BLUE); StyleConstants.setBold(styleOperator, true); styleComments = sc.addStyle("comments", parent); StyleConstants.setForeground(styleComments, new Color(128, 128, 128)); // Hooker's green styleCData = sc.addStyle("cdata", parent); StyleConstants.setForeground(styleCData, new Color(30, 30, 0)); StyleConstants.setBackground(styleCData, new Color(250, 250, 240)); styleProcessingInstructions = sc.addStyle("processingIntruction", parent); styleDOCTYPE = sc.addStyle("doctype", styleComments); }
public SimpleAttributeSet getAttributeSet() { if (fontName != null && !"".equals(fontName)) { StyleConstants.setFontFamily(attrSet, fontName); } if (fontStyle == 0) { // 常规 StyleConstants.setBold(attrSet, false); StyleConstants.setItalic(attrSet, false); } else if (fontStyle == 1) { // 粗体 StyleConstants.setBold(attrSet, true); StyleConstants.setItalic(attrSet, false); } else if (fontStyle == 2) { // 斜体 StyleConstants.setBold(attrSet, false); StyleConstants.setItalic(attrSet, true); } else if (fontStyle == 3) { // 粗体 斜体 StyleConstants.setBold(attrSet, true); StyleConstants.setItalic(attrSet, true); } if (foreColor != null) { // 背景色 StyleConstants.setForeground(attrSet, foreColor); } if (backColor != null) { // 前景色 StyleConstants.setBackground(attrSet, backColor); } if (fontSize != -1) { StyleConstants.setFontSize(attrSet, fontSize); } return attrSet; }
private void resetStyles() { doc.setParagraphAttributes(0, doc.getLength(), plainStyle, true); StyleConstants.setFontSize(fontSizeStyle, 14); Font f = plainFont; StyleConstants.setFontFamily(fontSizeStyle, f.getFamily()); doc.setParagraphAttributes(0, doc.getLength(), fontSizeStyle, false); setupFont(); }
private void setTextAttribute() { BOLD_BLACK = new SimpleAttributeSet(); StyleConstants.setForeground(BOLD_BLACK, Color.red); StyleConstants.setBold(BOLD_BLACK, true); StyleConstants.setFontFamily(BOLD_BLACK, "Helvetica"); StyleConstants.setFontSize(BOLD_BLACK, 20); }
// ---------------------------------------------------------------------------- public AttributeSet getAttributes() { if (attributes_ != null) { StyleConstants.setFontFamily(attributes_, font_names_.getSelected()); StyleConstants.setFontSize(attributes_, font_sizes_.getSelectedInt()); } return attributes_; }
/** * Generate an attribute set for links. * * @param action the action to perform * @return the attribute set */ public static SimpleAttributeSet getActionStyle(ActionListener action) { SimpleAttributeSet style = new SimpleAttributeSet(); StyleConstants.setForeground(style, Color.blue); StyleConstants.setUnderline(style, true); StyleConstants.setFontFamily(style, font); StyleConstants.setFontSize(style, fontSize); style.addAttribute(ACTION_ATTRIBUTE, action); return style; }
/** Inits the Styles bold and regular */ private void initStyles() { Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = this.addStyle("regular", def); StyleConstants.setFontFamily(def, "SansSerif"); Style s = this.addStyle("bold", regular); StyleConstants.setBold(s, true); }
/** * Create an attribute set for stylish text. * * @param color the color * @param italic whether the text should be slanted * @param bold whether the text should be bold * @param fontName the name of the font to use * @param fontSize the font size to use * @return the attribute set */ public static SimpleAttributeSet getStyle( Color color, boolean italic, boolean bold, String fontName, int fontSize) { SimpleAttributeSet style = new SimpleAttributeSet(); StyleConstants.setForeground(style, color); StyleConstants.setItalic(style, italic); StyleConstants.setBold(style, bold); StyleConstants.setFontFamily(style, fontName); StyleConstants.setFontSize(style, fontSize); return style; }
/** Set default value for all the attributes */ protected static void useDefaultStyle() { defaultStyle = true; StyleConstants.setForeground(fontColorAttribute, defaultForeground); // StyleConstants.setBackground(fontColorAttribute, defaultBackground); StyleConstants.setFontFamily(fontColorAttribute, defaultFamily); StyleConstants.setFontSize(fontColorAttribute, defaultSize); StyleConstants.setBold(fontColorAttribute, false); StyleConstants.setItalic(fontColorAttribute, false); StyleConstants.setUnderline(fontColorAttribute, false); }
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"); }
protected void addStylesToDocument(final StyledDocument doc) { // Initialize some styles. final Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); final Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "SansSerif"); Style s = doc.addStyle("entailment", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.blue); s = doc.addStyle("color_blue", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.BLUE); s = doc.addStyle("color_red", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.RED); s = doc.addStyle("color_green", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.GREEN); s = doc.addStyle("color_cyan", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.CYAN); s = doc.addStyle("color_dark_gray", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.DARK_GRAY); s = doc.addStyle("color_pink", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.PINK); s = doc.addStyle("color_yellow", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.YELLOW); s = doc.addStyle("color_magenta", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.MAGENTA); s = doc.addStyle("color_orange", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.ORANGE); s = doc.addStyle("unknown", regular); StyleConstants.setBold(s, true); StyleConstants.setUnderline(s, true); s = doc.addStyle("system", regular); StyleConstants.setBold(s, true); }
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); }
/** Creates the text area. */ private void initTextArea() { textArea.setOpaque(false); textArea.setEditable(false); StyledDocument doc = textArea.getStyledDocument(); MutableAttributeSet standard = new SimpleAttributeSet(); StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER); StyleConstants.setFontFamily(standard, textArea.getFont().getFamily()); StyleConstants.setFontSize(standard, 12); doc.setParagraphAttributes(0, 0, standard, true); parentWindow.addSearchFieldListener(this); }
private void _applyFontStyleForSelection(Font font) { StyledDocument doc = mTextEditor.getStyledDocument(); MutableAttributeSet attrs = mTextEditor.getInputAttributes(); StyleConstants.setFontFamily(attrs, font.getFamily()); StyleConstants.setFontSize(attrs, font.getSize()); StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0)); StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0)); StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0)); int start = mTextEditor.getSelectionStart(); int end = mTextEditor.getSelectionEnd(); doc.setCharacterAttributes(start, (end - start), attrs, false); }
/** * Change default attributes with user option * * @param fontFamily Text Font Family (Helvetica, Times etc.) * @param fontType Text Font Type (Plain, Bold, Italic etc.) * @param fontSize Text Font Size (8 ... 24) * @param fgColor Text foreground color * @param bgColor Text background color */ protected static void changeStyle( String fontFamily, String fontType, int fontSize, Color fgColor, Color bgColor) { defaultStyle = false; StyleConstants.setForeground(fontColorAttribute, fgColor); // StyleConstants.setBackground(fontColorAttribute, bgColor); StyleConstants.setFontFamily(fontColorAttribute, fontFamily); StyleConstants.setFontSize(fontColorAttribute, fontSize); if (fontType != null) { if (fontType.equals("Italic")) StyleConstants.setItalic(fontColorAttribute, true); else if (fontType.equals("Bold")) StyleConstants.setBold(fontColorAttribute, true); else if (fontType.equals("Underline")) StyleConstants.setUnderline(fontColorAttribute, true); } }
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); }
private void setStyles() { doc = helpPanel.getjTextPane1().getStyledDocument(); style = helpPanel.getjTextPane1().addStyle("I'm a Style", null); StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER); StyleConstants.setForeground(style, Color.PINK); StyleConstants.setFontSize(style, 20); StyleConstants.setFontFamily(style, "cambria"); StyleConstants.setBold(style, true); StyleConstants.setSpaceAbove(style, 4); style2 = helpPanel.getjTextPane1().addStyle("I'm a Style", null); StyleConstants.setFontFamily(style2, "cambria"); StyleConstants.setForeground(style2, Color.BLUE); StyleConstants.setBold(style2, true); StyleConstants.setAlignment(style2, StyleConstants.ALIGN_JUSTIFIED); StyleConstants.setFontSize(style2, 12); styleW = helpPanel.getjTextPane1().addStyle("I'm a Style", null); StyleConstants.setFontFamily(styleW, "cambria"); StyleConstants.setAlignment(styleW, StyleConstants.ALIGN_JUSTIFIED); StyleConstants.setFontSize(styleW, 12); styleWB = helpPanel.getjTextPane1().addStyle("I'm a Style", null); StyleConstants.setFontFamily(styleWB, "cambria"); StyleConstants.setBold(styleWB, true); StyleConstants.setAlignment(styleWB, StyleConstants.ALIGN_JUSTIFIED); StyleConstants.setFontSize(styleWB, 12); styleP = helpPanel.getjTextPane1().addStyle("I'm a Style", null); StyleConstants.setFontFamily(styleP, "cambria"); StyleConstants.setForeground(styleP, Color.MAGENTA); StyleConstants.setBold(styleP, true); StyleConstants.setAlignment(styleP, StyleConstants.ALIGN_JUSTIFIED); StyleConstants.setFontSize(styleP, 12); }
private void setupStyle() { Document document = myHTMLViewer.getDocument(); if (!(document instanceof StyledDocument)) { return; } StyledDocument styledDocument = (StyledDocument) document; EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); Style style = styledDocument.addStyle("active", null); StyleConstants.setFontFamily(style, scheme.getEditorFontName()); StyleConstants.setFontSize(style, scheme.getEditorFontSize()); styledDocument.setCharacterAttributes(0, document.getLength(), style, false); }
private void addStylesToHexDump(StyledDocument doc) { Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style base = doc.addStyle("base", def); StyleConstants.setFontFamily(base, "Monospaced"); Style regular = doc.addStyle("regular", base); // StyleConstants.setUnderline(regular , true); Style s = doc.addStyle("d", regular); StyleConstants.setBackground(s, new Color(72, 164, 255)); s = doc.addStyle("Q", regular); StyleConstants.setBackground(s, new Color(255, 255, 128)); s = doc.addStyle("h", regular); StyleConstants.setBackground(s, Color.ORANGE); s = doc.addStyle("s", regular); StyleConstants.setBackground(s, new Color(156, 220, 156)); s = doc.addStyle("S", regular); StyleConstants.setBackground(s, new Color(156, 220, 156)); s = doc.addStyle("c", regular); StyleConstants.setBackground(s, Color.PINK); s = doc.addStyle("f", regular); StyleConstants.setBackground(s, Color.LIGHT_GRAY); Color bxColor = new Color(255, 234, 213); s = doc.addStyle("b", regular); StyleConstants.setBackground(s, bxColor); s = doc.addStyle("x", regular); StyleConstants.setBackground(s, bxColor); s = doc.addStyle("op", regular); StyleConstants.setBackground(s, Color.YELLOW); s = doc.addStyle("selected", regular); StyleConstants.setBackground(s, Color.BLUE); s = doc.addStyle("chk", regular); StyleConstants.setBackground(s, Color.GREEN); }
void finishInit() { // Create 3 styles associated with the text panes Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(def, "SansSerif"); Style regular0 = jTextPane.addStyle("regular", def); Style regular1 = commentPane.addStyle("regular", def); Style s0 = jTextPane.addStyle("old", regular0); Style s1 = commentPane.addStyle("old", regular1); StyleConstants.setBackground(s0, Color.yellow); StyleConstants.setBackground(s1, Color.yellow); s0 = jTextPane.addStyle("new", regular0); StyleConstants.setBackground(s0, Color.pink); s1 = commentPane.addStyle("new", regular1); StyleConstants.setBackground(s1, Color.pink); }
public void displaySharkey() { displayDataState = DisplayDataState.SHARKEY; clearText(); style = jTextPane.addStyle("STYLE", null); Document doc = jTextPane.getStyledDocument(); try { StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW); StyleConstants.setFontSize(style, 13); StyleConstants.setFontFamily(style, "Menlo"); doc.insertString(doc.getLength(), SharkBG.SHARKEY, style); } catch (BadLocationException e) { e.printStackTrace(); } jTextPane.setDocument(doc); }
private void applyFontSize() { Document document = myEditorPane.getDocument(); if (!(document instanceof StyledDocument)) { return; } StyledDocument styledDocument = (StyledDocument) document; if (myFontSizeStyle == null) { myFontSizeStyle = styledDocument.addStyle("active", null); } EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); StyleConstants.setFontSize(myFontSizeStyle, scheme.getQuickDocFontSize().getSize()); if (Registry.is("documentation.component.editor.font")) { StyleConstants.setFontFamily(myFontSizeStyle, scheme.getEditorFontName()); } styledDocument.setCharacterAttributes(0, document.getLength(), myFontSizeStyle, false); }
/** * Sets the reason of a call failure if one occurs. The renderer should display this reason to the * user. * * @param reason the reason to display */ public void setErrorReason(final String reason) { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater( new Runnable() { public void run() { setErrorReason(reason); } }); return; } if (errorMessageComponent == null) { errorMessageComponent = new JTextPane(); JTextPane textPane = (JTextPane) errorMessageComponent; textPane.setEditable(false); textPane.setOpaque(false); StyledDocument doc = textPane.getStyledDocument(); MutableAttributeSet standard = new SimpleAttributeSet(); StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER); StyleConstants.setFontFamily(standard, textPane.getFont().getFamily()); StyleConstants.setFontSize(standard, 12); doc.setParagraphAttributes(0, 0, standard, true); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 4; constraints.weightx = 1; constraints.weighty = 0; constraints.insets = new Insets(5, 0, 0, 0); add(errorMessageComponent, constraints); this.revalidate(); } errorMessageComponent.setText(reason); if (isVisible()) errorMessageComponent.repaint(); }
private void displayCenteredText(String text) { textArea.setText(""); text = "\n\n\n" + text; SimpleAttributeSet attribs = new SimpleAttributeSet(); 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 { 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); } }