com.isti.util.gui
Class GuiUtilFns

java.lang.Object
  extended by com.isti.util.gui.GuiUtilFns

public class GuiUtilFns
extends java.lang.Object

Class GuiUtilFns defines a set of various static utility methods for use in GUI applications.


Field Summary
static int DEF_PAD_WIDTH
          The default pad width for components that sometimes require it, such as 'JComboBox'.
static char defaultWidthChar
          The default width character, m.
 
Method Summary
static void ensureRowVisible(javax.swing.JTable tableObj, int row)
          Ensures that the specified table row is visible.
static void ensureSelectionVisible(javax.swing.JTable tableObj)
          Ensures that the current table selection is visible.
static int getExtendedFrameState(java.awt.Frame frameObj)
          Returns the "extended" state of the given frame.
static int getFrameMaximizedBothValue()
          Returns the value of Frame.MAXIMIZED_BOTH.
static int getMaxCharWidth(java.awt.Component compObj)
          Returns the maximum width, in pixels, of the default width character.
static int getMaxCharWidth(java.awt.Component compObj, char widthChar)
          Returns the maximum width, in pixels, of the specified width character.
static int getMaxCharWidth(java.awt.Component compObj, java.lang.String specialChars, boolean allowedFlag)
          Returns the maximum width, in pixels, of an allowed character.
static int getMaxCharWidth(java.awt.Component compObj, com.isti.util.gui.textvalidator.TextValidator tv)
          Returns the maximum width, in pixels, of an allowed character.
static IstiNamedValue getMaxCharWidthValue(java.awt.Component compObj, java.lang.String specialChars, boolean allowedFlag)
          Returns the maximum width, in pixels, of an allowed character.
static java.awt.Rectangle getMaximumWindowBounds()
          Returns the maximum bounds for centered windows.
static java.lang.String getSpacerStrForWidth(int widthVal, java.awt.Component compObj)
          Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width, using the given component.
static java.lang.String getSpacerStrForWidth(int widthVal, java.awt.Component compObj, java.awt.Font fontObj)
          Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width, using the given component and font.
static java.lang.String getSpacerStrForWidth(int widthVal, java.awt.Component compObj, java.awt.Font fontObj, int defWidthVal)
          Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width, using the given component and font.
static java.lang.String getSpacerStrForWidth(int widthVal, java.awt.Component compObj, int defWidthVal)
          Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width, using the given component.
static java.lang.String getSpacerStrForWidth(int widthVal, int spaceCharSize)
          Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width.
static int getStringWidth(java.awt.Component compObj, java.awt.Font fontObj, java.lang.String str)
          Returns the width, in pixels, of the given string.
static int getStringWidth(java.awt.Component compObj, java.awt.Font fontObj, java.lang.String str, int defWidthVal)
          Returns the width, in pixels, of the given string.
static int getStringWidth(java.awt.Component compObj, java.lang.String str)
          Returns the width, in pixels, of the given string.
static int getStringWidth(java.awt.Component compObj, java.lang.String str, int defWidthVal)
          Returns the width, in pixels, of the given string.
static int getStringWidth(java.awt.Font fontObj, java.lang.String str)
          Returns the width, in pixels, of the given string.
static int getStringWidth(java.awt.Font fontObj, java.lang.String str, int defWidthVal)
          Returns the width, in pixels, of the given string.
static int getStringWidth(java.lang.String str)
          Returns the width, in pixels, of the given string.
static int getStringWidth(java.lang.String str, int defWidthVal)
          Returns the width, in pixels, of the given string.
static void initColumnSizes(javax.swing.JTable tableObj)
           
static boolean isFrameMaximized(java.awt.Frame frameObj)
          Determines if the given frame is maximized (both horizontally and vertically).
static boolean maximizeFrame(java.awt.Frame frameObj)
          Sets the state of the given frame to "maximized" (both horizontally and vertically).
static void setButtonsContentAreaFilled(java.awt.Container contObj, boolean flgVal)
          Calls the 'setContentAreaFilled()' method on all button objects held by the given container or any subcontainers of it.
static void setEmptyJListWidth(javax.swing.JList listObj, int widthVal)
          Sets the fixed cell width that the given 'JList' is to have when its contents are empty.
static boolean setExtendedFrameState(java.awt.Frame frameObj, int stateVal)
          Sets the "extended" state of the given frame.
static boolean setPreferredSize(java.awt.Component compObj, java.awt.Dimension dimObj)
          Sets the preferred size of the given component to a constant value.
