diff --git a/component/src/main/java/org/pushingpixels/radiance/component/api/common/JCommandButton.java b/component/src/main/java/org/pushingpixels/radiance/component/api/common/JCommandButton.java index fafe709c9..c10a4900a 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/api/common/JCommandButton.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/api/common/JCommandButton.java @@ -76,14 +76,6 @@ public class JCommandButton extends JComponent implements RichTooltipManager.Wit @SuppressWarnings("rawtypes") private BaseCommandButtonPresentationModel commandPresentation; - /** - * Associated icon. - * - * @see #setIcon(RadianceIcon) - * @see #getIcon() - */ - private RadianceIcon icon; - /** * The button text. * @@ -491,9 +483,6 @@ public JCommandButton(BaseCommandButtonProjection, this.setText(command.getText()); this.setExtraText(command.getExtraText()); - this.setIcon((command.getIconFactory() != null) - ? command.getIconFactory().createNewIcon() - : null); RadianceThemingCortex.ComponentScope.setIconFilterStrategies(this, commandPresentation.getActiveIconFilterStrategy(), commandPresentation.getEnabledIconFilterStrategy(), @@ -624,6 +613,15 @@ public CommandButtonUI getUI() { return this.projection; } + public BaseCommand getContentModel() { + return this.projection.getContentModel(); + } + + public BaseCommandButtonPresentationModel> getPresentationModel() { + return this.projection.getPresentationModel(); + } + /** * Sets new presentation state for this button. Fires a * presentationState property change event. @@ -638,38 +636,6 @@ public void setPresentationState(CommandButtonPresentationState state) { this.firePropertyChange("presentationState", old, this.presentationState); } - /** - * Returns the associated icon. - * - * @return The associated icon. - * @see #setIcon(RadianceIcon) - */ - public RadianceIcon getIcon() { - return icon; - } - - /** - * Sets new icon for this button. Fires an icon property change - * event. - * - * @param defaultIcon New default icon for this button. - * @see #getIcon() - */ - public void setIcon(RadianceIcon defaultIcon) { - RadianceIcon oldValue = this.icon; - this.icon = defaultIcon; - - firePropertyChange("icon", oldValue, defaultIcon); - if (defaultIcon != oldValue) { - if (defaultIcon == null || oldValue == null - || defaultIcon.getIconWidth() != oldValue.getIconWidth() - || defaultIcon.getIconHeight() != oldValue.getIconHeight()) { - revalidate(); - } - repaint(); - } - } - /** * Return the current presentation state of this button. * diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/theming/common/ui/RadianceCommandButtonUI.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/theming/common/ui/RadianceCommandButtonUI.java index 1228b700c..58072a35c 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/theming/common/ui/RadianceCommandButtonUI.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/theming/common/ui/RadianceCommandButtonUI.java @@ -274,17 +274,16 @@ public void fireRolloverActionPerformed(ActionEvent e) { * Tracks possible usage of glowing icon. */ private void trackGlowingIcon() { - RadianceIcon currIcon = this.commandButton.getIcon(); - if (currIcon instanceof GlowingRadianceIcon) + if (this.icon instanceof GlowingRadianceIcon) return; - if (currIcon == null) + if (this.icon == null) return; boolean isPopupOnly = (this.commandButton.getCommandButtonKind() == JCommandButton.CommandButtonKind.POPUP_ONLY); StateTransitionTracker tracker = isPopupOnly ? this.radianceVisualStateTracker.getPopupStateTransitionTracker() : this.radianceVisualStateTracker.getActionStateTransitionTracker(); - this.glowingIcon = new GlowingRadianceIcon(currIcon, tracker.getIconGlowTracker()); + this.glowingIcon = new GlowingRadianceIcon(this.icon, tracker.getIconGlowTracker()); } private void paintButtonBackground(Graphics graphics) { @@ -303,15 +302,14 @@ private void paintButtonBackground(Graphics graphics) { } private void paintButtonIconRegular(Graphics g, Rectangle iconRect, Color textColor) { - Icon icon = this.commandButton.getIcon(); - if ((iconRect == null) || (icon == null) || (iconRect.width == 0) + if ((iconRect == null) || (this.icon == null) || (iconRect.width == 0) || (iconRect.height == 0)) { return; } Graphics2D g2d = (Graphics2D) g.create(); - GhostPaintingUtils.paintGhostIcon(g2d, this.commandButton, icon, iconRect); + GhostPaintingUtils.paintGhostIcon(g2d, this.commandButton, this.icon, iconRect); g2d.setComposite(WidgetUtilities.getAlphaComposite(this.commandButton, g)); StateTransitionTracker tracker = this.radianceVisualStateTracker @@ -322,7 +320,7 @@ private void paintButtonIconRegular(Graphics g, Rectangle iconRect, Color textCo model = this.commandButton.getPopupModel(); } this.commandButtonBackgroundDelegate.paintCommandButtonIcon(g2d, iconRect, - this.commandButton, icon, this.glowingIcon, model, tracker, textColor); + this.commandButton, this.icon, this.glowingIcon, model, tracker, textColor); g2d.dispose(); } @@ -369,8 +367,7 @@ protected void paintButtonIcon(Graphics g, Rectangle iconRect, Color textColor) } this.paintButtonIconRegular(g, iconRect, textColor); // does it actually have an icon? - Icon iconToPaint = this.commandButton.getIcon(); - if (showSelectionAroundIcon && (iconToPaint == null)) { + if (showSelectionAroundIcon && (this.icon == null)) { // draw a checkmark Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, @@ -456,7 +453,7 @@ protected boolean isPaintingSeparators() { if (super.isPaintingSeparators()) { return true; } - boolean hasIcon = (this.commandButton.getIcon() != null); + boolean hasIcon = (this.icon != null); return this.commandButton.hasFocus() || (hasIcon && (this.overallStateTransitionTracker .getFacetStrength(ComponentStateFacet.ROLLOVER) > 0.0f)); } @@ -668,10 +665,9 @@ private void paintPopupActionIcon(Graphics g, Rectangle popupActionRect) { @Override public Dimension getPreferredSize(JComponent c) { - JCommandButton button = (JCommandButton) c; - RadianceButtonShaper shaper = RadianceCoreUtilities.getButtonShaper(button); + RadianceButtonShaper shaper = RadianceCoreUtilities.getButtonShaper(this.commandButton); - Dimension superPref = super.getPreferredSize(button); + Dimension superPref = super.getPreferredSize(this.commandButton); if (superPref == null) return null; @@ -683,13 +679,13 @@ public Dimension getPreferredSize(JComponent c) { // not have min size enforced as well // Additional fix - buttons in popup menus and breadcrumb bars should // not have min size enforced - if ((button.getPresentationState() == CommandButtonPresentationState.MEDIUM) - && (SwingUtilities.getAncestorOfClass(JRibbon.class, button) == null) - && (SwingUtilities.getAncestorOfClass(JBreadcrumbBar.class, button) == null) - && (SwingUtilities.getAncestorOfClass(AbstractPopupMenuPanel.class, button) == null)) { - JButton forSizing = new JButton(button.getText(), button.getIcon()); + if ((this.commandButton.getPresentationState() == CommandButtonPresentationState.MEDIUM) + && (SwingUtilities.getAncestorOfClass(JRibbon.class, this.commandButton) == null) + && (SwingUtilities.getAncestorOfClass(JBreadcrumbBar.class, this.commandButton) == null) + && (SwingUtilities.getAncestorOfClass(AbstractPopupMenuPanel.class, this.commandButton) == null)) { + JButton forSizing = new JButton(this.commandButton.getContentModel().getText(), this.icon); Dimension result = shaper.getPreferredSize(forSizing, superPref); - if (ComponentUtilities.hasPopupAction(button)) { + if (ComponentUtilities.hasPopupAction(this.commandButton)) { result.width = superPref.width; } return result; diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/theming/ribbon/ui/RadianceRibbonTaskToggleButtonUI.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/theming/ribbon/ui/RadianceRibbonTaskToggleButtonUI.java index a55d4b730..7e09d0a43 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/theming/ribbon/ui/RadianceRibbonTaskToggleButtonUI.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/theming/ribbon/ui/RadianceRibbonTaskToggleButtonUI.java @@ -314,11 +314,9 @@ private static Color getForegroundColor(JCommandButton button, @Override public Dimension getPreferredSize(JComponent c) { - JCommandButton button = (JCommandButton) c; - - JButton forSizing = new JButton(button.getText(), button.getIcon()); + JButton forSizing = new JButton(this.commandButton.getText(), this.icon); Dimension result = forSizing.getUI().getPreferredSize(forSizing); - Insets borderInsets = button.getBorder().getBorderInsets(button); + Insets borderInsets = this.commandButton.getBorder().getBorderInsets(this.commandButton); result.width += (borderInsets.left + borderInsets.right); result.height += (borderInsets.top + borderInsets.bottom); return result; diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/BasicCommandButtonUI.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/BasicCommandButtonUI.java index d84470823..8ec88e4e7 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/BasicCommandButtonUI.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/BasicCommandButtonUI.java @@ -94,6 +94,8 @@ public abstract class BasicCommandButtonUI extends CommandButtonUI { protected boolean isInnerFocusOnAction; + protected RadianceIcon icon; + /** * Client property to mark the command button to not dispose the popups on activation. * @@ -164,6 +166,9 @@ protected void installDefaults() { this.commandButton.setFont(RadianceThemingCortex.GlobalScope.getFontPolicy() .getFontSet().getControlFont()); } + + RadianceIcon.Factory iconFactory = this.commandButton.getContentModel().getIconFactory(); + this.icon = (iconFactory != null) ? iconFactory.createNewIcon() : null; this.syncIconDimension(); // Support for focus traversal inside command buttons that have action area @@ -226,9 +231,8 @@ private void updateBorder() { protected void installComponents() { this.updatePopupActionIcon(); - RadianceIcon buttonIcon = this.commandButton.getIcon(); - if (buttonIcon instanceof AsynchronousLoading) { - ((AsynchronousLoading) buttonIcon).addAsynchronousLoadListener((boolean success) -> { + if (this.icon instanceof AsynchronousLoading) { + ((AsynchronousLoading) this.icon).addAsynchronousLoadListener((boolean success) -> { if (success && (commandButton != null)) commandButton.repaint(); }); @@ -333,7 +337,8 @@ protected void installListeners() { } if ("iconFactory".equals(propertyChangeEvent.getPropertyName())) { RadianceIcon.Factory factory = (RadianceIcon.Factory) propertyChangeEvent.getNewValue(); - commandButton.setIcon((factory != null) ? factory.createNewIcon() : null); + icon = (factory != null) ? factory.createNewIcon() : null; + commandButton.repaint(); } if ("isToggleSelected".equals(propertyChangeEvent.getPropertyName())) { commandButton.getActionModel().setSelected((Boolean) propertyChangeEvent.getNewValue()); @@ -513,7 +518,7 @@ private void updateIconDimension() { Dimension dimension = this.commandButton.getIconDimension(); if (dimension != null) { - this.commandButton.getIcon().setDimension(dimension); + this.icon.setDimension(dimension); this.commandButton.setPresentationState(CommandButtonPresentationState.BIG_FIT_TO_ICON); this.commandButton.invalidate(); @@ -677,8 +682,7 @@ public void processPopupAction() { } private void syncIconDimension() { - RadianceIcon icon = this.commandButton.getIcon(); - if (icon == null) { + if (this.icon == null) { return; } @@ -695,19 +699,19 @@ private void syncIconDimension() { int iconWidth = (preferredIconSize != null) ? preferredIconSize.width : -1; if (iconWidth < 0) { - iconWidth = this.commandButton.getIcon().getIconWidth(); + iconWidth = this.icon.getIconWidth(); } int iconHeight = (preferredIconSize != null) ? preferredIconSize.height : -1; if (iconHeight < 0) { - iconHeight = this.commandButton.getIcon().getIconHeight(); + iconHeight = this.icon.getIconHeight(); } - if ((icon.getIconWidth() == iconWidth) && (icon.getIconHeight() == iconHeight)) { + if ((this.icon.getIconWidth() == iconWidth) && (this.icon.getIconHeight() == iconHeight)) { return; } Dimension newDim = new Dimension(iconWidth, iconHeight); - icon.setDimension(newDim); + this.icon.setDimension(newDim); } private void syncActionPreview(BaseCommand command, Command.CommandActionPreview actionPreview) { diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerBig.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerBig.java index 387bc8573..0621ada7c 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerBig.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerBig.java @@ -64,13 +64,13 @@ public Dimension getPreferredIconSize(JCommandButton commandButton) { } protected int getCurrentIconWidth(JCommandButton commandButton) { - return (commandButton.getIcon() != null) + return (commandButton.getContentModel().getIconFactory() != null) ? this.getPreferredIconSize(commandButton).width : 0; } protected int getCurrentIconHeight(JCommandButton commandButton) { - return (commandButton.getIcon() != null) + return (commandButton.getContentModel().getIconFactory() != null) ? this.getPreferredIconSize(commandButton).height : 0; } @@ -91,7 +91,7 @@ public Dimension getPreferredSize(JCommandButton commandButton) { int layoutHGap = ComponentUtilities.getHLayoutGap(commandButton); int layoutVGap = ComponentUtilities.getVLayoutGap(commandButton); - boolean hasIcon = (commandButton.getIcon() != null); + boolean hasIcon = (commandButton.getContentModel().getIconFactory() != null); boolean hasText = (this.titlePart1 != null); boolean hasPopupIcon = ComponentUtilities.hasPopupAction(commandButton); @@ -251,9 +251,7 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { JCommandButton.CommandButtonKind buttonKind = commandButton.getCommandButtonKind(); - RadianceIcon buttonIcon = commandButton.getIcon(); - - boolean hasIcon = (commandButton.getIcon() != null); + boolean hasIcon = (commandButton.getContentModel().getIconFactory() != null); boolean hasText = (this.titlePart1 != null); boolean hasPopupIcon = ComponentUtilities.hasPopupAction(commandButton); @@ -272,8 +270,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { if (hasIcon) { y += layoutVGap; - int iconHeight = buttonIcon.getIconHeight(); - int iconWidth = buttonIcon.getIconWidth(); + int iconHeight = getCurrentIconHeight(commandButton); + int iconWidth = getCurrentIconWidth(commandButton); result.iconRect.x = (width - iconWidth) / 2; result.iconRect.y = y; diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerMedium.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerMedium.java index 99a8b63fc..be7e7af30 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerMedium.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerMedium.java @@ -61,7 +61,7 @@ protected float getIconTextGapFactor() { } private boolean hasIcon(JCommandButton button) { - if (button.getIcon() != null) { + if (button.getContentModel().getIconFactory() != null) { return true; } if (Boolean.TRUE.equals(button.getClientProperty(BasicCommandPopupMenuPanelUI.FORCE_ICON))) { diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerSmall.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerSmall.java index 4962912ac..f61009fff 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerSmall.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerSmall.java @@ -62,7 +62,7 @@ public Dimension getPreferredSize(JCommandButton commandButton) { int layoutHGap = ComponentUtilities.getHLayoutGap(commandButton); - boolean hasIcon = (commandButton.getIcon() != null); + boolean hasIcon = (commandButton.getContentModel().getIconFactory() != null); boolean hasPopupIcon = ComponentUtilities.hasPopupAction(commandButton); int prefIconWidth = hasIcon ? this.getPreferredIconSize(commandButton).width : 0; @@ -177,10 +177,9 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } } - RadianceIcon buttonIcon = commandButton.getIcon(); String buttonText = commandButton.getText(); - boolean hasIcon = (buttonIcon != null); + boolean hasIcon = (commandButton.getContentModel().getIconFactory() != null); boolean hasText = (buttonText != null); boolean hasPopupIcon = ComponentUtilities.hasPopupAction(commandButton); @@ -198,8 +197,9 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { if (hasIcon) { x += layoutHGap; - int iconHeight = buttonIcon.getIconHeight(); - int iconWidth = buttonIcon.getIconWidth(); + Dimension iconSize = getPreferredIconSize(commandButton); + int iconHeight = iconSize.height; + int iconWidth = iconSize.width; result.iconRect.x = x; result.iconRect.y = (height - iconHeight) / 2; @@ -299,8 +299,9 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { if (hasIcon) { x -= layoutHGap; - int iconHeight = buttonIcon.getIconHeight(); - int iconWidth = buttonIcon.getIconWidth(); + Dimension iconSize = getPreferredIconSize(commandButton); + int iconHeight = iconSize.height; + int iconWidth = iconSize.width; result.iconRect.x = x - iconWidth; result.iconRect.y = (height - iconHeight) / 2; diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerTile.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerTile.java index 630c97e65..e6ee5aef5 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerTile.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/CommandButtonLayoutManagerTile.java @@ -70,7 +70,7 @@ public Dimension getPreferredSize(JCommandButton commandButton) { int layoutHGap = ComponentUtilities.getHLayoutGap(commandButton); - boolean hasIcon = (commandButton.getIcon() != null); + boolean hasIcon = (commandButton.getContentModel().getIconFactory() != null); boolean hasText = (textWidth > 0); boolean hasPopupIcon = ComponentUtilities.hasPopupAction(commandButton); @@ -135,7 +135,7 @@ public Dimension getPreferredSize(JCommandButton commandButton) { @Override public Point getActionKeyTipAnchorCenterPoint(JCommandButton commandButton) { CommandButtonLayoutInfo layoutInfo = this.getLayoutInfo(commandButton); - boolean hasIcon = (commandButton.getIcon() != null); + boolean hasIcon = (commandButton.getContentModel().getIconFactory() != null); int height = commandButton.getHeight(); if (commandButton.getComponentOrientation().isLeftToRight()) { @@ -212,11 +212,10 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } } - RadianceIcon buttonIcon = commandButton.getIcon(); String buttonText = commandButton.getText(); String buttonExtraText = commandButton.getExtraText(); - boolean hasIcon = (buttonIcon != null); + boolean hasIcon = (commandButton.getContentModel().getIconFactory() != null); boolean hasText = (buttonText != null) || (buttonExtraText != null); boolean hasPopupIcon = ComponentUtilities.hasPopupAction(commandButton); @@ -234,8 +233,9 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { if (hasIcon) { x += layoutHGap; - int iconHeight = buttonIcon.getIconHeight(); - int iconWidth = buttonIcon.getIconWidth(); + Dimension iconSize = getPreferredIconSize(commandButton); + int iconHeight = iconSize.height; + int iconWidth = iconSize.width; result.iconRect.x = x; result.iconRect.y = bt + (height - by - iconHeight) / 2; @@ -413,8 +413,9 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { if (hasIcon) { x -= layoutHGap; - int iconHeight = buttonIcon.getIconHeight(); - int iconWidth = buttonIcon.getIconWidth(); + Dimension iconSize = getPreferredIconSize(commandButton); + int iconHeight = iconSize.height; + int iconWidth = iconSize.width; result.iconRect.x = x - iconWidth; result.iconRect.y = bt + (height - by - iconHeight) / 2; diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/popup/BasicCommandPopupMenuPanelUI.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/popup/BasicCommandPopupMenuPanelUI.java index 3f8b2d40b..7f97a00e7 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/popup/BasicCommandPopupMenuPanelUI.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/common/popup/BasicCommandPopupMenuPanelUI.java @@ -309,7 +309,7 @@ public void layoutContainer(Container parent) { for (Component menuComponent : menuComponents) { if (menuComponent instanceof JCommandButton) { JCommandButton menuButton = (JCommandButton) menuComponent; - if (menuButton.getIcon() != null) { + if (menuButton.getContentModel().getIconFactory() != null) { atLeastOneButtonHasIcon = true; } if (menuButton.getProjection().getContentModel().isToggle()) { diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/BasicRibbonTaskToggleButtonUI.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/BasicRibbonTaskToggleButtonUI.java index d1b09a0f2..952728374 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/BasicRibbonTaskToggleButtonUI.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/BasicRibbonTaskToggleButtonUI.java @@ -115,21 +115,19 @@ protected void uninstallListeners() { @Override public Dimension getMinimumSize(JComponent c) { - JRibbonTaskToggleButton b = (JRibbonTaskToggleButton) c; - - Icon icon = b.getIcon(); + Icon icon = this.icon; String text = "Www"; - Font font = b.getFont(); + Font font = this.commandButton.getFont(); FontMetrics fm = RadianceMetricsUtilities.getFontMetrics( - RadianceCommonCortex.getScaleFactor(b), font); + RadianceCommonCortex.getScaleFactor(this.commandButton), font); Rectangle iconR = new Rectangle(); Rectangle textR = new Rectangle(); Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE); int horizontalAlignment = SwingUtilities.LEADING; - switch (b.getHorizontalAlignment()) { + switch (this.commandButton.getHorizontalAlignment()) { case CENTER: horizontalAlignment = SwingUtilities.CENTER; break; @@ -137,14 +135,14 @@ public Dimension getMinimumSize(JComponent c) { horizontalAlignment = SwingUtilities.TRAILING; break; } - SwingUtilities.layoutCompoundLabel(b, fm, text, icon, + SwingUtilities.layoutCompoundLabel(this.commandButton, fm, text, icon, SwingUtilities.CENTER, horizontalAlignment, SwingUtilities.CENTER, SwingUtilities.CENTER, viewR, iconR, textR, (text == null ? 0 : 6)); Rectangle r = iconR.union(textR); - Insets insets = b.getInsets(); + Insets insets = this.commandButton.getInsets(); r.width += 4; r.height += insets.top + insets.bottom; diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/CommandButtonLayoutManagerBigFixed.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/CommandButtonLayoutManagerBigFixed.java index 97daf35e5..2ede779ec 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/CommandButtonLayoutManagerBigFixed.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/CommandButtonLayoutManagerBigFixed.java @@ -127,22 +127,20 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { result.popupClickArea.height = height; } - JSeparator jsep = new JSeparator(JSeparator.VERTICAL); - - RadianceIcon buttonIcon = commandButton.getIcon(); + Dimension iconSize = getPreferredIconSize(commandButton); + int iconWidth = iconSize.width; + int iconHeight = iconSize.height; if (commandButton.getText() == null) { - y = ins.top - + (height - ins.top - ins.bottom - buttonIcon - .getIconHeight()) / 2; + y = ins.top + (height - ins.top - ins.bottom - iconHeight) / 2; } - result.iconRect.x = (width - buttonIcon.getIconWidth()) / 2; + result.iconRect.x = (width - iconWidth) / 2; result.iconRect.y = y; - result.iconRect.width = buttonIcon.getIconWidth(); - result.iconRect.height = buttonIcon.getIconHeight(); - y += buttonIcon.getIconHeight(); + result.iconRect.width = iconWidth; + result.iconRect.height = iconHeight; + y += iconHeight; - y += jsep.getPreferredSize().width; + y += new JSeparator(JSeparator.HORIZONTAL).getPreferredSize().height; TextLayoutInfo lineLayoutInfo = new TextLayoutInfo(); lineLayoutInfo.text = commandButton.getText(); diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/CommandButtonLayoutManagerBigFixedLandscape.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/CommandButtonLayoutManagerBigFixedLandscape.java index 37ae28e1d..20217b4cc 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/CommandButtonLayoutManagerBigFixedLandscape.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/CommandButtonLayoutManagerBigFixedLandscape.java @@ -128,22 +128,20 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { result.popupClickArea.height = height; } - JSeparator jsep = new JSeparator(JSeparator.VERTICAL); - - RadianceIcon buttonIcon = commandButton.getIcon(); + Dimension iconSize = getPreferredIconSize(commandButton); + int iconWidth = iconSize.width; + int iconHeight = iconSize.height; if (commandButton.getText() == null) { - y = ins.top - + (height - ins.top - ins.bottom - buttonIcon - .getIconHeight()) / 2; + y = ins.top + (height - ins.top - ins.bottom - iconHeight) / 2; } - result.iconRect.x = (width - buttonIcon.getIconWidth()) / 2; + result.iconRect.x = (width - iconWidth) / 2; result.iconRect.y = y; - result.iconRect.width = buttonIcon.getIconWidth(); - result.iconRect.height = buttonIcon.getIconHeight(); - y += buttonIcon.getIconHeight(); + result.iconRect.width = iconWidth; + result.iconRect.height = iconHeight; + y += iconHeight; - y += jsep.getPreferredSize().width; + y += new JSeparator(JSeparator.HORIZONTAL).getPreferredSize().height; TextLayoutInfo lineLayoutInfo = new TextLayoutInfo(); lineLayoutInfo.text = commandButton.getText(); diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/appmenu/CommandButtonLayoutManagerMenuTileLevel1.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/appmenu/CommandButtonLayoutManagerMenuTileLevel1.java index 80e309aa7..74870a3ac 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/appmenu/CommandButtonLayoutManagerMenuTileLevel1.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/appmenu/CommandButtonLayoutManagerMenuTileLevel1.java @@ -141,17 +141,19 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { boolean ltr = commandButton.getComponentOrientation().isLeftToRight(); - RadianceIcon buttonIcon = commandButton.getIcon(); + Dimension iconSize = getPreferredIconSize(commandButton); + int iconWidth = iconSize.width; + int iconHeight = iconSize.height; if (ltr) { int x = ins.left; // small icon, 1-line text, 1-line extra text and action arrow result.iconRect.x = x; - result.iconRect.y = (height - buttonIcon.getIconHeight()) / 2; - result.iconRect.width = buttonIcon.getIconWidth(); - result.iconRect.height = buttonIcon.getIconHeight(); + result.iconRect.y = (height - iconHeight) / 2; + result.iconRect.width = iconWidth; + result.iconRect.height = iconHeight; - x += commandButton.getIcon().getIconWidth(); + x += iconWidth; if (buttonKind == JCommandButton.CommandButtonKind.ACTION_AND_POPUP_MAIN_POPUP) { result.actionClickArea.x = 0; result.actionClickArea.y = 0; @@ -222,12 +224,12 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } else { int x = commandButton.getWidth() - ins.right; // small icon, 1-line text, 1-line extra text and action arrow - result.iconRect.x = x - buttonIcon.getIconWidth(); - result.iconRect.y = (height - buttonIcon.getIconHeight()) / 2; - result.iconRect.width = buttonIcon.getIconWidth(); - result.iconRect.height = buttonIcon.getIconHeight(); + result.iconRect.x = x - iconWidth; + result.iconRect.y = (height - iconHeight) / 2; + result.iconRect.width = iconWidth; + result.iconRect.height = iconHeight; - x -= commandButton.getIcon().getIconWidth(); + x -= iconWidth; if (buttonKind == JCommandButton.CommandButtonKind.ACTION_AND_POPUP_MAIN_POPUP) { result.actionClickArea.x = x + layoutHGap; result.actionClickArea.y = 0; diff --git a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/appmenu/CommandButtonLayoutManagerMenuTileLevel2.java b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/appmenu/CommandButtonLayoutManagerMenuTileLevel2.java index 936c04a60..a8c62c94e 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/appmenu/CommandButtonLayoutManagerMenuTileLevel2.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/internal/ui/ribbon/appmenu/CommandButtonLayoutManagerMenuTileLevel2.java @@ -151,7 +151,10 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { int layoutHGap = 2 * ComponentUtilities.getHLayoutGap(commandButton); int layoutVGap = 2 * ComponentUtilities.getVLayoutGap(commandButton); - RadianceIcon buttonIcon = commandButton.getIcon(); + Dimension iconSize = getPreferredIconSize(commandButton); + int iconWidth = iconSize.width; + int iconHeight = iconSize.height; + boolean ltr = commandButton.getComponentOrientation().isLeftToRight(); if (ltr) { @@ -159,10 +162,10 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { // medium icon, 1-line text, 2-line extra text and popup arrow result.iconRect.x = x; result.iconRect.y = ins.top + layoutVGap; - result.iconRect.width = buttonIcon.getIconWidth(); - result.iconRect.height = buttonIcon.getIconHeight(); + result.iconRect.width = iconWidth; + result.iconRect.height = iconHeight; - x += buttonIcon.getIconWidth(); + x += iconWidth; if (buttonKind == JCommandButton.CommandButtonKind.ACTION_AND_POPUP_MAIN_POPUP) { result.actionClickArea.x = 0; result.actionClickArea.y = 0; @@ -280,12 +283,12 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } else { int x = commandButton.getWidth() - ins.right; // medium icon, 1-line text, 2-line extra text and popup arrow - result.iconRect.x = x - buttonIcon.getIconWidth(); + result.iconRect.x = x - iconWidth; result.iconRect.y = ins.top + layoutVGap; - result.iconRect.width = buttonIcon.getIconWidth(); - result.iconRect.height = buttonIcon.getIconHeight(); + result.iconRect.width = iconWidth; + result.iconRect.height = iconHeight; - x -= buttonIcon.getIconWidth(); + x -= iconWidth; if (buttonKind == JCommandButton.CommandButtonKind.ACTION_AND_POPUP_MAIN_POPUP) { result.actionClickArea.x = x + layoutHGap; result.actionClickArea.y = 0; diff --git a/demos/component-demo/src/main/java/org/pushingpixels/radiance/demo/component/common/TestCommandButtons.java b/demos/component-demo/src/main/java/org/pushingpixels/radiance/demo/component/common/TestCommandButtons.java index e9837b381..c2407d051 100644 --- a/demos/component-demo/src/main/java/org/pushingpixels/radiance/demo/component/common/TestCommandButtons.java +++ b/demos/component-demo/src/main/java/org/pushingpixels/radiance/demo/component/common/TestCommandButtons.java @@ -152,7 +152,7 @@ private CommandMenuContentModel getPopupMenuContentModel() { List simpleEntries2 = new ArrayList<>(); simpleEntries1.add(Command.builder() - .setText(mf.format(new Object[]{"1"}) + "sfdjhskjshdksjdh") + .setText(mf.format(new Object[]{"1"})) .setIconFactory(Address_book_new.factory()) .setAction(commandActionEvent -> System.out.println("Popup action 1")) .build()); diff --git a/demos/component-demo/src/main/java/org/pushingpixels/radiance/demo/component/ribbon/BasicCheckRibbon.java b/demos/component-demo/src/main/java/org/pushingpixels/radiance/demo/component/ribbon/BasicCheckRibbon.java index b9a75f014..dbe93f1ec 100644 --- a/demos/component-demo/src/main/java/org/pushingpixels/radiance/demo/component/ribbon/BasicCheckRibbon.java +++ b/demos/component-demo/src/main/java/org/pushingpixels/radiance/demo/component/ribbon/BasicCheckRibbon.java @@ -2518,11 +2518,17 @@ private void configureStatusBar() { if (JCommandButton.class.isAssignableFrom(ownerClass)) { JCommandButton cb = (JCommandButton) owner; BaseCommand command = cb.getProjection().getContentModel(); + BaseCommandButtonPresentationModel presentation = + cb.getProjection().getPresentationModel(); toShow = "[" + ownerClass.getSimpleName() + "] " + command.getText(); if (command.getIconFactory() != null) { icon = command.getIconFactory().createNewIcon(); - int iconWidth = Math.min(cb.getIcon().getIconWidth(), 16); - int iconHeight = Math.min(cb.getIcon().getIconHeight(), 16); + int iconWidth = 16; + int iconHeight = 16; + if (presentation.getIconDimension() != null) { + iconWidth = presentation.getIconDimension().width; + iconHeight = presentation.getIconDimension().height; + } icon.setDimension(new Dimension(iconWidth, iconHeight)); } } else if (JRibbonComboBox.class.isAssignableFrom(ownerClass)) {