bibliothek.gui.dock.station.toolbar.layout
Class PlaceholderToolbarGrid<D,S,P extends bibliothek.gui.dock.station.support.PlaceholderListItem<D>>

java.lang.Object
  extended by bibliothek.gui.dock.station.toolbar.layout.PlaceholderToolbarGrid<D,S,P>
Type Parameters:
D - the kind of object that should be treated as Dockable
S - the kind of object that should be treated as DockStation
P - the type of item which represents a Dockable
Direct Known Subclasses:
ModeledPlaceholderToolbarGrid

public abstract class PlaceholderToolbarGrid<D,S,P extends bibliothek.gui.dock.station.support.PlaceholderListItem<D>>
extends Object

A PlaceholderToolbarGrid behaves like a list of PlaceholderLists.

Author:
Benjamin Sigg

Constructor Summary
PlaceholderToolbarGrid()
           
 
Method Summary
 void addPlaceholder(int column, int line, bibliothek.util.Path placeholder)
          Stores the placeholder placeholder in the designated column.
protected  Iterator<bibliothek.gui.dock.station.support.PlaceholderList<D,S,P>> allColumns()
          Gets an iterator over all columns, including the columns with no content.
 void bind()
          Informs this grid that it is actually used and that it should be allowed to add observers to various resources.
 void clear()
          Removes all content from this grid.
protected  Iterator<bibliothek.gui.dock.station.support.PlaceholderList<D,S,P>> columns()
          Gets an iterator over all non-empty columns.
protected abstract  bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> createColumn()
          Creates one column.
protected abstract  GridPlaceholderList<D,S,P> createGrid()
          Creates a new GridPlaceholderList.
protected abstract  void fill(D dockable, bibliothek.gui.dock.station.support.ConvertedPlaceholderListItem item)
          Called by toMap(Map), this method should read persistent data from dockable and write that data into item.
 void fromMap(bibliothek.gui.dock.station.support.PlaceholderMap map)
          Replaces the content of this grid by a map that was written earlier using toMap() or toMap(Map).
 void fromMap(bibliothek.gui.dock.station.support.PlaceholderMap map, Map<Integer,D> identifiers, PlaceholderToolbarGridConverter<D,P> converter)
           
 P get(D dockable)
          Gets the item that represents dockable
 P get(int index)
          Gets the index'th item of this grid.
 P get(bibliothek.util.Path placeholder)
          Searches the item which is at the location of placeholder.
 int getColumn(D dockable)
          Tells in which non-empty column dockable is.
protected  bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> getColumn(int index)
          Gets the non-empty column with index index.
 int getColumn(bibliothek.util.Path placeholder)
          Gets the index of the first column that contains placeholder .
 Iterator<P> getColumnContent(int index)
          Gets an iterator over the contents of the index'th non-empty column.
 int getColumnCount()
          Gets the number of columns that are currently stored in this grid.
 int getLine(D dockable)
          Tells at which position dockable is within its column.
 int getLine(int column, D dockable)
          Tells at which position dockable is within the column column
 int getLine(int column, bibliothek.util.Path placeholder)
          Tells at which line placeholder appears in the column column.
 int getLine(bibliothek.util.Path placeholder)
          Tells at which line placeholder apperas in the first column that contains placeholder.
 int getLineCount(int column)
          Tells how many items are currently stored at the non-empty column with index column.
protected abstract  Set<bibliothek.util.Path> getPlaceholders(D dockable)
          Gets all placeholders that are associated with dockable.
 bibliothek.gui.dock.station.support.PlaceholderStrategy getStrategy()
          Gets the PlaceholderStrategy that is currently used by this grid.
 int getTotalColumnCount()
          Gets the total number of columns, this includes empty columns.
 boolean hasPlaceholder(bibliothek.util.Path placeholder)
          Tells whether this PlaceholderToolbarGrid knows a column which contains the placeholder placeholder, this includes empty columns.
