JIDE 3.5.15

com.jidesoft.swing
Class LayoutPersistenceManager

java.lang.Object
  extended by com.jidesoft.swing.AbstractLayoutPersistence
      extended by com.jidesoft.swing.LayoutPersistenceManager
All Implemented Interfaces:
LayoutPersistence

public class LayoutPersistenceManager
extends AbstractLayoutPersistence

LayoutPersistenceManager can manage multiple LayoutPersistences as one unit. Right now DockingManager and DockableBarManager are both LayoutPersistence. If user call saveLayout on both managers, you will end up with two layout files (or two entries in registry). If user didn't set profile key correctly, the two could even step on each other. That's why introduce LayoutPersistenceManager.

If you use DefaultDockableBarHolder (for Action Framework only) or DefaultDockableHolder (for Docking Framework only) as your JFrame, there is no change to the way you load/save layout.

If you are using DefaultDockableBarDockableHolder, you should call all layout related methods on getLayoutPersistence(). For example, frame.getLayoutPersistence().saveLayoutData(), frame.getLayoutPersistence().setProfileKey()

If you are not using DefaultDockableBarDockableHolder for some reason, you need to add some code to make it happen.

First, create a new field call LayoutPersistenceManager _layoutPersistence. After initiaization of DockingManager and DockableBarManager, call the code below.


  _layoutPersistence = new LayoutPersistenceManager();
  _layoutPersistence.addLayoutPersistence(getDockableBarManager());
  _layoutPersistence.addLayoutPersistence(getDockingManager());
 

Then add a new method. See below.

  public LayoutPersistence getLayoutPersistence() {
      return _layoutPersistence;
  }
 
Now in your code to use layout, call those layout methods use getLayoutPersistence() you just added. For example, when you save layout, call getLayoutPersistence().saveLayoutData(). When loading layout, call getLayoutPersistence().loadLayoutData(). Or if you want to change profile key, call getLayoutPersistence().setProfileKey(newKey).

A2. SampleVsnet example is such an example using DefaultDockableBarDockableHolder. You can always refer to its source code to find out how to use the class.


Field Summary
static String NODE_DOCKABLE_BAR_MANAGER
           
static String NODE_DOCKING_MANAGER
           
static String NODE_DOCUMENT_PANE
           
 
Fields inherited from class com.jidesoft.swing.AbstractLayoutPersistence
_layoutDirectory, _loadingLayoutData, _profileKey, _useFrameBounds, _useFrameBoundsSet, _useFrameState, _useFrameStateSet, _usePref, _version, DEFAULT_PROFILE_NAME, LAYOUT_COUNT_STRING, LAYOUT_POSTFIX, MAX_PREF_BYTE_ARRAY_LENGTH, PROPERTY_PROFILE_KEY, PROPERTY_USE_PREF, PROPERTY_VERSION, V2004, V2005_09
 
Fields inherited from interface com.jidesoft.swing.LayoutPersistence
ATTRIBUTE_PERSISTENCE_NAME, NODE_LAYOUT_PERSISTENCE
 
Constructor Summary
LayoutPersistenceManager()
           
 
Method Summary
 void addLayoutPersistence(LayoutPersistence layoutPersistence)
           
 void beginLoadLayoutData()
          Starts a process to add/remove frame or dockable bar without showing on screen immediately.
 void clear()
           
 boolean isLast()
          Checks if it is the last one during when loading several several LayoutPersistences.
 boolean isLoadDataSuccessful()
          Did the loadLayoutFrom(InputStream in) method load successfully from the input stream (false indicates that it called resetToDefault to load the layout.) This method can be called immediately after the loadLayoutFrom(InputStream in) call to determine if a specific LayoutPersistence was forced to call resetToDefault.
 void loadInitialLayout(Document layoutDocument)
          Load initial layout from an initial layout file designed by Visual Designer.
 void loadInitialLayout(InputStream layoutStream)
          Load initial layout from an initial layout file designed by Visual Designer.
 void loadInitialLayout(String layoutFile)
          Load initial layout from an initial layout file designed by Visual Designer.
 boolean loadLayoutFrom(Document document)
          Load layout data from an Node that specified as node parameter.
 boolean loadLayoutFrom(InputStream in)
          Load layout data from an InputStream that specified as in parameter.
 void removeLayoutPersistence(LayoutPersistence layoutPersistence)
           
 void resetToDefault()
          Resets layout.
 void saveLayoutTo(Document document)
          Save layout data to a Document that specified as document parameter.
 void saveLayoutTo(OutputStream out)
          Save layout data to an OutputStream that specified as out parameter.
 void setLast(boolean last)
          Sets the LayoutPersistence as the last one (or not the last one) when loading several LayoutPersistences.
 void setLayoutDirectory(String layoutDirectory)
          Sets the layout directory.
 void setProfileKey(String profileKey)
          Sets the profile key to be used to store layout information.
 void setUseFrameBounds(boolean useFrameBounds)
          If true, the bounds of main frame will be persisted in layout data.
 void setUseFrameState(boolean useFrameState)
          If true, the state of main frame will be persisted in layout data.
 void setUsePref(boolean usePref)
          If true, use javax.util.pref to store frames layout data.
 void setVersion(short version)
          Sets version number of profile.
 
