RichEdit control - JDK 1.1 compatibility classes

X-SVN-Rev: 1180
This commit is contained in:
Alan Liu 2000-04-20 17:33:07 +00:00
parent 05a806c6bc
commit 5f7a92e6c0
10 changed files with 1098 additions and 0 deletions

View file

@ -0,0 +1,29 @@
/*
* @(#)$RCSfile: FontUtils.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:30:44 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
// Requires Java2
package com.ibm.textlayout;
import java.awt.Font;
public final class FontUtils {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
public static Font getFont(java.util.Map attributes) {
return Font.getFont(attributes);
}
}

View file

@ -0,0 +1,56 @@
/*
* @(#)$RCSfile: Graphics2DConversion.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:30:44 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
// Requires Java2
package com.ibm.textlayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
/**
* This class allows JDK 1.1 code to use a "fake" Graphics2D
* for source-code compatibility with Java2 code. On Java2 it's
* a trivial class. The JDK 1.1 version of this class does interesting
* work.
*/
public final class Graphics2DConversion {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
public static Graphics2D getGraphics2D(Graphics g) {
return (Graphics2D) g;
}
public static Graphics getGraphics(Graphics2D g) {
return g;
}
/**
* Will return an instance of Paint.
*/
public static Object getColorState(Graphics2D g) {
return g.getPaint();
}
/**
* State must be an instance of Paint.
*/
public static void restoreColorState(Graphics2D g, Object state) {
g.setPaint((Paint) state);
}
}

View file

@ -0,0 +1,165 @@
/*
* @(#)$RCSfile: AttributeKey.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:33:07 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.textlayout.attributes;
import java.io.Serializable;
/**
* This class provides a cannonical mapping between fields in TextAttribute
* and instances of itself. It is used by AttributeMap to serialize
* and deserialize TextAttribute to preserve uniqueness of TextAttribute
* instances (ie so that TextAttribute instances remain singletons),
* and to provide compatability between 1.1 and 1.2 versions of
* TextAttribute.
* <p>
* Example use - instead of doing this:
* <blockquote><pre>
* out.writeObject(anAttribute);
* </pre></blockquote>
* do this:
* <blockquote><pre>
* out.writeObject(AttributeKey.mapAttributeToKey(anAttribute));
* </pre></blockquote>
* Similarly, instead of this:
* <blockquote><pre>
* anAttribute = in.readObject();
* </pre></blockquote>
* do this:
* <blockquote><pre>
* anAttribute = AttributeKey.mapKeyToAttribute(in.readObject());
* </pre></blockquote>
* <p>
* If anAttribute is not a known TextAttribute, then <code>mapAttributeToKey</code>
* will just return its argument. Similarly, <code>mapKeyToAttribute</code> will
* return its argument if the argument is not a known AttributeKey.
*/
/*public*/ final class AttributeKey implements Serializable {
/*
In this implementation, two parallel Vectors are
maintained. TextAttribute(i) maps to AttributeKey(i).
For compatability with existing data, this mapping must
be maintained in the future! So, when new attributes
are added, add them to the end of the list.
*/
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
private static final long serialVersionUID = 3772371253277107294L;
private static Object[] fgTextAttributes;
private static Object[] fgAttributeKeys;
static {
fgTextAttributes = new Object[] {
TextAttribute.FONT,
TextAttribute.FAMILY,
TextAttribute.WEIGHT,
TextAttribute.POSTURE,
TextAttribute.SIZE,
TextAttribute.SUPERSCRIPT,
TextAttribute.FOREGROUND,
TextAttribute.BACKGROUND,
TextAttribute.UNDERLINE,
TextAttribute.STRIKETHROUGH,
TextAttribute.CHAR_REPLACEMENT,
TextAttribute.EXTRA_LINE_SPACING,
TextAttribute.FIRST_LINE_INDENT,
TextAttribute.MIN_LINE_SPACING,
TextAttribute.LINE_FLUSH,
TextAttribute.LEADING_MARGIN,
TextAttribute.TRAILING_MARGIN,
TextAttribute.TAB_RULER,
TextAttribute.RUN_DIRECTION,
TextAttribute.BIDI_EMBEDDING,
TextAttribute.JUSTIFICATION,
};
final int attrCount = fgTextAttributes.length;
fgAttributeKeys = new Object[attrCount];
for (int i=0; i < attrCount; i += 1) {
fgAttributeKeys[i] = new AttributeKey(i);
}
}
/**
* Return the TextAttribute corresponding to the given key.
* If key is an instance of AttributeKey it will be mapped to
* a TextAttribute. Otherwise, the key is returned.
* @param key the key to map to a TextAttribute field
* @return the TextAttribute for <code>key</code> if <code>key</code>
* is an AttributeKey; otherwise <code>key</code> is returned
*/
/*public*/ static Object mapKeyToAttribute(Object key) {
try {
AttributeKey aKey = (AttributeKey) key;
if (aKey.fId < fgTextAttributes.length) {
return fgTextAttributes[aKey.fId];
}
else {
return key;
}
}
catch(ClassCastException e) {
return key;
}
}
/**
* If attribute is a known TextAttribute, return an AttributeKey
* for it. Otherwise the object is returned.
* @param attribute the attribute to map to an AttributeKey
* @return an AttributeKey for <code>attribute</code>
* if <code>attribute</code> is a known attribute; otherwise
* <code>attribute</code> is returned
*/
/*public*/ static Object mapAttributeToKey(Object attribute) {
final int attrCount = fgTextAttributes.length;
for (int index = 0; index < attrCount; index += 1) {
if (fgTextAttributes[index].equals(attribute)) {
return fgAttributeKeys[index];
}
}
return attribute;
}
private int fId;
private AttributeKey(int id) {
fId = id;
}
public boolean equals(Object rhs) {
try {
return ((AttributeKey)rhs).fId == fId;
}
catch(ClassCastException e) {
return false;
}
}
public int hashCode() {
return fId;
}
}

