public final class GridDataFactory extends Object
GridDataFactory instances are created using one of the static methods on this class.
Example usage:
////////////////////////////////////////////////////////////
// Example 1: Typical grid data for a non-wrapping label
// GridDataFactory version
GridDataFactory.fillDefaults().applyTo(myLabel);
// Equivalent SWT version
GridData labelData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
myLabel.setLayoutData(labelData);
///////////////////////////////////////////////////////////
// Example 2: Typical grid data for a wrapping label
// GridDataFactory version
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.CENTER)
.hint(150, SWT.DEFAULT)
.grab(true, false)
.applyTo(wrappingLabel);
// Equivalent SWT version
GridData wrappingLabelData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
wrappingLabelData.minimumWidth = 1;
wrappingLabelData.widthHint = 150;
wrappingLabel.setLayoutData(wrappingLabelData);
//////////////////////////////////////////////////////////////
// Example 3: Typical grid data for a scrollable control (a list box, tree, table, etc.)
// GridDataFactory version
GridDataFactory.fillDefaults().grab(true, true).hint(150, 150).applyTo(listBox);
// Equivalent SWT version
GridData listBoxData = new GridData(GridData.FILL_BOTH);
listBoxData.widthHint = 150;
listBoxData.heightHint = 150;
listBoxData.minimumWidth = 1;
listBoxData.minimumHeight = 1;
listBox.setLayoutData(listBoxData);
/////////////////////////////////////////////////////////////
// Example 4: Typical grid data for a button
// GridDataFactory version
Point preferredSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
Point hint = Geometry.max(LayoutConstants.getMinButtonSize(), preferredSize);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(hint).applyTo(button);
// Equivalent SWT version
Point preferredSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
Point hint = Geometry.max(LayoutConstants.getMinButtonSize(), preferredSize);
GridData buttonData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
buttonData.widthHint = hint.x;
buttonData.heightHint = hint.y;
button.setLayoutData(buttonData);
/////////////////////////////////////////////////////////////
// Example 5: Generated GridData
// Generates GridData a wrapping label that spans 2 columns
GridDataFactory.generate(wrappingLabel, 2, 1);
// Generates GridData for a listbox. and adjusts the preferred size to 300x400 pixels
GridDataFactory.defaultsFor(listBox).hint(300, 400).applyTo(listBox);
// Generates GridData equivalent to example 4
GridDataFactory.generate(button, 1, 1);
Modifier and Type | Method and Description |
---|---|
GridDataFactory |
align(int hAlign,
int vAlign)
Sets the alignment of the control within its cell.
|
void |
applyTo(Control control)
Sets the layout data on the given control.
|
GridDataFactory |
copy()
Creates a copy of the receiver.
|
static GridData |
copyData(GridData data)
Returns a copy of the given GridData
|
GridData |
create()
Creates a new GridData instance.
|
static GridDataFactory |
createFrom(GridData data)
Creates a new GridDataFactory that creates copies of the given GridData
by default.
|
static GridDataFactory |
defaultsFor(Control theControl)
Returns a GridDataFactory initialized with heuristicly generated defaults for the given control.
|
GridDataFactory |
exclude(boolean shouldExclude)
Instructs the GridLayout to ignore this control when performing layouts.
|
static GridDataFactory |
fillDefaults()
Creates a GridDataFactory initialized with defaults that will cause
the control to fill its cell.
|
static void |
generate(Control theControl,
int hSpan,
int vSpan)
Generates layout data to the given control, given the number of cells
spanned by the control.
|
static void |
generate(Control theControl,
Point span)
Generates layout data to the given control, given the number of cells
spanned by the control.
|
GridDataFactory |
grab(boolean horizontal,
boolean vertical)
Determines whether extra horizontal or vertical space should be allocated to
this control's column when the layout resizes.
|
GridDataFactory |
hint(int xHint,
int yHint)
Sets the width and height hints.
|
GridDataFactory |
hint(Point hint)
Sets the width and height hints.
|
GridDataFactory |
indent(int hIndent,
int vIndent)
Sets the indent of the control within the cell.
|
GridDataFactory |
indent(Point indent)
Sets the indent of the control within the cell.
|
GridDataFactory |
minSize(int minX,
int minY)
Sets the minimum size for the control.
|
GridDataFactory |
minSize(Point min)
Sets the minimum size for the control.
|
GridDataFactory |
span(int hSpan,
int vSpan)
Sets the GridData span.
|
GridDataFactory |
span(Point span)
Sets the GridData span.
|
static GridDataFactory |
swtDefaults()
Creates a new GridDataFactory initialized with the SWT defaults.
|
public static GridDataFactory swtDefaults()
Initial values are:
fillDefaults()
public static GridDataFactory createFrom(GridData data)
data
- GridData to copypublic static GridDataFactory fillDefaults()
Initial values are:
swtDefaults()
public static GridDataFactory defaultsFor(Control theControl)
This method is intended for situations where generateLayout is generating layout data for a particular control that is not quite right for the desired layout. This allows callers to start with the generated values and tweak one or two settings before applying the GridData to the control.
theControl
- GridLayoutFactory.generateLayout(org.eclipse.swt.widgets.Composite)
public static void generate(Control theControl, int hSpan, int vSpan)
The generated layout data is the same as what would be generated by GridLayoutFactory.generateLayout, except that the span is configurable
theControl
- hSpan
- number of columns spanned by the controlvSpan
- number of rows spanned by the controlGridLayoutFactory.generateLayout(org.eclipse.swt.widgets.Composite)
public static void generate(Control theControl, Point span)
The generated layout data is the same as what would be generated by GridLayoutFactory.generateLayout, except that the span is configurable
theControl
- span
- The x coordinate indicates the number of
columns spanned, and the y coordinate indicates the number of rows.GridLayoutFactory.generateLayout(org.eclipse.swt.widgets.Composite)
public GridDataFactory span(int hSpan, int vSpan)
hSpan
- number of columns spanned by the controlvSpan
- number of rows spanned by the controlpublic GridDataFactory span(Point span)
span
- the new span. The x coordinate indicates the number of
columns spanned, and the y coordinate indicates the number of rows.public GridDataFactory hint(int xHint, int yHint)
xHint
- horizontal hint (pixels), or SWT.DEFAULT to use the control's preferred sizeyHint
- vertical hint (pixels), or SWT.DEFAULT to use the control's preferred sizepublic GridDataFactory hint(Point hint)
hint
- size (pixels) to be used instead of the control's preferred size. If
the x or y values are set to SWT.DEFAULT, the control's computeSize() method will
be used to obtain that dimension of the preferred size.public GridDataFactory align(int hAlign, int vAlign)
hAlign
- horizontal alignment. One of SWT.BEGINNING, SWT.CENTER, SWT.END, or SWT.FILL.vAlign
- vertical alignment. One of SWT.BEGINNING, SWT.CENTER, SWT.END, or SWT.FILL.public GridDataFactory indent(int hIndent, int vIndent)
hIndent
- distance to move to the right (negative values move left)vIndent
- distance to move down (negative values move up)public GridDataFactory indent(Point indent)
indent
- offset to move the controlpublic GridDataFactory grab(boolean horizontal, boolean vertical)
horizontal
- true if the control's column should grow horizontallyvertical
- true if the control's row should grow verticallypublic GridDataFactory minSize(int minX, int minY)
minX
- minimum a value of 1 or more is a horizontal size of the control (pixels).
SWT.DEFAULT indicates that the control's preferred size should be used. A size
of 0 has special semantics defined by GridLayout.minY
- minimum a value of 1 or more is a vertical size of the control (pixels). SWT.DEFAULT
indicates that the control's preferred size should be used. A size
of 0 has special semantics defined by GridLayout.public GridDataFactory minSize(Point min)
min
- minimum size of the controlpublic GridDataFactory exclude(boolean shouldExclude)
shouldExclude
- true iff the control should be excluded from layoutspublic GridData create()
public GridDataFactory copy()
public static GridData copyData(GridData data)
data
- GridData to copypublic void applyTo(Control control)
control
- control whose layout data will be initialized
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.