001 /* AttributeSet.java -- 002 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package javax.swing.text; 039 040 import java.util.Enumeration; 041 042 /** 043 * A set of attributes. An attribute has a key and a value. They typically 044 * describe features of a piece of text that make up its graphical 045 * representation. 046 * 047 * An <code>AttributeSet</code> may have a resolving parent, 048 * that is another <code>AttributeSet</code> that is searched for attribute 049 * keys that are not stored locally in this <code>AttributeSet</code>. 050 * 051 * @author original author unknown 052 * @author Roman Kennke (roman@kennke.org) 053 */ 054 public interface AttributeSet 055 { 056 /** 057 * Used as keys to identify character-run attributes. 058 */ 059 static interface CharacterAttribute 060 { 061 // This interface is a marker interface and has no methods. 062 } 063 064 /** 065 * Used as keys to identify color attributes. 066 */ 067 static interface ColorAttribute 068 { 069 // This interface is a marker interface and has no methods. 070 } 071 072 /** 073 * Used as keys to identify font attributes. 074 */ 075 static interface FontAttribute 076 { 077 // This interface is a marker interface and has no methods. 078 } 079 080 /** 081 * Used as keys to identify paragraph level attributes. 082 */ 083 static interface ParagraphAttribute 084 { 085 // This interface is a marker interface and has no methods. 086 } 087 088 /** 089 * Key of the attribute that is used to describe the name of an 090 * <code>AttributeSet</code>. 091 */ 092 Object NameAttribute = StyleConstants.NameAttribute; 093 094 /** 095 * Key of the attribute that is used to identify the resolving parent of 096 * an <code>AttributeSet</code>. 097 */ 098 Object ResolveAttribute = StyleConstants.ResolveAttribute; 099 100 /** 101 * Returns <code>true</code> if this <code>AttributeSet</code> contains 102 * an attribute with the specified <code>name</code> and <code>value</code>, 103 * <code>false</code> otherwise. 104 * 105 * @param name the name of the requested attribute 106 * @param value the value of the requested attribute 107 * 108 * @return <code>true</code> if this <code>AttributeSet</code> contains 109 * an attribute with the specified <code>name</code> and 110 * <code>value</code>, <code>false</code> otherwise 111 */ 112 boolean containsAttribute(Object name, Object value); 113 114 /** 115 * Returns <code>true</code> of this <code>AttributeSet</code> contains all 116 * of the specified <code>attributes</code>. 117 * 118 * @param attributes the requested attributes 119 * 120 * @return <code>true</code> of this <code>AttributeSet</code> contains all 121 * of the specified <code>attributes</code> 122 */ 123 boolean containsAttributes(AttributeSet attributes); 124 125 /** 126 * Creates and returns a copy of this <code>AttributeSet</code>. 127 * 128 * @return a copy of this <code>AttributeSet</code> 129 */ 130 AttributeSet copyAttributes(); 131 132 /** 133 * Returns the attribute with the specified <code>key</code> or 134 * <code>null</code> if no such attribute is defined in this 135 * <code>AttributeSet</code> and its resolving parents. 136 * 137 * @param key the key of the attribute that is looked up 138 * 139 * @return the attribute with the specified <code>key</code> or 140 * <code>null</code> if no such attribute is defined in this 141 * <code>AttributeSet</code> and its resolving parents 142 */ 143 Object getAttribute(Object key); 144 145 /** 146 * Returns the number of attributes that are stored locally in this 147 * <code>AttributeSet</code>. 148 * 149 * @return the number of attributes that are stored locally in this 150 * <code>AttributeSet</code> 151 */ 152 int getAttributeCount(); 153 154 /** 155 * Returns the names of the attributes that are stored in this 156 * <code>AttributeSet</code>. 157 * 158 * @return the names of the attributes that are stored in this 159 * <code>AttributeSet</code> 160 */ 161 Enumeration<?> getAttributeNames(); 162 163 /** 164 * Returns the resolving parent of this <code>AttributeSet</code>. 165 * If a key is not stored locally, then a {@link #getAttribute(Object)} 166 * request is resolved up in the resolving parent of this 167 * <code>AttributeSet</code>. 168 * 169 * @return the resolving parent of this <code>AttributeSet</code> 170 */ 171 AttributeSet getResolveParent(); 172 173 /** 174 * Returns <code>true</code> if an attribute with the specified name is 175 * defined locally in this <code>AttributeSet</code>, without resolving 176 * through the resolving parents. 177 * 178 * @return <code>true</code> if an attribute with the specified name is 179 * defined locally in this <code>AttributeSet</code> 180 */ 181 boolean isDefined(Object attrName); 182 183 /** 184 * Returns <code>true</code> if all of the attributes in <code>attr</code> 185 * are equal to the attributes in this <code>AttributeSet</code>, 186 * <code>false</code> otherwise. 187 * 188 * @param attr the attributes to be compared to <code>this</code> 189 * 190 * @return <code>true</code> if all of the attributes in <code>attr</code> 191 * are equal to the attributes in this <code>AttributeSet</code>, 192 * <code>false</code> otherwise 193 */ 194 boolean isEqual(AttributeSet attr); 195 }