View file

@ -0,0 +1,51 @@
/*
* @(#)$RCSfile: Map.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:33:07 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
// Requires Java2
package com.ibm.textlayout.attributes;
/**
* A Map is a collection of key-value pairs (or entries), where each
* key in the Map is unique. This interface is a subset of the
* JDK 1.2 Map interface. It is used by JDK 1.1-compatible code.
*/
public interface Map {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
/**
* Return the number of entries in this Map.
* @return the number of entries in this Map
*/
public int size();
/**
* Return true if this Map has no entries.
* @return true if this Map has no entries
*/
public boolean isEmpty();
/**
* Return the value of the given key.
* @return the value of the given key. If the key does not have
* a value in this Map, null is returned.
*/
public Object get(Object key);
/**
* Return true if this Map contains the given key.
* @return true if this Map contains the given key
*/
public boolean containsKey(Object key);
}

View file

@ -0,0 +1,248 @@
/*
* @(#)$RCSfile: TextAttribute.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:33:07 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
// Requires Java2
package com.ibm.textlayout.attributes;
import java.util.Hashtable;
import java.text.AttributedCharacterIterator.Attribute;
import java.io.InvalidObjectException;
/**
* This class contains a number of keys (or attributes) for specifying text styles
* in a Map. A text style is a collection of key-value pairs, where
* the key represents a certain characteristic (such as size) and
* the value tells how that characteristic is realized (ie what the
* size is).
* <p>
* All of the attributes in TextAttribute specify a class for their value.
* Map does not enforce these class specifications; however, text rendering code
* will tend to fail with a ClassCastException if a key's value
* has an unexpected class.
* <p>
* Some attributes are meaningful for entire paragraphs, not individual
* characters. These attributes are documented as applying to paragraphs.
* All other attributes apply to characters.
* <p>
* Many of the field names and values in this class
* are taken from the JDK 1.2
* <code>java.awt.font.TextAttribute class</code>.
* @see Map
*/
public class TextAttribute extends Attribute {
private static final Hashtable instanceMap = new Hashtable(9);
protected TextAttribute(String name) {
super(name);
if (this.getClass() == TextAttribute.class) {
instanceMap.put(name, this);
}
}
protected Object readResolve() throws InvalidObjectException {
if (this.getClass() != TextAttribute.class) {
throw new InvalidObjectException("subclass didn't correctly implement readResolve");
}
TextAttribute instance = (TextAttribute) instanceMap.get(getName());
if (instance != null) {
return instance;
} else {
throw new InvalidObjectException("unknown attribute name");
};
}
public static final Object FONT = java.awt.font.TextAttribute.FONT;
public static final Object FAMILY = java.awt.font.TextAttribute.FAMILY;
public static final Object WEIGHT = java.awt.font.TextAttribute.WEIGHT;
public static final Float WEIGHT_BOLD = java.awt.font.TextAttribute.WEIGHT_BOLD;
public static final Object POSTURE = java.awt.font.TextAttribute.POSTURE;
public static final Float POSTURE_OBLIQUE = java.awt.font.TextAttribute.POSTURE_OBLIQUE;
public static final Object SIZE = java.awt.font.TextAttribute.SIZE;
public static final Object SUPERSCRIPT = java.awt.font.TextAttribute.SUPERSCRIPT;
public static final Integer SUPERSCRIPT_SUPER = java.awt.font.TextAttribute.SUPERSCRIPT_SUPER;
public static final Integer SUPERSCRIPT_SUB = java.awt.font.TextAttribute.SUPERSCRIPT_SUB;
/**
* Attribute key for the foreground and background color adornment.
*/
public static final Object FOREGROUND = java.awt.font.TextAttribute.FOREGROUND;
public static final Object BACKGROUND = java.awt.font.TextAttribute.BACKGROUND;
public static final Object UNDERLINE = java.awt.font.TextAttribute.UNDERLINE;
public static final Integer UNDERLINE_ON = java.awt.font.TextAttribute.UNDERLINE_ON;
public static final Object STRIKETHROUGH = java.awt.font.TextAttribute.STRIKETHROUGH;
public static final Boolean STRIKETHROUGH_ON = java.awt.font.TextAttribute.STRIKETHROUGH_ON;
public static final Object OFFSET = new TextAttribute("offset");
public static final Object CHAR_REPLACEMENT = java.awt.font.TextAttribute.CHAR_REPLACEMENT;
// Paragraph Styles
// values are Floats:
public static final Object EXTRA_LINE_SPACING = new TextAttribute("extra_line_spacing");
public static final Object EXTRA_FIRST_LINE_SPACING = new TextAttribute("extra_first_line_spacing");
/**
* Amount beyond leading margin to indent the first line of a paragraph.
*/
public static final Object FIRST_LINE_INDENT = new TextAttribute("first_line_indent");
public static final Object MIN_LINE_SPACING = new TextAttribute("min_line_spacing");
public static final Object MIN_FIRST_LINE_SPACING = new TextAttribute("min_first_line_spacing");
/**
* Flush lines left, right, or center.
*/
public static final Object LINE_FLUSH = new TextAttribute("line_flush");
public static final Integer FLUSH_LEADING = new Integer(0);
public static final Integer FLUSH_CENTER = new Integer(1);
public static final Integer FLUSH_TRAILING = new Integer(2);
/**
* Value of <code>LINE_FLUSH</code> for full justification.
*/
public static final Integer FULLY_JUSTIFIED = new Integer(3);
/**
* Leading and trailing margin in paragraph.
*/
public static final Object LEADING_MARGIN = new TextAttribute("leading_margin");
public static final Object TRAILING_MARGIN = new TextAttribute("trailing_margin");
/**
* Tab ruler. Values are MTabRuler instances.
*/
public static final Object TAB_RULER = new TextAttribute("tab_ruler");
/**
* Attribute key for the run direction of the line.
*
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
* <TD VALIGN="TOP">RUN_DIRECTION</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
* <TD VALIGN="TOP">Boolean</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
* <TD VALIGN="TOP">RUN_DIRECTION_LTR = true, RUN_DIRECTION_RTL = false
* </TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
* <TD VALIGN="TOP">Use the default Unicode base direction from the BIDI
* algorithm.</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
* <TD VALIGN="TOP"><P>Specifies which base run direction to use when
* positioning mixed directional runs within a paragraph. If this value is
* RUN_DIRECTION_DEFAULT, <code>TextLayout</code> uses the default Unicode
* base direction from the BIDI algorithm.</P>
* <P><I>This attribute should have the same value over the whole
* paragraph.</I></TD></TR>
* </TABLE>
*/
public static final Object RUN_DIRECTION = java.awt.font.TextAttribute.RUN_DIRECTION;
/**
* Left-to-right run direction.
* @see #RUN_DIRECTION
*/
public static final Boolean RUN_DIRECTION_LTR = java.awt.font.TextAttribute.RUN_DIRECTION_LTR;
/**
* Right-to-left run direction.
* @see #RUN_DIRECTION
*/
public static final Boolean RUN_DIRECTION_RTL = java.awt.font.TextAttribute.RUN_DIRECTION_RTL;
/**
* Attribute key for the embedding level for nested bidirectional runs.
*
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
* <TD VALIGN="TOP">BIDI_EMBEDDING</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
* <TD VALIGN="TOP">Integer</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
* <TD VALIGN="TOP">Positive values 1 through 15 are <I>embedding</I>
* levels, negative values<BR> through -15 are <I>override</I> levels
* </TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
* <TD VALIGN="TOP">Use standard BIDI to compute levels from formatting
* characters in the text.</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
* <TD VALIGN="TOP">Specifies the bidi embedding level of the character.
* When this attribute is present anywhere in a paragraph, then the
* Unicode characters RLO, LRO, RLE, LRE, PDF are disregarded in the BIDI
* analysis of that paragraph.
* See the Unicode Standard v. 2.0, section 3-11.
* </TD></TR>
* </TABLE>
*/
public static final Object BIDI_EMBEDDING = java.awt.font.TextAttribute.BIDI_EMBEDDING;
/**
* Attribute key for the justification of a paragraph.
*
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
* <TD VALIGN="TOP">JUSTIFICATION</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
* <TD VALIGN="TOP">Float</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
* <TD VALIGN="TOP">0.0 through1.0</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
* <TD VALIGN="TOP">1.0</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
* <TD VALIGN="TOP"><P>Specifies which fraction of the extra space to use
* when justification is requested. For example, if the line is 50 points
* wide and the margins are 70 points apart, a value of 0.5 means that the
* line is padded to reach a width of 60 points.</P>
* <P><I>This attribute should have the same value over the whole
* paragraph.</I></TD></TR>
* </TABLE>
*/
public static final Object JUSTIFICATION = java.awt.font.TextAttribute.JUSTIFICATION;
/**
* Justify the line to the full requested width.
* @see #JUSTIFICATION
*/
public static final Float JUSTIFICATION_FULL = java.awt.font.TextAttribute.JUSTIFICATION_FULL;
/**
* Do not allow the line to be justified.
* @see #JUSTIFICATION
*/
public static final Float JUSTIFICATION_NONE = java.awt.font.TextAttribute.JUSTIFICATION_NONE;
}

