bibliothek.gui.dock.layout
Class PredefinedDockSituation

java.lang.Object
  extended by bibliothek.gui.dock.layout.DockSituation
      extended by bibliothek.gui.dock.layout.PredefinedDockSituation

public class PredefinedDockSituation
extends DockSituation

A DockSituation that does not load or store all DockElements. All elements which are registered by put(DockElement) are stored in an internal list. On writing, just a unique id is written to the stream. A DockFactory is still necessary for these elements, but the factory may just do nothing.

Author:
Benjamin Sigg

Constructor Summary
PredefinedDockSituation()
           
 
Method Summary
 void addBackup(DockFactory<? extends DockElement,?,BackupFactoryData<?>> factory)
          Adds a backup factory to this situation.
static java.lang.String convertFactoryID(java.lang.String id)
          Given the unique identifier of a factory tells what identifier will be used internally.
 PredefinedPerspective createPerspective()
          Creates a new PredefinedPerspective.
protected  DockLayoutInfo fillMissing(DockLayoutInfo info)
          Called by DockSituation.fillMissing(DockLayoutComposition) only for DockLayoutInfos which contain a DockLayout.
protected  DockFactory<? extends DockElement,?,BackupFactoryData<?>> getBackup(java.lang.String id)
          Searches a backup factory with the name id.
 DockFactory<? extends DockElement,?,?> getFactory(java.lang.String id)
          Gets the factory which has the given id.
protected  java.lang.String getFactoryID(java.lang.String id)
          Transforms an id read from a stream to the id of the factory which would be used.
 java.lang.String getID(DockElement dockable)
          Gets the id of the factory which is needed to write (and later read) element
protected  java.lang.String getID(DockFactory<?,?,?> factory)
          Gets the id of factory.
protected  java.lang.String getID(PerspectiveElement element, PredefinedPerspective perspective)
          Gets the identifier that matches element which is part of perspective.
 java.util.Map<java.lang.String,DockableProperty> listEstimatedLocations(DockLayoutComposition composition, boolean missingOnly)
          Lists for all keys that can be found in composition its estimated location.
 java.util.Map<java.lang.String,DockableProperty> listEstimatedLocations(DockLayoutComposition composition, DockableProperty location, boolean missingOnly)
          Lists for all keys that can be found in composition its estimated location.
 java.util.Map<java.lang.String,DockLayoutComposition> listLayouts(DockLayoutComposition composition, boolean missingOnly)
          Gets a map containing some or all of the named layouts.
<D extends DockElement>
java.util.Set<D>
listVisible(java.util.Collection<D> base, DockLayoutComposition composition)
          Given a set of Dockables this method estimates which of them will be visible once composition is applied.
 void put(DockElement element)
          Deprecated. use put(String, DockElement) instead
 void put(java.lang.String key, DockElement element)
          Registers an element at this situation.
 void removeBackup(java.lang.String id)
          Removes the backup factory with the name id.
protected  boolean shouldLayout(DockElement element)
          Tells whether the layout of element itself should be stored or loaded, that will not prevent the element from showing up but from changing its content.
protected  boolean shouldLayout(PerspectiveElement element, PredefinedPerspective perspective)
          Tells whether the layout of element itself should be stored or loaded, that will not prevent the element from showing up but from changing its content.
 
Methods inherited from class bibliothek.gui.dock.layout.DockSituation
add, addAdjacent, convert, convert, convertFactoryId, convertFactoryId, estimateLocations, estimateLocations, estimateLocations, fillMissing, getAdjacentFactory, getAdjacentFactoryID, getAdjacentFactorys, getAdjacentID, getFactoryID, getID, getIgnore, getIntermediatePlaceholders, getMissingAdjacentFactory, getMissingFactory, getPlaceholder, getPlaceholderStrategy, ignoreChildren, ignoreElement, read, read, readComposition, readCompositions, readCompositionsXML, readCompositionXML, readXML, setIgnore, setIntermediatePlaceholders, setMissingAdjacentFactory, setMissingFactory, setPlaceholderStrategy, write, write, writeComposition, writeCompositions, writeCompositionsXML, writeCompositionXML, writeXML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PredefinedDockSituation

