當前位置: 首頁>>代碼示例>>Java>>正文


Java Style.addAttribute方法代碼示例

本文整理匯總了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;
}
 
開發者ID:rossdrew,項目名稱:emuRox,代碼行數:19,代碼來源:DebuggerWindow.java

示例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;
}
 
開發者ID:otros-systems,項目名稱:otroslogviewer,代碼行數:25,代碼來源:StackTraceColorizer.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:41,代碼來源:StackTraceSupport.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:54,代碼來源:AddModulePanel.java

示例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));
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:19,代碼來源:BasicTextPaneUI.java

示例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;
}
 
開發者ID:Adrodoc55,項目名稱:MPL,代碼行數:10,代碼來源:MplSyntaxFilter.java

示例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;
}
 
開發者ID:Adrodoc55,項目名稱:MPL,代碼行數:10,代碼來源:MplSyntaxFilter.java

示例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;
}
 
開發者ID:otros-systems,項目名稱:otroslogviewer,代碼行數:15,代碼來源:StackTraceColorizer.java


注:本文中的javax.swing.text.Style.addAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。