DESY ACOP Beans Home

com.cosylab.gui.components
Class TitledPanel

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 com.cosylab.gui.components.TitledPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class TitledPanel
extends javax.swing.JPanel

TitledPanel is an extension of the Swing's JPanel, which contains a PanelTitleBar at the top. The rest of the panel's space is occupied by the content read-write property, which is an arbitrary Component. By default, the content property is set to null.
The title bar shows an Icon which is passed as a parameter to the constructor, and a String read-write property named title. Toolbar buttons can be added to the panel using the addTitleBarButton() method, passing a JButton as a parameter. The buttons added to the panel may be associated with an arbitrary action, which will not be affected by the TitledPanel.Note that buttons will not retain their original color, border or size after being added to the TitledPanel.
Width of the title bar (and thus also the size of the toolbar buttons) and the space between the panel's border and its content can both be determined when constructing the panel.

Version:
$id$
Author:
Miha Kadunc
See Also:
PanelTitleBar, JPanel, Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  PanelTitleBar bar
           
 
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
TitledPanel()
          Creates a new TitledPanel object.
TitledPanel(java.lang.String name, java.lang.String title, javax.swing.Icon icon)
          Constructor for TitledPanel.
TitledPanel(java.lang.String name, java.lang.String title, javax.swing.Icon icon, int titleBarHeight)
          Constructor for TitledPanel.
 
Method Summary
 java.awt.Component add(java.awt.Component comp)
           
 java.awt.Component add(java.awt.Component comp, int index)
           
 void add(java.awt.Component comp, java.lang.Object constraints)
           
 void add(java.awt.Component comp, java.lang.Object constraints, int index)
           
 java.awt.Component add(java.lang.String name, java.awt.Component comp)
           
 void addNotify()
           
 void addTitleBarAction(javax.swing.Action action)
          Adds a button activating the specified action to this panel's title bar.
 void addTitleBarAction(int index, javax.swing.Action action)
          Adds a button activating the specified action to this panel's title bar at specified index.
 void addTitleBarButton(javax.swing.AbstractButton button)
          Adds a JButton to this panel's title bar.
 void addTitleBarButton(int index, javax.swing.AbstractButton button)
          Adds a button to this panel's title bar at specified index.
 boolean containsTitleBarAction(javax.swing.AbstractButton button)
           
 boolean containsTitleBarAction(javax.swing.Action action)
           
 java.awt.Container getContentPane()
          Gets the content Container.
 javax.swing.Icon getIcon()
          Return this panel's title bar icon.
 java.lang.String getTitle()
          Gets the title.
 java.awt.Color getTitleBackgroundLeft()
          Returns the left background color of this panel's title bar.
 java.awt.Color getTitleBackgroundRight()
          Gets the right background color of this panel's title bar.
protected  GradientLabel getTitleBarLabel()
           
 boolean isTitleBarVisible()
          Returns true if title bar is visible or false otherwise.
 void remove(java.awt.Component comp)
           
 void removeTitleBarAction(javax.swing.Action action)
          Removes the button associated with the specified action from this panel's title bar.
 void removeTitleBarButton(javax.swing.AbstractButton button)
          Removes a button from this panel's title bar.
 void setContentPane(java.awt.Container content)
          Sets the content.
 void setFont(java.awt.Font font)
           
 void setIcon(javax.swing.Icon icon)
          Sets the icon of this panel's title bar.
 void setTitle(java.lang.String title)
          Sets this panel's title, which is diaplayed in the title bar.
 void setTitleBackground(java.awt.Color left, java.awt.Color right)
          Sets the background colors of this panel's title bar.
 void setTitleBackgroundLeft(java.awt.Color left)
          Sets the background colors of this panel's title bar.
 void setTitleBackgroundRight(java.awt.Color right)
          Sets the background colors of this panel's title bar.
 void setTitleBarVisible(boolean visible)
          Sets the visibility of the title bar.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, 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, 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

bar

protected PanelTitleBar bar
Constructor Detail

TitledPanel

public TitledPanel(java.lang.String name,
                   java.lang.String title,
                   javax.swing.Icon icon)
Constructor for TitledPanel. The name parameter is not visible in the panel, so it can be set to null. Title and Icon will be used for constructing the PanelTitleBar. The title bar will be created with the default width of 24 pixels and there will be no space between the border of the panel and its contents (titlebar and content component)

Parameters:
name - The name of the panel.
title - The title which will be displayed in the title bar.
icon - The icon to be rendered in the upper-left corner of the panel.

TitledPanel

public TitledPanel()
Creates a new TitledPanel object.


TitledPanel

public TitledPanel(java.lang.String name,
                   java.lang.String title,
                   javax.swing.Icon icon,
                   int titleBarHeight)
Constructor for TitledPanel. The name parameter is not visible in the panel, so it can be set to null. Title and Icon will be used for constructing the PanelTitleBar.

