A CompositeDock is a Dock that contains other docks. It does not contain dockables. The child docks can also be composite docks.
If you want to use a composite dock, you have to do the folowing things:
The most frequently used composite dock is the SplitDock. This composite dock can contain 0, 1, or 2 child docks. When there are 2 child docks, they are split by a divider. In the folowing example a split dock is created with one child dock:
The only child dock is put in the center of the split dock.// Create the child tab dock. TabDock tabDock = new TabDock(); // Add the dockables to the tab dock. tabDock.addDockable(dockable1, new Position(0)); tabDock.addDockable(dockable2, new Position(1)); tabDock.addDockable(dockable3, new Position(2)); tabDock.addDockable(dockable4, new Position(3)); // Create the split dock. SplitDock splitDock = new SplitDock(); // Add the child dock in the center of the split dock. splitDock.addChildDock(tabDock, new Position(Position.CENTER));
In the folowing example a split dock is created with two child docks:
You can also put the children at the top and bottom:// Create the child tab dock. TabDock leftTabDock = new TabDock(); TabDock rightTabDock = new TabDock(); // Add the dockables to the tab docks. leftTabDock.addDockable(dockable1, new Position(0)); leftTabDock.addDockable(dockable2, new Position(1)); rightTabDock.addDockable(dockable3, new Position(0)); rightTabDock.addDockable(dockable4, new Position(1)); // Create the split dock. SplitDock splitDock = new SplitDock(); // Add the child docks to the split dock. splitDock.addChildDock(leftTabDock, new Position(Position.LEFT)); splitDock.addChildDock(rightTabDock, new Position(Position.RIGHT)); splitDock.setDividerLocation(290);
// Add the child docks to the split dock. splitDock.addChildDock(leftTabDock, new Position(Position.TOP)); splitDock.addChildDock(rightTabDock, new Position(Position.BOTTOM)); splitDock.setDividerLocation(190);
A special composite dock is the FloatDock. This dock is not a java.awt.Component. Its child docks are the docks in floating windows.
If you are working with a FloatDockModel, then you don't have to create the float dock by yourself. This model creates a float dock for every owner window that you add. You can retrieve this float dock with the folowing code:
Add the child docks to the floatdock. The positions in float docks are 3-dimensional (x-position, y-position, z-order).// Get the float dock. This is a standard dock of the floating dock model. FloatDock floatDock = dockModel.getFloatDock(windowId);
When a dockable is dragged, and when no other dock is found to dock the dockable, only then the dockable will be docked in the float dock. If you want a higher priority to let dockables float, then you have to augment the dock priority of the float dock:// Add the child docks to the float dock. floatDock.addChildDock(singleDock1, new Position(x, y, 0)); floatDock.addChildDock(singleDock2, new Position(x + 50, y + 50, 1));
floatDock.setDockPriority(DockPriority.CAN_DOCK_WITH_PRIORITY);
A composite dock has always a DockFactory to create its child docks.
When you drag a dockable above a composite dock and you release the mouse, then the dockable can be added to the composite dock. The folowing things will be done by the docking functionality:
floatDock.setChildDockFactory(new SingleDockFactory());
A special composite dock is a CompositeLineDock. It organizes its child docks in a line.
In the folowing example 2 horizontal composite line docks are created. They have a TabDockFactory as child dock factory.
// Create the composite line docks. CompositeLineDock lineDock1 = new CompositeLineDock( CompositeLineDock.ORIENTATION_HORIZONTAL, true, new TabDockFactory()); CompositeLineDock lineDock2 = new CompositeLineDock( CompositeLineDock.ORIENTATION_HORIZONTAL, true, new TabDockFactory()); // Add the child docks to the composite dock. lineDock1.addChildDock(tabDock1, new Position(0)); lineDock1.addChildDock(tabDock2, new Position(1)); lineDock1.addChildDock(tabDock3, new Position(2)); lineDock2.addChildDock(tabDock4, new Position(0)); lineDock2.addChildDock(tabDock5, new Position(1)); lineDock2.addChildDock(tabDock6, new Position(2));
Another special composite dock is a CompositeGridDock. It organizes its child docks in a grid.
In the folowing example a composite grid dock is created. It has a SingleDockFactory as child dock factory.
// Create the grid dock. CompositeGridDock gridDock = new CompositeGridDock(new SingleDockFactory()); // Add the child docks to the composite dock. gridDock.addChildDock(dock1, new Position(0)); gridDock.addChildDock(dock2, new Position(1)); gridDock.addChildDock(dock3, new Position(2)); gridDock.addChildDock(dock4, new Position(3)); gridDock.addChildDock(dock5, new Position(4)); gridDock.addChildDock(dock6, new Position(5));
If you want nested tabs as docks you have to use CompositeTabDocks.
In the folowing example composite tab docks are created. The dockables are added to a dock created by the child dock factory. These docks are added to the composite tab docks. compositeTabDock3 is added as child dock to compositeTabDock2.
// Create the composite tab docks. CompositeTabDock compositeTabDock1 = new CompositeTabDock(); CompositeTabDock compositeTabDock2 = new CompositeTabDock(); CompositeTabDock compositeTabDock3 = new CompositeTabDock(); // Get the child dock factory. DockFactory dockFactory = compositeTabDock1.getChildDockFactory(); // Create the deepest single docks. Dock dock1 = dockFactory.createDock(dockable1, DockingMode.SINGLE); Dock dock2 = dockFactory.createDock(dockable2, DockingMode.SINGLE); Dock dock3 = dockFactory.createDock(dockable3, DockingMode.SINGLE); Dock dock4 = dockFactory.createDock(dockable4, DockingMode.SINGLE); Dock dock5 = dockFactory.createDock(dockable5, DockingMode.SINGLE); Dock dock6 = dockFactory.createDock(dockable6, DockingMode.SINGLE); Dock dock7 = dockFactory.createDock(dockable7, DockingMode.SINGLE); Dock dock8 = dockFactory.createDock(dockable8, DockingMode.SINGLE); // Add the dockables to these tab docks. Point position = new Point(0, 0); dock1.addDockable(dockable1, position, position); dock2.addDockable(dockable2, position, position); dock3.addDockable(dockable3, position, position); dock4.addDockable(dockable4, position, position); dock5.addDockable(dockable5, position, position); dock6.addDockable(dockable6, position, position); dock7.addDockable(dockable7, position, position); dock8.addDockable(dockable8, position, position); // Add the child docks to the composite dock. compositeTabDock1.addChildDock(dock1, new Position(0)); compositeTabDock1.addChildDock(dock2, new Position(1)); compositeTabDock1.addChildDock(dock3, new Position(2)); compositeTabDock2.addChildDock(dock4, new Position(0)); compositeTabDock2.addChildDock(dock5, new Position(1)); compositeTabDock3.addChildDock(dock6, new Position(0)); compositeTabDock3.addChildDock(dock7, new Position(1)); compositeTabDock3.addChildDock(dock8, new Position(2)); compositeTabDock2.addChildDock(compositeTabDock3, new Position(2));
| SplitDockWithOneChild | Shows the use of split docks. |
| SplitDockWithTwoChildren | Shows the use of split docks. |
| FloatChildDocks | Shows the use of float docks. |
| CompositeLineDocks | Shows the use of composite line docks. |
| CompositeGridDocks | Shows the use of composite grid docks. |
| CompositeTabDocks | Shows the use of composite tab docks. |