Skip to content

Commit

Permalink
Convert button layout managers to use the popup icon dimension
Browse files Browse the repository at this point in the history
For #451
  • Loading branch information
kirill-grouchnikov committed Jun 2, 2023
1 parent e6483a1 commit 928ec1d
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public BreadcrumbItem<T> getItem(int index) {
*/
public void replace(List<BreadcrumbItem<T>> items) {
this.items.clear();
for (int i = 0; i < items.size(); i++) {
this.items.addLast(items.get(i));
for (BreadcrumbItem<T> item : items) {
this.items.addLast(item);
}
this.firePathChanged(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ public enum CommandButtonKind {
/**
* <code>true</code> if the command button kind has an action.
*/
private boolean hasAction;
private final boolean hasAction;

/**
* <code>true</code> if the command button kind has a popup.
*/
private boolean hasPopup;
private final boolean hasPopup;

/**
* Constructs a new command button kind.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ public GlobalPopupMenuPanel(Projection<JCommandPopupMenuPanel, CommandMenuConten
}
}

@SuppressWarnings("unchecked")
private void handlePopupTrigger(MouseEvent event, Component c) {
if (!isValidPopupTriggerSource(c)) {
// Component not in the ribbon. Do nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,7 +49,7 @@
/**
* The core resize policies. 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:
Expand Down Expand Up @@ -369,8 +370,7 @@ public int getPreferredWidth(int availableHeight, int gap) {
int startRowIndex = (controlPanelGroup.getGroupTitle() == null) ? 0 : 1;
int rowIndex = startRowIndex;
int maxWidthInCurrColumn = 0;
for (int i = 0; i < ribbonComps.size(); i++) {
JRibbonComponent ribbonComp = ribbonComps.get(i);
for (JRibbonComponent ribbonComp : ribbonComps) {
int rowSpan = 1;

// do we need to start a new column?
Expand Down Expand Up @@ -488,8 +488,7 @@ public void install(int availableHeight, int gap) {
boolean isCoreContent = controlPanelGroup.isCoreContent();
if (isCoreContent) {
List<JRibbonComponent> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,7 +69,7 @@
* <p>
* 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 928ec1d

Please sign in to comment.