View file

@ -0,0 +1,29 @@
/*
* @(#)$RCSfile: FontUtils.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:30:44 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
// Requires Java2
package com.ibm.textlayout;
import java.awt.Font;
public final class FontUtils {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
public static Font getFont(java.util.Map attributes) {
return Font.getFont(attributes);
}
}

View file

@ -0,0 +1,56 @@
/*
* @(#)$RCSfile: Graphics2DConversion.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:30:44 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
// Requires Java2
package com.ibm.textlayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
/**
* This class allows JDK 1.1 code to use a "fake" Graphics2D
* for source-code compatibility with Java2 code. On Java2 it's
* a trivial class. The JDK 1.1 version of this class does interesting
* work.
*/
public final class Graphics2DConversion {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
public static Graphics2D getGraphics2D(Graphics g) {
return (Graphics2D) g;
}
public static Graphics getGraphics(Graphics2D g) {
return g;
}
/**
* Will return an instance of Paint.
*/
public static Object getColorState(Graphics2D g) {
return g.getPaint();
}
/**
* State must be an instance of Paint.
*/
public static void restoreColorState(Graphics2D g, Object state) {
g.setPaint((Paint) state);
}
}

View file

@ -0,0 +1,165 @@
/*
* @(#)$RCSfile: AttributeKey.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:33:07 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.textlayout.attributes;
import java.io.Serializable;
/**
* This class provides a cannonical mapping between fields in TextAttribute
* and instances of itself. It is used by AttributeMap to serialize
* and deserialize TextAttribute to preserve uniqueness of TextAttribute
* instances (ie so that TextAttribute instances remain singletons),
* and to provide compatability between 1.1 and 1.2 versions of
* TextAttribute.
* <p>
* Example use - instead of doing this:
* <blockquote><pre>
* out.writeObject(anAttribute);
* </pre></blockquote>
* do this:
* <blockquote><pre>
* out.writeObject(AttributeKey.mapAttributeToKey(anAttribute));
* </pre></blockquote>
* Similarly, instead of this:
* <blockquote><pre>
* anAttribute = in.readObject();
* </pre></blockquote>
* do this:
* <blockquote><pre>
* anAttribute = AttributeKey.mapKeyToAttribute(in.readObject());
* </pre></blockquote>
* <p>
* If anAttribute is not a known TextAttribute, then <code>mapAttributeToKey</code>
* will just return its argument. Similarly, <code>mapKeyToAttribute</code> will
* return its argument if the argument is not a known AttributeKey.
*/
/*public*/ final class AttributeKey implements Serializable {
/*
In this implementation, two parallel Vectors are
maintained. TextAttribute(i) maps to AttributeKey(i).
For compatability with existing data, this mapping must
be maintained in the future! So, when new attributes
are added, add them to the end of the list.
*/
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
private static final long serialVersionUID = 3772371253277107294L;
private static Object[] fgTextAttributes;
private static Object[] fgAttributeKeys;
static {
fgTextAttributes = new Object[] {
TextAttribute.FONT,
TextAttribute.FAMILY,
TextAttribute.WEIGHT,
TextAttribute.POSTURE,
TextAttribute.SIZE,
TextAttribute.SUPERSCRIPT,
TextAttribute.FOREGROUND,
TextAttribute.BACKGROUND,
TextAttribute.UNDERLINE,
TextAttribute.STRIKETHROUGH,
TextAttribute.CHAR_REPLACEMENT,
TextAttribute.EXTRA_LINE_SPACING,
TextAttribute.FIRST_LINE_INDENT,
TextAttribute.MIN_LINE_SPACING,
TextAttribute.LINE_FLUSH,
TextAttribute.LEADING_MARGIN,
TextAttribute.TRAILING_MARGIN,
TextAttribute.TAB_RULER,
TextAttribute.RUN_DIRECTION,
TextAttribute.BIDI_EMBEDDING,
TextAttribute.JUSTIFICATION,
};
final int attrCount = fgTextAttributes.length;
fgAttributeKeys = new Object[attrCount];
for (int i=0; i < attrCount; i += 1) {
fgAttributeKeys[i] = new AttributeKey(i);
}
}
/**
* Return the TextAttribute corresponding to the given key.
* If key is an instance of AttributeKey it will be mapped to
* a TextAttribute. Otherwise, the key is returned.
* @param key the key to map to a TextAttribute field
* @return the TextAttribute for <code>key</code> if <code>key</code>
* is an AttributeKey; otherwise <code>key</code> is returned
*/
/*public*/ static Object mapKeyToAttribute(Object key) {
try {
AttributeKey aKey = (AttributeKey) key;
if (aKey.fId < fgTextAttributes.length) {
return fgTextAttributes[aKey.fId];
}
else {
return key;
}
}
catch(ClassCastException e) {
return key;
}
}
/**
* If attribute is a known TextAttribute, return an AttributeKey
* for it. Otherwise the object is returned.
* @param attribute the attribute to map to an AttributeKey
* @return an AttributeKey for <code>attribute</code>
* if <code>attribute</code> is a known attribute; otherwise
* <code>attribute</code> is returned
*/
/*public*/ static Object mapAttributeToKey(Object attribute) {
final int attrCount = fgTextAttributes.length;
for (int index = 0; index < attrCount; index += 1) {
if (fgTextAttributes[index].equals(attribute)) {
return fgAttributeKeys[index];
}
}
return attribute;
}
private int fId;
private AttributeKey(int id) {
fId = id;
}
public boolean equals(Object rhs) {
try {
return ((AttributeKey)rhs).fId == fId;
}
catch(ClassCastException e) {
return false;
}
}
public int hashCode() {
return fId;
}
}