static void setPreferredSize(java.awt.Component compObj, int maxNumChars, int maxCharWidth)
          Set the preferred size for the component.
static void setPreferredSize(java.awt.Component compObj, int maxNumChars, int maxCharWidth, int padWidth)
          Set the preferred size for the component.
static void setPreferredSize(java.awt.Component compObj, com.isti.util.gui.textvalidator.TextValidator tv)
          Set the preferred size for the component.
static void setPreferredSize(javax.swing.JComponent compObj, int maxNumChars)
          Set the preferred size for the component.
static void setScrollPaneCentered(javax.swing.JScrollPane paneObj)
          Sets the given scroll-pane to have its scroll-bars centered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultWidthChar

public static final char defaultWidthChar
The default width character, m.

See Also:
Constant Field Values

DEF_PAD_WIDTH

public static int DEF_PAD_WIDTH
The default pad width for components that sometimes require it, such as 'JComboBox'.

Method Detail

ensureSelectionVisible

public static void ensureSelectionVisible(javax.swing.JTable tableObj)
Ensures that the current table selection is visible.

Parameters:
tableObj - the table object.

ensureRowVisible

public static void ensureRowVisible(javax.swing.JTable tableObj,
                                    int row)
Ensures that the specified table row is visible.

Parameters:
tableObj - the table object.
row - the row index.

getMaxCharWidth

public static int getMaxCharWidth(java.awt.Component compObj)
Returns the maximum width, in pixels, of the default width character.

Parameters:
compObj - the component to use.
Returns:
the maximum width or 0 if none.

getMaxCharWidth

public static int getMaxCharWidth(java.awt.Component compObj,
                                  char widthChar)
Returns the maximum width, in pixels, of the specified width character.

Parameters:
compObj - the component to use.
widthChar - the width character.
Returns:
the maximum width or 0 if none.

getMaxCharWidth

public static int getMaxCharWidth(java.awt.Component compObj,
                                  java.lang.String specialChars,
                                  boolean allowedFlag)
Returns the maximum width, in pixels, of an allowed character.

Parameters:
compObj - the component to use.
specialChars - the allowed (or not allowed) special characters.
allowedFlag - true to allow only the special characters, false to not allow the special characters.
Returns:
the maximum width or 0 if none.

getMaxCharWidthValue

public static IstiNamedValue getMaxCharWidthValue(java.awt.Component compObj,
                                                  java.lang.String specialChars,
                                                  boolean allowedFlag)
Returns the maximum width, in pixels, of an allowed character. The return named value has a name that is the character with the maximum width and an Integer width value.

Parameters:
compObj - the component to use.
specialChars - the allowed (or not allowed) special characters.
allowedFlag - true to allow only the special characters, false to not allow the special characters.
Returns:
the maximum width value or 0 if none.

getMaxCharWidth

public static int getMaxCharWidth(java.awt.Component compObj,
                                  com.isti.util.gui.textvalidator.TextValidator tv)
Returns the maximum width, in pixels, of an allowed character.

Parameters:
compObj - the component to use.
tv - the text validator.
Returns:
the maximum width or 0 if none.

getStringWidth

public static int getStringWidth(java.awt.Component compObj,
                                 java.awt.Font fontObj,
                                 java.lang.String str,
                                 int defWidthVal)
Returns the width, in pixels, of the given string.

Parameters:
compObj - the component to use, or null to use a default 'JLabel' object.
fontObj - the font to use, or null to use the font from the given component object.
str - the string to use.
defWidthVal - a default width value to be returned if an error occurs while calculating the width.
Returns:
The width, in pixels, of the given string.

getStringWidth

public static int getStringWidth(java.awt.Component compObj,
                                 java.lang.String str,
                                 int defWidthVal)
Returns the width, in pixels, of the given string. The font from the given component object is used.

Parameters:
compObj - the component to use, or null to use a default 'JLabel' object.
str - the string to use.
defWidthVal - a default width value to be returned if an error occurs while calculating the width.
Returns:
The width, in pixels, of the given string.

getStringWidth

public static int getStringWidth(java.awt.Font fontObj,
                                 java.lang.String str,
                                 int defWidthVal)
Returns the width, in pixels, of the given string. A default 'JLabel' object is used.

Parameters:
fontObj - the font to use, or null to use the font from the given component object.
str - the string to use.
defWidthVal - a default width value to be returned if an error occurs while calculating the width.
Returns:
The width, in pixels, of the given string.

