com.japisoft.framework.dockable
Class JDock

java.lang.Object
  |
  +--com.japisoft.framework.dockable.JDock

public class JDock
extends java.lang.Object

Main component for the docking environnement. The user adds inner windows calling the addInnerWindow method. An inner window has always an unique ID. This ID can be used after for selecting, maximizing, hiding, restoring... the bound inner window. It is also possible to add an inner window without ID calling the add method, in this case the inner window is called "anonymous" and the final user can't handle it.

Here sample of usage

 
 // Main panel 
 JDock pane = new JDock();
 
 // Action for removing the default shadow
 // pane.setShadowMode( false );
 
 // The default JDock layout is a BorderLayout
 
 JTextArea t;
 
 pane.addInnerWindow(new InnerWindowProperties("T1", "Tree", new JScrollPane(
 		new JTree())), BorderLayout.WEST);
 pane.addInnerWindow(new InnerWindowProperties("TA", "Text Area",
 		t = new JTextArea()), BorderLayout.CENTER);
 
 // We set an initial size as sample
 
 t.setPreferredSize(new Dimension(200, 50));
 
 JFrame frame = new JFrame();
 frame.getContentPane().add(pane.getView());
 frame.setSize(600, 500);
 frame.setVisible(true);
 
 
 

By default the default layout is a BorderLayout, but the user can use another one like a GridbagLayout calling setLayout on the JDock instance. This method MUST be called before adding the inner windows. Note that the setPreferredSize method can be used for setting an initial size to a component.

For saving the inner windows state, the getState method can be used. The result object can be stored using an ObjectOutputStream. For restoring the JDock state, the user must called setState. Note that the state is not saved for anonymous inner window.

The user can change the look of the inner windows using the following UIManager properties :

 
 
 // Sample for resetting the starting color of the header for each non selected inner window
 UIManager.put("jdock.innerwindow.gradient.startColor", Color.DARK_GRAY);
 // Sample for resetting the final color of the header for each non selected inner window
 UIManager.put("jdock.innerwindow.gradient.stopColor", Color.WHITE);
 // Sample for resetting the starting color of the header for each selected inner window
 UIManager.put("jdock.innerwindow.gradient.selectedStartColor", Color.RED
 		.darker());
 // Sample for resetting the final color of the header for each selected inner window		
 UIManager.put("jdock.innerwindow.gradient.selectedStopColor", Color.WHITE);
 
 
 

By default an inner window has an header with a title and a set of actions located at the right part of the window. The default actions are stored as classes inside the CommonActionManager. The available actions are stored inside the com.japisoft.framework.dockable.action.common package. The user can remove default action or add new default action with the CommonActionManager. It is also possible to use custom actions using the ActionModel. An instance of this class is available for each inner window. The user can add / remove dynamically a swing action with it. Here a sample

 
 // We remove the ExtractAction inside the inner window with the T1 id
 ActionModel model1 = pane.getInnerWindowActionsForId("T1");
 Action a1 = model1.getActionByClass(ExtractAction.class);
 model1.removeAction(a1);
 
 Action[] actions = new Action[] { new CopyAction(textArea), // Action sample
 		new CutAction(textArea), // Action sample
 		new PasteAction(textArea), // Action sample
 		new ExtractAction() // This is a default action
 };
 
 // We use a new actions toolbar for the inner window TA id
 pane.addInnerWindow(new InnerWindowProperties("TA", "Text Area",
 		new BasicActionModel(actions), textArea), BorderLayout.CENTER);
 
 

More information at : http://www.swingall.com

Version:
1.4
Author:
(c) 2005 JAPISOFT

Constructor Summary
JDock()
          Default constructor.
