ToolWindowManager

How to init a ToolWindowManager?

To obtain an instance of the ToolWindowManager interface you have to instantiate the MyDoggyToolWindowManager class which provides the default implementation.
Use the following:

ToolWindowManager twManager = new MyDoggyToolWindowManager(...);

or

ToolWindowManager toolWindowManager = new MyDoggyToolWindowManager(
                  Locale.getDefault() // A Locale instance
    );
                

MyDoggyToolWindowManager is implemented like a JPanel so you can use it like any other component.
For example:

JFrame frame = new JFrame("MyDoggy-Set...");
...
MyDoggyToolWindowManager myDoggyToolWindowManager = new MyDoggyToolWindowManager();
...
frame.getContentPane().add(myDoggyToolWindowManager);

Warning: to be able to use all the toolwindow types (Sliding, Floating Live, etc.), ensure that the toolwindow manager has as window ancestor an object implementing the RootPaneContainer interface (i.e. JFrame, JWindow, JApplet, ...).

How to register a ToolWindow?

Use the following :
ToolWindowManager twManager = new MyDoggyToolWindowManager(...);
ToolWindow debugTool = twManager.registerToolWindow(
       "Debug",               // Tool Window identifier
       "Debug Tool",          // Tool Window Title
       debugIcon,             // Tool Window Icon
       debugComponent,        // Tool Window component
       ToolWindowAnchor.LEFT  // Tool Window anchor
);

How to unregister a ToolWindow?

Use the following :
ToolWindowManager twManager = new MyDoggyToolWindowManager(...);
twManager.unregisterToolWindow("Debug");

How to add a ToolWindow Alias?

Use the following :
ToolWindowManager twManager = new MyDoggyToolWindowManager(...);
Object debugToolAlias = new DebugToolAlias();
twManager.addAlias(debugTool, debugToolAlias);

How to get a ToolWindowManagerDescriptor instance?

To obtain the instance of the ToolWindowManagerDescriptor for a specific ToolWindowManager use the following:


ToolWindowManagerDescriptor descriptor = twManager.getToolWindowManagerDescriptor();

How to set the PushAwayMode?

After you have obtained an instance of the ToolWindowManagerDescriptor for a specific ToolWindowManager use the following to change to PushAwayMode:


ToolWindowManagerDescriptor descriptor = twManager.getToolWindowManagerDescriptor();
descriptor.setPushAwayMode(PushAwayMode.MOST_RECENT);

To retrieve the current PushAwayMode use the following:

ToolWindowManagerDescriptor descriptor = twManager.getToolWindowManagerDescriptor();
PushAwayMode pushAwayMode = descriptor.getPushAwayMode();

How to set a Corner Component?

After you have obtained an instance of the ToolWindowManagerDescriptor for a specific ToolWindowManager use the following to set a corner component:

ToolWindowManagerDescriptor descriptor = twManager.getToolWindowManagerDescriptor();
descriptor.setCornerComponent(
                    ToolWindowManagerDescriptor.Corner.NORD_WEST,
                    new JLabel("NW"));

ToolWindow

How to show or hide a ToolWindow?

Use the following :
                    ToolWindow tool = toolWindowManager.getToolWindow(0);
                    tool.setVisibile(true); // false to hide
                

The tool shows or hides the component in a way that depends on tool window type.
There is an another way to show a tool. You can use the aggregate methedo

                    ToolWindow tool = toolWindowManager.getToolWindow(0);
                    tool.aggregate();
                

The method is used to set to the true value the visible property of the tool. The tool becomes visible in a special way. In fact, if there is another tool visible with the same anchor than these two tools will be aggregate to be visible both.

How to activate a ToolWindow?

Use the following :
                    ToolWindow tool = toolWindowManager.getToolWindow(0);
                    tool.setActive(true); // false to deactivate
                

The tool grabs the focus from focus owner and becomes active.

How to Move a ToolWindow?

Use the following :
                    ToolWindow tool = toolWindowManager.getToolWindow(0);
                    tool.setAnchor(ToolWindowAnchor.TOP);
                

The anchor specifies the position of the tool when it is anchored to the docking system.

How to request attention using Flashing?

