public static void renderSurface( Graphics g, Container c, Rectangle rect, boolean toSimulateRollover, boolean hasTopBorder, boolean hasBottomBorder) { CellRendererPane buttonRendererPane = new CellRendererPane(); JButton rendererButton = new JButton(""); rendererButton.getModel().setRollover(toSimulateRollover); buttonRendererPane.setBounds(rect.x, rect.y, rect.width, rect.height); Graphics2D g2d = (Graphics2D) g.create(); g2d.clipRect(rect.x, rect.y, rect.width, rect.height); buttonRendererPane.paintComponent( g2d, rendererButton, c, rect.x - rect.width / 2, rect.y - rect.height / 2, 2 * rect.width, 2 * rect.height, true); g2d.setColor(FlamingoUtilities.getBorderColor()); if (hasTopBorder) { g2d.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y); } if (hasBottomBorder) { g2d.drawLine( rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1); } g2d.dispose(); }
public static Color getBorderColor() { return FlamingoUtilities.getColor( Color.gray, "TextField.inactiveForeground", "Button.disabledText", "ComboBox.disabledForeground"); }
/* * (non-Javadoc) * * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics, * int, int) */ @Override public void paintIcon(Component c, Graphics g, int x, int y) { // check if loading if (this.delegate instanceof AsynchronousLoading) { AsynchronousLoading asyncDelegate = (AsynchronousLoading) this.delegate; // if the delegate is still loading - do nothing if (asyncDelegate.isLoading()) return; } SubstanceColorScheme scheme = SubstanceColorSchemeUtilities.getColorScheme(c, ComponentState.DISABLED_UNSELECTED); HashMapKey key = SubstanceCoreUtilities.getHashKey( this.getIconWidth(), this.getIconHeight(), scheme.getDisplayName()); BufferedImage filtered = this.cachedImages.get(key); if (filtered == null) { BufferedImage offscreen = FlamingoUtilities.getBlankImage(this.getIconWidth(), this.getIconHeight()); Graphics2D g2d = offscreen.createGraphics(); this.delegate.paintIcon(c, g2d, 0, 0); g2d.dispose(); filtered = SubstanceImageCreator.getColorSchemeImage(offscreen, scheme, 0.5f); this.cachedImages.put(key, filtered); } g.drawImage(filtered, x, y, null); }
/* * (non-Javadoc) * * @see * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#getPreferredSize(javax * .swing.JComponent) */ @Override public Dimension getPreferredSize(JComponent c) { AbstractCommandButton button = (AbstractCommandButton) c; SubstanceButtonShaper shaper = SubstanceCoreUtilities.getButtonShaper(button); Dimension superPref = super.getPreferredSize(button); if (superPref == null) return null; if (shaper == null) return superPref; // fix for issue 35 on Flamingo - do not enforce // min size on buttons in the ribbon // Additional fix - buttons with popup action should // not have min size enforced as well // Additional fix - buttons in popup menus and breadcrumb bars should // not have min size enforced if ((button.getDisplayState() == CommandButtonDisplayState.MEDIUM) && (SwingUtilities.getAncestorOfClass(AbstractRibbonBand.class, button) == null) && (SwingUtilities.getAncestorOfClass(JBreadcrumbBar.class, button) == null) && (SwingUtilities.getAncestorOfClass(JCommandPopupMenu.class, button) == null)) { JButton dummy = new JButton(button.getText(), button.getIcon()); Dimension result = shaper.getPreferredSize(dummy, superPref); if (FlamingoUtilities.hasPopupAction(button)) { result.width = superPref.width; } return result; } return superPref; }
private static Image getImage(ResizableIcon icon, int size) { icon.setDimension(new Dimension(size, size)); if (icon instanceof AsynchronousLoading) { AsynchronousLoading async = (AsynchronousLoading) icon; if (async.isLoading()) { final CountDownLatch latch = new CountDownLatch(1); final boolean[] status = new boolean[1]; AsynchronousLoadListener all = new AsynchronousLoadListener() { @Override public void completed(boolean success) { status[0] = success; latch.countDown(); } }; async.addAsynchronousLoadListener(all); try { latch.await(); } catch (InterruptedException ignored) { } async.removeAsynchronousLoadListener(all); if (!status[0]) { return null; } if (async.isLoading()) { return null; } } } Image result = FlamingoUtilities.getBlankImage(size, size); Graphics2D g2d = (Graphics2D) result.getGraphics().create(); icon.paintIcon(null, g2d, 0, 0); g2d.dispose(); return result; }
/* * (non-Javadoc) * * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonUI#paintTaskArea(java.awt. * Graphics , int, int, int, int) */ @Override protected void paintTaskArea(Graphics g, int x, int y, int width, int height) { if (this.ribbon.getTaskCount() == 0) return; Graphics2D g2d = (Graphics2D) g.create(); RibbonTask selectedTask = this.ribbon.getSelectedTask(); JRibbonTaskToggleButton selectedTaskButton = this.taskToggleButtons.get(selectedTask); Rectangle selectedTaskButtonBounds = selectedTaskButton.getBounds(); Point converted = SwingUtilities.convertPoint( selectedTaskButton.getParent(), selectedTaskButtonBounds.getLocation(), this.ribbon); float radius = SubstanceSizeUtils.getClassicButtonCornerRadius( SubstanceSizeUtils.getComponentFontSize(this.ribbon)); float borderDelta = SubstanceSizeUtils.getBorderStrokeWidth() / 2.0f; SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(this.ribbon); float borderThickness = SubstanceSizeUtils.getBorderStrokeWidth(); AbstractRibbonBand band = (selectedTask.getBandCount() == 0) ? null : selectedTask.getBand(0); SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities.getColorScheme( band, ColorSchemeAssociationKind.BORDER, ComponentState.ENABLED); Rectangle taskToggleButtonsViewportBounds = taskToggleButtonsScrollablePanel.getView().getParent().getBounds(); taskToggleButtonsViewportBounds.setLocation( SwingUtilities.convertPoint( taskToggleButtonsScrollablePanel, taskToggleButtonsViewportBounds.getLocation(), this.ribbon)); int startSelectedX = Math.max(converted.x + 1, (int) taskToggleButtonsViewportBounds.getMinX()); startSelectedX = Math.min(startSelectedX, (int) taskToggleButtonsViewportBounds.getMaxX()); int endSelectedX = Math.min( converted.x + selectedTaskButtonBounds.width - 1, (int) taskToggleButtonsViewportBounds.getMaxX()); endSelectedX = Math.max(endSelectedX, (int) taskToggleButtonsViewportBounds.getMinX()); Shape outerContour = RibbonBorderShaper.getRibbonBorderOutline( this.ribbon, x + borderDelta, x + width - borderDelta, startSelectedX - borderThickness, endSelectedX + borderThickness, converted.y + borderDelta, y + borderDelta, y + height - borderDelta, radius); Shape innerContour = RibbonBorderShaper.getRibbonBorderOutline( this.ribbon, x + borderDelta + borderThickness, x + width - borderThickness - borderDelta, startSelectedX - borderThickness, endSelectedX + borderThickness, converted.y + borderDelta + borderThickness, y + borderDelta + borderThickness, y + height - borderThickness - borderDelta, radius); g2d.setColor( SubstanceColorSchemeUtilities.getColorScheme(band, ComponentState.ENABLED) .getBackgroundFillColor()); g2d.clipRect(x, y, width, height + 2); g2d.fill(outerContour); // g2d.setColor(Color.red); // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_ON); // g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, // RenderingHints.VALUE_STROKE_PURE); // g2d.setStroke(new BasicStroke(0.5f)); // g2d.draw(outerContour); // g2d.setColor(Color.blue); // g2d.draw(innerContour); borderPainter.paintBorder( g2d, this.ribbon, width, height + selectedTaskButtonBounds.height + 1, outerContour, innerContour, borderScheme); // check whether the currently selected task is a contextual task RibbonTask selected = selectedTask; RibbonContextualTaskGroup contextualGroup = selected.getContextualGroup(); if (contextualGroup != null) { // paint a small gradient directly below the task area Insets ins = this.ribbon.getInsets(); int topY = ins.top + getTaskbarHeight(); int bottomY = topY + 5; Color hueColor = contextualGroup.getHueColor(); Paint paint = new GradientPaint( 0, topY, FlamingoUtilities.getAlphaColor( hueColor, (int) (255 * RibbonContextualTaskGroup.HUE_ALPHA)), 0, bottomY, FlamingoUtilities.getAlphaColor(hueColor, 0)); g2d.setPaint(paint); g2d.clip(outerContour); g2d.fillRect(0, topY, width, bottomY - topY + 1); } // paint outlines of the contextual task groups // paintContextualTaskGroupsOutlines(g); g2d.dispose(); }
/* * (non-Javadoc) * * @see * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paint(java.awt.Graphics * , javax.swing.JComponent) */ @Override public void paint(Graphics g, JComponent c) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setFont( FlamingoUtilities.getFont(this.commandButton, "Ribbon.font", "Button.font", "Panel.font")); this.layoutInfo = this.layoutManager.getLayoutInfo(this.commandButton, g); commandButton.putClientProperty("icon.bounds", layoutInfo.iconRect); commandButton.putClientProperty("icon", commandButton.getIcon()); if (this.isPaintingBackground()) { this.paintButtonBackground(g2d, new Rectangle(0, 0, c.getWidth(), c.getHeight())); } // decide which command button model should be used to // compute the foreground color of the command button's text boolean useActionAreaForFg = layoutInfo.isTextInActionArea; StateTransitionTracker transitionTrackerForFg = useActionAreaForFg ? this.getActionTransitionTracker() : this.getPopupTransitionTracker(); ModelStateInfo modelStateInfoForFg = transitionTrackerForFg.getModelStateInfo(); ComponentState currStateForFg = modelStateInfoForFg.getCurrModelState(); Color fgColor = this.commandButton.getForeground(); if (fgColor instanceof UIResource) { float buttonAlpha = SubstanceColorSchemeUtilities.getAlpha(this.commandButton, currStateForFg); fgColor = SubstanceTextUtilities.getForegroundColor( this.commandButton, this.commandButton.getText(), modelStateInfoForFg, buttonAlpha); } if (layoutInfo.textLayoutInfoList != null) { for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo : layoutInfo.textLayoutInfoList) { if (mainTextLayoutInfo.text != null) { SubstanceTextUtilities.paintText( g2d, c, mainTextLayoutInfo.textRect, mainTextLayoutInfo.text, -1, g2d.getFont(), fgColor, g2d.getClipBounds()); } } } if (layoutInfo.extraTextLayoutInfoList != null) { Color disabledFgColor = SubstanceColorSchemeUtilities.getColorScheme( this.commandButton, ComponentState.DISABLED_UNSELECTED) .getForegroundColor(); float buttonAlpha = SubstanceColorSchemeUtilities.getAlpha( this.commandButton, ComponentState.DISABLED_UNSELECTED); if (buttonAlpha < 1.0f) { Color bgFillColor = SubstanceColorUtilities.getBackgroundFillColor(this.commandButton); disabledFgColor = SubstanceColorUtilities.getInterpolatedColor(disabledFgColor, bgFillColor, buttonAlpha); } if (currStateForFg.isDisabled()) { disabledFgColor = SubstanceColorUtilities.getInterpolatedColor( disabledFgColor, SubstanceColorUtilities.getBackgroundFillColor(c), 0.5); } for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo : layoutInfo.extraTextLayoutInfoList) { if (extraTextLayoutInfo.text != null) { SubstanceTextUtilities.paintText( g2d, c, extraTextLayoutInfo.textRect, extraTextLayoutInfo.text, -1, g2d.getFont(), disabledFgColor, g2d.getClipBounds()); } } } if (layoutInfo.iconRect != null) { this.paintButtonIcon(g2d, layoutInfo.iconRect); } if (layoutInfo.popupActionRect.getWidth() > 0) { paintPopupActionIcon(g2d, layoutInfo.popupActionRect); } if (this.isPaintingSeparators() && (layoutInfo.separatorArea != null)) { if (layoutInfo.separatorOrientation == CommandButtonSeparatorOrientation.HORIZONTAL) { this.paintButtonHorizontalSeparator(g2d, layoutInfo.separatorArea); } else { this.paintButtonVerticalSeparator(g2d, layoutInfo.separatorArea); } } // g2d.setColor(Color.red); // g2d.draw(layoutInfo.iconRect); // g2d.setColor(Color.blue); // if (layoutInfo.textLayoutInfoList != null) { // for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo : // layoutInfo.textLayoutInfoList) { // if (mainTextLayoutInfo.text != null) { // g2d.draw(mainTextLayoutInfo.textRect); // } // } // } // g2d.setColor(Color.magenta); // if (layoutInfo.extraTextLayoutInfoList != null) { // for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo : // layoutInfo.extraTextLayoutInfoList) { // if (extraTextLayoutInfo.text != null) { // g2d.draw(extraTextLayoutInfo.textRect); // } // } // } // g2d.setColor(Color.green); // g2d.draw(layoutInfo.popupActionRect); g2d.dispose(); }
@Override protected void installComponents() { super.installComponents(); this.mainPanel = createMainPanel(); this.panelLevel1 = new JPanel(); this.panelLevel1.setLayout( new LayoutManager() { @Override public void addLayoutComponent(String name, Component comp) {} @Override public void removeLayoutComponent(Component comp) {} @Override public Dimension preferredLayoutSize(Container parent) { int height = 0; int width = 0; for (int i = 0; i < parent.getComponentCount(); i++) { Dimension pref = parent.getComponent(i).getPreferredSize(); height += pref.height; width = Math.max(width, pref.width); } Insets ins = parent.getInsets(); return new Dimension(width + ins.left + ins.right, height + ins.top + ins.bottom); } @Override public Dimension minimumLayoutSize(Container parent) { return preferredLayoutSize(parent); } @Override public void layoutContainer(Container parent) { Insets ins = parent.getInsets(); int topY = ins.top; for (int i = 0; i < parent.getComponentCount(); i++) { Component comp = parent.getComponent(i); Dimension pref = comp.getPreferredSize(); comp.setBounds(ins.left, topY, parent.getWidth() - ins.left - ins.right, pref.height); topY += pref.height; } } }); final RibbonApplicationMenu ribbonAppMenu = this.applicationMenuPopupPanel.getRibbonAppMenu(); if (ribbonAppMenu != null) { List<List<RibbonApplicationMenuEntryPrimary>> primaryEntries = ribbonAppMenu.getPrimaryEntries(); int primaryGroupCount = primaryEntries.size(); for (int i = 0; i < primaryGroupCount; i++) { for (final RibbonApplicationMenuEntryPrimary menuEntry : primaryEntries.get(i)) { final JCommandMenuButton commandButton = new JCommandMenuButton(menuEntry.getText(), menuEntry.getIcon()); commandButton.setCommandButtonKind(menuEntry.getEntryKind()); commandButton.addActionListener(menuEntry.getMainActionListener()); commandButton.setActionKeyTip(menuEntry.getActionKeyTip()); commandButton.setPopupKeyTip(menuEntry.getPopupKeyTip()); if (menuEntry.getDisabledIcon() != null) { commandButton.setDisabledIcon(menuEntry.getDisabledIcon()); } if (menuEntry.getSecondaryGroupCount() == 0) { // if there are no secondary menu items, register the // application rollover callback to populate the // second level panel commandButton.addRolloverActionListener( new RolloverActionListener() { @Override public void actionPerformed(ActionEvent e) { // System.out.println("Rollover action"); PrimaryRolloverCallback callback = menuEntry.getRolloverCallback(); if (callback != null) { callback.menuEntryActivated(panelLevel2); } else { // default callback? PrimaryRolloverCallback defaultCallback = ribbonAppMenu.getDefaultCallback(); if (defaultCallback != null) { defaultCallback.menuEntryActivated(panelLevel2); } else { panelLevel2.removeAll(); panelLevel2.revalidate(); panelLevel2.repaint(); } } panelLevel2.applyComponentOrientation( applicationMenuPopupPanel.getComponentOrientation()); } }); } else { // register a core callback to populate the second level // panel with secondary menu items final PrimaryRolloverCallback coreCallback = new PrimaryRolloverCallback() { @Override public void menuEntryActivated(JPanel targetPanel) { targetPanel.removeAll(); targetPanel.setLayout(new BorderLayout()); JRibbonApplicationMenuPopupPanelSecondary secondary = new JRibbonApplicationMenuPopupPanelSecondary(menuEntry) { @Override public void removeNotify() { super.removeNotify(); commandButton.getPopupModel().setPopupShowing(false); } }; secondary.applyComponentOrientation( applicationMenuPopupPanel.getComponentOrientation()); targetPanel.add(secondary, BorderLayout.CENTER); } }; commandButton.addRolloverActionListener( new RolloverActionListener() { @Override public void actionPerformed(ActionEvent e) { coreCallback.menuEntryActivated(panelLevel2); // emulate showing the popup so the // button remains "selected" commandButton.getPopupModel().setPopupShowing(true); } }); } commandButton.setDisplayState(MENU_TILE_LEVEL_1); commandButton.setHorizontalAlignment(SwingUtilities.LEADING); commandButton.setPopupOrientationKind(CommandButtonPopupOrientationKind.SIDEWARD); commandButton.setEnabled(menuEntry.isEnabled()); this.panelLevel1.add(commandButton); } if (i < (primaryGroupCount - 1)) { this.panelLevel1.add(new JPopupMenu.Separator()); } } } mainPanel.add(this.panelLevel1, BorderLayout.LINE_START); this.panelLevel2 = new JPanel(); this.panelLevel2.setBorder( new Border() { @Override public Insets getBorderInsets(Component c) { boolean ltr = c.getComponentOrientation().isLeftToRight(); return new Insets(0, ltr ? 1 : 0, 0, ltr ? 0 : 1); } @Override public boolean isBorderOpaque() { return true; } @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g.setColor(FlamingoUtilities.getColor(Color.gray, "Label.disabledForeground")); boolean ltr = c.getComponentOrientation().isLeftToRight(); int xToPaint = ltr ? x : x + width - 1; g.drawLine(xToPaint, y, xToPaint, y + height); } }); this.panelLevel2.setPreferredSize( new Dimension( 30 * FlamingoUtilities.getFont( this.panelLevel1, "Ribbon.font", "Button.font", "Panel.font") .getSize() - 30, 10)); mainPanel.add(this.panelLevel2, BorderLayout.CENTER); if (ribbonAppMenu != null) { if (ribbonAppMenu.getDefaultCallback() != null) { ribbonAppMenu.getDefaultCallback().menuEntryActivated(this.panelLevel2); } } this.applicationMenuPopupPanel.add(mainPanel, BorderLayout.CENTER); this.footerPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING)) { @Override protected void paintComponent(Graphics g) { FlamingoUtilities.renderSurface( g, footerPanel, new Rectangle(0, 0, footerPanel.getWidth(), footerPanel.getHeight()), false, false, false); } }; if (ribbonAppMenu != null) { for (RibbonApplicationMenuEntryFooter footerEntry : ribbonAppMenu.getFooterEntries()) { JCommandButton commandFooterButton = new JCommandButton(footerEntry.getText(), footerEntry.getIcon()); if (footerEntry.getDisabledIcon() != null) { commandFooterButton.setDisabledIcon(footerEntry.getDisabledIcon()); } commandFooterButton.setCommandButtonKind(CommandButtonKind.ACTION_ONLY); commandFooterButton.addActionListener(footerEntry.getMainActionListener()); commandFooterButton.setDisplayState(CommandButtonDisplayState.MEDIUM); commandFooterButton.setFlat(false); commandFooterButton.setEnabled(footerEntry.isEnabled()); this.footerPanel.add(commandFooterButton); } } this.applicationMenuPopupPanel.add(this.footerPanel, BorderLayout.SOUTH); this.applicationMenuPopupPanel.setBorder( new Border() { @Override public Insets getBorderInsets(Component c) { return new Insets(20, 2, 2, 2); } @Override public boolean isBorderOpaque() { return true; } @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g.setColor(FlamingoUtilities.getColor(Color.gray, "Label.disabledForeground")); g.drawRect(x, y, width - 1, height - 1); g.setColor( FlamingoUtilities.getColor(Color.gray, "Label.disabledForeground") .brighter() .brighter()); g.drawRect(x + 1, y + 1, width - 3, height - 3); FlamingoUtilities.renderSurface( g, applicationMenuPopupPanel, new Rectangle(x + 2, y + 2, width - 4, 24), false, false, false); // draw the application menu button JCommandButton button = applicationMenuPopupPanel.getAppMenuButton(); JRibbonApplicationMenuButton rendererButton = new JRibbonApplicationMenuButton( ((RibbonProvider) applicationMenuPopupPanel.getAppMenuButton()).getRibbon()); rendererButton.setPopupKeyTip(button.getPopupKeyTip()); rendererButton.setIcon(button.getIcon()); rendererButton.getPopupModel().setRollover(false); rendererButton.getPopupModel().setPressed(true); rendererButton.getPopupModel().setArmed(true); rendererButton.getPopupModel().setPopupShowing(true); CellRendererPane buttonRendererPane = new CellRendererPane(); Point buttonLoc = button.getLocationOnScreen(); Point panelLoc = c.getLocationOnScreen(); buttonRendererPane.setBounds( panelLoc.x - buttonLoc.x, panelLoc.y - buttonLoc.y, button.getWidth(), button.getHeight()); buttonRendererPane.paintComponent( g, rendererButton, (Container) c, -panelLoc.x + buttonLoc.x, -panelLoc.y + buttonLoc.y, button.getWidth(), button.getHeight(), true); } }); }
private void setMainAppIcon(ResizableIcon icon) { this.appIcon = icon; FlamingoUtilities.updateRibbonFrameIconImages(this); }
/** Initializes the layout and the ribbon. */ private void initRibbon() { this.setLayout(new RibbonFrameLayout()); this.ribbon = new JRibbon(this); this.add(this.ribbon, BorderLayout.NORTH); // this.keyTipManager = new KeyTipManager(this); Toolkit.getDefaultToolkit() .addAWTEventListener( new AWTEventListener() { private boolean prevAltModif = false; @Override public void eventDispatched(AWTEvent event) { Object src = event.getSource(); if (src instanceof Component) { Component c = (Component) src; if ((c == JRibbonFrame.this) || (SwingUtilities.getWindowAncestor(c) == JRibbonFrame.this)) { if (event instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent) event; // System.out.println(keyEvent.getID() + ":" // + keyEvent.getKeyCode()); switch (keyEvent.getID()) { case KeyEvent.KEY_PRESSED: // if (keyEvent.getKeyCode() == // KeyEvent.VK_ESCAPE) { // keyTipManager.showPreviousChain(); // } break; case KeyEvent.KEY_RELEASED: boolean wasAltModif = prevAltModif; prevAltModif = keyEvent.getModifiersEx() == InputEvent.ALT_DOWN_MASK; if (wasAltModif && keyEvent.getKeyCode() == KeyEvent.VK_ALT) break; char keyChar = keyEvent.getKeyChar(); if (Character.isLetter(keyChar) || Character.isDigit(keyChar)) { // System.out.println("Will handle key press " // + keyChar); KeyTipManager.defaultManager().handleKeyPress(keyChar); } if ((keyEvent.getKeyCode() == KeyEvent.VK_ALT) || (keyEvent.getKeyCode() == KeyEvent.VK_F10)) { if (keyEvent.getModifiers() != 0 || keyEvent.getModifiersEx() != 0) break; boolean hadPopups = !PopupPanelManager.defaultManager().getShownPath().isEmpty(); PopupPanelManager.defaultManager().hidePopups(null); if (hadPopups || KeyTipManager.defaultManager().isShowingKeyTips()) { KeyTipManager.defaultManager().hideAllKeyTips(); } else { KeyTipManager.defaultManager().showRootKeyTipChain(JRibbonFrame.this); } } if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE) { // System.out.println("In KTM"); KeyTipManager.defaultManager().showPreviousChain(); } break; } } if (event instanceof MouseEvent) { MouseEvent mouseEvent = (MouseEvent) event; switch (mouseEvent.getID()) { case MouseEvent.MOUSE_CLICKED: case MouseEvent.MOUSE_DRAGGED: case MouseEvent.MOUSE_PRESSED: case MouseEvent.MOUSE_RELEASED: KeyTipManager.defaultManager().hideAllKeyTips(); } } } } } }, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK); final KeyTipLayer keyTipLayer = new KeyTipLayer(); JRootPane rootPane = this.getRootPane(); JLayeredPane layeredPane = rootPane.getLayeredPane(); final LayoutManager currLM = rootPane.getLayout(); rootPane.setLayout( new LayoutManager() { @Override public void addLayoutComponent(String name, Component comp) { currLM.addLayoutComponent(name, comp); } @Override public void layoutContainer(Container parent) { currLM.layoutContainer(parent); JRibbonFrame ribbonFrame = JRibbonFrame.this; if (ribbonFrame.getRootPane().getWindowDecorationStyle() != JRootPane.NONE) keyTipLayer.setBounds(ribbonFrame.getRootPane().getBounds()); else keyTipLayer.setBounds(ribbonFrame.getRootPane().getContentPane().getBounds()); } @Override public Dimension minimumLayoutSize(Container parent) { return currLM.minimumLayoutSize(parent); } @Override public Dimension preferredLayoutSize(Container parent) { return currLM.preferredLayoutSize(parent); } @Override public void removeLayoutComponent(Component comp) { currLM.removeLayoutComponent(comp); } }); // layeredPane.setLayout(new OverlayLayout(layeredPane)); layeredPane.add(keyTipLayer, (Integer) (JLayeredPane.DEFAULT_LAYER + 60)); this.addWindowListener( new WindowAdapter() { @Override public void windowDeactivated(WindowEvent e) { // hide all key tips on window deactivation KeyTipManager keyTipManager = KeyTipManager.defaultManager(); if (keyTipManager.isShowingKeyTips()) { keyTipManager.hideAllKeyTips(); } } }); KeyTipManager.defaultManager() .addKeyTipListener( new KeyTipManager.KeyTipListener() { @Override public void keyTipsHidden(KeyTipEvent event) { if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(false); } @Override public void keyTipsShown(KeyTipEvent event) { if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(true); } }); ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); JPopupMenu.setDefaultLightWeightPopupEnabled(false); super.setIconImages(Arrays.asList(FlamingoUtilities.getBlankImage(16, 16))); }