Java 类javax.swing.text.StyleConstants 实例源码

项目:Tarski    文件:SwingLogPanel.java   
/** 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); }
}
项目:litiengine    文件:ConsoleLogHandler.java   
@Override
public void publish(final LogRecord record) {
  StyledDocument doc = textPane.getStyledDocument();
  SimpleAttributeSet keyWord = new SimpleAttributeSet();
  StyleConstants.setForeground(keyWord, getColor(record.getLevel()));
  StyleConstants.setBold(keyWord, true);
  StyleConstants.setFontSize(keyWord, 12);
  StyleConstants.setFontFamily(keyWord, CONSOLE_FONT);

  SimpleAttributeSet text = new SimpleAttributeSet();
  StyleConstants.setForeground(text, getColor(record.getLevel()));
  StyleConstants.setFontFamily(text, CONSOLE_FONT);
  try {
    doc.insertString(doc.getLength(), String.format("%1$-10s", record.getLevel()), keyWord);
    if (record.getParameters() != null) {
      doc.insertString(doc.getLength(), MessageFormat.format(record.getMessage(), record.getParameters()), text);
    } else {
      doc.insertString(doc.getLength(), record.getMessage(), text);
    }

    doc.insertString(doc.getLength(), "\n", text);
  } catch (BadLocationException e) {
  }

  textPane.setCaretPosition(doc.getLength());
}
项目:Tarski    文件:OurSyntaxDocument.java   
/** Changes the font and tabsize for the document. */
public final void do_setFont(String fontName, int fontSize, int tabSize) {
   if (tabSize < 1) tabSize = 1; else if (tabSize > 100) tabSize = 100;
   if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize) return;
   this.font = fontName;
   this.fontSize = fontSize;
   this.tabSize = tabSize;
   for(MutableAttributeSet s: all) { StyleConstants.setFontFamily(s, fontName);  StyleConstants.setFontSize(s, fontSize); }
   do_reapplyAll();
   BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); // this is used to derive the tab width
   int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
   TabStop[] pos = new TabStop[100];
   for(int i=0; i<100; i++) { pos[i] = new TabStop(i*gap + gap); }
   StyleConstants.setTabSet(tabset, new TabSet(pos));
   setParagraphAttributes(0, getLength(), tabset, false);
}
项目:incubator-netbeans    文件:ViewFactoryImpl.java   
public View create(Element elem) {
    String kind = elem.getName();
    if (kind != null) {
        if (kind.equals(AbstractDocument.ContentElementName)) {
            return new LabelView(elem);
        } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
            return null;
        } else if (kind.equals(AbstractDocument.SectionElementName)) {
            return new DocumentView(elem);
        } else if (kind.equals(StyleConstants.ComponentElementName)) {
            return new ComponentView(elem);
        } else if (kind.equals(StyleConstants.IconElementName)) {
            return new IconView(elem);
        }
    }
    return null;
}
项目:incubator-netbeans    文件:ReadOnlyFilesHighlighting.java   
public ReadOnlyFilesHighlighting(Document doc) {
    this.document = doc;
    FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class);
    if (fcs != null) {
        AttributeSet readOnlyFilesColoring = fcs.getFontColors("readonly-files"); //NOI18N
        if (readOnlyFilesColoring != null) {
            this.attribs = AttributesUtilities.createImmutable(
                    readOnlyFilesColoring,
                    EXTENDS_EOL_OR_EMPTY_ATTR_SET);
        } else {
            this.attribs = null;
        }
    } else {
        this.attribs = null;
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("~~~ this=" + s2s(this) + ", doc=" + s2s(doc) + ", file=" + fileFromDoc(doc) //NOI18N
                + ", attribs=" + attribs + (attribs != null ? ", bg=" + attribs.getAttribute(StyleConstants.Background) : "")); //NOI18N
    }
}
项目:Yass    文件:YassLyrics.java   
/**
 * Description of the Method
 */