JDock(boolean shadowMode)
           
 
Method Summary
 void add(javax.swing.JComponent view, java.lang.Object constraint)
          Add a component without bar.
 void addInnerWindow(InnerWindowProperties properties, java.lang.Object constraint)
          Insert a frame inside the JDock container.
 void addInnerWindow(javax.swing.JComponent view, java.lang.Object constraint)
          Add a component without bar.
 void addJDockListener(JDockListener listener)
          Add a listener for the inner window state (selected, maximized, moved, removed...)
 void dispose()
          Free all inner resources.
 void extractInnerWindow(java.lang.String id)
          Extract and content of this inner window and put it inside a frame.
 java.awt.Color getBackground()
           
 java.awt.Color getDraggingActiveWindow()
           
 java.awt.Color getDraggingShadowColor()
           
 ActionModel getInnerWindowActionsForId(java.lang.String id)
          This method will return null for a wrong id.
 javax.swing.Icon getInnerWindowIconForId(java.lang.String id)
           
 java.lang.String getInnerWindowTitleForId(java.lang.String id)
          This method will return null for a wrong id.
 javax.swing.JComponent getInnerWindowViewForId(java.lang.String id)
          This method will return null for a wrong id.
 java.awt.Dimension getMinimalInnerWindowSize()
           
 java.awt.Color getResizingShadowColor()
           
 State getState()
          This action MUST only be used with inner windows having an ID
 javax.swing.JComponent getView()
           
 void hideInnerWindow(java.lang.String id)
          Hide the inner window with the following id.
 boolean isEnabledActionPopup()
           
 boolean isEnabledDraggingShasow()
           
 boolean isEnabledResizeShasow()
           
 boolean isEnabledStatusBar()
           
 boolean isInnerWindowFixed(java.lang.String id)
           
 boolean isInnerWindowHidden(java.lang.String id)
           
 boolean isMaximizedInnerWindow(java.lang.String id)
           
 boolean isShadowMode()
           
 void maximizedRestoredInnerWindow(java.lang.String id)
          Maximized or restored this inner window depending on its state.
 void maximizeInnerWindow(java.lang.String id)
          Put this inner window in a "full-window" mode.
 void removeInnerWindow(java.lang.String id)
          Remove definitly the frame with the following id
 void removeJDockListener(JDockListener listener)
          Remove a listener for the inner window state
 boolean resize(java.lang.String id, int addedWidth, int addedHeight)
          This method can be used for dynamically resize an inner window
 void restoreInnerWindow(java.lang.String id)
          Restore this inner window size if it has been maximized previously.
 void selectInnerWindow(java.lang.String id)
          Highlight this window with the following id.
 void setBackground(java.awt.Color color)
          Reset the jdock background
 void setDraggingActiveWindow(java.awt.Color color)
          Reset the color while dragging an inner window under an active inner window.
 void setDraggingShadowColor(java.awt.Color color)
          Reset the color while dragging an inner window.
 void setEnabledActionPopup(boolean enabled)
          Enable a popup menu on the window bar icon.
 void setEnabledDraggingShadow(boolean enabled)
          if true it will draw a shadow while dragging an inner window.
 void setEnabledResizeShadow(boolean enabled)
          if true it will draw a shadow while resizing an inner window.
 void setEnabledStatusBar(boolean enabled)
          Enable a status bar containg the hidden inner window.
 void setInnerWindowBackgroundForId(java.lang.String id, java.awt.Color color)
          Update the background color of the header for this inner window id.
 void setInnerWindowFixed(java.lang.String id, boolean fixed)
          It will fixe an inner window, thus it will not able to move to another inner window space.
 void setInnerWindowForegroundForId(java.lang.String id, java.awt.Color color)
          Update the foreground color of the header for this inner window id.
 void setInnerWindowIconForId(java.lang.String id, javax.swing.Icon icon)
          Update an icon for an inner window with the following id.
 void setInnerWindowTitleForId(java.lang.String id, java.lang.String title)
          Update a title for an inner window with the following id.
 void setLayout(java.awt.LayoutManager2 layout)
          Reset a layout for initializing each frame.
 void setMenuWindow(javax.swing.JMenu menuWindow)
          Here a menu for your main frame or dialog containg a set of available inner windows to be hidden or shown.
 void setMinimalInnerWindowSize(java.awt.Dimension dim)
          Update the minimal frame size.
 void setResizingShadowColor(java.awt.Color color)
          Reset the shadow color while resizing an inner window.
 void setShadowMode(boolean shadow)
          Here a mode for displaying shadow around the inner windows.
 void setState(State state)
          Reset the inner windows state (size and location).
 void showInnerWindow(java.lang.String id)
          Show the inner window with the following id.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDock

public JDock()
Default constructor. The shadow mode is activated


JDock

public JDock(boolean shadowMode)
Parameters:
shadowMode - Display a shadow for the inner frames. By default true
Method Detail

setShadowMode

public void setShadowMode(boolean shadow)
Here a mode for displaying shadow around the inner windows. By default true


isShadowMode

public boolean isShadowMode()
Returns:
true if a shadow is displayed for the inner frames

setLayout

public void setLayout(java.awt.LayoutManager2 layout)
Reset a layout for initializing each frame. By default a BorderLayout


setMenuWindow

