Class JRibbon
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- org.pushingpixels.flamingo.api.ribbon.JRibbon
-
public class JRibbon extends javax.swing.JComponentThe ribbon component.The ribbon has the following major parts:
- Ribbon tasks added with
addTask(RibbonTask) - Contextual ribbon task groups added with
addContextualTaskGroup(RibbonContextualTaskGroup) - Application menu content set by
setApplicationMenuCommand(RibbonApplicationMenuCommandButtonProjection) - Taskbar panel populated by
addTaskbarCommand(Command, AbstractPopupMenuPresentationModel),addTaskbarGalleryDropdown(RibbonGalleryProjection)andaddTaskbarComponent(ComponentProjection) - Anchored content set by
addAnchoredCommand(CommandButtonProjection)
While multiple ribbon tasks can be added to the ribbon, only one is visible at any given time. This task is called the selected task. Tasks can be switched with the task buttons placed along the top part of the ribbon. Once a task has been added to the ribbon, it cannot be removed.
The contextual ribbon task groups allow showing and hiding ribbon tasks based on the current selection in the application. For example, Word only shows the table tasks when a table is selected in the document. By default, tasks belonging to the groups added by
addContextualTaskGroup(RibbonContextualTaskGroup)are not visible. To show the tasks belonging to the specific group, callsetVisible(RibbonContextualTaskGroup, boolean)API. Note that you can have multiple task groups visible at the same time.The application menu button is a rectangular button shown in the top left corner of the ribbon. If the
setApplicationMenuCommand(RibbonApplicationMenuCommandButtonProjection)is not called, or called with thenullvalue, the application menu button is not shown, and ribbon task buttons are shifted to the left.The taskbar panel allows showing controls that are visible no matter what ribbon task is selected. To add a taskbar component use the
addTaskbarCommand(Command, AbstractPopupMenuPresentationModel),addTaskbarGalleryDropdown(RibbonGalleryProjection)andaddTaskbarComponent(ComponentProjection)APIs. The taskbar panel lives in the top-left corner of the application frame.The ribbon can be minimized in one of the following ways:
- Calling
setMinimized(boolean)withtrue. - User double-clicking on a task button.
- User pressing
Meta+Alt+Rkey combination on a Mac machine orCtrl+F1key combination on a non-Mac machine.
A minimized ribbon shows the application menu button, taskbar panel, task buttons and anchored contet, but not the ribbon bands of the selected task. Clicking a task button shows the ribbon bands of that task in a popup without shifting the application content down.
- See Also:
- Serialized Form
- Ribbon tasks added with
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceJRibbon.OnShowContextualMenuListenerstatic interfaceJRibbon.OnTaskSelectionChangeListener-
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
Fields Modifier and Type Field Description static java.lang.StringuiClassIDThe UI class ID string.-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Constructor Description JRibbon()Creates a new empty ribbon.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAnchoredCommand(CommandButtonProjection projection)Adds the specified ribbon command projection to the trailing edge of the task toggle strip of this ribbon.voidaddChangeListener(javax.swing.event.ChangeListener l)Adds the specified change listener to track changes to this ribbon.voidaddContextualTaskGroup(RibbonContextualTaskGroup group)Adds the specified contextual task group to this ribbon.voidaddOnTaskSelectionChangedListener(JRibbon.OnTaskSelectionChangeListener listener)voidaddTask(RibbonTask task)Adds the specified task to this ribbon.voidaddTaskbarAppMenuLink(Command appMenuCommand)voidaddTaskbarCommand(Command command, AbstractPopupMenuPresentationModel popupMenuPresentationModel)Adds the specified command to the taskbar area of this ribbon.voidaddTaskbarComponent(ComponentProjection<? extends javax.swing.JComponent,? extends ComponentContentModel> projection)voidaddTaskbarGalleryDropdown(RibbonGalleryProjection galleryProjection)voidclearTaskbar()Removes all taskbar content from this ribbon.protected voidfireStateChanged()Notifies all registered listeners that the state of this ribbon has changed.java.util.List<CommandButtonProjection>getAnchoredCommands()Returns the anchored commands for this ribbon.RibbonApplicationMenuCommandButtonProjectiongetApplicationMenuCommandProjection()org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.RibbonApplicationMenuProjectiongetApplicationMenuProjection()Returns the application menu of this ribbon.RibbonContextualTaskGroupgetContextualTaskGroup(int index)Retrieves contextual task group at specified index.intgetContextualTaskGroupCount()Returns the number of contextual task groups inthisribbon.JRibbon.OnShowContextualMenuListenergetOnShowContextualMenuListener()JRibbonFramegetRibbonFrame()Returns the ribbon frame that hosts this ribbon.RibbonTaskgetSelectedTask()Returns the currently selected task.RibbonTaskgetTask(int index)Retrieves the regular task at specified index.java.util.List<java.awt.Component>getTaskbarComponents()RibbonTaskbarKeyTipPolicygetTaskbarKeyTipPolicy()intgetTaskCount()Returns the number of regular tasks inthisribbon.org.pushingpixels.flamingo.internal.ui.ribbon.RibbonUIgetUI()Returns the UI delegate for this component.java.lang.StringgetUIClassID()booleanisMinimized()Returns the indication whether this ribbon is minimized.booleanisShowingInTaskbar(Command command)booleanisShowingInTaskbar(RibbonGalleryContentModel galleryContentModel)booleanisShowingInTaskbar(ComponentContentModel componentContentModel)booleanisVisible(RibbonContextualTaskGroup group)Returns the visibility of ribbon tasks in the specified contextual task group.voidremoveAnchoredCommand(CommandButtonProjection projection)Removes the specified ribbon command from the trailing edge of the task toggle strip of this ribbon.voidremoveChangeListener(javax.swing.event.ChangeListener l)Removes the specified change listener from tracking changes to this ribbon.voidremoveOnTaskSelectionChangedListener(JRibbon.OnTaskSelectionChangeListener listener)voidremoveTaskbarCommand(Command command)voidremoveTaskbarComponent(ComponentContentModel componentContentModel)voidremoveTaskbarGallery(RibbonGalleryContentModel galleryContentModel)voidsetApplicationMenuCommand(RibbonApplicationMenuCommandButtonProjection applicationMenuCommandProjection)Sets the application menu command for this ribbon.voidsetMinimized(boolean isMinimized)Changes the minimized state of this ribbon.voidsetOnShowContextualMenuListener(JRibbon.OnShowContextualMenuListener onShowContextualMenuListener)voidsetSelectedTask(RibbonTask task)Selects the specified task.voidsetTaskbarKeyTipPolicy(RibbonTaskbarKeyTipPolicy taskbarKeyTipPolicy)voidsetVisible(boolean flag)voidsetVisible(RibbonContextualTaskGroup group, boolean isVisible)Sets the visibility of ribbon tasks in the specified contextual task group.voidupdateUI()-
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, getAccessibleContext, 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, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Methods inherited from class java.awt.Container
add, add, add, add, add, 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, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
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, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, 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, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, unregisterKeyboardAction, update
-
-
-
-
Field Detail
-
uiClassID
public static final java.lang.String uiClassID
The UI class ID string.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JRibbon
public JRibbon()
Creates a new empty ribbon. Applications are highly encouraged to useJRibbonFrameand access the ribbon withJRibbonFrame.getRibbon()API.
-
-
Method Detail
-
setTaskbarKeyTipPolicy
public void setTaskbarKeyTipPolicy(RibbonTaskbarKeyTipPolicy taskbarKeyTipPolicy)
-
getTaskbarKeyTipPolicy
public RibbonTaskbarKeyTipPolicy getTaskbarKeyTipPolicy()
-
addTaskbarCommand
public void addTaskbarCommand(Command command, AbstractPopupMenuPresentationModel popupMenuPresentationModel)
Adds the specified command to the taskbar area of this ribbon.- Parameters:
command- The taskbar command to add.popupMenuPresentationModel- Optional presentation model for the popup menu of the command. This must be set ifCommand.getSecondaryContentModel()has non-nullCommandMenuContentModel.getPanelContentModel(). Otherwise it can be null.- See Also:
clearTaskbar()
-
isShowingInTaskbar
public boolean isShowingInTaskbar(Command command)
-
removeTaskbarCommand
public void removeTaskbarCommand(Command command)
-
addTaskbarAppMenuLink
public void addTaskbarAppMenuLink(Command appMenuCommand)
-
addTaskbarComponent
public void addTaskbarComponent(ComponentProjection<? extends javax.swing.JComponent,? extends ComponentContentModel> projection)
-
isShowingInTaskbar
public boolean isShowingInTaskbar(ComponentContentModel componentContentModel)
-
removeTaskbarComponent
public void removeTaskbarComponent(ComponentContentModel componentContentModel)
-
addTaskbarGalleryDropdown
public void addTaskbarGalleryDropdown(RibbonGalleryProjection galleryProjection)
-
isShowingInTaskbar
public boolean isShowingInTaskbar(RibbonGalleryContentModel galleryContentModel)
-
removeTaskbarGallery
public void removeTaskbarGallery(RibbonGalleryContentModel galleryContentModel)
-
clearTaskbar
public void clearTaskbar()
Removes all taskbar content from this ribbon.
-
addTask
public void addTask(RibbonTask task)
Adds the specified task to this ribbon.- Parameters:
task- The ribbon task to add.- See Also:
addContextualTaskGroup(RibbonContextualTaskGroup),getTaskCount(),getTask(int)
-
addAnchoredCommand
public void addAnchoredCommand(CommandButtonProjection projection)
Adds the specified ribbon command projection to the trailing edge of the task toggle strip of this ribbon.- Parameters:
projection- Command projection to add.- See Also:
getAnchoredCommands(),removeAnchoredCommand(CommandButtonProjection)
-
removeAnchoredCommand
public void removeAnchoredCommand(CommandButtonProjection projection)
Removes the specified ribbon command from the trailing edge of the task toggle strip of this ribbon.- Parameters:
projection- Command projection to remove.- See Also:
getAnchoredCommands(),addAnchoredCommand(CommandButtonProjection)
-
getAnchoredCommands
public java.util.List<CommandButtonProjection> getAnchoredCommands()
Returns the anchored commands for this ribbon.- Returns:
- This ribbon's anchored commands.
- See Also:
addAnchoredCommand(CommandButtonProjection),removeAnchoredCommand(CommandButtonProjection)
-
addContextualTaskGroup
public void addContextualTaskGroup(RibbonContextualTaskGroup group)
Adds the specified contextual task group to this ribbon.- Parameters:
group- Task group to add.- See Also:
addTask(RibbonTask),setVisible(RibbonContextualTaskGroup, boolean),isVisible(RibbonContextualTaskGroup)
-
getTaskCount
public int getTaskCount()
Returns the number of regular tasks inthisribbon.- Returns:
- Number of regular tasks in
thisribbon. - See Also:
getTask(int),addTask(RibbonTask)
-
getTask
public RibbonTask getTask(int index)
Retrieves the regular task at specified index.- Parameters:
index- Task index.- Returns:
- Task that matches the specified index.
- See Also:
getTaskCount(),addTask(RibbonTask)
-
getContextualTaskGroupCount
public int getContextualTaskGroupCount()
Returns the number of contextual task groups inthisribbon.- Returns:
- Number of contextual task groups in
thisribbon. - See Also:
addContextualTaskGroup(RibbonContextualTaskGroup),getContextualTaskGroup(int)
-
getContextualTaskGroup
public RibbonContextualTaskGroup getContextualTaskGroup(int index)
Retrieves contextual task group at specified index.- Parameters:
index- Group index.- Returns:
- Group that matches the specified index.
- See Also:
addContextualTaskGroup(RibbonContextualTaskGroup),getContextualTaskGroupCount()
-
setSelectedTask
public void setSelectedTask(RibbonTask task)
Selects the specified task. The task can be either regular (added withaddTask(RibbonTask)) or a task in a visible contextual task group (added withaddContextualTaskGroup(RibbonContextualTaskGroup). Fires aselectedTaskproperty change event.- Parameters:
task- Task to select.- Throws:
java.lang.IllegalArgumentException- If the specified task is not in the ribbon or not visible.- See Also:
getSelectedTask()
-
getSelectedTask
public RibbonTask getSelectedTask()
Returns the currently selected task.- Returns:
- The currently selected task.
- See Also:
setSelectedTask(RibbonTask)
-
updateUI
public void updateUI()
- Overrides:
updateUIin classjavax.swing.JComponent
-
getUI
public org.pushingpixels.flamingo.internal.ui.ribbon.RibbonUI getUI()
Returns the UI delegate for this component.- Overrides:
getUIin classjavax.swing.JComponent- Returns:
- a
RibbonUIobject - See Also:
JComponent.setUI(javax.swing.plaf.ComponentUI)
-
getUIClassID
public java.lang.String getUIClassID()
- Overrides:
getUIClassIDin classjavax.swing.JComponent
-
getTaskbarComponents
public java.util.List<java.awt.Component> getTaskbarComponents()
-
addChangeListener
public void addChangeListener(javax.swing.event.ChangeListener l)
Adds the specified change listener to track changes to this ribbon.- Parameters:
l- Change listener to add.- See Also:
removeChangeListener(ChangeListener)
-
removeChangeListener
public void removeChangeListener(javax.swing.event.ChangeListener l)
Removes the specified change listener from tracking changes to this ribbon.- Parameters:
l- Change listener to remove.- See Also:
addChangeListener(ChangeListener)
-
fireStateChanged
protected void fireStateChanged()
Notifies all registered listeners that the state of this ribbon has changed.
-
setVisible
public void setVisible(RibbonContextualTaskGroup group, boolean isVisible)
Sets the visibility of ribbon tasks in the specified contextual task group. Visibility of all ribbon tasks in the specified group is affected. Note that the ribbon can show ribbon tasks of multiple groups at the same time.- Parameters:
group- Contextual task group.isVisible- Iftrue, all ribbon tasks in the specified group will be visible. Iffalse, all ribbon tasks in the specified group will be hidden.- See Also:
isVisible(RibbonContextualTaskGroup)
-
isVisible
public boolean isVisible(RibbonContextualTaskGroup group)
Returns the visibility of ribbon tasks in the specified contextual task group.- Parameters:
group- Contextual task group.- Returns:
trueif the ribbon tasks in the specified group are visible,falseotherwise.
-
setApplicationMenuCommand
public void setApplicationMenuCommand(RibbonApplicationMenuCommandButtonProjection applicationMenuCommandProjection)
Sets the application menu command for this ribbon. Ifnullis passed, the application menu button is hidden.- Parameters:
applicationMenuCommandProjection- The new application menu command. Can benull.- See Also:
getApplicationMenuProjection()
-
getApplicationMenuCommandProjection
public RibbonApplicationMenuCommandButtonProjection getApplicationMenuCommandProjection()
-
getApplicationMenuProjection
public org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.RibbonApplicationMenuProjection getApplicationMenuProjection()
Returns the application menu of this ribbon.- Returns:
- The application menu of this ribbon.
- See Also:
setApplicationMenuCommand(RibbonApplicationMenuCommandButtonProjection)
-
isMinimized
public boolean isMinimized()
Returns the indication whether this ribbon is minimized.- Returns:
trueif this ribbon is minimized,falseotherwise.- See Also:
setMinimized(boolean)
-
setMinimized
public void setMinimized(boolean isMinimized)
Changes the minimized state of this ribbon. Fires aminimizedproperty change event.- Parameters:
isMinimized- iftrue, this ribbon becomes minimized, otherwise it is unminimized.
-
getRibbonFrame
public JRibbonFrame getRibbonFrame()
Returns the ribbon frame that hosts this ribbon. The result can benull.- Returns:
- The ribbon frame that hosts this ribbon.
-
setVisible
public void setVisible(boolean flag)
- Overrides:
setVisiblein classjavax.swing.JComponent
-
setOnShowContextualMenuListener
public void setOnShowContextualMenuListener(JRibbon.OnShowContextualMenuListener onShowContextualMenuListener)
-
getOnShowContextualMenuListener
public JRibbon.OnShowContextualMenuListener getOnShowContextualMenuListener()
-
addOnTaskSelectionChangedListener
public void addOnTaskSelectionChangedListener(JRibbon.OnTaskSelectionChangeListener listener)
-
removeOnTaskSelectionChangedListener
public void removeOnTaskSelectionChangedListener(JRibbon.OnTaskSelectionChangeListener listener)
-
-