protected  void init()
          Initializes all fields of this object.
 void insert(int column, int line, P item)
          Adds the item item to the non-empty column column into position line.
 void insert(int columnIndex, P item)
          Adds the item item to a new column, the new column will have the index columnIndex.
 void insert(int columnIndex, P item, boolean reuse)
          Adds the item item to a new column, the new column will have the index columnIndex.
 void insertPlaceholder(int column, int line, bibliothek.util.Path placeholder)
          Inserts placeholder into column column at line.
 Iterator<P> items()
          Gets an iterator that visits all items of this grid.
 void move(int sourceColumn, int sourceLine, int destinationColumn, int destinationLine, bibliothek.gui.dock.station.support.PlaceholderList.Level destinationLevel)
          Moves the item at sourceColumn/sourceLine to destinationColumn/destinationLine.
protected abstract  void onInserted()
          Called if all columns were inserted at the same time.
protected abstract  void onInserted(bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> column, int index)
          Called if a new column column was added to this grid.
protected abstract  void onInserted(bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> column, int columnIndex, P item, int itemIndex)
          Called if item was added to the column column.
protected abstract  void onRemoved()
          Called if all columns were removed from this grid
protected abstract  void onRemoved(bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> column, int index)
          Called if the column column was removed from this grid.
protected abstract  void onRemoved(bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> column, int columnIndex, P item, int itemIndex)
          Called if item was removed to the column column.
 boolean put(bibliothek.util.Path placeholder, P item)
          Tries to put item into this list at location placeholder.
 boolean remove(P item)
          Removes item from this grid, but leaves a placeholder for the item.
 void setStrategy(bibliothek.gui.dock.station.support.PlaceholderStrategy strategy)
          Sets the PlaceholderStrategy which is to be used by this grid.
 int size()
          Gets the total count of items stored in this grid.
 bibliothek.gui.dock.station.support.PlaceholderMap toMap()
          Converts this grid into a PlaceholderMap, if possible any Dockable is converted into a placeholder.
 bibliothek.gui.dock.station.support.PlaceholderMap toMap(Map<D,Integer> identifiers)
          Converts this grid into a PlaceholderMap using identifiers to remember which Dockable was a which position.
 void unbind()
          Informs this grid that it is no longer used and that is should remove any observers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlaceholderToolbarGrid

public PlaceholderToolbarGrid()
Method Detail

init

protected void init()
Initializes all fields of this object.


createColumn

protected abstract bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> createColumn()
Creates one column.

Returns:
a new, empty list

createGrid

protected abstract GridPlaceholderList<D,S,P> createGrid()
Creates a new GridPlaceholderList.

Returns:
the new, empty grid

getPlaceholders

protected abstract Set<bibliothek.util.Path> getPlaceholders(D dockable)
Gets all placeholders that are associated with dockable.

Parameters:
dockable - some element used by this grid
Returns:
the placeholders

onInserted

protected abstract void onInserted(bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> column,
                                   int columnIndex,
                                   P item,
                                   int itemIndex)
Called if item was added to the column column.

Parameters:
column - a visible column
columnIndex - the index of the column
item - a new item of column
itemIndex - the index of the new item

onRemoved

protected abstract void onRemoved(bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> column,
                                  int columnIndex,
                                  P item,
                                  int itemIndex)
Called if item was removed to the column column.

Parameters:
column - a visible column
columnIndex - the index of the column
item - the removed item of column
itemIndex - the index the item had before removing

onInserted

protected abstract void onInserted(bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> column,
                                   int index)
Called if a new column column was added to this grid. The column may not contain any elements when this method is called.

Parameters:
column - the new column
index - the index of the new column

onRemoved

protected abstract void onRemoved(bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> column,
                                  int index)
Called if the column column was removed from this grid. The column may still contain elements when it is removed.

Parameters:
column - the removed column
index - the index the column had before it was removed

onInserted

protected abstract void onInserted()
Called if all columns were inserted at the same time. This means that the grid previously was completely empty.


onRemoved

protected abstract void onRemoved()
Called if all columns were removed from this grid


clear

public void clear()
Removes all content from this grid.


insert

public void insert(int column,
                   int line,
                   P item)
Adds the item item to the non-empty column column into position line. This method may add a new column in order to store item.

Parameters:
column - the column in which to store item
line - the index within column
item - the item to store, not null
Throws:
IllegalArgumentException - if item is null
IllegalStateException - if there is no PlaceholderStrategy set

