com.ibm.commons.swt
Class SWTUtils

java.lang.Object
  extended by com.ibm.commons.swt.SWTUtils

public class SWTUtils
extends java.lang.Object

Miscellaneous SWT utilities.


Field Summary
static java.lang.String CONTROL_ID
           
static int IMG_BOTTOM
           
static int IMG_CENTER
           
static int IMG_LEFT
           
static int IMG_MOSAIC
           
static int IMG_RIGHT
           
static int IMG_STRETCH
           
static int IMG_TOP
           
static int PLATFORM_CARBON
           
static int PLATFORM_GTK
           
static int PLATFORM_UNKNOWN
           
static int PLATFORM_WIN32
           
 
Constructor Summary
SWTUtils()
           
 
Method Summary
static void disposeChilden(org.eclipse.swt.widgets.Composite parent)
          Given a parent control (Composite) this utility method will get all first layer children of the parent and call the dispose method on each child Control.
static void drawImage(org.eclipse.swt.graphics.GC g, int hAlign, int vAlign, org.eclipse.swt.graphics.Image image, org.eclipse.swt.graphics.Rectangle bounds, org.eclipse.swt.graphics.Color fillColor)
           
static org.eclipse.swt.graphics.Color getBackgroundColor(org.eclipse.swt.widgets.Control controlViewer)
          Returns a background color for a given control, depending on high contrast.
static java.lang.String getControlId(org.eclipse.swt.widgets.Widget control)
          Given a widget this utility method will return the programmatic ID associated with the control if one has been assigned.
static int getPlatform()
          Returns the platform that the code is running.
static boolean isChildOf(org.eclipse.swt.widgets.Control c, org.eclipse.swt.widgets.Control parent)
          Calculates if the provided parent is in the parent hierarchy of the given Control.
static boolean isInDialog(org.eclipse.swt.widgets.Control control)
          Test the given control to determine if it is a in dialog or not.
static void setBackgroundColor(org.eclipse.swt.widgets.Control parent)
          Sets the background color of all of the control's children to the current color of the provided parent control.
static void setBackgroundColor(org.eclipse.swt.widgets.Control parent, org.eclipse.swt.graphics.Color color)
          Recursively walks down through the hierarchy of controls under the given parent setting the background color provided on each control encountered.
static void setBackgroundColor(org.eclipse.swt.widgets.Control parent, org.eclipse.swt.graphics.Color color, boolean checkEnabled)
          Recursively sets the background color of all of the children of the provided parent Control.
static void setControlId(org.eclipse.swt.widgets.Widget control, java.lang.String id)
          This utility method associates an ID with the provided Widget.
static void setControlIdFromAttribute(org.eclipse.swt.widgets.Widget control, java.lang.String attrName)
           
static void setEnabled(org.eclipse.swt.widgets.Control control, boolean state)
          Recursively walks through the children of the control provided and finally the control itself calling the Control.setEnabled(state) method on each control it encounters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTROL_ID

public static final java.lang.String CONTROL_ID
See Also:
Constant Field Values

PLATFORM_UNKNOWN

public static final int PLATFORM_UNKNOWN
See Also:
Constant Field Values

PLATFORM_WIN32

public static final int PLATFORM_WIN32
See Also:
Constant Field Values

PLATFORM_GTK

public static final int PLATFORM_GTK
See Also:
Constant Field Values

PLATFORM_CARBON

public static final int PLATFORM_CARBON
See Also:
Constant Field Values

IMG_LEFT

public static final int IMG_LEFT
See Also:
Constant Field Values

IMG_TOP

public static final int IMG_TOP
See Also:
Constant Field Values

IMG_CENTER

public static final int IMG_CENTER
See Also:
Constant Field Values

IMG_RIGHT

public static final int IMG_RIGHT
See Also:
Constant Field Values

IMG_BOTTOM

public static final int IMG_BOTTOM
See Also:
Constant Field Values

IMG_MOSAIC

public static final int IMG_MOSAIC
See Also:
Constant Field Values

IMG_STRETCH

public static final int IMG_STRETCH
See Also:
Constant Field Values
Constructor Detail

SWTUtils