Use the following :
                    ToolWindow tool = toolWindowManager.getToolWindow(0);
                    tool.setFlashing(true); // false to disable
                

Sets the flashing mode. If the flashing mode is enabled then the toolwindow representative button will be flashing until the tool will be made visible. If the tool is visible but not active then the toolwindow title bar will be flashing until the tool will be made visible.
You can use setFlashing(int) to enable flashing for a specific duration.

How to add a PropertyChangeListener?

Use the following :
                    ToolWindow tool = toolWindowManager.getToolWindow(0);
                    tool.setAnchor(ToolWindowAnchor.TOP);
                

Adds a PropertyChangeListener to the listener list. The listener is registered for all bound properties of this class, including the following:

  • this tool's index ("index")
  • this tool's aailable status ("available")
  • this tool's visible status ("visible")
  • this tool's active status ("active")
  • this tool's anchor ("anchor")
  • this tool's autoHide ("autoHide")
  • this tool's type ("type")
  • this tool's icon ("icon")
  • this tool's title ("title")

How to enable/disable the PopupMenu?

Use the following :
                    DockedTypeDescriptor desc = (DockedTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.DOCKED);
                    desc.setPopupMenuEnabled(true); // false to denie.
                

So you can Specifies whether the popup menu of the representative anchor button of the tool should be enabled.

How to manage the Tools Menu?

