javax.swing.text.SimpleAttributeSet#EMPTY源码实例Demo

下面列出了javax.swing.text.SimpleAttributeSet#EMPTY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: GuardedBlockSuppressLayer.java
private AttributeSet getAttribs(String coloringName, boolean extendsEol, boolean extendsEmptyLine) {
    FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
    AttributeSet attribs = fcs.getFontColors(coloringName);
    
    if (attribs == null) {
        attribs = SimpleAttributeSet.EMPTY;
    } else if (extendsEol || extendsEmptyLine) {
        attribs = AttributesUtilities.createImmutable(
            attribs, 
            AttributesUtilities.createImmutable(
                ATTR_EXTENDS_EOL, Boolean.valueOf(extendsEol),
                ATTR_EXTENDS_EMPTY_LINE, Boolean.valueOf(extendsEmptyLine))
        );
    }
    
    return attribs;
}
 
源代码2 项目: netbeans   文件: AttributesUtilities.java
/**
 * Creates an immutable <code>AttributeSet</code> as a copy of <code>AttributeSet</code>s
 * passed into this method. If the <code>AttributeSet</code>s
 * contain attributes with the same name the resulting <code>AttributeSet</code>
 * will return value of the first attribute it will find going through
 * the sets in the order as they were passed in.
 *
 * @param sets    The <code>AttributeSet</code>s which attributes will become
 *                a contents of the newly created <code>AttributeSet</code>.
 *
 * @return The new immutable <code>AttributeSet</code>.
 */
public static AttributeSet createImmutable(AttributeSet... sets) {
    if (true) {
        return org.netbeans.modules.editor.settings.AttrSet.merge(sets);
    }
    HashMap<Object, Object> map = new HashMap<Object, Object>();
    
    for(int i = sets.length - 1; i >= 0; i--) {
        AttributeSet set = sets[i];
        for(Enumeration<?> keys = set.getAttributeNames(); keys.hasMoreElements(); ) {
            Object attrKey = keys.nextElement();
            Object attrValue = set.getAttribute(attrKey);

            map.put(attrKey, attrValue);
        }
    }

    return map.size() > 0 ? new Immutable(map) : SimpleAttributeSet.EMPTY;
}
 
源代码3 项目: netbeans   文件: CaretBasedBlockHighlighting.java
void setAttrs(Lookup.Result<FontColorSettings> result) {
    if (Boolean.TRUE.equals(component.getClientProperty("AsTextField"))) {
        if (UIManager.get("TextField.selectionBackground") != null) {
            attribs = AttributesUtilities.createImmutable(
                    StyleConstants.Background, (Color) UIManager.get("TextField.selectionBackground"),
                    StyleConstants.Foreground, (Color) UIManager.get("TextField.selectionForeground"));
        } else {
            final JTextField referenceTextField = (JTextField) new JComboBox<String>().getEditor().getEditorComponent();
            attribs = AttributesUtilities.createImmutable(
                    StyleConstants.Background, referenceTextField.getSelectionColor(),
                    StyleConstants.Foreground, referenceTextField.getSelectedTextColor());
        }
        return;
    }
    FontColorSettings fcs = result.allInstances().iterator().next();
    attribs = fcs.getFontColors(coloringName);
    if (attribs == null) {
        attribs = SimpleAttributeSet.EMPTY;
    } else if (extendsEOL || extendsEmptyLine) {
        attribs = AttributesUtilities.createImmutable(
                attribs,
                AttributesUtilities.createImmutable(
                ATTR_EXTENDS_EOL, Boolean.valueOf(extendsEOL),
                ATTR_EXTENDS_EMPTY_LINE, Boolean.valueOf(extendsEmptyLine)));
    }
}
 
源代码4 项目: netbeans   文件: BlockHighlighting.java
private AttributeSet getAttribs(String coloringName, boolean extendsEol, boolean extendsEmptyLine) {
    FontColorSettings fcs = MimeLookup.getLookup(getMimeType(component)).lookup(FontColorSettings.class);
    AttributeSet attribs = fcs.getFontColors(coloringName);
    
    if (attribs == null) {
        attribs = SimpleAttributeSet.EMPTY;
    } else if (extendsEol || extendsEmptyLine) {
        attribs = AttributesUtilities.createImmutable(
            attribs, 
            AttributesUtilities.createImmutable(
                ATTR_EXTENDS_EOL, Boolean.valueOf(extendsEol),
                ATTR_EXTENDS_EMPTY_LINE, Boolean.valueOf(extendsEmptyLine))
        );
    }
    
    return attribs;
}
 
源代码5 项目: netbeans   文件: ComposedTextHighlighting.java
private AttributeSet translateAttributes(Map<AttributedCharacterIterator.Attribute, ?> source) {
    for(AttributedCharacterIterator.Attribute sourceKey : source.keySet()) {
        Object sourceValue = source.get(sourceKey);
        
        // Ignore any non-input method related highlights
        if (!(sourceValue instanceof InputMethodHighlight)) {
            continue;
        }
        
        InputMethodHighlight imh = (InputMethodHighlight) sourceValue;
        
        if (imh.isSelected()) {
            return highlightInverse;
        } else {
            return highlightUnderlined;
        }
    }
    
    LOG.fine("No translation for " + source);
    return SimpleAttributeSet.EMPTY;
}
 
