JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util.swing
Class JCSwingTypeConverter

java.lang.Object
  |
  +--com.klg.jclass.util.swing.JCSwingTypeConverter

public class JCSwingTypeConverter
extends Object

JCSwingTypeConverter contains static methods for converting to/from AWT and Swing data types.


Field Summary
static String[] horizontalAlignmentStrings
           
static int[] horizontalAlignmentValues
           
static String[] justificationStrings
           
static int[] justificationValues
           
static Color lightBlue
          The color light blue.
static String[] positionStrings
           
static int[] positionValues
           
static String[] verticalAlignmentStrings
           
static int[] verticalAlignmentValues
           
 
Constructor Summary
JCSwingTypeConverter()
           
 
Method Summary
static String fromBorder(Border border, Component comp)
          Returns border in format "name|param|param".
static String fromColor(Color c)
          Converts color to one of the Color enums, or format "r-g-b" .
static String fromColorList(Color[] list)
          Converts list to a comma-separated list of tokens.
static String fromFont(Font f)
          Returns font in format "name-style-size".
static String fromInsets(Insets insets)
          Creates a String from an awt Insets value.
static String fromInsetsToIntList(Insets insets)
          Converts an Insets object to a code String list of integers.
static String fromInsetsToIntList(Insets insets, String separator)
          Converts an Insets object to a code String list of integers.
static float getHorizontalAWTFromSwingConstant(int swingValue, float defaultValue, boolean isLeftToRight)
          Spits out an AWT alignment float from the equivalent SwingConstant enum.
static int getHorizontalSwingConstantFromAWT(float componentAlignment, int defaultValue)
          Takes in an AWT alignment float, and spits out the equivalent SwingConstant enum.
static Color getMatteBorderColor(MatteBorder matte, Component comp)
          As of JDK 1.3, MatteBorder has a getMatteColor() method.
static float getVerticalAWTFromSwingConstant(int swingValue, float defaultValue)
          Spits out an AWT alignment float from the equivalent SwingConstant enum.
static int getVerticalSwingConstantFromAWT(float componentAlignment, int defaultValue)
          Takes in an AWT alignment float, and spits out the equivalent SwingConstant enum.
static Border toBorder(String s)
          Converts a border name in format "name|param|param|etc."; for example, "empty|10|10|10|10"
static Color toColor(String s)
          Converts a String to a Color.
static Color toColor(String s, Color def)
          Converts a String to a Color.
static Color[] toColorList(String s)
          Converts a String to an array of Colors.
static Color[] toColorList(String s, Color[] def)
          Converts a String to an array of Colors.
static Dimension toDimension(String s, Dimension def)
          Converts a String to a Dimension instance.
static Font toFont(String s)
          Converts a font name in format "name-style-size", e.g.
static Font toFont(String s, Font def)
          Converts a font name to a Font instance.
static Insets toInsets(String s, Insets def)
          Converts a String to an Insets instance.
static Point toPoint(String s, Point def)
          Converts a String to a Point instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lightBlue

public static final Color lightBlue
The color light blue.


positionValues

public static final int[] positionValues

positionStrings

public static final String[] positionStrings

justificationValues

public static final int[] justificationValues

justificationStrings

public static final String[] justificationStrings

horizontalAlignmentValues

public static final int[] horizontalAlignmentValues

horizontalAlignmentStrings

public static final String[] horizontalAlignmentStrings

verticalAlignmentValues

public static final int[] verticalAlignmentValues

verticalAlignmentStrings

public static final String[] verticalAlignmentStrings
Constructor Detail

JCSwingTypeConverter

public JCSwingTypeConverter()
Method Detail

toColorList

public static Color[] toColorList(String s,
                                  Color[] def)
Converts a String to an array of Colors.

Parameters:
s - the String containing color names separated by commas
def - the default value, returned if a parse error occurs
Returns:
the newly created color list

toColorList

public static Color[] toColorList(String s)
Converts a String to an array of Colors.

Parameters:
s - the comma-separated color names
Returns:
the newly created color list

toColor

public static Color toColor(String s,
                            Color def)
Converts a String to a Color.

Parameters:
s - the String containing a color name
def - the default value, returned if a parse error occurs
Returns:
the newly created Color

toColor

public static Color toColor(String s)
Converts a String to a Color.

Parameters:
s - a color enum ("black", "pink", etc.); hex value in format "#RRGGBB", "#RRRRGGGGBBBB" or "#N"; or rgb values in format "r-g-b"
Returns:
the newly created Color

fromColorList

public static String fromColorList(Color[] list)
Converts list to a comma-separated list of tokens.

Parameters:
list - the list of colors to be converted to a string
Returns:
the String containing a list of comma separated colors
See Also:
fromColor(java.awt.Color)

