From 1f14b6d848df8ebacce31294808d9a23cc9860cd Mon Sep 17 00:00:00 2001 From: Kirill Grouchnikov Date: Tue, 17 Dec 2024 12:08:23 -0500 Subject: [PATCH] Updates to the palette demo For #400 --- .../main/palette/ContainerPreview.java | 83 +++++++++++++++++++ .../theming/main/palette/PaletteDemo.java | 59 +++++++------ 2 files changed, 115 insertions(+), 27 deletions(-) create mode 100644 demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/palette/ContainerPreview.java diff --git a/demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/palette/ContainerPreview.java b/demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/palette/ContainerPreview.java new file mode 100644 index 000000000..159006929 --- /dev/null +++ b/demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/palette/ContainerPreview.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2005-2024 Radiance Kirill Grouchnikov. All Rights Reserved. + * + * 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 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. + */ +package org.pushingpixels.radiance.demo.theming.main.palette; + +import org.pushingpixels.radiance.common.api.RadianceCommonCortex; +import org.pushingpixels.radiance.theming.api.RadianceThemingCortex; +import org.pushingpixels.radiance.theming.api.palette.ContainerColorTokens; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +public class ContainerPreview extends JPanel { + private ContainerColorTokens colorTokens; + + public ContainerPreview(ContainerColorTokens colorTokens, String text) { + this.colorTokens = colorTokens; + + this.setLayout(new BorderLayout()); + this.setBorder(new EmptyBorder(4, 4, 4, 4)); + + this.add(new JComponent() { + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g.create(); + + int width = getWidth(); + int height = getHeight(); + + g2d.setColor(colorTokens.getContainer()); + g2d.fillRect(0, 0, width, height); + + g2d.setColor(colorTokens.getContainerOutline()); + g2d.setStroke(new BasicStroke(2.0f)); + g2d.drawRect(1, 1, width - 2, height - 2); + + Font font = RadianceThemingCortex.GlobalScope.getFontPolicy().getFontSet().getTitleFont(); + g2d.setFont(font); + RadianceCommonCortex.installDesktopHints(g2d, font); + FontMetrics fm = g2d.getFontMetrics(); + int textWidth = fm.stringWidth(text); + + g2d.setColor(colorTokens.getOnContainer()); + g2d.drawString(text, (width - textWidth) / 2, + (height - fm.getHeight()) / 2 + fm.getAscent()); + + g2d.dispose(); + } + }, BorderLayout.CENTER); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(220, 50); + } +} diff --git a/demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/palette/PaletteDemo.java b/demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/palette/PaletteDemo.java index f09335886..1c2144c18 100644 --- a/demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/palette/PaletteDemo.java +++ b/demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/palette/PaletteDemo.java @@ -34,12 +34,11 @@ import com.jgoodies.forms.layout.CellConstraints; import org.pushingpixels.ephemeral.chroma.hct.Hct; import org.pushingpixels.radiance.demo.theming.main.RadianceLogo; -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.palette.ColorSchemeUtils; import org.pushingpixels.radiance.theming.api.palette.RadianceColorScheme2; -import org.pushingpixels.radiance.theming.api.skin.CremeSkin; +import org.pushingpixels.radiance.theming.api.skin.BusinessSkin; import javax.swing.*; @@ -47,13 +46,10 @@ public class PaletteDemo extends JFrame { public PaletteDemo() { super("Chroma Palette"); - setIconImage(RadianceLogo.getLogoImage(this, - RadianceThemingCortex.ComponentScope.getCurrentSkin(this.getRootPane()) - .getColorScheme(RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE, - RadianceThemingSlices.ColorSchemeAssociationKind.FILL, ComponentState.ENABLED))); + RadianceLogo.tonalConfigureOn(this); FormBuilder builder = FormBuilder.create(). - columns("right:pref, 4dlu, fill:pref:grow"). + columns("right:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref:grow"). rows("p, $lg, p, $lg, p, $lg, p, $lg, p, $lg, p, 12dlu, p, $lg, p, $lg, p, $lg, " + "p, $lg, p, $lg, p"). padding(Paddings.DIALOG); @@ -62,42 +58,51 @@ public PaletteDemo() { RadianceColorScheme2 lightColorScheme = ColorSchemeUtils.getLightTonalBalancedColorScheme( Hct.fromInt(0xFF76A8C8), 16.0, 10.0); - builder.addSeparator("LIGHT").xyw(1, row, 3, CellConstraints.CENTER, CellConstraints.FILL); + RadianceColorScheme2 darkColorScheme = ColorSchemeUtils.getDarkTonalBalancedColorScheme( + Hct.fromInt(0xFF76A8C8), 16.0, 10.0); + + builder.addSeparator("LIGHT").xy(3, row, CellConstraints.CENTER, CellConstraints.FILL); + builder.addSeparator("DARK").xy(5, row, CellConstraints.CENTER, CellConstraints.FILL); + row += 2; builder.addROLabel("Surfaces").xy(1, row) - .add(new SurfacePreview(lightColorScheme)).xy(3, row); + .add(new SurfacePreview(lightColorScheme)).xy(3, row) + .add(new SurfacePreview(darkColorScheme)).xy(5, row); row += 2; - builder.addROLabel("Surface container").xy(1, row) - .add(new ContainerPalettePreview(lightColorScheme.getNeutralContainerTokens())).xy(3, row); + builder.addROLabel("Neutral container").xy(1, row) + .add(new ContainerPalettePreview(lightColorScheme.getNeutralContainerTokens())).xy(3, row) + .add(new ContainerPalettePreview(darkColorScheme.getNeutralContainerTokens())).xy(5, row); row += 2; builder.addROLabel("Muted container").xy(1, row) - .add(new ContainerPalettePreview(lightColorScheme.getMutedContainerTokens())).xy(3, row); + .add(new ContainerPalettePreview(lightColorScheme.getMutedContainerTokens())).xy(3, row) + .add(new ContainerPalettePreview(darkColorScheme.getMutedContainerTokens())).xy(5, row); row += 2; builder.addROLabel("Tonal container").xy(1, row) - .add(new ContainerPalettePreview(lightColorScheme.getTonalContainerTokens())).xy(3, row); + .add(new ContainerPalettePreview(lightColorScheme.getTonalContainerTokens())).xy(3, row) + .add(new ContainerPalettePreview(darkColorScheme.getTonalContainerTokens())).xy(5, row); row += 2; builder.addROLabel("Primary container").xy(1, row) - .add(new ContainerPalettePreview(lightColorScheme.getPrimaryContainerTokens())).xy(3, row); + .add(new ContainerPalettePreview(lightColorScheme.getPrimaryContainerTokens())).xy(3, row) + .add(new ContainerPalettePreview(darkColorScheme.getPrimaryContainerTokens())).xy(5, row); - RadianceColorScheme2 darkColorScheme = ColorSchemeUtils.getDarkTonalBalancedColorScheme( - Hct.fromInt(0xFF76A8C8), 16.0, 10.0); row += 2; - builder.addSeparator("DARK").xyw(1, row, 3, CellConstraints.CENTER, CellConstraints.FILL); - row += 2; - builder.addROLabel("Surfaces").xy(1, row) - .add(new SurfacePreview(darkColorScheme)).xy(3, row); - row += 2; - builder.addROLabel("Surface container").xy(1, row) - .add(new ContainerPalettePreview(darkColorScheme.getNeutralContainerTokens())).xy(3, row); + builder.addROLabel("Neutral container").xy(1, row) + .add(new ContainerPreview(lightColorScheme.getNeutralContainerTokens(), "Neutral")).xy(3, row) + .add(new ContainerPreview(darkColorScheme.getNeutralContainerTokens(), "Neutral")).xy(5, row); row += 2; builder.addROLabel("Muted container").xy(1, row) - .add(new ContainerPalettePreview(darkColorScheme.getMutedContainerTokens())).xy(3, row); + .add(new ContainerPreview(lightColorScheme.getMutedContainerTokens(), "Muted")).xy(3, row) + .add(new ContainerPreview(darkColorScheme.getMutedContainerTokens(), "Muted")).xy(5, row); row += 2; builder.addROLabel("Tonal container").xy(1, row) - .add(new ContainerPalettePreview(darkColorScheme.getTonalContainerTokens())).xy(3, row); + .add(new ContainerPreview(lightColorScheme.getTonalContainerTokens(), "Tonal")).xy(3, row) + .add(new ContainerPreview(darkColorScheme.getTonalContainerTokens(), "Tonal")).xy(5, row); row += 2; builder.addROLabel("Primary container").xy(1, row) - .add(new ContainerPalettePreview(darkColorScheme.getPrimaryContainerTokens())).xy(3, row); + .add(new ContainerPreview(lightColorScheme.getPrimaryContainerTokens(), "Primary")).xy(3, row) + .add(new ContainerPreview(darkColorScheme.getPrimaryContainerTokens(), "Primary")).xy(5, row); + + this.add(builder.build()); this.pack(); @@ -109,7 +114,7 @@ public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame.setDefaultLookAndFeelDecorated(true); RadianceThemingCortex.GlobalScope.setFocusKind(RadianceThemingSlices.FocusKind.NONE); - RadianceThemingCortex.GlobalScope.setSkin(new CremeSkin()); + RadianceThemingCortex.GlobalScope.setSkin(new BusinessSkin.BusinessTonalSkin()); new PaletteDemo().setVisible(true); }); }