APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.java.swing.plaf.gtk

pack-priv Class GTKColorChooserPanel

extends AbstractColorChooserPanel
implements ChangeListener
Class Inheritance
All Implemented Interfaces
javax.swing.event.ChangeListener, java.util.EventListener
Annotations
@SuppressWarnings:serial
Imports
java.awt.*, java.awt.event.*, java.awt.image.*, javax.swing.*, javax.swing.colorchooser.*, javax.swing.event.*, javax.swing.plaf.*

A color chooser panel mimicking that of GTK's: a color wheel showing hue and a triangle that varies saturation and brightness.
Author
Scott Violet

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
GTKColorChooserPanel.ColorAction

Action class used for colors.

private class
GTKColorChooserPanel.ColorTriangle

Class responsible for rendering a color wheel and color triangle.

private static class

Field Summary

Modifier and TypeField and Description
private JSpinner
private float
private JTextField
private static final int
FLAGS_CHANGED_ANGLE

Flag indicating the angle, or hue, has changed and the triangle needs to be recreated.

private static final int
FLAGS_DRAGGING

Indicates the wheel is being dragged.

private static final int
FLAGS_DRAGGING_TRIANGLE

Indicates the triangle is being dragged.

private static final int
FLAGS_FOCUSED_TRIANGLE

Indicates the triangle has focus.

private static final int
FLAGS_FOCUSED_WHEEL

Indicates the wheel has focus.

private static final int
FLAGS_SETTING_COLOR

Indicates a color is being set and we should ignore setColor

private JSpinner
private float
private JSpinner
private JLabel
private JLabel
private static final float
private JSpinner
private float
private JSpinner
private boolean
private GTKColorChooserPanel.ColorTriangle
private JSpinner
Inherited from javax.swing.colorchooser.AbstractColorChooserPanel:
TRANSPARENCY_ENABLED_PROPERTY

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
add(Container parent, String key, JComponent widget, int x, int y)

Adds the widget creating a JLabel with the specified name.

protected void
buildChooser()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.buildChooser.

Builds and configures the widgets for the GTKColorChooserPanel.

pack-priv static void
compositeRequestFocus(Component component, boolean direction)

Convenience method to transfer focus to the next child of component.

private void
configureSpinner(JSpinner spinner, String name)

Configures the spinner.

private float
getBrightness()

Returns the brightness.

public Color
public int
public String
getDisplayName()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.getDisplayName.

Returns a user presentable description of this GTKColorChooserPane.

private float
getHue()

Returns the current amount of hue.

public Icon
getLargeDisplayIcon()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.getLargeDisplayIcon.

Returns the large display icon for the panel.

public int
getMnemonic()

Overrides javax.swing.colorchooser.AbstractColorChooserPanel.getMnemonic.

Returns the mnemonic to use with getDisplayName.

private float
getSaturation()

Returns the saturation.

public Icon
getSmallDisplayIcon()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.getSmallDisplayIcon.

Returns the small display icon for the panel.

private void
setBlue(int blue)

Resets the blue component of the selected color.

private void
setBrightness(float brightness)

Sets the brightness.

private void
setColor(Color
new Color
color
,
boolean
whether or not to update the spinners.
updateSpinners
,
boolean
if true, the hsb fields are updated based on the new color
updateHSB
,
boolean
if true, the model is set.
updateModel
)

Rests the color.

public void
setEnabled(boolean enabled)

Overrides javax.swing.JComponent.setEnabled.

Sets whether or not this component is enabled.

private static void
setEnabled(Container container, boolean enabled)

private void
setGreen(int green)

Resets the green component of the selected color.

private void
setHSB(float h, float s, float b)

Resets the hsb values.

private void
setHue(float hue, boolean update)

Sets the hue of the selected color and updates the display if necessary.

private void
setRed(int red)

Resets the red component of the selected color.

private void
setRGB(int rgb)

Resets the rgb values.

private void
setSaturation(float saturation)

Resets the saturation.