insert

public void insert(int columnIndex,
                   P item)
Adds the item item to a new column, the new column will have the index columnIndex. If columnIndex is out of bounds, then the new column will be added as near as possible to the preferred position. This method will try to reuse an empty column, if one is available at the desired location.

Parameters:
columnIndex - the column to add
item - the item to store, not null

insert

public void insert(int columnIndex,
                   P item,
                   boolean reuse)
Adds the item item to a new column, the new column will have the index columnIndex. If columnIndex is out of bounds, then the new column will be added as near as possible to the preferred position.

Parameters:
columnIndex - the column to add
item - the item to store, not null
reuse - if false then a new column will be built in any case, if true then this grid tries to reuse an existing yet empty column if possible

move

public void move(int sourceColumn,
                 int sourceLine,
                 int destinationColumn,
                 int destinationLine,
                 bibliothek.gui.dock.station.support.PlaceholderList.Level destinationLevel)
Moves the item at sourceColumn/sourceLine to destinationColumn/destinationLine. The operation behaves as if the item would first be removed from the source position, and afterwards inserted at the destination position.

Parameters:
sourceColumn - the column in which to find the item, only includes non-empty columns
sourceLine - the line in the column in which to find the item
destinationColumn - the column in which to insert the item
destinationLine - the line at which to insert the item
destinationLevel - the level at which to find destinationColumn, will be converted to an index from PlaceholderList.Level.BASE
Throws:
IllegalArgumentException - if any index is out of bounds

put

public boolean put(bibliothek.util.Path placeholder,
                   P item)
Tries to put item into this list at location placeholder. If there is already an element at placeholder, then the old item is silenlty removed and the new item inserted. This method may create a new non-empty column if necessary.

Parameters:
placeholder - the name of the item
item - the item to insert
Returns:
true if insertion was a success, false otherwise

addPlaceholder

public void addPlaceholder(int column,
                           int line,
                           bibliothek.util.Path placeholder)
Stores the placeholder placeholder in the designated column.

Parameters:
column - the column in which to add placeholder, only includes non-empty columns
line - the line in which to add placeholder
placeholder - the placeholder to store

insertPlaceholder

public void insertPlaceholder(int column,
                              int line,
                              bibliothek.util.Path placeholder)
Inserts placeholder into column column at line. This method may create a new column if column is as big as the grid.

Parameters:
column - the column into which to insert placeholder, includes empty columns.
line - the line into which to insert placeholder
placeholder - the new placeholder, not null

remove

public boolean remove(P item)
Removes item from this grid, but leaves a placeholder for the item.

Parameters:
item - the item to remove
Returns:
true if item was found and removed

getColumn

public int getColumn(D dockable)
Tells in which non-empty column dockable is.

Parameters:
dockable - the item to search
Returns:
the column of the dockable or -1 if not found

getColumn

public int getColumn(bibliothek.util.Path placeholder)
Gets the index of the first column that contains placeholder .

Parameters:
placeholder - the placeholder to search
Returns:
the first column with placeholder or -1 if not found, this includes empty columns

getLine

public int getLine(D dockable)
Tells at which position dockable is within its column.

Parameters:
dockable - the item to search
Returns:
the location of dockable

getLine

public int getLine(int column,
                   D dockable)
Tells at which position dockable is within the column column

Parameters:
column - the index of the non-empty column to search
dockable - the item to search
Returns:
the location of dockable

getLine

public int getLine(bibliothek.util.Path placeholder)
Tells at which line placeholder apperas in the first column that contains placeholder. This includes empty columns.

Parameters:
placeholder - the placeholder to search
Returns:
the line at which placeholder was found

getLine

public int getLine(int column,
                   bibliothek.util.Path placeholder)
Tells at which line placeholder appears in the column column.

Parameters:
column - the index of the column, this includes empty columns
placeholder - the placeholder to search
Returns:
the index the item would have or -1 if placeholder was not found

hasPlaceholder

public boolean hasPlaceholder(bibliothek.util.Path placeholder)
Tells whether this PlaceholderToolbarGrid knows a column which contains the placeholder placeholder, this includes empty columns.

