public class TLcyAlwaysFitJToolBar extends JToolBar
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.
java.awt.Container
counterparts.
This is required because this java.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 regular add
method, it appears after the
remaining items button. If the addRRI
method is used, it will appear, as expected,
as the last button in the remaining items popup.
JToolBar.AccessibleJToolBar, JToolBar.Separator
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
TLcyAlwaysFitJToolBar()
Creates a new
TLcyAlwaysFitJToolBar , ready to be used. |
TLcyAlwaysFitJToolBar(int aOrientation)
Creates a new
TLcyAlwaysFitJToolBar , ready to be used. |
TLcyAlwaysFitJToolBar(String aName)
Creates a new
TLcyAlwaysFitJToolBar , ready to be used. |
TLcyAlwaysFitJToolBar(String aName,
int aOrientation)
Creates a new
TLcyAlwaysFitJToolBar , ready to be used. |
Modifier and Type | Method and Description |
---|---|
void |
addRRI(Component comp)
Adds the given component to this tool bar, respecting the remaining items pop up.
|
void |
addRRI(Component comp,
int index)
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 |
getComponentCountRRI()
Functionally equivalent to
getComponentsRRI().length . |
Component |
getComponentRRI(int aIndex)
Functionally equivalent to
getComponentsRRI()[aIndex] . |
Component[] |
getComponentsRRI()
Returns an array with all tool bar components.
|
Dimension |
getMaximumSize() |
Dimension |
getMinimumSize() |
protected Point |
getPreferredRemainingItemsPopupLocation(Component aInvoker,
Component aContent)
Fetches the desired location for the top left of the popup containing the remaining items.
|
Dimension |
getPreferredSize() |
ILcdIcon |
getRemainingItemsIcon()
Returns the icon that is used to show the remaining items.
|
void |
invalidate() |
protected boolean |
isRemainingItemsPopupVisible()
Returns
true if the popup is currently on screen. |
void |
removeAllRRI()
Removes all components from this tool bar, respecting the remaining items pop up.
|
void |
removeRRI(Component comp)
Removes the given component 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 |
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() |
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
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
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
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, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public TLcyAlwaysFitJToolBar()
TLcyAlwaysFitJToolBar
, ready to be used.JToolBar.JToolBar()
public TLcyAlwaysFitJToolBar(int aOrientation)
TLcyAlwaysFitJToolBar
, ready to be used.aOrientation
- The orientation of the tool bar. Either HORIZONTAL
or VERTICAL
.JToolBar.JToolBar(int)
public TLcyAlwaysFitJToolBar(String aName)
TLcyAlwaysFitJToolBar
, ready to be used.aName
- The name for the title of the undocked tool bar.JToolBar.JToolBar(String)
public TLcyAlwaysFitJToolBar(String aName, int aOrientation)
TLcyAlwaysFitJToolBar
, ready to be used.aName
- The name for the title of the undocked tool bar.aOrientation
- The orientation of the tool bar. Either HORIZONTAL
or VERTICAL
.JToolBar.JToolBar(String, int)
public ILcdIcon getRemainingItemsIcon()
setRemainingItemsIcon(com.luciad.gui.ILcdIcon)
public void setRemainingItemsIcon(ILcdIcon aIcon)
aIcon
- The icon.public Dimension getMinimumSize()
getMinimumSize
in class JComponent
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
public Dimension getMaximumSize()
getMaximumSize
in class JComponent
public void addRRI(Component comp)
comp
- The component to add.Container.add(java.awt.Component)
public void addRRI(Component comp, int index)
comp
- The component to add.index
- The index for inserting the component.Container.add(java.awt.Component, int)
public void removeRRI(int index)
index
- The index of the component to remove.Container.remove(int)
public void removeRRI(Component comp)
comp
- The component to remove.Container.remove(int)
public void removeAllRRI()
Container.removeAll()
public Component[] getComponentsRRI()
JToolBar
, but also those that are (hidden in) the remaining items popup. It does not
include the button to shows the remaining items.Container.getComponents()
public Component getComponentRRI(int aIndex)
getComponentsRRI()[aIndex]
. See class comment for more info.aIndex
- The index of the component to retrieve. 0 <= aIndex < getComponentCountRRI()Container.getComponent(int)
,
getComponentsRRI()
public int getComponentCountRRI()
getComponentsRRI().length
. See class comment for more info.Container.getComponentCount()
,
getComponentsRRI()
public void invalidate()
invalidate
in class Container
public void setBounds(int x, int y, int width, int height)
protected JComponent createRemainingItemsPopupContent(Component[] aRemainingItems)
JToolBar
, and add the given components to it.aRemainingItems
- The components that should be displayed in the remaining items popup.protected Point getPreferredRemainingItemsPopupLocation(Component aInvoker, Component aContent)
clampRemainingItemsPopupOnScreen
.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.aInvoker.getLocationOnScreen()
plus aInvoker.getHeight()
.protected Point clampRemainingItemsPopupOnScreen(Component aInvoker, Component aContent, Point aPreferredLocation)
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 by
getPreferredRemainingItemsPopupLocation
.aPreferredLocation
can simply be returned.protected boolean isRemainingItemsPopupVisible()
true
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.true
if the popup is currently on screen, false
otherwise.setRemainingItemsPopupVisible(boolean)
protected void setRemainingItemsPopupVisible(boolean aVisible)
aVisible
- true
to make the popup visible, false
to hide it.public static Component createToolBarPanel(Component aComponent)
JComboBox
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 the JComboBox
resolves
this issue.aComponent
- The component to wrap.