JIDE 3.5.15

com.jidesoft.swing
Interface LayoutPersistence

All Known Subinterfaces:
DockableBarManager, DockingManager
All Known Implementing Classes:
AbstractLayoutPersistence, DefaultDockableBarManager, DefaultDockingManager, DockableBarLayoutLoader, DockingLayoutLoader, LayoutPersistenceManager

public interface LayoutPersistence

An interface to support persist layout.


Field Summary
static String ATTRIBUTE_PERSISTENCE_NAME
           
static String NODE_LAYOUT_PERSISTENCE
           
 
Method Summary
 void beginLoadLayoutData()
          Starts a process to add/remove frame or dockable bar without showing on screen immediately.
 List<String> getAvailableLayouts()
          Gets the list of available layout names.
 String getLayoutDirectory()
          Gets the directory that used for storing layout files.
 String getLayoutPersistenceName()
          Gets the persistence's name.
 byte[] getLayoutRawData()
          Gets layout raw data in byte array.
 PersistenceUtilsCallback.Load getLoadCallback()
          Gets the load callback to help add some customized information while loading layout from XML format.
 PersistenceUtilsCallback.Save getSaveCallback()
          Gets the save callback to help add some customized information while saving layout to XML format.
 short getVersion()
          Gets version number of profile.
 String getXmlEncoding()
          Gets XML encoding while saving layout to XML format.
 boolean isLast()
          Checks if it is the last one during when loading several several LayoutPersistences.
 boolean isLayoutAvailable(String layoutName)
          Checks if the layout is available.
 boolean isLayoutDataVersionValid(String layoutName)
          Checks if the layout is valid.
 boolean isLoadDataSuccessful()
          Checks if 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.
 boolean isNeedFormatCheck()
          Gets the flag indicating if format check is required.
 boolean isXmlFormat()
          Gets the flag indicating if the layout should be saved to XML format by default.
 void loadInitialLayout(Document initialLayoutDocument)
          Load initial layout from an initial layout file designed by Visual Designer.
 void loadInitialLayout(InputStream initialLayoutStream)
          Load initial layout from an initial layout file designed by Visual Designer.
 void loadInitialLayout(String initialLayoutFileName)
          Load initial layout from an initial layout file designed by Visual Designer.
 void loadLayoutData()
          Loads layout from default layout data from profile.
 void loadLayoutDataFrom(String layoutName)
          Load layout data from the profile name specified in layoutName.
 void loadLayoutDataFromFile(String layoutFileName)
          Loads layout from a file.
 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 removeLayout(String layoutName)
          Removes the layout.
 void resetToDefault()
          Resets layout.
 void saveLayoutData()
          Save layout data to default layout.
 void saveLayoutDataAs(String layoutName)
          Save layout data to the layout that specified in layoutName Note: Always use all lower case.
 void saveLayoutDataToFile(String layoutFileName)
          Save layout data to file that specified in layoutFileName.
 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 setLayoutPersistenceName(String layoutPersistenceName)
          Sets the persistence's name.
 void setLayoutRawData(byte[] layoutData)
          Sets the layout using layout raw data.
 void setLoadCallback(PersistenceUtilsCallback.Load loadCallback)
          Sets the load callback to help add some customized information while loading layout from XML format.
 void setNeedFormatCheck(boolean needFormatCheck)
          Sets the flag indicating if format check is required.
 void setProfileKey(String key)
          Sets profile key.
 void setSaveCallback(PersistenceUtilsCallback.Save saveCallback)
          Sets the save callback to help add some customized information while saving layout to XML format.
 void setUseFrameBounds(boolean useFrameBounds)
          If true, the main frame will be set to the frame bounds information restored from the layout data.
 void setUseFrameState(boolean useFrameState)
          If true, the main frame will be set to the frame state information will be restored from the layout data.
 void setUsePref(boolean use)
          If true, we will use javax.util.pref to store the layout information.
 void setVersion(short version)
          Sets version number of profile.
 void setXmlEncoding(String xmlEncoding)
          Sets XML encoding while saving layout to XML format.
 void setXmlFormat(boolean xmlFormat)
          Sets the flag indicating if the layout should be saved to XML format by default.
 

Field Detail

NODE_LAYOUT_PERSISTENCE

static final String NODE_LAYOUT_PERSISTENCE
See Also:
Constant Field Values

ATTRIBUTE_PERSISTENCE_NAME

static final String ATTRIBUTE_PERSISTENCE_NAME
See Also:
Constant Field Values
Method Detail

setProfileKey

void setProfileKey(String key)
Sets profile key. Profile key is used in the registry (on Windows, under HKEY_CURRENT_USER\Software\JavaSoft\Prefs) or a folder name (on UNIX or Linux, JDK will automatically prefix with "." so that it is hidden) where the layout data will be stored.

Parameters:
key - the profile key

getVersion

short getVersion()
Gets version number of profile.

Returns:
version of profile

setVersion

void setVersion(short version)
Sets version number of profile. User can set a new version so that application restart, it will ignore previous layout information.

Parameters:
version - new version

setUsePref