fromColor

public static String fromColor(Color c)
Converts color to one of the Color enums, or format "r-g-b" .

Parameters:
c - the color to be converted
Returns:
a String representation of the passed in color

toFont

public static Font toFont(String s,
                          Font def)
Converts a font name to a Font instance.

Parameters:
s - the String containing font name
def - the default value, returned if a parse error occurs
Returns:
the font based on the inputted font name

toFont

public static Font toFont(String s)
Converts a font name in format "name-style-size", e.g. "Helvetica-plain-10"

Parameters:
s - the String representation of the Font
Returns:
the font based on the inputted font name (returns null on error)

fromFont

public static String fromFont(Font f)
Returns font in format "name-style-size".

Parameters:
f - the font to be converted to a String
Returns:
a String representation of the font

toInsets

public static Insets toInsets(String s,
                              Insets def)
Converts a String to an Insets instance.

Parameters:
s - the String containing the top, left, bottom, and right values, separated by commas
def - the default value, returned if the String could not be converted
Returns:
the Insets object created from the String

fromInsets

public static String fromInsets(Insets insets)
Creates a String from an awt Insets value.

Parameters:
insets - the InsetsReturns:
the String representation of the Insets object passed in

toDimension

public static Dimension toDimension(String s,
                                    Dimension def)
Converts a String to a Dimension instance.

Parameters:
s - the String in the format [width]x[height]
def - the default value, returned if the String could not be converted
Returns:
the Dimension object created from the String

toPoint

public static Point toPoint(String s,
                            Point def)
Converts a String to a Point instance.

Parameters:
s - the String in the format [x],[y]
def - the default value, returned if the String could not be converted
Returns:
the Point object created from the String

fromInsetsToIntList

public static String fromInsetsToIntList(Insets insets)
Converts an Insets object to a code String list of integers.

Parameters:
insets - an Insets object
Returns:
a code generation String consisting of a series of comma separated integers

fromInsetsToIntList

public static String fromInsetsToIntList(Insets insets,
                                         String separator)
Converts an Insets object to a code String list of integers.

Parameters:
insets - an Insets object
separator - the separator used between each number
Returns:
a code generation String consisting of a series of comma separated integers

toBorder

public static Border toBorder(String s)
Converts a border name in format "name|param|param|etc."; for example, "empty|10|10|10|10"

Parameters:
s - the String to convert to a Border object
Returns:
the border object created from the String

fromBorder

public static String fromBorder(Border border,
                                Component comp)
Returns border in format "name|param|param".

Parameters:
border - the border object to convert
comp - the component to get default values from (for example: insets, colors)
Returns:
the String representation of the passed in Border object

getMatteBorderColor

public static Color getMatteBorderColor(MatteBorder matte,
                                        Component comp)
As of JDK 1.3, MatteBorder has a getMatteColor() method. See if its there and invoke if it is. Otherwise, return the component's background color.

Parameters:
matte - the MatteBorder from which the color is needed
comp - the component which holds the border
Returns:
the MatteBorder's color

getVerticalSwingConstantFromAWT

public static int getVerticalSwingConstantFromAWT(float componentAlignment,
                                                  int defaultValue)
Takes in an AWT alignment float, and spits out the equivalent SwingConstant enum.

Parameters:
componentAlignment -
defaultValue - the value to return if the value is not found.
Returns:
the matching SwingConstant.

getHorizontalSwingConstantFromAWT

public static int getHorizontalSwingConstantFromAWT(float componentAlignment,
                                                    int defaultValue)
Takes in an AWT alignment float, and spits out the equivalent SwingConstant enum.

Parameters:
componentAlignment -
defaultValue - the value to return if the value is not found.
Returns:
the matching SwingConstant.

getVerticalAWTFromSwingConstant

public static float getVerticalAWTFromSwingConstant(int swingValue,
                                                    float defaultValue)
Spits out an AWT alignment float from the equivalent SwingConstant enum.

Parameters:
swingValue -
defaultValue - the value to return if the value is not found.
Returns:
the matching Component alignment constant.

getHorizontalAWTFromSwingConstant

public static float getHorizontalAWTFromSwingConstant(int swingValue,
                                                      float defaultValue,
                                                      boolean isLeftToRight)
Spits out an AWT alignment float from the equivalent SwingConstant enum.

Parameters:
swingValue -
defaultValue - the value to return if the value is not found.
isLeftToRight - determines whether trailing and leading are right or left respectively (Can be determinded by calling Component.getComponentOrientation.isLeftToRight();
Returns:
the matching Component alignment constant.

Copyright © 2004 Quest Software Inc..
All rights reserved.