diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic.properties
index 6087def3607ad0e1ff5767b4b77da96cc14795d7..4dac249bfa02d51e370a6693bd856ab04fd70f2a 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=82
ColorChooser.sampleText=Sample Text Sample Text
ColorChooser.swatchesNameText=Swatches
ColorChooser.swatchesMnemonic=83
-ColorChooser.swatchesDisplayedMnemonicIndex=0
ColorChooser.swatchesRecentText=Recent:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=G
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=Red
ColorChooser.rgbRedMnemonic=68
ColorChooser.rgbGreenText=Green
ColorChooser.rgbGreenMnemonic=78
ColorChooser.rgbBlueText=Blue
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_de.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_de.properties
index 93660548035468b21864fdfb7bcdc953afc12d11..b345597773881824428b934cda91e5d4f2b9b6bd 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_de.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_de.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=90
ColorChooser.sampleText=Beispieltext Beispieltext
ColorChooser.swatchesNameText=Muster
ColorChooser.swatchesMnemonic=77
-ColorChooser.swatchesDisplayedMnemonicIndex=0
ColorChooser.swatchesRecentText=Aktuell:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=G
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=Rot
ColorChooser.rgbRedMnemonic=82
ColorChooser.rgbGreenText=Gr\u00fcn
ColorChooser.rgbGreenMnemonic=78
ColorChooser.rgbBlueText=Blau
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_es.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_es.properties
index b553b26f06525ebef312d8cbd5cf0869e12f0f7f..75877dd656062c436e9e2b3b1731b8daba8a6f29 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_es.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_es.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=82
ColorChooser.sampleText=Texto de ejemplo Texto de ejemplo
ColorChooser.swatchesNameText=Muestras
ColorChooser.swatchesMnemonic=77
-ColorChooser.swatchesDisplayedMnemonicIndex=0
ColorChooser.swatchesRecentText=Reciente:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=V
-ColorChooser.hsbBlueText=A
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=Rojo
ColorChooser.rgbRedMnemonic=74
ColorChooser.rgbGreenText=Verde
ColorChooser.rgbGreenMnemonic=86
ColorChooser.rgbBlueText=Azul
ColorChooser.rgbBlueMnemonic=76
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_fr.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_fr.properties
index b18de0274a8730ab954abe08225f4e9e20a4a3d4..333a1a82fa1d8752299892ccd84cd4bd1c7de94b 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_fr.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_fr.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=82
ColorChooser.sampleText=Echantillon de texte Echantillon de texte
ColorChooser.swatchesNameText=Echantillons
ColorChooser.swatchesMnemonic=69
-ColorChooser.swatchesDisplayedMnemonicIndex=0
ColorChooser.swatchesRecentText=Dernier :
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=V
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RVB
ColorChooser.rgbMnemonic=86
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=Rouge
ColorChooser.rgbRedMnemonic=71
ColorChooser.rgbGreenText=Vert
ColorChooser.rgbGreenMnemonic=84
ColorChooser.rgbBlueText=Bleu
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_it.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_it.properties
index 1c9f3790e6fbbbacaf63cbd67ce2b4c8c1a50141..7bc69dbcf5e45583730c7822c5b90d301e94c229 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_it.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_it.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=82
ColorChooser.sampleText=Testo di prova Testo di prova
ColorChooser.swatchesNameText=Colori campione
ColorChooser.swatchesMnemonic=67
-ColorChooser.swatchesDisplayedMnemonicIndex=0
ColorChooser.swatchesRecentText=Recenti:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=G
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=Rosso
ColorChooser.rgbRedMnemonic=79
ColorChooser.rgbGreenText=Verde
ColorChooser.rgbGreenMnemonic=69
ColorChooser.rgbBlueText=Blu
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ja.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ja.properties
index 1b5a131cabde008e5c76b926bb78114cf6faffa7..5603e9aa1bc09c79c2adf13930945d5454500362 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ja.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ja.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=82
ColorChooser.sampleText=\u30b5\u30f3\u30d7\u30eb\u30c6\u30ad\u30b9\u30c8 \u30b5\u30f3\u30d7\u30eb\u30c6\u30ad\u30b9\u30c8
ColorChooser.swatchesNameText=\u30b5\u30f3\u30d7\u30eb(S)
ColorChooser.swatchesMnemonic=83
-ColorChooser.swatchesDisplayedMnemonicIndex=5
ColorChooser.swatchesRecentText=\u6700\u65b0:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=G
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=\u8d64(D)
ColorChooser.rgbRedMnemonic=68
ColorChooser.rgbGreenText=\u7dd1(N)
ColorChooser.rgbGreenMnemonic=78
ColorChooser.rgbBlueText=\u9752(B)
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ko.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ko.properties
index 9b873a43a61bcf05987a333192fb6237223d4f20..f3866d01f31f8bed0405cc6f7c4713d220359514 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ko.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ko.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=82
ColorChooser.sampleText=\uc0d8\ud50c \ud14d\uc2a4\ud2b8 \uc0d8\ud50c \ud14d\uc2a4\ud2b8
ColorChooser.swatchesNameText=\uacac\ubcf8(S)
ColorChooser.swatchesMnemonic=83
-ColorChooser.swatchesDisplayedMnemonicIndex=3
ColorChooser.swatchesRecentText=\ucd5c\uadfc \ubaa9\ub85d:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=G
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=\ube68\uac04\uc0c9(D)
ColorChooser.rgbRedMnemonic=68
ColorChooser.rgbGreenText=\ub179\uc0c9(N)
ColorChooser.rgbGreenMnemonic=78
ColorChooser.rgbBlueText=\ud30c\ub780\uc0c9(B)
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_sv.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_sv.properties
index 2b8561b812e83b7de7d18cd73ab5525ad77dce5b..17ef3b2be265be857aedcc9c5027a6c660b8a795 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_sv.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_sv.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=84
ColorChooser.sampleText=Exempeltext Exempeltext
ColorChooser.swatchesNameText=Prov
ColorChooser.swatchesMnemonic=80
-ColorChooser.swatchesDisplayedMnemonicIndex=0
ColorChooser.swatchesRecentText=Tidigare:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=G
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=R\u00f6d
ColorChooser.rgbRedMnemonic=82
ColorChooser.rgbGreenText=Gr\u00f6n
ColorChooser.rgbGreenMnemonic=71
ColorChooser.rgbBlueText=Bl\u00e5
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_CN.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_CN.properties
index 7ef35330d865a29703dc9b50f09ce6de22d0dfea..b030c20a944d95f0be26af00df8bdaf1c34146d5 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_CN.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_CN.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=82
ColorChooser.sampleText=\u6837\u54c1\u6587\u672c \u6837\u54c1\u6587\u672c
ColorChooser.swatchesNameText=\u6837\u54c1(S)
ColorChooser.swatchesMnemonic=83
-ColorChooser.swatchesDisplayedMnemonicIndex=3
ColorChooser.swatchesRecentText=\u6700\u8fd1:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=G
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=\u7ea2
ColorChooser.rgbRedMnemonic=68
ColorChooser.rgbGreenText=\u7eff
ColorChooser.rgbGreenMnemonic=78
ColorChooser.rgbBlueText=\u84dd
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_TW.properties b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_TW.properties
index dba0d76de2884113001e0d72dd7a2e68495ceb53..47f99f0dcc90f5c6d736729c223288390c8f8292 100644
--- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_TW.properties
+++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_TW.properties
@@ -101,30 +101,41 @@ ColorChooser.resetMnemonic=82
ColorChooser.sampleText=\u7bc4\u4f8b\u6587\u5b57 \u7bc4\u4f8b\u6587\u5b57
ColorChooser.swatchesNameText=\u8abf\u8272\u677f(S)
ColorChooser.swatchesMnemonic=83
-ColorChooser.swatchesDisplayedMnemonicIndex=4
ColorChooser.swatchesRecentText=\u6700\u65b0\u9078\u64c7:
-ColorChooser.hsbNameText=HSB
# Each of the ColorChooser types can define a mnemonic, as a KeyEvent.VK_XXX
# constant, and an index into the text to render the mnemonic as. The
# mnemonic is xxxMnemonic and the index of the character to underline is
# xxxDisplayedMnemonicIndex.
-ColorChooser.hsbMnemonic=72
-ColorChooser.hsbDisplayedMnemonicIndex=0
-ColorChooser.hsbHueText=H
-ColorChooser.hsbSaturationText=S
-ColorChooser.hsbBrightnessText=B
-ColorChooser.hsbRedText=R
-ColorChooser.hsbGreenText=G
-ColorChooser.hsbBlueText=B
+ColorChooser.hsvNameText=HSV
+ColorChooser.hsvMnemonic=72
+ColorChooser.hsvHueText=Hue
+ColorChooser.hsvSaturationText=Saturation
+ColorChooser.hsvValueText=Value
+ColorChooser.hsvTransparencyText=Transparency
+ColorChooser.hslNameText=HSL
+ColorChooser.hslMnemonic=76
+ColorChooser.hslHueText=Hue
+ColorChooser.hslSaturationText=Saturation
+ColorChooser.hslLightnessText=Lightness
+ColorChooser.hslTransparencyText=Transparency
ColorChooser.rgbNameText=RGB
ColorChooser.rgbMnemonic=71
-ColorChooser.rgbDisplayedMnemonicIndex=1
ColorChooser.rgbRedText=\u7d05\u8272(D)
ColorChooser.rgbRedMnemonic=68
ColorChooser.rgbGreenText=\u7da0\u8272(N)
ColorChooser.rgbGreenMnemonic=78
ColorChooser.rgbBlueText=\u85cd\u8272(B)
ColorChooser.rgbBlueMnemonic=66
+ColorChooser.rgbAlphaText=Alpha
+ColorChooser.rgbHexCodeText=Color Code
+ColorChooser.rgbHexCodeMnemonic=67
+ColorChooser.cmykNameText=CMYK
+ColorChooser.cmykMnemonic=77
+ColorChooser.cmykCyanText=Cyan
+ColorChooser.cmykMagentaText=Magenta
+ColorChooser.cmykYellowText=Yellow
+ColorChooser.cmykBlackText=Black
+ColorChooser.cmykAlphaText=Alpha
############ OPTION PANE STRINGS #############
# Mnemonic keys correspond to KeyEvent.VK_XXX constant
diff --git a/src/share/classes/javax/swing/colorchooser/ColorChooserComponentFactory.java b/src/share/classes/javax/swing/colorchooser/ColorChooserComponentFactory.java
index b36c6524d8a127d10ee625ba3cb5d718e32a1673..0ee01e6cb5ac2c6b365a8d2db86b7619ffb011e0 100644
--- a/src/share/classes/javax/swing/colorchooser/ColorChooserComponentFactory.java
+++ b/src/share/classes/javax/swing/colorchooser/ColorChooserComponentFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1998-2001 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,7 @@
package javax.swing.colorchooser;
-import javax.swing.*;
-
-
+import javax.swing.JComponent;
/**
* A class designed to produce preconfigured "accessory" objects to
@@ -49,16 +47,17 @@ public class ColorChooserComponentFactory {
private ColorChooserComponentFactory() { } // can't instantiate
-
public static AbstractColorChooserPanel[] getDefaultChooserPanels() {
- AbstractColorChooserPanel[] choosers = { new DefaultSwatchChooserPanel(),
- new DefaultHSBChooserPanel(),
- new DefaultRGBChooserPanel() };
- return choosers;
+ return new AbstractColorChooserPanel[] {
+ new DefaultSwatchChooserPanel(),
+ new ColorChooserPanel(new ColorModelHSV()),
+ new ColorChooserPanel(new ColorModelHSL()),
+ new ColorChooserPanel(new ColorModel()),
+ new ColorChooserPanel(new ColorModelCMYK()),
+ };
}
public static JComponent getPreviewPanel() {
return new DefaultPreviewPanel();
}
-
}
diff --git a/src/share/classes/javax/swing/colorchooser/ColorChooserPanel.java b/src/share/classes/javax/swing/colorchooser/ColorChooserPanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..46b5351c6958a1f408916baf1394ada8ecb23d70
--- /dev/null
+++ b/src/share/classes/javax/swing/colorchooser/ColorChooserPanel.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.swing.colorchooser;
+
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import javax.swing.Icon;
+import javax.swing.JComponent;
+import javax.swing.JFormattedTextField;
+import javax.swing.JLabel;
+import javax.swing.SwingConstants;
+
+final class ColorChooserPanel extends AbstractColorChooserPanel implements PropertyChangeListener {
+
+ private static final int MASK = 0xFF000000;
+ private final ColorModel model;
+ private final ColorPanel panel;
+ private final DiagramComponent slider;
+ private final DiagramComponent diagram;
+ private final JFormattedTextField text;
+ private final JLabel label;
+
+ ColorChooserPanel(ColorModel model) {
+ this.model = model;
+ this.panel = new ColorPanel(this.model);
+ this.slider = new DiagramComponent(this.panel, false);
+ this.diagram = new DiagramComponent(this.panel, true);
+ this.text = new JFormattedTextField();
+ this.label = new JLabel(null, null, SwingConstants.RIGHT);
+ ValueFormatter.init(6, true, this.text);
+ }
+
+ @Override
+ public void updateChooser() {
+ Color color = getColorFromModel();
+ this.panel.setColor(color);
+ this.text.setValue(Integer.valueOf(color.getRGB()));
+ this.slider.repaint();
+ this.diagram.repaint();
+ }
+
+ @Override
+ protected void buildChooser() {
+ if (0 == getComponentCount()) {
+ setLayout(new GridBagLayout());
+
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ gbc.gridx = 3;
+ gbc.gridwidth = 2;
+ gbc.weighty = 1.0;
+ gbc.anchor = GridBagConstraints.NORTH;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ gbc.insets.top = 10;
+ gbc.insets.right = 10;
+ add(this.panel, gbc);
+
+ gbc.gridwidth = 1;
+ gbc.weightx = 1.0;
+ gbc.weighty = 0.0;
+ gbc.anchor = GridBagConstraints.CENTER;
+ gbc.insets.right = 5;
+ gbc.insets.bottom = 10;
+ add(this.label, gbc);
+
+ gbc.gridx = 4;
+ gbc.weightx = 0.0;
+ gbc.insets.right = 10;
+ add(this.text, gbc);
+
+ gbc.gridx = 2;
+ gbc.gridheight = 2;
+ gbc.anchor = GridBagConstraints.NORTH;
+ gbc.ipadx = this.text.getPreferredSize().height;
+ gbc.ipady = getPreferredSize().height;
+ add(this.slider, gbc);
+
+ gbc.gridx = 1;
+ gbc.insets.left = 10;
+ gbc.ipadx = gbc.ipady;
+ add(this.diagram, gbc);
+
+ this.label.setLabelFor(this.text);
+ this.text.addPropertyChangeListener("value", this); // NON-NLS: the property name
+ this.slider.setBorder(this.text.getBorder());
+ this.diagram.setBorder(this.text.getBorder());
+
+ setInheritsPopupMenu(this, true); // CR:4966112
+ }
+ String label = this.model.getText(this, "HexCode"); // NON-NLS: suffix
+ boolean visible = label != null;
+ this.text.setVisible(visible);
+ this.label.setVisible(visible);
+ if (visible) {
+ this.label.setText(label);
+ int mnemonic = this.model.getInteger(this, "HexCodeMnemonic"); // NON-NLS: suffix
+ if (mnemonic > 0) {
+ this.label.setDisplayedMnemonic(mnemonic);
+ mnemonic = this.model.getInteger(this, "HexCodeMnemonicIndex"); // NON-NLS: suffix
+ if (mnemonic >= 0) {
+ this.label.setDisplayedMnemonicIndex(mnemonic);
+ }
+ }
+ }
+ this.panel.buildPanel();
+ }
+
+ @Override
+ public String getDisplayName() {
+ return this.model.getText(this, "Name"); // NON-NLS: suffix
+ }
+
+ @Override
+ public int getMnemonic() {
+ return this.model.getInteger(this, "Mnemonic"); // NON-NLS: suffix
+ }
+
+ @Override
+ public int getDisplayedMnemonicIndex() {
+ return this.model.getInteger(this, "DisplayedMnemonicIndex"); // NON-NLS: suffix
+ }
+
+ @Override
+ public Icon getSmallDisplayIcon() {
+ return null;
+ }
+
+ @Override
+ public Icon getLargeDisplayIcon() {
+ return null;
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ Object object = event.getNewValue();
+ if (object instanceof Integer) {
+ int value = MASK & getColorFromModel().getRGB() | (Integer) object;
+ getColorSelectionModel().setSelectedColor(new Color(value, true));
+ }
+ this.text.selectAll();
+ }
+
+ /**
+ * Allows to show context popup for all components recursively.
+ *
+ * @param component the root component of the tree
+ * @param value whether or not the popup menu is inherited
+ */
+ private static void setInheritsPopupMenu(JComponent component, boolean value) {
+ component.setInheritsPopupMenu(value);
+ for (Object object : component.getComponents()) {
+ if (object instanceof JComponent) {
+ setInheritsPopupMenu((JComponent) object, value);
+ }
+ }
+ }
+}
diff --git a/src/share/classes/javax/swing/colorchooser/ColorModel.java b/src/share/classes/javax/swing/colorchooser/ColorModel.java
new file mode 100644
index 0000000000000000000000000000000000000000..955ed162663d6f34434b91f6c2b499590c37c0d6
--- /dev/null
+++ b/src/share/classes/javax/swing/colorchooser/ColorModel.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.swing.colorchooser;
+
+import java.awt.Component;
+import javax.swing.UIManager;
+
+class ColorModel {
+
+ private final String prefix;
+ private final String[] labels;
+
+ ColorModel(String name, String... labels) {
+ this.prefix = "ColorChooser." + name; // NON-NLS: default prefix
+ this.labels = labels;
+ }
+
+ ColorModel() {
+ this("rgb", "Red", "Green", "Blue", "Alpha"); // NON-NLS: components
+ }
+
+ void setColor(int color, float[] model) {
+ model[0] = normalize(color >> 16);
+ model[1] = normalize(color >> 8);
+ model[2] = normalize(color);
+ model[3] = normalize(color >> 24);
+ }
+
+ int getColor(float[] model) {
+ return to8bit(model[2]) | (to8bit(model[1]) << 8) | (to8bit(model[0]) << 16) | (to8bit(model[3]) << 24);
+ }
+
+ int getCount() {
+ return this.labels.length;
+ }
+
+ int getMinimum(int index) {
+ return 0;
+ }
+
+ int getMaximum(int index) {
+ return 255;
+ }
+
+ float getDefault(int index) {
+ return 0.0f;
+ }
+
+ final String getLabel(Component component, int index) {
+ return getText(component, this.labels[index]);
+ }
+
+ private static float normalize(int value) {
+ return (float) (value & 0xFF) / 255.0f;
+ }
+
+ private static int to8bit(float value) {
+ return (int) (255.0f * value);
+ }
+
+ final String getText(Component component, String suffix) {
+ return UIManager.getString(this.prefix + suffix + "Text", component.getLocale()); // NON-NLS: default postfix
+ }
+
+ final int getInteger(Component component, String suffix) {
+ Object value = UIManager.get(this.prefix + suffix, component.getLocale());
+ if (value instanceof Integer) {
+ return (Integer) value;
+ }
+ if (value instanceof String) {
+ try {
+ return Integer.parseInt((String) value);
+ }
+ catch (NumberFormatException exception) {
+ }
+ }
+ return -1;
+ }
+}
diff --git a/src/share/classes/javax/swing/colorchooser/ColorModelCMYK.java b/src/share/classes/javax/swing/colorchooser/ColorModelCMYK.java
new file mode 100644
index 0000000000000000000000000000000000000000..77a7ca555941f6887945351eeb6a1dc01e7eb938
--- /dev/null
+++ b/src/share/classes/javax/swing/colorchooser/ColorModelCMYK.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.swing.colorchooser;
+
+final class ColorModelCMYK extends ColorModel {
+
+ ColorModelCMYK() {
+ super("cmyk", "Cyan", "Magenta", "Yellow", "Black", "Alpha"); // NON-NLS: components
+ }
+
+ @Override
+ void setColor(int color, float[] space) {
+ super.setColor(color, space);
+ space[4] = space[3];
+ RGBtoCMYK(space, space);
+ }
+
+ @Override
+ int getColor(float[] space) {
+ CMYKtoRGB(space, space);
+ space[3] = space[4];
+ return super.getColor(space);
+ }
+
+ /**
+ * Converts CMYK components of a color to a set of RGB components.
+ *
+ * @param cmyk a float array with length equal to
+ * the number of CMYK components
+ * @param rgb a float array with length of at least 3
+ * that contains RGB components of a color
+ * @return a float array that contains RGB components
+ */
+ private static float[] CMYKtoRGB(float[] cmyk, float[] rgb) {
+ if (rgb == null) {
+ rgb = new float[3];
+ }
+ rgb[0] = 1.0f + cmyk[0] * cmyk[3] - cmyk[3] - cmyk[0];
+ rgb[1] = 1.0f + cmyk[1] * cmyk[3] - cmyk[3] - cmyk[1];
+ rgb[2] = 1.0f + cmyk[2] * cmyk[3] - cmyk[3] - cmyk[2];
+ return rgb;
+ }
+
+ /**
+ * Converts RGB components of a color to a set of CMYK components.
+ *
+ * @param rgb a float array with length of at least 3
+ * that contains RGB components of a color
+ * @param cmyk a float array with length equal to
+ * the number of CMYK components
+ * @return a float array that contains CMYK components
+ */
+ private static float[] RGBtoCMYK(float[] rgb, float[] cmyk) {
+ if (cmyk == null) {
+ cmyk = new float[4];
+ }
+ float max = ColorModelHSL.max(rgb[0], rgb[1], rgb[2]);
+ if (max > 0.0f) {
+ cmyk[0] = 1.0f - rgb[0] / max;
+ cmyk[1] = 1.0f - rgb[1] / max;
+ cmyk[2] = 1.0f - rgb[2] / max;
+ }
+ else {
+ cmyk[0] = 0.0f;
+ cmyk[1] = 0.0f;
+ cmyk[2] = 0.0f;
+ }
+ cmyk[3] = 1.0f - max;
+ return cmyk;
+ }
+}
diff --git a/src/share/classes/javax/swing/colorchooser/ColorModelHSL.java b/src/share/classes/javax/swing/colorchooser/ColorModelHSL.java
new file mode 100644
index 0000000000000000000000000000000000000000..85b0c8e5da4d3b7b129f3498c97875341b799f18
--- /dev/null
+++ b/src/share/classes/javax/swing/colorchooser/ColorModelHSL.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.swing.colorchooser;
+
+final class ColorModelHSL extends ColorModel {
+
+ ColorModelHSL() {
+ super("hsl", "Hue", "Saturation", "Lightness", "Transparency"); // NON-NLS: components
+ }
+
+ @Override
+ void setColor(int color, float[] space) {
+ super.setColor(color, space);
+ RGBtoHSL(space, space);
+ space[3] = 1.0f - space[3];
+ }
+
+ @Override
+ int getColor(float[] space) {
+ space[3] = 1.0f - space[3];
+ HSLtoRGB(space, space);
+ return super.getColor(space);
+ }
+
+ @Override
+ int getMaximum(int index) {
+ return (index == 0) ? 360 : 100;
+ }
+
+ @Override
+ float getDefault(int index) {
+ return (index == 0) ? -1.0f : (index == 2) ? 0.5f : 1.0f;
+ }
+
+ /**
+ * Converts HSL components of a color to a set of RGB components.
+ *
+ * @param hsl a float array with length equal to
+ * the number of HSL components
+ * @param rgb a float array with length of at least 3
+ * that contains RGB components of a color
+ * @return a float array that contains RGB components
+ */
+ private static float[] HSLtoRGB(float[] hsl, float[] rgb) {
+ if (rgb == null) {
+ rgb = new float[3];
+ }
+ float hue = hsl[0];
+ float saturation = hsl[1];
+ float lightness = hsl[2];
+
+ if (saturation > 0.0f) {
+ hue = (hue < 1.0f) ? hue * 6.0f : 0.0f;
+ float q = lightness + saturation * ((lightness > 0.5f) ? 1.0f - lightness : lightness);
+ float p = 2.0f * lightness - q;
+ rgb[0]= normalize(q, p, (hue < 4.0f) ? (hue + 2.0f) : (hue - 4.0f));
+ rgb[1]= normalize(q, p, hue);
+ rgb[2]= normalize(q, p, (hue < 2.0f) ? (hue + 4.0f) : (hue - 2.0f));
+ }
+ else {
+ rgb[0] = lightness;
+ rgb[1] = lightness;
+ rgb[2] = lightness;
+ }
+ return rgb;
+ }
+
+ /**
+ * Converts RGB components of a color to a set of HSL components.
+ *
+ * @param rgb a float array with length of at least 3
+ * that contains RGB components of a color
+ * @param hsl a float array with length equal to
+ * the number of HSL components
+ * @return a float array that contains HSL components
+ */
+ private static float[] RGBtoHSL(float[] rgb, float[] hsl) {
+ if (hsl == null) {
+ hsl = new float[3];
+ }
+ float max = max(rgb[0], rgb[1], rgb[2]);
+ float min = min(rgb[0], rgb[1], rgb[2]);
+
+ float summa = max + min;
+ float saturation = max - min;
+ if (saturation > 0.0f) {
+ saturation /= (summa > 1.0f)
+ ? 2.0f - summa
+ : summa;
+ }
+ hsl[0] = getHue(rgb[0], rgb[1], rgb[2], max, min);
+ hsl[1] = saturation;
+ hsl[2] = summa / 2.0f;
+ return hsl;
+ }
+
+ /**
+ * Returns the smaller of three color components.
+ *
+ * @param red the red component of the color
+ * @param green the green component of the color
+ * @param blue the blue component of the color
+ * @return the smaller of {@code red}, {@code green} and {@code blue}
+ */
+ static float min(float red, float green, float blue) {
+ float min = (red < green) ? red : green;
+ return (min < blue) ? min : blue;
+ }
+
+ /**
+ * Returns the larger of three color components.
+ *
+ * @param red the red component of the color
+ * @param green the green component of the color
+ * @param blue the blue component of the color
+ * @return the larger of {@code red}, {@code green} and {@code blue}
+ */
+ static float max(float red, float green, float blue) {
+ float max = (red > green) ? red : green;
+ return (max > blue) ? max : blue;
+ }
+
+ /**
+ * Calculates the hue component for HSL and HSV color spaces.
+ *
+ * @param red the red component of the color
+ * @param green the green component of the color
+ * @param blue the blue component of the color
+ * @param max the larger of {@code red}, {@code green} and {@code blue}
+ * @param min the smaller of {@code red}, {@code green} and {@code blue}
+ * @return the hue component
+ */
+ static float getHue(float red, float green, float blue, float max, float min) {
+ float hue = max - min;
+ if (hue > 0.0f) {
+ if (max == red) {
+ hue = (green - blue) / hue;
+ if (hue < 0.0f) {
+ hue += 6.0f;
+ }
+ }
+ else if (max == green) {
+ hue = 2.0f + (blue - red) / hue;
+ }
+ else /*max == blue*/ {
+ hue = 4.0f + (red - green) / hue;
+ }
+ hue /= 6.0f;
+ }
+ return hue;
+ }
+
+ private static float normalize(float q, float p, float color) {
+ if (color < 1.0f) {
+ return p + (q - p) * color;
+ }
+ if (color < 3.0f) {
+ return q;
+ }
+ if (color < 4.0f) {
+ return p + (q - p) * (4.0f - color);
+ }
+ return p;
+ }
+}
diff --git a/src/share/classes/javax/swing/colorchooser/ColorModelHSV.java b/src/share/classes/javax/swing/colorchooser/ColorModelHSV.java
new file mode 100644
index 0000000000000000000000000000000000000000..e33eef77dfe022919846facabaf23c4deb205823
--- /dev/null
+++ b/src/share/classes/javax/swing/colorchooser/ColorModelHSV.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.swing.colorchooser;
+
+final class ColorModelHSV extends ColorModel {
+
+ ColorModelHSV() {
+ super("hsv", "Hue", "Saturation", "Value", "Transparency"); // NON-NLS: components
+ }
+
+ @Override
+ void setColor(int color, float[] space) {
+ super.setColor(color, space);
+ RGBtoHSV(space, space);
+ space[3] = 1.0f - space[3];
+ }
+
+ @Override
+ int getColor(float[] space) {
+ space[3] = 1.0f - space[3];
+ HSVtoRGB(space, space);
+ return super.getColor(space);
+ }
+
+ @Override
+ int getMaximum(int index) {
+ return (index == 0) ? 360 : 100;
+ }
+
+ @Override
+ float getDefault(int index) {
+ return (index == 0) ? -1.0f : 1.0f;
+ }
+
+ /**
+ * Converts HSV components of a color to a set of RGB components.
+ *
+ * @param hsv a float array with length equal to
+ * the number of HSV components
+ * @param rgb a float array with length of at least 3
+ * that contains RGB components of a color
+ * @return a float array that contains RGB components
+ */
+ private static float[] HSVtoRGB(float[] hsv, float[] rgb) {
+ if (rgb == null) {
+ rgb = new float[3];
+ }
+ float hue = hsv[0];
+ float saturation = hsv[1];
+ float value = hsv[2];
+
+ rgb[0] = value;
+ rgb[1] = value;
+ rgb[2] = value;
+
+ if (saturation > 0.0f) {
+ hue = (hue < 1.0f) ? hue * 6.0f : 0.0f;
+ int integer = (int) hue;
+ float f = hue - (float) integer;
+ switch (integer) {
+ case 0:
+ rgb[1] *= 1.0f - saturation * (1.0f - f);
+ rgb[2] *= 1.0f - saturation;
+ break;
+ case 1:
+ rgb[0] *= 1.0f - saturation * f;
+ rgb[2] *= 1.0f - saturation;
+ break;
+ case 2:
+ rgb[0] *= 1.0f - saturation;
+ rgb[2] *= 1.0f - saturation * (1.0f - f);
+ break;
+ case 3:
+ rgb[0] *= 1.0f - saturation;
+ rgb[1] *= 1.0f - saturation * f;
+ break;
+ case 4:
+ rgb[0] *= 1.0f - saturation * (1.0f - f);
+ rgb[1] *= 1.0f - saturation;
+ break;
+ case 5:
+ rgb[1] *= 1.0f - saturation;
+ rgb[2] *= 1.0f - saturation * f;
+ break;
+ }
+ }
+ return rgb;
+ }
+
+ /**
+ * Converts RGB components of a color to a set of HSV components.
+ *
+ * @param rgb a float array with length of at least 3
+ * that contains RGB components of a color
+ * @param hsv a float array with length equal to
+ * the number of HSV components
+ * @return a float array that contains HSV components
+ */
+ private static float[] RGBtoHSV(float[] rgb, float[] hsv) {
+ if (hsv == null) {
+ hsv = new float[3];
+ }
+ float max = ColorModelHSL.max(rgb[0], rgb[1], rgb[2]);
+ float min = ColorModelHSL.min(rgb[0], rgb[1], rgb[2]);
+
+ float saturation = max - min;
+ if (saturation > 0.0f) {
+ saturation /= max;
+ }
+ hsv[0] = ColorModelHSL.getHue(rgb[0], rgb[1], rgb[2], max, min);
+ hsv[1] = saturation;
+ hsv[2] = max;
+ return hsv;
+ }
+}
diff --git a/src/share/classes/javax/swing/colorchooser/ColorPanel.java b/src/share/classes/javax/swing/colorchooser/ColorPanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..6e9329dbefbc0594d2f9a9083b3cf0dec49dc7e5
--- /dev/null
+++ b/src/share/classes/javax/swing/colorchooser/ColorPanel.java
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.swing.colorchooser;
+
+import java.awt.Color;
+import java.awt.ContainerOrderFocusTraversalPolicy;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.ButtonGroup;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.border.EmptyBorder;
+
+final class ColorPanel extends JPanel implements ActionListener {
+
+ private final SlidingSpinner[] spinners = new SlidingSpinner[5];
+ private final float[] values = new float[this.spinners.length];
+
+ private final ColorModel model;
+ private Color color;
+ private int x = 1;
+ private int y = 2;
+ private int z;
+
+ ColorPanel(ColorModel model) {
+ super(new GridBagLayout());
+
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+
+ gbc.gridx = 1;
+ ButtonGroup group = new ButtonGroup();
+ EmptyBorder border = null;
+ for (int i = 0; i < this.spinners.length; i++) {
+ if (i < 3) {
+ JRadioButton button = new JRadioButton();
+ if (i == 0) {
+ Insets insets = button.getInsets();
+ insets.left = button.getPreferredSize().width;
+ border = new EmptyBorder(insets);
+ button.setSelected(true);
+ gbc.insets.top = 5;
+ }
+ add(button, gbc);
+ group.add(button);
+ button.setActionCommand(Integer.toString(i));
+ button.addActionListener(this);
+ this.spinners[i] = new SlidingSpinner(this, button);
+ }
+ else {
+ JLabel label = new JLabel();
+ add(label, gbc);
+ label.setBorder(border);
+ label.setFocusable(false);
+ this.spinners[i] = new SlidingSpinner(this, label);
+ }
+ }
+ gbc.gridx = 2;
+ gbc.weightx = 1.0;
+ gbc.insets.top = 0;
+ gbc.insets.left = 5;
+ for (SlidingSpinner spinner : this.spinners) {
+ add(spinner.getSlider(), gbc);
+ gbc.insets.top = 5;
+ }
+ gbc.gridx = 3;
+ gbc.weightx = 0.0;
+ gbc.insets.top = 0;
+ for (SlidingSpinner spinner : this.spinners) {
+ add(spinner.getSpinner(), gbc);
+ gbc.insets.top = 5;
+ }
+ setFocusTraversalPolicy(new ContainerOrderFocusTraversalPolicy());
+ setFocusTraversalPolicyProvider(true);
+ setFocusable(false);
+
+ this.model = model;
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ try {
+ this.z = Integer.parseInt(event.getActionCommand());
+ this.y = (this.z != 2) ? 2 : 1;
+ this.x = (this.z != 0) ? 0 : 1;
+ getParent().repaint();
+ }
+ catch (NumberFormatException exception) {
+ }
+ }
+
+ void buildPanel() {
+ int count = this.model.getCount();
+ this.spinners[4].setVisible(count > 4);
+ for (int i = 0; i < count; i++) {
+ Object object = this.spinners[i].getLabel();
+ if (object instanceof JRadioButton) {
+ JRadioButton button = (JRadioButton) object;
+ button.setText(this.model.getLabel(this, i));
+ }
+ else if (object instanceof JLabel) {
+ JLabel label = (JLabel) object;
+ label.setText(this.model.getLabel(this, i));
+ }
+ this.spinners[i].setRange(this.model.getMinimum(i), this.model.getMaximum(i));
+ this.spinners[i].setValue(this.values[i]);
+ }
+ }
+
+ void colorChanged() {
+ this.color = new Color(getColor(0), true);
+ Object parent = getParent();
+ if (parent instanceof ColorChooserPanel) {
+ ColorChooserPanel chooser = (ColorChooserPanel) parent;
+ chooser.getColorSelectionModel().setSelectedColor(this.color);
+ chooser.repaint();
+ }
+ }
+
+ float getValueX() {
+ return this.spinners[this.x].getValue();
+ }
+
+ float getValueY() {
+ return 1.0f - this.spinners[this.y].getValue();
+ }
+
+ float getValueZ() {
+ return 1.0f - this.spinners[this.z].getValue();
+ }
+
+ void setValue(float z) {
+ this.spinners[this.z].setValue(1.0f - z);
+ colorChanged();
+ }
+
+ void setValue(float x, float y) {
+ this.spinners[this.x].setValue(x);
+ this.spinners[this.y].setValue(1.0f - y);
+ colorChanged();
+ }
+
+ int getColor(float z) {
+ setDefaultValue(this.x);
+ setDefaultValue(this.y);
+ this.values[this.z] = 1.0f - z;
+ return getColor(3);
+ }
+
+ int getColor(float x, float y) {
+ this.values[this.x] = x;
+ this.values[this.y] = 1.0f - y;
+ setValue(this.z);
+ return getColor(3);
+ }
+
+ void setColor(Color color) {
+ if (!color.equals(this.color)) {
+ this.color = color;
+ this.model.setColor(color.getRGB(), this.values);
+ for (int i = 0; i < this.model.getCount(); i++) {
+ this.spinners[i].setValue(this.values[i]);
+ }
+ }
+ }
+
+ private int getColor(int index) {
+ while (index < this.model.getCount()) {
+ setValue(index++);
+ }
+ return this.model.getColor(this.values);
+ }
+
+ private void setValue(int index) {
+ this.values[index] = this.spinners[index].getValue();
+ }
+
+ private void setDefaultValue(int index) {
+ float value = this.model.getDefault(index);
+ this.values[index] = (value < 0.0f)
+ ? this.spinners[index].getValue()
+ : value;
+ }
+}
diff --git a/src/share/classes/javax/swing/colorchooser/DefaultHSBChooserPanel.java b/src/share/classes/javax/swing/colorchooser/DefaultHSBChooserPanel.java
deleted file mode 100644
index 89759e247a49c1cfdcb9247699138fe76a2cb244..0000000000000000000000000000000000000000
--- a/src/share/classes/javax/swing/colorchooser/DefaultHSBChooserPanel.java
+++ /dev/null
@@ -1,801 +0,0 @@
-/*
- * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package javax.swing.colorchooser;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.event.*;
-import javax.swing.border.*;
-import java.awt.image.*;
-import java.util.Locale;
-
-/**
- * Implements the default HSB Color chooser
- *
- * @author Tom Santos
- * @author Steve Wilson
- * @author Mark Davidson
- * @author Shannon Hickey
- */
-class DefaultHSBChooserPanel extends AbstractColorChooserPanel implements ChangeListener, HierarchyListener {
-
- private transient HSBImage palette;
- private transient HSBImage sliderPalette;
-
- private transient Image paletteImage;
- private transient Image sliderPaletteImage;
-
- private JSlider slider;
- private JSpinner hField;
- private JSpinner sField;
- private JSpinner bField;
-
- private JTextField redField;
- private JTextField greenField;
- private JTextField blueField;
-
- private boolean isAdjusting = false; // Flag which indicates that values are set internally
- private Point paletteSelection = new Point();
- private JLabel paletteLabel;
- private JLabel sliderPaletteLabel;
-
- private JRadioButton hRadio;
- private JRadioButton sRadio;
- private JRadioButton bRadio;
-
- private static final int PALETTE_DIMENSION = 200;
- private static final int MAX_HUE_VALUE = 359;
- private static final int MAX_SATURATION_VALUE = 100;
- private static final int MAX_BRIGHTNESS_VALUE = 100;
-
- private int currentMode = HUE_MODE;
-
- private static final int HUE_MODE = 0;
- private static final int SATURATION_MODE = 1;
- private static final int BRIGHTNESS_MODE = 2;
-
- public DefaultHSBChooserPanel() {
- }
-
- private void addPaletteListeners() {
- paletteLabel.addMouseListener(new MouseAdapter() {
- public void mousePressed(MouseEvent e ) {
- float[] hsb = new float[3];
- palette.getHSBForLocation( e.getX(), e.getY(), hsb );
- updateHSB( hsb[0], hsb[1], hsb[2] );
- }
- });
-
- paletteLabel.addMouseMotionListener(new MouseMotionAdapter() {
- public void mouseDragged( MouseEvent e ){
- int labelWidth = paletteLabel.getWidth();
-
- int labelHeight = paletteLabel.getHeight();
- int x = e.getX();
- int y = e.getY();
-
- if ( x >= labelWidth ) {
- x = labelWidth - 1;
- }
-
- if ( y >= labelHeight ) {
- y = labelHeight - 1;
- }
-
- if ( x < 0 ) {
- x = 0;
- }
-
- if ( y < 0 ) {
- y = 0;
- }
-
- float[] hsb = new float[3];
- palette.getHSBForLocation( x, y, hsb );
- updateHSB( hsb[0], hsb[1], hsb[2] );
- }
- });
- }
-
- private void updatePalette( float h, float s, float b ) {
- int x = 0;
- int y = 0;
-
- switch ( currentMode ) {
- case HUE_MODE:
- if ( h != palette.getHue() ) {
- palette.setHue( h );
- palette.nextFrame();
- }
- x = PALETTE_DIMENSION - (int)(s * PALETTE_DIMENSION);
- y = PALETTE_DIMENSION - (int)(b * PALETTE_DIMENSION);
- break;
- case SATURATION_MODE:
- if ( s != palette.getSaturation() ) {
- palette.setSaturation( s );
- palette.nextFrame();
- }
- x = (int)(h * PALETTE_DIMENSION);
- y = PALETTE_DIMENSION - (int)(b * PALETTE_DIMENSION);
- break;
- case BRIGHTNESS_MODE:
- if ( b != palette.getBrightness() ) {
- palette.setBrightness( b );
- palette.nextFrame();
- }
- x = (int)(h * PALETTE_DIMENSION);
- y = PALETTE_DIMENSION - (int)(s * PALETTE_DIMENSION);
- break;
- }
-
- paletteSelection.setLocation( x, y );
- paletteLabel.repaint();
- }
-
- private void updateSlider( float h, float s, float b ) {
- // Update the slider palette if necessary.
- // When the slider is the hue slider or the hue hasn't changed,
- // the hue of the palette will not need to be updated.
- if (currentMode != HUE_MODE && h != sliderPalette.getHue() ) {
- sliderPalette.setHue( h );
- sliderPalette.nextFrame();
- }
-
- float value = 0f;
-
- switch ( currentMode ) {
- case HUE_MODE:
- value = h;
- break;
- case SATURATION_MODE:
- value = s;
- break;
- case BRIGHTNESS_MODE:
- value = b;
- break;
- }
-
- slider.setValue( Math.round(value * (slider.getMaximum())) );
- }
-
- private void updateHSBTextFields( float hue, float saturation, float brightness ) {
- int h = Math.round(hue * 359);
- int s = Math.round(saturation * 100);
- int b = Math.round(brightness * 100);
-
- if (((Integer)hField.getValue()).intValue() != h) {
- hField.setValue(new Integer(h));
- }
- if (((Integer)sField.getValue()).intValue() != s) {
- sField.setValue(new Integer(s));
- }
- if (((Integer)bField.getValue()).intValue() != b) {
- bField.setValue(new Integer(b));
- }
- }
-
- /**
- * Updates the values of the RGB fields to reflect the new color change
- */
- private void updateRGBTextFields( Color color ) {
- redField.setText(String.valueOf(color.getRed()));
- greenField.setText(String.valueOf(color.getGreen()));
- blueField.setText(String.valueOf(color.getBlue()));
- }
-
- /**
- * Main internal method of updating the ui controls and the color model.
- */
- private void updateHSB( float h, float s, float b ) {
- if ( !isAdjusting ) {
- isAdjusting = true;
-
- updatePalette( h, s, b );
- updateSlider( h, s, b );
- updateHSBTextFields( h, s, b );
-
- Color color = Color.getHSBColor(h, s, b);
- updateRGBTextFields( color );
-
- getColorSelectionModel().setSelectedColor( color );
-
- isAdjusting = false;
- }
- }
-
- /**
- * Invoked automatically when the model's state changes.
- * It is also called by installChooserPanel to allow
- * you to set up the initial state of your chooser.
- * Override this method to update your ChooserPanel.
- */
- public void updateChooser() {
- if ( !isAdjusting ) {
- float[] hsb = getHSBColorFromModel();
- updateHSB( hsb[0], hsb[1], hsb[2] );
- }
- }
-
- public void installChooserPanel(JColorChooser enclosingChooser) {
- super.installChooserPanel(enclosingChooser);
- setInheritsPopupMenu(true);
- addHierarchyListener(this);
- }
-
- /**
- * Invoked when the panel is removed from the chooser.
- */
- public void uninstallChooserPanel(JColorChooser enclosingChooser) {
- super.uninstallChooserPanel(enclosingChooser);
- cleanupPalettesIfNecessary();
- removeAll();
- removeHierarchyListener(this);
- }
-
- /**
- * Returns an float array containing the HSB values of the selected color from
- * the ColorSelectionModel
- */
- private float[] getHSBColorFromModel() {
- Color color = getColorFromModel();
- float[] hsb = new float[3];
- Color.RGBtoHSB( color.getRed(), color.getGreen(), color.getBlue(), hsb );
-
- return hsb;
- }
-
- /**
- * Builds a new chooser panel.
- */
- protected void buildChooser() {
- setLayout(new BorderLayout());
- JComponent spp = buildSliderPalettePanel();
- spp.setInheritsPopupMenu(true);
- add(spp, BorderLayout.BEFORE_LINE_BEGINS);
-
- JPanel controlHolder = new JPanel(new SmartGridLayout(1,3));
- JComponent hsbControls = buildHSBControls();
- hsbControls.setInheritsPopupMenu(true);
- controlHolder.add(hsbControls);
-
- controlHolder.add(new JLabel(" ")); // spacer
-
- JComponent rgbControls = buildRGBControls();
- rgbControls.setInheritsPopupMenu(true);
- controlHolder.add(rgbControls);
- controlHolder.setInheritsPopupMenu(true);
-
- controlHolder.setBorder(new EmptyBorder( 10, 5, 10, 5));
- add( controlHolder, BorderLayout.CENTER);
- }
-
- /**
- * Creates the panel with the uneditable RGB field
- */
- private JComponent buildRGBControls() {
- JPanel panel = new JPanel(new SmartGridLayout(2,3));
- panel.setInheritsPopupMenu(true);
-
- Color color = getColorFromModel();
- redField = new JTextField( String.valueOf(color.getRed()), 3 );
- redField.setEditable(false);
- redField.setHorizontalAlignment( JTextField.RIGHT );
- redField.setInheritsPopupMenu(true);
-
- greenField = new JTextField(String.valueOf(color.getGreen()), 3 );
- greenField.setEditable(false);
- greenField.setHorizontalAlignment( JTextField.RIGHT );
- greenField.setInheritsPopupMenu(true);
-
- blueField = new JTextField( String.valueOf(color.getBlue()), 3 );
- blueField.setEditable(false);
- blueField.setHorizontalAlignment( JTextField.RIGHT );
- blueField.setInheritsPopupMenu(true);
-
- Locale locale = getLocale();
- String redString = UIManager.getString("ColorChooser.hsbRedText", locale);
- String greenString = UIManager.getString("ColorChooser.hsbGreenText", locale);
- String blueString = UIManager.getString("ColorChooser.hsbBlueText", locale);
-
- panel.add( new JLabel(redString) );
- panel.add( redField );
- panel.add( new JLabel(greenString) );
- panel.add( greenField );
- panel.add( new JLabel(blueString) );
- panel.add( blueField );
-
- return panel;
- }
-
- /**
- * Creates the panel with the editable HSB fields and the radio buttons.
- */
- private JComponent buildHSBControls() {
-
- Locale locale = getLocale();
- String hueString = UIManager.getString("ColorChooser.hsbHueText", locale);
- String saturationString = UIManager.getString("ColorChooser.hsbSaturationText", locale);
- String brightnessString = UIManager.getString("ColorChooser.hsbBrightnessText", locale);
-
- RadioButtonHandler handler = new RadioButtonHandler();
-
- hRadio = new JRadioButton(hueString);
- hRadio.addActionListener(handler);
- hRadio.setSelected(true);
- hRadio.setInheritsPopupMenu(true);
-
- sRadio = new JRadioButton(saturationString);
- sRadio.addActionListener(handler);
- sRadio.setInheritsPopupMenu(true);
-
- bRadio = new JRadioButton(brightnessString);
- bRadio.addActionListener(handler);
- bRadio.setInheritsPopupMenu(true);
-
- ButtonGroup group = new ButtonGroup();
- group.add(hRadio);
- group.add(sRadio);
- group.add(bRadio);
-
- float[] hsb = getHSBColorFromModel();
-
- hField = new JSpinner(new SpinnerNumberModel((int)(hsb[0] * 359), 0, 359, 1));
- sField = new JSpinner(new SpinnerNumberModel((int)(hsb[1] * 100), 0, 100, 1));
- bField = new JSpinner(new SpinnerNumberModel((int)(hsb[2] * 100), 0, 100, 1));
-
- hField.addChangeListener(this);
- sField.addChangeListener(this);
- bField.addChangeListener(this);
-
- hField.setInheritsPopupMenu(true);
- sField.setInheritsPopupMenu(true);
- bField.setInheritsPopupMenu(true);
-
- JPanel panel = new JPanel( new SmartGridLayout(2, 3) );
-
- panel.add(hRadio);
- panel.add(hField);
- panel.add(sRadio);
- panel.add(sField);
- panel.add(bRadio);
- panel.add(bField);
- panel.setInheritsPopupMenu(true);
-
- return panel;
- }
-
- /**
- * Handler for the radio button classes.
- */
- private class RadioButtonHandler implements ActionListener {
- public void actionPerformed(ActionEvent evt) {
- Object obj = evt.getSource();
-
- if (obj instanceof JRadioButton) {
- JRadioButton button = (JRadioButton)obj;
- if (button == hRadio) {
- setMode(HUE_MODE);
- } else if (button == sRadio) {
- setMode(SATURATION_MODE);
- } else if (button == bRadio) {
- setMode(BRIGHTNESS_MODE);
- }
- }
- }
- }
-
- private void setMode(int mode) {
- if (currentMode == mode) {
- return;
- }
-
- isAdjusting = true; // Ensure no events propagate from changing slider value.
- currentMode = mode;
-
- float[] hsb = getHSBColorFromModel();
-
- switch (currentMode) {
- case HUE_MODE:
- slider.setInverted(true);
- slider.setMaximum(MAX_HUE_VALUE);
- palette.setValues(HSBImage.HSQUARE, hsb[0], 1.0f, 1.0f);
- sliderPalette.setValues(HSBImage.HSLIDER, 0f, 1.0f, 1.0f);
- break;
- case SATURATION_MODE:
- slider.setInverted(false);
- slider.setMaximum(MAX_SATURATION_VALUE);
- palette.setValues(HSBImage.SSQUARE, hsb[0], hsb[1], 1.0f);
- sliderPalette.setValues(HSBImage.SSLIDER, hsb[0], 1.0f, 1.0f);
- break;
- case BRIGHTNESS_MODE:
- slider.setInverted(false);
- slider.setMaximum(MAX_BRIGHTNESS_VALUE);
- palette.setValues(HSBImage.BSQUARE, hsb[0], 1.0f, hsb[2]);
- sliderPalette.setValues(HSBImage.BSLIDER, hsb[0], 1.0f, 1.0f);
- break;
- }
-
- isAdjusting = false;
-
- palette.nextFrame();
- sliderPalette.nextFrame();
-
- updateChooser();
- }
-
- protected JComponent buildSliderPalettePanel() {
-
- // This slider has to have a minimum of 0. A lot of math in this file is simplified due to this.
- slider = new JSlider(JSlider.VERTICAL, 0, MAX_HUE_VALUE, 0);
- slider.setInverted(true);
- slider.setPaintTrack(false);
- slider.setPreferredSize(new Dimension(slider.getPreferredSize().width, PALETTE_DIMENSION + 15));
- slider.addChangeListener(this);
- slider.setInheritsPopupMenu(true);
- // We're not painting ticks, but need to ask UI classes to
- // paint arrow shape anyway, if possible.
- slider.putClientProperty("Slider.paintThumbArrowShape", Boolean.TRUE);
- paletteLabel = createPaletteLabel();
- addPaletteListeners();
- sliderPaletteLabel = new JLabel();
-
- JPanel panel = new JPanel();
- panel.add( paletteLabel );
- panel.add( slider );
- panel.add( sliderPaletteLabel );
-
- initializePalettesIfNecessary();
-
- return panel;
- }
-
- private void initializePalettesIfNecessary() {
- if (palette != null) {
- return;
- }
-
- float[] hsb = getHSBColorFromModel();
-
- switch(currentMode){
- case HUE_MODE:
- palette = new HSBImage(HSBImage.HSQUARE, PALETTE_DIMENSION, PALETTE_DIMENSION, hsb[0], 1.0f, 1.0f);
- sliderPalette = new HSBImage(HSBImage.HSLIDER, 16, PALETTE_DIMENSION, 0f, 1.0f, 1.0f);
- break;
- case SATURATION_MODE:
- palette = new HSBImage(HSBImage.SSQUARE, PALETTE_DIMENSION, PALETTE_DIMENSION, 1.0f, hsb[1], 1.0f);
- sliderPalette = new HSBImage(HSBImage.SSLIDER, 16, PALETTE_DIMENSION, 1.0f, 0f, 1.0f);
- break;
- case BRIGHTNESS_MODE:
- palette = new HSBImage(HSBImage.BSQUARE, PALETTE_DIMENSION, PALETTE_DIMENSION, 1.0f, 1.0f, hsb[2]);
- sliderPalette = new HSBImage(HSBImage.BSLIDER, 16, PALETTE_DIMENSION, 1.0f, 1.0f, 0f);
- break;
- }
- paletteImage = Toolkit.getDefaultToolkit().createImage(palette);
- sliderPaletteImage = Toolkit.getDefaultToolkit().createImage(sliderPalette);
-
- paletteLabel.setIcon(new ImageIcon(paletteImage));
- sliderPaletteLabel.setIcon(new ImageIcon(sliderPaletteImage));
- }
-
- private void cleanupPalettesIfNecessary() {
- if (palette == null) {
- return;
- }
-
- palette.aborted = true;
- sliderPalette.aborted = true;
-
- palette.nextFrame();
- sliderPalette.nextFrame();
-
- palette = null;
- sliderPalette = null;
-
- paletteImage = null;
- sliderPaletteImage = null;
-
- paletteLabel.setIcon(null);
- sliderPaletteLabel.setIcon(null);
- }
-
- protected JLabel createPaletteLabel() {
- return new JLabel() {
- protected void paintComponent( Graphics g ) {
- super.paintComponent( g );
- g.setColor( Color.white );
- g.drawOval( paletteSelection.x - 4, paletteSelection.y - 4, 8, 8 );
- }
- };
- }
-
- public String getDisplayName() {
- return UIManager.getString("ColorChooser.hsbNameText", getLocale());
- }
-
- /**
- * Provides a hint to the look and feel as to the
- * KeyEvent.VK constant that can be used as a mnemonic to
- * access the panel. A return value <= 0 indicates there is no mnemonic.
- *
- * The return value here is a hint, it is ultimately up to the look - * and feel to honor the return value in some meaningful way. - *
- * This implementation looks up the value from the default
- * ColorChooser.hsbMnemonic, or if it
- * isn't available (or not an Integer) returns -1.
- * The lookup for the default is done through the UIManager:
- * UIManager.get("ColorChooser.rgbMnemonic");.
- *
- * @return KeyEvent.VK constant identifying the mnemonic; <= 0 for no
- * mnemonic
- * @see #getDisplayedMnemonicIndex
- * @since 1.4
- */
- public int getMnemonic() {
- return getInt("ColorChooser.hsbMnemonic", -1);
- }
-
- /**
- * Provides a hint to the look and feel as to the index of the character in
- * getDisplayName that should be visually identified as the
- * mnemonic. The look and feel should only use this if
- * getMnemonic returns a value > 0.
- *
- * The return value here is a hint, it is ultimately up to the look
- * and feel to honor the return value in some meaningful way. For example,
- * a look and feel may wish to render each
- * AbstractColorChooserPanel in a JTabbedPane,
- * and further use this return value to underline a character in
- * the getDisplayName.
- *
- * This implementation looks up the value from the default
- * ColorChooser.rgbDisplayedMnemonicIndex, or if it
- * isn't available (or not an Integer) returns -1.
- * The lookup for the default is done through the UIManager:
- * UIManager.get("ColorChooser.hsbDisplayedMnemonicIndex");.
- *
- * @return Character index to render mnemonic for; -1 to provide no
- * visual identifier for this panel.
- * @see #getMnemonic
- * @since 1.4
- */
- public int getDisplayedMnemonicIndex() {
- return getInt("ColorChooser.hsbDisplayedMnemonicIndex", -1);
- }
-
- public Icon getSmallDisplayIcon() {
- return null;
- }
-
- public Icon getLargeDisplayIcon() {
- return null;
- }
-
- /**
- * Class for the slider and palette images.
- */
- class HSBImage extends SyntheticImage {
- protected float h = .0f;
- protected float s = .0f;
- protected float b = .0f;
- protected float[] hsb = new float[3];
-
- protected boolean isDirty = true;
- protected int cachedY;
- protected int cachedColor;
- protected int type;
-
- private static final int HSQUARE = 0;
- private static final int SSQUARE = 1;
- private static final int BSQUARE = 2;
- private static final int HSLIDER = 3;
- private static final int SSLIDER = 4;
- private static final int BSLIDER = 5;
-
- protected HSBImage(int type, int width, int height, float h, float s, float b) {
- super(width, height);
- setValues(type, h, s, b);
- }
-
- public void setValues(int type, float h, float s, float b) {
- this.type = type;
- cachedY = -1;
- cachedColor = 0;
- setHue( h );
- setSaturation( s );
- setBrightness( b );
- }
-
- public final void setHue( float hue ) {
- h = hue;
- }
-
- public final void setSaturation( float saturation ) {
- s = saturation;
- }
-
- public final void setBrightness( float brightness ) {
- b = brightness;
- }
-
- public final float getHue() {
- return h;
- }
-
- public final float getSaturation() {
- return s;
- }
-
- public final float getBrightness() {
- return b;
- }
-
- protected boolean isStatic() {
- return false;
- }
-
- public synchronized void nextFrame() {
- isDirty = true;
- notifyAll();
- }
-
- public synchronized void addConsumer(ImageConsumer ic) {
- isDirty = true;
- super.addConsumer(ic);
- }
-
- private int getRGBForLocation( int x, int y ) {
- if (type >= HSLIDER && y == cachedY) {
- return cachedColor;
- }
-
- getHSBForLocation( x, y, hsb );
- cachedY = y;
- cachedColor = Color.HSBtoRGB( hsb[0], hsb[1], hsb[2] );
-
- return cachedColor;
- }
-
- public void getHSBForLocation( int x, int y, float[] hsbArray ) {
- switch (type) {
- case HSQUARE: {
- float saturationStep = ((float)x) / width;
- float brightnessStep = ((float)y) / height;
- hsbArray[0] = h;
- hsbArray[1] = s - saturationStep;
- hsbArray[2] = b - brightnessStep;
- break;
- }
- case SSQUARE: {
- float brightnessStep = ((float)y) / height;
- float step = 1.0f / ((float)width);
- hsbArray[0] = x * step;
- hsbArray[1] = s;
- hsbArray[2] = 1.0f - brightnessStep;
- break;
- }
- case BSQUARE: {
- float saturationStep = ((float)y) / height;
- float step = 1.0f / ((float)width);
- hsbArray[0] = x * step;
- hsbArray[1] = 1.0f - saturationStep;
- hsbArray[2] = b;
- break;
- }
- case HSLIDER: {
- float step = 1.0f / ((float)height);
- hsbArray[0] = y * step;
- hsbArray[1] = s;
- hsbArray[2] = b;
- break;
- }
- case SSLIDER: {
- float saturationStep = ((float)y) / height;
- hsbArray[0] = h;
- hsbArray[1] = s - saturationStep;
- hsbArray[2] = b;
- break;
- }
- case BSLIDER: {
- float brightnessStep = ((float)y) / height;
- hsbArray[0] = h;
- hsbArray[1] = s;
- hsbArray[2] = b - brightnessStep;
- break;
- }
- }
- }
-
- /**
- * Overriden method from SyntheticImage
- */
- protected void computeRow( int y, int[] row ) {
- if ( y == 0 ) {
- synchronized ( this ) {
- try {
- while ( !isDirty ) {
- wait();
- }
- } catch (InterruptedException ie) {
- }
- isDirty = false;
- }
- }
-
- if (aborted) {
- return;
- }
-
- for ( int i = 0; i < row.length; ++i ) {
- row[i] = getRGBForLocation( i, y );
- }
- }
- }
-
- public void stateChanged(ChangeEvent e) {
- if (e.getSource() == slider) {
- boolean modelIsAdjusting = slider.getModel().getValueIsAdjusting();
-
- if (!modelIsAdjusting && !isAdjusting) {
- int sliderValue = slider.getValue();
- int sliderRange = slider.getMaximum();
- float value = (float)sliderValue / (float)sliderRange;
-
- float[] hsb = getHSBColorFromModel();
-
- switch ( currentMode ){
- case HUE_MODE:
- updateHSB(value, hsb[1], hsb[2]);
- break;
- case SATURATION_MODE:
- updateHSB(hsb[0], value, hsb[2]);
- break;
- case BRIGHTNESS_MODE:
- updateHSB(hsb[0], hsb[1], value);
- break;
- }
- }
- } else if (e.getSource() instanceof JSpinner) {
- float hue = ((Integer)hField.getValue()).floatValue() / 359f;
- float saturation = ((Integer)sField.getValue()).floatValue() / 100f;
- float brightness = ((Integer)bField.getValue()).floatValue() / 100f;
-
- updateHSB(hue, saturation, brightness);
- }
- }
-
- public void hierarchyChanged(HierarchyEvent he) {
- if ((he.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
- if (isDisplayable()) {
- initializePalettesIfNecessary();
- } else {
- cleanupPalettesIfNecessary();
- }
- }
- }
-
-}
diff --git a/src/share/classes/javax/swing/colorchooser/DefaultRGBChooserPanel.java b/src/share/classes/javax/swing/colorchooser/DefaultRGBChooserPanel.java
deleted file mode 100644
index 28850dffaac1e5fad906ccd9d86c2d07b8a130ef..0000000000000000000000000000000000000000
--- a/src/share/classes/javax/swing/colorchooser/DefaultRGBChooserPanel.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package javax.swing.colorchooser;
-
-import javax.swing.*;
-import javax.swing.event.*;
-import java.awt.*;
-import java.util.Locale;
-
-/**
- * The standard RGB chooser.
- *
- * Warning:
- * Serialized objects of this class will not be compatible with
- * future Swing releases. The current serialization support is
- * appropriate for short term storage or RMI between applications running
- * the same version of Swing. As of 1.4, support for long term storage
- * of all JavaBeansTM
- * has been added to the java.beans package.
- * Please see {@link java.beans.XMLEncoder}.
- *
- * @author Steve Wilson
- * @author Mark Davidson
- * @see JColorChooser
- * @see AbstractColorChooserPanel
- */
-class DefaultRGBChooserPanel extends AbstractColorChooserPanel implements ChangeListener {
-
- protected JSlider redSlider;
- protected JSlider greenSlider;
- protected JSlider blueSlider;
- protected JSpinner redField;
- protected JSpinner blueField;
- protected JSpinner greenField;
-
- private final int minValue = 0;
- private final int maxValue = 255;
-
- private boolean isAdjusting = false; // indicates the fields are being set internally
-
- public DefaultRGBChooserPanel() {
- super();
- setInheritsPopupMenu(true);
- }
-
- /**
- * Sets the values of the controls to reflect the color
- */
- private void setColor( Color newColor ) {
- int red = newColor.getRed();
- int blue = newColor.getBlue();
- int green = newColor.getGreen();
-
- if (redSlider.getValue() != red) {
- redSlider.setValue(red);
- }
- if (greenSlider.getValue() != green) {
- greenSlider.setValue(green);
- }
- if (blueSlider.getValue() != blue) {
- blueSlider.setValue(blue);
- }
-
- if (((Integer)redField.getValue()).intValue() != red)
- redField.setValue(new Integer(red));
- if (((Integer)greenField.getValue()).intValue() != green)
- greenField.setValue(new Integer(green));
- if (((Integer)blueField.getValue()).intValue() != blue )
- blueField.setValue(new Integer(blue));
- }
-
- public String getDisplayName() {
- return UIManager.getString("ColorChooser.rgbNameText", getLocale());
- }
-
- /**
- * Provides a hint to the look and feel as to the
- * KeyEvent.VK constant that can be used as a mnemonic to
- * access the panel. A return value <= 0 indicates there is no mnemonic.
- *
- * The return value here is a hint, it is ultimately up to the look - * and feel to honor the return value in some meaningful way. - *
- * This implementation looks up the value from the default
- * ColorChooser.rgbMnemonic, or if it
- * isn't available (or not an Integer) returns -1.
- * The lookup for the default is done through the UIManager:
- * UIManager.get("ColorChooser.rgbMnemonic");.
- *
- * @return KeyEvent.VK constant identifying the mnemonic; <= 0 for no
- * mnemonic
- * @see #getDisplayedMnemonicIndex
- * @since 1.4
- */
- public int getMnemonic() {
- return getInt("ColorChooser.rgbMnemonic", -1);
- }
-
- /**
- * Provides a hint to the look and feel as to the index of the character in
- * getDisplayName that should be visually identified as the
- * mnemonic. The look and feel should only use this if
- * getMnemonic returns a value > 0.
- *
- * The return value here is a hint, it is ultimately up to the look
- * and feel to honor the return value in some meaningful way. For example,
- * a look and feel may wish to render each
- * AbstractColorChooserPanel in a JTabbedPane,
- * and further use this return value to underline a character in
- * the getDisplayName.
- *
- * This implementation looks up the value from the default
- * ColorChooser.rgbDisplayedMnemonicIndex, or if it
- * isn't available (or not an Integer) returns -1.
- * The lookup for the default is done through the UIManager:
- * UIManager.get("ColorChooser.rgbDisplayedMnemonicIndex");.
- *
- * @return Character index to render mnemonic for; -1 to provide no
- * visual identifier for this panel.
- * @see #getMnemonic
- * @since 1.4
- */
- public int getDisplayedMnemonicIndex() {
- return getInt("ColorChooser.rgbDisplayedMnemonicIndex", -1);
- }
-
- public Icon getSmallDisplayIcon() {
- return null;
- }
-
- public Icon getLargeDisplayIcon() {
- return null;
- }
-
- /**
- * The background color, foreground color, and font are already set to the
- * defaults from the defaults table before this method is called.
- */
- public void installChooserPanel(JColorChooser enclosingChooser) {
- super.installChooserPanel(enclosingChooser);
- }
-
- protected void buildChooser() {
-
- Locale locale = getLocale();
- String redString = UIManager.getString("ColorChooser.rgbRedText", locale);
- String greenString = UIManager.getString("ColorChooser.rgbGreenText", locale);
- String blueString = UIManager.getString("ColorChooser.rgbBlueText", locale);
-
- setLayout( new BorderLayout() );
- Color color = getColorFromModel();
-
-
- JPanel enclosure = new JPanel();
- enclosure.setLayout( new SmartGridLayout( 3, 3 ) );
- enclosure.setInheritsPopupMenu(true);
-
- // The panel that holds the sliders
-
- add( enclosure, BorderLayout.CENTER );
- // sliderPanel.setBorder(new LineBorder(Color.black));
-
- // The row for the red value
- JLabel l = new JLabel(redString);
- l.setDisplayedMnemonic(getInt("ColorChooser.rgbRedMnemonic", -1));
- enclosure.add(l);
- redSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getRed());
- redSlider.setMajorTickSpacing( 85 );
- redSlider.setMinorTickSpacing( 17 );
- redSlider.setPaintTicks( true );
- redSlider.setPaintLabels( true );
- redSlider.setInheritsPopupMenu(true);
- enclosure.add( redSlider );
- redField = new JSpinner(
- new SpinnerNumberModel(color.getRed(), minValue, maxValue, 1));
- l.setLabelFor(redSlider);
- redField.setInheritsPopupMenu(true);
- JPanel redFieldHolder = new JPanel(new CenterLayout());
- redFieldHolder.setInheritsPopupMenu(true);
- redField.addChangeListener(this);
- redFieldHolder.add(redField);
- enclosure.add(redFieldHolder);
-
-
- // The row for the green value
- l = new JLabel(greenString);
- l.setDisplayedMnemonic(getInt("ColorChooser.rgbGreenMnemonic", -1));
- enclosure.add(l);
- greenSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getGreen());
- greenSlider.setMajorTickSpacing( 85 );
- greenSlider.setMinorTickSpacing( 17 );
- greenSlider.setPaintTicks( true );
- greenSlider.setPaintLabels( true );
- greenSlider.setInheritsPopupMenu(true);
- enclosure.add(greenSlider);
- greenField = new JSpinner(
- new SpinnerNumberModel(color.getGreen(), minValue, maxValue, 1));
- l.setLabelFor(greenSlider);
- greenField.setInheritsPopupMenu(true);
- JPanel greenFieldHolder = new JPanel(new CenterLayout());
- greenFieldHolder.add(greenField);
- greenFieldHolder.setInheritsPopupMenu(true);
- greenField.addChangeListener(this);
- enclosure.add(greenFieldHolder);
-
- // The slider for the blue value
- l = new JLabel(blueString);
- l.setDisplayedMnemonic(getInt("ColorChooser.rgbBlueMnemonic", -1));
- enclosure.add(l);
- blueSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getBlue());
- blueSlider.setMajorTickSpacing( 85 );
- blueSlider.setMinorTickSpacing( 17 );
- blueSlider.setPaintTicks( true );
- blueSlider.setPaintLabels( true );
- blueSlider.setInheritsPopupMenu(true);
- enclosure.add(blueSlider);
- blueField = new JSpinner(
- new SpinnerNumberModel(color.getBlue(), minValue, maxValue, 1));
- l.setLabelFor(blueSlider);
- blueField.setInheritsPopupMenu(true);
- JPanel blueFieldHolder = new JPanel(new CenterLayout());
- blueFieldHolder.add(blueField);
- blueField.addChangeListener(this);
- blueFieldHolder.setInheritsPopupMenu(true);
- enclosure.add(blueFieldHolder);
-
- redSlider.addChangeListener( this );
- greenSlider.addChangeListener( this );
- blueSlider.addChangeListener( this );
-
- redSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
- greenSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
- blueSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
- }
-
- public void uninstallChooserPanel(JColorChooser enclosingChooser) {
- super.uninstallChooserPanel(enclosingChooser);
- removeAll();
- }
-
- public void updateChooser() {
- if (!isAdjusting) {
- isAdjusting = true;
-
- setColor(getColorFromModel());
-
- isAdjusting = false;
- }
- }
-
- public void stateChanged( ChangeEvent e ) {
- if ( e.getSource() instanceof JSlider && !isAdjusting) {
-
- int red = redSlider.getValue();
- int green = greenSlider.getValue();
- int blue = blueSlider.getValue() ;
- Color color = new Color (red, green, blue);
-
- getColorSelectionModel().setSelectedColor(color);
- } else if (e.getSource() instanceof JSpinner && !isAdjusting) {
-
- int red = ((Integer)redField.getValue()).intValue();
- int green = ((Integer)greenField.getValue()).intValue();
- int blue = ((Integer)blueField.getValue()).intValue();
- Color color = new Color (red, green, blue);
-
- getColorSelectionModel().setSelectedColor(color);
- }
- }
-
-}
diff --git a/src/share/classes/javax/swing/colorchooser/DiagramComponent.java b/src/share/classes/javax/swing/colorchooser/DiagramComponent.java
new file mode 100644
index 0000000000000000000000000000000000000000..04905589e992e1e1e4718fffb9f00e132f84d312
--- /dev/null
+++ b/src/share/classes/javax/swing/colorchooser/DiagramComponent.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.swing.colorchooser;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.image.BufferedImage;
+import javax.swing.JComponent;
+
+final class DiagramComponent extends JComponent implements MouseListener, MouseMotionListener {
+
+ private final ColorPanel panel;
+ private final boolean diagram;
+
+ private final Insets insets = new Insets(0, 0, 0, 0);
+
+ private int width;
+ private int height;
+
+ private int[] array;
+ private BufferedImage image;
+
+ DiagramComponent(ColorPanel panel, boolean diagram) {
+ this.panel = panel;
+ this.diagram = diagram;
+ addMouseListener(this);
+ addMouseMotionListener(this);
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {
+ getInsets(this.insets);
+ this.width = getWidth() - this.insets.left - this.insets.right;
+ this.height = getHeight() - this.insets.top - this.insets.bottom;
+
+ boolean update = (this.image == null)
+ || (this.width != this.image.getWidth())
+ || (this.height != this.image.getHeight());
+ if (update) {
+ int size = this.width * this.height;
+ if ((this.array == null) || (this.array.length < size)) {
+ this.array = new int[size];
+ }
+ this.image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB);
+ }
+ {
+ float dx = 1.0f / (float) (this.width - 1);
+ float dy = 1.0f / (float) (this.height - 1);
+
+ int offset = 0;
+ float y = 0.0f;
+ for (int h = 0; h < this.height; h++, y += dy) {
+ if (this.diagram) {
+ float x = 0.0f;
+ for (int w = 0; w < this.width; w++, x += dx, offset++) {
+ this.array[offset] = this.panel.getColor(x, y);
+ }
+ }
+ else {
+ int color = this.panel.getColor(y);
+ for (int w = 0; w < this.width; w++, offset++) {
+ this.array[offset] = color;
+ }
+ }
+ }
+ }
+ this.image.setRGB(0, 0, this.width, this.height, this.array, 0, this.width);
+ g.drawImage(this.image, this.insets.left, this.insets.top, this.width, this.height, this);
+ if (isEnabled()) {
+ this.width--;
+ this.height--;
+ g.setXORMode(Color.WHITE);
+ g.setColor(Color.BLACK);
+ if (this.diagram) {
+ int x = getValue(this.panel.getValueX(), this.insets.left, this.width);
+ int y = getValue(this.panel.getValueY(), this.insets.top, this.height);
+ g.drawLine(x - 8, y, x + 8, y);
+ g.drawLine(x, y - 8, x, y + 8);
+ }
+ else {
+ int z = getValue(this.panel.getValueZ(), this.insets.top, this.height);
+ g.drawLine(this.insets.left, z, this.insets.left + this.width, z);
+ }
+ g.setPaintMode();
+ }
+ }
+
+ public void mousePressed(MouseEvent event) {
+ mouseDragged(event);
+ }
+
+ public void mouseReleased(MouseEvent event) {
+ }
+
+ public void mouseClicked(MouseEvent event) {
+ }
+
+ public void mouseEntered(MouseEvent event) {
+ }
+
+ public void mouseExited(MouseEvent event) {
+ }
+
+ public void mouseMoved(MouseEvent event) {
+ }
+
+ public void mouseDragged(MouseEvent event) {
+ if (isEnabled()) {
+ float y = getValue(event.getY(), this.insets.top, this.height);
+ if (this.diagram) {
+ float x = getValue(event.getX(), this.insets.left, this.width);
+ this.panel.setValue(x, y);
+ }
+ else {
+ this.panel.setValue(y);
+ }
+ }
+ }
+
+ private static int getValue(float value, int min, int max) {
+ return min + (int) (value * (float) (max));
+ }
+
+ private static float getValue(int value, int min, int max) {
+ if (min < value) {
+ value -= min;
+ return (value < max)
+ ? (float) value / (float) max
+ : 1.0f;
+ }
+ return 0.0f;
+ }
+}
diff --git a/src/share/classes/javax/swing/colorchooser/SlidingSpinner.java b/src/share/classes/javax/swing/colorchooser/SlidingSpinner.java
new file mode 100644
index 0000000000000000000000000000000000000000..99e9bf298587f2998483c4e694298efd8a590fd9
--- /dev/null
+++ b/src/share/classes/javax/swing/colorchooser/SlidingSpinner.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package javax.swing.colorchooser;
+
+import javax.swing.JComponent;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.JSpinner.DefaultEditor;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+final class SlidingSpinner implements ChangeListener {
+
+ private final ColorPanel panel;
+ private final JComponent label;
+ private final SpinnerNumberModel model = new SpinnerNumberModel();
+ private final JSlider slider = new JSlider();
+ private final JSpinner spinner = new JSpinner(this.model);
+ private float value;
+ private boolean internal;
+
+ SlidingSpinner(ColorPanel panel, JComponent label) {
+ this.panel = panel;
+ this.label = label;
+ this.slider.addChangeListener(this);
+ this.spinner.addChangeListener(this);
+ DefaultEditor editor = (DefaultEditor) this.spinner.getEditor();
+ ValueFormatter.init(3, false, editor.getTextField());
+ editor.setFocusable(false);
+ this.spinner.setFocusable(false);
+ }
+
+ JComponent getLabel() {
+ return this.label;
+ }
+
+ JSlider getSlider() {
+ return this.slider;
+ }
+
+ JSpinner getSpinner() {
+ return this.spinner;
+ }
+
+ float getValue() {
+ return this.value;
+ }
+
+ void setValue(float value) {
+ int min = this.slider.getMinimum();
+ int max = this.slider.getMaximum();
+ this.internal = true;
+ this.slider.setValue(min + (int) (value * (float) (max - min)));
+ this.spinner.setValue(Integer.valueOf(this.slider.getValue()));
+ this.internal = false;
+ this.value = value;
+ }
+
+ void setRange(int min, int max) {
+ this.internal = true;
+ this.slider.setMinimum(min);
+ this.slider.setMaximum(max);
+ this.model.setMinimum(Integer.valueOf(min));
+ this.model.setMaximum(Integer.valueOf(max));
+ this.internal = false;
+ }
+
+ void setVisible(boolean visible) {
+ this.label.setVisible(visible);
+ this.slider.setVisible(visible);
+ this.spinner.setVisible(visible);
+ }
+
+ public void stateChanged(ChangeEvent event) {
+ if (!this.internal) {
+ if (this.spinner == event.getSource()) {
+ Object value = this.spinner.getValue();
+ if (value instanceof Integer) {
+ this.internal = true;
+ this.slider.setValue((Integer) value);
+ this.internal = false;
+ }
+ }
+ int value = this.slider.getValue();
+ this.internal = true;
+ this.spinner.setValue(Integer.valueOf(value));
+ this.internal = false;
+ int min = this.slider.getMinimum();
+ int max = this.slider.getMaximum();
+ this.value = (float) (value - min) / (float) (max - min);
+ this.panel.colorChanged();
+ }
+ }
+}
diff --git a/src/share/classes/javax/swing/colorchooser/SyntheticImage.java b/src/share/classes/javax/swing/colorchooser/SyntheticImage.java
deleted file mode 100644
index cec69e9c39d9ae269afe313b621056b0d289013d..0000000000000000000000000000000000000000
--- a/src/share/classes/javax/swing/colorchooser/SyntheticImage.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package javax.swing.colorchooser;
-
-import java.awt.*;
-import java.awt.image.*;
-
-/** A helper class to make computing synthetic images a little easier.
- * All you need to do is define a subclass that overrides computeRow
- * to compute a row of the image. It is passed the y coordinate of the
- * row and an array into which to put the pixels in
- *
- * standard ARGB format.
- *
Normal usage looks something like this: - *
Image i = createImage(new SyntheticImage(200, 100) {
- * protected void computeRow(int y, int[] row) {
- * for(int i = width; --i>=0; ) {
- * int grey = i*255/(width-1);
- * row[i] = (255<<24)|(grey<<16)|(grey<<8)|grey;
- * }
- * }
- * }
- * This creates a image 200 pixels wide and 100 pixels high
- * that is a horizontal grey ramp, going from black on the left to
- * white on the right.
- *
- * If the image is to be a movie, override isStatic to return false,
- * y cycling back to 0 is computeRow's signal that the next
- * frame has started. It is acceptable (expected?) for computeRow(0,r)
- * to pause until the appropriate time to start the next frame.
- *
- * @author James Gosling
- */
-abstract class SyntheticImage implements ImageProducer {
- private SyntheticImageGenerator root;
- protected int width=10, height=100;
- static final ColorModel cm = ColorModel.getRGBdefault();
- public static final int pixMask = 0xFF;
- private Thread runner;
- protected SyntheticImage() { }
- protected SyntheticImage(int w, int h) { width = w; height = h; }
- protected void computeRow(int y, int[] row) {
- int p = 255-255*y/(height-1);
- p = (pixMask<<24)|(p<<16)|(p<<8)|p;
- for (int i = row.length; --i>=0; ) row[i] = p;
- }
- public synchronized void addConsumer(ImageConsumer ic){
- for (SyntheticImageGenerator ics = root; ics != null; ics = ics.next)
- if (ics.ic == ic) return;
- root = new SyntheticImageGenerator(ic, root, this);
- }
- public synchronized boolean isConsumer(ImageConsumer ic){
- for (SyntheticImageGenerator ics = root; ics != null; ics = ics.next)
- if (ics.ic == ic) return true;
- return false;
- }
- public synchronized void removeConsumer(ImageConsumer ic) {
- SyntheticImageGenerator prev = null;
- for (SyntheticImageGenerator ics = root; ics != null; ics = ics.next) {
- if (ics.ic == ic) {
- ics.useful = false;
- if (prev!=null) prev.next = ics.next;
- else root = ics.next;
- return;
- }
- prev = ics;
- }
- }
- public synchronized void startProduction(ImageConsumer ic) {
- addConsumer(ic);
- for (SyntheticImageGenerator ics = root; ics != null; ics = ics.next)
- if (ics.useful && !ics.isAlive())
- ics.start();
- }
- protected boolean isStatic() { return true; }
- public void nextFrame(int param) {}//Override if !isStatic
- public void requestTopDownLeftRightResend(ImageConsumer ic){}
-
- protected volatile boolean aborted = false;
-}
-
-class SyntheticImageGenerator extends Thread {
- ImageConsumer ic;
- boolean useful;
- SyntheticImageGenerator next;
- SyntheticImage parent;
- SyntheticImageGenerator(ImageConsumer ic, SyntheticImageGenerator next,
- SyntheticImage parent) {
- super("SyntheticImageGenerator");
- this.ic = ic;
- this.next = next;
- this.parent = parent;
- useful = true;
- setDaemon(true);
- }
- public void run() {
- ImageConsumer ic = this.ic;
- int w = parent.width;
- int h = parent.height;
- int hints = ic.SINGLEPASS|ic.COMPLETESCANLINES|ic.TOPDOWNLEFTRIGHT;
- if (parent.isStatic())
- hints |= ic.SINGLEFRAME;
- ic.setHints(hints);
- ic.setDimensions(w, h);
- ic.setProperties(null);
- ic.setColorModel(parent.cm);
-
- if (useful) {
- int[] row=new int[w];
- doPrivileged( new Runnable() {
- public void run() {
- Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
- }
- });
-
- do {
- for (int y = 0; y