de.matthiasmann.twl
Class DialogLayout

java.lang.Object
  extended by de.matthiasmann.twl.Widget
      extended by de.matthiasmann.twl.DialogLayout
Direct Known Subclasses:
ColorSelector, ColumnLayout, DatePicker, FileSelector

public class DialogLayout
extends Widget

A layout manager similar to Swing's GroupLayout This layout manager uses two independant layout groups: one for the horizontal axis one for the vertical axis. Every widget must be added to both the horizontal and the vertical group. When a widget is added to a group it will also be added as a child widget if it was not already added. You can add widgets to DialogLayout before adding them to a group to set the focus order. There are two kinds of groups: a sequential group which which behaves similar to BoxLayout a parallel group which alignes the start and size of each child Groups can be cascaded as a tree without restrictions. It is also possible to add widgets to DialogLayout without adding them to the layout groups. These widgets are then not touched by DialogLayout's layout system. When a widget is only added to either the horizontal or vertical groups and not both, then an IllegalStateException exception is created on layout. To help debugging the group construction you can set the system property "debugLayoutGroups" to "true" which will collect additional stack traces to help locate the source of the error.

See Also:
createParallelGroup(), createSequentialGroup()

Nested Class Summary
static class DialogLayout.Gap
           
 class DialogLayout.Group
           
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Widget
Widget.OffscreenMouseAdjustments, Widget.RenderOffscreen
 
Field Summary
protected  boolean addDefaultGaps
           
protected  boolean blockInvalidateLayoutTree
           
static int DEFAULT_GAP
          Symbolic constant to refer to "default gap".
protected  Dimension defaultGap
           
protected  boolean includeInvisibleWidgets
           
protected  boolean isPrepared
           
static int LARGE_GAP
          Symbolic constant to refer to "large gap".
protected  Dimension largeGap
           
static int MEDIUM_GAP
          Symbolic constant to refer to "medium gap".
protected  Dimension mediumGap
           
protected  ParameterMap namedGaps
           
protected  boolean redoDefaultGaps
           
static int SMALL_GAP
          Symbolic constant to refer to "small gap".
protected  Dimension smallGap
           
protected  boolean warnOnIncomplete
           
 
Fields inherited from class de.matthiasmann.twl.Widget
STATE_DISABLED, STATE_HAS_FOCUSED_CHILD, STATE_HAS_OPEN_POPUPS, STATE_KEYBOARD_FOCUS
 
Constructor Summary
DialogLayout()
          Creates a new DialogLayout widget.
 
Method Summary
 void addDefaultGaps()
          Adds theme dependant default gaps to all groups.
 void adjustSize()
          Auto adjust the size of this widget based on it's preferred size.
protected  void afterAddToGUI(GUI gui)
          Called after this widget has been added to a GUI tree.
protected  void applyTheme(ThemeInfo themeInfo)
          Apply the given theme.
protected  void applyThemeDialogLayout(ThemeInfo themeInfo)
           
protected  void childVisibilityChanged(Widget child)
          Called when the visibility state of a child was changed.
 DialogLayout.Group createParallelGroup()
          Creates a new parallel group.
 DialogLayout.Group createParallelGroup(DialogLayout.Group... groups)
          Creates a parallel group and adds the specified groups.
 DialogLayout.Group createParallelGroup(Widget... widgets)
          Creates a parallel group and adds the specified widgets.
 DialogLayout.Group createSequentialGroup()
          Creates a new sequential group.
 DialogLayout.Group createSequentialGroup(DialogLayout.Group... groups)
          Creates a sequential group and adds the specified groups.
 DialogLayout.Group createSequentialGroup(Widget... widgets)
          Creates a sequential group and adds the specified widgets.
protected  void doLayout()
           
 Dimension getDefaultGap()
           
 DialogLayout.Group getHorizontalGroup()
           
 Dimension getLargeGap()
           
 Dimension getMediumGap()
           
 int getMinHeight()
          Returns the minimum height of the widget.
 int getMinWidth()
          Returns the minimum width of the widget.
 int getPreferredInnerHeight()
          Computes the preferred inner height (the size of the widget without the border) The default implementation uses the current position of the children.
 int getPreferredInnerWidth()
          Computes the preferred inner width (the size of the widget without the border) The default implementation uses the current position of the children.
 Dimension getSmallGap()
           
 DialogLayout.Group getVerticalGroup()
           
 void insertChild(Widget child, int index)
          Inserts a new child into this widget.
 void invalidateLayout()
          Called when something has changed which affected the layout of this widget.
 boolean isAddDefaultGaps()
           
 boolean isIncludeInvisibleWidgets()
           