Parameters:
name - The name of the panel.
title - The title which will be displayed in the title bar.
icon - The icon to be rendered in the upper-left corner of the panel.
titleBarHeight - Height of the title bar rendered in the top area of the panel.
Method Detail

addTitleBarButton

public void addTitleBarButton(javax.swing.AbstractButton button)
Adds a JButton to this panel's title bar. Note that all the user has to provide is the button's icon and an associated action. All the behaviour needed for the button to fit into the title bar will be added to the button by the PanelTitleBar. The button will be resized to a square with the same size as the height of the bar. Its background color will be changed to that of the bar and the border will be removed. Some mouse and keyboard sensitivity will be added to the button.

Parameters:
button - The button to be added to the title bar.

addTitleBarButton

public void addTitleBarButton(int index,
                              javax.swing.AbstractButton button)
Adds a button to this panel's title bar at specified index.

Parameters:
index - location of added button
button -

removeTitleBarButton

public void removeTitleBarButton(javax.swing.AbstractButton button)
Removes a button from this panel's title bar.

Parameters:
button -

addTitleBarAction

public void addTitleBarAction(javax.swing.Action action)
Adds a button activating the specified action to this panel's title bar.

Parameters:
action -

addTitleBarAction

public void addTitleBarAction(int index,
                              javax.swing.Action action)
Adds a button activating the specified action to this panel's title bar at specified index.

Parameters:
index - location of added action
action -

containsTitleBarAction

public boolean containsTitleBarAction(javax.swing.Action action)
See Also:
PanelTitleBar.containsAction(Action)

containsTitleBarAction

public boolean containsTitleBarAction(javax.swing.AbstractButton button)
See Also:
PanelTitleBar.containsButton(AbstractButton)

removeTitleBarAction

public void removeTitleBarAction(javax.swing.Action action)
Removes the button associated with the specified action from this panel's title bar.

Parameters:
action -

setTitle

public void setTitle(java.lang.String title)
Sets this panel's title, which is diaplayed in the title bar. If the title is too long for the space which is available to the panel, it is trimmed and the missing parts are replaced by ...

Parameters:
title - The text that should be displayed as the title.

getTitle

public java.lang.String getTitle()
Gets the title.

Returns:
Returns the String displayed as the title.
See Also:
getTitle()

getTitleBackgroundLeft

public java.awt.Color getTitleBackgroundLeft()
Returns the left background color of this panel's title bar.

Returns:
Color

getTitleBackgroundRight

public java.awt.Color getTitleBackgroundRight()
Gets the right background color of this panel's title bar.

Returns:
Color

setTitleBackground

public void setTitleBackground(java.awt.Color left,
                               java.awt.Color right)
Sets the background colors of this panel's title bar.

Parameters:
left -
right -

setTitleBackgroundLeft

public void setTitleBackgroundLeft(java.awt.Color left)
Sets the background colors of this panel's title bar.

Parameters:
left -

setTitleBackgroundRight

public void setTitleBackgroundRight(java.awt.Color right)
Sets the background colors of this panel's title bar.

Parameters:
right -

getIcon

public javax.swing.Icon getIcon()
Return this panel's title bar icon.

Returns:
Icon

setIcon

public void setIcon(javax.swing.Icon icon)
Sets the icon of this panel's title bar.

Parameters:
icon -

getContentPane

public java.awt.Container getContentPane()
Gets the content Container.

Returns:
Returns the Component contained in this panel as the content pane.

setContentPane

public void setContentPane(java.awt.Container content)
Sets the content. The content is added to the panel below the title bar, covering all the available area.

Parameters:
content - The content to set

getTitleBarLabel

protected GradientLabel getTitleBarLabel()

setTitleBarVisible

public void setTitleBarVisible(boolean visible)
Sets the visibility of the title bar.

Parameters:
visible - true if title bar is visible

isTitleBarVisible

public boolean isTitleBarVisible()
Returns true if title bar is visible or false otherwise.

Returns:
true if title bar is visible

add

public java.awt.Component add(java.awt.Component comp,
                              int index)
Overrides:
add in class java.awt.Container

add

public void add(java.awt.Component comp,
                java.lang.Object constraints,
                int index)
Overrides:
add in class java.awt.Container

add

public void add(java.awt.Component comp,
                java.lang.Object constraints)
Overrides:
add in class java.awt.Container

add

public java.awt.Component add(java.awt.Component comp)
Overrides:
add in class java.awt.Container

add

public java.awt.Component add(java.lang.String name,
                              java.awt.Component comp)
Overrides:
add in class java.awt.Container

setFont

public void setFont(java.awt.Font font)
Overrides:
setFont in class javax.swing.JComponent

addNotify

public void addNotify()
Overrides:
addNotify in class javax.swing.JComponent

remove

public void remove(java.awt.Component comp)
Overrides:
remove in class java.awt.Container


Copyright © 2010. All Rights Reserved.