private void
setSaturationAndBrightness(float s, float b, boolean update)

Sets the saturation and brightness and updates the display if necessary.

public void
stateChanged(ChangeEvent e)

Implements javax.swing.event.ChangeListener.stateChanged.

ChangeListener method, updates the necessary display widgets.

public void
uninstallChooserPanel(JColorChooser enclosingChooser)

Overrides javax.swing.colorchooser.AbstractColorChooserPanel.uninstallChooserPanel.

Invoked when the panel is removed from the chooser.

public void
updateChooser()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.updateChooser.

Refreshes the display from the model.

Inherited from javax.swing.colorchooser.AbstractColorChooserPanel:
getColorFromModelgetColorSelectionModelinstallChooserPanelisColorTransparencySelectionEnabledpaintsetColorTransparencySelectionEnabled

Field Detail

blueSpinnerback to summary
private JSpinner blueSpinner
brightnessback to summary
private float brightness
colorNameTFback to summary
private JTextField colorNameTF
FLAGS_CHANGED_ANGLEback to summary
private static final int FLAGS_CHANGED_ANGLE

Flag indicating the angle, or hue, has changed and the triangle needs to be recreated.

FLAGS_DRAGGINGback to summary
private static final int FLAGS_DRAGGING

Indicates the wheel is being dragged.

FLAGS_DRAGGING_TRIANGLEback to summary
private static final int FLAGS_DRAGGING_TRIANGLE

Indicates the triangle is being dragged.

FLAGS_FOCUSED_TRIANGLEback to summary
private static final int FLAGS_FOCUSED_TRIANGLE

Indicates the triangle has focus.

FLAGS_FOCUSED_WHEELback to summary
private static final int FLAGS_FOCUSED_WHEEL

Indicates the wheel has focus.

FLAGS_SETTING_COLORback to summary
private static final int FLAGS_SETTING_COLOR

Indicates a color is being set and we should ignore setColor

greenSpinnerback to summary
private JSpinner greenSpinner
hueback to summary
private float hue
hueSpinnerback to summary
private JSpinner hueSpinner
labelback to summary
private JLabel label
lastLabelback to summary
private JLabel lastLabel
PI_3back to summary
private static final float PI_3
redSpinnerback to summary
private JSpinner redSpinner
saturationback to summary
private float saturation
saturationSpinnerback to summary
private JSpinner saturationSpinner
settingColorback to summary
private boolean settingColor
triangleback to summary
private GTKColorChooserPanel.ColorTriangle triangle
valueSpinnerback to summary
private JSpinner valueSpinner

Constructor Detail

GTKColorChooserPanelback to summary
pack-priv GTKColorChooserPanel()

Method Detail

addback to summary
private void add(Container parent, String key, JComponent widget, int x, int y)

Adds the widget creating a JLabel with the specified name.

buildChooserback to summary
protected void buildChooser()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.buildChooser.

Builds and configures the widgets for the GTKColorChooserPanel.

Annotations
@Override
compositeRequestFocusback to summary
pack-priv static void compositeRequestFocus(Component component, boolean direction)

Convenience method to transfer focus to the next child of component.

configureSpinnerback to summary
private void configureSpinner(JSpinner spinner, String name)

Configures the spinner.

getBrightnessback to summary
private float getBrightness()

Returns the brightness.

getColorback to summary
public Color getColor()
getDisplayedMnemonicIndexback to summary
public int getDisplayedMnemonicIndex()

Overrides javax.swing.colorchooser.AbstractColorChooserPanel.getDisplayedMnemonicIndex.

Character to underline that represents the mnemonic.

Annotations
@Override
getDisplayNameback to summary
public String getDisplayName()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.getDisplayName.

Returns a user presentable description of this GTKColorChooserPane.

Annotations
@Override
getHueback to summary
private float getHue()

Returns the current amount of hue.

getLargeDisplayIconback to summary
public Icon getLargeDisplayIcon()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.getLargeDisplayIcon.