View file

@ -0,0 +1,51 @@
/*
* @(#)$RCSfile: Map.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:33:07 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
// Requires Java2
package com.ibm.textlayout.attributes;
/**
* A Map is a collection of key-value pairs (or entries), where each
* key in the Map is unique. This interface is a subset of the
* JDK 1.2 Map interface. It is used by JDK 1.1-compatible code.
*/
public interface Map {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
/**
* Return the number of entries in this Map.
* @return the number of entries in this Map
*/
public int size();
/**
* Return true if this Map has no entries.
* @return true if this Map has no entries
*/
public boolean isEmpty();
/**
* Return the value of the given key.
* @return the value of the given key. If the key does not have
* a value in this Map, null is returned.
*/
public Object get(Object key);
/**
* Return true if this Map contains the given key.
* @return true if this Map contains the given key
*/
public boolean containsKey(Object key);
}

View file

@ -0,0 +1,248 @@
/*
* @(#)$RCSfile: TextAttribute.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:33:07 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
// Requires Java2
package com.ibm.textlayout.attributes;
import java.util.Hashtable;
import java.text.AttributedCharacterIterator.Attribute;
import java.io.InvalidObjectException;
/**
* This class contains a number of keys (or attributes) for specifying text styles
* in a Map. A text style is a collection of key-value pairs, where
* the key represents a certain characteristic (such as size) and
* the value tells how that characteristic is realized (ie what the
* size is).
* <p>
* All of the attributes in TextAttribute specify a class for their value.
* Map does not enforce these class specifications; however, text rendering code
* will tend to fail with a ClassCastException if a key's value
* has an unexpected class.
* <p>
* Some attributes are meaningful for entire paragraphs, not individual
* characters. These attributes are documented as applying to paragraphs.
* All other attributes apply to characters.
* <p>
* Many of the field names and values in this class
* are taken from the JDK 1.2
* <code>java.awt.font.TextAttribute class</code>.
* @see Map
*/
public class TextAttribute extends Attribute {
private static final Hashtable instanceMap = new Hashtable(9);
protected TextAttribute(String name) {
super(name);
if (this.getClass() == TextAttribute.class) {
instanceMap.put(name, this);
}
}
protected Object readResolve() throws InvalidObjectException {
if (this.getClass() != TextAttribute.class) {
throw new InvalidObjectException("subclass didn't correctly implement readResolve");
}
TextAttribute instance = (TextAttribute) instanceMap.get(getName());
if (instance != null) {
return instance;
} else {
throw new InvalidObjectException("unknown attribute name");
};
}
public static final Object FONT = java.awt.font.TextAttribute.FONT;
public static final Object FAMILY = java.awt.font.TextAttribute.FAMILY;
public static final Object WEIGHT = java.awt.font.TextAttribute.WEIGHT;
public static final Float WEIGHT_BOLD = java.awt.font.TextAttribute.WEIGHT_BOLD;
public static final Object POSTURE = java.awt.font.TextAttribute.POSTURE;
public static final Float POSTURE_OBLIQUE = java.awt.font.TextAttribute.POSTURE_OBLIQUE;
public static final Object SIZE = java.awt.font.TextAttribute.SIZE;
public static final Object SUPERSCRIPT = java.awt.font.TextAttribute.SUPERSCRIPT;
public static final Integer SUPERSCRIPT_SUPER = java.awt.font.TextAttribute.SUPERSCRIPT_SUPER;
public static final Integer SUPERSCRIPT_SUB = java.awt.font.TextAttribute.SUPERSCRIPT_SUB;
/**
* Attribute key for the foreground and background color adornment.
*/
public static final Object FOREGROUND = java.awt.font.TextAttribute.FOREGROUND;
public static final Object BACKGROUND = java.awt.font.TextAttribute.BACKGROUND;
public static final Object UNDERLINE = java.awt.font.TextAttribute.UNDERLINE;
public static final Integer UNDERLINE_ON = java.awt.font.TextAttribute.UNDERLINE_ON;
public static final Object STRIKETHROUGH = java.awt.font.TextAttribute.STRIKETHROUGH;
public static final Boolean STRIKETHROUGH_ON = java.awt.font.TextAttribute.STRIKETHROUGH_ON;
public static final Object OFFSET = new TextAttribute("offset");
public static final Object CHAR_REPLACEMENT = java.awt.font.TextAttribute.CHAR_REPLACEMENT;
// Paragraph Styles
// values are Floats:
public static final Object EXTRA_LINE_SPACING = new TextAttribute("extra_line_spacing");
public static final Object EXTRA_FIRST_LINE_SPACING = new TextAttribute("extra_first_line_spacing");
/**
* Amount beyond leading margin to indent the first line of a paragraph.
*/
public static final Object FIRST_LINE_INDENT = new TextAttribute("first_line_indent");
public static final Object MIN_LINE_SPACING = new TextAttribute("min_line_spacing");
public static final Object MIN_FIRST_LINE_SPACING = new TextAttribute("min_first_line_spacing");
/**
* Flush lines left, right, or center.
*/
public static final Object LINE_FLUSH = new TextAttribute("line_flush");
public static final Integer FLUSH_LEADING = new Integer(0);
public static final Integer FLUSH_CENTER = new Integer(1);
public static final Integer FLUSH_TRAILING = new Integer(2);
/**
* Value of <code>LINE_FLUSH</code> for full justification.
*/
public static final Integer FULLY_JUSTIFIED = new Integer(3);
/**
* Leading and trailing margin in paragraph.
*/
public static final Object LEADING_MARGIN = new TextAttribute("leading_margin");
public static final Object TRAILING_MARGIN = new TextAttribute("trailing_margin");
/**
* Tab ruler. Values are MTabRuler instances.
*/
public static final Object TAB_RULER = new TextAttribute("tab_ruler");
/**
* Attribute key for the run direction of the line.
*
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
* <TD VALIGN="TOP">RUN_DIRECTION</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
* <TD VALIGN="TOP">Boolean</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
* <TD VALIGN="TOP">RUN_DIRECTION_LTR = true, RUN_DIRECTION_RTL = false
* </TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
* <TD VALIGN="TOP">Use the default Unicode base direction from the BIDI
* algorithm.</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
* <TD VALIGN="TOP"><P>Specifies which base run direction to use when
* positioning mixed directional runs within a paragraph. If this value is
* RUN_DIRECTION_DEFAULT, <code>TextLayout</code> uses the default Unicode
* base direction from the BIDI algorithm.</P>
* <P><I>This attribute should have the same value over the whole
* paragraph.</I></TD></TR>
* </TABLE>
*/
public static final Object RUN_DIRECTION = java.awt.font.TextAttribute.RUN_DIRECTION;
/**
* Left-to-right run direction.
* @see #RUN_DIRECTION
*/
public static final Boolean RUN_DIRECTION_LTR = java.awt.font.TextAttribute.RUN_DIRECTION_LTR;
/**
* Right-to-left run direction.
* @see #RUN_DIRECTION
*/
public static final Boolean RUN_DIRECTION_RTL = java.awt.font.TextAttribute.RUN_DIRECTION_RTL;
/**
* Attribute key for the embedding level for nested bidirectional runs.
*
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
* <TD VALIGN="TOP">BIDI_EMBEDDING</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
* <TD VALIGN="TOP">Integer</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
* <TD VALIGN="TOP">Positive values 1 through 15 are <I>embedding</I>
* levels, negative values<BR> through -15 are <I>override</I> levels
* </TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
* <TD VALIGN="TOP">Use standard BIDI to compute levels from formatting
* characters in the text.</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
* <TD VALIGN="TOP">Specifies the bidi embedding level of the character.
* When this attribute is present anywhere in a paragraph, then the
* Unicode characters RLO, LRO, RLE, LRE, PDF are disregarded in the BIDI
* analysis of that paragraph.
* See the Unicode Standard v. 2.0, section 3-11.
* </TD></TR>
* </TABLE>
*/
public static final Object BIDI_EMBEDDING = java.awt.font.TextAttribute.BIDI_EMBEDDING;
/**
* Attribute key for the justification of a paragraph.
*
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
* <TD VALIGN="TOP">JUSTIFICATION</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
* <TD VALIGN="TOP">Float</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
* <TD VALIGN="TOP">0.0 through1.0</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
* <TD VALIGN="TOP">1.0</TD></TR>
* <TR>
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
* <TD VALIGN="TOP"><P>Specifies which fraction of the extra space to use
* when justification is requested. For example, if the line is 50 points
* wide and the margins are 70 points apart, a value of 0.5 means that the
* line is padded to reach a width of 60 points.</P>
* <P><I>This attribute should have the same value over the whole
* paragraph.</I></TD></TR>
* </TABLE>
*/
public static final Object JUSTIFICATION = java.awt.font.TextAttribute.JUSTIFICATION;
/**
* Justify the line to the full requested width.
* @see #JUSTIFICATION
*/
public static final Float JUSTIFICATION_FULL = java.awt.font.TextAttribute.JUSTIFICATION_FULL;
/**
* Do not allow the line to be justified.
* @see #JUSTIFICATION
*/
public static final Float JUSTIFICATION_NONE = java.awt.font.TextAttribute.JUSTIFICATION_NONE;
}