bibliothek.gui.dock.station.toolbar.layout
Class ToolbarGridLayoutManager<P extends bibliothek.gui.dock.station.support.PlaceholderListItem<bibliothek.gui.Dockable>>

java.lang.Object
  extended by bibliothek.gui.dock.station.toolbar.layout.ToolbarGridLayoutManager<P>
All Implemented Interfaces:
LayoutManager, LayoutManager2

public abstract class ToolbarGridLayoutManager<P extends bibliothek.gui.dock.station.support.PlaceholderListItem<bibliothek.gui.Dockable>>
extends Object
implements LayoutManager2

This LayoutManager2 orders a set of Components in columns. To decide which component belongs to which column, the contents of a DockablePlaceholderToolbarGrid are used.

Author:
Benjamin Sigg

Nested Class Summary
protected  class ToolbarGridLayoutManager.Wrapper
          A wrapper around one Component, caches minimal, maximal or preferred size.
 
Constructor Summary
ToolbarGridLayoutManager(Container parent, Orientation orientation, DockablePlaceholderToolbarGrid<P> grid, ToolbarGroupDockStation station)
          Creates a new layout manager.
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
           
 void addLayoutComponent(String name, Component comp)
           
 void addListener(ToolbarGridLayoutManagerListener listener)
          Adds the observer listener to this object.
 Rectangle getBounds(int column)
          Gets the boundaries of the column at index column.
 Rectangle getBounds(int column, int line)
          Calculates the current boundaries of the cell at column/line .
 int getColumnAt(int location)
          Tells which column covers the coordinate location.
 Rectangle getGapBounds(int column, boolean includeScrollBars)
          Gets the boundaries of the gab between the column column-1 and column.
 Rectangle getGapBounds(int column, int line)
          Gets the size of a gap between two rows.
 int getInsertionLineAt(int column, int location)
          Tells where to insert an item during a drag and drop operation, if the mouse is hovering over the column column.
 float getLayoutAlignmentX(Container target)
           
 float getLayoutAlignmentY(Container target)
           
 Rectangle getScreenBounds(int column)
           
 Rectangle getScreenBounds(int column, int line)
           
protected abstract  Component getScrollbar(int column)
          Gets the scrollbars that are currently shown for column.
protected abstract  int getScrollbarValue(int column, int required, int available)
          Gets the current position of the scrollbar for column, this method is at the same time used to inform the scrollbar about the required and available size.
 void invalidateLayout(Container target)
           
 boolean isColumnAt(int location)
          Tells whether there is a column covering location.
protected  ToolbarGridLayoutManager.Wrapper[][] layout()
          Gets an array of columns, where each column is an array of Components.
protected  void layout(Container parent, ToolbarGridLayoutManager.Wrapper[][] components, Dimension required, Dimension available, bibliothek.gui.dock.station.toolbar.layout.ToolbarGridLayoutManager.Size size)
          Layouts components such that they fit into available.
 void layoutContainer(Container parent)
           
 Dimension maximumLayoutSize(Container parent)
           
 Dimension minimumLayoutSize(Container parent)
           
 void mutate()
          Closes all gaps for inserting items.
 void mutate(int column)
          Opens a gap for inserting an item into column.
 void mutate(int column, int line)
          Opens a gap for inserting an item into column at line.
 Dimension preferredLayoutSize(Container parent)
           
 void removeLayoutComponent(Component comp)
           
 void removeListener(ToolbarGridLayoutManagerListener listener)
          Removes the observer listener from this object.
 void setController(bibliothek.gui.DockController controller)
          Sets the DockController in whose realm this manager works.
 void setDividerStrategy(ToolbarGroupDividerStrategy dividers)
          Sets the strategy responsible for painting a border between the Dockables.
protected abstract  void setShowScrollbar(int column, boolean show)
          Enables or disables a scrollbar for a column.
protected abstract  Component toComponent(P item)
          Converts item into a Component, this LayoutManager will then set the location and size of the resulting component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolbarGridLayoutManager

public ToolbarGridLayoutManager(Container parent,
                                Orientation orientation,
                                DockablePlaceholderToolbarGrid<P> grid,
                                ToolbarGroupDockStation station)
Creates a new layout manager.

Parameters:
parent - the Container which is going to use this LayoutManager
orientation - the orientation, must not be null
grid - the list of items to lay out, must not be null
station - the station using this layout manager
Method Detail

setController

public void setController(bibliothek.gui.DockController controller)
Sets the DockController in whose realm this manager works. Allows this manager access to properties like the SpanFactory.

Parameters:
controller - the controller or null

setDividerStrategy

public void setDividerStrategy(ToolbarGroupDividerStrategy dividers)
Sets the strategy responsible for painting a border between the Dockables. The strategy is required to find the minimum size of the gaps between the items.

Parameters:
dividers - the new strategy, can be null

mutate

public void mutate()
Closes all gaps for inserting items.


mutate

public void mutate(int column)
Opens a gap for inserting an item into column.

Parameters:
column - the column where an item is inserted

mutate

public void mutate(int column,
                   int line)
Opens a gap for inserting an item into column at line.

Parameters:
column - the column into which an item is inserted
line - the location of the new item

toComponent

protected abstract Component toComponent(P item)
Converts item into a Component, this LayoutManager will then set the location and size of the resulting component.

Parameters:
item - the item to convert
Returns:
the Component whose position and size will be set

setShowScrollbar

protected abstract void setShowScrollbar(int column,
                                         boolean show)
Enables or disables a scrollbar for a column.