Doc from javax.swing.colorchooser.AbstractColorChooserPanel.getLargeDisplayIcon.

Returns the large display icon for the panel.

Annotations
@Override
getMnemonicback to summary
public int getMnemonic()

Overrides javax.swing.colorchooser.AbstractColorChooserPanel.getMnemonic.

Returns the mnemonic to use with getDisplayName.

Annotations
@Override
getSaturationback to summary
private float getSaturation()

Returns the saturation.

getSmallDisplayIconback to summary
public Icon getSmallDisplayIcon()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.getSmallDisplayIcon.

Doc from javax.swing.colorchooser.AbstractColorChooserPanel.getSmallDisplayIcon.

Returns the small display icon for the panel.

Annotations
@Override
setBlueback to summary
private void setBlue(int blue)

Resets the blue component of the selected color.

setBrightnessback to summary
private void setBrightness(float brightness)

Sets the brightness.

setColorback to summary
private void setColor(Color color, boolean updateSpinners, boolean updateHSB, boolean updateModel)

Rests the color.

Parameters
color:Color

new Color

updateSpinners:boolean

whether or not to update the spinners.

updateHSB:boolean

if true, the hsb fields are updated based on the new color

updateModel:boolean

if true, the model is set.

setEnabledback to summary
public void setEnabled(boolean enabled)

Overrides javax.swing.JComponent.setEnabled.

Doc from javax.swing.JComponent.setEnabled.

Sets whether or not this component is enabled. A component that is enabled may respond to user input, while a component that is not enabled cannot respond to user input. Some components may alter their visual representation when they are disabled in order to provide feedback to the user that they cannot take input.

Note

Disabling a component does not disable its children.

Note

Disabling a lightweight component does not prevent it from receiving MouseEvents.

Annotations
@Override
setEnabledback to summary
private static void setEnabled(Container container, boolean enabled)
setGreenback to summary
private void setGreen(int green)

Resets the green component of the selected color.

setHSBback to summary
private void setHSB(float h, float s, float b)

Resets the hsb values.

setHueback to summary
private void setHue(float hue, boolean update)

Sets the hue of the selected color and updates the display if necessary.

setRedback to summary
private void setRed(int red)

Resets the red component of the selected color.

setRGBback to summary
private void setRGB(int rgb)

Resets the rgb values.

setSaturationback to summary
private void setSaturation(float saturation)

Resets the saturation.

setSaturationAndBrightnessback to summary
private void setSaturationAndBrightness(float s, float b, boolean update)

Sets the saturation and brightness and updates the display if necessary.

stateChangedback to summary
public void stateChanged(ChangeEvent e)

Implements javax.swing.event.ChangeListener.stateChanged.

ChangeListener method, updates the necessary display widgets.

Annotations
@Override
uninstallChooserPanelback to summary
public void uninstallChooserPanel(JColorChooser enclosingChooser)

Overrides javax.swing.colorchooser.AbstractColorChooserPanel.uninstallChooserPanel.

Doc from javax.swing.colorchooser.AbstractColorChooserPanel.uninstallChooserPanel.

Invoked when the panel is removed from the chooser. If override this, be sure to call super.

Annotations
@Override
updateChooserback to summary
public void updateChooser()

Implements abstract javax.swing.colorchooser.AbstractColorChooserPanel.updateChooser.

Refreshes the display from the model.

Annotations
@Override
com.sun.java.swing.plaf.gtk back to summary

private Class GTKColorChooserPanel.ColorAction

extends AbstractAction
Class Inheritance
Annotations
@SuppressWarnings:serial

Action class used for colors.

Field Summary

Modifier and TypeField and Description
private int
Inherited from javax.swing.AbstractAction:
changeSupportenabled

Constructor Summary

AccessConstructor and Description
pack-priv
ColorAction(String name, int type)

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Inherited from javax.swing.AbstractAction:
addPropertyChangeListenerclonefirePropertyChangegetKeysgetPropertyChangeListenersgetValueisEnabledputValueremovePropertyChangeListenersetEnabled

