Package bibliothek.gui.dock.support.mode
Class ModeManager<H,M extends Mode<H>>
java.lang.Object
bibliothek.gui.dock.support.mode.ModeManager<H,M>
- Type Parameters:
H- the kind of properties that are to be stored in this managerM- the kind ofModes used by this manager
- Direct Known Subclasses:
LocationModeManager
Associates
Dockables with one Mode out of a set
of modes. This manager remembers in which order the modes were applied
to a Dockable.- Author:
- Benjamin Sigg
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a newDockableat this manager.voidaddAffected(Iterable<Dockable> dockables) Adds all elements ofdockablesto the currentAffectedSet.voidAdds an empty entry to this manager.voidaddModeManagerListener(ModeManagerListener<? super H, ? super M> listener) Adds a listener to this manager, the listener will be informed about changes in this manager.voidaddToModeHistory(Dockable dockable, M mode, H history) Adds the history datahistorytodockablefor modemode, and storesmodeas the newest used mode.booleanAlters the mode ofdockabletomode.booleanapply(Dockable dockable, Path mode, AffectedSet set, boolean force) Alters the mode ofdockabletomode.booleanapply(Dockable dockable, Path mode, H history, AffectedSet set) Alters the mode ofdockableto bemode.voidAlters the mode ofdockabletomode.voidapply(Dockable dockable, M mode, AffectedSet set, boolean force) Alters the mode ofdockabletomode.voidapply(Dockable dockable, M mode, H history, AffectedSet set) Alters the mode ofdockableto bemode.protected abstract voidapplyDuringRead(String key, Path old, Path current, Dockable dockable) Called while reading modes inreadSettings(ModeSettings).protected booleanTells whether an entry for a missingDockableshould be created.<B> ModeSettings<H,B> createModeSettings(ModeSettingsConverter<H, B> converter) Creates the empty set of settings for thisModeManager.<B> ModeSettings<H,B> createSettings(ModeSettingsConverter<H, B> converter) Creates a newModeSettingwhich is configured to transfer data from thisModeManagerto persistent storage or the other way.voiddestroy()Unregisters listeners which this manager added to theDockControllerand other components.protected voidCallsModeManagerListener.dockableAdded(ModeManager, Dockable)on all listeners that are currently registeredprotected voidCallsModeManagerListener.modeAdded(ModeManager, Mode)on all listeners that are currently registered.protected voidfireModeChanged(Dockable dockable, M oldMode, M newMode) CallsModeManagerListener.modeChanged(ModeManager, Dockable, Mode, Mode)on all listeners that are currently registered.protected voidfireRemoved(Dockable dockable) CallsModeManagerListener.dockableRemoved(ModeManager, Dockable)on all listeners that are currently registered.protected voidfireRemoved(M mode) CallsModeManagerListener.modeRemoved(ModeManager, Mode)on all listeners that are currently registered.Gets the controller in whose realm this manager works.getCurrentMode(Dockable dockable) Tries to find the modedockableis currently in.protected MgetDefaultMode(Dockable dockable) Gets the default mode ofdockable, the modedockableis in if nothing else is specified.getDoubleClickTarget(Dockable target) Given someDockableon which an event was registered, searches a registered dockable that is a child oftargetortargetitself.Gets a set containing all theModeSettingFactorys that were added to this manager.getHistory(Dockable dockable, Path modeId) Gets the history ofdockablein modemodeId.Gets the currentHistoryRewriter.Gets the unique identifier which is used fordockable.Searches and returns the mode with given unique identifierpath.getModeHistory(Dockable dockable) Gets the history which modesdockableused in the past.getPreviousMode(Dockable dockable) Reading the history this method tells which modedockablewas in before the current mode.protected HgetProperties(M mode, Dockable dockable) Gets the properties which correspond todockableandmode.getPropertyHistory(Dockable dockable) Gets the history which propertiesdockableused in the past.abstract DockActionSourcegetSharedActions(DockStation station) Gets a list of actions that should be shown onstationdepending on the current children ofstation.booleanTells whether information about dockablekeygets stored indefinitely or not.booleanTells whether this manager currently runs a continuous transaction.booleanbooleanisRegistered(Dockable dockable) Returns a set containing allDockables that are currently registered at this manager.protected ModeManagerListener<? super H,? super M>[] Gets all the listeners that are currently registered in this manager.modes()Returns an iteration of all modes that are stored in this manager.voidRegisters a newDockableat this manager.voidputFactory(ModeSettingFactory<H> factory) Adds a factory to thisModeManager.voidPuts a new mode in this manager.voidreadSettings(ModeSettings<H, ?> settings) Reads the contents ofsettingsand stores it.readSettings(ModeSettings<H, ?> settings, UndoableModeSettings pending) Reads the contents ofsettings, creates new entries if eithercreateEntryDuringRead(String)or ifpendingallows the setting to be undone if not needed.protected voidRebuilds the action sources ofdockable.protected voidRebuilds the actions sources for allDockables.voidreduceToEmpty(Dockable dockable) Removesdockableitself, put the properties ofdockableremain in the system.voidrefresh()Updates the modes of allDockables that are registered at thisModeManager.voidUpdates the mode ofdockableand updates the actions associated withdockable.voidRemoves the properties that belong todockable.voidremoveEmpty(String name) Removes the entry fornamebut only if the entry is not associated with anyDockable.voidremoveMode(M mode) Removesmodefrom this manager.voidremoveModeManagerListener(ModeManagerListener<? super H, ? super M> listener) Removeslistenerfrom this manager.voidrunTransaction(AffectingRunnable runnable) Runs an algorithm which affects the mode of someDockables.voidrunTransaction(AffectingRunnable run, boolean continuous) Runs an algorithm which affects the mode of someDockables.voidrunTransaction(Runnable run) Runsrunas transaction, theDockRegisteris stalled andisOnTransaction()returnstruewhilerunruns.voidrunTransaction(Runnable run, boolean continuous) Runsrunas transaction, theDockRegisteris stalled andisOnTransaction()returnstruewhilerunruns.voidsetHistoryRewriter(HistoryRewriter<H, M> historyRewriter) Sets the currentHistoryRewriter.protected voidsetProperties(M mode, Dockable dockable, H property) Stores a property fordockableif in modemode.voidStores the current location ofdockableand all its children in respect to their currentMode.protected voidStores the location ofdockableunder the keymode.
This method does nothing ifisOnContinuous()returnstruetoString()voidwriteSettings(ModeSettings<H, ?> setting) Writes all the information stored in thisModeManagertosetting.
-
Constructor Details
-
ModeManager
Creates a new manager.- Parameters:
controller- the controller in whose realm this manager will work
-
-
Method Details
-
destroy
public void destroy()Unregisters listeners which this manager added to theDockControllerand other components. -
getController
Gets the controller in whose realm this manager works.- Returns:
- the controller
-
addModeManagerListener
Adds a listener to this manager, the listener will be informed about changes in this manager.- Parameters:
listener- the new listener, notnull
-
removeModeManagerListener
Removeslistenerfrom this manager.- Parameters:
listener- the listener to remove
-
putMode
Puts a new mode in this manager. If there is already a mode with the same id registered, then the old mode gets replaced by the new one.- Parameters:
mode- the new mode
-
putFactory
Adds a factory to thisModeManager. The factory will be used by theModeSettingsto read and write data of the mode with the same identifier asfactorypersistently.
Note: AModemight also provide aModeSettingFactory, if there is a collision of unique identifiers the factory of the mode is used.- Parameters:
factory- the new factory
-
getFactories
Gets a set containing all theModeSettingFactorys that were added to this manager.- Returns:
- the factories
-
removeMode
Removesmodefrom this manager. Note that history information about the mode remains.- Parameters:
mode- the mode to remove
-
getMode
Searches and returns the mode with given unique identifierpath.- Parameters:
path- some unique identifier- Returns:
- the mode with that identifier or
null
-
setHistoryRewriter
Sets the currentHistoryRewriter. The rewriter is invoked every time before theapplymethod of aModeis called. The rewriter can then change the history of oneDockable, e.g. to apply additional checks whether an old state is still valid.
A history rewriter does not change the history permanently. It creates a new history object before theapplymethod is called, but that new history object will not be stored by theModeManager.- Parameters:
historyRewriter- the new rewriter, can benull
-
getHistoryRewriter
Gets the currentHistoryRewriter.- Returns:
- the rewriter, can be
null - See Also:
-
listeners
Gets all the listeners that are currently registered in this manager.- Returns:
- the list of registered listeners
-
fireAdded
CallsModeManagerListener.dockableAdded(ModeManager, Dockable)on all listeners that are currently registered- Parameters:
dockable- the new element
-
fireRemoved
CallsModeManagerListener.dockableRemoved(ModeManager, Dockable)on all listeners that are currently registered.- Parameters:
dockable- the removed element
-
fireModeChanged
CallsModeManagerListener.modeChanged(ModeManager, Dockable, Mode, Mode)on all listeners that are currently registered.- Parameters:
dockable- the element whose mode changedoldMode- its old modenewMode- its new mode
-
fireAdded
CallsModeManagerListener.modeAdded(ModeManager, Mode)on all listeners that are currently registered.- Parameters:
mode- the added mode
-
fireRemoved
CallsModeManagerListener.modeRemoved(ModeManager, Mode)on all listeners that are currently registered.- Parameters:
mode- the removed mode
-
add
Registers a newDockableat this manager. If there is already mode-information forkeypresent, thendockableinherits this information.- Parameters:
key- the unique key ofdockabledockable- the new element- Throws:
NullPointerException- if eitherkeyordockableisnullIllegalArgumentException- if there is already a dockable registered withkey
-
put
Registers a newDockableat this manager. This method works likeadd(String, Dockable)but does not throw an exception if anotherDockableis already registered withkey. Instead the otherDockableis unregistered anddockableinherits its mode-information.- Parameters:
key- the unique identifier ofdockabledockable- some new element- Throws:
NullPointerException- if eitherkeyordockableisnull
-
getKey
Gets the unique identifier which is used fordockable.- Parameters:
dockable- some element- Returns:
- the unique identifier or
nullifdockableis not registered
-
isRegistered
- Parameters:
dockable- the element to check- Returns:
trueif the element is known,falseotherwise
-
listDockables
Returns a set containing allDockables that are currently registered at this manager.- Returns:
- the set of dockables
-
runTransaction
Runs an algorithm which affects the mode of someDockables.- Parameters:
runnable- the algorithm,nullwill be ignored
-
runTransaction
Runs an algorithm which affects the mode of someDockables.- Parameters:
run- the algorithm,nullwill be ignoredcontinuous- if set totruethe transaction should run without changing the internal cache storing the position of allDockables. This can be important if an operation runs anapplymethod and additional work will change the position of some elements again. Clients should callstore(Dockable)afterwards.
-
runTransaction
Runsrunas transaction, theDockRegisteris stalled andisOnTransaction()returnstruewhilerunruns.- Parameters:
run- the runnable to execute
-
runTransaction
Runsrunas transaction, theDockRegisteris stalled andisOnTransaction()returnstruewhilerunruns.- Parameters:
run- the runnable to executecontinuous- if set totruethe transaction should run without changing the internal cache storing the position of allDockables. This can be important if an operation runs anapplymethod and additional work will change the position of some elements again. Clients should callstore(Dockable)afterwards.
-
apply
- Parameters:
dockable- the element whose mode is going to be changedmode- the new modeforce- iftruedockableis relocated even if the current mode already ismode- Returns:
trueifmodewas found,falseotherwise- Throws:
IllegalArgumentException- ifdockableisnull,modeisnullordockableis not registered.
-
apply
Alters the mode ofdockabletomode. This method just callsapply(Dockable, Mode, AffectedSet, boolean).- Parameters:
dockable- the element whose mode is going to be changedmode- the new modeforce- iftruedockableis relocated even if the current mode already ismode- Throws:
IllegalArgumentException- ifdockableisnull,modeisnullordockableis not registered.
-
apply
Alters the mode ofdockabletomode. This method just callsapply(Dockable, Mode, AffectedSet, boolean).- Parameters:
dockable- the element whose mode is going to be changedmode- the new modeset- to store all dockables whose mode might have been changedforce- iftruedockableis relocated even if the current mode already ismode- Returns:
trueifmodewas found,falseotherwise- Throws:
IllegalArgumentException- ifdockableisnull,modeisnull,setisnull, ordockableis not registered.
-
apply
Alters the mode ofdockabletomode. This method does nothing if the current mode ofdockablealready ismode.
After initial checks and reading the history, this method callsapply(Dockable, Mode, Object, AffectedSet).- Parameters:
dockable- the element whose mode is going to be changedmode- the new modeset- to store all dockables whose mode might have been changedforce- iftruedockableis relocated even if the current mode already ismode- Throws:
IllegalArgumentException- ifdockableisnull,modeisnull,setisnull, ordockableis not registered.
-
getHistory
Gets the history ofdockablein modemodeId.- Parameters:
dockable- the element whose history is searchedmodeId- the identifier of the mode- Returns:
- the history information or
nullif not found
-
apply
Alters the mode ofdockableto bemode. This method just callsapply(Dockable, Mode, Object, AffectedSet).- Parameters:
dockable- the element whose mode is changedmode- the new mode ofdockablehistory- history information forMode.apply(Dockable, Object, AffectedSet), can benullset- to store elements that have changed- Returns:
trueifmodewas found,falseotherwise- Throws:
IllegalArgumentException- if eitherdockable,modeorsetisnull
-
apply
Alters the mode ofdockableto bemode. This method does not alter the modes of other dockables, notice however that the methodsMode.apply(Dockable, Object, AffectedSet)may trigger additional mode-changes.- Parameters:
dockable- the element whose mode is changedmode- the new mode ofdockablehistory- history information forMode.apply(Dockable, Object, AffectedSet), can benullset- to store elements that have changed- Throws:
IllegalArgumentException- if eitherdockable,modeorsetisnull
-
setProperties
Stores a property fordockableif in modemode. This method does not trigger any version of theapplymethods.- Parameters:
mode- the mode which is affecteddockable- the dockables whose property is changedproperty- the new property, can benull
-
getProperties
Gets the properties which correspond todockableandmode.- Parameters:
mode- the first part of the keydockable- the second part of the key- Returns:
- the properties or
null
-
isOnTransaction
public boolean isOnTransaction()- Returns:
trueif a mode is currently working
-
isOnContinuous
public boolean isOnContinuous()Tells whether this manager currently runs a continuous transaction. As long as a continuous transaction is running the internal states of this manager do not change.- Returns:
- whether a continuous transaction is running
-
refresh
public void refresh()Updates the modes of allDockables that are registered at thisModeManager. -
refresh
Updates the mode ofdockableand updates the actions associated withdockable. This method is intended to be called by any code that changes the mode in a way that is not automatically registered by thisModeManager.- Parameters:
dockable- the element whose mode might have changedrecursive- if set, then the children ofdockableare refreshed as well.
-
remove
Removes the properties that belong todockable.- Parameters:
dockable- the element to remove
-
reduceToEmpty
Removesdockableitself, put the properties ofdockableremain in the system.- Parameters:
dockable- the element to reduce
-
applyDuringRead
Called while reading modes inreadSettings(ModeSettings). Subclasses might change the mode according tonewMode.- Parameters:
key- the identifier ofdockableold- the modedockableis currently incurrent- the modedockableis going to bedockable- the element that changes its mode, might benull
-
createEntryDuringRead
Tells whether an entry for a missingDockableshould be created. This will result in a call toaddEmpty(String)duringreadSettings(ModeSettings). The default implementation returns alwaysfalse.- Parameters:
key- the key for which to create a new entry- Returns:
trueif an entry should be created
-
addEmpty
Adds an empty entry to this manager. The empty entry can be used to store information for aDockablethat has not yet been created. It is helpful if the client intends to load first its properties and create only thoseDockables which are visible.
Also an empty entry gets never deleted unlessremoveEmpty(String)is called.- Parameters:
key- the name of the empty entry- Throws:
NullPointerException- ifkeyisnull
-
removeEmpty
Removes the entry fornamebut only if the entry is not associated with anyDockable.- Parameters:
name- the name of the entry which might be empty- Throws:
NullPointerException- ifkeyisnull
-
isEmpty
Tells whether information about dockablekeygets stored indefinitely or not.- Parameters:
key- the key to check- Returns:
trueif the key is never removed automaticallyfalseotherwise
-
getDoubleClickTarget
Given someDockableon which an event was registered, searches a registered dockable that is a child oftargetortargetitself.- Parameters:
target- the target whose registered child is searched- Returns:
target, a child oftarget, ornull
-
getDefaultMode
Gets the default mode ofdockable, the modedockableis in if nothing else is specified. This method checksMode.isDefaultMode(Dockable)and returns the firstModewhere the answer wastrue.- Parameters:
dockable- some dockable, notnull- Returns:
- its default mode, must be registered at this
ModeManagerand not benull
-
getCurrentMode
Tries to find the modedockableis currently in. This method callsMode.isCurrentMode(Dockable)and returns the firstModewhere the answer wastrue.- Parameters:
dockable- some dockable, notnull- Returns:
- the current mode or
nullif not found
-
getPreviousMode
Reading the history this method tells which modedockablewas in before the current mode.- Parameters:
dockable- some element- Returns:
- the previous mode or
nullif this information is not available
-
getModeHistory
Gets the history which modesdockableused in the past. The older entries are at the beginning of the list. The current mode may or may not be included in the list.- Parameters:
dockable- the element whose history is asked- Returns:
- the history or an empty list if no history is available
-
addToModeHistory
Adds the history datahistorytodockablefor modemode, and storesmodeas the newest used mode.- Parameters:
dockable- the element whose history is modified must be known to this managermode- the mode whose history is modifiedhistory- the new history- Throws:
IllegalStateException- ifdockableis not known to this manager
-
getPropertyHistory
Gets the history which propertiesdockableused in the past. Entries of valuenullare ignored. The older entries are at the beginning of the list.- Parameters:
dockable- the element whose history is asked- Returns:
- the history or an empty list if no history is available
-
store
Stores the current location ofdockableand all its children in respect to their currentMode. Dockables that are not registered at this manager are ignored.
This method does nothing ifisOnContinuous()returnstrue- Parameters:
dockable- a root of a tree
-
store
Stores the location ofdockableunder the keymode.
This method does nothing ifisOnContinuous()returnstrue- Parameters:
mode- the modedockableis currently indockable- the element whose location will be stored
-
modes
Returns an iteration of all modes that are stored in this manager.- Returns:
- the iteration
-
rebuildAll
protected void rebuildAll()Rebuilds the actions sources for allDockables. -
rebuild
Rebuilds the action sources ofdockable.- Parameters:
dockable- the element whose actions are to be updated
-
createSettings
Creates a newModeSettingwhich is configured to transfer data from thisModeManagerto persistent storage or the other way. The new setting contains all theModeSettingFactorys which are currently known to this manager.- Type Parameters:
B- the intermediate format- Parameters:
converter- conversion tool from this manager's meta-data format to the intermediate format.- Returns:
- the new empty settings
-
createModeSettings
Creates the empty set of settings for thisModeManager. Subclasses may override this method to use another set of settings. This method does not need to callModeSettings.addFactory(ModeSettingFactory).- Type Parameters:
B- the intermediate format- Parameters:
converter- conversion tool from this manager's meta-data format to the intermediate format.- Returns:
- the new empty settings
-
writeSettings
Writes all the information stored in thisModeManagertosetting.- Parameters:
setting- the settings to fill
-
readSettings
Reads the contents ofsettingsand stores it.- Parameters:
settings- the settings to read
-
readSettings
Reads the contents ofsettings, creates new entries if eithercreateEntryDuringRead(String)or ifpendingallows the setting to be undone if not needed.- Parameters:
settings- the settings to readpending- undoable settings, can benull- Returns:
- an algorithm that will remove any entry that was created because
pendingdid advise so,nullifpendingwasnull
-
addAffected
Adds all elements ofdockablesto the currentAffectedSet.- Parameters:
dockables- the elements to add
-
toString
-