下面列出了javax.swing.text.AttributeSet#isDefined ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Object getAttribute(Object key) {
if (key instanceof String && key.equals(ATTR_DISMANTLED_STRUCTURE)) {
return dismantle(this);
}
for(AttributeSet delegate : delegates) {
AttributeSet current = delegate;
while (current != null) {
if (current.isDefined(key)) {
return current.getAttribute(key);
}
current = current.getResolveParent();
}
}
return null;
}
public Object getAttribute(Object key) {
if (key instanceof String && key.equals(ATTR_DISMANTLED_STRUCTURE)) {
return dismantle(this);
}
for(AttributeSet delegate : new AttributeSet[] {delegate0, delegate1}) {
AttributeSet current = delegate;
while (current != null) {
if (current.isDefined(key)) {
return current.getAttribute(key);
}
current = current.getResolveParent();
}
}
return null;
}
@Override
public Object getAttribute(Object key) {
if (key instanceof String && key.equals(ATTR_DISMANTLED_STRUCTURE)) {
return dismantle(this);
}
AttributeSet[] set;
if (delegate3 == null) {
set = new AttributeSet[] {delegate0, delegate1, delegate2};
} else {
set = new AttributeSet[] {delegate0, delegate1, delegate2, delegate3};
}
for(AttributeSet delegate : set) {
AttributeSet current = delegate;
while (current != null) {
if (current.isDefined(key)) {
return current.getAttribute(key);
}
current = current.getResolveParent();
}
}
return null;
}
/**
* Convenient method for getting an integer attribute from the elements
* AttributeSet.
*/
private int getIntAttr(HTML.Attribute name, int deflt) {
AttributeSet attr = getElement().getAttributes();
if (attr.isDefined(name)) { // does not check parents!
int i;
String val = (String)attr.getAttribute(name);
if (val == null) {
i = deflt;
}
else {
try{
i = Math.max(0, Integer.parseInt(val));
}catch( NumberFormatException x ) {
i = deflt;
}
}
return i;
} else
return deflt;
}
/**
* Convenience method for getting an integer attribute from the elements
* AttributeSet.
*/
private int getIntAttr(HTML.Attribute name, int deflt) {
AttributeSet attr = getElement().getAttributes();
if (attr.isDefined(name)) { // does not check parents!
int i;
String val = (String)attr.getAttribute(name);
if (val == null) {
i = deflt;
}
else {
try{
i = Math.max(0, Integer.parseInt(val));
}catch( NumberFormatException x ) {
i = deflt;
}
}
return i;
} else
return deflt;
}
protected JPanelActiveBox createNewBox(int pos, Options options, Component parent) {
JPanelActiveBox result = null;
TextActivityBase tab = getTextActivity();
AttributeSet a = tab.tad.getCharacterElement(pos).getAttributes();
if (a.isDefined(TextActivityDocument.TARGET)) {
options.getMessages().showAlert(parent, "edit_text_act_err_cellInTarget");
return null;
}
ActiveBoxContent ab = new ActiveBoxContent();
ab.setDimension(new Dimension(100, 40));
ab.setBoxBase(tab.tad.boxesContent.bb);
ab = ActiveBoxContentEditor.getActiveBoxContent(ab, parent, options, getMediaBagEditor(), null);
if (ab != null) {
try {
result = TextActivityDocument.insertBox(ab, pos, tab.tad, tab, null);
} catch (Exception ex) {
options.getMessages().showErrorWarning(parent, "ERROR", ex);
}
}
return result;
}
public boolean isDefined(Object key) {
for(AttributeSet delegate : delegates) {
if (delegate.isDefined(key)) {
return true;
}
}
return false;
}
/** Get element name if defined */
public String getName() {
AttributeSet as = attrs;
if (as != null && as.isDefined(ElementNameAttribute)) {
return (String)as.getAttribute(ElementNameAttribute);
} else {
return null;
}
}
private void assertAttribNotContains(String msg, AttributeSet as, String... keys) {
// System.out.print("assertAttribNotContains: attributes: ");
// for(Enumeration<?> attribKeys = as.getAttributeNames(); attribKeys.hasMoreElements(); ) {
// Object key = attribKeys.nextElement();
// Object value = as.getAttribute(key);
// System.out.print("'" + key + "' = '" + value + "', ");
// }
// System.out.println();
for (String key : keys) {
if (null != as.getAttribute(key) || as.isDefined(key)) {
fail(msg + " attribute key: " + key);
}
}
}
static void saveColorings (FileObject fo, Collection colorings) {
final StringBuffer sb = XMLStorage.generateHeader ();
XMLStorage.generateFolderStart (sb, "fontscolors", null, "");
Iterator it = colorings.iterator ();
while (it.hasNext ()) {
AttributeSet category = (AttributeSet) it.next ();
Attribs attributes = new Attribs (true);
attributes.add (
"name",
(String) category.getAttribute (StyleConstants.NameAttribute)
);
if (category.isDefined (StyleConstants.Foreground))
attributes.add (
"foreColor",
XMLStorage.colorToString (
(Color) category.getAttribute (StyleConstants.Foreground)
)
);
if (category.isDefined (StyleConstants.Background))
attributes.add (
"bgColor",
XMLStorage.colorToString (
(Color) category.getAttribute (StyleConstants.Background)
)
);
if (category.isDefined (StyleConstants.StrikeThrough))
attributes.add (
"strikeThrough",
XMLStorage.colorToString (
(Color) category.getAttribute (StyleConstants.StrikeThrough)
)
);
if (category.isDefined ("waveUnderlined"))
attributes.add (
"waveUnderlined",
XMLStorage.colorToString (
(Color) category.getAttribute ("waveUnderlined")
)
);
if (category.isDefined (StyleConstants.Underline))
attributes.add (
"underline",
XMLStorage.colorToString (
(Color) category.getAttribute (StyleConstants.Underline)
)
);
if (category.isDefined ("default"))
attributes.add (
"default",
(String) category.getAttribute ("default")
);
if ( category.isDefined (StyleConstants.FontFamily) ||
category.isDefined (StyleConstants.FontSize) ||
category.isDefined (StyleConstants.Bold) ||
category.isDefined (StyleConstants.Italic)
) {
XMLStorage.generateFolderStart (sb, "fontcolor", attributes, " ");
attributes = new Attribs (true);
if (category.isDefined (StyleConstants.FontFamily))
attributes.add (
"name",
(String) category.getAttribute (StyleConstants.FontFamily)
);
if (category.isDefined (StyleConstants.FontSize))
attributes.add (
"size",
"" + category.getAttribute (StyleConstants.FontSize)
);
if (category.isDefined (StyleConstants.Bold) ||
category.isDefined (StyleConstants.Italic)
) {
Boolean bold = Boolean.FALSE, italic = Boolean.FALSE;
if (category.isDefined (StyleConstants.Bold))
bold = (Boolean) category.getAttribute (StyleConstants.Bold);
if (category.isDefined (StyleConstants.Italic))
italic = (Boolean) category.getAttribute (StyleConstants.Italic);
attributes.add ("style",
bold.booleanValue () ?
(italic.booleanValue () ?
"bold+italic" :
"bold") :
(italic.booleanValue () ?
"italic" : "plain")
);
}
XMLStorage.generateLeaf (sb, "font", attributes, " ");
XMLStorage.generateFolderEnd (sb, "fontcolor", " ");
} else
XMLStorage.generateLeaf (sb, "fontcolor", attributes, " ");
}
XMLStorage.generateFolderEnd (sb, "fontscolors", "");
XMLStorage.save (fo, new String (sb));
}
@Override
public Document getDocument() {
Document doc = XMLUtil.createDocument(E_ROOT, null, PUBLIC_ID, SYSTEM_ID);
Node root = doc.getElementsByTagName(E_ROOT).item(0);
for(AttributeSet category : getAdded().values()) {
Element fontColor = doc.createElement(E_FONTCOLOR);
root.appendChild(fontColor);
fontColor.setAttribute(A_NAME, (String) category.getAttribute(StyleConstants.NameAttribute));
if (category.isDefined(StyleConstants.Foreground)) {
fontColor.setAttribute(
A_FOREGROUND,
colorToString((Color) category.getAttribute(StyleConstants.Foreground))
);
}
if (category.isDefined(StyleConstants.Background)) {
fontColor.setAttribute(
A_BACKGROUND,
colorToString((Color) category.getAttribute(StyleConstants.Background))
);
}
if (category.isDefined(StyleConstants.StrikeThrough)) {
fontColor.setAttribute(
A_STRIKETHROUGH,
colorToString((Color) category.getAttribute(StyleConstants.StrikeThrough))
);
}
if (category.isDefined(EditorStyleConstants.WaveUnderlineColor)) {
fontColor.setAttribute(
A_WAVEUNDERLINE,
colorToString((Color) category.getAttribute(EditorStyleConstants.WaveUnderlineColor))
);
}
if (category.isDefined(StyleConstants.Underline)) {
fontColor.setAttribute(
A_UNDERLINE,
colorToString((Color) category.getAttribute(StyleConstants.Underline))
);
}
if (category.isDefined(EditorStyleConstants.Default)) {
fontColor.setAttribute(
A_DEFAULT,
(String) category.getAttribute(EditorStyleConstants.Default)
);
}
if ( category.isDefined(StyleConstants.FontFamily) ||
category.isDefined(StyleConstants.FontSize) ||
category.isDefined(StyleConstants.Bold) ||
category.isDefined(StyleConstants.Italic)
) {
Element font = doc.createElement(E_FONT);
fontColor.appendChild(font);
if (category.isDefined(StyleConstants.FontFamily)) {
font.setAttribute(
A_NAME,
(String) category.getAttribute(StyleConstants.FontFamily)
);
}
if (category.isDefined(StyleConstants.FontSize)) {
font.setAttribute(
A_SIZE,
((Integer) category.getAttribute(StyleConstants.FontSize)).toString()
);
}
if (category.isDefined(StyleConstants.Bold) ||
category.isDefined(StyleConstants.Italic)
) {
Boolean bold = Boolean.FALSE, italic = Boolean.FALSE;
if (category.isDefined(StyleConstants.Bold)) {
bold = (Boolean) category.getAttribute(StyleConstants.Bold);
}
if (category.isDefined(StyleConstants.Italic)) {
italic = (Boolean) category.getAttribute(StyleConstants.Italic);
}
font.setAttribute(A_STYLE, bold ?
(italic ? V_BOLD_ITALIC : V_BOLD) :
(italic ? V_ITALIC : V_PLAIN)
);
}
}
}
return doc;
}
private Object getValue (String language, AttributeSet category, Object key) {
if (category.isDefined (key))
return category.getAttribute (key);
return getDefault (language, category, key);
}
public void setAnnotations (
String profile,
Collection<AttributeSet> annotations
) {
if (annotations == null) {
EditorSettings.getDefault().setAnnotations(profile, null);
return;
}
Collection<AttributeSet> annos = new ArrayList<AttributeSet>();
for(AttributeSet category : annotations) {
AnnotationType annotationType = (AnnotationType)
category.getAttribute ("annotationType");
SimpleAttributeSet c = new SimpleAttributeSet();
c.addAttribute(StyleConstants.NameAttribute, category.getAttribute(StyleConstants.NameAttribute));
if (category.isDefined (StyleConstants.Background)) {
annotationType.setUseHighlightColor (true);
if (annotationType.getHighlight() == null || !annotationType.getHighlight().equals((Color) category.getAttribute (StyleConstants.Background))) {
annotationType.setHighlight (
(Color) category.getAttribute (StyleConstants.Background)
);
}
c.addAttribute(StyleConstants.Background, category.getAttribute(StyleConstants.Background));
} else
annotationType.setUseHighlightColor (false);
if (category.isDefined (StyleConstants.Foreground)) {
annotationType.setInheritForegroundColor (false);
if (annotationType.getForegroundColor() == null || !annotationType.getForegroundColor().equals( (Color) category.getAttribute (StyleConstants.Foreground))) {
annotationType.setForegroundColor (
(Color) category.getAttribute (StyleConstants.Foreground)
);
}
c.addAttribute(StyleConstants.Foreground, category.getAttribute(StyleConstants.Foreground));
} else
annotationType.setInheritForegroundColor (true);
if (category.isDefined (EditorStyleConstants.WaveUnderlineColor)) {
annotationType.setUseWaveUnderlineColor (true);
if(category.getAttribute (EditorStyleConstants.WaveUnderlineColor) == null || !category.getAttribute (EditorStyleConstants.WaveUnderlineColor).equals(annotationType.getWaveUnderlineColor())) {
annotationType.setWaveUnderlineColor (
(Color) category.getAttribute (EditorStyleConstants.WaveUnderlineColor)
);
}
c.addAttribute((EditorStyleConstants.WaveUnderlineColor), category.getAttribute (EditorStyleConstants.WaveUnderlineColor));
} else
annotationType.setUseWaveUnderlineColor (false);
//S ystem.out.println(" " + category.getDisplayName () + " : " + annotationType + " : " + annotationType.getHighlight() + " : " + annotationType.isUseHighlightColor());
annos.add(c);
}
EditorSettings.getDefault().setAnnotations(profile, toMap(annos));
}
@Override
protected Map<Attribute,Object> getAttributes(AttributeSet attrSet)
{
Map<Attribute,Object> attrMap = new HashMap<Attribute,Object>();
if (attrSet.isDefined(StyleConstants.FontFamily))
{
attrMap.put(
TextAttribute.FAMILY,
StyleConstants.getFontFamily(attrSet)
);
}
if (attrSet.isDefined(StyleConstants.Bold))
{
attrMap.put(
TextAttribute.WEIGHT,
StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR
);
}
if (attrSet.isDefined(StyleConstants.Italic))
{
attrMap.put(
TextAttribute.POSTURE,
StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR
);
}
if (attrSet.isDefined(StyleConstants.Underline))
{
attrMap.put(
TextAttribute.UNDERLINE,
StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null
);
}
if (attrSet.isDefined(StyleConstants.StrikeThrough))
{
attrMap.put(
TextAttribute.STRIKETHROUGH,
StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null
);
}
if (attrSet.isDefined(StyleConstants.FontSize))
{
attrMap.put(
TextAttribute.SIZE,
StyleConstants.getFontSize(attrSet)
);
}
if (attrSet.isDefined(StyleConstants.Foreground))
{
attrMap.put(
TextAttribute.FOREGROUND,
StyleConstants.getForeground(attrSet)
);
}
if (attrSet.isDefined(StyleConstants.Background))
{
attrMap.put(
TextAttribute.BACKGROUND,
StyleConstants.getBackground(attrSet)
);
}
//FIXME: why StyleConstants.isSuperscript(attrSet) does return false
if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet))
{
attrMap.put(
TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUPER
);
}
if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet))
{
attrMap.put(
TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUB
);
}
return attrMap;
}
/**
*
*/
protected Map<Attribute,Object> getAttributes(AttributeSet attrSet)
{
Map<Attribute,Object> attrMap = new HashMap<Attribute,Object>();
if (attrSet.isDefined(StyleConstants.FontFamily))
{
attrMap.put(
TextAttribute.FAMILY,
StyleConstants.getFontFamily(attrSet)
);
}
if (attrSet.isDefined(StyleConstants.Bold))
{
attrMap.put(
TextAttribute.WEIGHT,
StyleConstants.isBold(attrSet) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR
);
}
if (attrSet.isDefined(StyleConstants.Italic))
{
attrMap.put(
TextAttribute.POSTURE,
StyleConstants.isItalic(attrSet) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR
);
}
if (attrSet.isDefined(StyleConstants.Underline))
{
attrMap.put(
TextAttribute.UNDERLINE,
StyleConstants.isUnderline(attrSet) ? TextAttribute.UNDERLINE_ON : null
);
}
if (attrSet.isDefined(StyleConstants.StrikeThrough))
{
attrMap.put(
TextAttribute.STRIKETHROUGH,
StyleConstants.isStrikeThrough(attrSet) ? TextAttribute.STRIKETHROUGH_ON : null
);
}
if (attrSet.isDefined(StyleConstants.FontSize))
{
attrMap.put(
TextAttribute.SIZE,
StyleConstants.getFontSize(attrSet)
);
}
if (attrSet.isDefined(StyleConstants.Foreground))
{
attrMap.put(
TextAttribute.FOREGROUND,
StyleConstants.getForeground(attrSet)
);
}
if (attrSet.isDefined(StyleConstants.Background))
{
attrMap.put(
TextAttribute.BACKGROUND,
StyleConstants.getBackground(attrSet)
);
}
//FIXME: why StyleConstants.isSuperscript(attrSet) does return false
if (attrSet.isDefined(StyleConstants.Superscript) && !StyleConstants.isSubscript(attrSet))
{
attrMap.put(
TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUPER
);
}
if (attrSet.isDefined(StyleConstants.Subscript) && StyleConstants.isSubscript(attrSet))
{
attrMap.put(
TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUB
);
}
return attrMap;
}