本文整理汇总了Java中javax.swing.text.StyleContext类的典型用法代码示例。如果您正苦于以下问题:Java StyleContext类的具体用法?Java StyleContext怎么用?Java StyleContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StyleContext类属于javax.swing.text包,在下文中一共展示了StyleContext类的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: addStylesToDocument
import javax.swing.text.StyleContext; //导入依赖的package包/类
/**
* Add styles to the document.
*
* @param doc the StyledDocument to add styles to
*/
protected void addStylesToDocument(final StyledDocument doc)
{
//Initialize some styles.
Style def = StyleContext.getDefaultStyleContext().
getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "SansSerif");
StyleConstants.setFontSize(def, 12);
StyleConstants.setLineSpacing(def, 2.0f);
Style s = doc.addStyle("italic", regular);
StyleConstants.setItalic(s, true);
s = doc.addStyle("bold", regular);
StyleConstants.setBold(s, true);
s = doc.addStyle("small", regular);
StyleConstants.setFontSize(s, 10);
s = doc.addStyle("large", regular);
StyleConstants.setFontSize(s, 14);
}
示例3: writeStyles
import javax.swing.text.StyleContext; //导入依赖的package包/类
/**
* Outputs the styles as a single element. Styles are not stored as
* elements, but part of the document. For the time being styles are
* written out as a comment, inside a style tag.
*/
void writeStyles(StyleSheet sheet) throws IOException {
if (sheet != null) {
Enumeration styles = sheet.getStyleNames();
if (styles != null) {
boolean outputStyle = false;
while (styles.hasMoreElements()) {
String name = (String) styles.nextElement();
// Don't write out the default style.
if (!StyleContext.DEFAULT_STYLE.equals(name)
&& writeStyle(name, sheet.getStyle(name), outputStyle)) {
outputStyle = true;
}
}
if (outputStyle) {
writeStyleEndTag();
}
}
}
}
示例4: createSearchPanel
import javax.swing.text.StyleContext; //导入依赖的package包/类
private Component createSearchPanel() {
StyleContext styleContent = StyleContext.getDefaultStyleContext();
AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);
AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);
searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
searchPanel.hide();
return searchPanel.getComponent();
}
示例5: showPacket
import javax.swing.text.StyleContext; //导入依赖的package包/类
private void showPacket(final AbstractPacketPoint point) {
SwingUtilities4.invokeInEDT(() -> {
final String[] lines = point.getPayload().split("\n");
int max = 0;
for (final String line1 : lines) {
max = Math.max(max, line1.length());
}
max += 5;
for (final String line2 : lines) {
final Color color = colorForLine(line2);
final StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.BLACK);
aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
aset = sc.addAttribute(aset, StyleConstants.Bold, false);
aset = sc.addAttribute(aset, StyleConstants.Background, color);
final int len = _details.getDocument().getLength();
_details.setCaretPosition(len);
_details.setCharacterAttributes(aset, false);
_details.replaceSelection(line2 + StringUtils.repeat(" ", max - line2.length()) + "\n");
}
_details.setCaretPosition(0);
});
}
示例6: writeWhitespaceNode
import javax.swing.text.StyleContext; //导入依赖的package包/类
private static void writeWhitespaceNode(DefaultStyledDocument doc,
StyleContext styles, Node node, int indent,
Collection<IdentifierLocation> idLocations, boolean flagged) throws BadLocationException {
if(isWhitespaceNewlineNode(node)) {
doc.insertString(doc.getLength(), "\n", styles.getStyle(STYLE_WS));
if(indent > 0) {
doc.insertString(doc.getLength(), indent(indent), styles.getStyle(STYLE_WS));
}
} else if(isWhitespaceIndentNode(node)) {
doc.insertString(doc.getLength(), indent(1), styles.getStyle(STYLE_WS));
NodeList children = node.getChildNodes();
for(int i = 0; i < children.getLength(); i++) {
write(doc, styles, children.item(i), indent + 1, idLocations, flagged);
}
} else {
doc.insertString(doc.getLength(), " ", styles.getStyle(STYLE_WS));
}
}
示例7: makeDocument
import javax.swing.text.StyleContext; //导入依赖的package包/类
public static DefaultStyledDocument makeDocument(CoqDocable term,
StyleContext styles, Collection<IdentifierLocation> idLocations,
String optionalSuffix) {
DefaultStyledDocument document = new DefaultStyledDocument();
try {
write(document, styles,
term.makeCoqDocTerm(CoqDoc.makeDocument()), 0,
idLocations, false);
if(optionalSuffix != null) {
document.insertString(document.getLength(), " ",
styles.getStyle(STYLE_WS));
document.insertString(document.getLength(), optionalSuffix,
styles.getStyle(STYLE_TEXT));
}
} catch(BadLocationException e) {
throw new RuntimeException(e);
}
return document;
}
示例8: write
import javax.swing.text.StyleContext; //导入依赖的package包/类
private static void write(DefaultStyledDocument doc, StyleContext styles,
Node node, int indent, Collection<IdentifierLocation> idLocations,
boolean flagged)
throws BadLocationException {
if(isWhitespaceNode(node)) {
writeWhitespaceNode(doc, styles, node, indent, idLocations, flagged);
} else if(isTextNode(node)) {
writeTextNode(doc, styles, node, indent, idLocations, flagged);
} else if(isKeywordNode(node)) {
writeKeywordNode(doc, styles, node, indent, idLocations, flagged);
} else if(isIdentifierNode(node)) {
writeIdentifierNode(doc, styles, node, indent, idLocations, flagged);
} else if(isTermNode(node)) {
writeTermNode(doc, styles, node, indent, idLocations, flagged);
} else if(isFlaggedNode(node)) {
writeFlaggedNode(doc, styles, node, indent, idLocations, true);
} else {
throw new IllegalArgumentException("Unknown node type: " + XMLUtils.nodeToString(node));
}
}
示例9: extractFont
import javax.swing.text.StyleContext; //导入依赖的package包/类
private Font extractFont(final StyleContext style, final int pos, final Element rootElement,
final AttributeSet attributes) {
Font font = null;
if (attributes.isDefined(StyleConstants.FontSize) || attributes.isDefined(StyleConstants.FontFamily)) {
font = style.getFont(attributes);
}
if (font == null) {
if (document instanceof DefaultStyledDocument) {
font = extractFontFromDefaultStyledDocument((DefaultStyledDocument) document, style, pos, rootElement);
}
else {
font = style.getFont(rootElement.getAttributes());
}
}
return font;
}
示例10: appendToPane
import javax.swing.text.StyleContext; //导入依赖的package包/类
private void appendToPane(JTextPane tp, String msg, MessageType t)
{
boolean scrollToBottom = scrollPane.getVerticalScrollBar().getValue() == scrollPane.getVerticalScrollBar().getMaximum();
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = SimpleAttributeSet.EMPTY;
MessageStyle ms = theme.getStyle(t);
aset = sc.addAttribute(aset, StyleConstants.Foreground, ms.getForeground() == null ? tp.getForeground() : ms.getForeground());
aset = sc.addAttribute(aset, StyleConstants.Background, ms.getBackground() == null ? tp.getBackground() : ms.getBackground());
aset = sc.addAttribute(aset, StyleConstants.Bold, ms.isBold());
aset = sc.addAttribute(aset, StyleConstants.Italic, ms.isItalic());
aset = sc.addAttribute(aset, StyleConstants.Underline, ms.isUnderlined());
StyledDocument sd = tp.getStyledDocument();
try
{
sd.insertString(sd.getLength(), msg, aset);
}
catch(BadLocationException e)
{
e.printStackTrace();
}
if(scrollToBottom)
{
scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum());
}
}
示例11: writeStyles
import javax.swing.text.StyleContext; //导入依赖的package包/类
/**
* Outputs the styles as a single element. Styles are not stored as
* elements, but part of the document. For the time being styles are written
* out as a comment, inside a style tag.
*/
void writeStyles(StyleSheet sheet) throws IOException {
if (sheet != null) {
Enumeration styles = sheet.getStyleNames();
if (styles != null) {
boolean outputStyle = false;
while (styles.hasMoreElements()) {
String name = (String) styles.nextElement();
// Don't write out the default style.
if (!StyleContext.DEFAULT_STYLE.equals(name)
&& writeStyle(name, sheet.getStyle(name), outputStyle)) {
outputStyle = true;
}
}
if (outputStyle) {
writeStyleEndTag();
}
}
}
}
示例12: 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;
}
示例13: setTipText
import javax.swing.text.StyleContext; //导入依赖的package包/类
@Override
public void setTipText(String tipText) {
UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
int maxTooltipWidth = lafDefaults.getInt("Tooltip.maxWidth");
if (maxTooltipWidth == 0) {
maxTooltipWidth = DesktopComponentsHelper.TOOLTIP_WIDTH;
}
FontMetrics fontMetrics = StyleContext.getDefaultStyleContext().getFontMetrics(getFont());
int actualWidth = SwingUtilities.computeStringWidth(fontMetrics, tipText);
if (actualWidth < maxTooltipWidth) {
tipText = "<html>" + tipText + "</html>";
} else {
tipText = "<html><body width=\"" + maxTooltipWidth + "px\">" + tipText + "</body></html>";
}
super.setTipText(tipText);
}
示例14: ReaderToTextPane
import javax.swing.text.StyleContext; //导入依赖的package包/类
/**
* Sets up the thread.
*
* @param input the Reader to monitor
* @param output the TextArea to send output to
* @param color the color to use
*/
public ReaderToTextPane(Reader input, JTextPane output, Color color) {
StyledDocument doc;
Style style;
setDaemon(true);
m_Color = color;
m_Input = new LineNumberReader(input);
m_Output = output;
doc = m_Output.getStyledDocument();
style = StyleContext.getDefaultStyleContext()
.getStyle(StyleContext.DEFAULT_STYLE);
style = doc.addStyle(getStyleName(), style);
StyleConstants.setFontFamily(style, "monospaced");
StyleConstants.setForeground(style, m_Color);
}
示例15: setUsers
import javax.swing.text.StyleContext; //导入依赖的package包/类
public void setUsers(User[] users){
textPane.removeAll();
StringBuilder sb = new StringBuilder();
final Style cwStyle = new StyleContext().addStyle("ConstantWidth", null);
StyleConstants.setBold(cwStyle, true);
boolean firstUser = true;
for(User user: users){
if(firstUser){
firstUser = false;
}
else{
sb.append(", ");
}
sb.append(user.getDisplayName());
}
try {
textPane.getDocument().insertString(textPane.getDocument().getLength(), "Participants: ", cwStyle);
StyleConstants.setBold(cwStyle, false);
textPane.getDocument().insertString(textPane.getDocument().getLength(), sb.toString(), cwStyle);
} catch (BadLocationException e) {
e.printStackTrace();
}
}