Field Detail

typeback to summary
private int type

Constructor Detail

ColorActionback to summary
pack-priv ColorAction(String name, int type)

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Annotations
@Override
com.sun.java.swing.plaf.gtk back to summary

private Class GTKColorChooserPanel.ColorTriangle

extends JPanel
Class Inheritance
Annotations
@SuppressWarnings:serial

Class responsible for rendering a color wheel and color triangle.

Field Summary

Modifier and TypeField and Description
private double
angle

Angle triangle is rotated by.

private int
circleX

X location of selected color indicator.

private int
circleY

Y location of selected color indicator.

private int
flags

Hides javax.swing.JComponent.flags.

Boolean bitmask.
private Image
triangleImage

Cached image of the triangle.

private Image
wheelImage

Cached image of the wheel.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean

Returns:

true if the location is valid.
adjustHue
(int
X location to adjust to, relative to the origin of the wheel
x
,
int
Y location to adjust to, relative to the origin of the wheel
y
,
boolean
if true the location is checked to make sure it is contained in the wheel, if false the location is constrained to fit in the wheel
check
)

Adjusts the hue based on the passed in location.

pack-priv boolean

Returns:

true if the location is valid
adjustSB
(int
X coordinate on the triangle to adjust to
x
,
int
Y coordinate on the triangle to adjust to
y
,
boolean
if true the location is checked to make sure it is contained in the triangle, if false the location is constrained to fit in the triangle.
checkLoc
)

Adjusts the saturation and brightness.

private int

Returns:

integer with red, green and blue components
colorWheelLocationToRGB
(int
X location to get color for
x
,
int
Y location to get color for
y
,
double
Radius from center of color wheel
rad
)

Returns the RGB color to use for the specified location.

pack-priv void
focusTriangle()

Gives focus to the triangle.

pack-priv void
focusWheel()

Gives focus to the wheel.

public Color
getColor()

Returns the selected color.

pack-priv int
getColorX()

Returns the x location of the selected color indicator.

pack-priv int
getColorY()

Returns the y location of the selected color indicator.

pack-priv GTKColorChooserPanel
getGTKColorChooserPanel()

Returns the GTKColorChooserPanel.

private Image
getImage(int size)

Returns an image representing the triangle and wheel.

private int
getIndicatorSize()

Returns the size of the color indicator.

private int
getTriangleCircumscribedRadius()

Returns the circumscribed radius of the triangle.

private Image

Returns:

Color wheel image
getWheelImage
(int
Integer giving size of color wheel.
size
)

Returns a color wheel image for the specified size.

private int
getWheelRadius()

Returns the radius of the wheel.

private int
getWheelWidth()

Returns the width of the wheel.

private int
getWheelXOrigin()

Returns the x origin of the wheel and triangle.

private int
getWheelYOrigin()

Returns y origin of the wheel and triangle.

pack-priv void
incrementHue(boolean positive)

Increments the hue.

private boolean
isSet(int flag)

Returns true if a particular flag has been set.

pack-priv boolean
isWheelFocused()

Returns true if the wheel currently has focus.

public void
paintComponent(Graphics g)

Overrides javax.swing.JComponent.paintComponent.

Calls the UI delegate's paint method, if the UI delegate is non-null.

private void
paintTriangle(Graphics g, int size, Color color)

protected void
processEvent(AWTEvent e)

Overrides java.awt.Container.processEvent.

Processes events on this container.

private void
setAngleFromHue(float hue)

Rotates the triangle to accommodate the passed in hue.

public void
setColor(float h, float s, float b)

Resets the selected color.

private void
setFlag(int flag, boolean value)

Hides javax.swing.JComponent.setFlag.

Updates the flags bitmask.

private void
setFocusType(int type)

Sets the focus to one of: 0 no one, 1 the wheel or 2 the triangle.

private void
setHueAngle(double angle)

Sets the angle representing the hue.

