javax.swing.text.SimpleAttributeSet Java Examples

The following examples show how to use javax.swing.text.SimpleAttributeSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GuardedBlockSuppressLayer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: DiffColorsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: JHtmlLabel.java    From zxpoly with GNU General Public License v3.0 6 votes vote down vote up
private void cacheLinkElements() {
  this.linkCache = new ArrayList<>();
  final View view = (View) this.getClientProperty("html"); //NOI18N
  if (view != null) {
    final HTMLDocument doc = (HTMLDocument) view.getDocument();
    final HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
    while (it.isValid()) {
      final SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
      final String link = (String) s.getAttribute(HTML.Attribute.HREF);
      if (link != null) {
        this.linkCache.add(new HtmlLinkAddress(link, it.getStartOffset(), it.getEndOffset()));
      }
      it.next();
    }
  }
}
 
Example #4
Source File: ContentReader.java    From SwingBox with GNU Lesser General Public License v3.0 6 votes vote down vote up
private SimpleAttributeSet buildText(TextBox box)
{
    VisualContext vc = box.getVisualContext();
    SimpleAttributeSet attr = new SimpleAttributeSet();

    attr.addAttribute(Constants.ATTRIBUTE_FONT_VARIANT, vc.getFontVariant());
    attr.addAttribute(Constants.ATTRIBUTE_TEXT_DECORATION, vc.getTextDecoration());
    attr.addAttribute(Constants.ATTRIBUTE_FONT, vc.getFont());
    attr.addAttribute(Constants.ATTRIBUTE_FOREGROUND, vc.getColor());

    attr.addAttribute(SwingBoxDocument.ElementNameAttribute, Constants.TEXT_BOX);
    attr.addAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE, new Anchor());
    attr.addAttribute(Constants.ATTRIBUTE_BOX_REFERENCE, box);

    return attr;
}
 
Example #5
Source File: BlockHighlighting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: AnnotationColorsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #7
Source File: PositionsBagTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #8
Source File: JHtmlLabel.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
private void cacheLinkElements() {
  this.linkCache = new ArrayList<>();
  final View view = (View) this.getClientProperty("html"); //NOI18N
  if (view != null) {
    final HTMLDocument doc = (HTMLDocument) view.getDocument();
    final HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
    while (it.isValid()) {
      final SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
      final String link = (String) s.getAttribute(HTML.Attribute.HREF);
      if (link != null) {
        this.linkCache.add(new HtmlLinkAddress(link, it.getStartOffset(), it.getEndOffset()));
      }
      it.next();
    }
  }
}
 
Example #9
Source File: MergePane.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void addHighlight (StyledDocument doc, int line1, int line2, final java.awt.Color color) {
    if (line1 > 0) {
        --line1;
    }
    SimpleAttributeSet attrs = new SimpleAttributeSet();
    StyleConstants.setBackground(attrs, color);
    attrs.addAttribute(HighlightsContainer.ATTR_EXTENDS_EOL, Boolean.TRUE);
    int startOffset = getRowStartFromLineOffset(doc, line1);
    int endOffset = getRowStartFromLineOffset(doc, line2);
    synchronized (highlights) {
        ListIterator<HighLight> it = highlights.listIterator();
        HighLight toAdd = new HighLight(startOffset, endOffset, attrs);
        while (it.hasNext()) {
            HighLight highlight = it.next();
            if (highlight.contains(startOffset)) {
                it.remove();
                break;
            } else if (highlight.precedes(startOffset)) {
                it.previous();
                break;
            }
        }
        it.add(toAdd);
    }
    fireHilitingChanged();
}
 
Example #10
Source File: CompoundHighlightsContainerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #11
Source File: LogRecordEntry.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #12
Source File: PositionsBagMemoryTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #13
Source File: OurConsole.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, boolean italic, boolean strike, Color color, int leftIndent) {


        fontName = AlloyGraphics.matchBestFontName(fontName);

        MutableAttributeSet s = new SimpleAttributeSet();
        StyleConstants.setFontFamily(s, fontName);
        StyleConstants.setFontSize(s, fontSize);
        StyleConstants.setLineSpacing(s, -0.2f);
        StyleConstants.setBold(s, boldness);
        StyleConstants.setItalic(s, italic);
        StyleConstants.setForeground(s, color);
        StyleConstants.setLeftIndent(s, leftIndent);
        StyleConstants.setStrikeThrough(s, strike);
        return s;
    }
 
Example #14
Source File: MergingOffsetsBagTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testAddCompleteMatchOverlap() {
    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(10, 20, attribsB);
    OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();
    
    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", marks.get(0).getAttributes(), "set-A", "set-B");
    assertNull("1. highlight - wrong end", marks.get(1).getAttributes());
}
 
Example #15
Source File: OffsetsBagTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testAddLeftOverlap() {
    OffsetsBag hs = new OffsetsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();
    
    attribsA.addAttribute("set-name", "attribsA");
    attribsB.addAttribute("set-name", "attribsB");
    
    hs.addHighlight(10, 20, attribsA);
    hs.addHighlight(5, 15, attribsB);
    OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();
    
    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", marks.get(0).getAttributes().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", marks.get(1).getAttributes().getAttribute("set-name"));
    assertNull("  2. highlight - wrong end", marks.get(2).getAttributes());
}
 