public PredefinedDockSituation()
Method Detail

createPerspective

public PredefinedPerspective createPerspective()
Creates a new PredefinedPerspective. This perspective will write the layout in such a way that a PredefinedDockSituation can read it again.
Please note that clients need to register DockElements using PredefinedPerspective.put(String, PerspectiveElement) before the perspective can be used. The DockElements registered to this by using put(String, DockElement) are ignored by the perspective.

Overrides:
createPerspective in class DockSituation
Returns:
the new perspective

addBackup

public void addBackup(DockFactory<? extends DockElement,?,BackupFactoryData<?>> factory)
Adds a backup factory to this situation. A backup factory is used when an element should be in the cache, but is missing. The backup factory receives a BackupFactoryData object, the identifier of that object does not have to be stored by factory. The factory has only to look at the data-property. This PredefinedDockSituation will set the identifier whenever a method of factory is called, that has a BackupFactoryData as parameter.

Parameters:
factory - a backup factory

removeBackup

public void removeBackup(java.lang.String id)
Removes the backup factory with the name id.

Parameters:
id - the id of the factory which should be removed

put

@Deprecated
public void put(DockElement element)
Deprecated. use put(String, DockElement) instead

Registers an element at this situation. When a stream is read, this element will be returned instead of a newly created element (assuming that the element was written into the stream). The key for the element is generated automatically.
Note: the order in which elements are added is important as the unique key depends on the order.

Parameters:
element - the element

put

public void put(java.lang.String key,
                DockElement element)
Registers an element at this situation. When a stream is read, this element will be returned instead a newly created element (assuming that the element was written into the stream).

Parameters:
key - the key of the element
element - the element
Throws:
java.lang.IllegalArgumentException - if the key is already used

shouldLayout

protected boolean shouldLayout(DockElement element)
Tells whether the layout of element itself should be stored or loaded, that will not prevent the element from showing up but from changing its content. The default implementation returns always true. This method is intended to be overridden by subclasses.

Parameters:
element - the element whose contents might or might not be stored or loaded
Returns:
true if the contents should be handled, false if they should be discarded

shouldLayout

protected boolean shouldLayout(PerspectiveElement element,
                               PredefinedPerspective perspective)
Tells whether the layout of element itself should be stored or loaded, that will not prevent the element from showing up but from changing its content. The default implementation uses the maps of perspective and this DockSituation to convert element into a preset DockElement and calls shouldLayout(DockElement). If the element is not found, true is returned.

Parameters:
element - the element whose contents might or might not be stored or loaded
perspective - the perspective for which the question has to be answered
Returns:
true if the contents should be handled, false if they should be discarded

fillMissing

protected DockLayoutInfo fillMissing(DockLayoutInfo info)
Description copied from class: DockSituation
Called by DockSituation.fillMissing(DockLayoutComposition) only for DockLayoutInfos which contain a DockLayout. This method can apply further updates to info if necessary. The default implementation just returns info.
This method is intended for subclasses which wrap DockFactorys and use a DockLayout even for incomplete data.

Overrides:
fillMissing in class DockSituation
Parameters:
info - the info to update
Returns:
either info if nothing changed or a new DockLayoutInfo if additional information could be retrieved

listVisible

public <D extends DockElement> java.util.Set<D> listVisible(java.util.Collection<D> base,
                                                            DockLayoutComposition composition)
Given a set of Dockables this method estimates which of them will be visible once composition is applied.

Type Parameters:
D - the kind of elements to check
Parameters:
base - a collection of Dockables in no specific order and with no restrictions
composition - location information for various elements
Returns:
A subset of base with those elements which will be visible once this situation converts composition

listEstimatedLocations

