bibliothek.gui.dock.frontend
Class DefaultLayoutChangeStrategy

java.lang.Object
  extended by bibliothek.gui.dock.frontend.DefaultLayoutChangeStrategy
All Implemented Interfaces:
LayoutChangeStrategy
Direct Known Subclasses:
CLayoutChangeStrategy

public class DefaultLayoutChangeStrategy
extends Object
implements LayoutChangeStrategy

This default implementation of a LayoutChangeStrategy heavily depends on the methods of PredefinedDockSituation. It also offers a set of methods that may be interesting for subclasses which do not use a PredefinedDockSituation.

Author:
Benjamin Sigg

Nested Class Summary
protected  class DefaultLayoutChangeStrategy.SettingAccess
          A wrapper around a Setting, allows algorithms access to the settings but also allows to modify the data without changing the setting.
 
Constructor Summary
DefaultLayoutChangeStrategy()
           
 
Method Summary
protected  void applyInvisibleLayout(DockFrontendInternals frontend, DockSituation situation, DefaultLayoutChangeStrategy.SettingAccess setting)
          Applies setting to the invisible elements.
protected  void applyLayout(DockFrontendInternals frontend, DockSituation situation, DefaultLayoutChangeStrategy.SettingAccess setting, boolean entry)
          Applies the layout described in setting to the visible elements.
protected  Collection<Dockable> approveClosing(DockFrontendInternals frontend, DockSituation situation, DefaultLayoutChangeStrategy.SettingAccess setting)
          Asks the VetoManager whether some Dockables can be hidden.
protected  DefaultLayoutChangeStrategy.SettingAccess createAccess(DockFrontendInternals frontend, Setting setting)
          Creates a wrapper around setting that allows the algorithm of this LayoutChangeStrategy to access the setting.
 DockFrontendPerspective createPerspective(DockFrontendInternals frontend, boolean entry, FrontendPerspectiveCache cache)
          Creates a Perspective that is used to read and write perspectives related to frontend.
 PredefinedDockSituation createSituation(DockFrontendInternals frontend, boolean entry)
          Forwards to createSituation(DockFrontendInternals, boolean, boolean) with the last argument set to false.
protected  PredefinedDockSituation createSituation(DockFrontendInternals frontend, boolean entry, boolean onSetLayout)
          Creates a DockSituation which represents all the knowledge frontend currently has.
 PropertyTransformer createTransformer(DockFrontendInternals frontend)
          Creates a converter for reading and writing DockablePropertys.
 void estimateLocations(DockFrontendInternals frontend, DockSituation situation, DockLayoutComposition layout)
          Tries to fill the property location for each element in layout.
protected  Set<Dockable> estimateVisible(DockFrontendInternals frontend, DockSituation situation, DockLayoutComposition layout)
          Tries to estimate which of the currently visible Dockables will still be visible if layout is applied to frontend.
protected  Collection<Dockable> getClosingDockables(DockFrontendInternals frontend, Set<Dockable> visible)
          Creates a collection of all the Dockables that are about to be closed.
 PlaceholderStrategy getPlaceholderStrategy(DockFrontendInternals frontend)
          Gets the default PlaceholderStrategy which should be used to filter placeholders by frontend.
protected  Map<String,DockableProperty> listEstimateLocations(DockSituation situation, DockLayoutComposition layout)
          Tries to estimate the location of missing Dockables.
protected  Map<String,DockLayoutComposition> listLayouts(DockSituation situation, DockLayoutComposition layout)
          Tries to estimate the layouts of missing Dockables.
 boolean setLayout(DockFrontendInternals frontend, Setting setting, boolean entry)
          Changes the layout of frontend by reading and applying setting.
protected  boolean shouldPredefine(Dockable dockable)
          Tells whether the element dockable should be added as predefined element to the PredefinedDockSituation that is created by createSituation(DockFrontendInternals, boolean, boolean).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLayoutChangeStrategy

public DefaultLayoutChangeStrategy()
Method Detail

setLayout

public boolean setLayout(DockFrontendInternals frontend,
                         Setting setting,
                         boolean entry)
                  throws IOException,
                         XException
Description copied from interface: LayoutChangeStrategy
Changes the layout of frontend by reading and applying setting. The DockRegister is stalled while this method runs.
This method should use the VetoManager provided by frontend to ensure that all operations are legal.

Specified by:
setLayout in interface LayoutChangeStrategy
Parameters:
frontend - internal information about a DockFrontend
setting - the layout to read and apply
entry - true if setting contains only little information about the layout, false if there is much information abut the layout.
Returns:
true if the layout has been applied, false if the operation was canceled due of any reason
Throws:
IOException - in case of some stream that cannot be read
XException - in case of some XElement that cannot be read

createAccess

protected DefaultLayoutChangeStrategy.SettingAccess createAccess(DockFrontendInternals frontend,
                                                                 Setting setting)
Creates a wrapper around setting that allows the algorithm of this LayoutChangeStrategy to access the setting.

Parameters:
frontend - the caller of this method
setting - the setting to hide
Returns:
the wrapper

createSituation

public PredefinedDockSituation createSituation(DockFrontendInternals frontend,
                                               boolean entry)
Forwards to createSituation(DockFrontendInternals, boolean, boolean) with the last argument set to false.

Specified by:
createSituation in interface LayoutChangeStrategy
Parameters:
frontend - the frontend for which the situation is required
entry - true if the situation is used for a regular setting, false if the situation is used as the final setting which will be loaded the next time the application starts.
Returns:
the situation

createSituation

protected PredefinedDockSituation createSituation(DockFrontendInternals frontend,
                                                  boolean entry,
                                                  boolean onSetLayout)
Creates a DockSituation which represents all the knowledge frontend currently has.

Parameters:
frontend - the frontend for which the situation is required
entry - true if the situation is used for a regular setting, false if the situation is used as the final setting which will be loaded the next time the application starts.
onSetLayout - whether this method is called by setLayout(DockFrontendInternals, Setting, boolean) or not. If true then the situation is used to apply some layout, otherwise it is used to store or read a layout
Returns:
the situation, the default implementation always returns a PredefinedDockSituation, subclasses may override and return other situations.

shouldPredefine

protected boolean shouldPredefine(Dockable dockable)
Tells whether the element dockable should be added as predefined element to the PredefinedDockSituation that is created by createSituation(DockFrontendInternals, boolean, boolean).

Parameters:
dockable - the element which may need to be predefined
Returns:
true if dockable is to be predefined

createPerspective

public DockFrontendPerspective createPerspective(DockFrontendInternals frontend,
                                                 boolean entry,
                                                 FrontendPerspectiveCache cache)
Description copied from interface: LayoutChangeStrategy
Creates a Perspective that is used to read and write perspectives related to frontend.

Specified by:
createPerspective in interface LayoutChangeStrategy
Parameters:
frontend - the frontend for which the situation is required
entry - true if the situation is used for a regular setting, false if the situation is used as the final setting which will be loaded the next time the application starts.
cache - a cache that takes DockElements and returns the matching PerspectiveElement. The cache also offers methods to convert ids and PerspectiveElements directly
Returns:
the new perspective

createTransformer

public PropertyTransformer createTransformer(DockFrontendInternals frontend)
Description copied from interface: LayoutChangeStrategy
Creates a converter for reading and writing DockablePropertys.

Specified by:
createTransformer in interface LayoutChangeStrategy
Parameters:
frontend - the frontend for which the converter is required
Returns:
the new converter

applyLayout

protected void applyLayout(DockFrontendInternals frontend,
                           DockSituation situation,
                           DefaultLayoutChangeStrategy.SettingAccess setting,
                           boolean entry)
                    throws IOException,
                           XException
Applies the layout described in setting to the visible elements. This implementation tries to estimate the location of missing dockables using listEstimateLocations(DockSituation, DockLayoutComposition).

