home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
jfc.bin
/
StyleConstants.java
< prev
next >
Wrap
Text File
|
1998-02-26
|
22KB
|
842 lines
/*
* @(#)StyleConstants.java 1.12 98/01/13
*
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
package com.sun.java.swing.text;
import java.awt.Color;
import java.awt.Component;
import com.sun.java.swing.Icon;
/**
* <p>
* A collection of <em>well known</em> or common attribute keys
* and methods to apply to an AttributeSet or MutableAttributeSet
* to get/set the properties in a typesafe manner.
* <p>
* The paragraph attributes form the definition of a paragraph to be rendered.
* All sizes are specified in points (such as found in postscript), a
* device independent measure.
* </p>
* <p align=center><img src="images/paragraph.gif"></p>
* <p>
*
* @author Timothy Prinzing
* @version 1.12 01/13/98
*/
public class StyleConstants {
/**
* Name of elements used to represent components.
*/
public static final String ComponentElementName = "component";
/**
* Name of elements used to represent icons.
*/
public static final String IconElementName = "icon";
/**
* Attribute name used to name the collection of
* attributes.
*/
public static final Object NameAttribute = new StyleConstants("name");
/**
* Attribute name used to identifiy the resolving parent
* set of attributes, if one is defined.
*/
public static final Object ResolveAttribute = new StyleConstants("resolver");
public String toString() {
return representation;
}
// ---- character constants -----------------------------------
/**
* Name of the font family.
*/
public static final Object FontFamily = CharacterConstants.Family;
/**
* Name of the font size.
*/
public static final Object FontSize = CharacterConstants.Size;
/**
* Name of the bold attribute.
*/
public static final Object Bold = CharacterConstants.Bold;
/**
* Name of the italic attribute.
*/
public static final Object Italic = CharacterConstants.Italic;
/**
* Name of the underline attribute.
*/
public static final Object Underline = CharacterConstants.Underline;
/**
* Name of the foreground color attribute.
*/
public static final Object Foreground = CharacterConstants.Foreground;
/**
* Name of the background color attribute.
*/
public static final Object Background = CharacterConstants.Background;
/**
* Name of the component attribute.
*/
public static final Object ComponentAttribute = CharacterConstants.ComponentAttribute;
/**
* Name of the icon attribute.
*/
public static final Object IconAttribute = CharacterConstants.IconAttribute;
/**
* The amount of space to indent the first
* line of the paragraph. This value may be negative
* to offset in the reverse direction. The type
* is Float and specifies the size of the space
* in points.
*/
public static final Object FirstLineIndent = ParagraphConstants.FirstLineIndent;
/**
* The amount to indent the left side
* of the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object LeftIndent = ParagraphConstants.LeftIndent;
/**
* The amount to indent the right side
* of the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object RightIndent = ParagraphConstants.RightIndent;
/**
* The amount of space between lines
* of the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object LineSpacing = ParagraphConstants.LineSpacing;
/**
* The amount of space above the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object SpaceAbove = ParagraphConstants.SpaceAbove;
/**
* The amount of space below the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object SpaceBelow = ParagraphConstants.SpaceBelow;
/**
* Alignment for the paragraph. The type is
* Integer. Valid values are:
* <ul>
* <li>ALIGN_LEFT
* <li>ALIGN_RIGHT
* <li>ALIGN_CENTER
* <li>ALIGN_JUSTIFED
* </ul>
*
*/
public static final Object Alignment = ParagraphConstants.Alignment;
/**
* TabSet for the paragraph, type is a TabSet containing
* TabStops.
*/
public static final Object TabSet = ParagraphConstants.TabSet;
/**
* A possible value for paragraph alignment. This
* specifies that the text aligned to the left
* indent and extra whitespace should be placed on
* the right.
*/
public static final int ALIGN_LEFT = 0;
/**
* A possible value for paragraph alignment. This
* specifies that the text aligned to the center
* and extra whitespace should be placed equally on
* the left and right.
*/
public static final int ALIGN_CENTER = 1;
/**
* A possible value for paragraph alignment. This
* specifies that the text aligned to the right
* indent and extra whitespace should be placed on
* the left.
*/
public static final int ALIGN_RIGHT = 2;
/**
* A possible value for paragraph alignment. This
* specifies that extra whitespace should be spread
* out through the rows of the paragraph with the
* text lined up with the left and right indent
* except on the last line which should be aligned
* to the left.
*/
public static final int ALIGN_JUSTIFIED = 3;
// --- character attribute accessors ---------------------------
/**
* Gets the component setting from the attribute list.
*
* @param a the attribute set
* @return the component
*/
public static Component getComponent(AttributeSet a) {
return (Component) a.getAttribute(ComponentAttribute);
}
/**
* Sets the component attribute.
*
* @param a the attribute set
* @param c the component
*/
public static void setComponent(MutableAttributeSet a, Component c) {
a.addAttribute(AbstractDocument.ElementNameAttribute, ComponentElementName);
a.addAttribute(ComponentAttribute, c);
}
/**
* Gets the icon setting from the attribute list.
*
* @param a the attribute set
* @return the icon
*/
public static Icon getIcon(AttributeSet a) {
return (Icon) a.getAttribute(IconAttribute);
}
/**
* Sets the icon attribute.
*
* @param a the attribute set
* @param c the icon
*/
public static void setIcon(MutableAttributeSet a, Icon c) {
a.addAttribute(AbstractDocument.ElementNameAttribute, IconElementName);
a.addAttribute(IconAttribute, c);
}
/**
* Gets the font family setting from the attribute list.
*
* @param a the attribute set
* @return the font family
*/
public static String getFontFamily(AttributeSet a) {
String family = (String) a.getAttribute(FontFamily);
if (family == null) {
family = "Courier";
}
return family;
}
/**
* Sets the font attribute.
*
* @param a the attribute set
* @param fam the font
*/
public static void setFontFamily(MutableAttributeSet a, String fam) {
a.addAttribute(FontFamily, fam);
}
/**
* Gets the font size setting from the attribute list.
*
* @param a the attribute set
* @return the font size
*/
public static int getFontSize(AttributeSet a) {
Integer size = (Integer) a.getAttribute(FontSize);
if (size != null) {
return size.intValue();
}
return 12;
}
/**
* Sets the font size attribute.
*
* @param a the attribute set
* @param s the font size
*/
public static void setFontSize(MutableAttributeSet a, int s) {
a.addAttribute(FontSize, new Integer(s));
}
/**
* Checks whether the bold attribute is set.
*
* @param a the attribute set
* @return true if set else false
*/
public static boolean isBold(AttributeSet a) {
Boolean bold = (Boolean) a.getAttribute(Bold);
if (bold != null) {
return bold.booleanValue();
}
return false;
}
/**
* Sets the bold attribute.
*
* @param a the attribute set
* @param b specifies true/false for setting the attribute
*/
public static void setBold(MutableAttributeSet a, boolean b) {
a.addAttribute(Bold, new Boolean(b));
}
/**
* Checks whether the italic attribute is set.
*
* @param a the attribute set
* @return true if set else false
*/
public static boolean isItalic(AttributeSet a) {
Boolean italic = (Boolean) a.getAttribute(Italic);
if (italic != null) {
return italic.booleanValue();
}
return false;
}
/**
* Sets the italic attribute.
*
* @param a the attribute set
* @param b specifies true/false for setting the attribute
*/
public static void setItalic(MutableAttributeSet a, boolean b) {
a.addAttribute(Italic, new Boolean(b));
}
/**
* Checks whether the underline attribute is set.
*
* @param a the attribute set
* @return true if set else false
*/
public static boolean isUnderline(AttributeSet a) {
Boolean underline = (Boolean) a.getAttribute(Underline);
if (underline != null) {
return underline.booleanValue();
}
return false;
}
/**
* Sets the underline attribute.
*
* @param a the attribute set
* @param b specifies true/false for setting the attribute
*/
public static void setUnderline(MutableAttributeSet a, boolean b) {
a.addAttribute(Underline, new Boolean(b));
}
/**
* Gets the foreground color setting from the attribute list.
*
* @param a the attribute set
* @return the color
*/
public static Color getForeground(AttributeSet a) {
Color fg = (Color) a.getAttribute(Foreground);
if (fg == null) {
fg = Color.black;
}
return fg;
}
/**
* Sets the foreground color.
*
* @param a the attribute set
* @param fg the color
*/
public static void setForeground(MutableAttributeSet a, Color fg) {
a.addAttribute(Foreground, fg);
}
// --- paragraph attribute accessors ----------------------------
/**
* Gets the first line indent setting.
*
* @param a the attribute set
* @returns the value
*/
public static float getFirstLineIndent(AttributeSet a) {
Float indent = (Float) a.getAttribute(FirstLineIndent);
if (indent != null) {
return indent.floatValue();
}
return 0;
}
/**
* Sets the first line indent.
*
* @param a the attribute set
* @param i the value
*/
public static void setFirstLineIndent(MutableAttributeSet a, float i) {
a.addAttribute(FirstLineIndent, new Float(i));
}
/**
* Gets the right indent setting.
*
* @param a the attribute set
* @returns the value
*/
public static float getRightIndent(AttributeSet a) {
Float indent = (Float) a.getAttribute(RightIndent);
if (indent != null) {
return indent.floatValue();
}
return 0;
}
/**
* Sets right indent.
*
* @param a the attribute set
* @param i the value
*/
public static void setRightIndent(MutableAttributeSet a, float i) {
a.addAttribute(RightIndent, new Float(i));
}
/**
* Gets the left indent setting.
*
* @param a the attribute set
* @returns the value
*/
public static float getLeftIndent(AttributeSet a) {
Float indent = (Float) a.getAttribute(LeftIndent);
if (indent != null) {
return indent.floatValue();
}
return 0;
}
/**
* Sets left indent.
*
* @param a the attribute set
* @param i the value
*/
public static void setLeftIndent(MutableAttributeSet a, float i) {
a.addAttribute(LeftIndent, new Float(i));
}
/**
* Gets the line spacing setting.
*
* @param a the attribute set
* @returns the value
*/
public static float getLineSpacing(AttributeSet a) {
Float space = (Float) a.getAttribute(LineSpacing);
if (space != null) {
return space.floatValue();
}
return 0;
}
/**
* Sets line spacing.
*
* @param a the attribute set
* @param i the value
*/
public static void setLineSpacing(MutableAttributeSet a, float i) {
a.addAttribute(LineSpacing, new Float(i));
}
/**
* Gets the space above setting.
*
* @param a the attribute set
* @returns the value
*/
public static float getSpaceAbove(AttributeSet a) {
Float space = (Float) a.getAttribute(SpaceAbove);
if (space != null) {
return space.floatValue();
}
return 0;
}
/**
* Sets space above.
*
* @param a the attribute set
* @param i the value
*/
public static void setSpaceAbove(MutableAttributeSet a, float i) {
a.addAttribute(SpaceAbove, new Float(i));
}
/**
* Gets the space below setting.
*
* @param a the attribute set
* @returns the value
*/
public static float getSpaceBelow(AttributeSet a) {
Float space = (Float) a.getAttribute(SpaceBelow);
if (space != null) {
return space.floatValue();
}
return 0;
}
/**
* Sets space below.
*
* @param a the attribute set
* @param i the value
*/
public static void setSpaceBelow(MutableAttributeSet a, float i) {
a.addAttribute(SpaceBelow, new Float(i));
}
/**
* Gets the alignment setting.
*
* @param a the attribute set
* @returns the value
*/
public static int getAlignment(AttributeSet a) {
Integer align = (Integer) a.getAttribute(Alignment);
if (align != null) {
return align.intValue();
}
return ALIGN_LEFT;
}
/**
* Sets alignment.
*
* @param a the attribute set
* @param align the alignment value
*/
public static void setAlignment(MutableAttributeSet a, int align) {
a.addAttribute(Alignment, new Integer(align));
}
/**
* Gets the TabSet.
*
* @param a the attribute set
* @returns the TabSet.
*/
public static TabSet getTabSet(AttributeSet a) {
TabSet tabs = (TabSet)a.getAttribute(TabSet);
// PENDING: should this return a default?
return tabs;
}
/**
* Sets the TabSet.
*
* @param a the attribute set.
* @param tabs the TabSet
*/
public static void setTabSet(MutableAttributeSet a, TabSet tabs) {
a.addAttribute(TabSet, tabs);
}
// --- privates ---------------------------------------------
private static Object[] keys = {
NameAttribute, ResolveAttribute,
FontFamily, FontSize, Bold, Italic, Underline,
Foreground, Background, ComponentAttribute,
IconAttribute, FirstLineIndent, LeftIndent,
RightIndent, LineSpacing, SpaceAbove, SpaceBelow,
Alignment, TabSet
};
static {
try {
for (int i = 0; i < keys.length; i++) {
StyleContext.registerStaticAttributeKey(keys[i]);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
private StyleConstants(String representation) {
this.representation = representation;
}
private String representation;
/**
* This is a typesafe enumeration of the <em>well-known</em>
* attributes that contribute to a paragraph style. These are
* aliased by the outer class for general presentation.
*/
public static class ParagraphConstants implements AttributeSet.ParagraphAttribute {
/**
* The amount of space to indent the first
* line of the paragraph. This value may be negative
* to offset in the reverse direction. The type
* is Float and specifies the size of the space
* in points.
*/
public static final Object FirstLineIndent = new ParagraphConstants("FirstLineIndent");
/**
* The amount to indent the left side
* of the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object LeftIndent = new ParagraphConstants("LeftIndent");
/**
* The amount to indent the right side
* of the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object RightIndent = new ParagraphConstants("RightIndent");
/**
* The amount of space between lines
* of the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object LineSpacing = new ParagraphConstants("LineSpacing");
/**
* The amount of space above the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object SpaceAbove = new ParagraphConstants("SpaceAbove");
/**
* The amount of space below the paragraph.
* Type is float and specifies the size in points.
*/
public static final Object SpaceBelow = new ParagraphConstants("SpaceBelow");
/**
* Alignment for the paragraph. The type is
* Integer. Valid values are:
* <ul>
* <li>ALIGN_LEFT
* <li>ALIGN_RIGHT
* <li>ALIGN_CENTER
* <li>ALIGN_JUSTIFED
* </ul>
*
*/
public static final Object Alignment = new ParagraphConstants("Alignment");
/**
* TabSet for the paragraph.
*/
public static final Object TabSet = new ParagraphConstants("TabSet");
public String toString() {
return representation;
}
// --- privates ---------------------------------------------
private ParagraphConstants(String representation) {
this.representation = representation;
}
private String representation;
}
/**
* This is a typesafe enumeration of the <em>well-known</em>
* attributes that contribute to a character style. These are
* aliased by the outer class for general presentation.
*/
public static class CharacterConstants implements AttributeSet.CharacterAttribute {
/**
* Name of the underline attribute.
*/
public static final Object Underline = new CharacterConstants("underline");
/**
* Name of the component attribute.
*/
public static final Object ComponentAttribute = new CharacterConstants("component");
/**
* Name of the icon attribute.
*/
public static final Object IconAttribute = new CharacterConstants("icon");
/**
* Name of the font family.
*/
public static final Object Family = FontConstants.Family;
/**
* Name of the font size.
*/
public static final Object Size = FontConstants.Size;
/**
* Name of the bold attribute.
*/
public static final Object Bold = FontConstants.Bold;
/**
* Name of the italic attribute.
*/
public static final Object Italic = FontConstants.Italic;
/**
* Name of the foreground color attribute.
*/
public static final Object Foreground = ColorConstants.Foreground;
/**
* Name of the background color attribute.
*/
public static final Object Background = ColorConstants.Background;
public String toString() {
return representation;
}
// --- privates ---------------------------------------------
private CharacterConstants(String representation) {
this.representation = representation;
}
private String representation;
}
/**
* This is a typesafe enumeration of the <em>well-known</em>
* attributes that contribute to a color. These are aliased
* by the outer class for general presentation.
*/
public static class ColorConstants implements
AttributeSet.ColorAttribute, AttributeSet.CharacterAttribute {
/**
* Name of the foreground color attribute.
*/
public static final Object Foreground = new ColorConstants("foreground");
/**
* Name of the background color attribute.
*/
public static final Object Background = new ColorConstants("background");
public String toString() {
return representation;
}
// --- privates ---------------------------------------------
private ColorConstants(String representation) {
this.representation = representation;
}
private String representation;
}
/**
* This is a typesafe enumeration of the <em>well-known</em>
* attributes that contribute to a font. These are aliased
* by the outer class for general presentation.
*/
public static class FontConstants implements
AttributeSet.FontAttribute, AttributeSet.CharacterAttribute {
/**
* Name of the font family.
*/
public static final Object Family = new FontConstants("family");
/**
* Name of the font size.
*/
public static final Object Size = new FontConstants("size");
/**
* Name of the bold attribute.
*/
public static final Object Bold = new FontConstants("bold");
/**
* Name of the italic attribute.
*/
public static final Object Italic = new FontConstants("italic");
public String toString() {
return representation;
}
// --- privates ---------------------------------------------
private FontConstants(String representation) {
this.representation = representation;
}
private String representation;
}
}