protected  void layout()
          Called when the layoutInvalid flag is set.
protected  void layoutGroupsChanged()
           
protected  void maybeInvalidateLayoutTree()
           
protected  void paintWidget(GUI gui)
          Called by Widget.paint(de.matthiasmann.twl.GUI) after painting the background and before painting all children.
protected  void prepare()
           
protected  void recheckWidgets()
           
 void removeAllChildren()
          Removes all children of this widget.
 Widget removeChild(int index)
          Removes the specified child from this widget.
 void removeDefaultGaps()
          removes all default gaps from all groups.
 void setAddDefaultGaps(boolean addDefaultGaps)
          Determine whether default gaps should be added from the theme or not.
 void setDefaultGap(Dimension defaultGap)
           
 void setHorizontalGroup(DialogLayout.Group g)
          The horizontal group controls the position and size of all child widgets along the X axis.
 void setIncludeInvisibleWidgets(boolean includeInvisibleWidgets)
          Controls whether invisible widgets should be included in the layout or not.
 void setLargeGap(Dimension largeGap)
           
 void setMediumGap(Dimension mediumGap)
           
 void setSmallGap(Dimension smallGap)
           
 void setVerticalGroup(DialogLayout.Group g)
          The vertical group controls the position and size of all child widgets along the Y axis.
 boolean setWidgetAlignment(Widget widget, Alignment alignment)
          Sets the alignment of the specified widget.
protected  void sizeChanged()
          Called when the size of this widget has changed.
 
Methods inherited from class de.matthiasmann.twl.Widget
add, addActionMapping, addPropertyChangeListener, addPropertyChangeListener, allChildrenRemoved, applyThemeBackground, applyThemeBorder, applyThemeInputMap, applyThemeMaxSize, applyThemeMinSize, applyThemeMouseCursor, applyThemeOffscreenExtra, applyThemeOverlay, applyThemeTooltip, beforeRemoveFromGUI, borderChanged, canAcceptKeyboardFocus, childAdded, childInvalidateLayout, childRemoved, computeSize, destroy, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, focusFirstChild, focusLastChild, focusNextChild, focusPrevChild, getActionMap, getAnimationState, getBackground, getBorderBottom, getBorderHorizontal, getBorderLeft, getBorderRight, getBorderTop, getBorderVertical, getBottom, getChild, getChildAt, getChildIndex, getGUI, getHeight, getInnerBottom, getInnerHeight, getInnerRight, getInnerWidth, getInnerX, getInnerY, getInputMap, getKeyboardFocusOrder, getMaxHeight, getMaxWidth, getMouseCursor, getMouseCursor, getNumChildren, getOffscreenExtraBottom, getOffscreenExtraLeft, getOffscreenExtraRight, getOffscreenExtraTop, getOrCreateActionMap, getOverlay, getParent, getPreferredHeight, getPreferredWidth, getRenderOffscreen, getRight, getRootWidget, getTheme, getThemePath, getThemeTooltipContent, getTintAnimator, getTooltipContent, getTooltipContentAt, getWidgetAt, getWidth, getX, getY, giveupKeyboardFocus, handleEvent, handleKeyStrokeAction, hasKeyboardFocus, hasOpenPopups, hasSharedAnimationState, invalidateLayoutLocally, isAbsoluteTheme, isClip, isDepthFocusTraversal, isEnabled, isFocusKeyEnabled, isInside, isLocallyEnabled, isMouseInside, isVisible, keyboardFocusChildChanged, keyboardFocusGained, keyboardFocusGained, keyboardFocusLost, layoutChildFullInnerArea, layoutChildrenFullInnerArea, moveChild, paint, paintBackground, paintChild, paintChildren, paintDragOverlay, paintOverlay, positionChanged, reapplyTheme, removeChild, removePropertyChangeListener, removePropertyChangeListener, requestKeyboardFocus, requestKeyboardFocus, resetTooltip, setActionMap, setBackground, setBorderSize, setBorderSize, setBorderSize, setBorderSize, setCanAcceptKeyboardFocus, setClip, setDepthFocusTraversal, setEnabled, setFocusKeyEnabled, setInnerSize, setInputMap, setMaxSize, setMinSize, setMouseCursor, setOffscreenExtra, setOffscreenExtra, setOverlay, setPosition, setRenderOffscreen, setSize, setTheme, setTintAnimator, setTooltipContent, setVisible, updateTintAnimation, updateTooltip, validateLayout, widgetDisabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SMALL_GAP

