本文整理汇总了Java中javax.swing.text.SimpleAttributeSet类的典型用法代码示例。如果您正苦于以下问题:Java SimpleAttributeSet类的具体用法?Java SimpleAttributeSet怎么用?Java SimpleAttributeSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleAttributeSet类属于javax.swing.text包,在下文中一共展示了SimpleAttributeSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showPacket
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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);
});
}
示例2: publish
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
@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());
}
示例3: updateData
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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);
}
示例4: testEvents2
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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);
}
示例5: invertCategory
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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;
}
示例6: testEvents
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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);
}
示例7: testEvents2
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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);
}
示例8: checkMemoryConsumption
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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());
}
示例9: getUnusedFieldAttributes
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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;
}
示例10: translateAttributes
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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;
}
示例11: testOrdering
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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));
}
示例12: 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());
}
示例13: testAddRightOverlap
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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());
}
示例14: LogRecordEntry
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
/**
* 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);
}
示例15: testAddRightMatchSmallerOverlap
import javax.swing.text.SimpleAttributeSet; //导入依赖的package包/类
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());
}