Skip to content

Commit

Permalink
More changes for tonal visuals of the title pane
Browse files Browse the repository at this point in the history
Use onContainer tokens for title pane text, test logo and default (flat) visuals of control button icons. For #400
  • Loading branch information
kirill-grouchnikov committed Dec 1, 2024
1 parent d323af3 commit 7a3f872
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.pushingpixels.radiance.theming.api.RadianceThemingCortex;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;

import javax.swing.*;
import java.awt.*;
Expand All @@ -52,10 +53,24 @@ public static RadianceIcon getLogoIcon(RadianceColorScheme scheme) {
return base;
}

public static RadianceIcon getLogoIcon(ContainerRenderColorTokens renderColorTokens) {
// Step 1 - create a colorized version of the transcoded Radiance logo
RadianceIcon base = radiance_menu.factory().createNewIcon();
base.setColorFilter(color -> renderColorTokens.getOnContainerColorTokens().getOnContainer());
// Step 2 - configure the colorized version to be 16x16
base.setDimension(new Dimension(16, 16));
// Step 3 - good to go
return base;
}

public static BufferedImage getLogoImage(Component comp, RadianceColorScheme scheme) {
return getLogoIcon(scheme).toImage(RadianceCommonCortex.getScaleFactor(comp));
}

public static BufferedImage getLogoImage(Component comp, ContainerRenderColorTokens renderColorTokens) {
return getLogoIcon(renderColorTokens).toImage(RadianceCommonCortex.getScaleFactor(comp));
}

public static void configureOn(JFrame frame) {
frame.setIconImage(RadianceLogo.getLogoImage(frame, RadianceThemingCortex.ComponentScope.getCurrentSkin(frame.getRootPane())
.getColorScheme(RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE,
Expand All @@ -66,4 +81,15 @@ public static void configureOn(JFrame frame) {
.getColorScheme(RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE,
RadianceThemingSlices.ColorSchemeAssociationKind.FILL, ComponentState.ENABLED)))));
}

public static void tonalConfigureOn(JFrame frame) {
frame.setIconImage(RadianceLogo.getLogoImage(frame,
RadianceThemingCortex.ComponentScope.getCurrentSkin(frame.getRootPane())
.getBackgroundRenderColorTokens(RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE)));
RadianceThemingCortex.GlobalScope.registerSkinChangeListener(() -> SwingUtilities.invokeLater(
() -> frame.setIconImage(RadianceLogo.getLogoImage(frame,
RadianceThemingCortex.ComponentScope.getCurrentSkin(frame.getRootPane())
.getBackgroundRenderColorTokens(
RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE)))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import org.pushingpixels.ephemeral.chroma.hct.Hct;
import org.pushingpixels.ephemeral.chroma.palettes.TonalPalette;
import org.pushingpixels.radiance.demo.theming.main.RadianceLogo;
import org.pushingpixels.radiance.theming.api.*;
import org.pushingpixels.radiance.theming.api.RadianceColorSchemeBundle;
import org.pushingpixels.radiance.theming.api.RadianceSkin;
import org.pushingpixels.radiance.theming.api.RadianceThemingCortex;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.AquaColorScheme;
import org.pushingpixels.radiance.theming.api.colorscheme.LightGrayColorScheme;
import org.pushingpixels.radiance.theming.api.colorscheme.MetallicColorScheme;
Expand Down Expand Up @@ -71,11 +74,7 @@ public ControlStates() {
this.pack();
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setIconImage(RadianceLogo.getLogoImage(this,
RadianceThemingCortex.ComponentScope.getCurrentSkin(this.getRootPane())
.getColorScheme(RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE,
RadianceThemingSlices.ColorSchemeAssociationKind.FILL,
ComponentState.ENABLED)));
RadianceLogo.tonalConfigureOn(this);
}

private static class SampleSkin extends RadianceSkin.Accented implements TonalSkin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.*;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.internal.painter.DecorationPainterUtils;

import javax.swing.*;
import javax.swing.plaf.UIResource;
Expand Down Expand Up @@ -217,17 +218,20 @@ public static RadianceColorScheme getColorScheme(Component component,
public static ContainerRenderColorTokens getColorRenderTokens(Component component,
RadianceThemingSlices.ColorSchemeAssociationKind associationKind,
ComponentState componentState) {
RadianceSkin skin = RadianceCoreUtilities.getSkin(component);

// special case - if the component is marked as flat and
// it is in the enabled state, get the color scheme of the parent.
// However, flat toolbars should be ignored, since they are
// the "top" level decoration area.
if (!(component instanceof JToolBar)
&& RadianceCoreUtilities.hasFlatAppearance(component, false)
&& (componentState == ComponentState.ENABLED)) {
component = component.getParent();
// TODO: TONAL - verify that we don't need to use the old logic.
return skin.getBackgroundRenderColorTokens( DecorationPainterUtils.getDecorationType(component));
// component = component.getParent();
}

RadianceSkin skin = RadianceCoreUtilities.getSkin(component);
if (skin == null) {
RadianceCoreUtilities.traceRadianceApiUsage(component,
"Radiance delegate used when Radiance is not the current LAF");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.api.skin.SkinInfo;
import org.pushingpixels.radiance.theming.api.titlepane.TitlePaneButtonProvider;
import org.pushingpixels.radiance.theming.api.titlepane.TitlePaneButtonsProvider;
Expand Down Expand Up @@ -836,8 +837,6 @@ public void paintComponent(Graphics g) {
RadianceCoreUtilities.traceRadianceApiUsage(this,
"Radiance delegate used when Radiance is not the current LAF");
}
RadianceColorScheme scheme = skin
.getEnabledColorScheme(RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE);

String theTitle = this.getTitle();
String displayTitle = getDisplayTitle();
Expand Down Expand Up @@ -882,9 +881,23 @@ public void paintComponent(Graphics g) {
int yOffset = titleTextRect.y + (int) ((titleTextRect.getHeight() - fm.getHeight()) / 2)
+ fm.getAscent();

RadianceTextUtilities.paintTextWithDropShadow(this, graphics,
scheme.getForegroundColor(), scheme.getEchoColor(), displayTitle,
width, height, xOffset, yOffset);
if (skin instanceof TonalSkin) {
ContainerRenderColorTokens renderColorTokens = skin.getBackgroundRenderColorTokens(
RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE);
// TODO: TONAL - finalize the text echo color logic
RadianceTextUtilities.paintTextWithDropShadow(this, graphics,
renderColorTokens.getOnContainerColorTokens().getOnContainer(),
RadianceColorUtilities.getAlphaColor(
renderColorTokens.getOnContainerColorTokens().getOnContainerVariant(),
100),
displayTitle, width, height, xOffset, yOffset);
} else {
RadianceColorScheme scheme = skin.getEnabledColorScheme(
RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE);
RadianceTextUtilities.paintTextWithDropShadow(this, graphics,
scheme.getForegroundColor(), scheme.getEchoColor(), displayTitle,
width, height, xOffset, yOffset);
}
}

GhostPaintingUtils.paintGhostImages(this, graphics);
Expand Down

0 comments on commit 7a3f872

Please sign in to comment.