public void editLyrics() {
    if (lyricsArea.isEditable()) {
        return;
    }

    if (initialBlinkRate < 0) {
        initialBlinkRate = lyricsArea.getCaret().getBlinkRate();
    }
    lyricsArea.requestFocus();
    lyricsArea.setEditable(true);
    StyleConstants.setBackground(
            notSelectStyle,
            nofontBG);
    lyricsArea.getCaret().setVisible(true);
    lyricsArea.getCaret().setBlinkRate(initialBlinkRate);
    lyricsArea.getStyledDocument().setCharacterAttributes(0,
            lyricsArea.getStyledDocument().getLength(), notSelectStyle,
            false);
    tableSelectionListener.valueChanged(null);
}
项目:incubator-netbeans    文件:ColorsManager.java   
private static AttributeSet getUnusedFieldAttributes () {
    if (unusedFieldAttributeSet == null) {
        SimpleAttributeSet sas = new SimpleAttributeSet ();
        StyleConstants.setForeground (sas, new Color (115, 115, 115));
        StyleConstants.setBold (sas, true);
        unusedFieldAttributeSet = sas;
    }
    return unusedFieldAttributeSet;
}
项目:incubator-netbeans    文件:ComposedTextHighlighting.java   
private static AttributedString getComposedTextAttribute(DocumentEvent e) {
    if (e instanceof BaseDocumentEvent) {
        AttributeSet attribs = ((BaseDocumentEvent) e).getChangeAttributes();
        if (attribs != null) {
            Object value = attribs.getAttribute(StyleConstants.ComposedTextAttribute);
            if (value instanceof AttributedString) {
                return (AttributedString) value;
            }
        }
    }
    return null;
}
项目:incubator-netbeans    文件:ColorsManager.java   
private static Map getCurrentColors(Language l) {
    // current colors
    FontColorSettingsFactory fcsf = EditorSettings.getDefault().
            getFontColorSettings(new String[] {l.getMimeType()});
    Collection<AttributeSet> colors = fcsf.getAllFontColors("NetBeans");
    Map<String,AttributeSet> colorsMap = new HashMap<String,AttributeSet> ();
    Iterator<AttributeSet> it = colors.iterator();
    while (it.hasNext()) {
        AttributeSet as = it.next();
        colorsMap.put(
                (String) as.getAttribute(StyleConstants.NameAttribute),
                as
                );
    }
    return colorsMap;
}
项目:incubator-netbeans    文件:UIUtilities.java   
private static String color(String string, AttributeSet set) {
    if (set == null) {
        return string;
    }
    if (string.trim().length() == 0) {
        return string.replace(" ", "&nbsp;").replace("\n", "<br>"); //NOI18N
    }
    StringBuffer buf = new StringBuffer(string);
    if (StyleConstants.isBold(set)) {
        buf.insert(0, "<b>"); //NOI18N
        buf.append("</b>"); //NOI18N
    }
    if (StyleConstants.isItalic(set)) {
        buf.insert(0, "<i>"); //NOI18N
        buf.append("</i>"); //NOI18N
    }
    if (StyleConstants.isStrikeThrough(set)) {
        buf.insert(0, "<s>"); // NOI18N
        buf.append("</s>"); // NOI18N
    }
    buf.insert(0, "<font color=" + getHTMLColor(LFCustoms.getForeground(set)) + ">"); //NOI18N
    buf.append("</font>"); //NOI18N
    return buf.toString();
}
项目:incubator-netbeans    文件:FontColorSettingsImplTest.java   
public void testAllLanguagesTheCrapWay() {
    Collection<AttributeSet> colorings = EditorSettings.getDefault().getFontColorSettings(new String[0]).getAllFontColors(EditorSettingsImpl.DEFAULT_PROFILE);
    assertNotNull("Can't get colorings for all languages", colorings);

    AttributeSet attribs = null;
    for(AttributeSet coloring : colorings) {
        String name = (String) coloring.getAttribute(StyleConstants.NameAttribute);
        if (name != null && name.equals("test-all-languages-set-all")) {
            attribs = coloring;
            break;
        }
    }

    assertNotNull("Can't find test-all-languages-set-all coloring", attribs);
    assertEquals("Wrong color", new Color(0x0A0B0C), attribs.getAttribute(StyleConstants.Background));
    assertEquals("Wrong color", new Color(0x0D0E0F), attribs.getAttribute(StyleConstants.Foreground));
    assertEquals("Wrong color", new Color(0x010203), attribs.getAttribute(StyleConstants.Underline));
    assertEquals("Wrong color", new Color(0x040506), attribs.getAttribute(StyleConstants.StrikeThrough));
    assertEquals("Wrong color", new Color(0x070809), attribs.getAttribute(EditorStyleConstants.WaveUnderlineColor));
}
项目:incubator-netbeans    文件:VCSHyperlinkSupport.java   
@Override
public void insertString(StyledDocument sd, Style style) throws BadLocationException {
    if(style == null) {
        style = authorStyle;
    }
    sd.insertString(sd.getLength(), author, style);

    String iconStyleName = AUTHOR_ICON_STYLE + author;
    Style iconStyle = sd.getStyle(iconStyleName);
    if(iconStyle == null) {
        iconStyle = sd.addStyle(iconStyleName, null);
        StyleConstants.setIcon(iconStyle, kenaiUser.getIcon());
    }
    sd.insertString(sd.getLength(), " ", style);
    sd.insertString(sd.getLength(), " ", iconStyle);
}
项目:incubator-netbeans    文件:AnnotationColorsPanel.java   
public VersioningSystemColors(OptionsPanelColorProvider provider) {
    this.colors = provider.getColors();
    if (colors == null) {
        throw new NullPointerException("Null colors for " + provider); // NOI18N
    }
    this.provider = provider;
    // initialize saved colors list
    savedColorAttributes = new ArrayList<AttributeSet>(colors.size());
    for (Map.Entry<String, Color[]> e : colors.entrySet()) {
        SimpleAttributeSet sas = new SimpleAttributeSet();
        StyleConstants.setBackground(sas, e.getValue()[0]);
        sas.addAttribute(StyleConstants.NameAttribute, e.getKey());
        sas.addAttribute(EditorStyleConstants.DisplayName, e.getKey());
        savedColorAttributes.add(sas);
    }
}
项目:incubator-netbeans    文件:QueryBuilderSqlTextArea.java   
public QueryBuilderSqlTextArea(QueryBuilder queryBuilder) {
        super();
        _queryBuilder = queryBuilder;
        createSqlTextPopup();
        // Get Netbeans-registered EditorKit for SQL content
    setEditorKit(CloneableEditorSupport.getEditorKit("text/x-sql"));
        if ( SYNTAX_HIGHLIGHT ) {
            addKeyListener(this);
        }

        // set the bold attribute
        // colors chosen from :
        // http://ui.netbeans.org/docs/hi/annotations/index2.html
        StyleConstants.setForeground(keyword,new Color(0,0,153));
        StyleConstants.setForeground(schema, new Color(0,111,0));
        StyleConstants.setForeground(column,new Color(120,0,0));

        // Add support for code completion (comment out, breaks syntax highlighting)
//        QueryBuilderSqlCompletion doc = new QueryBuilderSqlCompletion( this, sqlReservedWords);
//        this.setDocument(doc);
    }