Methods inherited from class com.jidesoft.swing.AbstractLayoutPersistence
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getAvailableLayouts, getLayoutDirectory, getLayoutPersistenceName, getLayoutRawData, getLoadCallback, getProfileKey, getPropertyChangeListeners, getPropertyChangeListeners, getSaveCallback, getVersion, getXmlEncoding, isLayoutAvailable, isLayoutDataVersionValid, isLoadingLayoutData, isNeedFormatCheck, isUsePref, isVersionCompatible, isXmlFormat, loadLayoutData, loadLayoutDataFrom, loadLayoutDataFromFile, removeLayout, removePropertyChangeListener, removePropertyChangeListener, saveLayoutData, saveLayoutDataAs, saveLayoutDataToFile, setLayoutPersistenceName, setLayoutRawData, setLoadCallback, setLoadingLayoutData, setNeedFormatCheck, setSaveCallback, setXmlEncoding, setXmlFormat, shouldUseFrameBounds, shouldUseFrameState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NODE_DOCKING_MANAGER

public static final String NODE_DOCKING_MANAGER
See Also:
Constant Field Values

NODE_DOCKABLE_BAR_MANAGER

public static final String NODE_DOCKABLE_BAR_MANAGER
See Also:
Constant Field Values

NODE_DOCUMENT_PANE

public static final String NODE_DOCUMENT_PANE
See Also:
Constant Field Values
Constructor Detail

LayoutPersistenceManager

public LayoutPersistenceManager()
Method Detail

addLayoutPersistence

public void addLayoutPersistence(LayoutPersistence layoutPersistence)

removeLayoutPersistence

public void removeLayoutPersistence(LayoutPersistence layoutPersistence)

clear

public void clear()

loadLayoutFrom

public boolean loadLayoutFrom(Document document)
Description copied from interface: LayoutPersistence
Load layout data from an Node that specified as node parameter. If any exception happens during the read, it will call resetLayout() to use default layout.

Parameters:
document - the Document where the layout data will be read from
Returns:
boolean true if load successfully. Otherwise false.

loadLayoutFrom

public boolean loadLayoutFrom(InputStream in)
Load layout data from an InputStream that specified as in parameter. If any exception happens during the read, it will call resetLayout() to use default layout.

Parameters:
in - the InputStream where the layout data will be read from.
Returns:
boolean did it load successfully from the input stream (false indicates that it called resetToDefault to load the layout.)

isLoadDataSuccessful

public boolean isLoadDataSuccessful()
Did the loadLayoutFrom(InputStream in) method load successfully from the input stream (false indicates that it called resetToDefault to load the layout.) This method can be called immediately after the loadLayoutFrom(InputStream in) call to determine if a specific LayoutPersistence was forced to call resetToDefault.

Returns:
boolean did it load successfully from the input stream (false indicates that it called resetToDefault to load the layout.)

saveLayoutTo

public void saveLayoutTo(Document document)
                  throws ParserConfigurationException
Description copied from interface: LayoutPersistence
Save layout data to a Document that specified as document parameter.

Parameters:
document - the Document where the layout data will be written to
Throws:
ParserConfigurationException - if any parser exception happens when writing to the document.

saveLayoutTo

public void saveLayoutTo(OutputStream out)
                  throws IOException
Description copied from interface: LayoutPersistence
Save layout data to an OutputStream that specified as out parameter.

Parameters:
out - the OutputStream where the layout data will be written to.
Throws:
IOException - if any IO exception happens when writing to the OutputStream.

resetToDefault

public void resetToDefault()
Description copied from interface: LayoutPersistence
Resets layout. It could be called either when there is no saved layout or the saved layout file is corrupted.


beginLoadLayoutData

public void beginLoadLayoutData()
Description copied from interface: LayoutPersistence
Starts a process to add/remove frame or dockable bar without showing on screen immediately. Any call to loadLayoutDataXxx methods or resetToDefault() will mark the process.


loadInitialLayout

public void loadInitialLayout(String layoutFile)
                       throws ParserConfigurationException,
                              SAXException,
                              IOException
Description copied from interface: LayoutPersistence
Load initial layout from an initial layout file designed by Visual Designer.

