本文整理汇总了Java中javax.swing.text.StyleContext.addStyle方法的典型用法代码示例。如果您正苦于以下问题:Java StyleContext.addStyle方法的具体用法?Java StyleContext.addStyle怎么用?Java StyleContext.addStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleContext
的用法示例。
在下文中一共展示了StyleContext.addStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCodeArea
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private JTextPane getCodeArea(){
final StyleContext sc = new StyleContext();
final DefaultStyledDocument doc = new DefaultStyledDocument(sc);
final JTextPane codeArea = new JTextPane(doc);
codeArea.setBackground(new Color(0x25401C));
codeArea.setCaretColor(new Color(0xD1E8CE));
final Style bodyStyle = sc.addStyle("body", null);
bodyStyle.addAttribute(StyleConstants.Foreground, new Color(0x789C6C));
bodyStyle.addAttribute(StyleConstants.FontSize, 13);
bodyStyle.addAttribute(StyleConstants.FontFamily, "monospaced");
bodyStyle.addAttribute(StyleConstants.Bold, true);
doc.setLogicalStyle(0, bodyStyle);
return codeArea;
}
示例2: getDefaultStyleContext
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Returns a default-populated StyleContext for UHSTextAreas.
*
* <p>Changes to a style will immediately affect existing
* components using its descendants only. The style itself
* will not update for some reason.</p>
*
* <blockquote><pre>
* @{code
* Java's default
* - base
* - - regular
* - - - visitable
* - - - link
* - - - hyper
* - - - monospaced
* }
* </pre></blockquote>
*/
private static StyleContext getDefaultStyleContext() {
StyleContext result = new StyleContext();
Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( StyleContext.DEFAULT_STYLE );
Style baseStyle = result.addStyle( "base", defaultStyle );
Style regularStyle = result.addStyle( STYLE_NAME_REGULAR, baseStyle );
Style visitableStyle = result.addStyle( STYLE_NAME_VISITABLE, regularStyle );
StyleConstants.setForeground( visitableStyle, VISITABLE_COLOR );
Style linkStyle = result.addStyle( STYLE_NAME_LINK, regularStyle );
StyleConstants.setForeground( linkStyle, LINK_COLOR );
Style hyperStyle = result.addStyle( STYLE_NAME_HYPERLINK, regularStyle );
StyleConstants.setForeground( hyperStyle, HYPER_COLOR );
StyleConstants.setUnderline( hyperStyle, true );
Style monospacedStyle = result.addStyle( STYLE_NAME_MONOSPACED, regularStyle );
StyleConstants.setFontFamily( monospacedStyle, "Monospaced" );
return result;
}
示例3: initStyles
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
protected void initStyles() {
styleContext = new StyleContext();
Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setFontFamily(defaultStyle, "courier");
styleStackTrace = styleContext.addStyle("stackTrace", defaultStyle);
StyleConstants.setBackground(styleStackTrace, new Color(255, 224, 193));
StyleConstants.setForeground(styleStackTrace, Color.BLACK);
stylePackage = styleContext.addStyle("stylePackage", styleStackTrace);
styleClass = styleContext.addStyle("styleClass", stylePackage);
StyleConstants.setForeground(styleClass, new Color(11, 143, 61));
StyleConstants.setBold(styleClass, true);
styleMethod = styleContext.addStyle("styleMethod", styleStackTrace);
StyleConstants.setForeground(styleMethod, new Color(83, 112, 223));
StyleConstants.setItalic(styleMethod, true);
StyleConstants.setBold(styleMethod, true);
styleFile = styleContext.addStyle("styleFile", styleStackTrace);
StyleConstants.setForeground(styleFile, Color.BLACK);
StyleConstants.setUnderline(styleFile, true);
styleCodeComment = styleContext.addStyle("styleCodeComment", defaultStyle);
StyleConstants.setForeground(styleCodeComment, Color.DARK_GRAY);
StyleConstants.setItalic(styleCodeComment, true);
}
示例4: colorize
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
@Override
public Collection<MessageFragmentStyle> colorize(String textToColorize) throws BadLocationException {
Collection<MessageFragmentStyle> list = new ArrayList<>();
if (StringUtils.isEmpty(searchString)) {
return list;
}
StyleContext sc = new StyleContext();
Style searchStyle = sc.addStyle("searchResult", sc.getStyle(StyleContext.DEFAULT_STYLE));
StyleConstants.setBackground(searchStyle, color);
if (searchMode.equals(SearchMode.STRING_CONTAINS)) {
list.addAll(colorizeString(textToColorize, searchStyle, searchString));
} else if (searchMode.equals(SearchMode.REGEX)) {
list.addAll(MessageColorizerUtils.colorizeRegex(searchStyle, textToColorize, Pattern.compile(searchString, Pattern.CASE_INSENSITIVE), 0));
}
for (MessageFragmentStyle style : list) {
style.setSearchResult(true);
}
return list;
}
示例5: getDefaultStyleContext
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private static StyleContext getDefaultStyleContext() {
StyleContext result = new StyleContext();
Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( StyleContext.DEFAULT_STYLE );
Style baseStyle = result.addStyle( "base", defaultStyle );
Style regularStyle = result.addStyle( STYLE_REGULAR, baseStyle );
StyleConstants.setFontFamily( regularStyle, Font.MONOSPACED );
StyleConstants.setFontSize( regularStyle, 12 );
Style hyperStyle = result.addStyle( STYLE_HYPERLINK, regularStyle );
StyleConstants.setForeground( hyperStyle, COLOR_HYPER );
StyleConstants.setUnderline( hyperStyle, true );
Style titleStyle = result.addStyle( STYLE_TITLE, baseStyle );
StyleConstants.setFontFamily( titleStyle, Font.SANS_SERIF );
StyleConstants.setFontSize( titleStyle, 24 );
StyleConstants.setBold( titleStyle, true );
return result;
}
示例6: changeColor
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Description method that changes the foreground color
* @param document document to be changed
* @return Style for the new document
* @throws BadLocationException
*/
public Style changeColor(DefaultStyledDocument document) throws BadLocationException {
StyleContext context = new StyleContext();
// build a style
Style style = context.addStyle("test", null);
// set some style properties
StyleConstants.setForeground(style, Color.RED);
return style;
}
示例7: changeColor
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Description method that changes the foreground color
* @param document document to be changed
* @return Style for the new document
* @throws BadLocationException
*/
public static Style changeColor(DefaultStyledDocument document) throws BadLocationException {
StyleContext context = new StyleContext();
// build a style
Style style = context.addStyle("test", null);
// set some style properties
StyleConstants.setForeground(style, Color.RED);
return style;
}
示例8: appendText
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Appends the given text in the given color to the content written on this
* textpane.
*
* @param mText
* The text to append.
*
* @param mColor
* The color to write the text in.
*/
public void appendText(final String mText, final Color mColor) {
DefaultStyledDocument s = (DefaultStyledDocument) this.getStyledDocument();
StyleContext context = new StyleContext();
Style style = context.addStyle("test", null);
StyleConstants.setForeground(style, mColor);
try {
s.insertString(s.getLength(), mText, style);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
示例9: initStyleContext
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static void initStyleContext(Font font) {
Style defaultStyle = StyleContext.getDefaultStyleContext()
.getStyle(StyleContext.DEFAULT_STYLE);
STYLE_CONTEXT = new StyleContext();
Style regular = STYLE_CONTEXT.addStyle("regular", defaultStyle);
StyleConstants.setFontFamily(regular, font.getFamily());
StyleConstants.setFontSize(regular, font.getSize());
Style buttonStyle = STYLE_CONTEXT.addStyle("button", regular);
StyleConstants.setForeground(buttonStyle, LINK_COLOR);
Style right = STYLE_CONTEXT.addStyle("right", regular);
StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);
}
示例10: createStyles
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
static void createStyles() {
styles = new StyleContext();
doc = new DefaultStyledDocument(styles);
contentAttributes = new HashMap<>();
// no attributes defined
Style s = styles.addStyle(null, null);
contentAttributes.put("none", s);
Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);
Style heading = styles.addStyle("heading", def);
StyleConstants.setFontFamily(heading, "SansSerif");
StyleConstants.setBold(heading, true);
StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
StyleConstants.setSpaceAbove(heading, 10);
StyleConstants.setSpaceBelow(heading, 10);
StyleConstants.setFontSize(heading, 18);
// Title
Style sty = styles.addStyle("title", heading);
StyleConstants.setFontSize(sty, 32);
// author
sty = styles.addStyle("author", heading);
StyleConstants.setItalic(sty, true);
StyleConstants.setSpaceBelow(sty, 25);
}
示例11: getStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static Style getStyle(StyleContext styleContext, DataConfiguration styleConfig, String styleName, int group) {
Style style = styleContext.addStyle(styleName, styleContext.getStyle(StyleContext.DEFAULT_STYLE));
String groupSuffix = "." + group;
if (group <= 0) {
groupSuffix = "";
}
String fontFamily = styleConfig.getString(PROP_FONT_FAMILY + groupSuffix, "");
if (fontFamily.trim().length() > 0) {
StyleConstants.setFontFamily(style, styleConfig.getString(PROP_FONT_FAMILY + groupSuffix));
}
if (styleConfig.getString(PROP_FONT_SIZE + groupSuffix, "").trim().length() > 0) {
StyleConstants.setFontSize(style, styleConfig.getInt(PROP_FONT_SIZE + groupSuffix));
}
if (styleConfig.getString(PROP_FONT_BOLD + groupSuffix, "").trim().length() > 0) {
StyleConstants.setBold(style, styleConfig.getBoolean(PROP_FONT_BOLD + groupSuffix));
}
if (styleConfig.getString(PROP_FONT_ITALIC + groupSuffix, "").trim().length() > 0) {
StyleConstants.setItalic(style, styleConfig.getBoolean(PROP_FONT_ITALIC + groupSuffix));
}
if (styleConfig.getString(PROP_FONT_UNDERLINE + groupSuffix, "").trim().length() > 0) {
StyleConstants.setUnderline(style, styleConfig.getBoolean(PROP_FONT_UNDERLINE + groupSuffix));
}
if (styleConfig.getString(PROP_BACKGROUND + groupSuffix, "").trim().length() > 0) {
StyleConstants.setBackground(style, styleConfig.getColor(PROP_BACKGROUND + groupSuffix));
}
if (styleConfig.getString(PROP_FOREGROUND + groupSuffix, "").trim().length() > 0) {
StyleConstants.setForeground(style, styleConfig.getColor(PROP_FOREGROUND + groupSuffix));
}
return style;
}
示例12: initStyles
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void initStyles() {
StyleContext 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);
}
示例13: createStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static void createStyle(StyleContext sc, String aName, Color aForegroundColor, String aFontFamily, Color aBackgroundColor, int aFontSize, Boolean isBold)
{
Style cursorStyle= sc.addStyle(aName, null);
StyleConstants.setForeground(cursorStyle, aForegroundColor);
StyleConstants.setFontFamily(cursorStyle, aFontFamily);
StyleConstants.setBackground(cursorStyle, aBackgroundColor);
StyleConstants.setFontSize(cursorStyle, aFontSize);
if (isBold != null)
StyleConstants.setBold(cursorStyle, isBold);
}
示例14: getLabelStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static Style getLabelStyle(){
if (labelStyle!=null)
return labelStyle;
if (defaultStyle==null)
getDefaultStyle();
StyleContext context = new StyleContext();
labelStyle= context.addStyle("Label", defaultStyle);
StyleConstants.setForeground(labelStyle, Color.red);
StyleConstants.setBackground(labelStyle, Color.yellow);
return labelStyle;
}
示例15: getEOLStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static Style getEOLStyle(){
if (EOLStyle!=null)
return EOLStyle;
if (defaultStyle==null)
getDefaultStyle();
StyleContext context = new StyleContext();
EOLStyle = context.addStyle("EOL", defaultStyle);
StyleConstants.setForeground(EOLStyle, Color.black);
StyleConstants.setBackground(EOLStyle, Color.lightGray);
return EOLStyle;
}