getStringWidth

public static int getStringWidth(java.awt.Component compObj,
                                 java.awt.Font fontObj,
                                 java.lang.String str)
Returns the width, in pixels, of the given string.

Parameters:
compObj - the component to use, or null to use a default 'JLabel' object.
fontObj - the font to use, or null to use the font from the given component object.
str - the string to use.
Returns:
The width, in pixels, of the given string; or 0 if an error occurs.

getStringWidth

public static int getStringWidth(java.awt.Font fontObj,
                                 java.lang.String str)
Returns the width, in pixels, of the given string. A default 'JLabel' object is used.

Parameters:
fontObj - the font to use, or null to use the font from the given component object.
str - the string to use.
Returns:
The width, in pixels, of the given string; or 0 if an error occurs.

getStringWidth

public static int getStringWidth(java.awt.Component compObj,
                                 java.lang.String str)
Returns the width, in pixels, of the given string. The font from the given component object is used.

Parameters:
compObj - the component to use, or null to use a default 'JLabel' object.
str - the string to use.
Returns:
The width, in pixels, of the given string; or 0 if an error occurs.

getStringWidth

public static int getStringWidth(java.lang.String str,
                                 int defWidthVal)
Returns the width, in pixels, of the given string. A default 'JLabel' object and font are used.

Parameters:
str - the string to use.
defWidthVal - a default width value to be returned if an error occurs while calculating the width.
Returns:
The width, in pixels, of the given string.

getStringWidth

public static int getStringWidth(java.lang.String str)
Returns the width, in pixels, of the given string. A default 'JLabel' object and font are used.

Parameters:
str - the string to use.
Returns:
The width, in pixels, of the given string; or 0 if an error occurs.

getSpacerStrForWidth

public static java.lang.String getSpacerStrForWidth(int widthVal,
                                                    int spaceCharSize)
Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width. The size of the space character ('spaceCharSize') may be generated via the 'getStringWidth()' method.

Parameters:
widthVal - the pixel width to use.
spaceCharSize - the size (in pixels) of a space character to use, or 0 to use a default size.
Returns:
A string containing 0 or more space characters.

getSpacerStrForWidth

public static java.lang.String getSpacerStrForWidth(int widthVal,
                                                    java.awt.Component compObj,
                                                    java.awt.Font fontObj,
                                                    int defWidthVal)
Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width, using the given component and font.

Parameters:
widthVal - the pixel width to use.
compObj - the component to use, or null to use a default 'JLabel' object.
fontObj - the font to use, or null to use the font from the given component object.
defWidthVal - a default width value for the size of space character in pixels (used if an error occurs while determining the size).
Returns:
A string containing 0 or more space characters.

getSpacerStrForWidth

public static java.lang.String getSpacerStrForWidth(int widthVal,
                                                    java.awt.Component compObj,
                                                    java.awt.Font fontObj)
Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width, using the given component and font.

Parameters:
widthVal - the pixel width to use.
compObj - the component to use, or null to use a default 'JLabel' object.
fontObj - the font to use, or null to use the font from the given component object.
Returns:
A string containing 0 or more space characters.

getSpacerStrForWidth

public static java.lang.String getSpacerStrForWidth(int widthVal,
                                                    java.awt.Component compObj,
                                                    int defWidthVal)
Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width, using the given component.

Parameters:
widthVal - the pixel width to use.
compObj - the component to use, or null to use a default 'JLabel' object.
defWidthVal - a default width value for the size of space character in pixels (used if an error occurs while determining the size).
Returns:
A string containing 0 or more space characters.

getSpacerStrForWidth

public static java.lang.String getSpacerStrForWidth(int widthVal,
                                                    java.awt.Component compObj)
Generates a spacer string containing the maximum number of space characters that will fit within the given pixel width, using the given component.

Parameters:
widthVal - the pixel width to use.
compObj - the component to use, or null to use a default 'JLabel' object.
Returns:
A string containing 0 or more space characters.

setScrollPaneCentered

public static void setScrollPaneCentered(javax.swing.JScrollPane paneObj)
Sets the given scroll-pane to have its scroll-bars centered. This action is delayed via "SwingUtilities.invokeLater()" to help allow the scroll-pane to get setup.

Parameters:
paneObj - the scroll-pane object to use.

setEmptyJListWidth

public static void setEmptyJListWidth(javax.swing.JList listObj,
                                      int widthVal)
