I've attached the source for an implementation of the
javax.swing.text.AttributeSet interface.


Enjoy,
Ian
-- 
A kind word need not cost much,
The price of praise can be cheap:
With half a loaf and an empty cup
I found myself a friend.
--Havamal, St. 52
/* AttributeSet.java -- Java interface defining a key-value pair set of
   attributes for a text segment
   Copyright (C) 2000 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
 
GNU Classpath 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 for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */

package javax.swing.text;

import java.util.Enumeration;

/**
 * The AttributeSet represents a set of immutable key-value pairs defining
 * traits of a segment of text.  It may represent a particular visual style,
 * the layout of a block of text, or some other attribute.
 */
public interface AttributeSet
{
  /**
   * The signature interface of an attribute which contributes to character-
   * level formatting
   */
  public static interface CharacterAttribute
  {
  }

  /**
   * The signature interface of an attribute which defines the color of
   * a text segment
   */
  public static interface ColorAttribute
  {
  }

  /**
   * The signature interface for an attribute which defines the font
   * to be used for a text segment.  This would include things like 
   * font weight, style, pitch size and font family
   */
  public static interface FontAttribute
  {
  }

  /**
   * The signature interface for any attribute which contributes to paragraph-
   * level formatting.
   */
  public static interface ParagraphAttribute
  {
  }

  /**
   * The attribute key for the name of the entire set of attributes
   */
  public static Object NameAttribute = "name";
  
  /**
   * Attribute key used to resolve the parent AttributeSet, if any
   */
  public static Object ResolveAttribute = "resolve";

  /**
   * Returns the number of attributes contained within this AttributeSet.
   * If the AttributeSet is empty, returns 0.
   */
  public int getAttributeCount();

  /**
   * Determines whether a value has been specified for the attribute 
   * with the given attribute name
   *
   * @param attrName the attribute name
   * @return true if the value for the associated attribute has been specified
   *     False otherwise
   */
  public boolean isDefined(Object attrName);

  /**
   * Determined whether this AttributeSet is equal to the specified 
   * AttributeSet
   * 
   * @param attr the AttributeSet being compared
   * @return true if the two AttributeSets are equal, false otherwise
   */
  public boolean isEqual(AttributeSet attr);

  /**
   * Returns a 'snapshot' of this AttributeSet.  This is an immutable copy
   * of this AttributeSet, as it existed at the time this method was invoked
   *
   * @return a copy of this AttributeSet
   */
  public AttributeSet copyAttributes();

  /**
   * Returns the value of the attribute with the specified attribute name.
   * If no attribute with the specified attribute name can be found, the
   * parent AttributeSet (if any) will be searched recursively.
   *
   * @param key the attribute key
   * @return the value of the attribute corresponding to <CODE>key</CODE>, or
   *   null if no attribute could be found
   */
  public Object getAttribute(Object key);

  /**
   * Returns an enumeration of all the keys used within this AttributeSet.
   * The elements of the resulting Enumeration are all String objects.
   *
   * This Enumeration does not include the parent AttributeSet (if any).
   */
  public Enumeration getAttributeNames();

  /**
   * Tests whether this AttributeSet contains the specified attribute.
   * This method only returns true if the AttributeSet contains an attribute
   * with the given attribute name and the value of the attribute matches
   * the specified value
   *
   * @param name  the name of the attribute
   * @param value the value of the attribute
   * @return true if an attribute with the given name and value is contained
   *     within this AttributeSet.  False otherwise
   */
  public boolean containsAttribute(Object name, Object value);

  /**
   * Tests whether this AttributeSet contains attributes with the specified
   * name and value of each of the attributes of the specified AttributeSet.
   *
   * @param attributes  the AttributeSet to compare
   * @return true if this AttributeSet contains each of the attributes in
   *     <CODE>attributes</CODE>.  False otherwise
   * @see #containsAttribute(java.lang.Object, java.lang.Object)
   */
  public boolean containsAttributes(AttributeSet attributes);

  /**
   * Returns the resolving parent AttributeSet of this AttributeSet, if any.
   *
   * @return the resolving parent AttributeSet
   */
  public AttributeSet getResolveParent();
}

Reply via email to