ccl.swing
Class SwingUtil

java.lang.Object
  |
  +--ccl.swing.SwingUtil

public class SwingUtil
extends java.lang.Object

Utility class for gui/swing stuff. Instead of creating and showing special dialogs yourself, this class provides some shortcut methods for this task.


Field Summary
static int CANCEL
          Constant for yes, no, and cancel.
static int NO
          Constant for yes, no, and cancel.
static int YES
          Constant for yes, no, and cancel.
 
Constructor Summary
SwingUtil()
           
 
Method Summary
static void centerComponent(java.awt.Component cmpObject)
           
static void centerComponent(java.awt.Component cmpObject_, java.awt.Component cmpParent_, int heightFraction_)
           
static CCLBorder createCCLBorder()
          Instead of creating your own new CCLBorder object each time you want to use a CCLBorder, you can simply reuse the object returned by this method.
static CCLButtonBorder createCCLButtonBorder()
          Instead of creating your own new CCLButtonBorder object each time you want to use a CCLButtonBorder, you can simply reuse the object returned by this method.
static void dispatchEnterKeyEvent(java.awt.Component pComponent_)
          Send enter key event to component, espacially text component.
static void dispatchKeyEvent(java.awt.Component pComponent_, char c_)
          Send characters interactively to components, espacially text components.
static void dispatchKeyEvent(java.awt.Component pComponent_, int virtualKey_)
          Send pKeyEvent_ to component, espacially text component.
static void doClick(javax.swing.JButton btnClick_)
          Using this method you don't need to create an inner class yourself to invoke it later in awt thread.
static java.awt.Component getComponent(java.awt.Container pContainer_, java.lang.String sName_, int n_)
          For example: getComponent( pFrame, "name_text", 0 ); or: getComponent( pFrame, "javax.swing.JTextField", 2 );
static java.awt.Component getComponent(java.awt.Container pContainer_, Testable pTestable_, int n_)
           
static java.lang.String getContainerDump(java.awt.Container container)
          Simliar to a stack trace a string containing the tree of awt components in the given container.
static java.lang.String getDirName(java.awt.Frame frmParent_, java.lang.String sTitle_, java.lang.String sDirectory_)
          This file choose selects peer class under windows, swing file chooser on other systems.
static java.lang.String getFileName(java.awt.Frame frmParent_, java.lang.String sTitle_, java.lang.String sStartDirectory_)
           
static java.lang.String getFileName(java.awt.Frame frmParent_, java.lang.String sTitle_, java.lang.String[] asFileSuffixes_, java.lang.String sDirectory_)
          This file choose selects peer class under windows, swing file chooser on other systems.