Use the following to retrieve the tools menu:
                    DockedTypeDescriptor desc = (DockedTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.DOCKED);
                    JMenu menu = desc.getToolsMenu();
                    menu.addJMenuItem(new JMenuItem("Hello World!!!");
                

The user can add specific menu items to the popup menu of the representative anchor button of the tool using the result of this method invocation.

How to set the Dock Panel Length?

Use the following:
                    DockedTypeDescriptor desc = (DockedTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.DOCKED);
                    desc.setDockLength(150);
                

Sets the width or heigth, based on anchor of tool window, of the dock panel. This value is used by DOCKED and SLIDING tool window type.

How to set a ToolWindowActionHandler?

Use the following:
                    DockedTypeDescriptor desc = (DockedTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.DOCKED);
                    desc.setToolWindowActionHandler(new ToolWindowActionHandler(){...});
                

How to enable the Preview Mode?

Use the following :
                    DockedTypeDescriptor desc = (DockedTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.DOCKED);
                    desc.setPreviewEnabled(true); // false to disable
                

Sets the preview mode. If the preview mode is enabled then when the mouse waits on the toolwindow representative button after a delay time the preview will become visible.
You can use setPreviewTransparentRatio and setPreviewDelay methods to set transparency paramenters and delay.

How to enable the Transparent Mode on SlidingType?

Use the following :
                    SlidingTypeDescriptor desc = (SlidingTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.SLIDING);
                    desc.setTransparentMode(true); // false to disable
                

Sets the transparent mode. If the transparent mode is enabled then when the toolwindow's content losts the focus it becomes transparent. This facility is os-independent.
You can use setTransparentRatio and setTransparentDelay methods to set transparency paramenters and delay.

Enable/Disable

Use the following :
                    SlidingTypeDescriptor desc = (SlidingTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.SLIDING);
                    desc.setEnabled(true); // false to disable
                

Enables or disables this mode, depending on the value of the parameterenabled. An enabled mode can used by user. This Mode is enabled initially by default.

Enable Transparent Mode on FloatingType

Use the following :
                    FloatingTypeDescriptor desc = (FloatingTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.SLIDING);
                    desc.setTransparentMode(true); // false to disable
                

Sets the transparent mode. If the transparent mode is enabled then when the window used by FLOATING and FLOATING_FREE type losts the focus it becomes transparent. This facility is os-dependent.
You can use setTransparentRatio and setTransparentDelay methods to set transparency paramenters and delay.

Enable/Disable

Use the following :
                    FloatingTypeDescriptor desc = (FloatingTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.SLIDING);
                    desc.setEnabled(true); // false to disable
                

Enables or disables this mode, depending on the value of the parameterenabled. An enabled mode can used by user. This Mode is enabled initially by default.

Change Window Position

Use the following :
                    FloatingTypeDescriptor desc = (FloatingTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.SLIDING);
                    desc.setPosition(150, 220);
                

Sets the window location. This location is also used the first time the window becomes visible. The top-left corner of the new location is specified by the x and y parameters in the system coordinate space.

Change Window Size

Use the following :
                    FloatingTypeDescriptor desc = (FloatingTypeDescriptor)
                    debugTool.getTypeDescriptor(ToolWindowType.SLIDING);
                    desc.setSize(320, 200);
                

Sets the window size. This size is also used the first time the window becomes visible.

ToolWindowTab

How to add a ToolWindowTab?

Use the following :
                    ToolWindow tool = toolWindowManager.getToolWindow(0);
                    tool.addToolWindowTab("Title", component);
                

Adds a component represented by a title and no icon.

ToolWindowGroup

How to get a group?

Use the following :
ToolWindowGroup group = toolWindowManager.getToolWindowGroup("group_name");

Returns the tool window group to which this manager maps the specified name. If the manager contains no mapping for this name then the manager create a new instance of ToolWindowGroup and associates the group created with the specified name in this manager.

How to remove a group?

Use the following :
toolWindowManager.removeToolWindowGroup("group_name");

Removes the tool window group for this name from this manager if it is present.

How to check if a group exists?

Use the following :
boolean contains = toolWindowManager.containsGroup("group_name");

Returns true if this manager contains a group for the specified name.

How to add a toolwindow to a group?

Use the following :
ToolWindowGroup group = toolWindowManager.getToolWindowGroup("group_name");
ToolWindow debugTool = toolWindowManager.getToolWindow("Debug");
group.addToolWindow(debugTool);

Appends the specified tool window to the end of this group.

How to Remove a toolwindow from a group?

Use the following :
ToolWindowGroup group = toolWindowManager.getToolWindowGroup("group_name");
ToolWindow debugTool = toolWindowManager.getToolWindow("Debug");
group.removeToolWindow(debugTool);

Removes the occurrence in this group of the specified tool window.

How to show or hide a group?

Use the following :
ToolWindowGroup group = toolWindowManager.getToolWindowGroup("group_name");
group.setVisible(true);

Invokes setVisible(visible) on all toolwindows contained in this group in proper sequence.

How to add a ToolWindowGroupListener?

Use the following :
ToolWindowGroup group = toolWindowManager.getToolWindowGroup("group_name");
group.addToolWindowGroupListener(listener);

Registers listener so that it will receive events when the groups are made visibile or invisible, when a tool is added or removed. If listener listener is null, no exception is thrown and no action is performed.

ContentManager

How to add a content?

Use the following :
ContentManager contentManager = toolWindowManager.getContentManager();
Content tools = ContentcontentManager.addContent("Tools"   // Content Key
                                                 "Tools",  // Content title
                                                 null,     // Content Item
                                                 toolsContent, // Content component
                                                 "ToolWindows" // Content tooltip text
);

Adds a component represented by a unique identifier key with a title and/or icon, either of which can be null.

How to remove a content?

Use the following :
ContentManager contentManager = toolWindowManager.getContentManager();
contentManager.removeContent(tools);

Removes the content from the manager.

How to get the selected content?

Use the following :
ContentManager contentManager = toolWindowManager.getContentManager();
Content content = contentManager.getSelectedContent();

Returns the selected content, or null if the selection is empty.

How to change the ContentManagerUI?

Use the following :
ContentManager contentManager = toolWindowManager.getContentManager();
ContentManagerUI contentManagerUI = new ... TODO
contentManager.setContentManagerUI(contentManagerUI);

Sets the content manager ui to contentManagerUI.

How to enable/disable the ContentManager?

Use the following :
ContentManager contentManager = toolWindowManager.getContentManager();
contentManager.setEnabled(false); // or true to enable

Enables or disables the content manager. If the content manager is disable the whole space will be available for toolwindows.

ContentManagerUI

How to obtain the instance of the ContentManagerUI interface?

Use the following :
ContentManagerUI contentManagerUI = toolWindowManager.getContentManager().getContentManagerUI();

Returns the content manager ui.

How to change the ContentManagerUI?

Use the following :
toolWindowManager.getContentManager().setContentManagerUI(new MyDoggyDesktopContentManagerUI());

Sets the content manager ui.

How to set 'Closeable' and 'Detachable' property?

Use the following :
ContentManagerUI contentManagerUI = toolWindowManager.getContentManager().getContentManagerUI();
contentManagerUI.setCloseable(true);
contentManagerUI.setsetDetachable(true);

Sets the 'Closeable' and/or 'Detachable' property of all contents registered to content manager.

How to add a ContentManagerUIListener?

Use the following :
ContentManagerUI contentManagerUI = toolWindowManager.getContentManager().getContentManagerUI();
contentManagerUI.addContentManagerUIListener(listener);

Registers listener so that it will receive events when a content is removed or detached using the ui. For the remove action you can apply a veto to the action. If listener listener is null, no exception is thrown and no action is performed.

ContentUI

How to retrieve the ContentUI given a Content?

Use the following :
ContentManagerUI contentManagerUI = toolWindowManager.getContentManager().getContentManagerUI();
Content content = toolWindowManager.getContentManager().getContent(0);
ContentUI contentUi = contentManagerUI.getContentUI(content);

Returns the ui part to which this manager maps the specified content.

How to retrieve the Content from a ContentUI?

Use the following :
ContentManagerUI contentManagerUI = toolWindowManager.getContentManager().getContentManagerUI();
Content content = toolWindowManager.getContentManager().getContent(0);
ContentUI contentUi = contentManagerUI.getContentUI(content);
assert contentUi.getContent() == content;

Returns the Content contropart of a ContentUI instance.

How to set the 'Closeable' and 'Detachable' property?

Use the following :
ContentManagerUI contentManagerUI = toolWindowManager.getContentManager().getContentManagerUI();
Content content = toolWindowManager.getContentManager().getContent(0);
ContentUI contentUi = contentManagerUI.getContentUI(content);
contentUi.setCloseable(true);
contentUi.setDetachable(true);

Sets the 'Closeable' and/or 'Detachable' property of a specific ContentUI.

How to customize transparency support?

Use the following :
ContentManagerUI contentManagerUI = toolWindowManager.getContentManager().getContentManagerUI();
Content content = toolWindowManager.getContentManager().getContent(0);
ContentUI contentUi = contentManagerUI.getContentUI(content);
contentUi.setTransparentMode(true);
contentUi.setTransparentRatio(0.7f);
contentUi.setTransparentDelay(1000);

Sets the transparent mode. If the transparent mode is enabled then when the content is detached and the window containing the content losts the focus then the window becomes transparent. This facility is os-dependent.

PersistenceDelegate

How to get an instance of the PersistenceDelegate interface?

To obtain the instance of the PersistenceDelegate for a specific ToolWindowManager use the following:

PersistenceDelegate pstDelegate = twManager.getPersistenceDelegate();

How to store a workspace?

After you have obtained an instance of the PersistenceDelegate for a specific ToolWindowManager use the following to store the workspace:

PersistenceDelegate pstDelegate = twManager.getPersistenceDelegate();
try {
    FileOutputStream output = new FileOutputStream("workspace.xml");
    twManager.getPersistenceDelegate().save(output);
    output.close();
} catch (Exception e) {
    e.printStackTrace();
}

How to restore a saved workspace?

After you have obtained an instance of the PersistenceDelegate for a specific ToolWindowManager use the following to apply a saved workspace to the current workspace:

PersistenceDelegate pstDelegate = twManager.getPersistenceDelegate();
try {
    FileInputStream inputStream = new FileInputStream("workspace.xml");
    pstDelegate.apply(inputStream);
    inputStream.close();
} catch (Exception e1) {
    e1.printStackTrace();
}

Using merge(InputStream, MergePolicy) method, you can decide the method's behaviour relative to the tools already visible when the method is called.

PersistenceDelegate pstDelegate = twManager.getPersistenceDelegate();
try {
    FileInputStream inputStream = new FileInputStream("workspace.xml");
    pstDelegate.merge(
                    inputStream,
                    PersistenceDelegate.MergePolicy.RESET);
    inputStream.close();
} catch (Exception e1) {
    e1.printStackTrace();
}