org.peace_tools.generic.dndTabs
Class DnDTabbedPane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTabbedPane
                  extended by org.peace_tools.generic.dndTabs.DnDTabbedPane
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants

public class DnDTabbedPane
extends javax.swing.JTabbedPane

See Also:
Serialized Form

Nested Class Summary
static class DnDTabbedPane.Location
          Preferred docking locations for tabs.
 
Nested classes/interfaces inherited from class javax.swing.JTabbedPane
javax.swing.JTabbedPane.AccessibleJTabbedPane, javax.swing.JTabbedPane.ModelListener
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  DnDTabbedPane.Location dockCue
          This instance variable is used to track if this DndTabbedPane should paint a outline on itself to indicate where a tab being dragged will be docked with respect to this window.
private static double EDGE_PANEL_SIZE
          This constant determines the default size that is used for panels that are docked to the edges (top, left, bottom, right) of a given DnDTabPanel.
private static java.util.ArrayList<DnDTabListener> listeners
          The list of listeners that have been added for this DnDTabbedPane.
private  boolean permanent
          A boolean variable that indicates if this tab is permanent and should not be deleted even if it is empty.
private static long serialVersionUID
          A generated serial version ID.
 
Fields inherited from class javax.swing.JTabbedPane
changeEvent, changeListener, model, SCROLL_TAB_LAYOUT, tabPlacement, WRAP_TAB_LAYOUT
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DnDTabbedPane()
          The default constructor.
 
Method Summary
static void addListener(DnDTabListener listener)
          Add a listener to be notified when a tab in this panel is deleted.
 DnDTabbedPane createSplitPane(java.lang.String title, javax.swing.Icon icon, java.awt.Component c, DnDTabbedPane.Location location)
          This method may be used to manually add components either directly to this tabbed pane or around this tabbed pane.
 DnDTabbedPane createSplitPane(java.lang.String title, javax.swing.Icon icon, java.awt.Component c, DnDTabbedPane.Location location, double gravity)
          This method may be used to manually add components either directly to this tabbed pane or around this tabbed pane.
 DnDTabbedPane createSplitPane(java.lang.String title, javax.swing.Icon icon, java.awt.Component c, DnDTabbedPane.Location location, double gravity, int size)
          This method may be used to manually add components either directly to this tabbed pane or around this tabbed pane.
 void deleteTab(java.awt.Component componentRemoved)
          Delete (and remove) a given tab component.
 DnDTabbedPane.Location getDockCue()
          This method can be used to determine the current docking cue associated with this DndTabPane.
 boolean isPermanent()
          This method may be used to determine if this tabbed pane should be permanently present or not.
protected static void notifyListeners(java.awt.Component comp)
          Helper method to report listeners that a component has been removed.
 void paintChildren(java.awt.Graphics g)
          This method overrides the default method in the parent class.
static void removeListener(DnDTabListener listener)
          Remove a listener to be notified from this tab.
 void removeTab(java.awt.Component componentRemoved)
          Remove a tab (or component) from this DnDTabbedPane.
 void setDockCue(DnDTabbedPane.Location cue)
          This method must be used to set/clear the current docking cue associated with this DndTabPane.
 void setPermanent(boolean perm)
          This method should be used to set if a tabbed pane should be permanent or not.
static javax.swing.JSplitPane setSplitWindow(java.awt.Container parent, DnDTabbedPane.Location location, java.awt.Component window1, java.awt.Component window2, int prefWidth, int prefHeight, java.awt.Dimension area)
          This is a utility method that is used by both DnDTabbedPane and DnDTabPos to create a JSplitPane containing two components organized in a specific manner to occupy a given preferred width/height depending on the type of orientation.
 
