當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleAttributeSet類代碼示例

本文整理匯總了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);
	});
}
 
開發者ID:leolewis,項目名稱:openvisualtraceroute,代碼行數:26,代碼來源:PacketDetailPanel.java

示例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());
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:27,代碼來源:ConsoleLogHandler.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:DiffColorsPanel.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:ProxyHighlightsContainerTest.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:SyntaxColoringPanel.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:CompoundHighlightsContainerTest.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:CompoundHighlightsContainerTest.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:PositionsBagMemoryTest.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:ColorsManager.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:ComposedTextHighlighting.java

示例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));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:MergingPositionsBagTest.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:OffsetsBagTest.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:MergingOffsetsBagTest.java

示例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);
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:29,代碼來源:LogRecordEntry.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:MergingOffsetsBagTest.java


注:本文中的javax.swing.text.SimpleAttributeSet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。