项目:incubator-netbeans    文件:SettingsProviderTest.java   
public void testInheritanceForAntPlusXml() {
    MimePath mimePath = MimePath.parse("text/ant+xml");
    FontColorSettings fcs = MimeLookup.getLookup(mimePath).lookup(FontColorSettings.class);

    AttributeSet antXmlAttribs = fcs.getTokenFontColors("test-inheritance-ant-xml");
    assertNotNull("Can't find coloring defined for text/ant+xml", antXmlAttribs);
    assertEquals("Wrong bgColor in coloring defined for text/ant+xml", new Color(0xAA0000), antXmlAttribs.getAttribute(StyleConstants.Background));

    AttributeSet xmlAttribs = fcs.getTokenFontColors("test-inheritance-xml");
    assertNotNull("Can't find coloring defined for text/xml", xmlAttribs);
    assertEquals("Wrong bgColor in coloring defined for text/xml", new Color(0x00BB00), xmlAttribs.getAttribute(StyleConstants.Background));

    AttributeSet attribs = fcs.getTokenFontColors("test-all-languages-super-default");
    assertNotNull("Can't find coloring defined for root", attribs);
    assertEquals("Wrong bgColor in coloring defined for root", new Color(0xABCDEF), attribs.getAttribute(StyleConstants.Background));
}
项目:incubator-netbeans    文件:DiffColorsPanel.java   
private void refreshUI () {
    int index = lCategories.getSelectedIndex();
    if (index < 0) {
        cbBackground.setEnabled(false);
        return;
    }
    cbBackground.setEnabled(true);

    List<AttributeSet> categories = getCategories();
 AttributeSet category = categories.get(index);

    listen = false;
    // set values
    cbBackground.setSelectedColor((Color) category.getAttribute(StyleConstants.Background));
    listen = true;
}
项目:SER316-Ingolstadt    文件:AltHTMLWriter.java   
/**
 * Returns true if the StyleConstants.NameAttribute is
 * equal to the tag that is passed in as a parameter.
 */
