When you don't need a dockable anymore, you can close it. It will be removed from the dock model. It is possible that, later, you want to display the content of the dockable again. Normally you want to put the dockable again, where it was, when it was removed. This is possible by using DockingPaths. A docking path keeps all the information about, where the dockable is in a dock model.
DockingPath dockingPath = DefaultDockingPath.createDockingPath(dockable, dockModel);
The DockingPathModel of the DockingManager will keep track of all your docking paths:
Add all your docking paths to the docking path model:DockingPathModel dockingPathModel = DockingManager.getDockingPathModel();
dockingPathModel.add(dockingPath);
When you close a dockable with a DockableStateAction a docking path will be created. It contains the information, where the dockable is docked now in the dock model. This docking path is added to the docking path model of the docking manager. When the dockable is restored with a dockable state action, it will be docked as good as possible where it was docked before.
... closeAction = new DockableStateAction(dockable, DockableState.CLOSED); restoreAction = new DockableStateAction(dockable, DockableState.NORMAL); ... // Close the dockable. closeAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Close")); ... // Restore the dockable. restoreAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Restore"));
When you want to use the restore action for a dockable that was not already docked in the dock model, you have to create a docking path for the dockable by your self. You can create that docking path by using the positions of a dockable that is already docked in the dock model.
// Add the path of the dockables that are not docked already. // We want dockable 5 to be docked, when it is made visible, where dockable 1 is docked. DockingPath dockingPathToCopy1 = DockingManager.getDockingPathModel().getDockingPath(dockable1.getID()); DockingPath dockingPath5 = DefaultDockingPath.copyDockingPath(dockable5, dockingPathToCopy1); DockingManager.getDockingPathModel().add(dockingPath5);
CodecExample | Shows the usage, encoding and decoding of dock models. |
WorkspaceExample | Shows the usage, the encoding, and the decoding of dock models. |