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, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
BasicButtonDockTitle, BasicDockTitle, BasicStationTitle, BubbleDockTitle, FlatButtonTitle

public class AbstractDockTitle
extends javax.swing.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
private  class AbstractDockTitle.ItemPanel
          Panel that shows the items.
private  class AbstractDockTitle.Listener
          A listener to the Dockable and the DockActionSource of this title.
private  class AbstractDockTitle.OrientedLabel
          A label which draws some text, and can change the layout of the text between horizontal and vertical.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Nested classes/interfaces inherited from interface bibliothek.gui.dock.title.DockTitle
DockTitle.Orientation
 
Field Summary
private  java.util.List<DockAction> actions
          A list of all actions that are on this title
private  boolean active
          true if this title is currently selected, false otherwise
private  boolean bind
          true if this title is currently binded to a Dockable
private  Dockable dockable
          The Dockable for which this title is shown
private  javax.swing.Icon icon
          The icon which is shown on this title
private  javax.swing.JPanel itemPanel
          A panel that displays the action-buttons of this title
private  java.util.Map<DockAction,BasicTitleViewItem<javax.swing.JComponent>> items
          The buttons of this title, each of them represents one action
private  AbstractDockTitle.OrientedLabel label
          A label for the title-text
private  AbstractDockTitle.Listener listener
          A listener added to the owned Dockable.
private static java.awt.Insets NULL_INSETS
          Insets of the size 0,0,0,0
private  DockTitle.Orientation orientation
          Whether the layout should be horizontal or vertical
private  DockTitleVersion origin
          The creator of this title
private  boolean showMiniButtons
          Tells whether small buttons for each action should be created and shown, or not
private  DockActionSource source
          A list of actions that should be shown on this title
 
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(javax.swing.event.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<javax.swing.JComponent> createItemFor(DockAction action, Dockable dockable)
          Creates a new item for action which will be shown on this title.
 void doLayout()
           
 java.awt.Component getComponent()
          Gets a Component which represents the DockTitle.
 Dockable getDockable()
          Gets the owner of this title.
protected  javax.swing.Icon getIcon()
          Gets the icon of this title.
 java.awt.Rectangle getIconBounds()
          Gets the location and the size of the icon.
protected  java.awt.Insets getInnerInsets()
          Gets the insets that have to be applied between the border and the content of this title.
 java.awt.Dimension getMinimumSize()
           
 DockTitle.Orientation getOrientation()
          Gets the current orientation.
 DockTitleVersion getOrigin()
          Gets the version which was used to create this title.
 java.awt.Point getPopupLocation(java.awt.Point click)
          Tells whether a popup menu should be opened when the user clicks at click with the mouse.
 java.awt.Dimension getPreferredSize()
           
protected  java.lang.String getText()
          Gets the text which is shown on this title.
 boolean isActive()
          Tells whether this title is selected (active) or not.
 boolean isBinded()
          Tells whether this title is binded to a Dockable or not.
protected  void paintBackground(java.awt.Graphics g, javax.swing.JComponent component)
          Paints the whole background of this title.
 void paintComponent(java.awt.Graphics g)
           
 void removeMouseInputListener(javax.swing.event.MouseInputListener listener)
          Removes a listener.
 void setActive(boolean active)
          Sets whether this title should be painted as focused or not.
 void setBackground(java.awt.Color fg)
           
 void setForeground(java.awt.Color fg)
           
protected  void setIcon(javax.swing.Icon icon)
          Sets the icon of this title.
 void setOrientation(DockTitle.Orientation orientation)
          Sets the orientation of this title.
protected  void setText(java.lang.String text)
          Sets the text of this title.
private  java.awt.Insets titleInsets()
           
 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
 

Field Detail

NULL_INSETS

private static final java.awt.Insets NULL_INSETS
Insets of the size 0,0,0,0


dockable

private Dockable dockable
The Dockable for which this title is shown


label

private AbstractDockTitle.OrientedLabel label
A label for the title-text


itemPanel

private javax.swing.JPanel itemPanel
A panel that displays the action-buttons of this title


items

private java.util.Map<DockAction,BasicTitleViewItem<javax.swing.JComponent>> items
The buttons of this title, each of them represents one action


actions

private java.util.List<DockAction> actions
A list of all actions that are on this title


listener

private AbstractDockTitle.Listener listener
A listener added to the owned Dockable. The listener changes the title-text and the icon of this title.


source

private DockActionSource source
A list of actions that should be shown on this title


origin

private DockTitleVersion origin
The creator of this title


active

private boolean active
true if this title is currently selected, false otherwise


bind

private boolean bind
true if this title is currently binded to a Dockable


showMiniButtons

private boolean showMiniButtons
Tells whether small buttons for each action should be created and shown, or not


orientation

private DockTitle.Orientation orientation
Whether the layout should be horizontal or vertical


icon

private javax.swing.Icon icon
The icon which is shown on this title

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(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

getIconBounds

public java.awt.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(java.awt.Graphics g,
                               javax.swing.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(javax.swing.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 javax.swing.Icon getIcon()
Gets the icon of this title.

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

setText

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

Parameters:
text - the text or null

getText

protected java.lang.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(java.awt.Color fg)
Overrides:
setForeground in class javax.swing.JComponent

setBackground

public void setBackground(java.awt.Color fg)
Overrides:
setBackground in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class javax.swing.JComponent

getInnerInsets

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

Returns:
the insets, not null

titleInsets

private java.awt.Insets titleInsets()

doLayout

public void doLayout()
Overrides:
doLayout in class java.awt.Container

getComponent

public java.awt.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(javax.swing.event.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(javax.swing.event.MouseInputListener listener)
Description copied from interface: DockTitle
Removes a listener.

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

getPopupLocation

public java.awt.Point getPopupLocation(java.awt.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 java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

createItemFor

protected BasicTitleViewItem<javax.swing.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

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.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.Dockable.unbind(DockTitle). The DockController will call the unbind-method before the Dockable looses the controller.

Specified by:
unbind in interface DockTitle

isBinded

public boolean isBinded()
Tells whether this title is binded to a Dockable or not.

Returns:
true if the title is binded, false otherwise