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

项目:openvisualtraceroute    文件:PacketDetailPanel.java   
private void showPacket(final AbstractPacketPoint point) {
    SwingUtilities4.invokeInEDT(() -> {
        final String[] lines = point.getPayload().split("\n");
        int max = 0;
        for (final String line1 : lines) {
            max = Math.max(max, line1.length());
        }
        max += 5;
        for (final String line2 : lines) {
            final Color color = colorForLine(line2);
            final StyleContext sc = StyleContext.getDefaultStyleContext();
            AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.BLACK);

            aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
            aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
            aset = sc.addAttribute(aset, StyleConstants.Bold, false);
            aset = sc.addAttribute(aset, StyleConstants.Background, color);
            final int len = _details.getDocument().getLength();
            _details.setCaretPosition(len);
            _details.setCharacterAttributes(aset, false);
            _details.replaceSelection(line2 + StringUtils.repeat(" ", max - line2.length()) + "\n");
        }
        _details.setCaretPosition(0);
    });
}
项目:litiengine    文件:ConsoleLogHandler.java   
@Override
public void publish(final LogRecord record) {
  StyledDocument doc = textPane.getStyledDocument();
  SimpleAttributeSet keyWord = new SimpleAttributeSet();
  StyleConstants.setForeground(keyWord, getColor(record.getLevel()));
  StyleConstants.setBold(keyWord, true);
  StyleConstants.setFontSize(keyWord, 12);
  StyleConstants.setFontFamily(keyWord, CONSOLE_FONT);

  SimpleAttributeSet text = new SimpleAttributeSet();
  StyleConstants.setForeground(text, getColor(record.getLevel()));
  StyleConstants.setFontFamily(text, CONSOLE_FONT);
  try {
    doc.insertString(doc.getLength(), String.format("%1$-10s", record.getLevel()), keyWord);
    if (record.getParameters() != null) {
      doc.insertString(doc.getLength(), MessageFormat.format(record.getMessage(), record.getParameters()), text);
    } else {
      doc.insertString(doc.getLength(), record.getMessage(), text);
    }

    doc.insertString(doc.getLength(), "\n", text);
  } catch (BadLocationException e) {
  }

  textPane.setCaretPosition(doc.getLength());
}
项目:incubator-netbeans    文件:DiffColorsPanel.java   
private void updateData () {
    int index = lCategories.getSelectedIndex();
    if (index < 0) return;

    List<AttributeSet> categories = getCategories();
    AttributeSet category = categories.get(lCategories.getSelectedIndex());
    SimpleAttributeSet c = new SimpleAttributeSet(category);

    Color color = cbBackground.getSelectedColor();
    if (color != null) {
        c.addAttribute(StyleConstants.Background, color);
    } else {
        c.removeAttribute(StyleConstants.Background);
    }

    categories.set(index, c);
}
项目:incubator-netbeans    文件:ProxyHighlightsContainerTest.java   
public void testEvents2() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);

    hsA.addHighlight(new SimplePosition(10), new SimplePosition(20), new SimpleAttributeSet());
    hsB.addHighlight(new SimplePosition(11), new SimplePosition(12), new SimpleAttributeSet());

    ProxyHighlightsContainer chc = new ProxyHighlightsContainer();
    Listener listener = new Listener();
    chc.addHighlightsChangeListener(listener);

    // changing delegate layers fires event covering 'all' offsets
    chc.setLayers(doc, new HighlightsContainer [] { hsA, hsB });
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 0, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", Integer.MAX_VALUE, listener.lastEventEndOffset);
}
项目:incubator-netbeans    文件:SyntaxColoringPanel.java   
private Collection<AttributeSet> invertCategory (Collection<AttributeSet> c, AttributeSet category) {
    if (category == null) return c;
    ArrayList<AttributeSet> result = new ArrayList<AttributeSet> (c);
    int i = result.indexOf (category);
    SimpleAttributeSet as = new SimpleAttributeSet (category);
    Color highlight = (Color) getValue (currentLanguage, category, StyleConstants.Background);
    if (highlight == null) return result;
    Color newColor = new Color (
        255 - highlight.getRed (),
        255 - highlight.getGreen (),
        255 - highlight.getBlue ()
    );
    as.addAttribute (
        StyleConstants.Underline,
        newColor
    );
    result.set (i, as);
    return result;
}
项目:incubator-netbeans    文件:CompoundHighlightsContainerTest.java   
public void testEvents() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);

    CompoundHighlightsContainer chc = new CompoundHighlightsContainer(doc, new HighlightsContainer [] { hsA, hsB });
    Listener listener = new Listener();
    chc.addHighlightsChangeListener(listener);

    hsA.addHighlight(new SimplePosition(10), new SimplePosition(20), new SimpleAttributeSet());
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 10, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", 20, listener.lastEventEndOffset);

    listener.reset();
    hsB.addHighlight(new SimplePosition(11), new SimplePosition(12), new SimpleAttributeSet());
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 11, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", 12, listener.lastEventEndOffset);
}
项目:incubator-netbeans    文件:CompoundHighlightsContainerTest.java   
public void testEvents2() {
    PlainDocument doc = new PlainDocument();
    PositionsBag hsA = new PositionsBag(doc);
    PositionsBag hsB = new PositionsBag(doc);

    hsA.addHighlight(new SimplePosition(10), new SimplePosition(20), new SimpleAttributeSet());
    hsB.addHighlight(new SimplePosition(11), new SimplePosition(12), new SimpleAttributeSet());

    CompoundHighlightsContainer chc = new CompoundHighlightsContainer();
    Listener listener = new Listener();
    chc.addHighlightsChangeListener(listener);

    // changing delegate layers fires event covering 'all' offsets
    chc.setLayers(doc, new HighlightsContainer [] { hsA, hsB });
    assertEquals("Wrong number of events", 1, listener.eventsCnt);
    assertEquals("Wrong change start offset", 0, listener.lastEventStartOffset);
    assertEquals("Wrong change end offset", Integer.MAX_VALUE, listener.lastEventEndOffset);
}
项目:incubator-netbeans    文件:PositionsBagMemoryTest.java   
private void checkMemoryConsumption(boolean merging, boolean bestCase) {
    PositionsBag bag = new PositionsBag(new PlainDocument(), merging);

    for(int i = 0; i < CNT; i++) {
        if (bestCase) {
            bag.addHighlight(new SimplePosition(i * 10), new SimplePosition((i + 1) * 10), SimpleAttributeSet.EMPTY);
        } else {
            bag.addHighlight(new SimplePosition(i * 10), new SimplePosition(i* 10 + 5), SimpleAttributeSet.EMPTY);
        }
    }

    compact(bag);

    assertSize("PositionsBag of " + CNT + " highlights " + (bestCase ? "(best case)" : "(worst case)"),
        Collections.singleton(bag), bestCase ? 8500 : 16500, new MF());
}
项目:incubator-netbeans    文件:ColorsManager.java   
private static AttributeSet getUnusedFieldAttributes () {
    if (unusedFieldAttributeSet == null) {
        SimpleAttributeSet sas = new SimpleAttributeSet ();
        StyleConstants.setForeground (sas, new Color (115, 115, 115));
        StyleConstants.setBold (sas, true);
        unusedFieldAttributeSet = sas;
    }
    return unusedFieldAttributeSet;
}
项目:incubator-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;
}
项目:incubator-netbeans    文件:MergingPositionsBagTest.java   
public void testOrdering() {
    PositionsBag hs = new PositionsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

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

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

    assertEquals("Wrong number of highlights", 4, marks.size());
    assertEquals("1. highlight - wrong attribs", "value-A", attributes.get(0).getAttribute("attribute"));
    assertEquals("2. highlight - wrong attribs", "value-B", attributes.get(1).getAttribute("attribute"));
    assertEquals("3. highlight - wrong attribs", "value-B", attributes.get(2).getAttribute("attribute"));
    assertNull("3. highlight - wrong end", attributes.get(3));
}
项目:incubator-netbeans    文件:OffsetsBagTest.java   
public void testRemoveAligned2Clip() {
    OffsetsBag hs = new OffsetsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();

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

    hs.addHighlight(10, 40, attribsA);
    hs.removeHighlights(10, 20, true);
    OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 20, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 40, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", marks.get(0).getAttributes().getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", marks.get(1).getAttributes());

    hs.removeHighlights(30, 40, true);

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 20, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 30, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", marks.get(0).getAttributes().getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", marks.get(1).getAttributes());
}
项目:incubator-netbeans    文件:MergingOffsetsBagTest.java   
public void testAddRightOverlap() {
    OffsetsBag hs = new OffsetsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

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

    hs.addHighlight(10, 20, attribsA);
    hs.addHighlight(15, 25, attribsB);
    OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();

    assertEquals("Wrong number of highlights", 4, 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", marks.get(0).getAttributes(), "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", marks.get(1).getAttributes(), "set-A", "set-B");

    assertEquals("3. highlight - wrong start offset", 20, marks.get(2).getOffset());
    assertEquals("3. highlight - wrong end offset", 25, marks.get(3).getOffset());
    assertAttribs("3. highlight - wrong attribs", marks.get(2).getAttributes(), "set-B");
    assertNull("3. highlight - wrong end", marks.get(3).getAttributes());
}
项目:rapidminer    文件:LogRecordEntry.java   
/**
 * Creates a new {@link LogRecordEntry} which automatically formats the given {@link LogRecord}
 * with the RapidMiner Studio log styling and default logging format.
 *
 * @param logRecord
 */
public LogRecordEntry(LogRecord logRecord) {

    logLevel = logRecord.getLevel();
    initialString = logRecord.getMessage();

    simpleAttributeSet = new SimpleAttributeSet();
    if (logRecord.getLevel().intValue() >= Level.SEVERE.intValue()) {
        StyleConstants.setForeground(simpleAttributeSet, COLOR_ERROR);
        StyleConstants.setBold(simpleAttributeSet, true);
    } else if (logRecord.getLevel().intValue() >= Level.WARNING.intValue()) {
        StyleConstants.setForeground(simpleAttributeSet, COLOR_WARNING);
        StyleConstants.setBold(simpleAttributeSet, true);
    } else if (logRecord.getLevel().intValue() >= Level.INFO.intValue()) {
        StyleConstants.setForeground(simpleAttributeSet, COLOR_INFO);
        StyleConstants.setBold(simpleAttributeSet, false);
    } else {
        StyleConstants.setForeground(simpleAttributeSet, COLOR_DEFAULT);
        StyleConstants.setBold(simpleAttributeSet, false);
    }

    formattedString = formatter.format(logRecord);
}
项目:incubator-netbeans    文件:MergingOffsetsBagTest.java   
public void testAddRightMatchSmallerOverlap() {
    OffsetsBag hs = new OffsetsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

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

    hs.addHighlight(10, 20, attribsA);
    hs.addHighlight(15, 20, attribsB);
    OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();

    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", marks.get(0).getAttributes(), "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", marks.get(1).getAttributes(), "set-A", "set-B");
    assertNull("2. highlight - wrong end", marks.get(2).getAttributes());
}
项目:incubator-netbeans    文件:MergingOffsetsBagTest.java   
public void testAddSmallerOverlap() {
    OffsetsBag hs = new OffsetsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

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

    hs.addHighlight(5, 25, attribsA);
    hs.addHighlight(10, 20, attribsB);
    OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();

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

    assertEquals("2. highlight - wrong start offset", 10, marks.get(1).getOffset());
    assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset());
    assertAttribs("2. highlight - wrong attribs", marks.get(1).getAttributes(), "set-A", "set-B");

    assertEquals("3. highlight - wrong start offset", 20, marks.get(2).getOffset());
    assertEquals("3. highlight - wrong end offset", 25, marks.get(3).getOffset());
    assertAttribs("3. highlight - wrong attribs", marks.get(0).getAttributes(), "set-A");
    assertNull("3. highlight - wrong end", marks.get(3).getAttributes());
}
项目:incubator-netbeans    文件:MergingOffsetsBagTest.java   
public void testOrdering() {
    OffsetsBag hs = new OffsetsBag(doc, true);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

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

    hs.addHighlight(5, 15, attribsA);
    hs.addHighlight(10, 20, attribsB);
    OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();

    assertEquals("Wrong number of highlights", 4, marks.size());
    assertEquals("1. highlight - wrong attribs", "value-A", marks.get(0).getAttributes().getAttribute("attribute"));
    assertEquals("2. highlight - wrong attribs", "value-B", marks.get(1).getAttributes().getAttribute("attribute"));
    assertEquals("3. highlight - wrong attribs", "value-B", marks.get(2).getAttributes().getAttribute("attribute"));
    assertNull("3. highlight - wrong end", marks.get(3).getAttributes());
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testAddLeftOverlap() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

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

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

    assertEquals("Wrong number of highlights", 3, marks.size());
    assertEquals("1. highlight - wrong start offset", 5, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsB", atttributes.get(0).getAttribute("set-name"));

    assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset());
    assertEquals("2. highlight - wrong end offset", 20, marks.get(2).getOffset());
    assertEquals("2. highlight - wrong attribs", "attribsA", atttributes.get(1).getAttribute("set-name"));
    assertNull("  2. highlight - wrong end", atttributes.get(2));
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testAddRightOverlap() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();

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

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.addHighlight(pos(15), pos(25), attribsB);
    GapList<Position> marks = hs.getMarks();
    GapList<AttributeSet> atttributes = 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());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));

    assertEquals("2. highlight - wrong start offset", 15, marks.get(1).getOffset());
    assertEquals("2. highlight - wrong end offset", 25, marks.get(2).getOffset());
    assertEquals("2. highlight - wrong attribs", "attribsB", atttributes.get(1).getAttribute("set-name"));
    assertNull(  "2. highlight - wrong end", atttributes.get(2));
}
项目:incubator-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;
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testRemoveRightOverlapClip() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();

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

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.removeHighlights(pos(15), pos(25), 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", 10, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 15, 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    文件:PositionsBagTest.java   
public void testRemoveSplitClip() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();

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

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

    assertEquals("Wrong number of highlights", 4, marks.size());
    assertEquals("1. highlight - wrong start offset", 10, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 15, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", atttributes.get(1));

    assertEquals("2. highlight - wrong start offset", 20, marks.get(2).getOffset());
    assertEquals("2. highlight - wrong end offset", 25, marks.get(3).getOffset());
    assertEquals("2. highlight - wrong attribs", "attribsA", atttributes.get(2).getAttribute("set-name"));
    assertNull("  2. highlight - wrong end", atttributes.get(3));
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testRemoveAlignedClip() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();

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

    hs.addHighlight(pos(10), pos(20), attribsA);
    hs.removeHighlights(pos(0), pos(10), 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", 10, 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));

    hs.removeHighlights(pos(20), pos(30), true);
    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());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", atttributes.get(1));
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void testRemoveAligned2Clip() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();

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

    hs.addHighlight(pos(10), pos(40), attribsA);
    hs.removeHighlights(pos(10), pos(20), 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", 20, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 40, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsA", atttributes.get(0).getAttribute("set-name"));
    assertNull("  1. highlight - wrong end", atttributes.get(1));

    hs.removeHighlights(pos(30), pos(40), true);

    assertEquals("Wrong number of highlights", 2, marks.size());
    assertEquals("1. highlight - wrong start offset", 20, marks.get(0).getOffset());
    assertEquals("1. highlight - wrong end offset", 30, 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    文件:PositionsBagTest.java   
public void test122663_AddMultipleLeftMatches() throws BadLocationException {
    doc.insertString(0, "01234567890123456789", null);

    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();
    attribsA.addAttribute("set-name", "attribsA");
    attribsB.addAttribute("set-name", "attribsB");

    PositionsBag bag = new PositionsBag(doc);
    bag.addHighlight(pos(5), pos(10), attribsA);
    bag.addHighlight(pos(15), pos(20), attribsA);
    bag.addHighlight(pos(25), pos(30), attribsA);
    bag.addHighlight(pos(5), pos(35), attribsB);

    assertMarks("Wrong highlights", createPositionsBag(5, 35, attribsB), bag);
}
项目:ripme    文件:MainWindow.java   
private void appendLog(final String text, final Color color) {
    SimpleAttributeSet sas = new SimpleAttributeSet();
    StyleConstants.setForeground(sas, color);
    StyledDocument sd = logText.getStyledDocument();
    try {
        synchronized (this) {
            sd.insertString(sd.getLength(), text + "\n", sas);
        }
    } catch (BadLocationException e) { }

    logText.setCaretPosition(sd.getLength());
}
项目:Wilmersdorf_SER316    文件:HTMLEditor.java   
void setElementProperties(Element el, String id, String cls, String sty) {
    ElementDialog dlg = new ElementDialog(null);
    //dlg.setLocation(linkActionB.getLocationOnScreen());
    Dimension dlgSize = dlg.getPreferredSize();
    Dimension frmSize = this.getSize();
    Point loc = this.getLocationOnScreen();
    dlg.setLocation(
        (frmSize.width - dlgSize.width) / 2 + loc.x,
        (frmSize.height - dlgSize.height) / 2 + loc.y);
    dlg.setModal(true);
    dlg.setTitle(Local.getString("Object properties"));
    dlg.idField.setText(id);
    dlg.classField.setText(cls);
    dlg.styleField.setText(sty);
    // Uncommented, returns a simple p into the header... fix needed ?
    //dlg.header.setText(el.getName());
    dlg.setVisible(true);
    if (dlg.CANCELLED)
        return;
    SimpleAttributeSet attrs = new SimpleAttributeSet(el.getAttributes());
    if (dlg.idField.getText().length() > 0)
        attrs.addAttribute(HTML.Attribute.ID, dlg.idField.getText());
    if (dlg.classField.getText().length() > 0)
        attrs.addAttribute(HTML.Attribute.CLASS, dlg.classField.getText());
    if (dlg.styleField.getText().length() > 0)
        attrs.addAttribute(HTML.Attribute.STYLE, dlg.styleField.getText());
    document.setParagraphAttributes(el.getStartOffset(), 0, attrs, true);
}
项目:incubator-netbeans    文件:AttrSetTesting.java   
public static void merge(Context context, int... indexes) throws Exception {
    @SuppressWarnings("unchecked")
    List<Item> list = (List<Item>) context.getInstance(List.class);
    StringBuilder sb = context.logOpBuilder();
    if (sb != null) {
        sb.append("Merge[");
    }
    MutableAttributeSet mutableAttributeSet = new SimpleAttributeSet();
    AttrSet[] attrSets = new AttrSet[indexes.length];
    for (int i = indexes.length - 1; i >= 0; i--) {
        int index = indexes[i];
        if (sb != null) {
            if (i > 0) {
                sb.append(',');
            }
            sb.append(index);
        }
        Item item = list.get(index);
        attrSets[i] = item.attrSet;
        mutableAttributeSet.addAttributes(item.expected);
    }
    AttrSet mergedAttrSet = AttrSet.merge(attrSets);
    Item mergedItem = new Item(mutableAttributeSet, mergedAttrSet);
    list.add(mergedItem);

    if (sb != null) {
        sb.append("]\n");
        context.logOp(sb);
    }
}
项目:incubator-netbeans    文件:HyperlinkListener.java   
private static AttributeSet getHyperlinkPressedAS () {
    if (hyperlinkPressedAS == null) {
        SimpleAttributeSet as = new SimpleAttributeSet ();
        as.addAttribute (StyleConstants.Foreground, Color.red);
        as.addAttribute (StyleConstants.Underline, Color.red);
        hyperlinkPressedAS = as;
    }
    return hyperlinkPressedAS;
}
项目:incubator-netbeans    文件:PositionsBagTest.java   
public void test122663_AddMultipleBothMatch() throws BadLocationException {
    doc.insertString(0, "01234567890123456789", null);

    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();
    attribsA.addAttribute("set-name", "attribsA");
    attribsB.addAttribute("set-name", "attribsB");

    PositionsBag bag = new PositionsBag(doc);
    bag.addHighlight(pos(10), pos(15), attribsA);
    bag.addHighlight(pos(20), pos(25), attribsA);
    bag.addHighlight(pos(30), pos(35), attribsA);
    bag.addHighlight(pos(10), pos(35), attribsB);
    assertMarks("Wrong highlights", createPositionsBag(10, 35, attribsB), bag);
}
项目:Tarski    文件:OurConsole.java   
/** Helper method that construct a mutable style with the given font name, font size, boldness, color, and left indentation. */
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, Color color, int leftIndent) {
   MutableAttributeSet s = new SimpleAttributeSet();
   StyleConstants.setFontFamily(s, fontName);
   StyleConstants.setFontSize(s, fontSize);
   StyleConstants.setBold(s, boldness);
   StyleConstants.setForeground(s, color);
   StyleConstants.setLeftIndent(s, leftIndent);
   return s;
}
项目:incubator-netbeans    文件:CompoundAttributes.java   
private AttributeSet firstItemAttrs() {
    AttributeSet attrs = highlightItems[0].getAttributes();
    if (attrs == null) {
        attrs = SimpleAttributeSet.EMPTY;
    }
    return attrs;
}
项目: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));
}
项目:incubator-netbeans    文件:SyntaxHighlightingTest.java   
public void testConcurrentModifications() throws BadLocationException {
    Document doc = createDocument(TestTokenId.language(), "NetBeans NetBeans NetBeans");
    SyntaxHighlighting layer = new SyntaxHighlighting(doc);

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

        // Modify the document
        doc.insertString(0, "Hey", SimpleAttributeSet.EMPTY);

        assertFalse("There should be no highlights after co-modification", hs.moveNext());
    }
}
项目:myqq    文件:MyTextPane.java   
/**
 * 获取某种字体
 * @param name 字体名称
 * @param size 字体大小
 * @param color 字体颜色
 * @param bold 是否加粗
 * @param underline 是否加下划线
 * @return 返回获取的字体
 */
public static SimpleAttributeSet getFontAttribute(String name, int size, Color color,
        boolean bold, boolean underline)
{
    SimpleAttributeSet attribute = new SimpleAttributeSet();
    StyleConstants.setFontFamily(attribute, name);
    StyleConstants.setFontSize(attribute, size);
    StyleConstants.setForeground(attribute, color);
    StyleConstants.setBold(attribute, bold);
    StyleConstants.setUnderline(attribute, underline);
    return attribute;
}
项目:OpenJSharp    文件:DocumentParser.java   
/**
 * Handle Start Tag.
 */
protected void handleStartTag(TagElement tag) {

    Element elem = tag.getElement();
    if (elem == dtd.body) {
        inbody++;
    } else if (elem == dtd.html) {
    } else if (elem == dtd.head) {
        inhead++;
    } else if (elem == dtd.title) {
        intitle++;
    } else if (elem == dtd.style) {
        instyle++;
    } else if (elem == dtd.script) {
        inscript++;
    }
    if (debugFlag) {
        if (tag.fictional()) {
            debug("Start Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
        } else {
            debug("Start Tag: " + tag.getHTMLTag() + " attributes: " +
                  getAttributes() + " pos: " + getCurrentPos());
        }
    }
    if (tag.fictional()) {
        SimpleAttributeSet attrs = new SimpleAttributeSet();
        attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
                           Boolean.TRUE);
        callback.handleStartTag(tag.getHTMLTag(), attrs,
                                getBlockStartPosition());
    } else {
        callback.handleStartTag(tag.getHTMLTag(), getAttributes(),
                                getBlockStartPosition());
        flushAttributes();
    }
}
项目:incubator-netbeans    文件:GuardedBlocksHighlighting.java   
public AttributeSet getAttributes() {
    synchronized (GuardedBlocksHighlighting.this) {
        if (!init) {
            throw new NoSuchElementException("Call moveNext() first."); //NOI18N
        } else if (block == null) {
            throw new NoSuchElementException();
        }

        if (attribs == null) {
            FontColorSettings fcs = MimeLookup.getLookup(mimePath).lookup(FontColorSettings.class);
            if (fcs != null) {
                attribs = fcs.getFontColors(FontColorNames.GUARDED_COLORING);
            }

            if (attribs == null) {
                attribs = SimpleAttributeSet.EMPTY;
            } else {
                attribs = AttributesUtilities.createImmutable(
                    attribs, 
                    EXTENDS_EOL_ATTR_SET
                );
            }
        }

        return attribs;
    }
}
项目:myqq    文件:MyTextPane.java   
public void addText(String text,SimpleAttributeSet font)
{
    try
    {
        document.insertString(document.getLength(), text, font);
        StyleConstants.setIcon(getMyAttribute(), MyTools.getIcon("../img/QQ_64.png"));
    }
    catch (BadLocationException e)
    {
        e.printStackTrace();
    }
}
项目:incubator-netbeans    文件:HyperlinkListener.java   
private static AttributeSet getHyperlinkAS () {
    if (hyperlinkAS == null) {
        SimpleAttributeSet as = new SimpleAttributeSet ();
        as.addAttribute (StyleConstants.Foreground, Color.blue);
        as.addAttribute (StyleConstants.Underline, Color.blue);
        hyperlinkAS = as;
    }
    return hyperlinkAS;
}
项目:candlelight    文件:StyleBuilder.java   
public javax.swing.text.AttributeSet getAttributes()
{
    SimpleAttributeSet attribs = new SimpleAttributeSet();
    if (this.parent != null)
    {
        attribs.addAttributes(this.parent.getAttributes());
    }
    attribs.addAttributes(this.attribs);
    return attribs;
}