Skip to content

Commit

Permalink
Updates to the palette demo
Browse files Browse the repository at this point in the history
For #400
  • Loading branch information
kirill-grouchnikov committed Dec 17, 2024
1 parent b286b1a commit 1f14b6d
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,22 @@
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.*;

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);
Expand All @@ -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();
Expand All @@ -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);
});
}
Expand Down

0 comments on commit 1f14b6d

Please sign in to comment.