Java 类javax.swing.text.AttributeSet 实例源码

项目:Reinickendorf_SER316    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:incubator-netbeans    文件:EmbeddedSectionsHighlighting.java   
EmbeddedSectionsHighlighting(Document document) {
    this.document = document;

    // load the background color for the embedding token
    AttributeSet attribs = null;
    String mimeType = (String) document.getProperty("mimeType"); //NOI18N
    FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
    if (fcs != null) {
        Color jsBC = getColoring(fcs, YamlTokenId.RUBY.primaryCategory());
        if (jsBC != null) {
            attribs = AttributesUtilities.createImmutable(
                    StyleConstants.Background, jsBC,
                    ATTR_EXTENDS_EOL, Boolean.TRUE);
        }
    }
    rubyBackground = attribs;
}
项目:SER316-Munich    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:incubator-netbeans    文件:MergingPositionsBagTest.java   
public void testAddRightMatchSmallerOverlap() {
    PositionsBag hs = new PositionsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

    attribsA.addAttribute("set-A", "attribsA");
    attribsB.addAttribute("set-B", "attribsB");

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.addHighlight(pos(15), pos(20), attribsB);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> attributes = hs.getAttributes();

    assertEquals("Wrong number of highlights", 3, marks.size());
    assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset());
    assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A");

    assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset());
    assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset());
    assertAttribs("2. highlight - wrong attribs", attributes.get(1), "set-A", "set-B");
    assertNull("2. highlight - wrong end", attributes.get(2));
}
项目:incubator-netbeans    文件:CompoundHighlightsContainerTest.java   
public void testConcurrentModification() throws Exception {
    PlainDocument doc = new PlainDocument();
    PositionsBag bag = createRandomBag(doc, "layer");
    HighlightsContainer [] layers = new HighlightsContainer [] { bag };

    CompoundHighlightsContainer hb = new CompoundHighlightsContainer(doc, layers);
    HighlightsSequence hs = hb.getHighlights(0, Integer.MAX_VALUE);

    assertTrue("No highlights", hs.moveNext());
    int s = hs.getStartOffset();
    int e = hs.getEndOffset();
    AttributeSet a = hs.getAttributes();

    // Change the layers
    hb.setLayers(doc, layers);

    assertEquals("Different startOffset", s, hs.getStartOffset());
    assertEquals("Different endOffset", e, hs.getEndOffset());
    assertEquals("Different attributes", a, hs.getAttributes());

    assertFalse("There should be no further highlighs after co-modification", hs.moveNext());
}
项目:incubator-netbeans    文件:ColorsManager.java   
private static Map getCurrentColors(Language l) {
    // current colors
    FontColorSettingsFactory fcsf = EditorSettings.getDefault().
            getFontColorSettings(new String[] {l.getMimeType()});
    Collection<AttributeSet> colors = fcsf.getAllFontColors("NetBeans");
    Map<String,AttributeSet> colorsMap = new HashMap<String,AttributeSet> ();
    Iterator<AttributeSet> it = colors.iterator();
    while (it.hasNext()) {
        AttributeSet as = it.next();
        colorsMap.put(
                (String) as.getAttribute(StyleConstants.NameAttribute),
                as
                );
    }
    return colorsMap;
}
项目:SimQRI    文件:IntFilter.java   
@Override
public void replace(FilterBypass fb, int offset, int length, String text,
      AttributeSet attrs) throws BadLocationException {

   Document doc = fb.getDocument();
   StringBuilder sb = new StringBuilder();
   sb.append(doc.getText(0, doc.getLength()));
   sb.replace(offset, offset + length, text);

   if (test(sb.toString())) {
      super.replace(fb, offset, length, text, attrs);
   } else {
         JOptionPane.showMessageDialog(null,  "STOP ! You're only allowed to encode numbers !", "Warning", JOptionPane.ERROR_MESSAGE);
   }

}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testRemoveLeftOverlapClip() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();

    attribsA.addAttribute("set-name", "attribsA");

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.removeHighlights(pos(5), pos(15), true);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> atttributes = hs.getAttributes();

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 15, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 20, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", atttributes.get(1));
}
项目:incubator-netbeans    文件:AnnotationColorsPanel.java   
public VersioningSystemColors(OptionsPanelColorProvider provider) {
    this.colors = provider.getColors();
    if (colors == null) {
        throw new NullPointerException("Null colors for " + provider); // NOI18N
    }
    this.provider = provider;
    // initialize saved colors list
    savedColorAttributes = new ArrayList<AttributeSet>(colors.size());
    for (Map.Entry<String, Color[]> e : colors.entrySet()) {
        SimpleAttributeSet sas = new SimpleAttributeSet();
        StyleConstants.setBackground(sas, e.getValue()[0]);
        sas.addAttribute(StyleConstants.NameAttribute, e.getKey());
        sas.addAttribute(EditorStyleConstants.DisplayName, e.getKey());
        savedColorAttributes.add(sas);
    }
}
项目:marathonv5    文件:JEditorPaneTagJavaElement.java   
@Override public String getAttribute(final String name) {
    if ("text".equals(name)) {
        return getText();
    }
    if ("hRefIndex".equals(name)) {
        return getHRefIndex() + "";
    }
    if ("textIndex".equals(name)) {
        return getTextIndex() + "";
    }
    return EventQueueWait.exec(new Callable<String>() {
        @Override public String call() throws Exception {
            Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument());
            AttributeSet attributes = iterator.getAttributes();
            Attribute attr = findAttribute(name);
            if (attr != null && attributes.isDefined(attr)) {
                return attributes.getAttribute(attr).toString();
            }
            return null;
        }
    });
}
项目:incubator-netbeans    文件:SyntaxColoringPanel.java   
@Override
public void applyChanges() {
    if (colorModel == null) return;
    for(String profile : toBeSaved.keySet()) {
        Set<String> toBeSavedLanguages = toBeSaved.get(profile);
        Map<String, List<AttributeSet>> schemeMap = profiles.get(profile);
        for(String languageName : toBeSavedLanguages) {
            colorModel.setCategories(
                profile,
                languageName,
                schemeMap.get(languageName)
            );
        }
    }
    toBeSaved = new HashMap<String, Set<String>>();
    profiles = new HashMap<String, Map<String, List<AttributeSet>>>();
    changed = false;
}
项目:incubator-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;
    }
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:incubator-netbeans    文件:CategoryRenderer.java   
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    setComponentOrientation(list.getComponentOrientation());
    if (isSelected) {
        setBackground(list.getSelectionBackground ());
        setForeground(list.getSelectionForeground ());
    } else {
        setBackground(list.getBackground ());
        setForeground(list.getForeground ());
    }
    setIcon((Icon) ((AttributeSet) value).getAttribute ("icon"));
    setText((String) ((AttributeSet) value).getAttribute (EditorStyleConstants.DisplayName));

    setEnabled(list.isEnabled());
    setFont(list.getFont());
    setBorder(cellHasFocus ? UIManager.getBorder ("List.focusCellHighlightBorder") : noFocusBorder);
    return this;
}
项目:SER316-Munich    文件:AltHTMLWriter.java   
public CircleRegionContainment(AttributeSet as) {
    int[] coords = extractCoords(as.getAttribute(HTML.Attribute.COORDS));

    if (coords == null || coords.length != 3) {
        throw new RuntimeException("Unable to parse circular area");
    }
    x = coords[0];
    y = coords[1];
    radiusSquared = coords[2] * coords[2];
    if (coords[0] < 0 || coords[1] < 0 || coords[2] < 0) {
        lastWidth = lastHeight = -1;
        percentValues = new float[3];
        for (int counter = 0; counter < 3; counter++) {
            if (coords[counter] < 0) {
                percentValues[counter] = coords[counter] / -100.0f;
            }
            else {
                percentValues[counter] = -1.0f;
            }
        }
    }
    else {
        percentValues = null;
    }
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testConcurrentModification() {
    PositionsBag hb = new PositionsBag(doc);

    // Modify the bag
    hb.addHighlight(pos(5), pos(10), EMPTY);
    hb.addHighlight(pos(15), pos(20), EMPTY);
    hb.addHighlight(pos(25), pos(30), EMPTY);

    HighlightsSequence hs = hb.getHighlights(Integer.MIN_VALUE, Integer.MAX_VALUE);
    assertTrue("There should be some highlights", hs.moveNext());

    int s = hs.getStartOffset();
    int e = hs.getEndOffset();
    AttributeSet a = hs.getAttributes();

    // Modification after the sequence was acquired
    hb.addHighlight(pos(100), pos(110), EMPTY);

    assertEquals("Wrong highlight start", s, hs.getStartOffset());
    assertEquals("Wrong highlight end", e, hs.getEndOffset());
    assertEquals("Wrong highlight attributes", a, hs.getAttributes());
    assertFalse("There should be no more highlights after co-modification", hs.moveNext());
}
项目:incubator-netbeans    文件:MergingPositionsBagTest.java   
public void testAddCompleteMatchOverlap() {
    PositionsBag hs = new PositionsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

    attribsA.addAttribute("set-A", "attribsA");
    attribsB.addAttribute("set-B", "attribsB");

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.addHighlight(pos(10), pos(20), attribsB);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> attributes = hs.getAttributes();

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 20, marks.get(1).getOffset());
    assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A", "set-B");
    assertNull("1. highlight - wrong end", attributes.get(1));
}
项目:Neukoelln_SER316    文件:AltHTMLWriter.java   
/**
 * Writes out the attribute set.  Ignores all
 * attributes with a key of type HTML.Tag,
 * attributes with a key of type StyleConstants,
 * and attributes with a key of type
 * HTML.Attribute.ENDTAG.
 *
 * @param attr   an AttributeSet
 * @exception IOException on any I/O error
 *
 */
