2
* @(#)HTMLColorSliderModel.java 1.0.1 2005-08-28
4
* Copyright (c) 2005 Werner Randelshofer
5
* Staldenmattweg 2, Immensee, CH-6405, Switzerland.
8
* This software is the confidential and proprietary information of
9
* Werner Randelshofer. ("Confidential Information"). You shall not
10
* disclose such Confidential Information and shall use it only in
11
* accordance with the terms of the license agreement you entered into
12
* with Werner Randelshofer.
15
package org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.colorchooser;
19
* ColorSliderModel for the HTML color model (red, green, blue, restricted
20
* to values considered as web-save).
22
* @author Werner Randelshofer
23
* @version 1.0.1 2005-08-28 Method toWebSave generates now ARGB value instead
24
* of just an RGB value. Method isWebSave ignores the alpha channel of a color.
25
* <br>1.0 May 22, 2005 Created.
27
public class HTMLColorSliderModel extends RGBColorSliderModel {
28
private boolean isWebSaveOnly = true;
30
* Creates a new instance.
32
public HTMLColorSliderModel() {
37
return getRGB(components[0].getValue(), components[1].getValue(), components[2].getValue());
40
public int getInterpolatedRGB(int component, float value) {
42
for (int i=0, n = getComponentCount(); i < n; i++) {
43
values[i] = Math.round(components[i].getValue() / 51f) * 51;
45
values[component] = Math.round((value * components[component].getMaximum()) / 51f) * 51;
48
return super.getInterpolatedRGB(component, value);
52
protected int getRGB(int r, int g, int b) {
54
return 0xff000000 | (Math.round(r / 51f) * 51) << 16 | (Math.round(g / 51f) * 51) << 8 | Math.round(b / 51f) * 51;
56
return super.getRGB(r, g, b);
61
public void setRGB(int rgb) {
63
components[0].setValue((Math.round((rgb & 0xff0000) / 51f) * 51) >> 16);
64
components[1].setValue((Math.round((rgb & 0x00ff00) / 51f) * 51) >> 8);
65
components[2].setValue(Math.round((rgb & 0x0000ff) / 51f) * 51);
72
public int toRGB(int[] values) {
75
| (Math.round(values[0] / 51f) * 51) << 16
76
| (Math.round(values[1] / 51f) * 51) << 8
77
| (Math.round(values[2] / 51f) * 51);
79
return super.toRGB(values);
83
public void setWebSaveOnly(boolean b) {
90
public boolean isWebSaveOnly() {
94
public static boolean isWebSave(int rgb) {
95
return (rgb & 0xffffff) == (toWebSave(rgb) & 0xffffff);
97
public static int toWebSave(int rgb) {
100
| ((Math.round(((rgb & 0xff0000) >> 16) / 51f) * 51) << 16)
101
| ((Math.round(((rgb & 0x00ff00) >> 8) / 51f) * 51) << 8)
102
| (Math.round((rgb & 0x0000ff) / 51f) * 51);