bibliothek.gui.dock.title
Class AbstractDockTitle

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by bibliothek.gui.dock.title.AbstractDockTitle
All Implemented Interfaces:
DockTitle, ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
BasicButtonDockTitle, BasicDockTitle, BasicStationTitle, BubbleDockTitle, FlatButtonTitle

public class AbstractDockTitle
extends JPanel
implements DockTitle

An abstract implementation of DockTitle. This title can have an icon, a title-text and some small buttons to display actions. The icon is at the top or left edge, the text in the middle, and the actions at the lower or the right edge of the title. If the orientation of the title is set to vertical, the text will be rotated by 90 degrees.
This title has also an ActionPopup which will appear when the user presses the right mouse-button. The popup shows a list of all actions known to this title.
The whole logic a DockTitle needs is implemented in this class, but subclasses may add graphical features - like a border or another background.
Subclasses may override getInnerInsets() to add a space between border and contents of this title.

Author:
Benjamin Sigg
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Nested classes/interfaces inherited from interface bibliothek.gui.dock.title.DockTitle
DockTitle.Orientation
 
Field Summary
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AbstractDockTitle(Dockable dockable, DockTitleVersion origin)
          Constructs a new title
AbstractDockTitle(Dockable dockable, DockTitleVersion origin, boolean showMiniButtons)
          Standard constructor
 
Method Summary
 void addMouseInputListener(MouseInputListener listener)
          Adds a listener to all Components of this title which are visible and which may be "grabbed" by the mouse.
 void bind()
          Called before the title is displayed.
 void changed(DockTitleEvent event)
          Called if a property (of this title, of the owner or anything else) has changed.
protected  BasicTitleViewItem<JComponent> createItemFor(DockAction action, Dockable dockable)
          Creates a new item for action which will be shown on this title.
 void doLayout()
           
protected  DockActionSource getActionSourceFor(Dockable dockable)
          Gets a list of all actions which will be shown on this title.
 Component getComponent()
          Gets a Component which represents the DockTitle.
 Dockable getDockable()
          Gets the owner of this title.
protected  Icon getIcon()
          Gets the icon of this title.
 Rectangle getIconBounds()
          Gets the location and the size of the icon.
protected  Insets getInnerInsets()
          Gets the insets that have to be applied between the border and the content of this title.
 Dimension getMinimumSize()
           
 DockTitle.Orientation getOrientation()
          Gets the current orientation.
 DockTitleVersion getOrigin()
          Gets the version which was used to create this title.
 Point getPopupLocation(Point click)
          Tells whether a popup menu should be opened when the user clicks at click with the mouse.
 Dimension getPreferredSize()
           
protected  String getText()
          Gets the text which is shown on this title.
 boolean isActive()
          Tells whether this title is selected (active) or not.
 boolean isBound()
          Tells whether this title is bound to a Dockable or not.
protected  void paintBackground(Graphics g, JComponent component)
          Paints the whole background of this title.
 void paintComponent(Graphics g)
           
 void removeMouseInputListener(MouseInputListener listener)
          Removes a listener.
 void setActive(boolean active)
          Sets whether this title should be painted as focused or not.
 void setBackground(Color fg)
           
 void setForeground(Color fg)
           
protected  void setIcon(Icon icon)
          Sets the icon of this title.
 void setOrientation(DockTitle.Orientation orientation)
          Sets the orientation of this title.
protected  void setText(String text)
          Sets the text of this title.
 void unbind()
          The reverse of DockTitle.bind().
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, 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, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, 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, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDockTitle

public AbstractDockTitle(Dockable dockable,
                         DockTitleVersion origin)
Constructs a new title

Parameters:
dockable - the Dockable which is the owner of this title
origin - the version which was used to create this title

AbstractDockTitle

public AbstractDockTitle(Dockable dockable,
                         DockTitleVersion origin,
                         boolean showMiniButtons)
Standard constructor

Parameters:
dockable - The Dockable whose title this will be
origin - The version which was used to create this title
showMiniButtons - true if the actions of the Dockable should be shown, false if they should not be visible
Method Detail

paintComponent

public void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

getIconBounds

public Rectangle getIconBounds()
Gets the location and the size of the icon.

Returns:
the bounds or null if no icon is registered

paintBackground

protected void paintBackground(Graphics g,
                               JComponent component)
Paints the whole background of this title. The default implementation just fills the background with the background color of component.

Parameters:
g - the graphics context used to paint
component - the Component which represents this title

setIcon

protected void setIcon(Icon icon)
Sets the icon of this title. The icon is shown on the top or the left edge.

Parameters:
icon - the icon, can be null

getIcon

protected Icon getIcon()
Gets the icon of this title.

Returns:
the icon or null
See Also:
setIcon(Icon)

setText

protected void setText(String text)
Sets the text of this title. The text either painted horizontally or vertically.

