当前位置: 首页>>代码示例>>Java>>正文


Java StyleConstants类代码示例

本文整理汇总了Java中javax.swing.text.StyleConstants的典型用法代码示例。如果您正苦于以下问题:Java StyleConstants类的具体用法?Java StyleConstants怎么用?Java StyleConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StyleConstants类属于javax.swing.text包,在下文中一共展示了StyleConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setFontName

import javax.swing.text.StyleConstants; //导入依赖的package包/类
/** 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); }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:22,代码来源:SwingLogPanel.java

示例2: publish

import javax.swing.text.StyleConstants; //导入依赖的package包/类
@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());
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:27,代码来源:ConsoleLogHandler.java

示例3: do_setFont

import javax.swing.text.StyleConstants; //导入依赖的package包/类
/** 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);
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:17,代码来源:OurSyntaxDocument.java

示例4: create

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ViewFactoryImpl.java

示例5: ReadOnlyFilesHighlighting

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ReadOnlyFilesHighlighting.java

示例6: editLyrics

import javax.swing.text.StyleConstants; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:24,代码来源:YassLyrics.java

示例7: getUnusedFieldAttributes

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ColorsManager.java

示例8: getComposedTextAttribute

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ComposedTextHighlighting.java

示例9: getCurrentColors

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ColorsManager.java

示例10: color

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:UIUtilities.java

示例11: testAllLanguagesTheCrapWay

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:FontColorSettingsImplTest.java

示例12: insertString

import javax.swing.text.StyleConstants; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:VCSHyperlinkSupport.java

示例13: VersioningSystemColors

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:AnnotationColorsPanel.java

示例14: QueryBuilderSqlTextArea

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:QueryBuilderSqlTextArea.java

示例15: testInheritanceForAntPlusXml

import javax.swing.text.StyleConstants; //导入依赖的package包/类
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));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SettingsProviderTest.java


注:本文中的javax.swing.text.StyleConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。