Methods inherited from class javax.swing.JTabbedPane
add, add, add, add, add, addChangeListener, addTab, addTab, addTab, createChangeListener, fireStateChanged, getAccessibleContext, getBackgroundAt, getBoundsAt, getChangeListeners, getComponentAt, getDisabledIconAt, getDisplayedMnemonicIndexAt, getForegroundAt, getIconAt, getMnemonicAt, getModel, getSelectedComponent, getSelectedIndex, getTabComponentAt, getTabCount, getTabLayoutPolicy, getTabPlacement, getTabRunCount, getTitleAt, getToolTipText, getToolTipTextAt, getUI, getUIClassID, indexAtLocation, indexOfComponent, indexOfTab, indexOfTab, indexOfTabComponent, insertTab, isEnabledAt, paramString, remove, remove, removeAll, removeChangeListener, removeTabAt, setBackgroundAt, setComponentAt, setDisabledIconAt, setDisplayedMnemonicIndexAt, setEnabledAt, setForegroundAt, setIconAt, setMnemonicAt, setModel, setSelectedComponent, setSelectedIndex, setTabComponentAt, setTabLayoutPolicy, setTabPlacement, setTitleAt, setToolTipTextAt, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
A generated serial version ID.

See Also:
Constant Field Values

EDGE_PANEL_SIZE

private static final double EDGE_PANEL_SIZE
This constant determines the default size that is used for panels that are docked to the edges (top, left, bottom, right) of a given DnDTabPanel. Setting this value to 0.5 will cause the panels to be split 50/50.

See Also:
Constant Field Values

permanent

private boolean permanent
A boolean variable that indicates if this tab is permanent and should not be deleted even if it is empty. This flag is set via call to setPermanent() method. This value is used by the TabDnDHanlder to decide if this tab should be removed when empty or not. It access's this property via the isPermanent() method.


dockCue

private DnDTabbedPane.Location dockCue
This instance variable is used to track if this DndTabbedPane should paint a outline on itself to indicate where a tab being dragged will be docked with respect to this window. This outline provides a visual cue to the user as to where a tab being dragged will end up. The visual cue is setup by the TabDnDHandler's methods.


listeners

private static final java.util.ArrayList<DnDTabListener> listeners
The list of listeners that have been added for this DnDTabbedPane. The listeners are added via the addListener() method or removed via the removeListener() method.

Note: The list of listeners is static so that all DnDTabbedPane objects, including those created dynamically when the user drags and drops tabs, will use this list of listeners. This is a bit non-standard implementation but appears to be the best given the dynamic nature of creation of DnDTabbedPanes

Constructor Detail

DnDTabbedPane

public DnDTabbedPane()
The default constructor. This constructor creates an empty TabbedPane with a default tab placement of JTabbedPane.TOP. It also creates a new DnD handler for this tabbed pane.

Method Detail

isPermanent

public boolean isPermanent()
This method may be used to determine if this tabbed pane should be permanently present or not. Permanent tabbed panes are not removed by the DnDHandler even if it is empty.

Returns:
Returns true if this tabbed pane is permanent.

setPermanent

public void setPermanent(boolean perm)
This method should be used to set if a tabbed pane should be permanent or not. If the parameter is true then the tabbed pane is set to be permanent for all subsequent DnD operations.

Parameters:
perm - Flag to indicate if this tabbed pane is permanent or not. True value indicates the tab is permanent and should not be removed even if it is empty.

createSplitPane

public DnDTabbedPane createSplitPane(java.lang.String title,
                                     javax.swing.Icon icon,
                                     java.awt.Component c,
                                     DnDTabbedPane.Location location)
This method may be used to manually add components either directly to this tabbed pane or around this tabbed pane.

Parameters:
title - The title to be used for new tab when created.
icon - The icon to be used if any.
c - The actual component to be added.
location - The preferred location around this pane.
Returns:
The newly created DndTabbedPane or this.

createSplitPane

public DnDTabbedPane createSplitPane(java.lang.String title,
                                     javax.swing.Icon icon,
                                     java.awt.Component c,
                                     DnDTabbedPane.Location location,
                                     double gravity)
This method may be used to manually add components either directly to this tabbed pane or around this tabbed pane.

Parameters:
title - The title to be used for new tab when created.
icon - The icon to be used if any.
c - The actual component to be added.
location - The preferred location around this pane.
gravity - The size into which the two panes must be split.
Returns:
The newly created DndTabbedPane or this.

createSplitPane

public DnDTabbedPane createSplitPane(java.lang.String title,
                                     javax.swing.Icon icon,
                                     java.awt.Component c,
                                     DnDTabbedPane.Location location,
                                     double gravity,
                                     int size)