Parameters:
placeholder - the placeholder to search
Returns:
true if placeholder was found

size

public int size()
Gets the total count of items stored in this grid.

Returns:
the total amount of items

get

public P get(int index)
Gets the index'th item of this grid.

Parameters:
index - the index of the item
Returns:
the item
Throws:
IllegalArgumentException - if index is not valid

get

public P get(D dockable)
Gets the item that represents dockable

Parameters:
dockable - the dockable to search
Returns:
the item that represents dockable or null if not found

get

public P get(bibliothek.util.Path placeholder)
Searches the item which is at the location of placeholder.

Parameters:
placeholder - some placeholder that may or may not be known to this grid
Returns:
the item at placeholder or null either if placeholder was not found or if there is no item stored

allColumns

protected Iterator<bibliothek.gui.dock.station.support.PlaceholderList<D,S,P>> allColumns()
Gets an iterator over all columns, including the columns with no content. This does not include columns with no list (columns that consist only of placeholders).

Returns:
all columns

columns

protected Iterator<bibliothek.gui.dock.station.support.PlaceholderList<D,S,P>> columns()
Gets an iterator over all non-empty columns. The iterator does not support modifications nor is it concurrent.

Returns:
the iterator

items

public Iterator<P> items()
Gets an iterator that visits all items of this grid.

Returns:
the iterator

getColumnCount

public int getColumnCount()
Gets the number of columns that are currently stored in this grid. Empty columns are excluded.

Returns:
the total number of non-empty columns

getLineCount

public int getLineCount(int column)
Tells how many items are currently stored at the non-empty column with index column.

Parameters:
column - the index of a non-empty column
Returns:
the size of the column

getTotalColumnCount

public int getTotalColumnCount()
Gets the total number of columns, this includes empty columns.

Returns:
the total number of columns

getColumnContent

public Iterator<P> getColumnContent(int index)
Gets an iterator over the contents of the index'th non-empty column.

Parameters:
index - the index of the non-empty column
Returns:
the content of the non-empty column

getColumn

protected bibliothek.gui.dock.station.support.PlaceholderList<D,S,P> getColumn(int index)
Gets the non-empty column with index index. Subclasses should not modify the returned list.

Parameters:
index - the index of the column
Returns:
the non-empty column or null if no such column exists

bind

public void bind()
Informs this grid that it is actually used and that it should be allowed to add observers to various resources.


unbind

public void unbind()
Informs this grid that it is no longer used and that is should remove any observers.


setStrategy

public void setStrategy(bibliothek.gui.dock.station.support.PlaceholderStrategy strategy)
Sets the PlaceholderStrategy which is to be used by this grid.

Parameters:
strategy - the new strategy, can be null

getStrategy

public bibliothek.gui.dock.station.support.PlaceholderStrategy getStrategy()
Gets the PlaceholderStrategy that is currently used by this grid.

Returns:
the strategy, can be null

fill

protected abstract void fill(D dockable,
                             bibliothek.gui.dock.station.support.ConvertedPlaceholderListItem item)
Called by toMap(Map), this method should read persistent data from dockable and write that data into item.

Parameters:
dockable - the dockable to read
item - the item to write into

toMap

public bibliothek.gui.dock.station.support.PlaceholderMap toMap(Map<D,Integer> identifiers)
Converts this grid into a PlaceholderMap using identifiers to remember which Dockable was a which position.

Parameters:
identifiers - identifiers for all children of the DockStation using this grid
Returns:
the map that persistently stores all data of this grid

fromMap

public void fromMap(bibliothek.gui.dock.station.support.PlaceholderMap map,
                    Map<Integer,D> identifiers,
                    PlaceholderToolbarGridConverter<D,P> converter)

toMap

public bibliothek.gui.dock.station.support.PlaceholderMap toMap()
Converts this grid into a PlaceholderMap, if possible any Dockable is converted into a placeholder.

Returns:
the converted map

fromMap

public void fromMap(bibliothek.gui.dock.station.support.PlaceholderMap map)
Replaces the content of this grid by a map that was written earlier using toMap() or toMap(Map).

Parameters:
map - the map to read, not null