protected void writeAttributes(AttributeSet attr) throws IOException {
    // translate css attributes to html
    convAttr.removeAttributes(convAttr);
    convertToHTML32(attr, convAttr);

    Enumeration names = convAttr.getAttributeNames();
    while (names.hasMoreElements()) {
        Object name = names.nextElement();
        if (name instanceof HTML.Tag || name instanceof StyleConstants || name == HTML.Attribute.ENDTAG) {
            continue;
        }
        write(" " + name + "=\"" + convAttr.getAttribute(name) + "\"");
    }
}
项目:Neukoelln_SER316    文件:AltHTMLWriter.java   
/**
 * Determines if the HTML.Tag associated with the
 * element is a block tag.
 *
 * @param attr  an AttributeSet
 * @return  true if tag is block tag, false otherwise.
 */
protected boolean isBlockTag(AttributeSet attr) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        return name.isBlock();
    }
    return false;
}
项目:OpenJSharp    文件:Map.java   
public RectangleRegionContainment(AttributeSet as) {
    int[]    coords = Map.extractCoords(as.getAttribute(HTML.
                                                   Attribute.COORDS));

    percents = null;
    if (coords == null || coords.length != 4) {
        throw new RuntimeException("Unable to parse rectangular area");
    }
    else {
        x0 = coords[0];
        y0 = coords[1];
        x1 = coords[2];
        y1 = coords[3];
        if (x0 < 0 || y0 < 0 || x1 < 0 || y1 < 0) {
            percents = new float[4];
            lastWidth = lastHeight = -1;
            for (int counter = 0; counter < 4; counter++) {
                if (coords[counter] < 0) {
                    percents[counter] = Math.abs
                                (coords[counter]) / 100.0f;
                }
                else {
                    percents[counter] = -1.0f;
                }
            }
        }
    }
}
项目:SER316-Ingolstadt    文件:AltHTMLWriter.java   
/**
 * Removes the previously created area.
 */