源代码6 项目: netbeans   文件: NonLexerSyntaxHighlighting.java
private AttributeSet findAttribs(TokenItem tokenItem) {
    synchronized (this) {
        AttributeSet attribs = attribsCache.get(tokenItem.getTokenID());

        if (attribs == null) {
            FontColorSettings fcs = MimeLookup.getLookup(mimePath).lookup(FontColorSettings.class);
            if (fcs != null) {
                attribs = findFontAndColors(fcs, tokenItem);
                if (attribs == null) {
                    attribs = SimpleAttributeSet.EMPTY;
                }
                
                attribsCache.put(tokenItem.getTokenID(), attribs);
            } else {
                LOG.warning("Can't find FCS for mime path: '" + mimePath.getPath() + "'"); //NOI18N
            }
        }

        return attribs == null ? SimpleAttributeSet.EMPTY : attribs;
    }
}
 
源代码7 项目: netbeans   文件: EmbeddingHighlightsContainer.java
EmbeddingHighlightsContainer(Document document) {
    this.document = document;

    //try load the background from tpl settings
    FontColorSettings fcs = MimeLookup.getLookup(TplDataLoader.MIME_TYPE).lookup(FontColorSettings.class);
    Color tplBG = null;
    if (fcs != null) {
        tplBG = getColoring(fcs, TPL_BACKGROUND_TOKEN_NAME);
    }

    tplBackground = tplBG == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable(
        StyleConstants.Background, tplBG, ATTR_EXTENDS_EOL, Boolean.TRUE);
}
 
源代码8 项目: netbeans   文件: AttributesUtilities.java
/**
 * Creates a proxy <code>AttributeSet</code> that will delegate to the
 * <code>AttributeSet</code>s passed in as a parameter. If the <code>AttributeSet</code>s
 * contain attributes with the same name the composite <code>AttributeSet</code>
 * will return value of the first attribute it will find going through
 * the sets in the order as they were passed in.
 *
 * @param sets    The <code>AttributeSet</code>s to delegate to.
 *
 * @return The new composite <code>AttributeSet</code> that will delegate
 *         to the <code>sets</code> passed in.
 */
public static AttributeSet createComposite(AttributeSet... sets) {
    if (true) {
        return org.netbeans.modules.editor.settings.AttrSet.merge(sets);
    }
    if (sets.length == 0) {
        return SimpleAttributeSet.EMPTY;
    } else if (sets.length == 1) {
        return sets[0];
    } else {
        LinkedList<AttributeSet> all = new LinkedList<AttributeSet>();

        for(AttributeSet s : sets) {
            if (s instanceof AttributesUtilities.CompositeAttributeSet) {
                all.addAll(((AttributesUtilities.CompositeAttributeSet) s).getDelegates());
            } else if (s != null && s != SimpleAttributeSet.EMPTY) {
                all.add(s);
            }
        }

        switch (all.size()) {
            case 0: return SimpleAttributeSet.EMPTY;
            case 1: return all.get(0);
            case 2: return new Composite2(all.get(0), all.get(1));
            case 3: return new Composite4(all.get(0), all.get(1), all.get(2), null);
            case 4: return new Composite4(all.get(0), all.get(1), all.get(2), all.get(3));
            default: return new BigComposite(all);
        }
    }
}
 
源代码9 项目: netbeans   文件: CompoundAttributes.java
private AttributeSet firstItemAttrs() {
    AttributeSet attrs = highlightItems[0].getAttributes();
    if (attrs == null) {
        attrs = SimpleAttributeSet.EMPTY;
    }
    return attrs;
}
 
源代码10 项目: netbeans   文件: BracesMatchHighlighting.java
public BracesMatchHighlighting(JTextComponent component, Document document) {
    this.document = document;

    String mimeType = getMimeType(component);
    MimePath mimePath = mimeType == null ? MimePath.EMPTY : MimePath.parse(mimeType);

    // Load the colorings
    FontColorSettings fcs = MimeLookup.getLookup(mimePath).lookup(FontColorSettings.class);
    AttributeSet match = fcs.getFontColors(BRACES_MATCH_COLORING);
    AttributeSet mismatch = fcs.getFontColors(BRACES_MISMATCH_COLORING);
    AttributeSet matchMultichar = fcs.getFontColors(BRACES_MATCH_MULTICHAR_COLORING);
    AttributeSet mismatchMultichar = fcs.getFontColors(BRACES_MISMATCH_MULTICHAR_COLORING);
    this.bracesMatchColoring = match != null ? match : SimpleAttributeSet.EMPTY;
    this.bracesMismatchColoring = mismatch != null ? mismatch : SimpleAttributeSet.EMPTY;
    this.bracesMatchMulticharColoring = matchMultichar != null ? matchMultichar : SimpleAttributeSet.EMPTY;
    this.bracesMismatchMulticharColoring = mismatchMultichar != null ? mismatchMultichar : SimpleAttributeSet.EMPTY;
    
    // Create and hook up the highlights bag
    this.bag = new OffsetsBag(document, true);
    this.bag.addHighlightsChangeListener(this);
    
    // Hook up the component
    this.component = component;
    this.component.addPropertyChangeListener(WeakListeners.propertyChange(this, this.component));

    // Hook up the caret
    this.caret = component.getCaret();
    if (this.caret != null) {
        this.caretListener = WeakListeners.change(this, this.caret);
        this.caret.addChangeListener(caretListener);
    }

    // Refresh the layer
    refresh();
}
 
