本文整理汇总了Java中javax.swing.text.Style.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Style.addAttribute方法的具体用法?Java Style.addAttribute怎么用?Java Style.addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Style
的用法示例。
在下文中一共展示了Style.addAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCodeArea
import javax.swing.text.Style; //导入方法依赖的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: colorizeStackTraceRegex
import javax.swing.text.Style; //导入方法依赖的package包/类
protected Collection<MessageFragmentStyle> colorizeStackTraceRegex(final Style style, String text, Pattern regex, int group) {
ArrayList<MessageFragmentStyle> list = new ArrayList<>();
Matcher matcher = regex.matcher(text);
Style styleToUse = style;
while (matcher.find()) {
LocationInfo locationInfo = LocationInfo.parse(matcher.group(0));
if (locationInfo != null) {
String name = styleToUse.getName();
Style newStyle = styleContext.addStyle(name + "-" + locationInfo.toString(), styleToUse);
newStyle.addAttribute(STYLE_ATTRIBUTE_LOCATION_INFO, locationInfo);
StyleConstants.setForeground(newStyle, StyleConstants.getForeground(styleToUse));
StyleConstants.setBold(newStyle, StyleConstants.isBold(styleToUse));
StyleConstants.setItalic(newStyle, StyleConstants.isItalic(styleToUse));
styleToUse = newStyle;
}
int start = matcher.start(group);
int end = matcher.end(group);
if (end - start > 0) {
MessageFragmentStyle messageFragmentStyle = new MessageFragmentStyle(start, end - start, styleToUse, false);
list.add(messageFragmentStyle);
}
}
return list;
}
示例3: underlineStacktraces
import javax.swing.text.Style; //导入方法依赖的package包/类
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);
}
}
示例4: showDescription
import javax.swing.text.Style; //导入方法依赖的package包/类
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);
}
}
示例5: installUI
import javax.swing.text.Style; //导入方法依赖的package包/类
/**
* Installs this UI on the specified <code>JTextPane</code>. This calls the
* super implementation and then adds a default style to the text pane.
*
* @param c the text pane to install the UI to
*/
public void installUI(JComponent c)
{
super.installUI(c);
JTextPane tp = (JTextPane) c;
Style defaultStyle = tp.getStyle(StyleContext.DEFAULT_STYLE);
defaultStyle.addAttribute(StyleConstants.Foreground,
new ColorUIResource(Color.BLACK));
defaultStyle.addAttribute(StyleConstants.FontFamily, "Serif");
defaultStyle.addAttribute(StyleConstants.Italic, Boolean.FALSE);
defaultStyle.addAttribute(StyleConstants.Bold, Boolean.FALSE);
defaultStyle.addAttribute(StyleConstants.FontSize, new Integer(12));
}
示例6: getErrorAttributes
import javax.swing.text.Style; //导入方法依赖的package包/类
private Style getErrorAttributes() {
Style errorStyle = doc.getStyle("error");
if (errorStyle == null) {
errorStyle = doc.addStyle("error", getDefaultStyle());
StyleConstants.setUnderline(errorStyle, true);
errorStyle.addAttribute(UnderlineColor, Color.RED);
}
return errorStyle;
}
示例7: getWarningAttributes
import javax.swing.text.Style; //导入方法依赖的package包/类
private Style getWarningAttributes() {
Style warningStyle = doc.getStyle("warning");
if (warningStyle == null) {
warningStyle = doc.addStyle("warning", getDefaultStyle());
StyleConstants.setUnderline(warningStyle, true);
warningStyle.addAttribute(UnderlineColor, new Color(255, 215, 0));
}
return warningStyle;
}
示例8: findExceptionNameAndMessage
import javax.swing.text.Style; //导入方法依赖的package包/类
protected Collection<MessageFragmentStyle> findExceptionNameAndMessage(final Style style, String subTextFragment) {
final ArrayList<MessageFragmentStyle> result = new ArrayList<>();
Matcher matcherMessage = exceptionNameAndMessage.matcher(subTextFragment);
while (matcherMessage.find()) {
final int beginIndex = matcherMessage.start(1);
final int endIndex = matcherMessage.end(1);
final String msg = subTextFragment.substring(beginIndex, endIndex).replaceFirst("Caused by: ", "");
final Style style1 = styleContext.addStyle("exceptionMessage-" + msg, style);
style1.addAttribute(STYLE_ATTRIBUTE_EXCEPTION_MSG, msg);
result.add(new MessageFragmentStyle(beginIndex, endIndex - beginIndex, style1, false));
System.out.println("Setting style with exceptionMessage " + style1);
}
return result;
}