net.xoetrope.swing.docking
Class XDockableHeader

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by net.xoetrope.swing.docking.XDockableHeader
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.SwingConstants

public class XDockableHeader
extends javax.swing.JLabel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.ActionListener

A header like panel that paints a gradient fill and displays a caption. The header also contains a minimize button that initiates docking. The header may also be double clicked to zoom in on the owner XDockingPanel and the header may also be dragged from one docking panel to another.

The colours of the header are controlled with the dockingHeader style and dockingHeader/active for the active tab colours

Copyright: Xoetrope Ltd. (c) 2003-2006
License: see license.txt

$Revision: 1.2 $

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
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
static int BUTTON_SIZE
          The default header button size
static int CLOSE
           
static int MINIMIZE
           
static int NUM_IMAGE_TYPES
           
static int RESTORE
           
static int ZOOM
           
 
Fields inherited from class javax.swing.JLabel
labelFor
 
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
XDockableHeader(XDockable dockable, java.awt.Color[] colors, java.lang.String[] tooltips)
          Creates a new instance of XDockableHeader
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Respond to the 'minimize' button and dock this panel.
static java.awt.Color brightenColor(java.awt.Color color, int percentage)
          Get an brighter version of a color
 java.lang.String clipStringIfNecessary(javax.swing.JComponent c, java.awt.FontMetrics fm, java.lang.String caption, int availTextWidth)
           
 void endDock()
          End the drag and drop operation by removing the drop site preview indicator
 boolean getCanClose()
          Determine if the docking component can close
 boolean getCanDock()
          Determine if the docking component can dock
 boolean getCanDrag()
          Determine if the docking component can be dragged
 boolean getCanMinimize()
          Determine if the docking component can minimize
 boolean getCanZoom()
          Determine if the docking component can be zoomed
 XDockable getDockable()
          Get the dockable object that this header is associated with.
 java.awt.Insets getInsets()
          If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.
 java.awt.Dimension getPreferredSize()
          If the preferredSize has been set to a non-null value just returns it.
 boolean isZoomed()
          Is the panel zoomed?
 void mouseClicked(java.awt.event.MouseEvent e)
          Invoked when the mouse button has been clicked (pressed and released) on a component.
 void mouseDragged(java.awt.event.MouseEvent e)
          Invoked when a mouse button is pressed on a component and then dragged.
 void mouseEntered(java.awt.event.MouseEvent e)
          Invoked when the mouse enters a component.
 void mouseExited(java.awt.event.MouseEvent e)
          Invoked when the mouse exits a component.
 void mouseMoved(java.awt.event.MouseEvent e)
          Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.
 void mousePressed(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been pressed on a component.
 void mouseReleased(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been released on a component.
 void paintComponent(java.awt.Graphics g)
          Paint the component, drawing the background gradient and the active indicator if the header is active/selected
 void setActive(boolean state)
          Mark this header as active or inactive.
protected  void setButtonProperties(javax.swing.JButton headerBtn, int itemId, java.lang.String tooltip, boolean isVisible)
          Configure the header buttons
 void setCanClose(boolean state)
          Control the docking component's ability to close
 void setCanDockClose(boolean state)
          Control the docking component's ability to dock.
 void setCanDrag(boolean state)
          Control the docking component's ability to be dragged and dropped.
 void setCanMinimize(boolean state)
          Control the docking component's ability to minimize
 void setCanZoom(boolean state)
          Control the docking component's ability to be zoomed.
static void setUseGradientHeaders(boolean state)
          Toggle the drawing of gradients in the headers
 void setZoomState(int newState)
          Set the state of the zoome/restore button
 void showDock(javax.swing.JComponent c, java.awt.Container target)
          Adjust the position of the drop area preview during a drag operation
 void zoomPanel()
          Zoom in on this panel, maximizing it so that it consumes the entire dockin apnel
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, 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, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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
add, add, add, add, add, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BUTTON_SIZE

public static final int BUTTON_SIZE
The default header button size

See Also:
Constant Field Values

MINIMIZE

public static final int MINIMIZE
See Also:
Constant Field Values

ZOOM

public static final int ZOOM
See Also:
Constant Field Values

CLOSE

public static final int CLOSE
See Also:
Constant Field Values

RESTORE

public static final int RESTORE
See Also:
Constant Field Values

NUM_IMAGE_TYPES

public static final int NUM_IMAGE_TYPES
See Also:
Constant Field Values
Constructor Detail

XDockableHeader

public XDockableHeader(XDockable dockable,
                       java.awt.Color[] colors,
                       java.lang.String[] tooltips)
Creates a new instance of XDockableHeader

Parameters:
dockable - the dockable object that to which this header contributes.
translator - the translator component or null if the tooltips are not translated
colors - the header colors: background, text color, active background, active text color
tooltips - the tooltip text for the minimize and close buttons
Method Detail

setButtonProperties

protected void setButtonProperties(javax.swing.JButton headerBtn,
                                   int itemId,
                                   java.lang.String tooltip,
                                   boolean isVisible)
Configure the header buttons

Parameters:
headerBtn - the button
itemId - the item index
tooltip - the tooltip text
isVisible - true if the button is visible

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Respond to the 'minimize' button and dock this panel. The panel is 'docked' into the sidebar specified in the constructor. Delegates to the owner XDockingPanel panel to remove the content

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the mouse event

getDockable

public XDockable getDockable()
Get the dockable object that this header is associated with.

Returns:
the managing dockable object

setActive

public void setActive(boolean state)
Mark this header as active or inactive. When active a highligh is shown along with a minimize/dock button


setCanClose

public void setCanClose(boolean state)
Control the docking component's ability to close

Parameters:
state - true to allow closing, false to prevent closing

getCanClose

public boolean getCanClose()
Determine if the docking component can close

Returns:
true if the component can close

setCanMinimize

public void setCanMinimize(boolean state)
Control the docking component's ability to minimize

Parameters:
state - true to allow closing, false to prevent minimizing

getCanMinimize

public boolean getCanMinimize()
Determine if the docking component can minimize

Returns:
true if the component can minimize

setCanDockClose

public void setCanDockClose(boolean state)
Control the docking component's ability to dock. Once the component is minimized it will not be able to dock back into the container if this parameter is false

Parameters:
state - true to allow closing, false to prevent docking

getCanDock

public boolean getCanDock()
Determine if the docking component can dock

Returns:
true if the component can dock

setCanDrag

public void setCanDrag(boolean state)
Control the docking component's ability to be dragged and dropped. if this parameter is false

Parameters:
state - true to allow dragging, false to prevent dragging

getCanDrag

public boolean getCanDrag()
Determine if the docking component can be dragged

Returns:
true if the component can be dragged

setCanZoom

public void setCanZoom(boolean state)
Control the docking component's ability to be zoomed. if this parameter is false

Parameters:
state - true to allow zooming, false to prevent zooming

getCanZoom

public boolean getCanZoom()
Determine if the docking component can be zoomed

Returns:
true if the component can be zoomed

getInsets

public java.awt.Insets getInsets()
If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.

Overrides:
getInsets in class javax.swing.JComponent
Returns:
the value of the insets property
See Also:
JComponent.setBorder(javax.swing.border.Border)

setZoomState

public void setZoomState(int newState)
Set the state of the zoome/restore button

Parameters:
newState - the ZOOM or RESTORE state

zoomPanel

public void zoomPanel()
Zoom in on this panel, maximizing it so that it consumes the entire dockin apnel


isZoomed

public boolean isZoomed()
Is the panel zoomed?

Returns:
true if it is zoomed.

getPreferredSize

public java.awt.Dimension getPreferredSize()
If the preferredSize has been set to a non-null value just returns it. If the UI delegate's getPreferredSize method returns a non null value then return that; otherwise defer to the component's layout manager.

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
the value of the preferredSize property
See Also:
JComponent.setPreferredSize(java.awt.Dimension), ComponentUI

paintComponent

public void paintComponent(java.awt.Graphics g)
Paint the component, drawing the background gradient and the active indicator if the header is active/selected

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the graphics context

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Invoked when a mouse button has been pressed on a component.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Invoked when the mouse button has been clicked (pressed and released) on a component. If a double click has been detected then the outer XCardPanel will swap views to and from the zoom view.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Invoked when the mouse enters a component.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Invoked when the mouse exits a component.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Invoked when a mouse button is pressed on a component and then dragged. MOUSE_DRAGGED events will continue to be delivered to the component where the drag originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the component).

Initiates a drag of the docked panel

Due to platform-dependent Drag&Drop implementations, MOUSE_DRAGGED events may not be delivered during a native Drag&Drop operation.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Invoked when a mouse button has been released on a component.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

showDock

public void showDock(javax.swing.JComponent c,
                     java.awt.Container target)
Adjust the position of the drop area preview during a drag operation

Parameters:
target - the potential drop site

endDock

public void endDock()
End the drag and drop operation by removing the drop site preview indicator


setUseGradientHeaders

public static void setUseGradientHeaders(boolean state)
Toggle the drawing of gradients in the headers

Parameters:
state - false to turn off gradient painting

brightenColor

public static java.awt.Color brightenColor(java.awt.Color color,
                                           int percentage)
Get an brighter version of a color

Parameters:
color - the original color
percentage - the percentage of the original color brightness to return

clipStringIfNecessary

public java.lang.String clipStringIfNecessary(javax.swing.JComponent c,
                                              java.awt.FontMetrics fm,
                                              java.lang.String caption,
                                              int availTextWidth)