本文整理汇总了Java中javax.swing.text.StyleContext.getStyle方法的典型用法代码示例。如果您正苦于以下问题:Java StyleContext.getStyle方法的具体用法?Java StyleContext.getStyle怎么用?Java StyleContext.getStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleContext
的用法示例。
在下文中一共展示了StyleContext.getStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: PlexMessageWindow
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Create a new PlexMessageWindow with the given title.
* <p>
* @param title Title string for the window.
*/
public PlexMessageWindow(String title) {
frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
context = new StyleContext();
document = new DefaultStyledDocument(context);
style = context.getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT);
StyleConstants.setFontSize(style, 14);
//StyleConstants.setSpaceAbove(style, 1);
//StyleConstants.setSpaceBelow(style, 1);
textPane = new JTextPane(document);
textPane.setEditable(false);
scrollPane = new JScrollPane(textPane);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 150);
}
示例3: 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);
}
示例4: addStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static void addStyle(JTextPane pane, String name, Color foreground,
Color background)
{
StyledDocument doc = pane.getStyledDocument();
StyleContext context = StyleContext.getDefaultStyleContext();
Style defaultStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
Style style = doc.addStyle(name, defaultStyle);
StyleConstants.setForeground(style, foreground);
StyleConstants.setBackground(style, background);
}
示例5: setStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static void setStyle(JTextPane textPane, int start, int length,
String name)
{
StyledDocument doc = textPane.getStyledDocument();
Style style;
if (name == null)
{
StyleContext context = StyleContext.getDefaultStyleContext();
style = context.getStyle(StyleContext.DEFAULT_STYLE);
}
else
style = doc.getStyle(name);
doc.setCharacterAttributes(start, length, style, true);
}
示例6: writeTextNode
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private static void writeTextNode(DefaultStyledDocument doc,
StyleContext styles, Node node, int indent,
Collection<IdentifierLocation> idLocations, boolean flagged)
throws BadLocationException {
String text = CoqDoc.getTextFromTextNode(node);
Style style = styles.getStyle(STYLE_TEXT);
if(flagged) style.addAttributes(styles.getStyle(STYLE_FLAGGED));
doc.insertString(doc.getLength(), text, style);
}
示例7: writeKeywordNode
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private static void writeKeywordNode(DefaultStyledDocument doc,
StyleContext styles, Node node, int indent,
Collection<IdentifierLocation> idLocations, boolean flagged)
throws BadLocationException {
Style style = styles.getStyle(STYLE_KEYWORD);
if(flagged) style.addAttributes(styles.getStyle(STYLE_FLAGGED));
doc.insertString(doc.getLength(), getKeywordFromKeywordNode(node), style);
}
示例8: writeIdentifierNode
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private static void writeIdentifierNode(DefaultStyledDocument doc,
StyleContext styles, Node node, int indent,
Collection<IdentifierLocation> idLocations, boolean flagged)
throws BadLocationException {
String id = CoqDoc.getIDFromIdentifierNode(node);
int offset = doc.getLength();
Style style = styles.getStyle(STYLE_IDENTIFIER);
if(flagged) style.addAttributes(styles.getStyle(STYLE_FLAGGED));
doc.insertString(offset, id, style);
if(idLocations != null) {
idLocations.add(new IdentifierLocation(offset, id.length(), id));
}
}
示例9: buildDocument
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* buildDocument.
*/
private void buildDocument() {
final StyleContext context = new StyleContext();
document = new DefaultStyledDocument(context);
final Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT);
StyleConstants.setFontSize(style, 14);
StyleConstants.setSpaceAbove(style, 4);
StyleConstants.setSpaceBelow(style, 4);
// Insert content
try {
document.insertString(document.getLength(), message, style);
} catch (final BadLocationException badLocationException) {
log.error(badLocationException.getMessage());
}
final SimpleAttributeSet attributes = new SimpleAttributeSet();
StyleConstants.setBold(attributes, true);
StyleConstants.setItalic(attributes, true);
// Third style for icon/component
final Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
final Icon icon = new ImageIcon("Computer.gif");
final JLabel label = new JLabel(icon);
StyleConstants.setComponent(labelStyle, label);
}
示例10: initStyles
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void initStyles(){
StyleContext context = StyleContext.getDefaultStyleContext();
Style defaultStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
Style newStyle;
//error : red
newStyle = textArea.addStyle(LogLevel.error.name(), defaultStyle);
StyleConstants.setFontFamily(newStyle, FONT_NAME);
StyleConstants.setForeground(newStyle, Color.MAGENTA);
StyleConstants.setFontSize(newStyle, FONT_SIZE);
//warning : orange
newStyle = textArea.addStyle(LogLevel.warn.name(), defaultStyle);
StyleConstants.setFontFamily(newStyle, FONT_NAME);
StyleConstants.setForeground(newStyle, Color.RED);
StyleConstants.setFontSize(newStyle, FONT_SIZE);
//info : green
newStyle = textArea.addStyle(LogLevel.info.name(), defaultStyle);
StyleConstants.setFontFamily(newStyle, FONT_NAME);
StyleConstants.setForeground(newStyle, Color.GREEN.darker().darker().darker());
StyleConstants.setFontSize(newStyle, FONT_SIZE);
//debug : gray
newStyle = textArea.addStyle(LogLevel.debug.name(), defaultStyle);
StyleConstants.setFontFamily(newStyle, FONT_NAME);
StyleConstants.setForeground(newStyle, Color.GRAY);
StyleConstants.setFontSize(newStyle, FONT_SIZE);
}
示例11: 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);
}
示例12: getDefaultStyle
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public static Style getDefaultStyle(){
if (defaultStyle==null){
StyleContext context = new StyleContext();
defaultStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setAlignment(defaultStyle, StyleConstants.ALIGN_LEFT);
StyleConstants.setSpaceAbove(defaultStyle, 4);
StyleConstants.setSpaceBelow(defaultStyle, 4);
StyleConstants.setFontFamily(defaultStyle, "Tahoma");
StyleConstants.setFontSize(defaultStyle, 12);
StyleConstants.setForeground(defaultStyle, Color.blue);
}
return defaultStyle;
}
示例13: OutputConsole
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public OutputConsole()
{
/*
* Layout
*/
setLayout(new BorderLayout());
output = new JTextPane(doc);
output.setEditable(false);
JScrollPane jsp = new JScrollPane();
jsp.setViewportView(output);
add(jsp, BorderLayout.CENTER);
/*
* Text styles
*/
StyleContext sc = StyleContext.getDefaultStyleContext();
Style def = sc.getStyle(StyleContext.DEFAULT_STYLE);
Style base = doc.addStyle(STYLE_DEFAULT, def);
Style emphasis = doc.addStyle(STYLE_EMPHASIS, def);
StyleConstants.setItalic(base, true);
StyleConstants.setBold(emphasis, true);
}
示例14: createStyles
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Creates all styles for syntax highlighting
* @param sc
*/
private static void createStyles(StyleContext sc) {
Style defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
styleMain = sc.addStyle("MainStyle", defaultStyle);
StyleConstants.setLeftIndent(styleMain, 16);
StyleConstants.setRightIndent(styleMain, 16);
StyleConstants.setFirstLineIndent(styleMain, 16);
StyleConstants.setFontFamily(styleMain, "monospaced");
StyleConstants.setFontSize(styleMain, 12);
StyleConstants.setForeground(styleMain, Color.BLACK);
StyleConstants.setBold(styleMain, false);
styleLogical = sc.addStyle("LogicalStyle", styleMain);
StyleConstants.setForeground(styleLogical, Color.GRAY);
StyleConstants.setBold(styleLogical, true);
stylePrecedence = sc.addStyle("PrecedenceStyle", styleMain);
StyleConstants.setForeground(stylePrecedence, Color.GREEN);
StyleConstants.setBold(stylePrecedence, true);
styleOperator = sc.addStyle("OperatorStyle", styleMain);
StyleConstants.setForeground(styleOperator, Color.BLUE);
StyleConstants.setBold(styleOperator, true);
styleField = sc.addStyle("FieldStyle", styleMain);
StyleConstants.setForeground(styleField, Color.RED);
StyleConstants.setBold(styleField, true);
styleValue = sc.addStyle("ValueStyle", styleMain);
StyleConstants.setForeground(styleValue, Color.DARK_GRAY);
StyleConstants.setBold(styleValue, true);
}
示例15: LexerNode
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
LexerNode(boolean isParent) {
StyleContext sc = StyleContext.getDefaultStyleContext();
defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
}