Parameters:
text - the text or null

getText

protected String getText()
Gets the text which is shown on this title.

Returns:
the text

setOrientation

public void setOrientation(DockTitle.Orientation orientation)
Description copied from interface: DockTitle
Sets the orientation of this title. The layout of this title should be influenced by the orientation.

Specified by:
setOrientation in interface DockTitle
Parameters:
orientation - the orientation

getOrientation

public DockTitle.Orientation getOrientation()
Gets the current orientation.

Specified by:
getOrientation in interface DockTitle
Returns:
the orientation
See Also:
setOrientation(bibliothek.gui.dock.title.DockTitle.Orientation)

getOrigin

public DockTitleVersion getOrigin()
Description copied from interface: DockTitle
Gets the version which was used to create this title. If this title was not created through the regular methods, then this method is allowed to return null. However, some features will only work correctly if this value is not null.

Specified by:
getOrigin in interface DockTitle
Returns:
the title-version, might be null

setForeground

public void setForeground(Color fg)
Overrides:
setForeground in class JComponent

setBackground

public void setBackground(Color fg)
Overrides:
setBackground in class JComponent

getMinimumSize

public Dimension getMinimumSize()
Overrides:
getMinimumSize in class JComponent

getInnerInsets

protected Insets getInnerInsets()
Gets the insets that have to be applied between the border and the content of this title.

Returns:
the insets, not null

doLayout

public void doLayout()
Overrides:
doLayout in class Container

getComponent

public Component getComponent()
Description copied from interface: DockTitle
Gets a Component which represents the DockTitle. The Component is displayed aside the owner of this title. This method must always return the same Component.

Specified by:
getComponent in interface DockTitle
Returns:
always the same Component

addMouseInputListener

public void addMouseInputListener(MouseInputListener listener)
Description copied from interface: DockTitle
Adds a listener to all Components of this title which are visible and which may be "grabbed" by the mouse.

Specified by:
addMouseInputListener in interface DockTitle
Parameters:
listener - the new listener

removeMouseInputListener

public void removeMouseInputListener(MouseInputListener listener)
Description copied from interface: DockTitle
Removes a listener.

Specified by:
removeMouseInputListener in interface DockTitle
Parameters:
listener - the listener to remove

getPopupLocation

public Point getPopupLocation(Point click)
Description copied from interface: DockTitle
Tells whether a popup menu should be opened when the user clicks at click with the mouse. If yes, then the top left edge of the popup should be returned, otherwise null should be returned.

Specified by:
getPopupLocation in interface DockTitle
Parameters:
click - the location where the user clicked with the mouse
Returns:
the preferred location of a popup or null if no popup-menu should be opened

getDockable

public Dockable getDockable()
Description copied from interface: DockTitle
Gets the owner of this title.

Specified by:
getDockable in interface DockTitle
Returns:
the owner

setActive

public void setActive(boolean active)
Sets whether this title should be painted as focused or not.

Parameters:
active - true if the Dockable of this title has the focus.

changed

public void changed(DockTitleEvent event)
Description copied from interface: DockTitle
Called if a property (of this title, of the owner or anything else) has changed. The title might change some of its own properties.

Specified by:
changed in interface DockTitle
Parameters:
event - information about the current state

isActive

public boolean isActive()
Description copied from interface: DockTitle
Tells whether this title is selected (active) or not. The title knows its state through the event-object of the method changed.

Specified by:
isActive in interface DockTitle
Returns:
the selection state

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

createItemFor

protected BasicTitleViewItem<JComponent> createItemFor(DockAction action,
                                                       Dockable dockable)
Creates a new item for action which will be shown on this title.

Parameters:
action - The action which will be triggered by the button
dockable - The Dockable which will be affected by the action
Returns:
the new graphical representation of the action

getActionSourceFor

protected DockActionSource getActionSourceFor(Dockable dockable)
Gets a list of all actions which will be shown on this title.

Parameters:
dockable - the owner of the actions
Returns:
the list of actions

bind

public void bind()
Description copied from interface: DockTitle
Called before the title is displayed. The method should connect the title with other objects, like its owner. If the title wants to show some DockActions (see the method DockController.listOffers(Dockable)), then this method should bind them too.
Clients should never call this method directly, they should call Dockable.bind(DockTitle). The DockController will call the bind-method, as soon as the Dockable knows the controller.

Specified by:
bind in interface DockTitle

unbind

public void unbind()
Description copied from interface: DockTitle
The reverse of DockTitle.bind(). The title should remove any connections to other objects and unbind its DockActions.
Clients should never call this method directly, they should call Dockable.unbind(DockTitle). The DockController will call the unbind-method before the Dockable looses the controller.

Specified by:
unbind in interface DockTitle

isBound

public boolean isBound()
Tells whether this title is bound to a Dockable or not.

Returns:
true if the title is bound, false otherwise