com.aptana.ide.core.ui
Class SWTUtils

java.lang.Object
  extended by com.aptana.ide.core.ui.SWTUtils

public class SWTUtils
extends java.lang.Object

Utilities to make SWT dialogs easier to manage

Author:
Ingo Muschenetz

Constructor Summary
protected SWTUtils()
          Protected constructor for utility class
 
Method Summary
static double[] calculateColumnPercents(org.eclipse.swt.widgets.Table table, double padding)
          Calculates the percentage width of each column in the table relative to the total table size
static int[] calculateColumnWidths(org.eclipse.swt.widgets.Table table)
          Calculates the width of each column in the table
static void center(org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.widgets.Shell parent)
          Centers the shell on screen.
static void centerAndPack(org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.widgets.Shell parent)
          Centers the shell on screen, and re-packs it to the preferred size.
static void colorBackground(org.eclipse.swt.widgets.Text widget, java.lang.String testValue)
          Colors the background of a text widget based on the test value
static org.eclipse.swt.graphics.Font getDefaultLargeFont()
          Retuyrns
static org.eclipse.swt.graphics.Font getDefaultSmallFont()
          Retuyrns
static org.eclipse.swt.graphics.Image getImage(org.eclipse.ui.plugin.AbstractUIPlugin plugin, java.lang.String path)
          Finds and caches the iamge from the image descriptor for this particular plugin
static void linkButtonAndField(org.eclipse.swt.widgets.Button button, org.eclipse.swt.widgets.Text text, boolean clearFieldOnDisable)
          Sets a text box to enable/disable based on a button click.
static void pack(org.eclipse.swt.widgets.Shell shell)
          Re-packs it to the preferred size.
static org.eclipse.swt.graphics.FontData[] resizeFont(org.eclipse.swt.graphics.Font font, int size)
          Returns a version of the specified font, resized by the requested size
static void setFieldWithDefaultValue(org.eclipse.swt.widgets.Text text, java.lang.String defaultValue)
          Indicated that this field is a "default", and so it contains a default value and is shaded unless a new value is entered
static void setTableColumnWidths(org.eclipse.swt.widgets.Table table, double[] columnPercentages, int[] columnMinimums)
          Sets the columns of a table to percentage widths, rather than pixels
static void setTextAsPassword(org.eclipse.swt.widgets.Text text)
          Echos out "*" characters when typing in a text field.
static void setTextWidgetValue(org.eclipse.swt.widgets.Text widget, java.lang.String text)
          Sets the text of the text widget, but only if the value is non-null;
static boolean testWidgetValue(org.eclipse.swt.widgets.Combo widget, int validSelectionIndex)
          Tests if the widget value is empty.
static boolean testWidgetValue(org.eclipse.swt.widgets.Text widget)
          Tests if the widget value is empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SWTUtils

protected SWTUtils()
Protected constructor for utility class

Method Detail

colorBackground

public static void colorBackground(org.eclipse.swt.widgets.Text widget,
                                   java.lang.String testValue)
Colors the background of a text widget based on the test value

Parameters:
widget -
testValue -

setTextWidgetValue

public static void setTextWidgetValue(org.eclipse.swt.widgets.Text widget,
                                      java.lang.String text)
Sets the text of the text widget, but only if the value is non-null;

Parameters:
widget - the widget to set text for
text - the text to set

testWidgetValue

public static boolean testWidgetValue(org.eclipse.swt.widgets.Text widget)
Tests if the widget value is empty. If so, it adds an error color to the background of the cell;

Parameters:
widget - the widget to set text for
Returns:
boolean

testWidgetValue

public static boolean testWidgetValue(org.eclipse.swt.widgets.Combo widget,
                                      int validSelectionIndex)
Tests if the widget value is empty. If so, it adds an error color to the background of the cell;

Parameters:
widget - the widget to set text for
validSelectionIndex - the first item that is a "valid" selection
Returns:
boolean

centerAndPack

public static void centerAndPack(org.eclipse.swt.widgets.Shell shell,
                                 org.eclipse.swt.widgets.Shell parent)
Centers the shell on screen, and re-packs it to the preferred size. Packing is necessary as otherwise dialogs tend to get cut off on the Mac

Parameters:
shell - The shell to center
parent - The shell to center within

center

public static void center(org.eclipse.swt.widgets.Shell shell,
                          org.eclipse.swt.widgets.Shell parent)
Centers the shell on screen.

Parameters:
shell - The shell to center
parent - The shell to center within

pack

public static void pack(org.eclipse.swt.widgets.Shell shell)
Re-packs it to the preferred size. Packing is necessary as otherwise dialogs tend to get cut off on the Mac

Parameters:
shell - The shell to center

setTextAsPassword

public static void setTextAsPassword(org.eclipse.swt.widgets.Text text)
Echos out "*" characters when typing in a text field. This simulates a SWT.PASSWORD field, which does not work on the Mac.

Parameters:
text -

setFieldWithDefaultValue

public static void setFieldWithDefaultValue(org.eclipse.swt.widgets.Text text,
                                            java.lang.String defaultValue)
Indicated that this field is a "default", and so it contains a default value and is shaded unless a new value is entered

Parameters:
text - The text widget to designate as "default"
defaultValue - The default string value to use

linkButtonAndField

public static void linkButtonAndField(org.eclipse.swt.widgets.Button button,
                                      org.eclipse.swt.widgets.Text text,
                                      boolean clearFieldOnDisable)
Sets a text box to enable/disable based on a button click. Generally this is used to clear a text field based on a checkbox

Parameters:
button - the button to test for the selection state
text - the text field to clear
clearFieldOnDisable - do we blank out the text field if its disabled?

setTableColumnWidths

public static void setTableColumnWidths(org.eclipse.swt.widgets.Table table,
                                        double[] columnPercentages,
                                        int[] columnMinimums)
Sets the columns of a table to percentage widths, rather than pixels

Parameters:
table - The table to modify
columnPercentages - The array of percentage widths (ex. 0.2 = 20%). Does not need to equal 100%.
columnMinimums - The array of minimum pixel widths for each column. 0 indicates whatever width works.

calculateColumnPercents

public static double[] calculateColumnPercents(org.eclipse.swt.widgets.Table table,
                                               double padding)
Calculates the percentage width of each column in the table relative to the total table size

Parameters:
table - the table to compute
padding - a padding value to add to each table cell to space out the display a bit
Returns:
the array of values

calculateColumnWidths

public static int[] calculateColumnWidths(org.eclipse.swt.widgets.Table table)
Calculates the width of each column in the table

Parameters:
table - the table to compute
Returns:
the array of values

getDefaultSmallFont

public static org.eclipse.swt.graphics.Font getDefaultSmallFont()
Retuyrns

Returns:

getDefaultLargeFont

public static org.eclipse.swt.graphics.Font getDefaultLargeFont()
Retuyrns

Returns:

resizeFont

public static org.eclipse.swt.graphics.FontData[] resizeFont(org.eclipse.swt.graphics.Font font,
                                                             int size)
Returns a version of the specified font, resized by the requested size

Parameters:
font - The font to resize
size - The font size
Returns:

getImage

public static org.eclipse.swt.graphics.Image getImage(org.eclipse.ui.plugin.AbstractUIPlugin plugin,
                                                      java.lang.String path)
Finds and caches the iamge from the image descriptor for this particular plugin

Parameters:
plugin - The plugin to search
path - The path to the image
Returns:
The image, or null if not found