源代码11 项目: netbeans   文件: MasterMatcherTest.java
public void testAreas() throws Exception {
    MockServices.setServices(MockMimeLookup.class);
    MockMimeLookup.setInstances(MimePath.EMPTY, new TestMatcher());
    
    AttributeSet EAS = SimpleAttributeSet.EMPTY;
    JEditorPane c = new JEditorPane();
    Document d = c.getDocument();
    OffsetsBag bag = new OffsetsBag(d);
    d.insertString(0, "text text { text } text", null);

    c.putClientProperty(MasterMatcher.PROP_MAX_BACKWARD_LOOKAHEAD, 256);
    c.putClientProperty(MasterMatcher.PROP_MAX_FORWARD_LOOKAHEAD, 256);
    
    TestMatcher.origin = new int [] { 2, 3 };
    TestMatcher.matches = new int [] { 10, 11 };
    
    MasterMatcher.get(c).highlight(d, 7, bag, EAS, EAS, EAS, EAS);
    TestMatcher.waitUntilCreated(1000);
    {
    TestMatcher tm = TestMatcher.lastMatcher;
    assertNotNull("No matcher created", tm);
    
    HighlightsSequence hs = bag.getHighlights(0, Integer.MAX_VALUE);
    assertTrue("Wrong number of highlighted areas", hs.moveNext());
    assertEquals("Wrong origin startOfset", 2, hs.getStartOffset());
    assertEquals("Wrong origin endOfset", 3, hs.getEndOffset());
    
    assertTrue("Wrong number of highlighted areas", hs.moveNext());
    assertEquals("Wrong match startOfset", 10, hs.getStartOffset());
    assertEquals("Wrong match endOfset", 11, hs.getEndOffset());
    }        
}
 
源代码12 项目: netbeans   文件: LineElement.java
public AttributeSet getAttributes() {
    AttributeSet as = attributes;
    return as == null ? SimpleAttributeSet.EMPTY : as;
}
 
源代码13 项目: netbeans   文件: BaseElement.java
/** Get attributes of this element */
public AttributeSet getAttributes() {
    AttributeSet as = attrs;
    return as == null ? SimpleAttributeSet.EMPTY : as;
}
 
源代码14 项目: netbeans   文件: TextSearchHighlighting.java
private AttributeSet getAttribs() {
    FontColorSettings fcs = MimeLookup.getLookup(mimePath).lookup(FontColorSettings.class);
    AttributeSet attribs = fcs.getFontColors(FontColorNames.HIGHLIGHT_SEARCH_COLORING);
    return attribs == null ? SimpleAttributeSet.EMPTY : attribs;
}
 
源代码15 项目: netbeans   文件: GsfSemanticLayer.java
@Override
public AttributeSet getAttributes() {
    return (element != null)
            ? layer.getColoring(element.coloring, element.language)
            : SimpleAttributeSet.EMPTY;
}
 
源代码16 项目: netbeans   文件: AbstractRootElement.java
@Override
public AttributeSet getAttributes() {
    return SimpleAttributeSet.EMPTY;
}
 
源代码17 项目: netbeans   文件: LineElement.java
@Override
public AttributeSet getAttributes() {
    // Do not return null since Swing's view factories assume that this is non-null.
    return (attributes instanceof AttributeSet) ? (AttributeSet) attributes : SimpleAttributeSet.EMPTY;
}
 
源代码18 项目: netbeans   文件: LineRootElement.java
@Override
public AttributeSet getAttributes() {
    // Do not return null since Swing's view factories assume that this is non-null.
    return SimpleAttributeSet.EMPTY;
}
 
源代码19 项目: netbeans   文件: AbstractPositionElement.java
@Override
public AttributeSet getAttributes() {
    // Do not return null since Swing's view factories assume that this is non-null.
    return SimpleAttributeSet.EMPTY;
}
 
源代码20 项目: netbeans   文件: TextRegionManager.java
private static AttributeSet getSyncedTextBlocksHighlight() {
    FontColorSettings fcs = MimeLookup.getLookup(MimePath.EMPTY).lookup(FontColorSettings.class);
    AttributeSet as = fcs.getFontColors("synchronized-text-blocks-ext"); //NOI18N
    return as == null ? SimpleAttributeSet.EMPTY : as;
}