public static final int SMALL_GAP
Symbolic constant to refer to "small gap".

See Also:
getSmallGap(), DialogLayout.Group.addGap(int), DialogLayout.Group.addGap(int, int, int), Constant Field Values

MEDIUM_GAP

public static final int MEDIUM_GAP
Symbolic constant to refer to "medium gap".

See Also:
getMediumGap(), DialogLayout.Group.addGap(int), DialogLayout.Group.addGap(int, int, int), Constant Field Values

LARGE_GAP

public static final int LARGE_GAP
Symbolic constant to refer to "large gap".

See Also:
getLargeGap(), DialogLayout.Group.addGap(int), DialogLayout.Group.addGap(int, int, int), Constant Field Values

DEFAULT_GAP

public static final int DEFAULT_GAP
Symbolic constant to refer to "default gap". The default gap is added (when enabled) between widgets.

See Also:
getDefaultGap(), setAddDefaultGaps(boolean), isAddDefaultGaps(), DialogLayout.Group.addGap(int), DialogLayout.Group.addGap(int, int, int), Constant Field Values

smallGap

protected Dimension smallGap

mediumGap

protected Dimension mediumGap

largeGap

protected Dimension largeGap

defaultGap

protected Dimension defaultGap

namedGaps

protected ParameterMap namedGaps

addDefaultGaps

protected boolean addDefaultGaps

includeInvisibleWidgets

protected boolean includeInvisibleWidgets

redoDefaultGaps

protected boolean redoDefaultGaps

isPrepared

protected boolean isPrepared

blockInvalidateLayoutTree

protected boolean blockInvalidateLayoutTree

warnOnIncomplete

protected boolean warnOnIncomplete
Constructor Detail

DialogLayout

public DialogLayout()
Creates a new DialogLayout widget. Initially both the horizontal and the vertical group are null.

See Also:
setHorizontalGroup(de.matthiasmann.twl.DialogLayout.Group), setVerticalGroup(de.matthiasmann.twl.DialogLayout.Group)
Method Detail

getHorizontalGroup

public DialogLayout.Group getHorizontalGroup()

setHorizontalGroup

public void setHorizontalGroup(DialogLayout.Group g)
The horizontal group controls the position and size of all child widgets along the X axis. Every widget must be part of both horizontal and vertical group. Otherwise a IllegalStateException is thrown at layout time. If you want to change both horizontal and vertical group then it's recommended to set the other group first to null:
 setVerticalGroup(null);
 setHorizontalGroup(newHorzGroup);
 setVerticalGroup(newVertGroup);
 

Parameters:
g - the group used for the X axis
See Also:
setVerticalGroup(de.matthiasmann.twl.DialogLayout.Group)

getVerticalGroup

public DialogLayout.Group getVerticalGroup()

setVerticalGroup

public void setVerticalGroup(DialogLayout.Group g)
The vertical group controls the position and size of all child widgets along the Y axis. Every widget must be part of both horizontal and vertical group. Otherwise a IllegalStateException is thrown at layout time.

Parameters:
g - the group used for the Y axis
See Also:
setHorizontalGroup(de.matthiasmann.twl.DialogLayout.Group)

getSmallGap

public Dimension getSmallGap()

setSmallGap

public void setSmallGap(Dimension smallGap)

getMediumGap

public Dimension getMediumGap()

setMediumGap

public void setMediumGap(Dimension mediumGap)

getLargeGap

