本文整理匯總了Java中javax.swing.text.AttributeSet類的典型用法代碼示例。如果您正苦於以下問題:Java AttributeSet類的具體用法?Java AttributeSet怎麽用?Java AttributeSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AttributeSet類屬於javax.swing.text包,在下文中一共展示了AttributeSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertToHTML40
import javax.swing.text.AttributeSet; //導入依賴的package包/類
/**
* Copies the given AttributeSet to a new set, converting
* any CSS attributes found to arguments of an HTML style
* attribute.
*/
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
Enumeration keys = from.getAttributeNames();
String value = "";
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof CSS.Attribute) {
value = value + " " + key + "=" + from.getAttribute(key) + ";";
}
else {
to.addAttribute(key, from.getAttribute(key));
}
}
if (value.length() > 0) {
to.addAttribute(HTML.Attribute.STYLE, value);
}
}
示例2: EmbeddedSectionsHighlighting
import javax.swing.text.AttributeSet; //導入依賴的package包/類
EmbeddedSectionsHighlighting(Document document) {
this.document = document;
// load the background color for the embedding token
AttributeSet attribs = null;
String mimeType = (String) document.getProperty("mimeType"); //NOI18N
FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
if (fcs != null) {
Color jsBC = getColoring(fcs, YamlTokenId.RUBY.primaryCategory());
if (jsBC != null) {
attribs = AttributesUtilities.createImmutable(
StyleConstants.Background, jsBC,
ATTR_EXTENDS_EOL, Boolean.TRUE);
}
}
rubyBackground = attribs;
}
示例3: testAddRightMatchSmallerOverlap
import javax.swing.text.AttributeSet; //導入依賴的package包/類
public void testAddRightMatchSmallerOverlap() {
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(20), attribsB);
GapList<Position> marks = hs.getMarks();
GapList<AttributeSet> attributes = 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());
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");
assertNull("2. highlight - wrong end", attributes.get(2));
}
示例4: testConcurrentModification
import javax.swing.text.AttributeSet; //導入依賴的package包/類
public void testConcurrentModification() throws Exception {
PlainDocument doc = new PlainDocument();
PositionsBag bag = createRandomBag(doc, "layer");
HighlightsContainer [] layers = new HighlightsContainer [] { bag };
CompoundHighlightsContainer hb = new CompoundHighlightsContainer(doc, layers);
HighlightsSequence hs = hb.getHighlights(0, Integer.MAX_VALUE);
assertTrue("No highlights", hs.moveNext());
int s = hs.getStartOffset();
int e = hs.getEndOffset();
AttributeSet a = hs.getAttributes();
// Change the layers
hb.setLayers(doc, layers);
assertEquals("Different startOffset", s, hs.getStartOffset());
assertEquals("Different endOffset", e, hs.getEndOffset());
assertEquals("Different attributes", a, hs.getAttributes());
assertFalse("There should be no further highlighs after co-modification", hs.moveNext());
}
示例5: getCurrentColors
import javax.swing.text.AttributeSet; //導入依賴的package包/類
private static Map getCurrentColors(Language l) {
// current colors
FontColorSettingsFactory fcsf = EditorSettings.getDefault().
getFontColorSettings(new String[] {l.getMimeType()});
Collection<AttributeSet> colors = fcsf.getAllFontColors("NetBeans");
Map<String,AttributeSet> colorsMap = new HashMap<String,AttributeSet> ();
Iterator<AttributeSet> it = colors.iterator();
while (it.hasNext()) {
AttributeSet as = it.next();
colorsMap.put(
(String) as.getAttribute(StyleConstants.NameAttribute),
as
);
}
return colorsMap;
}
示例6: replace
import javax.swing.text.AttributeSet; //導入依賴的package包/類
@Override
public void replace(FilterBypass fb, int offset, int length, String text,
AttributeSet attrs) throws BadLocationException {
Document doc = fb.getDocument();
StringBuilder sb = new StringBuilder();
sb.append(doc.getText(0, doc.getLength()));
sb.replace(offset, offset + length, text);
if (test(sb.toString())) {
super.replace(fb, offset, length, text, attrs);
} else {
JOptionPane.showMessageDialog(null, "STOP ! You're only allowed to encode numbers !", "Warning", JOptionPane.ERROR_MESSAGE);
}
}
示例7: testRemoveLeftOverlapClip
import javax.swing.text.AttributeSet; //導入依賴的package包/類
public void testRemoveLeftOverlapClip() {
PositionsBag hs = new PositionsBag(doc);
SimpleAttributeSet attribsA = new SimpleAttributeSet();
attribsA.addAttribute("set-name", "attribsA");
hs.addHighlight(pos(10), pos(20), attribsA);
hs.removeHighlights(pos(5), pos(15), 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", 15, 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));
}
示例8: VersioningSystemColors
import javax.swing.text.AttributeSet; //導入依賴的package包/類
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);
}
}
示例9: getAttribute
import javax.swing.text.AttributeSet; //導入依賴的package包/類
@Override public String getAttribute(final String name) {
if ("text".equals(name)) {
return getText();
}
if ("hRefIndex".equals(name)) {
return getHRefIndex() + "";
}
if ("textIndex".equals(name)) {
return getTextIndex() + "";
}
return EventQueueWait.exec(new Callable<String>() {
@Override public String call() throws Exception {
Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument());
AttributeSet attributes = iterator.getAttributes();
Attribute attr = findAttribute(name);
if (attr != null && attributes.isDefined(attr)) {
return attributes.getAttribute(attr).toString();
}
return null;
}
});
}
示例10: applyChanges
import javax.swing.text.AttributeSet; //導入依賴的package包/類
@Override
public void applyChanges() {
if (colorModel == null) return;
for(String profile : toBeSaved.keySet()) {
Set<String> toBeSavedLanguages = toBeSaved.get(profile);
Map<String, List<AttributeSet>> schemeMap = profiles.get(profile);
for(String languageName : toBeSavedLanguages) {
colorModel.setCategories(
profile,
languageName,
schemeMap.get(languageName)
);
}
}
toBeSaved = new HashMap<String, Set<String>>();
profiles = new HashMap<String, Map<String, List<AttributeSet>>>();
changed = false;
}
示例11: findAttribs
import javax.swing.text.AttributeSet; //導入依賴的package包/類
private AttributeSet findAttribs(TokenItem tokenItem) {
synchronized (this) {
AttributeSet attribs = attribsCache.get(tokenItem.getTokenID());
if (attribs == null) {
FontColorSettings fcs = MimeLookup.getLookup(mimePath).lookup(FontColorSettings.class);
if (fcs != null) {
attribs = findFontAndColors(fcs, tokenItem);
if (attribs == null) {
attribs = SimpleAttributeSet.EMPTY;
}
attribsCache.put(tokenItem.getTokenID(), attribs);
} else {
LOG.warning("Can't find FCS for mime path: '" + mimePath.getPath() + "'"); //NOI18N
}
}
return attribs == null ? SimpleAttributeSet.EMPTY : attribs;
}
}
示例12: getListCellRendererComponent
import javax.swing.text.AttributeSet; //導入依賴的package包/類
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
setComponentOrientation(list.getComponentOrientation());
if (isSelected) {
setBackground(list.getSelectionBackground ());
setForeground(list.getSelectionForeground ());
} else {
setBackground(list.getBackground ());
setForeground(list.getForeground ());
}
setIcon((Icon) ((AttributeSet) value).getAttribute ("icon"));
setText((String) ((AttributeSet) value).getAttribute (EditorStyleConstants.DisplayName));
setEnabled(list.isEnabled());
setFont(list.getFont());
setBorder(cellHasFocus ? UIManager.getBorder ("List.focusCellHighlightBorder") : noFocusBorder);
return this;
}
示例13: CircleRegionContainment
import javax.swing.text.AttributeSet; //導入依賴的package包/類
public CircleRegionContainment(AttributeSet as) {
int[] coords = extractCoords(as.getAttribute(HTML.Attribute.COORDS));
if (coords == null || coords.length != 3) {
throw new RuntimeException("Unable to parse circular area");
}
x = coords[0];
y = coords[1];
radiusSquared = coords[2] * coords[2];
if (coords[0] < 0 || coords[1] < 0 || coords[2] < 0) {
lastWidth = lastHeight = -1;
percentValues = new float[3];
for (int counter = 0; counter < 3; counter++) {
if (coords[counter] < 0) {
percentValues[counter] = coords[counter] / -100.0f;
}
else {
percentValues[counter] = -1.0f;
}
}
}
else {
percentValues = null;
}
}
示例14: testConcurrentModification
import javax.swing.text.AttributeSet; //導入依賴的package包/類
public void testConcurrentModification() {
PositionsBag hb = new PositionsBag(doc);
// Modify the bag
hb.addHighlight(pos(5), pos(10), EMPTY);
hb.addHighlight(pos(15), pos(20), EMPTY);
hb.addHighlight(pos(25), pos(30), EMPTY);
HighlightsSequence hs = hb.getHighlights(Integer.MIN_VALUE, Integer.MAX_VALUE);
assertTrue("There should be some highlights", hs.moveNext());
int s = hs.getStartOffset();
int e = hs.getEndOffset();
AttributeSet a = hs.getAttributes();
// Modification after the sequence was acquired
hb.addHighlight(pos(100), pos(110), EMPTY);
assertEquals("Wrong highlight start", s, hs.getStartOffset());
assertEquals("Wrong highlight end", e, hs.getEndOffset());
assertEquals("Wrong highlight attributes", a, hs.getAttributes());
assertFalse("There should be no more highlights after co-modification", hs.moveNext());
}
示例15: testAddCompleteMatchOverlap
import javax.swing.text.AttributeSet; //導入依賴的package包/類
public void testAddCompleteMatchOverlap() {
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(10), pos(20), attribsB);
GapList<Position> marks = hs.getMarks();
GapList<AttributeSet> attributes = 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());
assertAttribs("1. highlight - wrong attribs", attributes.get(0), "set-A", "set-B");
assertNull("1. highlight - wrong end", attributes.get(1));
}