private void
setSaturationAndBrightness(float s, float b)

Sets the saturation and brightness.

private void
setSaturationAndBrightness(float s, float b, int newCircleX, int newCircleY)

Sets the saturation and brightness.

Inherited from javax.swing.JPanel:
getAccessibleContextgetUIgetUIClassIDparamStringsetUIupdateUI

Field Detail

angleback to summary
private double angle

Angle triangle is rotated by.

circleXback to summary
private int circleX

X location of selected color indicator.

circleYback to summary
private int circleY

Y location of selected color indicator.

flagsback to summary
private int flags

Hides javax.swing.JComponent.flags.

Boolean bitmask.

triangleImageback to summary
private Image triangleImage

Cached image of the triangle.

wheelImageback to summary
private Image wheelImage

Cached image of the wheel.

Constructor Detail

ColorTriangleback to summary
public ColorTriangle()

Method Detail

adjustHueback to summary
private boolean adjustHue(int x, int y, boolean check)

Adjusts the hue based on the passed in location.

Parameters
x:int

X location to adjust to, relative to the origin of the wheel

y:int

Y location to adjust to, relative to the origin of the wheel

check:boolean

if true the location is checked to make sure it is contained in the wheel, if false the location is constrained to fit in the wheel

Returns:boolean

true if the location is valid.

adjustSBback to summary
pack-priv boolean adjustSB(int x, int y, boolean checkLoc)

Adjusts the saturation and brightness. x and y give the location to adjust to and are relative to the origin of the wheel/triangle.

Parameters
x:int

X coordinate on the triangle to adjust to

y:int

Y coordinate on the triangle to adjust to

checkLoc:boolean

if true the location is checked to make sure it is contained in the triangle, if false the location is constrained to fit in the triangle.

Returns:boolean

true if the location is valid

colorWheelLocationToRGBback to summary
private int colorWheelLocationToRGB(int x, int y, double rad)

Returns the RGB color to use for the specified location. The passed in point must be on the color wheel and be relative to the origin of the color wheel.

Parameters
x:int

X location to get color for

y:int

Y location to get color for

rad:double

Radius from center of color wheel

Returns:int

integer with red, green and blue components

focusTriangleback to summary
pack-priv void focusTriangle()

Gives focus to the triangle.

focusWheelback to summary
pack-priv void focusWheel()

Gives focus to the wheel.

getColorback to summary
public Color getColor()

Returns the selected color.

getColorXback to summary
pack-priv int getColorX()

Returns the x location of the selected color indicator.

getColorYback to summary
pack-priv int getColorY()

Returns the y location of the selected color indicator.

getGTKColorChooserPanelback to summary
pack-priv GTKColorChooserPanel getGTKColorChooserPanel()

Returns the GTKColorChooserPanel.

getImageback to summary
private Image getImage(int size)

Returns an image representing the triangle and wheel.

getIndicatorSizeback to summary
private int getIndicatorSize()

Returns the size of the color indicator.

getTriangleCircumscribedRadiusback to summary
private int getTriangleCircumscribedRadius()

Returns the circumscribed radius of the triangle.

getWheelImageback to summary
private Image getWheelImage(int size)

Returns a color wheel image for the specified size.

Parameters
size:int

Integer giving size of color wheel.

Returns:Image

Color wheel image

getWheelRadiusback to summary
private int getWheelRadius()

Returns the radius of the wheel.

getWheelWidthback to summary
private int getWheelWidth()

Returns the width of the wheel.

getWheelXOriginback to summary
private int getWheelXOrigin()

Returns the x origin of the wheel and triangle.

getWheelYOriginback to summary
private int getWheelYOrigin()

Returns y origin of the wheel and triangle.

incrementHueback to summary
pack-priv void incrementHue(boolean positive)

Increments the hue.

isSetback to summary
private boolean isSet(int flag)

Returns true if a particular flag has been set.

isWheelFocusedback to summary
pack-priv boolean isWheelFocused()

Returns true if the wheel currently has focus.