void setUsePref(boolean use)
If true, we will use javax.util.pref to store the layout information.

Here is the difference when this flag is true or false.

If usePref is true, you will also need to call setProfileKey(String) to specify a profile key.

If usePref is false, you will also need to call setLayoutDirectory(String) to specify a folder. If you never set a layout directory, by default the layout directory is {user.home}/.profileKey which is actually the same on Linux/UNIX when usePref is true. Please note, saveLayoutDataToFile(String) and loadLayoutDataFromFile(String) use absolute file path so it will not be affected by usePref flag or the profileKey or layoutDirectory setting.

Parameters:
use - use java.util.pref or not. Default is true.

getAvailableLayouts

List<String> getAvailableLayouts()
Gets the list of available layout names. If usePref is true and profileKey has been set, the method will return the list of save layouts. If usePref is false, it will find out the layout file in layout directory.

Returns:
the list of available layout names.

isLayoutAvailable

boolean isLayoutAvailable(String layoutName)
Checks if the layout is available.

Parameters:
layoutName - the layout name. In Window registry, the layout name is the registry key name. If it's a layout file, the layout name is the file name with ".layout" as suffix.
Returns:
true if the layout is available

removeLayout

void removeLayout(String layoutName)
Removes the layout.

Parameters:
layoutName - the layout name. In Window registry, the layout name is the registry key name. If it's a layout file, the layout name is the file name with ".layout" as suffix.

loadLayoutData

void loadLayoutData()
Loads layout from default layout data from profile.


loadLayoutDataFrom

void loadLayoutDataFrom(String layoutName)
Load layout data from the profile name specified in layoutName. Please note: we suggest you to use all lower cases for layoutName because we found some problems when it is upper case on Windows.

Parameters:
layoutName - the layout name. In Window registry, the layout name is the registry key name. If it's a layout file, the layout name is the file name with ".layout" as suffix. Please don't add ".layout" to invoke this method.

isLayoutDataVersionValid

boolean isLayoutDataVersionValid(String layoutName)
Checks if the layout is valid. It will return true if and only if the version number in layout file matches with the version number set on LayoutPersistence. If there is any IO exception during checking, it will return false as well.

Parameters:
layoutName - the layout name. In Window registry, the layout name is the registry key name. If it's a layout file, the layout name is the file name with ".layout" as suffix.
Returns:
true if the layout version valid.

loadLayoutDataFromFile

void loadLayoutDataFromFile(String layoutFileName)
Loads layout from a file.

Parameters:
layoutFileName - a layout file name.

loadLayoutFrom

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.)

loadLayoutFrom

boolean loadLayoutFrom(Document document)
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.

isLoadDataSuccessful

boolean isLoadDataSuccessful()
Checks if 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.)

saveLayoutData

void saveLayoutData()
Save layout data to default layout.


saveLayoutDataAs

void saveLayoutDataAs(String layoutName)
Save layout data to the layout that specified in layoutName Note: Always use all lower case. I found some problems with upper case on Windows.

Parameters:
layoutName - the layout name. In Window registry, the layout name is the registry key name. If it's a layout file, the layout name is the file name with ".layout" as suffix.

saveLayoutDataToFile

void saveLayoutDataToFile(String layoutFileName)
Save layout data to file that specified in layoutFileName. The fileName should be full qualified file name. If the file exists, it will be overwritten.

Parameters:
layoutFileName - full path to the layout file.

saveLayoutTo

void saveLayoutTo(OutputStream out)
                  throws IOException
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.

saveLayoutTo

void saveLayoutTo(Document document)
                  throws ParserConfigurationException
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.

getLayoutRawData

byte[] getLayoutRawData()
Gets layout raw data in byte array. You can keep the value returned and pass it in to setLayoutRawData to set the layout.

Returns:
layout data

setLayoutRawData

void setLayoutRawData(byte[] layoutData)
Sets the layout using layout raw data.

Parameters:
layoutData - the byte array that returned from getLayoutRawData

getLayoutDirectory

String getLayoutDirectory()
Gets the directory that used for storing layout files. It is used only when usePref is false.

Returns:
the directory so store layout files.

setLayoutDirectory

void setLayoutDirectory(String layoutDirectory)
Sets the layout directory. It is used only when usePref is false.

Parameters:
layoutDirectory - the layout directory.

resetToDefault

void resetToDefault()
Resets layout. It could be called either when there is no saved layout or the saved layout file is corrupted.


setUseFrameState

void setUseFrameState(boolean useFrameState)
If true, the main frame will be set to the frame state information will be restored from the layout data. Otherwise, loadLayoutData will ignore the main frame state saved in the layout data. By default, if the frame is invisible when loadLayoutData is called, we will use the saved frame state. If the frame is already visible, we will ignore it. Typically, for all nested LayoutPersistences (including DockingManager and DockableBarManager), you should call both setUseFrameBounds(false) and setUseFrameState(false) before loadLayoutData so that only the top level LayoutPersistence will set the frame bounds and state. If you have two or more top level LayoutPersistence, you should designate one LayoutPersistence as the main one. One way to do this is to add all top level LayoutPersistences to LayoutPersistenceManager. LayoutPersistenceManager will automatically designate the last docking manager as the main one which will set the frame state.

