libgdx API

com.badlogic.gdx.scenes.scene2d.ui.tablelayout
Class BaseTableLayout<T>

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.ui.tablelayout.BaseTableLayout<T>
Direct Known Subclasses:
TableLayout

public abstract class BaseTableLayout<T>
extends java.lang.Object

Base layout functionality. Subclasses must implement newTableLayout().


Field Summary
 int align
           
static int BOTTOM
           
 Cell cellDefaults
          The cell values that will be used as the defaults for all cells.
 java.util.ArrayList<Cell> cells
          The cells for this table only.
static int CENTER
           
 java.lang.String debug
           
static java.lang.String DEBUG_ALL
           
static java.lang.String DEBUG_CELL
           
static java.lang.String DEBUG_TABLE
           
static java.lang.String DEBUG_WIDGET
           
 java.lang.String height
           
static int LEFT
           
static java.lang.String MAX
           
static java.lang.String MIN
           
 java.lang.String padBottom
           
 java.lang.String padLeft
           
 java.lang.String padRight
           
 java.lang.String padTop
           
static java.lang.String PREF
           
static int RIGHT
           
 int tableLayoutHeight
           
 int tableLayoutWidth
           
 int tableLayoutX
           
 int tableLayoutY
           
 int tableMinHeight
           
 int tableMinWidth
           
 int tablePrefHeight
           
 int tablePrefWidth
           
static int TOP
           
 java.lang.String width
           
static int X
           
static int Y
           
 
Constructor Summary
BaseTableLayout()
           
 
Method Summary
 Cell addCell(T widget)
          Adds a new cell to the table with the specified widget.
abstract  void addChild(T parent, T child, java.lang.String layoutString)
          Adds a child to the specified parent.
static void addClassPrefix(java.lang.String prefix)
          Used by newWidget(String) to resolve class names.
abstract  void addDebugRectangle(java.lang.String type, int x, int y, int w, int h)
          Adds a rectangle that should be drawn for debugging.
 void clear()
          Removes all widgets and cells from the table and resets the cell and column defaults.
abstract  void clearDebugRectangles()
          Clears all debugging rectangles.
protected  java.lang.Object convertType(java.lang.Object parentObject, java.lang.String value, java.lang.Class type, java.lang.String memberName)
          Attempts to convert a string value to a non-string type to match a field or method on the specified parentObject.
 Cell getCell(java.lang.String name)
          Returns the cell with the specified name, anywhere in the table hierarchy.
 Cell getCell(T widget)
          Returns the cell for the specified widget, anywhere in the table hierarchy.
 java.util.List<Cell> getCells()
          Returns all cells, anywhere in the table hierarchy.
 java.util.List<Cell> getCells(java.lang.String namePrefix)
          Returns all cells with the specified name prefix, anywhere in the table hierarchy.
 Cell getColumnDefaults(int column)
          Gets the cell values that will be used as the defaults for all cells in the specified column.
abstract  int getMaxHeight(T widget)
           
abstract  int getMaxWidth(T widget)
           
abstract  int getMinHeight(T widget)
           
abstract  int getMinWidth(T widget)
           
abstract  int getPrefHeight(T widget)
           
abstract  int getPrefWidth(T widget)
           
abstract  T getTable()
          Returns the widget that will be laid out.
 T getWidget(java.lang.String name)
          Returns the widget with the specified name, anywhere in the table hierarchy.
 java.util.List<T> getWidgets()
          Returns all widgets, anywhere in the table hierarchy.
 java.util.List<T> getWidgets(java.lang.String namePrefix)
          Returns all widgets with the specified name prefix, anywhere in the table hierarchy.
 int height(float value)
          Interprets the specified value as a size.
 int height(java.lang.String value)
          Interprets the specified value as a height.
abstract  void invalidate()
          Marks the TableLayout as needing to layout again.
 void layout()
          Performs the actual layout.
protected  T newInstance(java.lang.String className)
          Returns an instance of the specified class.
abstract  T newStack()
          Returns a new widget that sizes all of its children to its size.
abstract  BaseTableLayout newTableLayout()
          Returns a new TableLayout that will be nested under this table.
 T newWidget(java.lang.String className)
          Creates a new widget from the specified class name.
 void parse(java.lang.String tableDescription)
          Parses a table description and adds the widgets and cells to the table.
 T register(java.lang.String name, T widget)
          Sets the name of a widget so it may be referenced in parse(String).