Example #16
Source File: ProxyHighlightsContainerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testConcurrentModification2() throws Exception {
    PlainDocument doc = new PlainDocument();
    PositionsBag bag = createRandomBag(doc, "layer");
    HighlightsContainer [] layers = new HighlightsContainer [] { bag };

    ProxyHighlightsContainer hb = new ProxyHighlightsContainer(doc, layers);
    HighlightsSequence hs = hb.getHighlights(0, Integer.MAX_VALUE);
    assertTrue("There should be some highlights", hs.moveNext());

    // Modify the bag
    bag.addHighlight(new SimplePosition(20), new SimplePosition(30), SimpleAttributeSet.EMPTY);
    assertFalse("There should be no more highlights after co-modification", hs.moveNext());
}
 
Example #17
Source File: OffsetsBagTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAddAligned2() {
    OffsetsBag hs = new OffsetsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();
    
    attribsA.addAttribute("set-name", "attribsA");
    attribsB.addAttribute("set-name", "attribsB");
    
    hs.addHighlight(10, 40, attribsA);
    hs.addHighlight(10, 20, attribsB);
    hs.addHighlight(30, 40, 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", 20, marks.get(1).getOffset());
    assertEquals("1. highlight - wrong attribs", "attribsB", marks.get(0).getAttributes().getAttribute("set-name"));

    assertEquals("2. highlight - wrong start offset", 20, marks.get(1).getOffset());
    assertEquals("2. highlight - wrong end offset", 30, marks.get(2).getOffset());
    assertEquals("2. highlight - wrong attribs", "attribsA", marks.get(1).getAttributes().getAttribute("set-name"));

    assertEquals("3. highlight - wrong start offset", 30, marks.get(2).getOffset());
    assertEquals("3. highlight - wrong end offset", 40, marks.get(3).getOffset());
    assertEquals("3. highlight - wrong attribs", "attribsB", marks.get(2).getAttributes().getAttribute("set-name"));
    assertNull("  3. highlight - wrong end", marks.get(3).getAttributes());
}
 
Example #18
Source File: HyperlinkListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #19
Source File: MASConsoleColorGUI.java    From jason with GNU Lesser General Public License v3.0 5 votes vote down vote up
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) {
    }
}
 
Example #20
Source File: OffsetsBagTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSet() {
    OffsetsBag hsA = new OffsetsBag(doc);
    OffsetsBag hsB = new OffsetsBag(doc);
    
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    SimpleAttributeSet attribsB = new SimpleAttributeSet();
    SimpleAttributeSet attribsC = new SimpleAttributeSet();

    attribsA.addAttribute("set-name", "attribsA");
    attribsB.addAttribute("set-name", "attribsB");
    attribsC.addAttribute("set-name", "attribsC");
    
    hsA.addHighlight(0, 30, attribsA);
    hsA.addHighlight(10, 20, attribsB);
    OffsetGapList<OffsetsBag.Mark> marksA = hsA.getMarks();
    
    hsB.addHighlight(0, 40, attribsC);
    hsB.setHighlights(hsA.getHighlights(Integer.MIN_VALUE, Integer.MAX_VALUE));
    OffsetGapList<OffsetsBag.Mark> marksB = hsB.getMarks();
    
    assertEquals("Wrong number of highlights", marksA.size(), marksB.size());
    for (int i = 0; i < marksA.size(); i++) {
        assertEquals(i + ". highlight - wrong start offset", 
            marksA.get(i).getOffset(), marksB.get(i).getOffset());
        assertEquals(i + ". highlight - wrong end offset", 
            marksA.get(i).getOffset(), marksB.get(i).getOffset());
        
        AttributeSet attrA = marksA.get(i).getAttributes();
        AttributeSet attrB = marksB.get(i).getAttributes();
        
        if (attrA != null && attrB != null) {
            assertEquals(i + ". highlight - wrong attribs",
                attrA.getAttribute("set-name"), 
                attrB.getAttribute("set-name"));
        } else {
            assertTrue(i + ". highlight - wrong attribs", attrA == null && attrB == null);
        }
    }
}
 
Example #21
Source File: ColoredJTextPane.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public ColoredJTextPane() {
	super();
	setDocument(new DefaultStyledDocument() {

		private static final long serialVersionUID = 1L;

		@Override
		public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
			super.insertString(offs, str, a);

			// now color all texts again
			// do coloring of words but ignore keys unless it is word termination
			String text = getText(0, getLength());
			char[] chars = text.toCharArray();
			StyleContext context = StyleContext.getDefaultStyleContext();
			int lastStart = 0;
			boolean charactersSinceLastStart = false;
			for (int i = 0; i < text.length(); i++) {
				if (!Character.isLetter(chars[i])) {
					if (charactersSinceLastStart) {
						AttributeSet attributeSet = context.addAttribute(SimpleAttributeSet.EMPTY,
								StyleConstants.Foreground, getColor(new String(chars, lastStart, i - lastStart)));
						setCharacterAttributes(lastStart, i - lastStart, attributeSet, true);
					}
					lastStart = i + 1;
					charactersSinceLastStart = false;
				} else {
					charactersSinceLastStart = true;
				}
			}
		}
	});

}
 
Example #22
Source File: ColorsManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static SimpleAttributeSet createColoring(
        String colorName,
        String displayName,
        String defaultColor,
        String foreground,
        String background,
        String underline,
        String waveunderline,
        String strikethrough,
        String fontName,
        String fontType
        ) {
    SimpleAttributeSet coloring = new SimpleAttributeSet();
    coloring.addAttribute(StyleConstants.NameAttribute, colorName);
    coloring.addAttribute(EditorStyleConstants.DisplayName, displayName);
    if (defaultColor != null)
        coloring.addAttribute(EditorStyleConstants.Default, defaultColor);
    if (foreground != null)
        coloring.addAttribute(StyleConstants.Foreground, readColor(foreground));
    if (background != null)
        coloring.addAttribute(StyleConstants.Background, readColor(background));
    if (strikethrough != null)
        coloring.addAttribute(StyleConstants.StrikeThrough, readColor(strikethrough));
    if (underline != null)
        coloring.addAttribute(StyleConstants.Underline, readColor(underline));
    if (waveunderline != null)
        coloring.addAttribute(EditorStyleConstants.WaveUnderlineColor, readColor(waveunderline));
    if (fontName != null)
        coloring.addAttribute(StyleConstants.FontFamily, fontName);
    if (fontType != null) {
        if (fontType.toLowerCase().indexOf("bold") >= 0)
            coloring.addAttribute(StyleConstants.Bold, Boolean.TRUE);
        if (fontType.toLowerCase().indexOf("italic") >= 0)
            coloring.addAttribute(StyleConstants.Italic, Boolean.TRUE);
    }
    return coloring;
}
 
Example #23
Source File: CompoundAttributes.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private AttributeSet firstItemAttrs() {
    AttributeSet attrs = highlightItems[0].getAttributes();
    if (attrs == null) {
        attrs = SimpleAttributeSet.EMPTY;
    }
    return attrs;
}
 
Example #24
Source File: PositionsBagTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testRemoveMiddle() {
    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(20), pos(30), attribsB);
    hs.removeHighlights(15, 25);
    GapList<Position> marks = hs.getMarks();
    
    assertEquals("Wrong number of highlights", 0, marks.size());
}
 
Example #25
Source File: ContentReader.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finishElementContents(ElementBox elem)
{
    if (!elem.isReplaced())
    {
        /*if (lastStarted == elem)
        {
            //rendering an empty element -- we must insert an empty string in order to preserve the element
            SimpleAttributeSet content = buildEmptyContent();
            elements.add(new ElementSpec(content, ElementSpec.ContentType, "".toCharArray(), 0, 0));
        }*/
        SimpleAttributeSet attr = buildElement(elem);
        elements.add(new ElementSpec(attr, ElementSpec.EndTagType, "}".toCharArray(), 1, 0));
    }
}
 
Example #26
Source File: ButtonsHTMLParser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    String tag = t.toString();
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "SimpleTag <{0}> with attributes: {1}",
                   new Object[]{tag, Collections.list(a.getAttributeNames()).toString()});
    }
    if (readingForm) {
        if (TAG_INPUT.equalsIgnoreCase(tag)) {
            inputs.add(new SimpleAttributeSet(a));
        }
    }
}
 
Example #27
Source File: PositionsBagTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testRemoveSplit() {
    PositionsBag hs = new PositionsBag(doc);
    SimpleAttributeSet attribsA = new SimpleAttributeSet();
    
    attribsA.addAttribute("set-name", "attribsA");
    
    hs.addHighlight(pos(10), pos(25), attribsA);
    hs.removeHighlights(15, 20);
    GapList<Position> marks = hs.getMarks();
    
    assertEquals("Wrong number of highlights", 0, marks.size());
}
 
Example #28
Source File: ContentReader.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
private final SimpleAttributeSet commonBuild(ElementBox box, Object elementNameValue)
{
    // when there are no special requirements to build an element, use this
    // one
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(SwingBoxDocument.ElementNameAttribute, elementNameValue);
    attr.addAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE, new Anchor());
    attr.addAttribute(Constants.ATTRIBUTE_BOX_REFERENCE, box);
    attr.addAttribute(Constants.ATTRIBUTE_ELEMENT_ID, box.getElement().getAttribute("id"));

    return attr;
}
 
Example #29
Source File: ScriptPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
private void appendResult(String msg, Color c)
  {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
resultPane.setCharacterAttributes(aset, false);
      int len = resultPane.getDocument().getLength();
      resultPane.setCaretPosition(len);
      resultPane.replaceSelection(msg);
      resultPane.setCaretPosition(resultPane.getDocument().getLength());
  }
 
Example #30
Source File: MasterMatcherTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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());
    }        
}