public java.util.Map<java.lang.String,DockableProperty> listEstimatedLocations(DockLayoutComposition composition,
                                                                               boolean missingOnly)
Lists for all keys that can be found in composition its estimated location.
Note: This method will call DockSituation.estimateLocations(DockLayoutComposition) to get the most recent locations

Parameters:
composition - some composition to search for keys and locations
missingOnly - if set, then only locations of keys for which no DockLayout is set are reported. This are the keys which most likely will be ignored when calling DockSituation.convert(DockLayoutComposition)
Returns:
the map of keys and positions, might be empty

listEstimatedLocations

public java.util.Map<java.lang.String,DockableProperty> listEstimatedLocations(DockLayoutComposition composition,
                                                                               DockableProperty location,
                                                                               boolean missingOnly)
Lists for all keys that can be found in composition its estimated location.
Note: This method will call DockSituation.estimateLocations(DockLayoutComposition) to get the most recent locations

Parameters:
composition - some composition to search for keys and locations
location - the location of composition itself
missingOnly - if set, then only locations of keys for which no DockLayout is set are reported. This are the keys which most likely will be ignored when calling DockSituation.convert(DockLayoutComposition)
Returns:
the map of keys and positions, might be empty

listLayouts

public java.util.Map<java.lang.String,DockLayoutComposition> listLayouts(DockLayoutComposition composition,
                                                                         boolean missingOnly)
Gets a map containing some or all of the named layouts.

Parameters:
composition - some composition to analyze
missingOnly - if set, then only locations of keys for which no DockLayout is set are reported. This are the keys which most likely will be ignored when calling DockSituation.convert(DockLayoutComposition)
Returns:
the map of keys and layouts, might be empty

getID

protected java.lang.String getID(PerspectiveElement element,
                                 PredefinedPerspective perspective)
Gets the identifier that matches element which is part of perspective.

Parameters:
element - some element whose identifier is searched
perspective - the owner of element
Returns:
the identifier

getID

public java.lang.String getID(DockElement dockable)
Description copied from class: DockSituation
Gets the id of the factory which is needed to write (and later read) element

Overrides:
getID in class DockSituation
Parameters:
dockable - the element to read
Returns:
the id of the factory
See Also:
DockSituation.getID(DockFactory), DockSituation.getFactory(String)

getID

protected java.lang.String getID(DockFactory<?,?,?> factory)
Description copied from class: DockSituation
Gets the id of factory. The default behavior is just to return DockConverter.getID(). Note that this method should be a bijection to DockSituation.getFactory(String).

Overrides:
getID in class DockSituation
Parameters:
factory - the factory whose id is needed
Returns:
the id of the factory

getFactoryID

protected java.lang.String getFactoryID(java.lang.String id)
Description copied from class: DockSituation
Transforms an id read from a stream to the id of the factory which would be used. This method must fulfill one contract: DockFactory factory = ... factory.getID().equals( getFactoryID( getID( factory )));

Overrides:
getFactoryID in class DockSituation
Parameters:
id - the id read from a stream
Returns:
the id of the original factory

convertFactoryID

public static java.lang.String convertFactoryID(java.lang.String id)
Given the unique identifier of a factory tells what identifier will be used internally. This method may be useful if creating a DockLayout manually.

Parameters:
id - the id of some factory
Returns:
the id that will be used internally

getFactory

public DockFactory<? extends DockElement,?,?> getFactory(java.lang.String id)
Description copied from class: DockSituation
Gets the factory which has the given id. Note that this method should be a bijection to DockSituation.getID(DockFactory). The default behavior compares id with the DockSituation.getID(DockFactory).

Overrides:
getFactory in class DockSituation
Parameters:
id - the name of the factory
Returns:
the factory or null if no factory has this id

getBackup

protected DockFactory<? extends DockElement,?,BackupFactoryData<?>> getBackup(java.lang.String id)
Searches a backup factory with the name id.

Parameters:
id - the name of the factory
Returns:
the factory or null