abstract  void removeChild(T parent, T child)
           
 void setCellProperty(Cell c, java.lang.String name, java.util.List<java.lang.String> values)
          Sets a property on the cell.
 void setParent(BaseTableLayout parent)
          Sets that this table is nested under the specified parent.
 void setProperty(T object, java.lang.String name, java.util.List<java.lang.String> values)
          Sets a property on the widget.
 void setTableProperty(java.lang.String name, java.util.List<java.lang.String> values)
          Sets a property on the table.
 void setWidget(Cell cell, T widget)
           
 void setWidget(java.lang.String name, T widget)
          Sets the widget in the cell with the specified name.
 Cell startRow()
          Indicates that subsequent cells should be added to a new row and returns the cell values that will be used as the defaults for all cells in the new row.
protected  java.lang.String validateSize(java.lang.String size)
          Validates the specified size is properly formatted.
 int width(float value)
          Interprets the specified value as a size.
 int width(java.lang.String value)
          Interprets the specified value as a width.
 T wrap(java.lang.Object object)
          Wraps the specified object in a widget.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CENTER

public static final int CENTER
See Also:
Constant Field Values

TOP

public static final int TOP
See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
See Also:
Constant Field Values

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

X

public static final int X
See Also:
Constant Field Values

Y

public static final int Y
See Also:
Constant Field Values

MIN

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

PREF

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

MAX

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

DEBUG_ALL

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

DEBUG_TABLE

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

DEBUG_CELL

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

DEBUG_WIDGET

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

width

public java.lang.String width

height

public java.lang.String height

padTop

public java.lang.String padTop

padLeft

public java.lang.String padLeft

padBottom

public java.lang.String padBottom

padRight

public java.lang.String padRight

align

public int align

debug

public java.lang.String debug

tableLayoutX

public int tableLayoutX

tableLayoutY

public int tableLayoutY

tableLayoutWidth

public int tableLayoutWidth

tableLayoutHeight

public int tableLayoutHeight

tableMinWidth

public int tableMinWidth

tableMinHeight

public int tableMinHeight

tablePrefWidth

public int tablePrefWidth

tablePrefHeight

public int tablePrefHeight

cells

public final java.util.ArrayList<Cell> cells
The cells for this table only.


cellDefaults

public final Cell cellDefaults
The cell values that will be used as the defaults for all cells.

Constructor Detail

BaseTableLayout

public BaseTableLayout()
Method Detail

addChild

public abstract void addChild(T parent,
                              T child,
                              java.lang.String layoutString)
Adds a child to the specified parent.

Parameters:
layoutString - May be null.

removeChild

public abstract void removeChild(T parent,
                                 T child)

newTableLayout

public abstract BaseTableLayout newTableLayout()
Returns a new TableLayout that will be nested under this table. The parent of the returned layout must be set.


newStack

public abstract T newStack()
Returns a new widget that sizes all of its children to its size.


getMinWidth

public abstract int getMinWidth(T widget)

getMinHeight

public abstract int getMinHeight(T widget)

getPrefWidth

public abstract int getPrefWidth(T widget)

getPrefHeight

public abstract int getPrefHeight(T widget)

getMaxWidth

public abstract int getMaxWidth(T widget)

getMaxHeight

public abstract int getMaxHeight(T widget)

invalidate

public abstract void invalidate()
Marks the TableLayout as needing to layout again.


clearDebugRectangles

public abstract void clearDebugRectangles()
Clears all debugging rectangles.


addDebugRectangle

public abstract void addDebugRectangle(java.lang.String type,
                                       int x,
                                       int y,
                                       int w,
                                       int h)
Adds a rectangle that should be drawn for debugging.


getTable

public abstract T getTable()
Returns the widget that will be laid out.


setParent

public void setParent(BaseTableLayout parent)
Sets that this table is nested under the specified parent. This allows the root table to look up widgets and cells in nested tables, for convenience.


register

public T register(java.lang.String name,
                  T widget)
Sets the name of a widget so it may be referenced in parse(String).


parse

public void parse(java.lang.String tableDescription)
Parses a table description and adds the widgets and cells to the table.


addCell

public Cell addCell(T widget)
Adds a new cell to the table with the specified widget.

Parameters:
widget - May be null to add a cell without a widget.

startRow

public Cell startRow()
Indicates that subsequent cells should be added to a new row and returns the cell values that will be used as the defaults for all cells in the new row.


getColumnDefaults

public Cell getColumnDefaults(int column)
Gets the cell values that will be used as the defaults for all cells in the specified column.


clear

public void clear()
Removes all widgets and cells from the table and resets the cell and column defaults.


getWidget

public T getWidget(java.lang.String name)
Returns the widget with the specified name, anywhere in the table hierarchy.


getWidgets

public java.util.List<T> getWidgets()
Returns all widgets, anywhere in the table hierarchy.


getWidgets