public void removeArea(AttributeSet as) {
    if (as != null && areaAttributes != null) {
        int numAreas = (areas != null) ? areas.size() : 0;
        for (int counter = areaAttributes.size() - 1; counter >= 0; counter--) {
            if (((AttributeSet) areaAttributes.elementAt(counter)).isEqual(as)) {
                areaAttributes.removeElementAt(counter);
                if (counter < numAreas) {
                    areas.removeElementAt(counter);
                }
            }
        }
    }
}
项目:Wilmersdorf_SER316    文件:AltHTMLWriter.java   
/**
 * Convert the give set of attributes to be html for
 * the purpose of writing them out.  Any keys that
 * have been converted will not appear in the resultant
 * set.  Any keys not converted will appear in the
 * resultant set the same as the received set.<p>
 * This will put the converted values into <code>to</code>, unless
 * it is null in which case a temporary AttributeSet will be returned.
 */
AttributeSet convertToHTML(AttributeSet from, MutableAttributeSet to) {
    if (to == null) {
        to = convAttr;
    }
    to.removeAttributes(to);
    if (writeCSS) {
        convertToHTML40(from, to);
    }
    else {
        convertToHTML32(from, to);
    }
    return to;
}
项目:incubator-netbeans    文件:DirectMergeContainerTest.java   
@Test
public void testSingleLayer() throws Exception {
    RandomTestContainer container = HighlightsMergeTesting.createContainer();
    AttributeSet attrs0 = HighlightsMergeTesting.attrSets[0];
    AttributeSet attrs1 = HighlightsMergeTesting.attrSets[1];
    AttributeSet attrs2 = HighlightsMergeTesting.attrSets[2];
    HighlightsMergeTesting.addFixedLayer(container.context(), 1000, 10, 12, attrs0, 12, 15, attrs1, 15, 20, attrs2);
    HighlightsMergeTesting.checkMerge(container.context(), false);
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Determines if the HTML.Tag associated with the
 * element is a block tag.
 *
 * @param attr  an AttributeSet
 * @return  true if tag is block tag, false otherwise.
 */
protected boolean isBlockTag(AttributeSet attr) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        return name.isBlock();
    }
    return false;
}
项目:incubator-netbeans    文件:UsagesASTEvaluator.java   
private static AttributeSet getParameterAttributes () {
    if (parameterAttributeSet == null) {
        SimpleAttributeSet sas = new SimpleAttributeSet ();
        parameterAttributeSet = sas;
    }
    return parameterAttributeSet;
}
项目:incubator-netbeans    文件:CompositeFCS.java   
private String processLayer(FontColorSettingsImpl fcsi, String name, ArrayList<AttributeSet> colorings) {
    // Try colorings first
    AttributeSet as = fcsi.getColorings(profile).get(name);
    if (as == null) {
        // If not found, try the layer's default colorings
        as = fcsi.getDefaultColorings(profile).get(name);
    }

    // If we found a coloring then process it
    if (as != null) {
        colorings.add(as);

        String nameOfColoring = (String) as.getAttribute(StyleConstants.NameAttribute);
        String nameOfDelegate = (String) as.getAttribute(EditorStyleConstants.Default);
        if (nameOfDelegate != null && !nameOfDelegate.equals(FontColorNames.DEFAULT_COLORING)) {
            if (!nameOfDelegate.equals(nameOfColoring)) {
                // Find delegate on the same layer
                nameOfDelegate = processLayer(fcsi, nameOfDelegate, colorings);
            }
        } else {
            // Use the coloring's name as the default name of a delegate
            nameOfDelegate = nameOfColoring;
        }

        name = nameOfDelegate;
    }

    // Return updated name - either the name of the coloring or the name of
    // the coloring's delegate
    return name;
}
项目:incubator-netbeans    文件:AttrSet.java   
@Override
public boolean isEqual(AttributeSet attrs) {
    if (attrs == this) {
        return true;
    }
    if (attrs.getClass() == Shared.class) {
        // Since all attr sets with shared attrs are weakly cached => compare by ==
        return (this == attrs);
    } else if (attrs.getClass() == Extra.class) {
        return false; // Cannot be equal since "attrs" contains non-shared attrs
    } else {
        return isEqual(toAttrSet(attrs));
    }
}
项目:incubator-netbeans    文件:UsagesASTEvaluator.java   
private static AttributeSet getUnusedFieldAttributes () {
    if (unusedFieldAttributeSet == null) {
        SimpleAttributeSet sas = new SimpleAttributeSet ();
        sas.addAttribute (EditorStyleConstants.WaveUnderlineColor, new Color (153, 153, 153));
        StyleConstants.setForeground (sas, new Color (0, 153, 0));
        unusedFieldAttributeSet = sas;
    }
    return unusedFieldAttributeSet;
}
项目:Reinickendorf_SER316    文件:AltHTMLWriter.java   
/**
 * Returns true if the StyleConstants.NameAttribute is
 * equal to the tag that is passed in as a parameter.
 */
