diff --git a/component/src/main/java/org/pushingpixels/radiance/component/api/bcb/BreadcrumbBarContentModel.java b/component/src/main/java/org/pushingpixels/radiance/component/api/bcb/BreadcrumbBarContentModel.java index a28bfe128..10f2d4e83 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/api/bcb/BreadcrumbBarContentModel.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/api/bcb/BreadcrumbBarContentModel.java @@ -144,8 +144,8 @@ public BreadcrumbItem getItem(int index) { */ public void replace(List> items) { this.items.clear(); - for (int i = 0; i < items.size(); i++) { - this.items.addLast(items.get(i)); + for (BreadcrumbItem item : items) { + this.items.addLast(item); } this.firePathChanged(0); } 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 58102958a..f8c602dfb 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 @@ -179,12 +179,12 @@ public enum CommandButtonKind { /** * true if the command button kind has an action. */ - private boolean hasAction; + private final boolean hasAction; /** * true if the command button kind has a popup. */ - private boolean hasPopup; + private final boolean hasPopup; /** * Constructs a new command button kind. diff --git a/component/src/main/java/org/pushingpixels/radiance/component/api/common/JSwitch.java b/component/src/main/java/org/pushingpixels/radiance/component/api/common/JSwitch.java index 7c9851c54..f57122e9b 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/api/common/JSwitch.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/api/common/JSwitch.java @@ -96,14 +96,6 @@ public RichTooltipPresentationModel getRichTooltipPresentationModel(MouseEvent m return this.presentationModel.getRichTooltipPresentationModel(); } - public void addChangeListener(ChangeListener l) { - this.listenerList.add(ChangeListener.class, l); - } - - public void removeChangeListener(ChangeListener l) { - this.listenerList.remove(ChangeListener.class, l); - } - protected void fireStateChanged() { Object[] listeners = listenerList.getListenerList(); ChangeEvent event = new ChangeEvent(this); diff --git a/component/src/main/java/org/pushingpixels/radiance/component/api/ribbon/JRibbonFrame.java b/component/src/main/java/org/pushingpixels/radiance/component/api/ribbon/JRibbonFrame.java index 2c89cb111..d8926b4cc 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/api/ribbon/JRibbonFrame.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/api/ribbon/JRibbonFrame.java @@ -680,7 +680,6 @@ public GlobalPopupMenuPanel(Projection ribbonComps = controlPanelGroup.getRibbonComps(); - for (int i = 0; i < ribbonComps.size(); i++) { - JRibbonComponent ribbonComp = ribbonComps.get(i); + for (JRibbonComponent ribbonComp : ribbonComps) { JRibbonBand.PresentationPriority targetPriority = JRibbonBand.PresentationPriority.TOP; if (ribbonComp.isResizingAware()) { targetPriority = this.mapping.map(JRibbonBand.PresentationPriority.TOP); diff --git a/component/src/main/java/org/pushingpixels/radiance/component/api/ribbon/resize/RibbonBandResizePolicy.java b/component/src/main/java/org/pushingpixels/radiance/component/api/ribbon/resize/RibbonBandResizePolicy.java index 99ebe801e..4c2217eef 100644 --- a/component/src/main/java/org/pushingpixels/radiance/component/api/ribbon/resize/RibbonBandResizePolicy.java +++ b/component/src/main/java/org/pushingpixels/radiance/component/api/ribbon/resize/RibbonBandResizePolicy.java @@ -31,6 +31,7 @@ import org.pushingpixels.radiance.component.api.common.CommandButtonPresentationState; import org.pushingpixels.radiance.component.api.common.JCommandButton; +import org.pushingpixels.radiance.component.api.common.projection.BaseCommandButtonProjection; import org.pushingpixels.radiance.component.api.common.projection.CommandButtonProjection; import org.pushingpixels.radiance.component.api.ribbon.AbstractRibbonBand; import org.pushingpixels.radiance.component.api.ribbon.JFlowRibbonBand; @@ -68,7 +69,7 @@ *

* The {@link CoreRibbonResizePolicies} provides a number of built in resize * policies that respect the application element priorities passed to - * {@link JRibbonBand#addRibbonCommand(CommandButtonProjection, JRibbonBand.PresentationPriority)} + * {@link JRibbonBand#addRibbonCommand(BaseCommandButtonProjection, JRibbonBand.PresentationPriority)} * and * {@link JRibbonBand#addRibbonGallery(RibbonGalleryProjection, JRibbonBand.PresentationPriority)} * APIs. There are three types of built in resize policies: 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 b164d5cba..a63872451 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 @@ -126,7 +126,7 @@ public Dimension getPreferredSize(JCommandButton commandButton) { if (!hasText && hasPopupIcon && commandButton.getPresentationModel().isShowPopupIcon()) { // padding above the popup icon height += layoutVGap; - // popup icon height - one line of text + // popup icon height to be equivalent to one line of text height += fm.getHeight(); // padding below the popup icon height += layoutVGap; @@ -222,6 +222,8 @@ public Point getPopupKeyTipAnchorCenterPoint(JCommandButton commandButton) { @Override public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { + BaseCommandButtonPresentationModel presentationModel = commandButton.getPresentationModel(); + if (!this.titlePartsComputed) { this.updateTitleStrings(commandButton); this.titlePartsComputed = true; @@ -322,7 +324,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { lastTextLineWidth = (this.titlePart2 != null) ? fm.stringWidth(this.titlePart2) : 0; - int extraWidth = hasPopupIcon && commandButton.getPresentationModel().isShowPopupIcon() ? 4 * layoutHGap + labelHeight / 2 : 0; + int extraWidth = (hasPopupIcon && presentationModel.isShowPopupIcon()) ? + presentationModel.getPopupIcon().getIconWidth() : 0; if (ltr) { x = ins.left + (width - lastTextLineWidth - extraWidth - ins.left - ins.right) / 2; @@ -359,10 +362,13 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { x = (width - 1 - labelHeight / 2) / 2; } + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); + result.popupActionRect.x = x; - result.popupActionRect.y = y - 1; - result.popupActionRect.width = 1 + labelHeight / 2; - result.popupActionRect.height = labelHeight + 2; + result.popupActionRect.y = y + (labelHeight - popupIconHeight) / 2; + result.popupActionRect.width = popupIconWidth; + result.popupActionRect.height = popupIconHeight; } switch (buttonKind) { 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 6383902c2..47c3173de 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 @@ -110,8 +110,8 @@ public Dimension getPreferredSize(JCommandButton commandButton) { if (hasText || hasIcon) { width += 2 * layoutHGap; } - // text width - width += 1 + fm.getHeight() / 2; + // popup icon width + width += commandButton.getPresentationModel().getPopupIcon().getIconWidth(); // padding after the popup icon width += 2 * layoutHGap; } @@ -269,8 +269,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (hasPopupIcon && presentationModel.isShowPopupIcon()) { - int popupIconWidth = ComponentUtilities.getCommandButtonPopupIconWidth( - commandButton.getFont().getSize()); + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); if (hasText || hasIcon) { if (presentationModel.getHorizontalAlignment() == HorizontalAlignment.FILL) { // Under Fill alignment, popup icon goes all the way to the right edge @@ -286,9 +286,9 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { x += (width - 2 * layoutHGap - popupIconWidth) / 2; } result.popupActionRect.x = x; - result.popupActionRect.y = (height - labelHeight) / 2 - 1; + result.popupActionRect.y = (height - popupIconHeight) / 2; result.popupActionRect.width = popupIconWidth + 4; - result.popupActionRect.height = labelHeight + 2; + result.popupActionRect.height = popupIconHeight; } int xBorderBetweenActionAndPopup = 0; @@ -433,8 +433,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (hasPopupIcon && presentationModel.isShowPopupIcon()) { - int popupIconWidth = ComponentUtilities.getCommandButtonPopupIconWidth( - commandButton.getFont().getSize()); + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); if (hasText || hasIcon) { if (presentationModel.getHorizontalAlignment() == HorizontalAlignment.FILL) { // Under Fill alignment, popup icon goes all the way to the left edge @@ -452,8 +452,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { result.popupActionRect.width = popupIconWidth + 4; result.popupActionRect.x = x - result.popupActionRect.width; - result.popupActionRect.y = (height - labelHeight) / 2 - 1; - result.popupActionRect.height = labelHeight + 2; + result.popupActionRect.y = (height - popupIconHeight) / 2; + result.popupActionRect.height = popupIconHeight; } int xBorderBetweenActionAndPopup = 0; 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 048788de4..8977f5e92 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 @@ -78,8 +78,8 @@ public Dimension getPreferredSize(JCommandButton commandButton) { if (hasPopupIcon && commandButton.getPresentationModel().isShowPopupIcon()) { // padding before the popup icon width += 2 * layoutHGap; - // text width - width += 1 + fm.getHeight() / 2; + // popup icon width + width += commandButton.getPresentationModel().getPopupIcon().getIconWidth(); // padding after the popup icon width += 2 * layoutHGap; } @@ -197,8 +197,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (hasPopupIcon && presentationModel.isShowPopupIcon()) { - int popupIconWidth = ComponentUtilities.getCommandButtonPopupIconWidth( - commandButton.getFont().getSize()); + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); if (hasIcon) { if (presentationModel.getHorizontalAlignment() == HorizontalAlignment.FILL) { // Under Fill alignment, popup icon goes all the way to the right edge @@ -213,9 +213,9 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } result.popupActionRect.x = x; - result.popupActionRect.y = (height - labelHeight) / 2 - 1; + result.popupActionRect.y = (height - popupIconHeight) / 2; result.popupActionRect.width = popupIconWidth; - result.popupActionRect.height = labelHeight + 2; + result.popupActionRect.height = popupIconHeight; } int xBorderBetweenActionAndPopup = 0; @@ -256,8 +256,7 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { result.popupClickArea.x = xBorderBetweenActionAndPopup; result.popupClickArea.y = 0; - result.popupClickArea.width = width - - xBorderBetweenActionAndPopup; + result.popupClickArea.width = width - xBorderBetweenActionAndPopup; result.popupClickArea.height = height; result.separatorOrientation = CommandButtonSeparatorOrientation.VERTICAL; @@ -298,8 +297,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (hasPopupIcon && presentationModel.isShowPopupIcon()) { - int popupIconWidth = ComponentUtilities.getCommandButtonPopupIconWidth( - commandButton.getFont().getSize()); + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); if (hasIcon) { if (presentationModel.getHorizontalAlignment() == HorizontalAlignment.FILL) { // Under Fill alignment, popup icon goes all the way to the left edge @@ -315,8 +314,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { result.popupActionRect.width = popupIconWidth; result.popupActionRect.x = x - result.popupActionRect.width; - result.popupActionRect.y = (height - labelHeight) / 2 - 1; - result.popupActionRect.height = labelHeight + 2; + result.popupActionRect.y = (height - popupIconHeight) / 2; + result.popupActionRect.height = popupIconHeight; x -= result.popupActionRect.width; } 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 c2db1957f..dc08de2ac 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 @@ -95,8 +95,8 @@ public Dimension getPreferredSize(JCommandButton commandButton) { if (hasPopupIcon && commandButton.getPresentationModel().isShowPopupIcon()) { // padding before the popup icon width += 2 * layoutHGap; - // text width - width += 1 + fm.getHeight() / 2; + // popup icon width + width += commandButton.getPresentationModel().getPopupIcon().getIconWidth(); // padding after the popup icon width += 2 * layoutHGap; } @@ -274,8 +274,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (hasPopupIcon && presentationModel.isShowPopupIcon()) { - int popupIconWidth = ComponentUtilities.getCommandButtonPopupIconWidth( - commandButton.getFont().getSize()); + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); if (hasText || hasIcon) { if (presentationModel.getHorizontalAlignment() == HorizontalAlignment.FILL) { // Under Fill alignment, popup icon goes all the way to the right edge @@ -287,9 +287,9 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } result.popupActionRect.x = x; - result.popupActionRect.y = bt + (height - by - labelHeight) / 2 - 1; + result.popupActionRect.y = bt + (height - by - popupIconHeight) / 2; result.popupActionRect.width = popupIconWidth; - result.popupActionRect.height = labelHeight + 2; + result.popupActionRect.height = popupIconHeight; } int xBorderBetweenActionAndPopup = 0; @@ -455,8 +455,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (hasPopupIcon && presentationModel.isShowPopupIcon()) { - int popupIconWidth = ComponentUtilities.getCommandButtonPopupIconWidth( - commandButton.getFont().getSize()); + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); if (hasText || hasIcon) { if (presentationModel.getHorizontalAlignment() == HorizontalAlignment.FILL) { // Under Fill alignment, popup icon goes all the way to the left edge @@ -469,8 +469,8 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { result.popupActionRect.width = popupIconWidth; result.popupActionRect.x = x - result.popupActionRect.width; - result.popupActionRect.y = bt + (height - by - labelHeight) / 2 - 1; - result.popupActionRect.height = labelHeight + 2; + result.popupActionRect.y = bt + (height - by - popupIconHeight) / 2; + result.popupActionRect.height = popupIconHeight; } int xBorderBetweenActionAndPopup = 0; 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 4ed071e24..fd344fc29 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 @@ -32,6 +32,7 @@ import org.pushingpixels.radiance.common.api.RadianceCommonCortex; import org.pushingpixels.radiance.component.api.common.CommandButtonLayoutManager; import org.pushingpixels.radiance.component.api.common.JCommandButton; +import org.pushingpixels.radiance.component.api.common.model.BaseCommandButtonPresentationModel; import org.pushingpixels.radiance.component.internal.utils.ComponentUtilities; import org.pushingpixels.radiance.theming.internal.utils.RadianceMetricsUtilities; @@ -63,9 +64,10 @@ public Dimension getPreferredSize(JCommandButton commandButton) { + 2 * layoutHGap + jsep.getPreferredSize().width + titleWidth - + (ComponentUtilities.hasPopupAction(commandButton) ? 1 - + fm.getHeight() / 2 + 4 * layoutHGap - + jsep.getPreferredSize().width : 0); + + (ComponentUtilities.hasPopupAction(commandButton) + ? commandButton.getPresentationModel().getPopupIcon().getIconWidth() + + 4 * layoutHGap + jsep.getPreferredSize().width + : 0); return new Dimension(bx + widthMed, by + Math.max(this.getPreferredIconSize(commandButton).height, 2 * (fm.getAscent() + fm.getDescent()) + layoutVGap)); @@ -101,6 +103,8 @@ public Point getPopupKeyTipAnchorCenterPoint(JCommandButton commandButton) { @Override public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { + BaseCommandButtonPresentationModel presentationModel = commandButton.getPresentationModel(); + CommandButtonLayoutInfo result = new CommandButtonLayoutInfo(); result.actionClickArea = new Rectangle(0, 0, 0, 0); @@ -214,11 +218,13 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (ComponentUtilities.hasPopupAction(commandButton)) { - result.popupActionRect.x = width - ins.right - labelHeight * 3 - / 4; - result.popupActionRect.y = (height - labelHeight) / 2 - 1; - result.popupActionRect.width = 1 + labelHeight / 2; - result.popupActionRect.height = labelHeight + 2; + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); + + result.popupActionRect.x = width - ins.right - popupIconWidth; + result.popupActionRect.y = (height - popupIconHeight) / 2; + result.popupActionRect.width = popupIconWidth; + result.popupActionRect.height = popupIconHeight; } } else { int x = commandButton.getWidth() - ins.right; @@ -288,10 +294,13 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (ComponentUtilities.hasPopupAction(commandButton)) { - result.popupActionRect.x = ins.left + labelHeight / 4; - result.popupActionRect.y = (height - labelHeight) / 2 - 1; - result.popupActionRect.width = 1 + labelHeight / 2; - result.popupActionRect.height = labelHeight + 2; + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); + + result.popupActionRect.x = ins.left; + result.popupActionRect.y = (height - popupIconHeight) / 2; + result.popupActionRect.width = popupIconWidth; + result.popupActionRect.height = popupIconHeight; } } 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 84a6b57c5..fdac51592 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 @@ -1,37 +1,38 @@ /* * Copyright (c) 2005-2023 Radiance Kirill Grouchnikov. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without + * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * - * o Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * o Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * + * + * o Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * o Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * o Neither the name of the copyright holder nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.pushingpixels.radiance.component.internal.ui.ribbon.appmenu; import org.pushingpixels.radiance.common.api.RadianceCommonCortex; import org.pushingpixels.radiance.component.api.common.CommandButtonLayoutManager; import org.pushingpixels.radiance.component.api.common.JCommandButton; +import org.pushingpixels.radiance.component.api.common.model.BaseCommandButtonPresentationModel; import org.pushingpixels.radiance.component.internal.utils.ComponentUtilities; import org.pushingpixels.radiance.theming.internal.utils.RadianceMetricsUtilities; @@ -66,9 +67,10 @@ public Dimension getPreferredSize(JCommandButton commandButton) { + 2 * layoutHGap + jsep.getPreferredSize().width + titleWidth - + (ComponentUtilities.hasPopupAction(commandButton) ? 1 - + fm.getHeight() / 2 + 4 * layoutHGap - + jsep.getPreferredSize().width : 0); + + (ComponentUtilities.hasPopupAction(commandButton) + ? commandButton.getPresentationModel().getPopupIcon().getIconWidth() + + 4 * layoutHGap + jsep.getPreferredSize().width + : 0); // height - three lines of text and two gaps between them. // The gap between the lines is half the main gap. @@ -112,6 +114,8 @@ public Point getPopupKeyTipAnchorCenterPoint(JCommandButton commandButton) { @Override public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { + BaseCommandButtonPresentationModel presentationModel = commandButton.getPresentationModel(); + CommandButtonLayoutInfo result = new CommandButtonLayoutInfo(); result.actionClickArea = new Rectangle(0, 0, 0, 0); @@ -270,11 +274,13 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (ComponentUtilities.hasPopupAction(commandButton)) { - result.popupActionRect.x = width - ins.right - labelHeight * 3 - / 4; - result.popupActionRect.y = (height - labelHeight) / 2 - 1; - result.popupActionRect.width = 1 + labelHeight / 2; - result.popupActionRect.height = labelHeight + 2; + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); + + result.popupActionRect.x = width - ins.right - popupIconWidth; + result.popupActionRect.y = (height - popupIconHeight) / 2; + result.popupActionRect.width = popupIconWidth; + result.popupActionRect.height = popupIconHeight; } } else { int x = commandButton.getWidth() - ins.right; @@ -390,10 +396,13 @@ public CommandButtonLayoutInfo getLayoutInfo(JCommandButton commandButton) { } if (ComponentUtilities.hasPopupAction(commandButton)) { - result.popupActionRect.x = ins.left + labelHeight / 4; - result.popupActionRect.y = (height - labelHeight) / 2 - 1; - result.popupActionRect.width = 1 + labelHeight / 2; - result.popupActionRect.height = labelHeight + 2; + int popupIconWidth = presentationModel.getPopupIcon().getIconWidth(); + int popupIconHeight = presentationModel.getPopupIcon().getIconHeight(); + + result.popupActionRect.x = ins.left; + result.popupActionRect.y = (height - popupIconHeight) / 2; + result.popupActionRect.width = popupIconWidth; + result.popupActionRect.height = popupIconHeight; } } return result;