protected boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        if (name == tag) {
            return true;
        }
    }
    return false;
}
项目:Wilmersdorf_SER316    文件:HTMLEditor.java   
public void cAlignActionB_actionPerformed(ActionEvent e) {
    HTMLEditorKit.AlignmentAction aa =
        new HTMLEditorKit.AlignmentAction(
            "centerAlign",
            StyleConstants.ALIGN_CENTER);
    aa.actionPerformed(e);
}
项目:incubator-netbeans    文件:AntHighlightsLayerFactory.java   
public @Override HighlightsLayer[] createLayers(final Context context) {
    AttributeSet _attrs = MimeLookup.getLookup("text/x-jsp").lookup(FontColorSettings.class).getTokenFontColors("expression-language"); // NOI18N
    final AttributeSet attrs;
    if (_attrs == null) {
        // Fallback from web.core.syntax/src/org/netbeans/modules/web/core/syntax/resources/fontsColors.xml:
        SimpleAttributeSet _sattrs = new SimpleAttributeSet();
        _sattrs.addAttribute(StyleConstants.Background, new Color(0xe3f2e1));
        attrs = _sattrs;
    } else {
        attrs = _attrs;
    }
    return new HighlightsLayer[] {HighlightsLayer.create("ant", ZOrder.SYNTAX_RACK.forPosition(10), true,
            new AntHighlightsContainer((AbstractDocument) context.getDocument(), attrs))}; // NOI18N
}
项目:rapidminer    文件:ColoredJTextPane.java   
public ColoredJTextPane() {
    super();
    setDocument(new DefaultStyledDocument() {

        private static final long serialVersionUID = 1L;

        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            super.insertString(offs, str, a);

            // now color all texts again
            // do coloring of words but ignore keys unless it is word termination
            String text = getText(0, getLength());
            char[] chars = text.toCharArray();
            StyleContext context = StyleContext.getDefaultStyleContext();
            int lastStart = 0;
            boolean charactersSinceLastStart = false;
            for (int i = 0; i < text.length(); i++) {
                if (!Character.isLetter(chars[i])) {
                    if (charactersSinceLastStart) {
                        AttributeSet attributeSet = context.addAttribute(SimpleAttributeSet.EMPTY,
                                StyleConstants.Foreground, getColor(new String(chars, lastStart, i - lastStart)));
                        setCharacterAttributes(lastStart, i - lastStart, attributeSet, true);
                    }
                    lastStart = i + 1;
                    charactersSinceLastStart = false;
                } else {
                    charactersSinceLastStart = true;
                }
            }
        }
    });

}
项目:Cognizant-Intelligent-Test-Scripter    文件:MessageConsole.java   
public ConsoleOutputStream(Color textColor, PrintStream printStream) {
    if (textColor != null) {
        attributes = new SimpleAttributeSet();
        StyleConstants.setForeground(attributes, textColor);
    }
    attr_PASS = new SimpleAttributeSet();
    attr_FAIL = new SimpleAttributeSet();
    StyleConstants.setForeground(attr_PASS, DARK_GREEN);
    StyleConstants.setForeground(attr_FAIL, Color.RED);
    this.printStream = printStream;
    if (isAppend) {
        isFirstLine = true;
    }
}
项目:Neukoelln_SER316    文件:AltHTMLWriter.java   
/**
 * Determines if the HTML.Tag associated with the
 * element is a block tag.
 *
 * @param attr  an AttributeSet
 * @return  true if tag is block tag, false otherwise.
 */
