« prev next »
Java Docking Home> Developer Guide> How to Use Dockable Actions

How to Use Dockable Actions

:: Custom dockable actions ::

You can decorate a Dockable with actions by using an ActionDockable. First you have to create your basic dockable. Then you create the wrapper action dockable around the dockable, that adds actions to it.

In the folowing example the dockable is decorated with 2 actions.

		// Create the dockable around the content component.
		Dockable dockable = new DefaultDockable("Window1", textPanel, "Window", new ImageIcon("resources/images/text12.gif"));

		...
				
		// Decorate the dockable with actions.
		MessageAction helloAction = new MessageAction(this, "Hello", new ImageIcon("/com/javadocking/resources/images/hello12.gif"), "Hello world!");
		MessageAction cautionAction = new MessageAction(this, "Caution", new ImageIcon("/com/javadocking/resources/images/caution12.gif"), "Be Careful!");
		Action[][] actions = new Action[1][];
		actions[0] = new Action[2];
		actions[0][0] = helloAction;
		actions[0][1] = cautionAction;
		dockable = new ActionDockable(dockable, actions);

:: Actions for closing, minimizing, maximizing, and externalizing a dockable ::

You can decorate a dockable with special actions to change the state of the dockable by using a StateActionDockable.

In the folowing example the dockable is decorated with actions to normalize, minimize, maximize, and externalize the dockable.

	// Add minimize, maximize, externalize, and close actions to the dockables.
	dockable1 = addActions(dockable1);
	dockable2 = addActions(dockable2);
		
		...
		
	private Dockable addActions(Dockable dockable)
	{
		Dockable wrapper = new StateActionDockable(dockable, new DefaultDockableStateActionFactory(), new int[0]);
		int[] states = {DockableState.CLOSED, DockableState.NORMAL, DockableState.MINIMIZED, DockableState.MAXIMIZED, DockableState.EXTERNALIZED};
		wrapper = new StateActionDockable(wrapper, new DefaultDockableStateActionFactory(), states);
		return wrapper;
	}
		

:: Popup menus for dockables ::

The PopupMenuFactory is used to create popup menus for the dockables. A popup menu for one dockable is shown, when you right click on the tab header of a dockable in a tab dock. A popup menu for a group of dockables is shown, when you right click on the header of a dock, but outside the header of one specific dockable.

The popup menu factory has to be given to the SwComponentFactory of the docking manager, otherwise the default popup menu factory DefaultPopupMenuFactory is used.

In the folowing example the actions of a dockable are shown in the popup menu, but also a close all and close others action.

		// We only want to see the dockable actions, the close all, and close others actions in the popup menu.
		DefaultPopupMenuFactory popupMenuFactory = new DefaultPopupMenuFactory();
		popupMenuFactory.setPopupActions(DefaultPopupMenuFactory.DOCKABLE_ACTIONS | DefaultPopupMenuFactory.CLOSE_ALL_ACTION | DefaultPopupMenuFactory.CLOSE_OTHERS_ACTION);
		DefaultSwComponentFactory componentFactory = new DefaultSwComponentFactory();
		componentFactory.setPopupMenuFactory(popupMenuFactory);
		DockingManager.setComponentFactory(componentFactory);



The source code of the samples can be found in:

ActionsDockableShows a dockable with actions.
DockableActionsExampleShows a dockables with actions and custom popup menus.



« prev next »