paintComponentback to summary
public void paintComponent(Graphics g)

Overrides javax.swing.JComponent.paintComponent.

Doc from javax.swing.JComponent.paintComponent.

Calls the UI delegate's paint method, if the UI delegate is non-null. We pass the delegate a copy of the Graphics object to protect the rest of the paint code from irrevocable changes (for example, Graphics.translate).

If you override this in a subclass you should not make permanent changes to the passed in Graphics. For example, you should not alter the clip Rectangle or modify the transform. If you need to do these operations you may find it easier to create a new Graphics from the passed in Graphics and manipulate it. Further, if you do not invoke super's implementation you must honor the opaque property, that is if this component is opaque, you must completely fill in the background in an opaque color. If you do not honor the opaque property you will likely see visual artifacts.

The passed in Graphics object might have a transform other than the identify transform installed on it. In this case, you might get unexpected results if you cumulatively apply another transform.

Annotations
@Override
paintTriangleback to summary
private void paintTriangle(Graphics g, int size, Color color)
processEventback to summary
protected void processEvent(AWTEvent e)

Overrides java.awt.Container.processEvent.

Doc from java.awt.Container.processEvent.

Processes events on this container. If the event is a ContainerEvent, it invokes the processContainerEvent method, else it invokes its superclass's processEvent.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Annotations
@Override
setAngleFromHueback to summary
private void setAngleFromHue(float hue)

Rotates the triangle to accommodate the passed in hue.

setColorback to summary
public void setColor(float h, float s, float b)

Resets the selected color.

setFlagback to summary
private void setFlag(int flag, boolean value)

Hides javax.swing.JComponent.setFlag.

Updates the flags bitmask.

setFocusTypeback to summary
private void setFocusType(int type)

Sets the focus to one of: 0 no one, 1 the wheel or 2 the triangle.

setHueAngleback to summary
private void setHueAngle(double angle)

Sets the angle representing the hue.

setSaturationAndBrightnessback to summary
private void setSaturationAndBrightness(float s, float b)

Sets the saturation and brightness.

setSaturationAndBrightnessback to summary
private void setSaturationAndBrightness(float s, float b, int newCircleX, int newCircleY)

Sets the saturation and brightness.

com.sun.java.swing.plaf.gtk back to summary

private Class GTKColorChooserPanel.OpaqueLabel

extends JLabel
Class Inheritance
Annotations
@SuppressWarnings:serial

Field Summary

Inherited from javax.swing.JLabel:
labelFor

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
isOpaque()

Overrides javax.swing.JComponent.isOpaque.

Returns true if this component is completely opaque.

Inherited from javax.swing.JLabel:
checkHorizontalKeycheckVerticalKeygetAccessibleContextgetDisabledIcongetDisplayedMnemonicgetDisplayedMnemonicIndexgetHorizontalAlignmentgetHorizontalTextPositiongetIcongetIconTextGapgetLabelForgetTextgetUIgetUIClassIDgetVerticalAlignmentgetVerticalTextPositionimageUpdateparamStringsetDisabledIconsetDisplayedMnemonicsetDisplayedMnemonicsetDisplayedMnemonicIndexsetHorizontalAlignmentsetHorizontalTextPositionsetIconsetIconTextGapsetLabelForsetTextsetUIsetVerticalAlignmentsetVerticalTextPositionupdateUI

Constructor Detail

OpaqueLabelback to summary
private OpaqueLabel()

Method Detail

isOpaqueback to summary
public boolean isOpaque()

Overrides javax.swing.JComponent.isOpaque.

Doc from javax.swing.JComponent.isOpaque.

Returns true if this component is completely opaque.

An opaque component paints every pixel within its rectangular bounds. A non-opaque component paints only a subset of its pixels or none at all, allowing the pixels underneath it to "show through". Therefore, a component that does not fully paint its pixels provides a degree of transparency.

Subclasses that guarantee to always completely paint their contents should override this method and return true.

Annotations
@Override