protected boolean isBlockTag(AttributeSet attr) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        return name.isBlock();
    }
    return false;
}
项目:SER316-Munich    文件:AltHTMLWriter.java   
/**
 * Returns true if the StyleConstants.NameAttribute is
 * equal to the tag that is passed in as a parameter.
 */
protected boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        if (name == tag) {
            return true;
        }
    }
    return false;
}
项目:incubator-netbeans    文件:HighlightingPanel.java   
private AttributeSet getDefaultColoring() {
    Collection/*<AttributeSet>*/ defaults = colorModel.getCategories(currentProfile, ColorModel.ALL_LANGUAGES);

    for(Iterator i = defaults.iterator(); i.hasNext(); ) {
        AttributeSet as = (AttributeSet) i.next();
        String name = (String) as.getAttribute(StyleConstants.NameAttribute);
        if (name != null && "default".equals(name)) { //NOI18N
            return as;
        }
    }

    return null;
}
项目:Dahlem_SER316    文件:AltHTMLWriter.java   
/**
 * Writes out the attribute set.  Ignores all
 * attributes with a key of type HTML.Tag,
 * attributes with a key of type StyleConstants,
 * and attributes with a key of type
 * HTML.Attribute.ENDTAG.
 *
 * @param attr   an AttributeSet
 * @exception IOException on any I/O error
 *
 */
