Skip to content

Commit

Permalink
Third pass to migrate away from component customizers for command but…
Browse files Browse the repository at this point in the history
…tons

Convert ribbon gallery scroller / expand buttons, as well as scrollable panel scroll buttons to be fully configured by the command and the presentation model, with no component customizer

For #447
  • Loading branch information
kirill-grouchnikov committed May 5, 2023
1 parent 0473da4 commit 1399018
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.pushingpixels.radiance.theming.internal.animation.StateTransitionTracker;
import org.pushingpixels.radiance.theming.internal.blade.BladeColorScheme;
import org.pushingpixels.radiance.theming.internal.blade.BladeUtils;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorSchemeUtilities;
import org.pushingpixels.radiance.theming.internal.utils.WidgetUtilities;
import org.pushingpixels.radiance.theming.internal.utils.icon.TransitionAware;

import java.awt.*;
Expand Down Expand Up @@ -111,13 +113,17 @@ public CommandButtonFollowColorSchemeIcon(ColorSchemeAssociationKind colorScheme

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
float alpha = 1.0f;
// If the passed component is null or not a JCommandButton, our best effort is to
// display either "enabled" or "disabled" version of the delegate icon
if (!(c instanceof JCommandButton)) {
BladeUtils.populateColorScheme(mutableColorScheme, null, null,
((c == null) || !c.isEnabled()) ? ComponentState.DISABLED_UNSELECTED
: ComponentState.ENABLED,
this.colorSchemeAssociationKind, false);
if ((c == null) || !c.isEnabled()) {
alpha = RadianceColorSchemeUtilities.getAlpha(c, ComponentState.DISABLED_UNSELECTED);
}
} else {
JCommandButton commandButton = (JCommandButton) c;

Expand All @@ -130,10 +136,14 @@ public void paintIcon(Component c, Graphics g, int x, int y) {

BladeUtils.populateColorScheme(mutableColorScheme, commandButton, modelStateInfo, currState,
this.colorSchemeAssociationKind, false);
alpha = RadianceColorSchemeUtilities.getAlpha(c, currState);
}

Graphics2D graphics = (Graphics2D) g.create();
graphics.translate(x, y);
if (alpha < 1.0f) {
graphics.setComposite(WidgetUtilities.getAlphaComposite(c, alpha, g));
}
this.delegate.drawColorSchemeIcon(graphics, mutableColorScheme, this.width, this.height);
graphics.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.pushingpixels.radiance.component.api.common.CommandButtonPresentationState;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;

import java.awt.*;

public class CommandStripPresentationModel implements ImmutablePresentationModel {
public static final double DEFAULT_GAP_SCALE_FACTOR_PRIMARY_AXIS = 0.75;
public static final double DEFAULT_GAP_SCALE_FACTOR_SECONDARY_AXIS = 1.0;
Expand Down Expand Up @@ -59,6 +61,8 @@ public enum StripOrientation {
*/
private CommandButtonPresentationState commandPresentationState;

private Insets commandContentPadding;

private RadianceThemingSlices.IconFilterStrategy activeIconFilterStrategy;
private RadianceThemingSlices.IconFilterStrategy enabledIconFilterStrategy;
private RadianceThemingSlices.IconFilterStrategy disabledIconFilterStrategy;
Expand Down Expand Up @@ -97,6 +101,10 @@ public CommandButtonPresentationState getCommandPresentationState() {
return this.commandPresentationState;
}

public Insets getCommandContentPadding() {
return this.commandContentPadding;
}

public RadianceThemingSlices.IconFilterStrategy getActiveIconFilterStrategy() {
return this.activeIconFilterStrategy;
}
Expand Down Expand Up @@ -134,8 +142,10 @@ public boolean isToDismissPopupsOnActivation() {
}

public static class Builder {
private CommandButtonPresentationState commandPresentationState
= CommandButtonPresentationState.SMALL;
private CommandButtonPresentationState commandPresentationState =
CommandButtonPresentationState.SMALL;
private Insets commandContentPadding =
CommandButtonPresentationModel.COMPACT_BUTTON_CONTENT_PADDING;
private RadianceThemingSlices.IconFilterStrategy activeIconFilterStrategy =
RadianceThemingSlices.IconFilterStrategy.ORIGINAL;
private RadianceThemingSlices.IconFilterStrategy enabledIconFilterStrategy =
Expand All @@ -156,6 +166,11 @@ public Builder setCommandPresentationState(
return this;
}

public Builder setCommandContentPadding(Insets commandContentPadding) {
this.commandContentPadding = commandContentPadding;
return this;
}

public Builder setIconFilterStrategies(
RadianceThemingSlices.IconFilterStrategy activeIconFilterStrategy,
RadianceThemingSlices.IconFilterStrategy enabledIconFilterStrategy,
Expand Down Expand Up @@ -200,6 +215,7 @@ public Builder setToDismissPopupsOnActivation(boolean toDismissPopupsOnActivatio
public CommandStripPresentationModel build() {
CommandStripPresentationModel presentationModel = new CommandStripPresentationModel();
presentationModel.commandPresentationState = this.commandPresentationState;
presentationModel.commandContentPadding = this.commandContentPadding;
presentationModel.activeIconFilterStrategy = this.activeIconFilterStrategy;
presentationModel.enabledIconFilterStrategy = this.enabledIconFilterStrategy;
presentationModel.disabledIconFilterStrategy = this.disabledIconFilterStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public void setComponentCustomizer(ComponentCustomizer<T> componentCustomizer) {
this.componentCustomizer = componentCustomizer;
}

/**
* @deprecated This method will be removed before the final 7.0 release.
*/
@Deprecated
public void setCommandComponentCustomizers(Map<Command,
ComponentCustomizer<JCommandButton>> commandComponentCustomizers) {
this.commandComponentCustomizers = commandComponentCustomizers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,14 @@
*/
package org.pushingpixels.radiance.component.internal.theming.common.ui;

import org.pushingpixels.radiance.common.api.icon.RadianceIcon;
import org.pushingpixels.radiance.component.api.common.JCommandButton;
import org.pushingpixels.radiance.component.api.common.JScrollablePanel;
import org.pushingpixels.radiance.component.internal.theming.common.BladeTransitionAwareRadianceIcon;
import org.pushingpixels.radiance.component.internal.ui.common.BasicScrollablePanelUI;
import org.pushingpixels.radiance.theming.api.RadianceThemingCortex;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.internal.blade.BladeArrowIconUtils;
import org.pushingpixels.radiance.theming.internal.painter.BackgroundPaintingUtils;
import org.pushingpixels.radiance.theming.internal.utils.RadianceCoreUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceSizeUtils;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.util.EnumSet;

/**
* UI for {@link JScrollablePanel} components in <b>Radiance</b> look and feel.
Expand Down Expand Up @@ -74,54 +66,4 @@ public void update(Graphics g, JComponent c) {
}
}
}

@Override
protected void configureLeadingScrollerButton(JCommandButton button) {
final int fontSize = RadianceSizeUtils.getComponentFontSize(button);
int arrowIconHeight = (int) RadianceSizeUtils.getSmallDoubleArrowIconHeight(fontSize);
int arrowIconWidth = (int) RadianceSizeUtils.getSmallArrowIconWidth(fontSize);
RadianceIcon arrowIcon = new BladeTransitionAwareRadianceIcon(button,
() -> ((ActionPopupTransitionAwareUI) button.getUI()).getActionTransitionTracker(),
(g, scheme, width, height) -> BladeArrowIconUtils.drawDoubleArrow(g, width, height,
RadianceSizeUtils.getSmallDoubleArrowGap(fontSize),
RadianceSizeUtils.getDoubleArrowStrokeWidth(fontSize),
(scrollablePanel.getScrollType() == JScrollablePanel.ScrollType.HORIZONTALLY)
? SwingUtilities.WEST
: SwingUtilities.NORTH,
scheme),
new Dimension(arrowIconHeight, arrowIconWidth));
button.setIcon(arrowIcon);
RadianceThemingCortex.ComponentScope.setButtonStraightSides(button,
(scrollablePanel.getScrollType() == JScrollablePanel.ScrollType.HORIZONTALLY)
? EnumSet.of(RadianceThemingSlices.Side.TRAILING)
: EnumSet.of(RadianceThemingSlices.Side.BOTTOM));

button.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

@Override
protected void configureTrailingScrollerButton(JCommandButton button) {
final int fontSize = RadianceSizeUtils.getComponentFontSize(button);
int arrowIconHeight = (int) RadianceSizeUtils.getSmallDoubleArrowIconHeight(fontSize);
int arrowIconWidth = (int) RadianceSizeUtils.getSmallArrowIconWidth(fontSize);
RadianceIcon arrowIcon = new BladeTransitionAwareRadianceIcon(button,
() -> ((ActionPopupTransitionAwareUI) button.getUI()).getActionTransitionTracker(),
(g, scheme, width, height) -> BladeArrowIconUtils.drawDoubleArrow(g, width, height,
RadianceSizeUtils.getSmallDoubleArrowGap(fontSize),
RadianceSizeUtils.getDoubleArrowStrokeWidth(fontSize),
(scrollablePanel.getScrollType() == JScrollablePanel.ScrollType.HORIZONTALLY)
? SwingUtilities.EAST
: SwingUtilities.SOUTH,
scheme),
new Dimension(arrowIconHeight, arrowIconWidth));
button.setIcon(arrowIcon);
RadianceThemingCortex.ComponentScope.setButtonStraightSides(button,
(scrollablePanel.getScrollType() == JScrollablePanel.ScrollType.HORIZONTALLY)
? EnumSet.of(RadianceThemingSlices.Side.LEADING)
: EnumSet.of(RadianceThemingSlices.Side.TOP));

button.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,11 @@
*/
package org.pushingpixels.radiance.component.internal.theming.ribbon.ui;

import org.pushingpixels.radiance.common.api.icon.RadianceIcon;
import org.pushingpixels.radiance.component.api.common.JCommandButton;
import org.pushingpixels.radiance.component.internal.theming.common.BladeTransitionAwareRadianceIcon;
import org.pushingpixels.radiance.component.internal.theming.common.ui.ActionPopupTransitionAwareUI;
import org.pushingpixels.radiance.component.internal.ui.ribbon.BasicRibbonGalleryUI;
import org.pushingpixels.radiance.component.internal.ui.ribbon.JRibbonGallery;
import org.pushingpixels.radiance.theming.api.ComponentState;
import org.pushingpixels.radiance.theming.api.RadianceThemingCortex;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices.ColorSchemeAssociationKind;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.internal.blade.BladeArrowIconUtils;
import org.pushingpixels.radiance.theming.internal.blade.BladeDrawingUtils;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorSchemeUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceCoreUtilities;
Expand Down Expand Up @@ -83,56 +76,6 @@ protected void paintRibbonGalleryBorder(Graphics graphics) {
g2d.dispose();
}

@Override
protected void configureExpandButton(JCommandButton button) {
final int fontSize = RadianceSizeUtils.getComponentFontSize(button);
int arrowIconHeight = (int) RadianceSizeUtils.getSmallDoubleArrowIconHeight(fontSize);
int arrowIconWidth = (int) RadianceSizeUtils.getSmallArrowIconWidth(fontSize);
final RadianceIcon arrowIcon = new BladeTransitionAwareRadianceIcon(button,
() -> ((ActionPopupTransitionAwareUI) button.getUI()).getActionTransitionTracker(),
(g, scheme, width, height) ->
BladeArrowIconUtils.drawDoubleArrow(g, width, height,
RadianceSizeUtils.getSmallDoubleArrowGap(fontSize),
RadianceSizeUtils.getDoubleArrowStrokeWidth(fontSize),
SwingConstants.SOUTH, scheme),
new Dimension(arrowIconWidth, arrowIconHeight));
button.setIcon(arrowIcon);
RadianceThemingCortex.ComponentScope.setButtonStraightSide(button,
RadianceThemingSlices.Side.LEADING);
}

@Override
protected void configureScrollDownButton(JCommandButton button) {
final int fontSize = RadianceSizeUtils.getComponentFontSize(button);
int arrowIconHeight = (int) RadianceSizeUtils.getSmallArrowIconHeight(fontSize);
int arrowIconWidth = (int) RadianceSizeUtils.getSmallArrowIconWidth(fontSize);
final RadianceIcon arrowIcon = new BladeTransitionAwareRadianceIcon(button,
() -> ((ActionPopupTransitionAwareUI) button.getUI()).getActionTransitionTracker(),
(g, scheme, width, height) -> BladeArrowIconUtils.drawArrow(g, width, height,
RadianceSizeUtils.getDoubleArrowStrokeWidth(fontSize),
SwingConstants.SOUTH, scheme),
new Dimension(arrowIconWidth, arrowIconHeight));
button.setIcon(arrowIcon);
RadianceThemingCortex.ComponentScope.setButtonStraightSide(button,
RadianceThemingSlices.Side.LEADING);
}

@Override
protected void configureScrollUpButton(JCommandButton button) {
final int fontSize = RadianceSizeUtils.getComponentFontSize(button);
int arrowIconHeight = (int) RadianceSizeUtils.getSmallArrowIconHeight(fontSize);
int arrowIconWidth = (int) RadianceSizeUtils.getSmallArrowIconWidth(fontSize);
final RadianceIcon arrowIcon = new BladeTransitionAwareRadianceIcon(button,
() -> ((ActionPopupTransitionAwareUI) button.getUI()).getActionTransitionTracker(),
(g, scheme, width, height) -> BladeArrowIconUtils.drawArrow(g, width, height,
RadianceSizeUtils.getDoubleArrowStrokeWidth(fontSize),
SwingConstants.NORTH, scheme),
new Dimension(arrowIconWidth, arrowIconHeight));
button.setIcon(arrowIcon);
RadianceThemingCortex.ComponentScope.setButtonStraightSide(button,
RadianceThemingSlices.Side.LEADING);
}

@Override
public void update(Graphics g, JComponent c) {
super.update(g, c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private void addButton(Command command) {
CommandButtonPresentationModel presentation = CommandButtonPresentationModel.withDefaults()
.overlayWith(CommandButtonPresentationModel.overlay()
.setPresentationState(stripPresentationModel.getCommandPresentationState())
.setContentPadding(stripPresentationModel.getCommandContentPadding())
.setIconFilterStrategies(
stripPresentationModel.getActiveIconFilterStrategy(),
stripPresentationModel.getEnabledIconFilterStrategy(),
Expand Down
Loading

0 comments on commit 1399018

Please sign in to comment.