This method may be used to manually add components either directly to this tabbed pane or around this tabbed pane.

Parameters:
title - The title to be used for new tab when created.
icon - The icon to be used if any.
c - The actual component to be added.
location - The preferred location around this pane.
gravity - The ratio of space to be allocated to each window. This value is set for JSplitPane.setResizeWeight
size - The size to be set for the component to be added. If this size is less than the minimum size of the component c, then the minimum size of component c will be used. If the size is negative then a size is not set and the defaults are used.
Returns:
The newly created DndTabbedPane or this.

setSplitWindow

public static javax.swing.JSplitPane setSplitWindow(java.awt.Container parent,
                                                    DnDTabbedPane.Location location,
                                                    java.awt.Component window1,
                                                    java.awt.Component window2,
                                                    int prefWidth,
                                                    int prefHeight,
                                                    java.awt.Dimension area)
This is a utility method that is used by both DnDTabbedPane and DnDTabPos to create a JSplitPane containing two components organized in a specific manner to occupy a given preferred width/height depending on the type of orientation. This method specifically replaces window1 in the parent with a new split pane containing window1 and window2. This method handles both cases where the parent can be JSplitPane or just a regular container. If the parent is JSplitPane this method suitably replaces window1 with the newly created split pane. In the second case, the newly created split pane is just directly added to the parent.

Parameters:
parent - The parent component that contains window1
location - The location to decide where window2 should be placed. This location cannot be CENTER.
window1 - The component to be replaced with a new split window containing window1 and window2.
window2 - The second component to be placed in the newly created split pane.
prefWidth - The preferred width of window1 if the location requires a vertical split.
prefHeight - The preferred height of window1 if the location requires a horizontal split.
area - The allocated area for the tabs so that the area is appropriately split between the two parts.
Returns:
The newly created split window for further customization.

deleteTab

public void deleteTab(java.awt.Component componentRemoved)
Delete (and remove) a given tab component.

Parameters:
componentRemoved -

removeTab

public void removeTab(java.awt.Component componentRemoved)
Remove a tab (or component) from this DnDTabbedPane. When the component is removed, and the pane is empty, then the pane automatically removes itself from its parent.

Parameters:
componentRemoved - The component to be removed from this pane.

notifyListeners

protected static void notifyListeners(java.awt.Component comp)
Helper method to report listeners that a component has been removed. This method is invoked from the removeTab() method after a component has been removed from the tab. This method notifies all registered listeners that the component has been removed.

Parameters:
comp - The component that has been removed.

addListener

public static void addListener(DnDTabListener listener)
Add a listener to be notified when a tab in this panel is deleted.

Note:The listener is not recursively propagated to all associated tabs. However, the listener is inherited by any new DnDTabbedPane that may be created from this pane due to user dragging tabs.

Parameters:
listener - The listener to be added.

removeListener

public static void removeListener(DnDTabListener listener)
Remove a listener to be notified from this tab.

Note: The listener is not recursively removed from all associated tabs.

Parameters:
listener - The listener to be removed from the set of listeners to be notified.

getDockCue

public DnDTabbedPane.Location getDockCue()
This method can be used to determine the current docking cue associated with this DndTabPane. The dock cue is used to draw a rectangle on this tab indicating where a tab will be docked to provide visual cues to the user. This method is currently used only by the TabDnDHandler.

Returns:
The current dock cue set for this tab. If a dock cue is not set, then this method returns null.

setDockCue

public void setDockCue(DnDTabbedPane.Location cue)
This method must be used to set/clear the current docking cue associated with this DndTabPane. The dock cue is used to draw a rectangle on this tab indicating where a tab will be docked to provide visual cues to the user. This method is currently used only by the TabDnDHandler.


paintChildren

public void paintChildren(java.awt.Graphics g)
This method overrides the default method in the parent class. This method first calls the parent's paintChildren() method. After that it checks and draws the cue box if the docCue instance variable is not null.

Overrides:
paintChildren in class javax.swing.JComponent
Parameters:
g - The graphics object to be used for drawing the cue box.