001/**
002 * Get more info at : www.jrebirth.org .
003 * Copyright JRebirth.org © 2011-2013
004 * Contact : sebastien.bordes@jrebirth.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.jrebirth.af.core.resource.color;
019
020import java.util.Arrays;
021import java.util.List;
022
023import javafx.beans.property.DoubleProperty;
024import javafx.beans.property.SimpleDoubleProperty;
025
026/**
027 * The class <strong>HSBColor</strong> used to create an HSB color.
028 *
029 * @author Sébastien Bordes
030 */
031public class HSBColor extends AbstractBaseColor {
032
033    /** The hue value [0.0-360.0] in degrees. */
034    private final DoubleProperty hue = new SimpleDoubleProperty();
035
036    /** The saturation value [0.0-1.0]. */
037    private final DoubleProperty saturation = new SimpleDoubleProperty();
038
039    /** The brightness value [0.0-1.0]. */
040    private final DoubleProperty brightness = new SimpleDoubleProperty();
041
042    /**
043     * Default Constructor.
044     *
045     * @param hue the color hue [0.0-360.0] in degrees
046     * @param saturation the color saturation [0.0-1.0]
047     * @param brightness the color brightness [0.0-1.0]
048     */
049    public HSBColor(final double hue, final double saturation, final double brightness) {
050        super();
051        this.hue.set(hue);
052        this.saturation.set(saturation);
053        this.brightness.set(brightness);
054    }
055
056    /**
057     * Default Constructor.
058     *
059     * @param hue the color hue [0.0-360.0] in degrees
060     * @param saturation the color saturation [0.0-1.0]
061     * @param brightness the color brightness [0.0-1.0]
062     * @param opacity the color opacity [0.0-1.0]
063     */
064    public HSBColor(final double hue, final double saturation, final double brightness, final double opacity) {
065        super(opacity);
066        this.hue.set(hue);
067        this.saturation.set(saturation);
068        this.brightness.set(brightness);
069    }
070
071    /**
072     * Return the hue value [0.0-360.0] in degrees.
073     *
074     * @return Returns the hue.
075     */
076    public double hue() {
077        return this.hue.get();
078    }
079
080    /**
081     * Return the hue property.
082     *
083     * @return Returns the hue property.
084     */
085    public DoubleProperty hueProperty() {
086        return this.hue;
087    }
088
089    /**
090     * Return the saturation value 0.0-1.0.
091     *
092     * @return Returns the saturation.
093     */
094    public double saturation() {
095        return this.saturation.get();
096    }
097
098    /**
099     * Return the saturation property.
100     *
101     * @return Returns the saturation property.
102     */
103    public DoubleProperty saturationProperty() {
104        return this.saturation;
105    }
106
107    /**
108     * Return the brightness value 0.0-1.0.
109     *
110     * @return Returns the brightness.
111     */
112    public double brightness() {
113        return this.brightness.get();
114    }
115
116    /**
117     * Return the brightness property.
118     *
119     * @return Returns the brightness property.
120     */
121    public DoubleProperty brightnessProperty() {
122        return this.brightness;
123    }
124
125    /**
126     * {@inheritDoc}
127     */
128    @Override
129    public void parse(final String... parameters) {
130        // Manage hue composite
131        if (parameters.length >= 1) {
132            hueProperty().set(readDouble(parameters[0], 0.0, 360.0));
133        }
134        // Manage saturation composite
135        if (parameters.length >= 2) {
136            saturationProperty().set(readDouble(parameters[1], 0.0, 1.0));
137        }
138        // Manage brightness composite
139        if (parameters.length >= 3) {
140            brightnessProperty().set(readDouble(parameters[2], 0.0, 1.0));
141        }
142        // Manage opacity
143        if (parameters.length >= 4) {
144            opacityProperty().set(readDouble(parameters[3], 0.0, 1.0));
145        }
146    }
147
148    /**
149     * {@inheritDoc}
150     */
151    @Override
152    protected List<? extends Object> getFieldValues() {
153        return Arrays.asList(hue(), saturation(), brightness(), opacity());
154    }
155
156}