Parameters:
frontend - the caller of this method
situation - used to convert the layout
setting - the new layout
entry - whether the layout is a full or regular layout
Throws:
IOException - if the layout cannot be converted
XException - if the layout cannot be converted

applyInvisibleLayout

protected void applyInvisibleLayout(DockFrontendInternals frontend,
                                    DockSituation situation,
                                    DefaultLayoutChangeStrategy.SettingAccess setting)
                             throws IOException,
                                    XException
Applies setting to the invisible elements.

Parameters:
frontend - the caller of this method
situation - to convert the layout
setting - the new layout
Throws:
IOException - if the layout cannot be converted
XException - if the layout cannot be converted

listLayouts

protected Map<String,DockLayoutComposition> listLayouts(DockSituation situation,
                                                        DockLayoutComposition layout)
Tries to estimate the layouts of missing Dockables. The default implementation works with any PredefinedDockSituation.

Parameters:
situation - the situation to use for transforming information
layout - the layout to analyze
Returns:
a map with Dockable-names as key or null

listEstimateLocations

protected Map<String,DockableProperty> listEstimateLocations(DockSituation situation,
                                                             DockLayoutComposition layout)
Tries to estimate the location of missing Dockables. The default implementation works with any PredefinedDockSituation.

Parameters:
situation - the situation to use for transforming information
layout - the layout to analyze
Returns:
a map with Dockable-names as key or null

estimateLocations

public void estimateLocations(DockFrontendInternals frontend,
                              DockSituation situation,
                              DockLayoutComposition layout)
Description copied from interface: LayoutChangeStrategy
Tries to fill the property location for each element in layout.

Specified by:
estimateLocations in interface LayoutChangeStrategy
Parameters:
frontend - the frontend which calls this method
situation - the situation to use for transforming information
layout - the layout to estimate

approveClosing

protected Collection<Dockable> approveClosing(DockFrontendInternals frontend,
                                              DockSituation situation,
                                              DefaultLayoutChangeStrategy.SettingAccess setting)
Asks the VetoManager whether some Dockables can be hidden. Only Dockables that are returned by DockFrontendInternals.getDockables() are checked by this method.

Parameters:
frontend - the caller of this method
situation - the situation that will convert the layout
setting - the new layout
Returns:
the set of elements for which closing was explicitly approved or null if the operation should be canceled

getClosingDockables

protected Collection<Dockable> getClosingDockables(DockFrontendInternals frontend,
                                                   Set<Dockable> visible)
Creates a collection of all the Dockables that are about to be closed. Subclasses may override this method, they should at least check all the Dockables that are registered at frontend. Subclasses may need to override estimateVisible as well to get the correct set of visible elements.

Parameters:
frontend - the caller of this method
visible - the elements that remain visible as told by estimateVisible(DockFrontendInternals, DockSituation, DockLayoutComposition).
Returns:
the set of dockables that is about to be closed, not null, may be empty

estimateVisible

protected Set<Dockable> estimateVisible(DockFrontendInternals frontend,
                                        DockSituation situation,
                                        DockLayoutComposition layout)
Tries to estimate which of the currently visible Dockables will still be visible if layout is applied to frontend. The default implementation assumes that situation is a PredefinedDockSituation.
Subclasses may override this method and modify the result in any way they like

Parameters:
frontend - the caller of this method
situation - algorithm used to convert layout
layout - the layout that will be applied
Returns:
an estimation of the elements that will be made invisible or null

getPlaceholderStrategy

public PlaceholderStrategy getPlaceholderStrategy(DockFrontendInternals frontend)
Description copied from interface: LayoutChangeStrategy
Gets the default PlaceholderStrategy which should be used to filter placeholders by frontend.

Specified by:
getPlaceholderStrategy in interface LayoutChangeStrategy
Parameters:
frontend - information about the DockFrontend that needs the strategy
Returns:
the strategy, can be null