Please be noted that in some latest OS X version, the UI might get frozen if this flag set to true. Please try to set this flag to false to work around in case you experience the UI frozen issue.

Parameters:
useFrameState - true if the state of main frame will be restored from the layout data.
See Also:
setUseFrameBounds(boolean)

setUseFrameBounds

void setUseFrameBounds(boolean useFrameBounds)
If true, the main frame will be set to the frame bounds information restored from the layout data. Otherwise, loadLayoutData will ignore the main frame bounds saved in the layout data. By default, if the frame is invisible when loadLayoutData is called, we will use the saved frame bounds. If the frame is already visible, we will ignore it. Typically, for all nested LayoutPersistences (including DockingManager and DockableBarManager), you should call both setUseFrameBounds(false) and setUseFrameState(false) before loadLayoutData so that only the top level LayoutPersistence will set the frame bounds and state. If you have two or more top level LayoutPersistence, you should designate one LayoutPersistence as the main one. One way to do this is to add all top level LayoutPersistences to LayoutPersistenceManager. LayoutPersistenceManager will automatically designate the last docking manager as the main one which will set the frame bounds.

Parameters:
useFrameBounds - true if the bounds of main frame will be restored from layout data.
See Also:
setUseFrameState(boolean)

beginLoadLayoutData

void beginLoadLayoutData()
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.


isLast

boolean isLast()
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.

Returns:
true or false.

setLast

void setLast(boolean last)
Sets the LayoutPersistence as the last one (or not the last one) when loading several LayoutPersistences.

Parameters:
last - true if the layout persistence is the last one in the LayoutPersistenceManager.

loadInitialLayout

void loadInitialLayout(String initialLayoutFileName)
                       throws ParserConfigurationException,
                              SAXException,
                              IOException
Load initial layout from an initial layout file designed by Visual Designer.

Parameters:
initialLayoutFileName - 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

void loadInitialLayout(InputStream initialLayoutStream)
                       throws ParserConfigurationException,
                              SAXException,
                              IOException
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.

Parameters:
initialLayoutStream - 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

void loadInitialLayout(Document initialLayoutDocument)
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:
initialLayoutDocument - the Document contains an initial layout.

isXmlFormat

boolean isXmlFormat()
Gets the flag indicating if the layout should be saved to XML format by default.

Returns:
true if the layout should be saved to XML format. Otherwise false.
See Also:
setXmlFormat(boolean)

setXmlFormat

void setXmlFormat(boolean xmlFormat)
Sets the flag indicating if the layout should be saved to XML format by default.

If the flag is set to true, the layout format would be XML format. Otherwise, it will be traditional binary format to save space.

By default, the flag is false to keep original behavior. No matter how this flag is set, the DockingManager should be able to read either XML format or binary format layout file.

Parameters:
xmlFormat - the flag

getSaveCallback

PersistenceUtilsCallback.Save getSaveCallback()
Gets the save callback to help add some customized information while saving layout to XML format.

Returns:
the save call back.

setSaveCallback

void setSaveCallback(PersistenceUtilsCallback.Save saveCallback)
Sets the save callback to help add some customized information while saving layout to XML format.

Parameters:
saveCallback - the save call back

getLoadCallback

PersistenceUtilsCallback.Load getLoadCallback()
Gets the load callback to help add some customized information while loading layout from XML format.

Returns:
the load call back.

setLoadCallback

void setLoadCallback(PersistenceUtilsCallback.Load loadCallback)
Sets the load callback to help add some customized information while loading layout from XML format.

Parameters:
loadCallback - the load call back

getXmlEncoding

String getXmlEncoding()
Gets XML encoding while saving layout to XML format.

Returns:
the xml encoding.

setXmlEncoding

void setXmlEncoding(String xmlEncoding)
Sets XML encoding while saving layout to XML format.

Parameters:
xmlEncoding - the xml encoding

getLayoutPersistenceName

String getLayoutPersistenceName()
Gets the persistence's name.

The persistence name will be used to distinguish different nodes while loading layout from XML file

By default, JIDE will simply put "1", "2", "3" as a default name for each persistence LayoutPersistenceManager manages.

Returns:
the layout persistence name.

setLayoutPersistenceName

void setLayoutPersistenceName(String layoutPersistenceName)
Sets the persistence's name.

Parameters:
layoutPersistenceName - the layout persistence name

isNeedFormatCheck

boolean isNeedFormatCheck()
Gets the flag indicating if format check is required.

By default, it should be true. In LayoutPersistenceManager scenario, it will be set to false if the format is traditional binary.

Returns:
true if format check to be skipped on loading. Otherwise false.

setNeedFormatCheck

void setNeedFormatCheck(boolean needFormatCheck)
Sets the flag indicating if format check is required.

It's not supposed to be invoked publicly. It will be invoked by LayoutPersistenceManager.

Parameters:
needFormatCheck - the flag

JIDE 3.5.15