public void setMenuWindow(javax.swing.JMenu menuWindow)
Here a menu for your main frame or dialog containg a set of available inner windows to be hidden or shown. This menu will be automatically managed by JDock so it must be empty and not managed by the user.

Parameters:
menuWindow - A menu for the set of frame

dispose

public void dispose()
Free all inner resources. It should be called for stopping definitly using the JDock container thus removing any inner pointers.


add

public void add(javax.swing.JComponent view,
                java.lang.Object constraint)
Add a component without bar. Such component can't be managed by the user except for resizing it. This is similar to addInnerWindow( view, constraint ).

Parameters:
view - A component to insert
constraint - A layout constraint. For a non BorderLayout, You must call setLayout before.

addInnerWindow

public void addInnerWindow(InnerWindowProperties properties,
                           java.lang.Object constraint)
Insert a frame inside the JDock container.

Parameters:
constraint - A layout constraint. For a non BorderLayout (the default layout), You must call setLayout before.

addInnerWindow

public void addInnerWindow(javax.swing.JComponent view,
                           java.lang.Object constraint)
Add a component without bar. Such component can't be managed by the user except for resizing it. This is similar to add( view, constraint ).

Parameters:
view - A component to insert
constraint - A layout constraint. For a non BorderLayout, You must call setLayout before.

getView

public javax.swing.JComponent getView()
Returns:
the main container for JDock

setEnabledStatusBar

public void setEnabledStatusBar(boolean enabled)
Enable a status bar containg the hidden inner window. By default this is not enabled. Note that this method must be called before calling the getView();

Parameters:
enabled - true for having a status bar with the hidden windows

isEnabledStatusBar

public boolean isEnabledStatusBar()
Returns:
true if a status bar is available with the inner window

setEnabledActionPopup

public void setEnabledActionPopup(boolean enabled)
Enable a popup menu on the window bar icon. By default true


isEnabledActionPopup

public boolean isEnabledActionPopup()
Returns:
true if a popup menu is activated while clicking on the window icon

setMinimalInnerWindowSize

public void setMinimalInnerWindowSize(java.awt.Dimension dim)
Update the minimal frame size. By default 10 x 10. This minimal value is used when resizing a frame

Parameters:
dim - A minimal frame size

getMinimalInnerWindowSize

public java.awt.Dimension getMinimalInnerWindowSize()
Returns:
the minimal size for the frames

getState

public State getState()
This action MUST only be used with inner windows having an ID

Returns:
the current inner windows state (size and location)

setState

public void setState(State state)
Reset the inner windows state (size and location). This action MUST only called when you have inner window with an ID.


getInnerWindowTitleForId

public java.lang.String getInnerWindowTitleForId(java.lang.String id)
This method will return null for a wrong id.

Returns:
a title for an inner window with the following id

isInnerWindowFixed

public boolean isInnerWindowFixed(java.lang.String id)
Parameters:
id - Inner window id
Returns:
true if the bound inner window cannot be moved

setInnerWindowFixed

public void setInnerWindowFixed(java.lang.String id,
                                boolean fixed)
It will fixe an inner window, thus it will not able to move to another inner window space. A JDockException will be thrown if the id is unknown

Parameters:
id - Inner window id
fixed - if true the inner window is static

getInnerWindowActionsForId

public ActionModel getInnerWindowActionsForId(java.lang.String id)
This method will return null for a wrong id.

Returns:
the set of actions bar for an inner window with the following id

setInnerWindowTitleForId

public void setInnerWindowTitleForId(java.lang.String id,
                                     java.lang.String title)
Update a title for an inner window with the following id. A JDockException will be thrown if the id is wrong

Parameters:
id - Id of the inner window
title - New title of the inner window (can be null)

setInnerWindowIconForId

public void setInnerWindowIconForId(java.lang.String id,
                                    javax.swing.Icon icon)
Update an icon for an inner window with the following id. A JDockException will be thrown if the id is wrong

Parameters:
id - Id of the inner window
icon - New icon of the inner window (can be null)

getInnerWindowIconForId

public javax.swing.Icon getInnerWindowIconForId(java.lang.String id)
Parameters:
id - Inner window id
Returns:
the main icon for this inner window

setInnerWindowBackgroundForId

public void setInnerWindowBackgroundForId(java.lang.String id,
                                          java.awt.Color color)
Update the background color of the header for this inner window id. Use null for restoring the default color

Parameters:
id - An inner window id
color - An inner window header background

setInnerWindowForegroundForId