public Dimension getLargeGap()

setLargeGap

public void setLargeGap(Dimension largeGap)

getDefaultGap

public Dimension getDefaultGap()

setDefaultGap

public void setDefaultGap(Dimension defaultGap)

isAddDefaultGaps

public boolean isAddDefaultGaps()

setAddDefaultGaps

public void setAddDefaultGaps(boolean addDefaultGaps)
Determine whether default gaps should be added from the theme or not.

Parameters:
addDefaultGaps - if true then default gaps are added.

removeDefaultGaps

public void removeDefaultGaps()
removes all default gaps from all groups.


addDefaultGaps

public void addDefaultGaps()
Adds theme dependant default gaps to all groups.


isIncludeInvisibleWidgets

public boolean isIncludeInvisibleWidgets()

setIncludeInvisibleWidgets

public void setIncludeInvisibleWidgets(boolean includeInvisibleWidgets)
Controls whether invisible widgets should be included in the layout or not. If they are not included then the layout is recomputed when the visibility of a child widget changes. The default is true

Parameters:
includeInvisibleWidgets - If true then invisible widgets are included, if false they don't contribute to the layout.

applyThemeDialogLayout

protected void applyThemeDialogLayout(ThemeInfo themeInfo)

applyTheme

protected void applyTheme(ThemeInfo themeInfo)
Description copied from class: Widget
Apply the given theme. This method also calls invalidateLayout()

Overrides:
applyTheme in class Widget
Parameters:
themeInfo - The theme info for this widget

getMinWidth

public int getMinWidth()
Description copied from class: Widget
Returns the minimum width of the widget. Layout manager will allocate atleast the minimum width to a widget even when the container is not big enough. The default implementation will not return values smaller then the current border width.

Overrides:
getMinWidth in class Widget
Returns:
the minimum width of the widget

getMinHeight

public int getMinHeight()
Description copied from class: Widget
Returns the minimum height of the widget. Layout manager will allocate atleast the minimum height to a widget even when the container is not big enough. The default implementation will not return values smaller then the current border width.

Overrides:
getMinHeight in class Widget
Returns:
the minimum height of the widget

getPreferredInnerWidth

public int getPreferredInnerWidth()
Description copied from class: Widget
Computes the preferred inner width (the size of the widget without the border) The default implementation uses the current position of the children. It is highly recommended to override this method as the default implementation lead to unstable layouts. The default behavior might change in the future to provide a better default behavior.

Overrides:
getPreferredInnerWidth in class Widget
Returns:
the preferred inner width

getPreferredInnerHeight

public int getPreferredInnerHeight()
Description copied from class: Widget
Computes the preferred inner height (the size of the widget without the border) The default implementation uses the current position of the children. It is highly recommended to override this method as the default implementation lead to unstable layouts. The default behavior might change in the future to provide a better default behavior.

Overrides:
getPreferredInnerHeight in class Widget
Returns:
the preferred inner height

adjustSize

public void adjustSize()
Description copied from class: Widget
Auto adjust the size of this widget based on it's preferred size. Subclasses can provide more functionality

Overrides:
adjustSize in class Widget

layout

protected void layout()
Description copied from class: Widget
Called when the layoutInvalid flag is set. The default implementation does nothing.

Overrides:
layout in class Widget

prepare

protected void prepare()

doLayout

protected void doLayout()

invalidateLayout

public void invalidateLayout()
Description copied from class: Widget
Called when something has changed which affected the layout of this widget. The default implementation calls invalidateLayoutLocally() followed by childInvalidateLayout() Called by the default implementation of borderChanged.

Overrides:
invalidateLayout in class Widget
See Also:
Widget.invalidateLayoutLocally(), Widget.borderChanged()

paintWidget

protected void paintWidget(GUI gui)
Description copied from class: Widget
Called by Widget.paint(de.matthiasmann.twl.GUI) after painting the background and before painting all children.

This should be overwritten instead of paint if normal themeable painting is desired by the subclass.

The default implementation does nothing.

Overrides:
paintWidget in class Widget
Parameters:
gui - the GUI object - it's the same as getGUI()

sizeChanged

