org.openbp.swing.layout.splitter
Class SplitterLayout

java.lang.Object
  extended by org.openbp.swing.layout.splitter.SplitterLayout
All Implemented Interfaces:
java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable

public class SplitterLayout
extends java.lang.Object
implements java.awt.LayoutManager2, java.io.Serializable

The splitter layout manager arranges several components that are separated by SplitterBar components. An intelligent resize algorithm determines the size of the remaining components when one of the splitter bars is moved.
For each component, its minimum and maximum sizes will be considered when giving the user a visual feedback when moving the splitter bar, e. g. the splitter bar won't move to a position that contradicts the constraints of the components. The splitter layout can be oriented horizontally or Vertically. Any SpliterBars placed in the container will automatically be oriented. When adding components to the container, a constraint can be given. The constraint can be either a SplitterConstraint object or a string.
If the string contains the keyword "fill", or the SplitterConstraint.setFiller(boolean) property has been set, the component will be used as filler, e. g. it will be used to fill up any remaining space when layout out the container. In a typical use case of a graphical editor with tool windows at its sides, the editor workspace would be defined as filler component. The layout manager will retain the sizes of the non-filler components if possible.
If there are no filler components at all, all non-SplitterBar components will be used as fillers, e. g. their sizes will be changed as needed.

See Also:
Serialized Form

Field Summary
static int HORIZONTAL
          Aligns components horizontally.
static int VERTICAL
          Aligns components vertically.
 
Constructor Summary
SplitterLayout()
          Constructor.
SplitterLayout(int orientation)
          Constructor.
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
          Adds the specified component to the layout, using the specified constraint object.
 void addLayoutComponent(java.lang.String constraint, java.awt.Component comp)
          Deprecated. replaced by addLayoutComponent(Component,Object)
 float getLayoutAlignmentX(java.awt.Container parent)
          Returns the alignment along the x axis.
 float getLayoutAlignmentY(java.awt.Container parent)
          Returns the alignment along the y axis.
 int getOrientation()
          Gets the orientation of the layout.
protected  SplitterConstraint getSplitterConstraint(java.awt.Component c)
          Retrieves the constraints of a component.
 void invalidateLayout(java.awt.Container target)
          Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
 void layoutContainer(java.awt.Container container)
          Lays out the container argument using this layout.
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Returns the maximum dimensions for this layout given the components in the specified target container.
 java.awt.Dimension minimumLayoutSize(java.awt.Container target)
          Determines the minimum size of the target container using this layout manager.
 java.awt.Dimension preferredLayoutSize(java.awt.Container target)
          Determines the preferred size of the target container using this layout manager, based on the components in the container.
 void processSplitterDrag(SplitterBar splitter, java.awt.Point pDelta, boolean updateLayout)
          Processes a splitter bar drag event.
 void removeLayoutComponent(java.awt.Component comp)
          Removes the specified component from this dock layout.
 void setOrientation(int orientation)
          Sets the orientation of the layout.
 java.lang.String toString()
          Returns a string representation of the state of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERTICAL

public static final int VERTICAL
Aligns components vertically. SplitterBars will move up/down

See Also:
Constant Field Values

HORIZONTAL

public static final int HORIZONTAL
Aligns components horizontally. SplitterBars will move left-right

See Also:
Constant Field Values
Constructor Detail

SplitterLayout

public SplitterLayout()
Constructor. Default orientation is vertical.


SplitterLayout

public SplitterLayout(int orientation)
Constructor.

Parameters:
orientation - Orientation of the components in the container (VERTICAL or HORIZONTAL)
Method Detail

getOrientation

public int getOrientation()
Gets the orientation of the layout.

Returns:
The orientation (VERTICAL or HORIZONTAL)

setOrientation

public void setOrientation(int orientation)
Sets the orientation of the layout.

Parameters:
orientation - The new orientation (VERTICAL or HORIZONTAL)

addLayoutComponent

public final void addLayoutComponent(java.awt.Component comp,
                                     java.lang.Object constraints)
Adds the specified component to the layout, using the specified constraint object. Most applications do not call this method directly. This method is called when a component is added to a container using the Container.add method with the same argument types.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2
Parameters:
comp - Component to be added
constraints - Object that specifies how and where the component is added to the layout.
Throws:
java.lang.IllegalArgumentException - If the constraint object is not a number

addLayoutComponent

public final void addLayoutComponent(java.lang.String constraint,
                                     java.awt.Component comp)
Deprecated. replaced by addLayoutComponent(Component,Object)

Adds the specified component with the specified constraint to the layout.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
constraint - Component constraint
comp - Component to be added

removeLayoutComponent

public final void removeLayoutComponent(java.awt.Component comp)
Removes the specified component from this dock layout. This method is called when a container calls its remove or removeAll methods. Most applications do not call this method directly.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
comp - Component to be removed

layoutContainer

public final void layoutContainer(java.awt.Container container)
Lays out the container argument using this layout. This method actually reshapes the components in the specified container in order to satisfy the constraints of this DockLayout object. Most applications do not call this method directly. This method is called when a container calls its doLayout method.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
container - Container in which to do the layout

processSplitterDrag

public void processSplitterDrag(SplitterBar splitter,
                                java.awt.Point pDelta,
                                boolean updateLayout)
Processes a splitter bar drag event. This method is being called from inside the mouse handler methods of the splitter. This method will try to apply the given offset to the position of the specified splitter. If the offset causes layout changes that conflict with minimum or maximum sizes, the offset will be adjusted so that the conflict is resolved.

Parameters:
splitter - Splitter being dragged
pDelta - Offset to current splitter bar position.
This offset may be modified by the method if the delta would violate the minimum sizes of the components of the target container.
updateLayout - true Update the layout immediately.
false Check the delta only.

preferredLayoutSize

public final java.awt.Dimension preferredLayoutSize(java.awt.Container target)
Determines the preferred size of the target container using this layout manager, based on the components in the container. Most applications do not call this method directly. This method is called when a container calls its getPreferredSize method.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
target - Container in which to do the layout
Returns:
Preferred dimensions to lay out the subcomponents of the specified container

minimumLayoutSize

public final java.awt.Dimension minimumLayoutSize(java.awt.Container target)
Determines the minimum size of the target container using this layout manager. This method is called when a container calls its getMinimumSize method. Most applications do not call this method directly.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
target - Container in which to do the layout
Returns:
Minimum dimensions needed to lay out the subcomponents of the specified container

maximumLayoutSize

public final java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions for this layout given the components in the specified target container. This method is called when a container calls its getMaximumSize method. Most applications do not call this method directly.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Parameters:
target - Component which needs to be laid out
Returns:
Maximum dimensions needed to lay out the subcomponents of the specified container

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis.

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2
Parameters:
parent - Container the layout has been applied to
Returns:
This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis.

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2
Parameters:
parent - Container the layout has been applied to
Returns:
This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

invalidateLayout

public void invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Specified by:
invalidateLayout in interface java.awt.LayoutManager2
Parameters:
target - Container the layout has been applied to

getSplitterConstraint

protected SplitterConstraint getSplitterConstraint(java.awt.Component c)
Retrieves the constraints of a component.

Parameters:
c - Component to look at
Returns:
The component's constraints or null if the component does not have any constraints (this shouldn't be the case as long as the component was properly added to the container).

toString

public java.lang.String toString()
Returns a string representation of the state of this object.

Overrides:
toString in class java.lang.Object


Copyright © 2011. All Rights Reserved.