protected boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        if (name == tag) {
            return true;
        }
    }
    return false;
}
项目:SER316-Munich    文件:AltHTMLWriter.java   
/**
 * Returns true if the StyleConstants.NameAttribute is
 * equal to the tag that is passed in as a parameter.
 */
protected boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        HTML.Tag name = (HTML.Tag) o;
        if (name == tag) {
            return true;
        }
    }
    return false;
}
项目:incubator-netbeans    文件:AttributesUtilities.java   
public synchronized boolean containsAttributes(AttributeSet attributes) {
    for(Enumeration names = attributes.getAttributeNames(); names.hasMoreElements(); ) {
        Object name = names.nextElement();
        Object value = attributes.getAttribute(name);

        if (!containsAttribute(name, value)) {
            return false;
        }
    }

    return true;
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Searches the attribute set for a tag, both of which
 * are passed in as a parameter.  Returns true if no match is found
 * and false otherwise.
 */
private boolean noMatchForTagInAttributes(AttributeSet attr, HTML.Tag t, Object tagValue) {
    if (attr != null && attr.isDefined(t)) {
        Object newValue = attr.getAttribute(t);

        if ((tagValue == null) ? (newValue == null) : (newValue != null && tagValue.equals(newValue))) {
            return false;
        }
    }
    return true;
}
项目:SER316-Aachen    文件:AltHTMLWriter.java   
/**
 * Creates and returns an instance of RegionContainment that can be
 * used to test if a particular point lies inside a region.
 */
protected RegionContainment createRegionContainment(AttributeSet attributes) {
    Object shape = attributes.getAttribute(HTML.Attribute.SHAPE);

    if (shape == null) {
        shape = "rect";
    }
    if (shape instanceof String) {
        String shapeString = ((String) shape).toLowerCase();
        RegionContainment rc = null;

        try {
            if (shapeString.equals("rect")) {
                rc = new RectangleRegionContainment(attributes);
            }
            else if (shapeString.equals("circle")) {
                rc = new CircleRegionContainment(attributes);
            }
            else if (shapeString.equals("poly")) {
                rc = new PolygonRegionContainment(attributes);
            }
            else if (shapeString.equals("default")) {
                rc = DefaultRegionContainment.sharedInstance();
            }
        }
        catch (RuntimeException re) {
            // Something wrong with attributes.
            rc = null;
        }
        return rc;
    }
    return null;
}
项目:code-sentinel    文件:MASConsoleColorGUI.java   
public void append(Color c, String s) {
    if (c == null)
        c = defaultColor;
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet as = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
    try {
        getDocument().insertString(getDocument().getLength(), s, as);
    } catch (BadLocationException e) {            
    }
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Returns the AttributeSets representing the differet areas of the Map.
 */
public AttributeSet[] getAreas() {
    int numAttributes = (areaAttributes != null) ? areaAttributes.size() : 0;
    if (numAttributes != 0) {
        AttributeSet[] retValue = new AttributeSet[numAttributes];

        areaAttributes.copyInto(retValue);
        return retValue;
    }
    return null;
}
项目:incubator-netbeans    文件:HighlightsList.java   
/**
 * Create attribute set covering single character at {@link #startOffset()}.
 * <br>
 * The list must cover {@link #startOffset()} otherwise the behavior is undefined.
 *
 * @return attribute set.
 */
public AttributeSet cutSingleChar() {
    HighlightItem item = get(0);
    startOffset++;
    if (startOffset == item.getEndOffset()) {
        cutStartItems(1);
    }
    return item.getAttributes();
}
项目:incubator-netbeans    文件:EditorSettingsStorageTest.java   
public void testColoringsImmutability() {
    MimePath mimePath = MimePath.parse("text/x-type-A");
    Lookup lookup = MimeLookup.getLookup(mimePath);

    FontColorSettings fcs = lookup.lookup(FontColorSettings.class);
    assertNotNull("Can't find FontColorSettings", fcs);

    // Check preconditions
    AttributeSet attribs = fcs.getTokenFontColors("test-immutable");
    assertNotNull("Can't find test-immutable coloring", attribs);
    assertEquals("Wrong background color", 
        new Color(0x0A0B0C), attribs.getAttribute(StyleConstants.Background));

    // Prepare new coloring
    SimpleAttributeSet newAttribs = new SimpleAttributeSet();
    newAttribs.addAttribute(StyleConstants.NameAttribute, "test-immutable");
    newAttribs.addAttribute(StyleConstants.Background, new Color(0xFFFFF0));

    // Change the coloring
    setOneColoring("text/x-type-A", newAttribs);

    // Check that the original FontColorSettings has not changed
    attribs = fcs.getTokenFontColors("test-immutable");
    assertNotNull("Can't find test-immutable coloring", attribs);
    assertEquals("Wrong background color", 
        new Color(0x0A0B0C), attribs.getAttribute(StyleConstants.Background));

    // Check that the new attributes were set
    fcs = lookup.lookup(FontColorSettings.class);
    assertNotNull("Can't find FontColorSettings", fcs);
    attribs = fcs.getTokenFontColors("test-immutable");
    assertNotNull("Can't find test-immutable coloring", attribs);
    assertEquals("Wrong background color", 
        new Color(0xFFFFF0), attribs.getAttribute(StyleConstants.Background));
}
项目:Dahlem_SER316    文件:AltHTMLWriter.java   
/**
 * Returns the AttributeSets representing the differet areas of the Map.
 */
public AttributeSet[] getAreas() {
    int numAttributes = (areaAttributes != null) ? areaAttributes.size() : 0;
    if (numAttributes != 0) {
        AttributeSet[] retValue = new AttributeSet[numAttributes];

        areaAttributes.copyInto(retValue);
        return retValue;
    }
    return null;
}
项目:incubator-netbeans    文件:UiUtils.java   
@Override
public void replace(
        @NonNull final FilterBypass fb,
        final int offset,
        final int length,
        @NullAllowed final String text,
        @NullAllowed final AttributeSet attrs) throws BadLocationException {
    if (text == null || Utils.isValidInput(text)) {
        super.replace(fb, offset, length, text, attrs);
    } else {
        handleWrongInput();
    }
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Removes the previously created area.
 */
public void removeArea(AttributeSet as) {
    if (as != null && areaAttributes != null) {
        int numAreas = (areas != null) ? areas.size() : 0;
        for (int counter = areaAttributes.size() - 1; counter >= 0; counter--) {
            if (((AttributeSet) areaAttributes.elementAt(counter)).isEqual(as)) {
                areaAttributes.removeElementAt(counter);
                if (counter < numAreas) {
                    areas.removeElementAt(counter);
                }
            }
        }
    }
}