au.id.pbw.hyfo.hyph
Class HyphenMarker

java.lang.Object
  extended by java.text.AttributedCharacterIterator.Attribute
      extended by au.id.pbw.hyfo.hyph.HyphenMarker
All Implemented Interfaces:
Serializable

public final class HyphenMarker
extends AttributedCharacterIterator.Attribute

The attribute key for an instance of HyphenBreak, containing the details of a potential hyphenation break in an AttributedString. The character on which the HyphenMarker attribute is expected to be set is the character preceding a possible hyphenation position.

HyphenMarker is designed to integrate hyphenation with Java2D text processing. The class extends java.text.AttributedCharacterIterator.Attribute, so that it can be used as an attribute in a java.text.AttributedString. For example, if a String hyphenated_string has been analysed for hyphenation, and a particular HyphenBreak value, hyphen_break, is associated with a particular position in hyhenated_string, hyphen_break_point, then HyphenMarker can be used to mark that position in an AttributedString, as follows.

   String hyhenated_string = ...;
   int hyphen_break_point = ...;
   AttributedString attributed_string = new AttributedString(hyphenated_string);
   ...
   attributed_string.addAttribute(
                              HyphenMarker.HYPHEN_MARKER, hyphen_break,
                              hyphen_break_point, hyphen_break_point + 1); 
 

An AttributedCharacterIterator can be derived from the AttributedString as follows.

   AttributedCharacterIterator iter = attributed_string.getIterator();
 

The AttributedString may have other attributes defined upon it. An iterator over only the HyphenMarkers can be derived as follows.

   AttributedCharacterIterator.Attribute[] hyphen_attr_only
                              = new AttributedCharacterIterator.Attribute[]
   AttributedCharacterIterator hyphen_iter
                          = attributed_string.getIterator(hyphen_attr_only);
 

Author:
pbw
See Also:
Serialized Form

Field Summary
static HyphenMarker HYPHEN_MARKER
          The named singleton instance of HyphenMarker.
 
Fields inherited from class java.text.AttributedCharacterIterator.Attribute
INPUT_METHOD_SEGMENT, LANGUAGE, READING
 
Constructor Summary
protected HyphenMarker(String name)
          Attempts to create a new instance of HyphenMarker
 
Method Summary
protected  Object readResolve()
          Deserialises instance to the only valid constant.
 
Methods inherited from class java.text.AttributedCharacterIterator.Attribute
equals, getName, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

HYPHEN_MARKER

public static final HyphenMarker HYPHEN_MARKER
The named singleton instance of HyphenMarker.

Constructor Detail

HyphenMarker

protected HyphenMarker(String name)
Attempts to create a new instance of HyphenMarker

Parameters:
name - the name of the HyphenMarker.
Method Detail

readResolve

protected Object readResolve()
                      throws InvalidObjectException
Deserialises instance to the only valid constant.

Overrides:
readResolve in class AttributedCharacterIterator.Attribute
Returns:
HYPHEN_MARKER
Throws:
InvalidObjectException - if this object is not resolved to the single instance during deserialization.


Copyright © 2005-2006 Peter B. West.