Sets the fixed cell width that the given 'JList' is to have when its contents are empty. This is accomplished via a 'ListDataListener' that is added to the given list's model, which enters the given fixed cell width when the list is empty and enters '-1' (via the 'setFixedCellWidth()' method) when the list contains entries. As such, if a new list model is set for the 'JList' then the listener will no longer operate.

Parameters:
listObj - the 'JList' to use.
widthVal - the width value to use.

getExtendedFrameState

public static int getExtendedFrameState(java.awt.Frame frameObj)
Returns the "extended" state of the given frame. If the frame is "maximized" (both horizontally and vertically) then the following test will be true: (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH This utility method allows programs compiled under Java 1.3 to access the Java >=1.4 method 'Frame.getExtendedState()'.

Parameters:
frameObj - 'Frame' object to use.
Returns:
The "extended" state of the given frame.

setExtendedFrameState

public static boolean setExtendedFrameState(java.awt.Frame frameObj,
                                            int stateVal)
Sets the "extended" state of the given frame. This utility method allows programs compiled under Java 1.3 to access the Java >=1.4 method 'Frame.setExtendedState()'.

Parameters:
frameObj - 'Frame' object to use.
stateVal - frame-state-bitmap value to use.
Returns:
true if successful; false if not.

initColumnSizes

public static void initColumnSizes(javax.swing.JTable tableObj)

isFrameMaximized

public static boolean isFrameMaximized(java.awt.Frame frameObj)
Determines if the given frame is maximized (both horizontally and vertically).

Parameters:
frameObj - 'Frame' object to use.
Returns:
true if the given frame is maximized; false if not.

maximizeFrame

public static boolean maximizeFrame(java.awt.Frame frameObj)
Sets the state of the given frame to "maximized" (both horizontally and vertically).

Parameters:
frameObj - 'Frame' object to use.
Returns:
true if successful; false if not.

getFrameMaximizedBothValue

public static int getFrameMaximizedBothValue()
Returns the value of Frame.MAXIMIZED_BOTH.

Returns:
The value of Frame.MAXIMIZED_BOTH.

getMaximumWindowBounds

public static java.awt.Rectangle getMaximumWindowBounds()
Returns the maximum bounds for centered windows. These bounds account for objects in the native windowing system such as task bars and menu bars. The returned bounds will reside on a single display with one exception: on multi-screen systems where Windows should be centered across all displays, this method returns the bounds of the entire display area. This utility method allows programs compiled under Java 1.3 to access the Java >=1.4 method 'GraphicsEnvironment.getMaximumWindowBounds()'.

Returns:
The maximum bounds for centered windows.

setPreferredSize

public static boolean setPreferredSize(java.awt.Component compObj,
                                       java.awt.Dimension dimObj)
Sets the preferred size of the given component to a constant value. This utility method allows programs compiled under Java <=1.4 to access the Java >=1.5 method 'Component.setPreferredSize()'.

Parameters:
compObj - 'Component' object to use.
dimObj - The new preferred size, or null.
Returns:
true if successful; false if not.

setPreferredSize

public static final void setPreferredSize(java.awt.Component compObj,
                                          int maxNumChars,
                                          int maxCharWidth)
Set the preferred size for the component.

Parameters:
compObj - the component.
maxNumChars - the maximum number of characters.
maxCharWidth - the maximum character width.

setPreferredSize

public static final void setPreferredSize(java.awt.Component compObj,
                                          int maxNumChars,
                                          int maxCharWidth,
                                          int padWidth)
Set the preferred size for the component.

Parameters:
compObj - the component.
maxNumChars - the maximum number of characters.
maxCharWidth - the maximum character width.
padWidth - the pad width or 0 if none.

setPreferredSize

public static final void setPreferredSize(javax.swing.JComponent compObj,
                                          int maxNumChars)
Set the preferred size for the component.

Parameters:
compObj - the component.
maxNumChars - the maximum number of characters.

setPreferredSize

public static final void setPreferredSize(java.awt.Component compObj,
                                          com.isti.util.gui.textvalidator.TextValidator tv)
Set the preferred size for the component.

Parameters:
compObj - the component.
tv - the text validator.

setButtonsContentAreaFilled

public static void setButtonsContentAreaFilled(java.awt.Container contObj,
                                               boolean flgVal)
Calls the 'setContentAreaFilled()' method on all button objects held by the given container or any subcontainers of it.

Parameters:
contObj - container to use.
flgVal - true for content filled; false for not.