protected void writeAttributes(AttributeSet attr) throws IOException {
    // translate css attributes to html
    convAttr.removeAttributes(convAttr);
    convertToHTML32(attr, convAttr);

    Enumeration names = convAttr.getAttributeNames();
    while (names.hasMoreElements()) {
        Object name = names.nextElement();
        if (name instanceof HTML.Tag || name instanceof StyleConstants || name == HTML.Attribute.ENDTAG) {
            continue;
        }
        write(" " + name + "=\"" + convAttr.getAttribute(name) + "\"");
    }
}
项目:incubator-netbeans    文件:SyntaxColoringPanel.java   
private boolean isFontChanged(String language, AttributeSet currentAS, AttributeSet savedAS) {
    String name = (String) getValue(language, currentAS, StyleConstants.FontFamily);
    assert (name != null);
    Integer size = (Integer) getValue(language, currentAS, StyleConstants.FontSize);
    assert (size != null);
    Boolean bold = (Boolean) getValue(language, currentAS, StyleConstants.Bold);
    if (bold == null) {
        bold = Boolean.FALSE;
    }
    Boolean italic = (Boolean) getValue(language, currentAS, StyleConstants.Italic);
    if (italic == null) {
        italic = Boolean.FALSE;
    }
    int style = bold.booleanValue() ? Font.BOLD : Font.PLAIN;
    if (italic.booleanValue()) {
        style += Font.ITALIC;
    }
    Font currentFont = new Font(name, style, size.intValue());

    name = (String) getValue(language, savedAS, StyleConstants.FontFamily);
    assert (name != null);
    size = (Integer) getValue(language, savedAS, StyleConstants.FontSize);
    assert (size != null);
    bold = (Boolean) getValue(language, savedAS, StyleConstants.Bold);
    if (bold == null) {
        bold = Boolean.FALSE;
    }
    italic = (Boolean) getValue(language, savedAS, StyleConstants.Italic);
    if (italic == null) {
        italic = Boolean.FALSE;
    }
    style = bold.booleanValue() ? Font.BOLD : Font.PLAIN;
    if (italic.booleanValue()) {
        style += Font.ITALIC;
    }
    Font savedFont = new Font(name, style, size.intValue());
    return !currentFont.equals(savedFont);
}
项目:incubator-netbeans    文件:StackTraceSupport.java   
private static void underlineStacktraces(StyledDocument doc, JTextPane textPane, List<StackTracePosition> stacktraces, String comment) {
    Style defStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    Style hlStyle = doc.addStyle("regularBlue-stacktrace", defStyle); // NOI18N
    hlStyle.addAttribute(HyperlinkSupport.STACKTRACE_ATTRIBUTE, new StackTraceAction());
    StyleConstants.setForeground(hlStyle, UIUtils.getLinkColor());
    StyleConstants.setUnderline(hlStyle, true);

    int last = 0;
    textPane.setText(""); // NOI18N
    for (StackTraceSupport.StackTracePosition stp : stacktraces) {
        int start = stp.getStartOffset();
        int end = stp.getEndOffset();

        if (last < start) {
            insertString(doc, comment, last, start, defStyle);
        }
        last = start;

        // for each line skip leading whitespaces (look bad underlined)
        boolean inStackTrace = (comment.charAt(start) > ' ');
        for (int i = start; i < end; i++) {
            char ch = comment.charAt(i);
            if ((inStackTrace && ch == '\n') || (!inStackTrace && ch > ' ')) {
                insertString(doc, comment, last, i, inStackTrace ? hlStyle : defStyle);
                inStackTrace = !inStackTrace;
                last = i;
            }
        }

        if (last < end) {
            insertString(doc, comment, last, end, inStackTrace ? hlStyle : defStyle);
        }
        last = end;
    }
    try {
        doc.insertString(doc.getLength(), comment.substring(last), defStyle);
    } catch (BadLocationException ex) {
        Support.LOG.log(Level.SEVERE, null, ex);
    }
}
项目:incubator-netbeans    文件:HyperlinkSupport.java   
@Override
public void mouseMoved(MouseEvent e) {
    JTextPane pane = (JTextPane)e.getSource();
    StyledDocument doc = pane.getStyledDocument();
    Element elem = doc.getCharacterElement(pane.viewToModel(e.getPoint()));
    AttributeSet as = elem.getAttributes();
    if (StyleConstants.isUnderline(as)) {
        pane.setCursor(new Cursor(Cursor.HAND_CURSOR));
    } else {
        pane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}
项目:freecol    文件:ColopediaGameObjectTypePanel.java   
public void appendRequiredAbility(StyledDocument doc, String key, boolean value) {
    final Specification spec = getSpecification();
    try {
        doc.insertString(doc.getLength(), Messages.getName(key),
                         doc.getStyle("regular"));
        List<JButton> requiredTypes
             = transform(spec.getTypesProviding(key, value), alwaysTrue(),
                 t -> {
                     JButton typeButton = getButton(t);
                     typeButton.addActionListener(this);
                     return typeButton;
                 });
        JButton rt = first(requiredTypes);
        if (rt != null) {
            doc.insertString(doc.getLength(), " (",
                             doc.getStyle("regular"));
            StyleConstants.setComponent(doc.getStyle("button"), rt);
            doc.insertString(doc.getLength(), " ", doc.getStyle("button"));
            for (int index = 1; index < requiredTypes.size(); index++) {
                JButton button = requiredTypes.get(index);
                doc.insertString(doc.getLength(), " / ",
                                 doc.getStyle("regular"));
                StyleConstants.setComponent(doc.getStyle("button"), button);
                doc.insertString(doc.getLength(), " ",
                                 doc.getStyle("button"));
            }
            doc.insertString(doc.getLength(), ")",
                             doc.getStyle("regular"));
        }
        doc.insertString(doc.getLength(), "\n", doc.getStyle("regular"));
    } catch (BadLocationException ble) {
        logger.log(Level.WARNING, "Insert fail", ble);
    }
}
项目:incubator-netbeans    文件:AddModulePanel.java   
private void showDescription() {
    StyledDocument doc = descValue.getStyledDocument();
    final Boolean matchCase = matchCaseValue.isSelected();
    try {
        doc.remove(0, doc.getLength());
        ModuleDependency[] deps = getSelectedDependencies();
        if (deps.length != 1) {
            return;
        }
        String longDesc = deps[0].getModuleEntry().getLongDescription();
        if (longDesc != null) {
            doc.insertString(0, longDesc, null);
        }
        String filterText = filterValue.getText().trim();
        if (filterText.length() != 0 && !FILTER_DESCRIPTION.equals(filterText)) {
            doc.insertString(doc.getLength(), "\n\n", null); // NOI18N
            Style bold = doc.addStyle(null, null);
            bold.addAttribute(StyleConstants.Bold, Boolean.TRUE);
            doc.insertString(doc.getLength(), getMessage("TEXT_matching_filter_contents"), bold);
            doc.insertString(doc.getLength(), "\n", null); // NOI18N
            if (filterText.length() > 0) {
                String filterTextLC = matchCase?filterText:filterText.toLowerCase(Locale.US);
                Style match = doc.addStyle(null, null);
                match.addAttribute(StyleConstants.Background, UIManager.get("selection.highlight")!=null?
                        UIManager.get("selection.highlight"):new Color(246, 248, 139));
                boolean isEven = false;
                Style even = doc.addStyle(null, null);
                even.addAttribute(StyleConstants.Background, UIManager.get("Panel.background"));
                if (filterer == null) {
                    return; // #101776
                }
                for (String hit : filterer.getMatchesFor(filterText, deps[0])) {
                    int loc = doc.getLength();
                    doc.insertString(loc, hit, (isEven ? even : null));
                    int start = (matchCase?hit:hit.toLowerCase(Locale.US)).indexOf(filterTextLC);
                    while (start != -1) {
                        doc.setCharacterAttributes(loc + start, filterTextLC.length(), match, true);
                        start = hit.toLowerCase(Locale.US).indexOf(filterTextLC, start + 1);
                    }
                    doc.insertString(doc.getLength(), "\n", (isEven ? even : null)); // NOI18N
                    isEven ^= true;
                }
            } else {
                Style italics = doc.addStyle(null, null);
                italics.addAttribute(StyleConstants.Italic, Boolean.TRUE);
                doc.insertString(doc.getLength(), getMessage("TEXT_no_filter_specified"), italics);
            }
        }
        descValue.setCaretPosition(0);
    } catch (BadLocationException e) {
        Util.err.notify(ErrorManager.INFORMATIONAL, e);
    }
}
项目:incubator-netbeans    文件:FoldView.java   
/**
 * Border color for the placeholder view or the tooltip.
 * If not defined, falls back to the {@link #getForegroundColor()}.
 * @return Color for the border
 */
private Color getBorderColor() {
    if (foldingBorderColors == null) {
        return getForegroundColor();
    }
    Object fgColorObj = foldingBorderColors.getAttribute(StyleConstants.Foreground);
    if (fgColorObj instanceof Color) {
        return (Color)fgColorObj;
    }
    return getForegroundColor();
}
项目:incubator-netbeans    文件:FoldView.java   
private Color getForegroundColor() {
    if (foldingColors == null) {
        return textComponent.getForeground();
    }
    Object bgColorObj = foldingColors.getAttribute(StyleConstants.Foreground);
    if (bgColorObj instanceof Color) {
        return (Color)bgColorObj;
    } else {
        return textComponent.getForeground();
    }
}
项目:8085simulator    文件:TextEditor.java   
public void setColor(Color c, String s) {
    try {
        StyledDocument doc = jTextPane1.getStyledDocument();
        javax.swing.text.Style style = jTextPane1.addStyle("", null);
        StyleConstants.setForeground(style, c);
        doc.insertString(doc.getLength(), s, style);
        jTextPane1.select(0, 10);
        jTextPane1.setSelectedTextColor(Color.YELLOW);
    } catch (BadLocationException ex) {
        System.out.println(ex);
    }
}
项目:incubator-netbeans    文件:CodeFoldingSideBar.java   
/**
 * Resolves background color. Must be called after getColoring(), satisfied in updateColors.
 * @return 
 */
private Color resolveBackColor(boolean fallback) {
    AttributeSet attr = specificAttrs;
    Color x = (Color)attr.getAttribute(StyleConstants.ColorConstants.Background);
    if (x == null) {
        Container c = getParent();
        if (c != null) {
            x = c.getBackground();
        } else if (fallback) {
            // fallback in case of inherited color and uninitialized parent
            return getColoring().getBackColor();
        }
    }
    return x;
}
项目:Reinickendorf_SER316    文件:AltHTMLWriter.java   
/**
 * Writes out the attribute set.  Ignores all
 * attributes with a key of type HTML.Tag,
 * attributes with a key of type StyleConstants,
 * and attributes with a key of type
 * HTML.Attribute.ENDTAG.
 *
 * @param attr   an AttributeSet
 * @exception IOException on any I/O error
 *
 */
protected void writeAttributes(AttributeSet attr) throws IOException {
    // translate css attributes to html
    convAttr.removeAttributes(convAttr);
    convertToHTML32(attr, convAttr);

    Enumeration names = convAttr.getAttributeNames();
    while (names.hasMoreElements()) {
        Object name = names.nextElement();
        if (name instanceof HTML.Tag || name instanceof StyleConstants || name == HTML.Attribute.ENDTAG) {
            continue;
        }
        write(" " + name + "=\"" + convAttr.getAttribute(name) + "\"");
    }
}
项目:Wilmersdorf_SER316    文件:AltHTMLWriter.java   
/**
 * Returns true if the StyleConstants.NameAttribute is
 * equal to the tag that is passed in as a parameter.
 */
protected boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        if (name == tag) {
            return true;
        }
    }
    return false;
}
项目:SER316-Aachen    文件:HTMLEditor.java   
public void cAlignActionB_actionPerformed(ActionEvent e) {
    HTMLEditorKit.AlignmentAction aa =
        new HTMLEditorKit.AlignmentAction(
            "centerAlign",
            StyleConstants.ALIGN_CENTER);
    aa.actionPerformed(e);
}
项目:Reinickendorf_SER316    文件:HTMLEditor.java   
public void rAlignActionB_actionPerformed(ActionEvent e) {
    HTMLEditorKit.AlignmentAction aa =
        new HTMLEditorKit.AlignmentAction(
            "rightAlign",
            StyleConstants.ALIGN_RIGHT);
    aa.actionPerformed(e);
}
项目:candlelight    文件:Console.java   
public synchronized Console print(String msg, Color color)
{
    SimpleAttributeSet attrib = new SimpleAttributeSet();
    StyleConstants.setForeground(attrib, color);
    this.print(msg, attrib);
    return this;
}
项目:Dahlem_SER316    文件:AltHTMLWriter.java   
/**
 * Determines if the HTML.Tag associated with the
 * element is a block tag.
 *
 * @param attr  an AttributeSet
 * @return  true if tag is block tag, false otherwise.
 */
protected boolean isBlockTag(AttributeSet attr) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        return name.isBlock();
    }
    return false;
}