|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uic.layout.NaturalLayout
NaturalLayout is a layout manager that arranges components in rows and columns like a spreadsheet. NaturalLayout allows each row or column to be a different size. A row or column can be given an absolute size in pixels, or it can grow and shrink according to the widgets that are contained.
Using spreadsheet terminology, a cell is the intersection of a row and column. Cells have finite, non-negative sizes measured in pixels. The dimensions of a cell depend solely upon the dimensions of its row and column.
A component occupies a rectangular group of one or more cells. If the component occupies more than one cell, the component is resized to fit perfectly in the rectangular region of cells. If the component occupies a single cell, it can be aligned in four ways within that cell.
A single cell component can be stretched horizontally to fit the cell (full justification), or it can be placed in the center of the cell. The component could also be left justified or right justified. Similarly, the component can be full, center, top, or bottom justified in the vertical.
Constraints
,
Serialized FormField Summary | |
static int |
ALIGN_BOTTOM
|
static int |
ALIGN_CENTER
|
static int |
ALIGN_FULL
|
static int |
ALIGN_LEFT
|
static int |
ALIGN_RIGHT
|
static int |
ALIGN_TOP
|
protected int[] |
columnOffset
Offsets of columns in pixels. |
protected int[] |
columnSize
Widths of columns in pixels |
protected double[] |
columnSpec
Widths of columns expressed in absolute and relative terms |
protected static double[][] |
DEFAULT_SIZE
Default row/column size |
protected boolean |
dirty
Indicates whether or not the size of the cells are known for the last known size of the container. |
static double |
FILL
|
protected Vector |
list
List of components and their sizes |
protected int |
margin
Margin/spacing |
protected Dimension |
maximumSize
|
static double |
MINIMUM
|
protected Dimension |
minimumSize
|
protected int |
oldHeight
Previous known height of the container |
protected int |
oldWidth
Previous known width of the container |
static double |
PREFERRED
|
protected Dimension |
preferredSize
|
protected int[] |
rowOffset
Offsets of rows in pixels. |
protected int[] |
rowSize
Heights of rows in pixels |
protected double[] |
rowSpec
Heights of rows expressed in absolute and relative terms |
static int |
SIZE_POLICY_EXPANDING
|
static int |
SIZE_POLICY_FIXED
|
static int |
SIZE_POLICY_IGNORED
|
static int |
SIZE_POLICY_MAXIMUM
|
static int |
SIZE_POLICY_MINIMUM
|
static int |
SIZE_POLICY_MINIMUM_EXPANDING
|
static int |
SIZE_POLICY_PREFERRED
|
protected int |
spacing
Margin/spacing |
Constructor Summary | |
NaturalLayout()
Constructs an instance of NaturalLayout. |
|
NaturalLayout(double[][] size)
Constructs an instance of NaturalLayout. |
|
NaturalLayout(int columns,
int rows)
Constructs an instance of NaturalLayout with a specified row/column size. |
Method Summary | |
void |
addLayoutComponent(Component component,
Object constraint)
Adds the specified component with the specified name to the layout. |
void |
addLayoutComponent(String name,
Component component)
Adds the specified component with the specified name to the layout. |
protected void |
calculateSize(Container container)
Calculates the sizes of the rows and columns based on the absolute and relative sizes specified in rowSpec and columnSpec
and the size of the container. |
void |
deleteColumn(int i)
Deletes a column in this layout. |
void |
deleteRow(int i)
Deletes a row in this layout. |
void |
drawGrid(Container container,
Graphics g)
Draws a grid on the given container. |
protected double |
ensureCorrectSpecSize(double size)
Checks if size of a row/col is correct. |
double |
getColumn(int i)
Gets the width of a single column in this layout. |
protected Entry |
getEntryContaining(Component c)
Return the entry that contains argument component. |
float |
getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis. |
float |
getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis. |
int |
getMargin()
|
int |
getNumColumns()
Gets the number of columns in this layout. |
int |
getNumRows()
Gets the number of rows in this layout. |
double |
getRow(int i)
Gets the sizes of a row in this layout. |
int |
getSpacing()
|
void |
insertColumn(int i)
Convinience function for the above one. |
void |
insertColumn(int i,
double size)
Inserts a column in this layout. |
void |
insertRow(int i)
Convinience function for the above one. |
void |
insertRow(int i,
double size)
Inserts a row in this layout. |
void |
invalidateLayout(Container target)
Invalidates the layout. |
void |
layoutContainer(Container container)
To lay out the specified container using this layout. |
protected void |
layoutIsChanged()
Remove all cached data. |
protected static int |
max2(int a,
int b)
|
Dimension |
maximumLayoutSize(Container component)
Returns the maximum dimensions for this layout given the components in the specified target container. |
Dimension |
minimumLayoutSize(Container container)
Determines the minimum size of the container argument using this layout. |
protected void |
placeWidget(Sizes minimumSizes,
Sizes preferredSizes,
Sizes maximumSizes,
Entry entry)
Helper method for calculateSize |
Dimension |
preferredLayoutSize(Container container)
Determines the preferred size of the container argument using this layout. |
void |
removeLayoutComponent(Component component)
Removes the specified component from the layout. |
void |
setColumn(int i,
double size)
Adjusts the width of a single column in this layout. |
void |
setConstraints(Component component,
Constraints constraint)
Sets the constraints of a given component. |
void |
setMargin(int margin)
Set margin. |
void |
setRow(int i,
double size)
Adjusts the height of a single row in this layout. |
void |
setSpacing(int spacing)
Set spacing. |
String |
toString()
Converts this NaturalLayout to a string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int ALIGN_LEFT
public static final int ALIGN_TOP
public static final int ALIGN_CENTER
public static final int ALIGN_FULL
public static final int ALIGN_BOTTOM
public static final int ALIGN_RIGHT
public static final double FILL
public static final double PREFERRED
public static final double MINIMUM
public static final int SIZE_POLICY_FIXED
public static final int SIZE_POLICY_MINIMUM
public static final int SIZE_POLICY_MAXIMUM
public static final int SIZE_POLICY_PREFERRED
public static final int SIZE_POLICY_MINIMUM_EXPANDING
public static final int SIZE_POLICY_EXPANDING
public static final int SIZE_POLICY_IGNORED
protected static final double[][] DEFAULT_SIZE
protected double[] columnSpec
protected double[] rowSpec
protected int[] columnSize
protected int[] rowSize
protected int[] columnOffset
protected int[] rowOffset
protected Vector list
protected boolean dirty
protected int oldWidth
protected int oldHeight
protected Dimension minimumSize
protected Dimension preferredSize
protected Dimension maximumSize
protected int margin
protected int spacing
Constructor Detail |
public NaturalLayout()
public NaturalLayout(int columns, int rows)
columns
- the number of columns in this layout.rows
- the number of rows in this layout.public NaturalLayout(double[][] size)
size
- widths of columns and heights of rows in the format,
{{col0, col1, col2, ..., colN}, {row0, row1, row2, ..., rowM}}
If this parameter is invalid, the NaturalLayout will have
exactly one row and one column.Method Detail |
public void setConstraints(Component component, Constraints constraint)
component
- desired component. This parameter cannot be null.constraint
- new set of constraints. This parameter cannot be null.public void setColumn(int i, double size)
i
- zero-based index of column to set. If this parameter is not
valid, an ArrayOutOfBoundsException will be thrown.size
- width of the column. This parameter cannot be null.getColumn(int)
public void setRow(int i, double size)
i
- zero-based index of row to set. If this parameter is not
valid, an ArrayOutOfBoundsException will be thrown.size
- height of the row. This parameter cannot be null.public double getColumn(int i)
i
- zero-based index of row to get. If this parameter is not valid,
an ArrayOutOfBoundsException will be thrown.
public double getRow(int i)
i
- zero-based index of row to get. If this parameter is not valid,
an ArrayOutOfBoundsException will be thrown.
setRow(int, double)
public int getNumColumns()
public int getNumRows()
public void insertColumn(int i, double size)
setColumn
.
i
- zero-based index at which to insert the column.size
- size of the column to be insertedsetColumn(int, double)
,
deleteColumn(int)
public void insertColumn(int i)
i
- column to insert. When the layout has 3 columns and i = 4 then 2 columns will be
inserted. Making sure that afterwards 5 columns exist (i=4 means 5 columns since we start
counting at 0).public void insertRow(int i, double size)
setRow
.
i
- zero-based index at which to insert the column.size
- size of the row to be insertedsetRow(int, double)
,
deleteRow(int)
public void insertRow(int i)
i
- row to insert. When the layout has 3 rows and i = 4 then 2 rows will be
inserted. Making sure that afterwards 5 rows exist (i=4 means 5 rows since we start
counting at 0).public void deleteColumn(int i)
setColumn
.
i
- zero-based index of column to deletesetColumn(int, double)
,
deleteColumn(int)
public void deleteRow(int i)
setRow
. There must be at least two rows in order
to delete a row.
i
- zero-based index of column to deletesetRow(int, double)
,
deleteRow(int)
protected void layoutIsChanged()
protected double ensureCorrectSpecSize(double size)
protected Entry getEntryContaining(Component c) throws IllegalArgumentException
c
- that this layouter should contain.
IllegalArgumentException
public String toString()
public void drawGrid(Container container, Graphics g)
container
- container using this NaturalLayoutg
- graphics content of container (can be offscreen)protected void calculateSize(Container container)
rowSpec
and columnSpec
and the size of the container. The result is stored in rowSize
and columnSize
.
container
- container using this NaturalLayoutprotected void placeWidget(Sizes minimumSizes, Sizes preferredSizes, Sizes maximumSizes, Entry entry)
public void layoutContainer(Container container)
User code should not have to call this method directly.
layoutContainer
in interface LayoutManager
container
- container being served by this layout managerpublic Dimension preferredLayoutSize(Container container)
preferredLayoutSize
in interface LayoutManager
container
- container being served by this layout manager
public Dimension minimumLayoutSize(Container container)
minimumLayoutSize
in interface LayoutManager
container
- container being served by this layout manager
public void addLayoutComponent(String name, Component component)
addLayoutComponent
in interface LayoutManager
name
- indicates entry's position and anchorcomponent
- component to addpublic void addLayoutComponent(Component component, Object constraint)
addLayoutComponent
in interface LayoutManager2
component
- component to addconstraint
- indicates entry's position and alignmentpublic void removeLayoutComponent(Component component)
removeLayoutComponent
in interface LayoutManager
component
- component being removedpublic Dimension maximumLayoutSize(Container component)
maximumLayoutSize
in interface LayoutManager2
component
- the component which needs to be laid outpublic float getLayoutAlignmentX(Container parent)
getLayoutAlignmentX
in interface LayoutManager2
public float getLayoutAlignmentY(Container parent)
getLayoutAlignmentY
in interface LayoutManager2
public void invalidateLayout(Container target)
invalidateLayout
in interface LayoutManager2
public void setMargin(int margin)
public void setSpacing(int spacing)
public int getSpacing()
public int getMargin()
protected static int max2(int a, int b)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |