Package com.luciad.lucy.gui
Class TLcyAlwaysFitJToolBar
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JToolBar
com.luciad.lucy.gui.TLcyAlwaysFitJToolBar
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,SwingConstants
Extension of
JToolBar
that nicely handles the case when not enough space is available to display all
tool bar items. If not all tool bar items fit, a button is added that shows a popup with the remaining
items.
Limitations
- Layout constraints of added components are ignored. This is usually no problem because tool bar buttons don't have any.
- Components which show a popup are not supported in the remaining items popup window. They will appear in the remaining items popup, but their popup menu cannot be shown. This is a limitation of the JDK, which does not support to have popups inside popups.
- When manipulating the tool bar items when the tool bar is already visible, the methods suffixed with 'RRI'
(Respect Remaining Items) need to be used instead of their
java.awt.Container
counterparts. This is required because thisjava.awt.Container
automatically removes components from itself if they don't fit. Also, if needed, a button to show the remaining items popup is automatically added. As a result, manipulating the children might behave different from what you expect. For example, if 5 buttons are added, it might happen that only one button is actually part of the tool bar, followed by a button to show the remaining items. The 4 other buttons reside in the remaining items popup. If a 6th button is now added using the regularadd
method, it appears after the remaining items button. If theaddRRI
method is used, it will appear, as expected, as the last button in the remaining items popup.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JToolBar
JToolBar.AccessibleJToolBar, JToolBar.Separator
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
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
-
Constructor Summary
ConstructorDescriptionCreates a newTLcyAlwaysFitJToolBar
, ready to be used.TLcyAlwaysFitJToolBar
(int aOrientation) Creates a newTLcyAlwaysFitJToolBar
, ready to be used.TLcyAlwaysFitJToolBar
(String aName) Creates a newTLcyAlwaysFitJToolBar
, ready to be used.TLcyAlwaysFitJToolBar
(String aName, int aOrientation) Creates a newTLcyAlwaysFitJToolBar
, ready to be used. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given component to this tool bar, respecting the remaining items pop up.void
Adds the given component to this tool bar, respecting the remaining items pop up.protected Point
clampRemainingItemsPopupOnScreen
(Component aInvoker, Component aContent, Point aPreferredLocation) Clamps the popup on screen.protected JComponent
createRemainingItemsPopupContent
(Component[] aRemainingItems) Builds the content for the remaining items popup.static Component
createToolBarPanel
(Component aComponent) Utility method to wrap a given component so that it plays nice on a tool bar.void
doLayout()
int
Functionally equivalent togetComponentsRRI().length
.getComponentRRI
(int aIndex) Functionally equivalent togetComponentsRRI()[aIndex]
.Returns an array with all tool bar components.protected Point
getPreferredRemainingItemsPopupLocation
(Component aInvoker, Component aContent) Fetches the desired location for the top left of the popup containing the remaining items.Returns the icon that is used to show the remaining items.void
protected boolean
Returnstrue
if the popup is currently on screen.void
Removes all components from this tool bar, respecting the remaining items pop up.void
removeRRI
(int index) Removes the given component from this tool bar, respecting the remaining items pop up.void
Removes the given component from this tool bar, respecting the remaining items pop up.void
setBounds
(int x, int y, int width, int height) void
setRemainingItemsIcon
(ILcdIcon aIcon) Sets the icon that is used to show the remaining items.protected void
setRemainingItemsPopupVisible
(boolean aVisible) Sets the visibility of the remaining items popup.void
updateUI()
Methods inherited from class javax.swing.JToolBar
add, addImpl, addSeparator, addSeparator, createActionChangeListener, createActionComponent, getAccessibleContext, getComponentAtIndex, getComponentIndex, getMargin, getOrientation, getUI, getUIClassID, isBorderPainted, isFloatable, isRollover, paintBorder, paramString, setBorderPainted, setFloatable, setLayout, setMargin, setOrientation, setRollover, setUI
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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, 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, 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, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
TLcyAlwaysFitJToolBar
public TLcyAlwaysFitJToolBar()Creates a newTLcyAlwaysFitJToolBar
, ready to be used.- See Also:
-
TLcyAlwaysFitJToolBar
public TLcyAlwaysFitJToolBar(int aOrientation) Creates a newTLcyAlwaysFitJToolBar
, ready to be used.- Parameters:
aOrientation
- The orientation of the tool bar. EitherHORIZONTAL
orVERTICAL
.- See Also:
-
TLcyAlwaysFitJToolBar
Creates a newTLcyAlwaysFitJToolBar
, ready to be used.- Parameters:
aName
- The name for the title of the undocked tool bar.- See Also:
-
TLcyAlwaysFitJToolBar
Creates a newTLcyAlwaysFitJToolBar
, ready to be used.- Parameters:
aName
- The name for the title of the undocked tool bar.aOrientation
- The orientation of the tool bar. EitherHORIZONTAL
orVERTICAL
.- See Also:
-
-
Method Details
-
updateUI
public void updateUI() -
getRemainingItemsIcon
Returns the icon that is used to show the remaining items.- Returns:
- the icon that is used to show the remaining items.
- See Also:
-
setRemainingItemsIcon
Sets the icon that is used to show the remaining items.- Parameters:
aIcon
- The icon.
-
getMinimumSize
- Overrides:
getMinimumSize
in classJComponent
-
getPreferredSize
- Overrides:
getPreferredSize
in classJComponent
-
getMaximumSize
- Overrides:
getMaximumSize
in classJComponent
-
addRRI
Adds the given component to this tool bar, respecting the remaining items pop up. See class comment for more info.- Parameters:
comp
- The component to add.- See Also:
-
addRRI
Adds the given component to this tool bar, respecting the remaining items pop up. See class comment for more info.- Parameters:
comp
- The component to add.index
- The index for inserting the component.- See Also:
-
removeRRI
public void removeRRI(int index) Removes the given component from this tool bar, respecting the remaining items pop up. See class comment for more info.- Parameters:
index
- The index of the component to remove.- See Also:
-
removeRRI
Removes the given component from this tool bar, respecting the remaining items pop up. See class comment for more info.- Parameters:
comp
- The component to remove.- See Also:
-
removeAllRRI
public void removeAllRRI()Removes all components from this tool bar, respecting the remaining items pop up. See class comment for more info.- See Also:
-
getComponentsRRI
Returns an array with all tool bar components. This includes the components currently part of thisJToolBar
, but also those that are (hidden in) the remaining items popup. It does not include the button to shows the remaining items.- Returns:
- An array with all visible and hidden components.
- See Also:
-
getComponentRRI
Functionally equivalent togetComponentsRRI()[aIndex]
. See class comment for more info.- Parameters:
aIndex
- The index of the component to retrieve. 0 <= aIndex < getComponentCountRRI()- Returns:
- The component at the given index.
- See Also:
-
getComponentCountRRI
public int getComponentCountRRI()Functionally equivalent togetComponentsRRI().length
. See class comment for more info.- Returns:
- The amount of child components, including those in the remaining items popup.
- See Also:
-
invalidate
public void invalidate()- Overrides:
invalidate
in classContainer
-
setBounds
public void setBounds(int x, int y, int width, int height) -
doLayout
public void doLayout() -
createRemainingItemsPopupContent
Builds the content for the remaining items popup. An implementation could for example be to create a newJToolBar
, and add the given components to it.- Parameters:
aRemainingItems
- The components that should be displayed in the remaining items popup.- Returns:
- The content for the remaining items popup.
-
getPreferredRemainingItemsPopupLocation
Fetches the desired location for the top left of the popup containing the remaining items. This preferred location might not be respected to avoid that the popup partially falls off screen (seeclampRemainingItemsPopupOnScreen
.- Parameters:
aInvoker
- The component that triggered displaying the popup, typically the 'arrow' button.aContent
- The content that needs to be displayed in the popup. Can for example be used to retrieve the preferred size.- Returns:
- The desired location for the popup, in screen coordinate space. For example
aInvoker.getLocationOnScreen()
plusaInvoker.getHeight()
.
-
clampRemainingItemsPopupOnScreen
protected Point clampRemainingItemsPopupOnScreen(Component aInvoker, Component aContent, Point aPreferredLocation) Clamps the popup on screen. This is useful to avoid that it is only partially visible, or to prevent that it is spread over multiple screens.- Parameters:
aInvoker
- The component that triggered displaying the popup, typically the 'arrow' button.aContent
- The content that needs to be displayed in the popup. Can for example be used to retrieve the preferred size.aPreferredLocation
- The preferred location in screen coordinate space, as provided bygetPreferredRemainingItemsPopupLocation
.- Returns:
- The actual location in screen coordinate space, that respects screen boundaries. If clamping the popup
on screen is not desired,
aPreferredLocation
can simply be returned.
-
isRemainingItemsPopupVisible
protected boolean isRemainingItemsPopupVisible()Returnstrue
if the popup is currently on screen. This method is protected as there is normally no need to call it from outside this class as the popup is automatically shown and hidden.- Returns:
true
if the popup is currently on screen,false
otherwise.- See Also:
-
setRemainingItemsPopupVisible
protected void setRemainingItemsPopupVisible(boolean aVisible) Sets the visibility of the remaining items popup. This method is protected as there is normally no need to call it from outside this class as the popup is automatically shown and hidden.- Parameters:
aVisible
-true
to make the popup visible,false
to hide it.
-
createToolBarPanel
Utility method to wrap a given component so that it plays nice on a tool bar. For example, if you add aJComboBox
on a tool bar, you'll notice that it receives all extra available space, making the combo much larger as desired. Using this method to add a wrapper panel around theJComboBox
resolves this issue.- Parameters:
aComponent
- The component to wrap.- Returns:
- The component, wrapped in a panel, to improve tool bar layout.
-