当前位置: 首页>>代码示例>>Java>>正文


Java StyledDocument.setCharacterAttributes方法代码示例

本文整理汇总了Java中javax.swing.text.StyledDocument.setCharacterAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java StyledDocument.setCharacterAttributes方法的具体用法?Java StyledDocument.setCharacterAttributes怎么用?Java StyledDocument.setCharacterAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.StyledDocument的用法示例。


在下文中一共展示了StyledDocument.setCharacterAttributes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setFontName

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Set the font name. */
public void setFontName(String fontName) {
	if (log == null)
		return;
	this.fontName = fontName;
	log.setFont(new Font(fontName, Font.PLAIN, fontSize));
	StyleConstants.setFontFamily(styleRegular, fontName);
	StyleConstants.setFontFamily(styleBold, fontName);
	StyleConstants.setFontFamily(styleRed, fontName);
	StyleConstants.setFontSize(styleRegular, fontSize);
	StyleConstants.setFontSize(styleBold, fontSize);
	StyleConstants.setFontSize(styleRed, fontSize);
	// Changes all existing text
	StyledDocument doc = log.getStyledDocument();
	Style temp = doc.addStyle("temp", null);
	StyleConstants.setFontFamily(temp, fontName);
	StyleConstants.setFontSize(temp, fontSize);
	doc.setCharacterAttributes(0, doc.getLength(), temp, false);
	// Changes all existing hyperlinks
	Font newFont = new Font(fontName, Font.BOLD, fontSize);
	for (JLabel link : links) {
		link.setFont(newFont);
	}
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:25,代码来源:SwingLogPanel.java

示例2: setFontName

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
/** Set the font name. */
public void setFontName(String fontName) {
    if (log==null) return;
    this.fontName = fontName;
    log.setFont(new Font(fontName, Font.PLAIN, fontSize));
    StyleConstants.setFontFamily(styleRegular, fontName);
    StyleConstants.setFontFamily(styleBold, fontName);
    StyleConstants.setFontFamily(styleRed, fontName);
    StyleConstants.setFontSize(styleRegular, fontSize);
    StyleConstants.setFontSize(styleBold, fontSize);
    StyleConstants.setFontSize(styleRed, fontSize);
    // Changes all existing text
    StyledDocument doc=log.getStyledDocument();
    Style temp=doc.addStyle("temp", null);
    StyleConstants.setFontFamily(temp, fontName);
    StyleConstants.setFontSize(temp, fontSize);
    doc.setCharacterAttributes(0, doc.getLength(), temp, false);
    // Changes all existing hyperlinks
    Font newFont = new Font(fontName, Font.BOLD, fontSize);
    for(JLabel link: links) { link.setFont(newFont); }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:22,代码来源:SwingLogPanel.java

示例3: showDescription

import javax.swing.text.StyledDocument; //导入方法依赖的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

示例4: insertString

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
@Override
public void insertString(StyledDocument sd, Style style) throws BadLocationException {
    sd.insertString(sd.getLength(), text, style);
    for (int i = 0; i < length; i++) {
        sd.setCharacterAttributes(sd.getLength() - text.length() + start[i], end[i] - start[i], issueHyperlinkStyle, false);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:VCSHyperlinkSupport.java

示例5: getListCellRendererComponent

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    GitRevisionInfoDelegate revision = (GitRevisionInfoDelegate) value;
    StyledDocument sd = getStyledDocument();

    String tooltip = null;
    Style style;
    Color backgroundColor;

    if (isSelected) {
        backgroundColor = selectionBackground;
        style = selectedStyle;
    } else {
        backgroundColor = UIManager.getColor("List.background"); // NOI18N
        style = normalStyle;
    }
    setBackground(backgroundColor);

    try {
        // clear document
        StringBuilder sb = new StringBuilder();
        String revStr = revision.getRevision();
        sb.append(revStr.length() > 7 ? revStr.substring(0, 7) : revStr).append(" - "); //NOI18N
        sb.append(revision.getMessage());
        tooltip = sb.toString();
        sd.remove(0, sd.getLength());
        String text = sb.toString();
        sd.insertString(0, text, style);
        String filter = txtFilter.getText().toLowerCase();
        if (!isSelected && !filter.isEmpty()) {
            text = text.toLowerCase();
            int pos = -filter.length();
            while ((pos = text.indexOf(filter, pos + filter.length())) > -1) {
                sd.setCharacterAttributes(pos, filter.length(), selectedStyle, false);
            }
        }
    } catch (BadLocationException e) {
        //
    }
    setToolTipText(tooltip);

    return this;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:RevisionListPanel.java

示例6: setDocument

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
public void setDocument(StyledDocument doc, List<HighlightImpl> golden, List<HighlightImpl> test, File goldenFile, File testFile) {
    this.golden = golden;
    this.test = test;
    this.goldenFile = goldenFile;
    this.testFile = testFile;
    List<HighlightImpl> missing = new ArrayList<HighlightImpl>();
    List<HighlightImpl> added   = new ArrayList<HighlightImpl>();
    
    Map<String, HighlightImpl> name2Golden = new HashMap<String, HighlightImpl>();
    Map<String, HighlightImpl> name2Test   = new HashMap<String, HighlightImpl>();
    
    for (HighlightImpl g : golden) {
        name2Golden.put(g.getHighlightTestData(), g);
    }
    
    for (HighlightImpl t : test) {
        name2Test.put(t.getHighlightTestData(), t);
    }
    
    Set<String> missingNames = new HashSet<String>(name2Golden.keySet());
    
    missingNames.removeAll(name2Test.keySet());
    
    for (String m : missingNames) {
        missing.add(name2Golden.get(m));
    }
    
    Set<String> addedNames = new HashSet<String>(name2Test.keySet());
    
    addedNames.removeAll(name2Golden.keySet());
    
    for (String a : addedNames) {
        added.add(name2Test.get(a));
    }
    
    List<HighlightImpl> modified = new ArrayList<HighlightImpl>();
    
    modified.addAll(missing);
    modified.addAll(added);
    
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet as = sc.getEmptySet();
    
    as = sc.addAttribute(as, StyleConstants.Foreground, Color.RED);
    as = sc.addAttribute(as, StyleConstants.Bold, Boolean.TRUE);
    
    for (HighlightImpl h : modified) {
        doc.setCharacterAttributes(h.getStart(), h.getEnd() - h.getStart(), as, false);
    }
    
    jEditorPane1.setContentType("text/html");
    jEditorPane1.setDocument(doc);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:ShowGoldenFilesPanel.java

示例7: addAuthor

import javax.swing.text.StyledDocument; //导入方法依赖的package包/类
private void addAuthor (JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {
    LogEntry entry = item.getUserData();
    StyledDocument sd = pane.getStyledDocument();
    clearSD(pane, sd);
    Style selectedStyle = createSelectedStyle(pane);
    Style normalStyle = createNormalStyle(pane);
    Style style;
    if (selected) {
        style = selectedStyle;
    } else {
        style = normalStyle;
    }
    Style authorStyle = createAuthorStyle(pane, normalStyle);
    Style hiliteStyle = createHiliteStyleStyle(pane, normalStyle, searchHiliteAttrs);
    String author = entry.getAuthor();
    AuthorLinker l = linkerSupport.getLinker(VCSHyperlinkSupport.AuthorLinker.class, id);
    if(l == null) {
        VCSKenaiAccessor.KenaiUser kenaiUser = getKenaiUser(author);
        if (kenaiUser != null) {
            l = new VCSHyperlinkSupport.AuthorLinker(kenaiUser, authorStyle, sd, author);
            linkerSupport.add(l, id);
        }
    }
    int pos = sd.getLength();
    if(l != null) {
        l.insertString(sd, selected ? style : null);
    } else {
        sd.insertString(sd.getLength(), author, style);
    }
    if (!selected) {
        for (SearchHighlight highlight : highlights) {
            if (highlight.getKind() == SearchHighlight.Kind.AUTHOR) {
                int doclen = sd.getLength();
                String highlightMessage = highlight.getSearchText();
                String authorText = sd.getText(pos, doclen - pos).toLowerCase();
                int idx = authorText.indexOf(highlightMessage);
                if (idx > -1) {
                    sd.setCharacterAttributes(doclen - authorText.length() + idx, highlightMessage.length(), hiliteStyle, false);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:SummaryCellRenderer.java


注:本文中的javax.swing.text.StyledDocument.setCharacterAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。