ch.javasoft.swing
Class JComponentGroup

java.lang.Object
  extended by ch.javasoft.swing.JComponentGroup

public class JComponentGroup
extends Object

A JComponentGroup groups components such that they can coordinate their sizes. The preferred, minimum and maximum size properties of grouped components are reconciled. If one of the reconciled sizes changes, this class is notified and the size is stored for the concerned component. All components of the group are then notified and the corresponding size is set to the largest value of all components (includes the component which just changed its size).


Nested Class Summary
static class JComponentGroup.Binding
           
 
Constructor Summary
JComponentGroup(JComponentGroup.Binding binding)
          Creates a component group with the given binding constraints
 
Method Summary
 JComponent addComponent(JComponent component)
          Adds the specified component to this component group.
 JComponent addComponentNoStretching(JComponent component)
          Adds the component in a panel, such that the component itself is not stretched.
 JComponent addComponentNoStretching(JComponent component, int align)
          Adds the component in a panel, such that the component itself is not stretched.
static JComponentGroup bind(JComponentGroup.Binding binding, JComponent... components)
          Creates a component group with the specified binding constraints, adding the given components to this component group
static JComponentGroup bind(JComponent label, JComponent control)
          Creates a component group with y binding for the specified controls
 boolean doBindX()
          True for BIND_X and BIND_BOTH
 boolean doBindY()
          True for BIND_Y and BIND_BOTH
protected  void fireComponentChanged(String event, JComponent component)
          The given component has changed, meaning been added, removed, hidden, shown or resized.
protected  void fireSizeChanged(JComponent component, ComponentSizeType sizeType)
          The specified size of the given component changed.
 JComponentGroup.Binding getBinding()
          Returns the binding as specified when invoking the constructor
protected  Dimension getMaximumSize(JComponent component)
          Returns the maximum group size.
protected  Dimension getMinimumSize(JComponent component)
          Returns the minimum group size.
protected  Dimension getPreferredSize(JComponent component)
          Returns the preferred group size.
protected  Dimension getSize(JComponent component, ComponentSizeType sizeType)
          Returns the specified group size.
protected  boolean log()
          Return true if you want to have calls to log(String), false (default) otherwise
protected  void log(String msg)
          Logs to system output.
 JComponent removeComponent(JComponent component)
          Removes the specified component from this component group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JComponentGroup

public JComponentGroup(JComponentGroup.Binding binding)
Creates a component group with the given binding constraints

Parameters:
binding - the binding constraints
Method Detail

bind

public static JComponentGroup bind(JComponentGroup.Binding binding,
                                   JComponent... components)
Creates a component group with the specified binding constraints, adding the given components to this component group

Parameters:
binding - the binding constraints
components - the components to add to this component group

bind

public static JComponentGroup bind(JComponent label,
                                   JComponent control)
Creates a component group with y binding for the specified controls

Parameters:
label - the label component
control - the control component, for instance a text field belonging to the given label component

addComponent

public JComponent addComponent(JComponent component)
Adds the specified component to this component group.

Parameters:
component - the component to add
Returns:
the added component, same as input

removeComponent

public JComponent removeComponent(JComponent component)
Removes the specified component from this component group. If the component has been added with no stretching, the panel returned by the addComponentNoStretching method must be passed.

Parameters:
component - the component to remove
Returns:
the removed component, or null if it has not been found

addComponentNoStretching

public JComponent addComponentNoStretching(JComponent component)
Adds the component in a panel, such that the component itself is not stretched. Leading alignment is chosen for x binding, top for y binding.

To remove the component from this component group, the returned panel must be passed to the remove method.

Parameters:
component - the component to add
Returns:
the panel in which the component has been placed

addComponentNoStretching

public JComponent addComponentNoStretching(JComponent component,
                                           int align)
Adds the component in a panel, such that the component itself is not stretched.

Parameters:
component - the component to add
align - the alignment as specified by SwingConstants
Returns:
the panel in which the component has been placed

getBinding

public JComponentGroup.Binding getBinding()
Returns the binding as specified when invoking the constructor


doBindX

public boolean doBindX()
True for BIND_X and BIND_BOTH


doBindY

public boolean doBindY()
True for BIND_Y and BIND_BOTH


fireComponentChanged

protected void fireComponentChanged(String event,
                                    JComponent component)
The given component has changed, meaning been added, removed, hidden, shown or resized. This triggers calls to fireSizeChanged(JComponent, ComponentSizeType) for preferred, minimum and maximum size.

Parameters:
event - the cause for the call to this method (for logging only)
component - the component which changed

fireSizeChanged

protected void fireSizeChanged(JComponent component,
                               ComponentSizeType sizeType)
The specified size of the given component changed. This might have had influence on the group size being the maximum of all component sizes on the bound axis. Thus, the size of all components is set to the new group size.


getPreferredSize

protected Dimension getPreferredSize(JComponent component)
Returns the preferred group size. Depending on the binding, the maximum of all group component sizes (if bound to this axis) or the component size itself is returned. If the component is null, 0 is returned instead of the component size (for non-bound axes).

Parameters:
component - The component to take the size from if the axis is not bound
Returns:
The group size for bound axes or the component size for unbound axes (0 if component is null)

getMinimumSize

protected Dimension getMinimumSize(JComponent component)
Returns the minimum group size. Depending on the binding, the maximum of all group component sizes (if bound to this axis) or the component size itself is returned. If the component is null, 0 is returned instead of the component size (for non-bound axes).

Parameters:
component - The component to take the size from if the axis is not bound
Returns:
The group size for bound axes or the component size for unbound axes (0 if component is null)

getMaximumSize

protected Dimension getMaximumSize(JComponent component)
Returns the maximum group size. Depending on the binding, the maximum of all group component sizes (if bound to this axis) or the component size itself is returned. If the component is null, 0 is returned instead of the component size (for non-bound axes).

Parameters:
component - The component to take the size from if the axis is not bound
Returns:
The group size for bound axes or the component size for unbound axes (0 if component is null)

getSize

protected Dimension getSize(JComponent component,
                            ComponentSizeType sizeType)
Returns the specified group size. Depending on the binding, the maximum of all group component sizes (if bound to this axis) or the component size itself is returned. If the component is null, 0 is returned instead of the component size (for non-bound axes).

Parameters:
component - The component to take the size from if the axis is not bound
Returns:
The group size for bound axes or the component size for unbound axes (0 if component is null)

log

protected boolean log()
Return true if you want to have calls to log(String), false (default) otherwise


log

protected void log(String msg)
Logs to system output. Only called if log() returns true