Package ca.cgjennings.ui.theme
Class Palette
- java.lang.Object
-
- ca.cgjennings.ui.theme.Palette
-
public final class Palette extends java.lang.ObjectA theme-aware palette of standard colours. The same standard set of named colours is available with variations suitable for different contexts. The colours are divided into subsets, first by brightness, then by opacity. For example, you can requestPalette.get.dark.opaque.blue.The special subsets
foregroundandbackgroundwill be either light or dark depending on the theme. For example, if the theme is dark, then asking for a background colour returns a dark colour, matching the theme's dark background; asking for a foreground colour returns a light colour (to contrast with the dark background).The special colours
whiteandblackdo not have light and dark versions: these return white or black as requested. The special colourstextandfillreturn colours that can be used for text and a solid background, respectively.- Since:
- 3.4
- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPalette.SubsetEncapsulates a palette subset broken into opaque and slightly translucent groups.static classPalette.Variant
-
Field Summary
Fields Modifier and Type Field Description Palette.SubsetbackgroundEither the light or dark subset, chosen to contrast with the foreground based on the theme.Palette.SubsetdarkThe dark subset of the palette.Palette.SubsetforegroundEither the light or dark subset, chosen to contrast with the background based on the theme.static PalettegetThe current palette.Palette.SubsetlightThe light subset of the palette.static intNUM_COLORSReturns the number of base colours (red, orange, etc.).Palette.SubsetpastelThe pastel subset of the palette.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Palette.Subsetcontrasting(int rgb)Returns either the light or dark palette subset, whichever will contrast best with the specified colour.Palette.Subsetcontrasting(java.awt.Component c)Returns either the light or dark palette subset, whichever will contrast best with the specified background.static PalettecreateDefaultPalette()Returns a new palette filled with default values.voiddebugDump()Inserts a chart of this palette's colours into the script console.static PalettefromImage(java.awt.image.BufferedImage im)Creates a palette from an image.Palette.Subsetharmonizing(int rgb)Returns either the light or dark palette subset, whichever will harmonize best with the specified colour.Palette.Subsetharmonizing(java.awt.Component c)Returns either the light or dark palette subset, whichever will harmonize best with the specified background.java.awt.image.BufferedImagetoImage()Returns the colours of this palette as an image in which y-index is the base colour and the x-index is the variant.
-
-
-
Field Detail
-
NUM_COLORS
public static final int NUM_COLORS
Returns the number of base colours (red, orange, etc.). Each base colour is available as either light or dark, and opaque or translucent.- See Also:
- Constant Field Values
-
get
public static Palette get
The current palette.
-
pastel
public final Palette.Subset pastel
The pastel subset of the palette. These are brighter and paler than the light subset.
-
light
public final Palette.Subset light
The light subset of the palette.
-
dark
public final Palette.Subset dark
The dark subset of the palette.
-
foreground
public final Palette.Subset foreground
Either the light or dark subset, chosen to contrast with the background based on the theme.
-
background
public final Palette.Subset background
Either the light or dark subset, chosen to contrast with the foreground based on the theme.
-
-
Method Detail
-
contrasting
public final Palette.Subset contrasting(java.awt.Component c)
Returns either the light or dark palette subset, whichever will contrast best with the specified background. If the component is null or its background cannot be determined, a subset based on the theme is returned.- Parameters:
c- the component to consider as the source of the background
-
contrasting
public final Palette.Subset contrasting(int rgb)
Returns either the light or dark palette subset, whichever will contrast best with the specified colour. Any alpha component is ignored.- Parameters:
rgb- the RGB value of the colour to contrast with
-
harmonizing
public final Palette.Subset harmonizing(java.awt.Component c)
Returns either the light or dark palette subset, whichever will harmonize best with the specified background. This is simply the opposite of the subset returned bycontrasting(java.awt.Component).- Parameters:
c- the component to consider as the source of the background
-
harmonizing
public final Palette.Subset harmonizing(int rgb)
Returns either the light or dark palette subset, whichever will harmonize best with the specified colour. This is simply the opposite of the subset returned bycontrasting(int).- Parameters:
c- the RGB value of the colour to contrast with
-
createDefaultPalette
public static Palette createDefaultPalette()
Returns a new palette filled with default values. When using the palette to render content, use the current palette.- Returns:
- a new default palette
-
toImage
public java.awt.image.BufferedImage toImage()
Returns the colours of this palette as an image in which y-index is the base colour and the x-index is the variant. The order of the variants is as follows: opaque (light then dark), followed by translucent (light then dark).- Returns:
- a non-null image in which each pixel represents one colour in the palette
-
fromImage
public static Palette fromImage(java.awt.image.BufferedImage im)
Creates a palette from an image. The image uses the same layout as that oftoImage(). The image may be larger than necessary, but an exception will be thrown if any colours are missing.- Parameters:
im- the image to convert into a palette- Returns:
- the palette image
-
debugDump
public void debugDump()
Inserts a chart of this palette's colours into the script console.
-
-