public java.util.List<T> getWidgets(java.lang.String namePrefix)
Returns all widgets with the specified name prefix, anywhere in the table hierarchy.


getCell

public Cell getCell(T widget)
Returns the cell for the specified widget, anywhere in the table hierarchy.


getCell

public Cell getCell(java.lang.String name)
Returns the cell with the specified name, anywhere in the table hierarchy.


getCells

public java.util.List<Cell> getCells(java.lang.String namePrefix)
Returns all cells with the specified name prefix, anywhere in the table hierarchy.


getCells

public java.util.List<Cell> getCells()
Returns all cells, anywhere in the table hierarchy.


setWidget

public void setWidget(Cell cell,
                      T widget)

setWidget

public void setWidget(java.lang.String name,
                      T widget)
Sets the widget in the cell with the specified name.


layout

public void layout()
Performs the actual layout.


validateSize

protected java.lang.String validateSize(java.lang.String size)
Validates the specified size is properly formatted. A size is valid if it can be parsed by width(String) and height(String). All sizes that are stored as strings pass through this method, providing a hook to validate sizes at parse time rather than layout time. The default implementation just returns the specified string. If the specified String is invalid, an exception should be thrown.


newWidget

public T newWidget(java.lang.String className)
Creates a new widget from the specified class name. This method can be overriden to create widgets using shortcut names (eg, "button"). The default implementation creates an instance of the class and calls wrap(Object).

Throws:
java.lang.RuntimeException - if the class could be found or otherwise failed to be instantiated.
See Also:
addClassPrefix(String)

newInstance

protected T newInstance(java.lang.String className)
                 throws java.lang.Exception
Returns an instance of the specified class. The default uses Class.forName(className).newInstance();

Throws:
java.lang.Exception - if the class cannot be found or instantiated.

wrap

public T wrap(java.lang.Object object)
Wraps the specified object in a widget. The default implementation handles the object being a TableLayout or widget. If the object is null, a placeholder widget to use for empty cells must be returned. If the object is a string, a label widget must be returned. Otherwise, the object can be any other class that was added to the table (eg, a Swing LayoutManager would be wrapped in a JPanel).

Throws:
java.lang.RuntimeException - if the object could not be wrapped.

setProperty

public void setProperty(T object,
                        java.lang.String name,
                        java.util.List<java.lang.String> values)
Sets a property on the widget. This is called for widget properties specified in the table description. The default implementation attempts to find a method, bean setter method, or field that will accept the specified values.

Throws:
java.lang.RuntimeException - if the property could not be set.

setTableProperty

public void setTableProperty(java.lang.String name,
                             java.util.List<java.lang.String> values)
Sets a property on the table. This is called for table properties specified in the table description.

Throws:
java.lang.RuntimeException - if the property could not be set.

setCellProperty

public void setCellProperty(Cell c,
                            java.lang.String name,
                            java.util.List<java.lang.String> values)
Sets a property on the cell. This is called for cell properties specified in the table description.

Throws:
java.lang.RuntimeException - if the property could not be set.

width

public int width(java.lang.String value)
Interprets the specified value as a width. This can be used to scale all sizes applied to a cell, implement size units (eg, 23px or 23em), etc. The default implementation converts to an int and calls width(float). Zero is used for null and empty string. If the suffix is "%", the value is converted to an int, divided by 100, and multiplied by tableLayoutWidth. If the suffix is "px", the value is converted to int without the suffix and returned unscaled.

Parameters:
value - May be null.

width

public int width(float value)
Interprets the specified value as a size. This can be used to scale all sizes applied to a cell. The default implementation just casts to int.


height

public int height(java.lang.String value)
Interprets the specified value as a height. This can be used to scale all sizes applied to a cell, implement size units (eg, 23px or 23em), etc. The default implementation converts to an int and calls height(float). Zero is used for null and empty string. If the suffix is "%", the value is converted to an int, divided by 100, and multiplied by tableLayoutHeight. If the suffix is "px", the value is converted to int without the suffix and returned unscaled.

Parameters:
value - May be null.

height

public int height(float value)
Interprets the specified value as a size. This can be used to scale all sizes applied to a cell. The default implementation just casts to int.


convertType

protected java.lang.Object convertType(java.lang.Object parentObject,
                                       java.lang.String value,
                                       java.lang.Class type,
                                       java.lang.String memberName)
Attempts to convert a string value to a non-string type to match a field or method on the specified parentObject. The default implementation tries all primitive type wrappers and looks for a static field with the name on both the specified type and the parentObject's type.

Returns:
the converted type, or null if it could not be converted.

addClassPrefix

public static void addClassPrefix(java.lang.String prefix)
Used by newWidget(String) to resolve class names.


libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)