本文整理汇总了Java中javax.swing.text.SimpleAttributeSet.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleAttributeSet.addAttribute方法的具体用法?Java SimpleAttributeSet.addAttribute怎么用?Java SimpleAttributeSet.addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.SimpleAttributeSet
的用法示例。
在下文中一共展示了SimpleAttributeSet.addAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRemoveSplitClip
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
public void testRemoveSplitClip() {
OffsetsBag hs = new OffsetsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
attribsA.addAttribute("set-name", "attribsA");
hs.addHighlight(10, 25, attribsA);
hs.removeHighlights(15, 20, true);
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());
assertEquals("1. highlight - wrong attribs", "attribsA", marks.get(0).getAttributes().getAttribute("set-name"));
assertNull(" 1. highlight - wrong end", marks.get(1).getAttributes());
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", marks.get(2).getAttributes().getAttribute("set-name"));
assertNull(" 2. highlight - wrong end", marks.get(3).getAttributes());
}
示例2: testOrdering
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
public void testOrdering() {
PlainDocument doc = new PlainDocument();
PositionsBag hsA = new PositionsBag(doc);
PositionsBag hsB = new PositionsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
SimpleAttributeSet attribsB = new SimpleAttributeSet();
attribsA.addAttribute("attribute", "value-A");
attribsB.addAttribute("attribute", "value-B");
hsA.addHighlight(new SimplePosition(5), new SimplePosition(15), attribsA);
hsB.addHighlight(new SimplePosition(10), new SimplePosition(20), attribsB);
CompoundHighlightsContainer chc = new CompoundHighlightsContainer(doc, new HighlightsContainer [] { hsA, hsB });
HighlightsSequence highlights = chc.getHighlights(0, Integer.MAX_VALUE);
assertTrue("Wrong number of highlights", highlights.moveNext());
assertEquals("1. highlight - wrong attribs", "value-A", highlights.getAttributes().getAttribute("attribute"));
assertTrue("Wrong number of highlights", highlights.moveNext());
assertEquals("2. highlight - wrong attribs", "value-B", highlights.getAttributes().getAttribute("attribute"));
assertTrue("Wrong number of highlights", highlights.moveNext());
assertEquals("3. highlight - wrong attribs", "value-B", highlights.getAttributes().getAttribute("attribute"));
}
示例3: testAddLeftOverlap
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
public void testAddLeftOverlap() {
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(5, 15, 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-B");
assertEquals("2. highlight - wrong start offset", 10, marks.get(1).getOffset());
assertEquals("2. highlight - wrong end offset", 15, marks.get(2).getOffset());
assertAttribs("2. highlight - wrong attribs", marks.get(1).getAttributes(), "set-A", "set-B");
assertEquals("3. highlight - wrong start offset", 15, marks.get(2).getOffset());
assertEquals("3. highlight - wrong end offset", 20, marks.get(3).getOffset());
assertAttribs("3. highlight - wrong attribs", marks.get(2).getAttributes(), "set-A");
assertNull("3. highlight - wrong end", marks.get(3).getAttributes());
}
示例4: testAddLeftOverlap
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
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));
}
示例5: testRemoveAligned2Clip
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
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());
}
示例6: testRemoveLeftOverlapClip
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
public void testRemoveLeftOverlapClip() {
OffsetsBag hs = new OffsetsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
attribsA.addAttribute("set-name", "attribsA");
hs.addHighlight(10, 20, attribsA);
hs.removeHighlights(5, 15, true);
OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();
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", marks.get(0).getAttributes().getAttribute("set-name"));
assertNull(" 1. highlight - wrong end", marks.get(1).getAttributes());
}
示例7: testAddCompleteMatchOverlap
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
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());
}
示例8: getHyperlinkAS
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
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;
}
示例9: setColor
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
public void setColor(int index, Color color) {
if (color == null) return;
AttributeSet attr = colorAttributes.get(index);
SimpleAttributeSet c = new SimpleAttributeSet(attr);
if (attr != null) {
c.addAttribute(StyleConstants.Background, color);
} else {
c.removeAttribute(StyleConstants.Background);
}
colorAttributes.set(index, c);
Color[] savedColor = colors.get((String)c.getAttribute(StyleConstants.NameAttribute));
savedColor[0] = color;
fireChanged();
}
示例10: createRandomBag
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
private PositionsBag createRandomBag(Document doc, String bagId) {
PositionsBag bag = new PositionsBag(doc, false);
Random rand = new Random(System.currentTimeMillis());
int attrIdx = 0;
int startOffset = 0;
int endOffset = 100;
int maxGapSize = Math.max((int) (endOffset - startOffset) / 10, 1);
int maxHighlightSize = Math.max((int) (endOffset - startOffset) / 2, 1);
for (int pointer = startOffset + rand.nextInt(maxGapSize); pointer <= endOffset; ) {
int highlightSize = rand.nextInt(maxHighlightSize);
SimpleAttributeSet attributes = new SimpleAttributeSet();
attributes.addAttribute("AttrName-" + bagId + "-" + attrIdx, "AttrValue");
attrIdx++;
if (pointer + highlightSize < endOffset) {
bag.addHighlight(
new SimplePosition(pointer), new SimplePosition(pointer + highlightSize), attributes);
} else {
bag.addHighlight(
new SimplePosition(pointer), new SimplePosition(endOffset), attributes);
}
// move the pointer
pointer += highlightSize + rand.nextInt(maxGapSize);
}
return bag;
}
示例11: test122663_AddLeftMatches
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
public void test122663_AddLeftMatches() 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");
OffsetsBag bag = new OffsetsBag(doc);
bag.addHighlight(5, 10, attribsA);
bag.addHighlight(5, 15, attribsB);
assertMarks("Wrong highlights", createOffsetsBag(5, 15, attribsB), bag);
}
示例12: testAddRightOverlap
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
public void testAddRightOverlap() {
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(25), attribsB);
GapList<Position> marks = hs.getMarks();
GapList<AttributeSet> attributes = 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());
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");
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", attributes.get(2), "set-B");
assertNull("3. highlight - wrong end", attributes.get(3));
}
示例13: testRemoveMiddle
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
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());
}
示例14: removeMiddleClip
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
private void removeMiddleClip(int middleMarks) {
PositionsBag hs = new PositionsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
SimpleAttributeSet attribsB = new SimpleAttributeSet();
attribsA.addAttribute("set-name", "attribsA");
attribsB.addAttribute("set-name", "attribsB");
for (int i = 0; i < middleMarks + 1; i++) {
hs.addHighlight(pos(10 * i + 10), pos(10 * i + 20), i % 2 == 0 ? attribsA : attribsB);
}
hs.removeHighlights(pos(15), pos(middleMarks * 10 + 15), true);
GapList<Position> marks = hs.getMarks();
GapList<AttributeSet> atttributes = hs.getAttributes();
assertEquals("Wrong number of highlights (middleMarks = " + middleMarks + ")",
4, marks.size());
assertEquals("1. highlight - wrong start offset (middleMarks = " + middleMarks + ")",
10, marks.get(0).getOffset());
assertEquals("1. highlight - wrong end offset (middleMarks = " + middleMarks + ")",
15, marks.get(1).getOffset());
assertEquals("1. highlight - wrong attribs (middleMarks = " + middleMarks + ")",
"attribsA", atttributes.get(0).getAttribute("set-name"));
assertNull(" 1. highlight - wrong end (middleMarks = " + middleMarks + ")",
atttributes.get(1));
assertEquals("2. highlight - wrong start offset (middleMarks = " + middleMarks + ")",
middleMarks * 10 + 15, marks.get(2).getOffset());
assertEquals("2. highlight - wrong end offset (middleMarks = " + middleMarks + ")",
(middleMarks + 2) * 10, marks.get(3).getOffset());
assertEquals("2. highlight - wrong attribs (middleMarks = " + middleMarks + ")",
middleMarks % 2 == 0 ? "attribsA" : "attribsB", atttributes.get(2).getAttribute("set-name"));
assertNull(" 2. highlight - wrong end (middleMarks = " + middleMarks + ")",
atttributes.get(3));
}
示例15: testRemoveLeftOverlap
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
public void testRemoveLeftOverlap() {
OffsetsBag hs = new OffsetsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
attribsA.addAttribute("set-name", "attribsA");
hs.addHighlight(10, 20, attribsA);
hs.removeHighlights(5, 15, false);
OffsetGapList<OffsetsBag.Mark> marks = hs.getMarks();
assertEquals("Wrong number of highlights", 0, marks.size());
}