/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A pool of styles and their associated resources. This class determines
* the lifetime of a group of resources by being a container that holds
* caches for various resources such as font and color that get reused
* by the various style definitions. This can be shared by multiple
* documents if desired to maximize the sharing of related resources.
* <p>
* This class also provides efficient support for small sets of attributes
* and compresses them by sharing across uses and taking advantage of
* their immutable nature. Since many styles are replicated, the potential
* for sharing is significant, and copies can be extremely cheap.
* Larger sets reduce the possibility of sharing, and therefore revert
* automatically to a less space-efficient implementation.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Timothy Prinzing
*/
/**
* Returns default AttributeContext shared by all documents that
*
* @return the context
*/
if (defaultContext == null) {
defaultContext = new StyleContext();
}
return defaultContext;
}
/**
* Creates a new StyleContext object.
*/
public StyleContext() {
}
/**
* Adds a new style into the style hierarchy. Style attributes
* resolve from bottom up so an attribute specified in a child
* will override an attribute specified in the parent.
*
* @param nm the name of the style (must be unique within the
* collection of named styles in the document). The name may
* be null if the style is unnamed, but the caller is responsible
* for managing the reference returned as an unnamed style can't
* be fetched by name. An unnamed style may be useful for things
* like character attribute overrides such as found in a style
* run.
* @param parent the parent style. This may be null if unspecified
* attributes need not be resolved in some other style.
* @return the created style
*/
// add a named style, a class of attributes
}
return style;
}
/**
* Removes a named style previously added to the document.
*
* @param nm the name of the style to remove
*/
}
/**
* Fetches a named style previously added to the document
*
* @param nm the name of the style
* @return the style
*/
}
/**
* Fetches the names of the styles defined.
*
* @return the list of names as an enumeration
*/
return styles.getAttributeNames();
}
/**
* Adds a listener to track when styles are added
* or removed.
*
* @param l the change listener
*/
}
/**
* Removes a listener that was tracking styles being
* added or removed.
*
* @param l the change listener
*/
}
/**
* Returns an array of all the <code>ChangeListener</code>s added
* to this StyleContext with addChangeListener().
*
* @return all of the <code>ChangeListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
}
/**
* Gets the font from an attribute set. This is
* implemented to try and fetch a cached font
* for the given AttributeSet, and if that fails
* the font features are resolved and the
* font is fetched from the low-level font cache.
*
* @param attr the attribute set
* @return the font
*/
// PENDING(prinz) add cache behavior
}
}
/**
* if either superscript or subscript is
* is set, we need to reduce the font size
* by 2.
*/
size -= 2;
}
}
/**
* Takes a set of attributes and turn it into a foreground color
* specification. This might be used to specify things
* like brighter, more hue, etc. By default it simply returns
* the value specified by the StyleConstants.Foreground attribute.
*
* @param attr the set of attributes
* @return the color
*/
}
/**
* Takes a set of attributes and turn it into a background color
* specification. This might be used to specify things
* like brighter, more hue, etc. By default it simply returns
* the value specified by the StyleConstants.Background attribute.
*
* @param attr the set of attributes
* @return the color
*/
}
/**
* Gets a new font. This returns a Font from a cache
* if a cached font exists. If not, a Font is added to
* the cache. This is basically a low-level cache for
* 1.1 font features.
*
* @param family the font family (such as "Monospaced")
* @param style the style of the font (such as Font.PLAIN)
* @param size the point size >= 1
* @return the new font
*/
if (f == null) {
// haven't seen this one yet.
if (defaultStyle != null) {
if (defaultFont != null
}
}
if (f == null) {
}
if (! FontUtilities.fontSupportsDefaultEncoding(f)) {
}
}
return f;
}
/**
* Returns font metrics for a font.
*
* @param f the font
* @return the metrics
*/
// The Toolkit implementations cache, so we just forward
// to the default toolkit.
}
// --- AttributeContext methods --------------------
/**
* Adds an attribute to the given set, and returns
* the new representative set.
* <p>
* This method is thread safe, although most Swing methods
* are not. Please see
* to Use Threads</A> for more information.
*
* @param old the old attribute set
* @param name the non-null attribute name
* @param value the attribute value
* @return the updated attribute set
* @see MutableAttributeSet#addAttribute
*/
// set.
return getImmutableUniqueSet();
}
return ma;
}
/**
* Adds a set of attributes to the element.
* <p>
* This method is thread safe, although most Swing methods
* are not. Please see
* to Use Threads</A> for more information.
*
* @param old the old attribute set
* @param attr the attributes to add
* @return the updated attribute set
* @see MutableAttributeSet#addAttribute
*/
// set.
return getImmutableUniqueSet();
}
return ma;
}
/**
* Removes an attribute from the set.
* <p>
* This method is thread safe, although most Swing methods
* are not. Please see
* to Use Threads</A> for more information.
*
* @param old the old set of attributes
* @param name the non-null attribute name
* @return the updated attribute set
* @see MutableAttributeSet#removeAttribute
*/
// set.
return getImmutableUniqueSet();
}
return ma;
}
/**
* Removes a set of attributes for the element.
* <p>
* This method is thread safe, although most Swing methods
* are not. Please see
* to Use Threads</A> for more information.
*
* @param old the old attribute set
* @param names the attribute names
* @return the updated attribute set
* @see MutableAttributeSet#removeAttributes
*/
// set.
return getImmutableUniqueSet();
}
return ma;
}
/**
* Removes a set of attributes for the element.
* <p>
* This method is thread safe, although most Swing methods
* are not. Please see
* to Use Threads</A> for more information.
*
* @param old the old attribute set
* @param attrs the attributes
* @return the updated attribute set
* @see MutableAttributeSet#removeAttributes
*/
// set.
return getImmutableUniqueSet();
}
return ma;
}
/**
* Fetches an empty AttributeSet.
*
* @return the set
*/
return SimpleAttributeSet.EMPTY;
}
/**
* Returns a set no longer needed by the MutableAttributeSet implmentation.
* This is useful for operation under 1.1 where there are no weak
* references. This would typically be called by the finalize method
* of the MutableAttributeSet implementation.
* <p>
* This method is thread safe, although most Swing methods
* are not. Please see
* to Use Threads</A> for more information.
*
* @param a the set to reclaim
*/
if (SwingUtilities.isEventDispatchThread()) {
}
// if current thread is not event dispatching thread
// do not bother with expunging stale entries.
}
// --- local methods -----------------------------------------------
/**
* limit will use hashtables and be a MutableAttributeSet.
*
* @return the threshold
*/
protected int getCompressionThreshold() {
return THRESHOLD;
}
/**
* Create a compact set of attributes that might be shared.
* This is a hook for subclasses that want to alter the
* behavior of SmallAttributeSet. This can be reimplemented
* to return an AttributeSet that provides some sort of
* attribute conversion.
*
* @param a The set of attributes to be represented in the
* the compact form.
*/
return new SmallAttributeSet(a);
}
/**
* Create a large set of attributes that should trade off
* space for time. This set will not be shared. This is
* a hook for subclasses that want to alter the behavior
* of the larger attribute storage format (which is
* SimpleAttributeSet by default). This can be reimplemented
* to return a MutableAttributeSet that provides some sort of
* attribute conversion.
*
* @param a The set of attributes to be represented in the
* the larger form.
*/
return new SimpleAttributeSet(a);
}
/**
* Clean the unused immutable sets out of the hashtable.
*/
synchronized void removeUnusedSets() {
}
/**
* Search for an existing attribute set using the current search
* parameters. If a matching set is found, return it. If a match
* is not found, we create a new set and add it to the pool.
*/
// PENDING(prinz) should consider finding a alternative to
// generating extra garbage on search key.
a = key;
}
return a;
}
/**
* Creates a mutable attribute set to hand out because the current
* needs are too big to try and use a shared version.
*/
if (a instanceof MutableAttributeSet &&
a != SimpleAttributeSet.EMPTY) {
return (MutableAttributeSet) a;
}
return createLargeAttributeSet(a);
}
/**
* Converts a StyleContext to a String.
*
* @return the string
*/
String s = "";
s = s + set + "\n";
}
return s;
}
// --- serialization ---------------------------------------------
/**
* Context-specific handling of writing out attributes
*/
AttributeSet a) throws IOException {
writeAttributeSet(out, a);
}
/**
* Context-specific handling of reading in attributes
*/
readAttributeSet(in, a);
}
/**
* Writes a set of attributes to the given object stream
* for the purpose of serialization. This will take
* special care to deal with static attribute keys that
* have been registered wit the
* <code>registerStaticAttributeKey</code> method.
* Any attribute key not regsitered as a static key
* will be serialized directly. All values are expected
* to be serializable.
*
* @param out the output stream
* @param a the attribute set
* @exception IOException on any I/O error
*/
AttributeSet a) throws IOException {
int n = a.getAttributeCount();
while (keys.hasMoreElements()) {
if (key instanceof Serializable) {
} else {
getName() + " is not serializable as a key in an AttributeSet");
}
}
if (value instanceof Serializable) {
} else {
getName() + " is not serializable as a value in an AttributeSet");
}
}
}
}
/**
* Reads a set of attributes from the given object input
* stream that have been previously written out with
* <code>writeAttributeSet</code>. This will try to restore
* keys that were static objects to the static objects in
* the current virtual machine considering only those keys
* that have been registered with the
* <code>registerStaticAttributeKey</code> method.
* The attributes retrieved from the stream will be placed
* into the given mutable set.
*
* @param in the object stream to read the attribute data from.
* @param a the attribute set to place the attribute
* definitions in.
* @exception ClassNotFoundException passed upward if encountered
* when reading the object stream.
* @exception IOException passed upward if encountered when
* reading the object stream.
*/
for (int i = 0; i < n; i++) {
if (thawKeyMap != null) {
}
if (staticValue != null) {
value = staticValue;
}
}
}
}
/**
* Registers an object as a static object that is being
* used as a key in attribute sets. This allows the key
* to be treated specially for serialization.
* <p>
* For operation under a 1.1 virtual machine, this
* uses the value returned by <code>toString</code>
* concatenated to the classname. The value returned
* by toString should not have the class reference
* in it (ie it should be reimplemented from the
* definition in Object) in order to be the same when
* recomputed later.
*
* @param key the non-null object key
*/
if (freezeKeyMap == null) {
}
}
/**
* Returns the object previously registered with
* <code>registerStaticAttributeKey</code>.
*/
return null;
}
}
/**
* Returns the String that <code>key</code> will be registered with
* @see #getStaticAttribute
* @see #registerStaticAttributeKey
*/
}
throws IOException
{
// clean out unused sets before saving
s.defaultWriteObject();
}
throws ClassNotFoundException, IOException
{
search = new SimpleAttributeSet();
s.defaultReadObject();
}
// --- variables ---------------------------------------------------
/**
* The name given to the default logical style attached
* to paragraphs.
*/
private transient Map<SmallAttributeSet, WeakReference<SmallAttributeSet>> attributesPool = Collections.
/**
* Number of immutable sets that are not currently
* being used. This helps indicate when the sets need
* to be cleaned out of the hashtable they are stored
* in.
*/
private int unusedSets;
/**
* The threshold for no longer sharing the set of attributes
* in an immutable table.
*/
/**
* This class holds a small number of attributes in an array.
* The storage format is key, value, key, value, etc. The size
* of the set is the length of the array divided by two. By
* default, this is the class that will be used to store attributes
* when held in the compact sharable form.
*/
this.attributes = attributes;
}
int n = attrs.getAttributeCount();
int i = 0;
while (names.hasMoreElements()) {
i += 2;
}
attributes = tbl;
}
private void updateResolveParent() {
break;
}
}
}
return resolveParent;
}
return tbl[i+1];
}
}
return null;
}
// --- Object methods -------------------------
/**
*/
String s = "{";
// don't recurse
} else {
}
}
s = s + "}";
return s;
}
/**
* Returns a hashcode for this set of attributes.
* @return a hashcode value for this set of attributes.
*/
public int hashCode() {
int code = 0;
}
return code;
}
/**
* Compares this object to the specifed object.
* The result is <code>true</code> if the object is an equivalent
* set of attributes.
* @param obj the object to compare with.
* @return <code>true</code> if the objects are equal;
* <code>false</code> otherwise.
*/
if (obj instanceof AttributeSet) {
}
return false;
}
/**
* Clones a set of attributes. Since the set is immutable, a
* clone is basically the same set.
*
* @return the set of attributes
*/
return this;
}
// --- AttributeSet methods ----------------------------
/**
* Gets the number of attributes that are defined.
*
* @return the number of attributes
* @see AttributeSet#getAttributeCount
*/
public int getAttributeCount() {
}
/**
* Checks whether a given attribute is defined.
*
* @param key the attribute key
* @return true if the attribute is defined
* @see AttributeSet#isDefined
*/
Object[] a = attributes;
int n = a.length;
for (int i = 0; i < n; i += 2) {
return true;
}
}
return false;
}
/**
* Checks whether two attribute sets are equal.
*
* @param attr the attribute set to check against
* @return true if the same
* @see AttributeSet#isEqual
*/
if (attr instanceof SmallAttributeSet) {
return attr == this;
}
}
/**
* Copies a set of attributes.
*
* @return the copy
* @see AttributeSet#copyAttributes
*/
return this;
}
/**
* Gets the value of an attribute.
*
* @param key the attribute name
* @return the attribute value
* @see AttributeSet#getAttribute
*/
}
return value;
}
/**
* Gets the names of all attributes.
*
* @return the attribute names
* @see AttributeSet#getAttributeNames
*/
return new KeyEnumeration(attributes);
}
/**
*
* @param name the attribute name
* @param value the attribute value
* @see AttributeSet#containsAttribute
*/
}
/**
* Checks whether the attribute set contains all of
* the given attributes.
*
* @param attrs the attributes to check
* @return true if the element contains all the attributes
* @see AttributeSet#containsAttributes
*/
boolean result = true;
}
return result;
}
/**
* If not overriden, the resolving parent defaults to
* the parent element.
*
* @return the attributes from the parent
* @see AttributeSet#getResolveParent
*/
return resolveParent;
}
// --- variables -----------------------------------------
// This is also stored in attributes
}
/**
* An enumeration of the keys in a SmallAttributeSet.
*/
i = 0;
}
/**
* Tests if this enumeration contains more elements.
*
* @return <code>true</code> if this enumeration contains more elements;
* <code>false</code> otherwise.
* @since JDK1.0
*/
public boolean hasMoreElements() {
}
/**
* Returns the next element of this enumeration.
*
* @return the next element of this enumeration.
* @exception NoSuchElementException if no more elements exist.
* @since JDK1.0
*/
i += 2;
return o;
}
throw new NoSuchElementException();
}
int i;
}
/**
* Sorts the key strings so that they can be very quickly compared
* in the attribute set searchs.
*/
class KeyBuilder {
if (a instanceof SmallAttributeSet) {
} else {
while (names.hasMoreElements()) {
}
}
}
/**
* Initialize with a set of already sorted
* keys (data from an existing SmallAttributeSet).
*/
for (int i = 0; i < n; i += 2) {
}
}
/**
* suitable for creation of an instance of
* SmallAttributeSet.
*/
for (int i = 0; i < n; i ++) {
int offs = 2 * i;
}
return tbl;
}
/**
* in the current key being forged.
*/
int getCount() {
}
/**
*/
}
/**
*/
if (attr instanceof SmallAttributeSet) {
// avoid searching the keys, they are already interned.
for (int i = 0; i < n; i += 2) {
}
} else {
while (names.hasMoreElements()) {
}
}
}
/**
* Removes the given name from the set.
*/
for (int i = 0; i < n; i++) {
keys.removeElementAt(i);
data.removeElementAt(i);
return;
}
}
}
/**
* Removes the set of keys from the set.
*/
while (names.hasMoreElements()) {
}
}
/**
* Removes the set of matching attributes from the set.
*/
while (names.hasMoreElements()) {
}
}
for (int i = 0; i < n; i++) {
keys.removeElementAt(i);
data.removeElementAt(i);
}
return;
}
}
}
}
/**
* key for a font table
*/
static class FontKey {
private int style;
private int size;
/**
* Constructs a font key.
*/
}
}
/**
* Returns a hashcode for this font.
* @return a hashcode value for this font.
*/
public int hashCode() {
}
/**
* Compares this object to the specifed object.
* The result is <code>true</code> if and only if the argument is not
* <code>null</code> and is a <code>Font</code> object with the same
* name, style, and point size as this font.
* @param obj the object to compare this font with.
* @return <code>true</code> if the objects are equal;
* <code>false</code> otherwise.
*/
}
return false;
}
}
/**
* A collection of attributes, typically used to represent
* character and paragraph styles. This is an implementation
* of MutableAttributeSet that can be observed if desired.
* These styles will take advantage of immutability while
* the sets are small enough, and may be substantially more
* efficient than something like SimpleAttributeSet.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*/
/**
* Creates a new named style.
*
* @param name the style name, null for unnamed
* @param parent the parent style, null if none
* @since 1.4
*/
attributes = getEmptySet();
}
}
}
/**
* Creates a new named style.
*
* @param parent the parent style, null if none
* @since 1.4
*/
}
/**
* Creates a new named style, with a null name and parent.
*/
public NamedStyle() {
attributes = getEmptySet();
}
/**
* Converts the style to a string.
*
* @return the string
*/
}
/**
* Fetches the name of the style. A style is not required to be named,
* so null is returned if there is no name associated with the style.
*
* @return the name
*/
}
return null;
}
/**
* Changes the name of the style. Does nothing with a null name.
*
* @param name the new name
*/
}
}
/**
* Adds a change listener.
*
* @param l the change listener
*/
}
/**
* Removes a change listener.
*
* @param l the change listener
*/
}
/**
* Returns an array of all the <code>ChangeListener</code>s added
* to this NamedStyle with addChangeListener().
*
* @return all of the <code>ChangeListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type. The event instance
* is lazily created using the parameters passed into
* the fire method.
*
* @see EventListenerList
*/
protected void fireStateChanged() {
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==ChangeListener.class) {
// Lazily create the event:
if (changeEvent == null)
changeEvent = new ChangeEvent(this);
}
}
}
/**
* Return an array of all the listeners of the given type that
* were added to this model.
*
* @return all of the objects receiving <em>listenerType</em> notifications
* from this model
*
* @since 1.3
*/
}
// --- AttributeSet ----------------------------
// delegated to the immutable field "attributes"
/**
* Gets the number of attributes that are defined.
*
* @return the number of attributes >= 0
* @see AttributeSet#getAttributeCount
*/
public int getAttributeCount() {
return attributes.getAttributeCount();
}
/**
* Checks whether a given attribute is defined.
*
* @param attrName the non-null attribute name
* @return true if the attribute is defined
* @see AttributeSet#isDefined
*/
}
/**
* Checks whether two attribute sets are equal.
*
* @param attr the attribute set to check against
* @return true if the same
* @see AttributeSet#isEqual
*/
}
/**
* Copies a set of attributes.
*
* @return the copy
* @see AttributeSet#copyAttributes
*/
NamedStyle a = new NamedStyle();
return a;
}
/**
* Gets the value of an attribute.
*
* @param attrName the non-null attribute name
* @return the attribute value
* @see AttributeSet#getAttribute
*/
}
/**
* Gets the names of all attributes.
*
* @return the attribute names as an enumeration
* @see AttributeSet#getAttributeNames
*/
return attributes.getAttributeNames();
}
/**
*
* @param name the non-null attribute name
* @param value the attribute value
* @see AttributeSet#containsAttribute
*/
}
/**
* Checks whether the element contains all the attributes.
*
* @param attrs the attributes to check
* @return true if the element contains all the attributes
* @see AttributeSet#containsAttributes
*/
}
/**
* Gets attributes from the parent.
* If not overriden, the resolving parent defaults to
* the parent element.
*
* @return the attributes from the parent
* @see AttributeSet#getResolveParent
*/
return attributes.getResolveParent();
}
// --- MutableAttributeSet ----------------------------------
// should fetch a new immutable record for the field
// "attributes".
/**
* Adds an attribute.
*
* @param name the non-null attribute name
* @param value the attribute value
* @see MutableAttributeSet#addAttribute
*/
}
/**
* Adds a set of attributes to the element.
*
* @param attr the attributes to add
* @see MutableAttributeSet#addAttribute
*/
}
/**
* Removes an attribute from the set.
*
* @param name the non-null attribute name
* @see MutableAttributeSet#removeAttribute
*/
}
/**
* Removes a set of attributes for the element.
*
* @param names the attribute names
* @see MutableAttributeSet#removeAttributes
*/
}
/**
* Removes a set of attributes for the element.
*
* @param attrs the attributes
* @see MutableAttributeSet#removeAttributes
*/
if (attrs == this) {
} else {
}
}
/**
* Sets the resolving parent.
*
* @param parent the parent, null if none
* @see MutableAttributeSet#setResolveParent
*/
} else {
}
}
// --- serialization ---------------------------------------------
s.defaultWriteObject();
}
throws ClassNotFoundException, IOException
{
s.defaultReadObject();
readAttributeSet(s, this);
}
// --- member variables -----------------------------------------------
/**
* The change listeners for the model.
*/
/**
* Only one ChangeEvent is needed per model instance since the
* event's only (read-only) state is the source property. The source
* of events generated here is always "this".
*/
/**
* Inner AttributeSet implementation, which may be an
* immutable unique set being shared.
*/
}
static {
// initialize the static key registry with the StyleConstants keys
try {
for (int i = 0; i < n; i++) {
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}