public void setInnerWindowForegroundForId(java.lang.String id,
                                          java.awt.Color color)
Update the foreground color of the header for this inner window id. Use null for restoring the default color

Parameters:
id - An inner window id
color - An inner window header foreground

getInnerWindowViewForId

public javax.swing.JComponent getInnerWindowViewForId(java.lang.String id)
This method will return null for a wrong id.

Returns:
The component of the frame with the following id

removeInnerWindow

public void removeInnerWindow(java.lang.String id)
Remove definitly the frame with the following id

Parameters:
id - an inner window Id

hideInnerWindow

public void hideInnerWindow(java.lang.String id)
Hide the inner window with the following id. A JDockException will be thrown if the id is unknown.

Parameters:
id - an inner window Id

showInnerWindow

public void showInnerWindow(java.lang.String id)
Show the inner window with the following id. A JDockException will be thrown if the id is unknown.

Parameters:
id - an inner window Id

isInnerWindowHidden

public boolean isInnerWindowHidden(java.lang.String id)
Returns:
true if the innerWindow with the following id is hidden

selectInnerWindow

public void selectInnerWindow(java.lang.String id)
Highlight this window with the following id.

Parameters:
id - An inner window id

extractInnerWindow

public void extractInnerWindow(java.lang.String id)
Extract and content of this inner window and put it inside a frame. A JDockException will be thrown for an unknown inner window.

Parameters:
id - An inner window id

maximizeInnerWindow

public void maximizeInnerWindow(java.lang.String id)
Put this inner window in a "full-window" mode. A JDockException will be thrown for an unknown id


isMaximizedInnerWindow

public boolean isMaximizedInnerWindow(java.lang.String id)
Parameters:
id - an Inner window id
Returns:
true if the inner window with the following id is maximized. If the id is unknown it will return always false

restoreInnerWindow

public void restoreInnerWindow(java.lang.String id)
Restore this inner window size if it has been maximized previously. A JDockException will be thrown for an unknown id


maximizedRestoredInnerWindow

public void maximizedRestoredInnerWindow(java.lang.String id)
Maximized or restored this inner window depending on its state. A JDockException will be thrown for an unknown id

Parameters:
id - An inner window id

setEnabledDraggingShadow

public void setEnabledDraggingShadow(boolean enabled)
if true it will draw a shadow while dragging an inner window. By default true


isEnabledDraggingShasow

public boolean isEnabledDraggingShasow()
Returns:
true if a shadow is drawn while dragging an inner window. By default true

setBackground

public void setBackground(java.awt.Color color)
Reset the jdock background

Parameters:
color - Background color

getBackground

public java.awt.Color getBackground()
Returns:
the jdock background

setDraggingShadowColor

public void setDraggingShadowColor(java.awt.Color color)
Reset the color while dragging an inner window. By default BLACK

Parameters:
color - Color for the shadow while dragging an inner window

getDraggingShadowColor

public java.awt.Color getDraggingShadowColor()
Returns:
the dragging shadow color. By default BLACK

setDraggingActiveWindow

public void setDraggingActiveWindow(java.awt.Color color)
Reset the color while dragging an inner window under an active inner window. By default RED

Parameters:
color - Color while dragging an inner window for an active inner window

getDraggingActiveWindow

public java.awt.Color getDraggingActiveWindow()
Returns:
the dragging active inner window color. By default RED

setResizingShadowColor

public void setResizingShadowColor(java.awt.Color color)
Reset the shadow color while resizing an inner window. By default BLACK

Parameters:
color - A color while resizing an inner window

getResizingShadowColor

public java.awt.Color getResizingShadowColor()
Returns:
the color of the shadow while resizing an inner window. By default BLACK

resize

public boolean resize(java.lang.String id,
                      int addedWidth,
                      int addedHeight)
This method can be used for dynamically resize an inner window

Parameters:
id - An inner window id
addedWidth - This is the value added to the width of the window
addedHeight - This is the value added to the height of the window
Returns:
true only if the operation is possible

addJDockListener

public void addJDockListener(JDockListener listener)
Add a listener for the inner window state (selected, maximized, moved, removed...)


removeJDockListener

public void removeJDockListener(JDockListener listener)
Remove a listener for the inner window state


setEnabledResizeShadow

public void setEnabledResizeShadow(boolean enabled)
if true it will draw a shadow while resizing an inner window. By default true


isEnabledResizeShasow

public boolean isEnabledResizeShasow()
Returns:
true if a shadow is drawn while resizing an inner window. By default true