org.tbee.swing.splitter
Class SplitterLayout

java.lang.Object
  extended by org.tbee.swing.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

http://javadude.com/tools/tabsplitter/splitterlayout.html SplitterLayout is a layout manager that will layout a container holding other components and SplitterBars. Usage: lContainer.setLayout(new SplitterLayout(SplitterLayout.VERTICAL)); lContainer.add("1", ...); // "1" is a weigth JSplitterBar b1 = new JSplitterBar(); lContainer.add(b1); ... lContainer.add(..., SplitterLayout.PREFERRED); // use the components preferred size in the initial layout ... JSplitterBar can contain components themselves, which can contain splitterbars again: JSplitterBar b2 = new JSplitterBar(); b2.setLayout(new SplitterLayout(SplitterLayout.HORIZONTAL)); b2.add("5", new JSplitterSpace()); b2.add(new JSplitterBar()); b2.add("10", new JLabel("Status")); b2.add(new JSplitterBar()); b2.add("40", new JTextField("Enter your name")); lContainer.add(b2);

Each component added to a container to be laid out using SplitterLayout must provide a String containing a "weight" for the component. This weight will be used to determine the initial spacing of all components being laid out. The weight numbers are arbitrary integers. The amount of space initially allocated for a component is

 (wc / wt) * (size - insets - splitterSize)
 

where

wc
the weight number for the component
wt
the total weight of all visible components in the container
size
the space free to display the components
insets
space used by insets in the container
splitterSize
amount of space needed to display SplitterBars

If the container being laid out holds no SplitterBars, SplitterLayout acts like a relational-weight layout manager. All components are always laid out based on their proportionate weights.

If the container being laid out holds some SplitterBars, SplitterLayout will initially size all non JSplitterBar components based on their weights. Any succesive layouts are computed strictly on the locations of the SplitterBars.

SplitterLayout can be oriented Horizontally or Vertically. Any SpliterBars placed in the container will automatically be oriented.

If a JSplitterBar has been modified (adding components to it) you will need to add JSplitterSpace components to it. See JSplitterBar for more details.

Known Problems:

Version:
$Revision: 1.6 $
See Also:
JSplitterBar, JSplitterSpace, Serialized Form

Field Summary
static JSplitterBar dragee
           
static int HORIZONTAL
          Aligns components horizontally -- SplitterBars will move left-right
static java.lang.Integer PREFERRED
           
static int VERTICAL
          Aligns components vertically -- SplitterBars will move up/down
 
Constructor Summary
SplitterLayout()
          Create a new SplitterLayout -- default orientation is VERTICAL
SplitterLayout(int orientation)
          Create a new SplitterLayout
 
Method Summary
 void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
          Adds a component w/ constraints to the layout.
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Adds a component w/ a String constraint to the layout.
 java.awt.Dimension determineLayoutSize(java.awt.Container target, boolean getPrefSize)
          Determine the size of this layout
 float getLayoutAlignmentX(java.awt.Container parent)
          Tells the caller that we prefer to be centered
 float getLayoutAlignmentY(java.awt.Container parent)
          Tells the caller that we prefer to be centered
 int getOrientation()
          Gets the orientation property (int) value.
 void invalidateLayout(java.awt.Container target)
          Does not have any effect (overridden to null the effect)
 void layoutContainer(java.awt.Container target)
          Lays out the components in the specified container by telling then what their size will be
static void main(java.lang.String[] args)
           
 java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Determines the maximum amount of space that could be used when laying out the components in the specified container.
 java.awt.Dimension minimumLayoutSize(java.awt.Container target)
          Determines the minimum amount of room requested for the layout of components contained in the specified container.
 java.awt.Dimension preferredLayoutSize(java.awt.Container target)
          Determines the preferred amount of room requested for the layout of components contained in the specified container.
 void removeLayoutComponent(java.awt.Component comp)
          Removes a component from the layout.
 void setOrientation(int orientation)
          Sets the orientation property (int) value.
 void swapOrientation(java.awt.Container container)
           
 java.lang.String toString()
          Returns a String representation of the Layout
 
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

dragee

public static JSplitterBar dragee

PREFERRED

public static java.lang.Integer PREFERRED
Constructor Detail

SplitterLayout

public SplitterLayout()
Create a new SplitterLayout -- default orientation is VERTICAL


SplitterLayout

public SplitterLayout(int orientation)
Create a new SplitterLayout

Parameters:
orientation - VERTICAL or HORIZONTAL
Method Detail

addLayoutComponent

public final void addLayoutComponent(java.awt.Component comp,
                                     java.lang.Object constraints)
Adds a component w/ constraints to the layout. This should only be called by java.awt.Container's add method.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager2

addLayoutComponent

public final void addLayoutComponent(java.lang.String name,
                                     java.awt.Component comp)
Adds a component w/ a String constraint to the layout. This should only be called by java.awt.Container's add method.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager

determineLayoutSize

public final java.awt.Dimension determineLayoutSize(java.awt.Container target,
                                                    boolean getPrefSize)
Determine the size of this layout

Parameters:
target -
getPrefSize -
Returns:

getLayoutAlignmentX

public final float getLayoutAlignmentX(java.awt.Container parent)
Tells the caller that we prefer to be centered

Specified by:
getLayoutAlignmentX in interface java.awt.LayoutManager2

getLayoutAlignmentY

public final float getLayoutAlignmentY(java.awt.Container parent)
Tells the caller that we prefer to be centered

Specified by:
getLayoutAlignmentY in interface java.awt.LayoutManager2

getOrientation

public int getOrientation()
Gets the orientation property (int) value.

Returns:
The orientation property value.
See Also:
setOrientation(int)

invalidateLayout

public final void invalidateLayout(java.awt.Container target)
Does not have any effect (overridden to null the effect)

Specified by:
invalidateLayout in interface java.awt.LayoutManager2

layoutContainer

public final void layoutContainer(java.awt.Container target)
Lays out the components in the specified container by telling then what their size will be

Specified by:
layoutContainer in interface java.awt.LayoutManager

maximumLayoutSize

public final java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Determines the maximum amount of space that could be used when laying out the components in the specified container.

Specified by:
maximumLayoutSize in interface java.awt.LayoutManager2
Parameters:
-- - the container being laid out

minimumLayoutSize

public final java.awt.Dimension minimumLayoutSize(java.awt.Container target)
Determines the minimum amount of room requested for the layout of components contained in the specified container.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
target - -- the Container being laid out

preferredLayoutSize

public final java.awt.Dimension preferredLayoutSize(java.awt.Container target)
Determines the preferred amount of room requested for the layout of components contained in the specified container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
target - the Container being laid out

removeLayoutComponent

public final void removeLayoutComponent(java.awt.Component comp)
Removes a component from the layout. This should only be called by java.awt.Container's remove method.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager

setOrientation

public void setOrientation(int orientation)
Sets the orientation property (int) value.

Parameters:
orientation - The new value for the property.
See Also:
getOrientation()

swapOrientation

public void swapOrientation(java.awt.Container container)

toString

public final java.lang.String toString()
Returns a String representation of the Layout

Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)


Copyright © 2010 KnowledgePlaza. All Rights Reserved.