Specified by:
loadInitialLayout in interface LayoutPersistence
Overrides:
loadInitialLayout in class AbstractLayoutPersistence
Parameters:
layoutFile - the full file path to the .ilayout file.
Throws:
ParserConfigurationException - when DocumentBuilder cannot be created which satisfies the configuration requested.
SAXException - when DocumentBuilder has trouble parsing the initial layout xml file.
IOException - when DocumetnBuilder encounters any errors when reading the initial layout xml file.

loadInitialLayout

public void loadInitialLayout(InputStream layoutStream)
                       throws ParserConfigurationException,
                              SAXException,
                              IOException
Description copied from interface: LayoutPersistence
Load initial layout from an initial layout file designed by Visual Designer. To use this method, you should bundle initial layout files into jars, then use ClassLoader to load the file as InputStream.

Specified by:
loadInitialLayout in interface LayoutPersistence
Overrides:
loadInitialLayout in class AbstractLayoutPersistence
Parameters:
layoutStream - an input stream containing an initial layout.
Throws:
ParserConfigurationException - when DocumentBuilder cannot be created which satisfies the configuration requested.
SAXException - when DocumentBuilder has trouble parsing the initial layout xml file.
IOException - when DocumetnBuilder encounters any errors when reading the initial layout xml file.

loadInitialLayout

public void loadInitialLayout(Document layoutDocument)
Description copied from interface: LayoutPersistence
Load initial layout from an initial layout file designed by Visual Designer. To use this method, you need to load the initial layout into Document which represents XML document.

Parameters:
layoutDocument - the Document contains an initial layout.

setUseFrameBounds

public void setUseFrameBounds(boolean useFrameBounds)
Description copied from class: AbstractLayoutPersistence
If true, the bounds of main frame will be persisted in layout data.

Specified by:
setUseFrameBounds in interface LayoutPersistence
Overrides:
setUseFrameBounds in class AbstractLayoutPersistence
Parameters:
useFrameBounds - true if the bounds of main frame will be persisted in layout data.
See Also:
LayoutPersistence.setUseFrameState(boolean)

setUseFrameState

public void setUseFrameState(boolean useFrameState)
Description copied from class: AbstractLayoutPersistence
If true, the state of main frame will be persisted in layout data.

Specified by:
setUseFrameState in interface LayoutPersistence
Overrides:
setUseFrameState in class AbstractLayoutPersistence
Parameters:
useFrameState - true if the state of main frame will be persisted in layout data.
See Also:
LayoutPersistence.setUseFrameBounds(boolean)

setLayoutDirectory

public void setLayoutDirectory(String layoutDirectory)
Description copied from interface: LayoutPersistence
Sets the layout directory. It is used only when usePref is false.

Specified by:
setLayoutDirectory in interface LayoutPersistence
Overrides:
setLayoutDirectory in class AbstractLayoutPersistence
Parameters:
layoutDirectory - the layout directory.

setVersion

public void setVersion(short version)
Description copied from class: AbstractLayoutPersistence
Sets version number of profile. User can set a new version so that application restart, it will ignore previous layout information.

Specified by:
setVersion in interface LayoutPersistence
Overrides:
setVersion in class AbstractLayoutPersistence
Parameters:
version - new version

setUsePref

public void setUsePref(boolean usePref)
Description copied from class: AbstractLayoutPersistence
If true, use javax.util.pref to store frames layout data. The setting only has effect on Windows. On UNIX or Linux, javax.util.pref is never used because it has problem to store binary data

Specified by:
setUsePref in interface LayoutPersistence
Overrides:
setUsePref in class AbstractLayoutPersistence
Parameters:
usePref - use javax pref or not. Default is true

setProfileKey

public void setProfileKey(String profileKey)
Description copied from class: AbstractLayoutPersistence
Sets the profile key to be used to store layout information. If usePref is true, profileKey will be used to create a node in registry. If usePref is false, it will be used to create a folder named as ".profileKey" and all layout files will be saved under that folder.

Specified by:
setProfileKey in interface LayoutPersistence
Overrides:
setProfileKey in class AbstractLayoutPersistence
Parameters:
profileKey - profile key

isLast

public boolean isLast()
Description copied from interface: LayoutPersistence
Checks if it is the last one during when loading several several LayoutPersistences. Only the last LayoutPersistence will restore the main window's state and bounds and make the main window visible.

Specified by:
isLast in interface LayoutPersistence
Overrides:
isLast in class AbstractLayoutPersistence
Returns:
true or false.

setLast

public void setLast(boolean last)
Description copied from interface: LayoutPersistence
Sets the LayoutPersistence as the last one (or not the last one) when loading several LayoutPersistences.

Specified by:
setLast in interface LayoutPersistence
Overrides:
setLast in class AbstractLayoutPersistence
Parameters:
last - true if the layout persistence is the last one in the LayoutPersistenceManager.

JIDE 3.5.15