Package com.jidesoft.swing
Class JideBoxLayout
- java.lang.Object
-
- com.jidesoft.swing.JideBoxLayout
-
- All Implemented Interfaces:
java.awt.LayoutManager,java.awt.LayoutManager2,java.io.Serializable
- Direct Known Subclasses:
JideSplitPaneLayout
public class JideBoxLayout extends java.lang.Object implements java.awt.LayoutManager2, java.io.SerializableJideBoxLayout is very similar to BoxLayout in the way that all components are arranged either from left to right or from top to bottom. Different \ from BoxLayout, there are three possible constraints when adding component to this layout - FIX, FLEXIBLE and VARY.- FIX: use the preferred size of the component and size is fixed
- FLEXIBLE: respect the preferred size of the component but size can be changed.
- VARY: ignore preferred size. Its size is calculated based how much area left.
JideSplitPane.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int_axisAxis, 0 for horizontal, or 1 for vertical.protected int[]_componentSizesprotected java.awt.Container_targetstatic java.lang.StringFIXFor FIX component, the width (or height if vertical) is and will always be the preferred width.static java.lang.StringFLEXIBLEFLEXIBLE components try to keep the preferred width.static intLINE_AXISSpecifies that components should be laid out in the direction of a line of text as determined by the target container'sComponentOrientationproperty.static intPAGE_AXISSpecifies that components should be laid out in the direction that lines flow across a page as determined by the target container'sComponentOrientationproperty.static java.lang.StringVARYFor VARY component, the width will always be whatever width left.static intX_AXISSpecifies that components should be laid out left to right.static intY_AXISSpecifies that components should be laid out top to bottom.
-
Constructor Summary
Constructors Constructor Description JideBoxLayout(java.awt.Container target)Creates a layout manager that will lay out components along the given axis.JideBoxLayout(java.awt.Container target, int axis)JideBoxLayout(java.awt.Container target, int axis, int gap)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLayoutComponent(java.awt.Component comp, java.lang.Object constraints)Adds the specified component to the layout, using the specified constraint object.voidaddLayoutComponent(java.lang.String name, java.awt.Component component)If the layout manager uses a per-component string, adds the componentcompto the layout, associating it with the string specified byname.protected booleancalculateComponentSizes(int availableSize, int startIndex, int endIndex)protected booleancomponentCountChanged(java.awt.Container c)protected intgetAvailableSize(java.awt.Dimension containerSize, java.awt.Insets insets)Returns the available width based on the container size and Insets.intgetAxis()Gets the axis.java.util.Map<java.awt.Component,java.lang.Object>getConstraintMap()Gets the map of constraints.intgetGap()Gets the gap between each component.protected intgetInitialLocation(java.awt.Insets insets)Returns the left inset, unless the Insets are null in which case 0 is returned.floatgetLayoutAlignmentX(java.awt.Container target)Returns the alignment along the x axis.floatgetLayoutAlignmentY(java.awt.Container target)Returns the alignment along the y axis.protected java.awt.DimensiongetPreferredSizeOf(java.awt.Component comp, int atIndex)protected intgetPreferredSizeOfComponent(java.awt.Component c)Returns the width of the passed in Components preferred size.protected intgetSizeOfComponent(java.awt.Component c)Returns the width of the passed in component.voidinvalidateLayout(java.awt.Container c)Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.booleanisAlwaysLayout()Checks if the alwaysLayout flag is true.booleanisResetWhenInvalidate()Checks of the layout should be reset wheninvalidateLayout(java.awt.Container)is called.voidlayoutContainer(java.awt.Container container)Lays out the specified container.java.awt.DimensionmaximumLayoutSize(java.awt.Container target)Returns the maximum layout size, which is Integer.MAX_VALUE in both directions.java.awt.DimensionminimumLayoutSize(java.awt.Container container)Returns the minimum size needed to contain the children.java.awt.DimensionpreferredLayoutSize(java.awt.Container container)Returns the preferred size needed to contain the children.voidremoveLayoutComponent(java.awt.Component comp)Removes the specified component from the layout.protected static intresolveAxis(int axis, java.awt.ComponentOrientation o)Given one of the 4 axis values, resolve it to an absolute axis.voidsetAlwaysLayout(boolean alwaysLayout)Sets the alwaysLayout flag.voidsetAxis(int axis)Sets the axis.protected voidsetComponentToSize(java.awt.Component c, int size, int location, java.awt.Insets insets, java.awt.Dimension containerSize)Sets the width of the component c to be size, placing its x location at location, y to the insets.top and height to the containersize.height less the top and bottom insets.voidsetGap(int gap)Sets the gap between each component.voidsetResetWhenInvalidate(boolean resetWhenInvalidate)Sets the flag if the layout should be reset wheninvalidateLayout(java.awt.Container)is called.
-
-
-
Field Detail
-
_axis
protected int _axis
Axis, 0 for horizontal, or 1 for vertical.
-
_target
protected java.awt.Container _target
-
_componentSizes
protected int[] _componentSizes
-
FIX
public static final java.lang.String FIX
For FIX component, the width (or height if vertical) is and will always be the preferred width.- See Also:
- Constant Field Values
-
FLEXIBLE
public static final java.lang.String FLEXIBLE
FLEXIBLE components try to keep the preferred width. If there isn't enough space, all FLEXIBLE components will shrink proportionally.- See Also:
- Constant Field Values
-
VARY
public static final java.lang.String VARY
For VARY component, the width will always be whatever width left. You can allow add multiple FIX or FLEXIBLE components but only one VARY component is allowed.- See Also:
- Constant Field Values
-
X_AXIS
public static final int X_AXIS
Specifies that components should be laid out left to right.- See Also:
- Constant Field Values
-
Y_AXIS
public static final int Y_AXIS
Specifies that components should be laid out top to bottom.- See Also:
- Constant Field Values
-
LINE_AXIS
public static final int LINE_AXIS
Specifies that components should be laid out in the direction of a line of text as determined by the target container'sComponentOrientationproperty.- See Also:
- Constant Field Values
-
PAGE_AXIS
public static final int PAGE_AXIS
Specifies that components should be laid out in the direction that lines flow across a page as determined by the target container'sComponentOrientationproperty.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JideBoxLayout
public JideBoxLayout(java.awt.Container target)
Creates a layout manager that will lay out components along the given axis.- Parameters:
target- the container that needs to be laid out- Throws:
java.awt.AWTError- if the value ofaxisis invalid
-
JideBoxLayout
public JideBoxLayout(java.awt.Container target, int axis)- Parameters:
target- the container that needs to be laid outaxis- the axis to lay out components along. Can be one of:JideBoxLayout.X_AXIS,JideBoxLayout.Y_AXIS,JideBoxLayout.LINE_AXISorJideBoxLayout.PAGE_AXIS
-
JideBoxLayout
public JideBoxLayout(java.awt.Container target, int axis, int gap)- Parameters:
target- the container that needs to be laid outaxis- the axis to lay out components along. Can be one of:JideBoxLayout.X_AXIS,JideBoxLayout.Y_AXIS,JideBoxLayout.LINE_AXISorJideBoxLayout.PAGE_AXISgap- the gap
-
-
Method Detail
-
layoutContainer
public void layoutContainer(java.awt.Container container)
Lays out the specified container.- Specified by:
layoutContainerin interfacejava.awt.LayoutManager- Parameters:
container- the container to be laid out
-
calculateComponentSizes
protected boolean calculateComponentSizes(int availableSize, int startIndex, int endIndex)
-
addLayoutComponent
public void addLayoutComponent(java.lang.String name, java.awt.Component component)If the layout manager uses a per-component string, adds the componentcompto the layout, associating it with the string specified byname.- Specified by:
addLayoutComponentin interfacejava.awt.LayoutManager- Parameters:
name- the string to be associated with the componentcomponent- the component to be added
-
minimumLayoutSize
public java.awt.Dimension minimumLayoutSize(java.awt.Container container)
Returns the minimum size needed to contain the children. The width is the sum of all the children min widths and the height is the largest of the children minimum heights.- Specified by:
minimumLayoutSizein interfacejava.awt.LayoutManager
-
preferredLayoutSize
public java.awt.Dimension preferredLayoutSize(java.awt.Container container)
Returns the preferred size needed to contain the children. The width is the sum of all the children preferred widths and the height is the largest of the children preferred heights.- Specified by:
preferredLayoutSizein interfacejava.awt.LayoutManager
-
removeLayoutComponent
public void removeLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout.- Specified by:
removeLayoutComponentin interfacejava.awt.LayoutManager- Parameters:
comp- the component to be removed
-
addLayoutComponent
public void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)Adds the specified component to the layout, using the specified constraint object.- Specified by:
addLayoutComponentin interfacejava.awt.LayoutManager2- Parameters:
comp- the component to be addedconstraints- where/how the component is added to the layout.
-
getLayoutAlignmentX
public float getLayoutAlignmentX(java.awt.Container target)
Returns the alignment along the x axis. 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.- Specified by:
getLayoutAlignmentXin interfacejava.awt.LayoutManager2
-
getLayoutAlignmentY
public float getLayoutAlignmentY(java.awt.Container target)
Returns the alignment along the y axis. 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.- Specified by:
getLayoutAlignmentYin interfacejava.awt.LayoutManager2
-
invalidateLayout
public void invalidateLayout(java.awt.Container c)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.- Specified by:
invalidateLayoutin interfacejava.awt.LayoutManager2
-
componentCountChanged
protected boolean componentCountChanged(java.awt.Container c)
-
maximumLayoutSize
public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum layout size, which is Integer.MAX_VALUE in both directions.- Specified by:
maximumLayoutSizein interfacejava.awt.LayoutManager2
-
getPreferredSizeOfComponent
protected int getPreferredSizeOfComponent(java.awt.Component c)
Returns the width of the passed in Components preferred size.- Parameters:
c- the component- Returns:
- the preferred size of the component.
-
getSizeOfComponent
protected int getSizeOfComponent(java.awt.Component c)
Returns the width of the passed in component.- Parameters:
c- the component- Returns:
- the size of the component.
-
getAvailableSize
protected int getAvailableSize(java.awt.Dimension containerSize, java.awt.Insets insets)Returns the available width based on the container size and Insets.- Parameters:
containerSize- the size of the containerinsets- the insets- Returns:
- the available size.
-
getInitialLocation
protected int getInitialLocation(java.awt.Insets insets)
Returns the left inset, unless the Insets are null in which case 0 is returned.- Parameters:
insets- the insets- Returns:
- the initial location.
-
setComponentToSize
protected void setComponentToSize(java.awt.Component c, int size, int location, java.awt.Insets insets, java.awt.Dimension containerSize)Sets the width of the component c to be size, placing its x location at location, y to the insets.top and height to the containersize.height less the top and bottom insets.- Parameters:
c- the componentsize- the size of the componentlocation- the location of the componentinsets- the insets of the componentcontainerSize- the size of the container
-
getConstraintMap
public java.util.Map<java.awt.Component,java.lang.Object> getConstraintMap()
Gets the map of constraints.- Returns:
- the map of constraints
-
resolveAxis
protected static int resolveAxis(int axis, java.awt.ComponentOrientation o)Given one of the 4 axis values, resolve it to an absolute axis. The relative axis values, PAGE_AXIS and LINE_AXIS are converted to their absolute counterpart given the target's ComponentOrientation value. The absolute axes, X_AXIS and Y_AXIS are returned unmodified.- Parameters:
axis- the axis to resolveo- the ComponentOrientation to resolve against- Returns:
- the resolved axis
-
getGap
public int getGap()
Gets the gap between each component.- Returns:
- the gap between each component.
-
setGap
public void setGap(int gap)
Sets the gap between each component. Make sure you cal doLayout() after you change the gap.- Parameters:
gap- the gap
-
getPreferredSizeOf
protected java.awt.Dimension getPreferredSizeOf(java.awt.Component comp, int atIndex)
-
isResetWhenInvalidate
public boolean isResetWhenInvalidate()
Checks of the layout should be reset wheninvalidateLayout(java.awt.Container)is called.- Returns:
- true or false.
-
setResetWhenInvalidate
public void setResetWhenInvalidate(boolean resetWhenInvalidate)
Sets the flag if the layout should be reset wheninvalidateLayout(java.awt.Container)is called.- Parameters:
resetWhenInvalidate- the flag
-
getAxis
public int getAxis()
Gets the axis.- Returns:
- the axis.
-
setAxis
public void setAxis(int axis)
Sets the axis. After changing the axis, you need to call doLayout method on the container which has this layout.- Parameters:
axis- the new axis.
-
isAlwaysLayout
public boolean isAlwaysLayout()
Checks if the alwaysLayout flag is true. If true, the layout manager will layout the components even there is no way to satisfy the minimum size requirements from all FIXED components. By default, it is true.- Returns:
- true or false.
-
setAlwaysLayout
public void setAlwaysLayout(boolean alwaysLayout)
Sets the alwaysLayout flag.- Parameters:
alwaysLayout- true to always layout components even there is no way to satisfy the minimum size requirements from all FIXED components.
-
-