public SWTUtils()
Method Detail

getControlId

public static java.lang.String getControlId(org.eclipse.swt.widgets.Widget control)
Given a widget this utility method will return the programmatic ID associated with the control if one has been assigned. An ID is typically only needed where the control in question needs to be later identified for purposes such as GUI automation.

Parameters:
control -
Returns:
String A unique identifier used to identify the supplied Widget (May be NULL!).

setControlId

public static void setControlId(org.eclipse.swt.widgets.Widget control,
                                java.lang.String id)
This utility method associates an ID with the provided Widget. The ID supplied should be unique in the context of shell upon which the supplied Widget resides. The method sets calls the Widget.setData(..) method to associate the ID with the widget.

Parameters:
control -
id -

setControlIdFromAttribute

public static void setControlIdFromAttribute(org.eclipse.swt.widgets.Widget control,
                                             java.lang.String attrName)

disposeChilden

public static void disposeChilden(org.eclipse.swt.widgets.Composite parent)
Given a parent control (Composite) this utility method will get all first layer children of the parent and call the dispose method on each child Control.

Parameters:
parent - Composite A composite control that contains children

isChildOf

public static boolean isChildOf(org.eclipse.swt.widgets.Control c,
                                org.eclipse.swt.widgets.Control parent)
Calculates if the provided parent is in the parent hierarchy of the given Control.

Parameters:
c - Control Control whose parent hierarchy is to be examined
parent - Control Control against which the provided child control will be tested
Returns:
returns true if the parent is in the child's parent hierarchy.

getPlatform

public static int getPlatform()
Returns the platform that the code is running. Must be one of:

Returns:
int
  • com.ibm.commons.swt.SWTUtils.PLATFORM_WIN32
  • com.ibm.commons.swt.SWTUtils.PLATFORM_GTK
  • com.ibm.commons.swt.SWTUtils.PLATFORM_CARBON
See Also:
SWT.getPlatform()

drawImage

public static final void drawImage(org.eclipse.swt.graphics.GC g,
                                   int hAlign,
                                   int vAlign,
                                   org.eclipse.swt.graphics.Image image,
                                   org.eclipse.swt.graphics.Rectangle bounds,
                                   org.eclipse.swt.graphics.Color fillColor)

setEnabled

public static void setEnabled(org.eclipse.swt.widgets.Control control,
                              boolean state)
Recursively walks through the children of the control provided and finally the control itself calling the Control.setEnabled(state) method on each control it encounters.

Parameters:
control - Control The parent Control
state - boolean The enabled state (true to enable all controls)

isInDialog

public static boolean isInDialog(org.eclipse.swt.widgets.Control control)
Test the given control to determine if it is a in dialog or not.

Parameters:
control - - control to test, may not be null.
Returns:
true if the control is in a dialog, false otherwise.

getBackgroundColor

public static org.eclipse.swt.graphics.Color getBackgroundColor(org.eclipse.swt.widgets.Control controlViewer)
Returns a background color for a given control, depending on high contrast.

Parameters:
control - Control The control whose background color needs to be obtained
Returns:
Color

setBackgroundColor

public static void setBackgroundColor(org.eclipse.swt.widgets.Control parent,
                                      org.eclipse.swt.graphics.Color color)
Recursively walks down through the hierarchy of controls under the given parent setting the background color provided on each control encountered.

Parameters:
parent - Control The parent whose children we wish to set the background color
color - Color The background color we wish to set

setBackgroundColor

public static void setBackgroundColor(org.eclipse.swt.widgets.Control parent,
                                      org.eclipse.swt.graphics.Color color,
                                      boolean checkEnabled)
Recursively sets the background color of all of the children of the provided parent Control. This method takes into account the enablement state of the controls whose color is about to change. If the control is disabled then the color will NOT be changed.

Parameters:
parent - Control Parent control
color - Color The new background color that we wish to set
checkEnabled - boolean If set to true then this method will not change the color of any control that is disabled.

setBackgroundColor

public static void setBackgroundColor(org.eclipse.swt.widgets.Control parent)
Sets the background color of all of the control's children to the current color of the provided parent control.

Parameters:
parent - Control