static java.lang.String getFileName(java.awt.Frame frmParent_, java.lang.String sTitle_, java.lang.String sFileName_, java.lang.String sDirectory_)
          (This file choose selects peer class under windows, swing file chooser on other systems.
static java.lang.String getFileName(java.awt.Frame frmParent_, java.lang.String sTitle_, java.lang.String sFileName_, java.lang.String sDirectory_, java.lang.String sOKButtonText_)
           
static java.lang.String getFileOrDirName(java.awt.Frame frmParent_, java.lang.String sTitle_, java.lang.String sDirectory_)
           
static java.awt.Component getFirstComponent(java.awt.Container pContainer_, java.lang.String sName_)
          For example: getFirstComponent( pFrame, "name_text" ); or: getFirstComponent( pFrame, "javax.swing.JTextField" );
static javax.swing.MenuElement getMenuElement(javax.swing.MenuElement pMenuElement_, java.lang.String[] asMenuName_)
           
static java.awt.Image getResourcesImage(java.lang.String sResourceImageName_)
           
static java.awt.Dimension getScreenSize()
           
static void getValue(Test pTest_)
          Deprecated. Test hack.
static java.lang.String inputCancel(java.awt.Frame frmParent_, java.lang.String sPrint_)
           
static java.lang.String inputCancel(java.awt.Frame frmParent_, java.lang.String sPrint_, java.lang.String sInit_)
           
static java.util.Vector inputDoubleListCancel(java.awt.Frame frmParent_, java.lang.String sPrint_, java.util.Vector vsFirst_, java.util.Vector vsSecond_, boolean bMultiSelect_)
           
static java.util.Vector inputDoubleListCancel(java.awt.Frame frmParent_, java.lang.String sPrint_, java.util.Vector vsFirst_, java.util.Vector vsSecond_, boolean bMultiSelect_, java.awt.Color clrListBackground_, java.awt.Color clrListForeground_)
           
static java.lang.String inputListCancel(java.awt.Frame frmParent_, java.lang.String sPrint_, java.util.Vector vsItems_)
           
static void insertNodeToTree(javax.swing.tree.DefaultMutableTreeNode tnRoot_, javax.swing.tree.DefaultMutableTreeNode tnChild_, java.lang.String sPath_, char cDelimiter_)
           
static void invokeAndWaitIfNecessary(java.lang.Runnable pRunnable_)
          If not running in an AWT thread, then invoke later.
static void invokeLaterIfNecessary(java.lang.Runnable pRunnable_)
          If not running in an AWT thread, then invoke later.
static boolean isFileSavable(java.awt.Frame frmParent_, java.lang.String sSaveFile_)
           
static boolean isOKOrCancel(java.awt.Frame frmParent_, java.lang.String sMessage_)
          Opens a dialog and returns either true or false.
static int lastIndexOf(javax.swing.text.Segment pSegment_, int c_)
          Like String.lastIndexOf() but working on Segment instead of String.
static int lastIndexOf(javax.swing.text.Segment pSegment_, int c_, int fromIndex_)
          Like String.lastIndexOf() but working on Segment instead of String.
static java.awt.Image loadImage(java.lang.String sImageFileName_)
           
static java.awt.Dimension max(java.awt.Dimension dimA_, java.awt.Dimension dimB_)
           
static void maximizeWindow(java.awt.Window pWindow_)
           
static void maximizeWindow(java.awt.Window window, float percentage)
           
static void pressOKButton(java.awt.Window pWindow_)
          Might return earlier than the action has finished.
static void removeEnterBinding(javax.swing.JTextField pTextField_)
          From sun's JTextField.java: [ccl 1998-1-8] Need this for default button in dialogs.
static void setCCLButtonBorderOnTableHeader(javax.swing.JTable table, java.awt.Font font)
          Uses ccl button border for the given table's headers.
static void setDefaultButton(java.awt.Component pComponent_, javax.swing.JButton pButton_)
           
static void setInitialFocus(java.awt.Window pWindow_, java.awt.Component pComponent_)
          Sets the initial focus of a component when a window pops up.
static void setList(javax.swing.JList pList_, java.util.Vector vValues_)
           
static void setMainFrame(java.awt.Frame pFrame_)
          Deprecated. Testing should not rely on this hack.
static void showAboutDialog(MainJFrame pMainFrame_)
           
static void showMessage(java.awt.Frame frmParent_, java.lang.String sMessages_)
          Requests focus for frmParent_ afterwards.
static java.util.Vector toVector(javax.swing.DefaultListModel pDefaultListModel_)
           
static void unregisterEnterAction(javax.swing.JButton pButton_)
          A swing workaround.
static int wannaSave(java.awt.Frame frmParent_)
          Deprecated. Use ccl.swing.SwingUtil instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

YES

public static final int YES
Constant for yes, no, and cancel.

See Also:
Constant Field Values

NO

public static final int NO
Constant for yes, no, and cancel.

See Also:
Constant Field Values

CANCEL

public static final int CANCEL
Constant for yes, no, and cancel.

See Also:
Constant Field Values
Constructor Detail

SwingUtil

public SwingUtil()
Method Detail

inputListCancel

public static java.lang.String inputListCancel(java.awt.Frame frmParent_,
                                               java.lang.String sPrint_,
                                               java.util.Vector vsItems_)
Returns:
null if canceled.

inputDoubleListCancel

public static java.util.Vector inputDoubleListCancel(java.awt.Frame frmParent_,
                                                     java.lang.String sPrint_,
                                                     java.util.Vector vsFirst_,
                                                     java.util.Vector vsSecond_,
                                                     boolean bMultiSelect_)
Returns:
null for cancel, empty vector if nothing was selected, still the user pressed ok.

inputDoubleListCancel

public static java.util.Vector inputDoubleListCancel(java.awt.Frame frmParent_,
                                                     java.lang.String sPrint_,
                                                     java.util.Vector vsFirst_,
                                                     java.util.Vector vsSecond_,
                                                     boolean bMultiSelect_,
                                                     java.awt.Color clrListBackground_,
                                                     java.awt.Color clrListForeground_)

getResourcesImage

public static java.awt.Image getResourcesImage(java.lang.String sResourceImageName_)
                                        throws java.util.MissingResourceException
java.util.MissingResourceException

showMessage

public static void showMessage(java.awt.Frame frmParent_,
                               java.lang.String sMessages_)
Requests focus for frmParent_ afterwards.


setInitialFocus

public static void setInitialFocus(java.awt.Window pWindow_,
                                   java.awt.Component pComponent_)
Sets the initial focus of a component when a window pops up. component.requestFocus() won't work in a constructor, since the window is not visible yet.


getFileName

public static java.lang.String getFileName(java.awt.Frame frmParent_,
                                           java.lang.String sTitle_,
                                           java.lang.String[] asFileSuffixes_,
                                           java.lang.String sDirectory_)
This file choose selects peer class under windows, swing file chooser on other systems. Swing file chooser is pretty broken on windows, while the native implementation is not bad. On unix it's vice versa.

Parameters:
asFileSuffixes_ - for example: { "jiml", "nr" }

getFileName

public static java.lang.String getFileName(java.awt.Frame frmParent_,
                                           java.lang.String sTitle_,
                                           java.lang.String sFileName_,
                                           java.lang.String sDirectory_)
(This file choose selects peer class under windows, swing file chooser on other systems. -- not true!) Swing file chooser is pretty broken on windows, while the native implementation is not bad. On unix it's vice versa.

Parameters:
sFileName_ - for example: *.proj

getFileName

public static java.lang.String getFileName(java.awt.Frame frmParent_,
                                           java.lang.String sTitle_,
                                           java.lang.String sFileName_,
                                           java.lang.String sDirectory_,
                                           java.lang.String sOKButtonText_)
Parameters:
sFileName_ - for example: *.proj

getDirName

public static java.lang.String getDirName(java.awt.Frame frmParent_,
                                          java.lang.String sTitle_,
                                          java.lang.String sDirectory_)
This file choose selects peer class under windows, swing file chooser on other systems. Swing file chooser is pretty broken on windows, while the native implementation is not bad. On unix it's vice versa.

Returns:
null on cancel

getFileOrDirName

public static java.lang.String getFileOrDirName(java.awt.Frame frmParent_,
                                                java.lang.String sTitle_,
                                                java.lang.String sDirectory_)
Returns:
null on cancel

getFileName

public static java.lang.String getFileName(java.awt.Frame frmParent_,
                                           java.lang.String sTitle_,
                                           java.lang.String sStartDirectory_)
Returns:
null on cancel

isOKOrCancel

public static boolean isOKOrCancel(java.awt.Frame frmParent_,
                                   java.lang.String sMessage_)
Opens a dialog and returns either true or false.


unregisterEnterAction

public static void unregisterEnterAction(javax.swing.JButton pButton_)
A swing workaround. Buttons react to enter. We need it for default button.


removeEnterBinding

public static void removeEnterBinding(javax.swing.JTextField pTextField_)
From sun's JTextField.java: [ccl 1998-1-8] Need this for default button in dialogs. For compatibility with java.awt.TextField, the VK_ENTER key fires the ActionEvent to the registered ActionListeners. However, awt didn't have default buttons like swing does. If a text field has focus and the VK_ENTER key is pressed, it will fire the fields ActionEvent rather than activate the default button. To disable the compatibility with awt for text fields, the following code fragment will remove the binding of VK_ENTER from the default keymap used by all JTextFields if that is desired.


createCCLBorder

public static CCLBorder createCCLBorder()
Instead of creating your own new CCLBorder object each time you want to use a CCLBorder, you can simply reuse the object returned by this method.


createCCLButtonBorder

public static CCLButtonBorder createCCLButtonBorder()
Instead of creating your own new CCLButtonBorder object each time you want to use a CCLButtonBorder, you can simply reuse the object returned by this method.


setCCLButtonBorderOnTableHeader

public static void setCCLButtonBorderOnTableHeader(javax.swing.JTable table,
                                                   java.awt.Font font)
Uses ccl button border for the given table's headers.

Parameters:
table - the table to change the header borders on. The table must have its columns already set.

invokeLaterIfNecessary

public static void invokeLaterIfNecessary(java.lang.Runnable pRunnable_)
If not running in an AWT thread, then invoke later. Otherwise just execute the code.


invokeAndWaitIfNecessary

public static void invokeAndWaitIfNecessary(java.lang.Runnable pRunnable_)
                                     throws java.lang.InterruptedException,
                                            java.lang.reflect.InvocationTargetException
If not running in an AWT thread, then invoke later. Otherwise just execute the code.

java.lang.InterruptedException
java.lang.reflect.InvocationTargetException

inputCancel

public static java.lang.String inputCancel(java.awt.Frame frmParent_,
                                           java.lang.String sPrint_,
                                           java.lang.String sInit_)
Returns:
null if canceled.

inputCancel

public static java.lang.String inputCancel(java.awt.Frame frmParent_,
                                           java.lang.String sPrint_)
Returns:
null if canceled.

insertNodeToTree

public static void insertNodeToTree(javax.swing.tree.DefaultMutableTreeNode tnRoot_,
                                    javax.swing.tree.DefaultMutableTreeNode tnChild_,
                                    java.lang.String sPath_,
                                    char cDelimiter_)
Parameters:
sPath_ - String representation of the new child node. For example "Notes/Ideas/Crazy". This will Search for node Notes->Ideas and inserts the new child assuming its string representation is "Crazy".
cDelimiter_ - '/' for example.

toVector

public static java.util.Vector toVector(javax.swing.DefaultListModel pDefaultListModel_)

getFirstComponent

public static java.awt.Component getFirstComponent(java.awt.Container pContainer_,
                                                   java.lang.String sName_)
For example: getFirstComponent( pFrame, "name_text" ); or: getFirstComponent( pFrame, "javax.swing.JTextField" );


getContainerDump

public static java.lang.String getContainerDump(java.awt.Container container)
Simliar to a stack trace a string containing the tree of awt components in the given container.


getComponent

public static java.awt.Component getComponent(java.awt.Container pContainer_,
                                              java.lang.String sName_,
                                              int n_)
For example: getComponent( pFrame, "name_text", 0 ); or: getComponent( pFrame, "javax.swing.JTextField", 2 );

Parameters:
n_ - >= 0; the n-1st component of this type will be returned.

getComponent

public static java.awt.Component getComponent(java.awt.Container pContainer_,
                                              Testable pTestable_,
                                              int n_)
Parameters:
n_ - >= 0; the n-1st component of this type will be returned.

pressOKButton

public static void pressOKButton(java.awt.Window pWindow_)
Might return earlier than the action has finished.


getMenuElement

public static javax.swing.MenuElement getMenuElement(javax.swing.MenuElement pMenuElement_,
                                                     java.lang.String[] asMenuName_)

dispatchKeyEvent

public static void dispatchKeyEvent(java.awt.Component pComponent_,
                                    char c_)
Send characters interactively to components, espacially text components.


dispatchKeyEvent

public static void dispatchKeyEvent(java.awt.Component pComponent_,
                                    int virtualKey_)
Send pKeyEvent_ to component, espacially text component.


dispatchEnterKeyEvent

public static void dispatchEnterKeyEvent(java.awt.Component pComponent_)
Send enter key event to component, espacially text component.


doClick

public static void doClick(javax.swing.JButton btnClick_)
Using this method you don't need to create an inner class yourself to invoke it later in awt thread.


lastIndexOf

public static int lastIndexOf(javax.swing.text.Segment pSegment_,
                              int c_)
Like String.lastIndexOf() but working on Segment instead of String.


lastIndexOf

public static int lastIndexOf(javax.swing.text.Segment pSegment_,
                              int c_,
                              int fromIndex_)
Like String.lastIndexOf() but working on Segment instead of String.


showAboutDialog

public static void showAboutDialog(MainJFrame pMainFrame_)

setList

public static void setList(javax.swing.JList pList_,
                           java.util.Vector vValues_)
Parameters:
pList_ - expects list with DefaultListModel.

wannaSave

public static int wannaSave(java.awt.Frame frmParent_)
Deprecated. Use ccl.swing.SwingUtil instead.

Returns:
AWTUtil.YES, AWTUtil.NO or AWTUtil.CANCEL
See Also:
YesNoCancelDialog

getScreenSize

public static java.awt.Dimension getScreenSize()

maximizeWindow

public static void maximizeWindow(java.awt.Window pWindow_)

maximizeWindow

public static void maximizeWindow(java.awt.Window window,
                                  float percentage)

centerComponent

public static void centerComponent(java.awt.Component cmpObject_,
                                   java.awt.Component cmpParent_,
                                   int heightFraction_)

centerComponent

public static void centerComponent(java.awt.Component cmpObject)

loadImage

public static java.awt.Image loadImage(java.lang.String sImageFileName_)

setMainFrame

public static void setMainFrame(java.awt.Frame pFrame_)
Deprecated. Testing should not rely on this hack.


getValue

public static void getValue(Test pTest_)
Deprecated. Test hack.


max

public static java.awt.Dimension max(java.awt.Dimension dimA_,
                                     java.awt.Dimension dimB_)

setDefaultButton

public static void setDefaultButton(java.awt.Component pComponent_,
                                    javax.swing.JButton pButton_)

isFileSavable

public static boolean isFileSavable(java.awt.Frame frmParent_,
                                    java.lang.String sSaveFile_)