Parameters:
column - the column whose settings are updated
show - whether to show scrollbars or not

getScrollbarValue

protected abstract int getScrollbarValue(int column,
                                         int required,
                                         int available)
Gets the current position of the scrollbar for column, this method is at the same time used to inform the scrollbar about the required and available size.

Parameters:
required - the amount of pixels required to show the column
available - the amount of pixels actually available for showing the column
Returns:
the offset of the scrollbar, a value between 0 and required - available

getScrollbar

protected abstract Component getScrollbar(int column)
Gets the scrollbars that are currently shown for column.

Parameters:
column - the column whose scrollbars are requested
Returns:
the scrollbars or null if not present

layout

protected ToolbarGridLayoutManager.Wrapper[][] layout()
Gets an array of columns, where each column is an array of Components.

Returns:
all children sorted into the columns

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
Specified by:
addLayoutComponent in interface LayoutManager

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Specified by:
removeLayoutComponent in interface LayoutManager

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)
Specified by:
addLayoutComponent in interface LayoutManager2

getColumnAt

public int getColumnAt(int location)
Tells which column covers the coordinate location. If the location is between columns, then the result can be either of these columns.

Parameters:
location - a point on the axis that is orthogonal to the orientation of the columns
Returns:
the column covering location or -1 if out of bounds
See Also:
isColumnAt(int)

isColumnAt

public boolean isColumnAt(int location)
Tells whether there is a column covering location.

Parameters:
location - a point on the axis that is orthogonal to the orientation of the columns
Returns:
whether there is a column directly covering location
See Also:
getColumnAt(int)

getInsertionLineAt

public int getInsertionLineAt(int column,
                              int location)
Tells where to insert an item during a drag and drop operation, if the mouse is hovering over the column column.

Parameters:
column - the column over which the mouse is hovering, must be an existing column
location - a point on the axis that is parallel to the orientation of the columns
Returns:
the best line to insert a new item or -1

maximumLayoutSize

public Dimension maximumLayoutSize(Container parent)
Specified by:
maximumLayoutSize in interface LayoutManager2

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)
Specified by:
preferredLayoutSize in interface LayoutManager

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)
Specified by:
minimumLayoutSize in interface LayoutManager

addListener

public void addListener(ToolbarGridLayoutManagerListener listener)
Adds the observer listener to this object. The observer will be called whenever the layout of a Container is updated.

Parameters:
listener - the new observer, not null

removeListener

public void removeListener(ToolbarGridLayoutManagerListener listener)
Removes the observer listener from this object.

Parameters:
listener - the listener to remove

layoutContainer

public void layoutContainer(Container parent)
Specified by:
layoutContainer in interface LayoutManager

layout

protected void layout(Container parent,
                      ToolbarGridLayoutManager.Wrapper[][] components,
                      Dimension required,
                      Dimension available,
                      bibliothek.gui.dock.station.toolbar.layout.ToolbarGridLayoutManager.Size size)
Layouts components such that they fit into available.

Parameters:
parent - the Container whose layout is upated
components - the components to layout
required - the size required for the optimal layout
available - the size that is actually available
size - which Dimension to get for layouting the components

getLayoutAlignmentX

public float getLayoutAlignmentX(Container target)
Specified by:
getLayoutAlignmentX in interface LayoutManager2

getLayoutAlignmentY

public float getLayoutAlignmentY(Container target)
Specified by:
getLayoutAlignmentY in interface LayoutManager2

invalidateLayout

public void invalidateLayout(Container target)
Specified by:
invalidateLayout in interface LayoutManager2

getBounds

public Rectangle getBounds(int column,
                           int line)
Calculates the current boundaries of the cell at column/line .

Parameters:
column - the column in which to search the cell
line - the row in column
Returns:
the boundaries, does not include any borders or offsets
Throws:
IllegalArgumentException - if there is no cell at column/line

getScreenBounds

public Rectangle getScreenBounds(int column,
                                 int line)

getBounds

public Rectangle getBounds(int column)
Gets the boundaries of the column at index column. This method returns the union of the boundaries of all cells, meaning if there are gaps between the cells they are included in the boundaries. But excess space around the cells (e.g. because other columns are bigger) is ignored by this method.

Parameters:
column - the column whose boundaries are searched
Returns:
the boundaries or null if the column column does not have any cells. This however is a special case that should not appear in a live application and indicates a bigger issue.
Throws:
IllegalArgumentException - if column is out of bounds

getScreenBounds

public Rectangle getScreenBounds(int column)

getGapBounds

public Rectangle getGapBounds(int column,
                              boolean includeScrollBars)
Gets the boundaries of the gab between the column column-1 and column. This is the gap of column to its left or top neighbor. The gap may have a width or height of 0, meaning the gap is not visible to the user. If column is 0, then the gap to the left or top end of the Container using this LayoutManager is returned. If column is equal to the total number of columns, the gap to the right or bottom end of the Container is returned.
If both columns do not use up all available space, then the result of this method does have a width and a height smaller then the width and height of the Container.

Parameters:
column - the column whose left gap is searched
includeScrollBars - if true, then the scrollbars are part of the gap as well
Returns:
the gap, null if one columns has no cells. This however is a case that should not appear in a live client and that indicates a bigger issue.
Throws:
IllegalArgumentException - if column is out of bounds

getGapBounds

public Rectangle getGapBounds(int column,
                              int line)
Gets the size of a gap between two rows.

Parameters:
column - the column in which the rows are
line - the row into which an item is inserted
Returns:
the gap between line-1 and line