protected void sizeChanged()
Description copied from class: Widget
Called when the size of this widget has changed. The default implementation calls invalidateLayoutLocally. As size changes are normally the result of the parent's layout() function.

Overrides:
sizeChanged in class Widget
See Also:
Widget.invalidateLayoutLocally()

afterAddToGUI

protected void afterAddToGUI(GUI gui)
Description copied from class: Widget
Called after this widget has been added to a GUI tree.

Overrides:
afterAddToGUI in class Widget
Parameters:
gui - the GUI object - same as getGUI()
See Also:
Widget.getGUI()

createParallelGroup

public DialogLayout.Group createParallelGroup()
Creates a new parallel group. All children in a parallel group share the same position and size of it's axis.

Returns:
the new parallel Group.

createParallelGroup

public DialogLayout.Group createParallelGroup(Widget... widgets)
Creates a parallel group and adds the specified widgets.

Parameters:
widgets - the widgets to add
Returns:
a new parallel Group.
See Also:
createParallelGroup()

createParallelGroup

public DialogLayout.Group createParallelGroup(DialogLayout.Group... groups)
Creates a parallel group and adds the specified groups.

Parameters:
groups - the groups to add
Returns:
a new parallel Group.
See Also:
createParallelGroup()

createSequentialGroup

public DialogLayout.Group createSequentialGroup()
Creates a new sequential group. All children in a sequential group are ordered with increasing coordinates along it's axis in the order they are added to the group. The available size is distributed among the children depending on their min/preferred/max sizes.

Returns:
a new sequential Group.

createSequentialGroup

public DialogLayout.Group createSequentialGroup(Widget... widgets)
Creates a sequential group and adds the specified widgets.

Parameters:
widgets - the widgets to add
Returns:
a new sequential Group.
See Also:
createSequentialGroup()

createSequentialGroup

public DialogLayout.Group createSequentialGroup(DialogLayout.Group... groups)
Creates a sequential group and adds the specified groups.

Parameters:
groups - the groups to add
Returns:
a new sequential Group.
See Also:
createSequentialGroup()

insertChild

public void insertChild(Widget child,
                        int index)
                 throws java.lang.IndexOutOfBoundsException
Description copied from class: Widget
Inserts a new child into this widget. The position of the child is treated as relative to this widget and adjusted. If a theme was applied to this widget then this theme is also applied to the new child.

Overrides:
insertChild in class Widget
Parameters:
child - the child that should be inserted
index - the index where it should be inserted
Throws:
java.lang.IndexOutOfBoundsException - if the index is invalid

removeAllChildren

public void removeAllChildren()
Description copied from class: Widget
Removes all children of this widget. The position of the all removed children is changed to the relative position to this widget. Calls allChildrenRemoved after removing all children.

Overrides:
removeAllChildren in class Widget
See Also:
Widget.allChildrenRemoved()

removeChild

public Widget removeChild(int index)
                   throws java.lang.IndexOutOfBoundsException
Description copied from class: Widget
Removes the specified child from this widget. The position of the removed child is changed to the relative position to this widget. Calls invalidateLayout after removing the child.

Overrides:
removeChild in class Widget
Parameters:
index - the index of the child
Returns:
the removed widget
Throws:
java.lang.IndexOutOfBoundsException - if the index is invalid
See Also:
Widget.invalidateLayout()

setWidgetAlignment

public boolean setWidgetAlignment(Widget widget,
                                  Alignment alignment)
Sets the alignment of the specified widget. The widget must have already been added to this container for this method to work.

The default alignment of a widget is Alignment.FILL

Parameters:
widget - the widget for which the alignment should be set
alignment - the new alignment
Returns:
true if the widget's alignment was changed, false otherwise

recheckWidgets

protected void recheckWidgets()

layoutGroupsChanged

protected void layoutGroupsChanged()

maybeInvalidateLayoutTree

protected void maybeInvalidateLayoutTree()

childVisibilityChanged

protected void childVisibilityChanged(Widget child)
Description copied from class: Widget
Called when the visibility state of a child was changed. The default implementation does nothing.

Overrides:
childVisibilityChanged in class Widget
Parameters:
child - the child which changed it's visibility state
See Also:
Widget.setVisible(boolean)