001/* ============
002 * FXGraphics2D
003 * ============
004 * 
005 * (C)opyright 2014-2020, by Object Refinery Limited.
006 * 
007 * http://www.jfree.org/fxgraphics2d/index.html
008 *
009 * The FXGraphics2D class has been developed by Object Refinery Limited for 
010 * use in Orson Charts (http://www.object-refinery.com/orsoncharts) and
011 * JFreeChart (http://www.jfree.org/jfreechart).  It may be useful for other
012 * code that uses the Graphics2D API provided by Java2D.
013 * 
014 * Redistribution and use in source and binary forms, with or without
015 * modification, are permitted provided that the following conditions are met:
016 *   - Redistributions of source code must retain the above copyright
017 *     notice, this list of conditions and the following disclaimer.
018 *   - Redistributions in binary form must reproduce the above copyright
019 *     notice, this list of conditions and the following disclaimer in the
020 *     documentation and/or other materials provided with the distribution.
021 *   - Neither the name of the Object Refinery Limited nor the
022 *     names of its contributors may be used to endorse or promote products
023 *     derived from this software without specific prior written permission.
024 *
025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
028 * ARE DISCLAIMED. IN NO EVENT SHALL OBJECT REFINERY LIMITED BE LIABLE FOR ANY
029 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
031 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
032 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
033 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
034 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
035 * 
036 */
037
038package org.jfree.fx;
039
040import java.awt.GraphicsConfiguration;
041import java.awt.GraphicsDevice;
042import java.awt.Rectangle;
043import java.awt.Transparency;
044import java.awt.geom.AffineTransform;
045import java.awt.image.ColorModel;
046import java.awt.image.DirectColorModel;
047
048/**
049 * A graphics configuration for the {@link FXGraphics2D} class.
050 */
051public class FXGraphicsConfiguration extends GraphicsConfiguration {
052
053    private GraphicsDevice device;
054    
055    private final int width, height;
056    
057    /**
058     * Creates a new instance.
059     * 
060     * @param width  the width of the bounds.
061     * @param height  the height of the bounds.
062     */
063    public FXGraphicsConfiguration(int width, int height) {
064      super(); 
065      this.width = width;
066      this.height = height;
067    }
068    
069    /**
070     * Returns the graphics device that this configuration is associated with.
071     * 
072     * @return The graphics device (never {@code null}).
073     */
074    @Override
075    public GraphicsDevice getDevice() {
076        if (this.device == null) {
077            this.device = new FXGraphicsDevice("FXGraphicsDevice", this);
078        }
079        return this.device;
080    }
081
082    /**
083     * Returns the color model for this configuration.
084     * 
085     * @return The color model.
086     */
087    @Override
088    public ColorModel getColorModel() {
089        return getColorModel(Transparency.TRANSLUCENT);
090    }
091
092    /**
093     * Returns the color model for the specified transparency type, or 
094     * {@code null}.
095     * 
096     * @param transparency  the transparency type.
097     * 
098     * @return A color model (possibly {@code null}).
099     */
100    @Override
101    public ColorModel getColorModel(int transparency) {
102        if (transparency == Transparency.TRANSLUCENT) {
103            return ColorModel.getRGBdefault();
104        } else if (transparency == Transparency.OPAQUE) {
105            return new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff);
106        } else {
107            return null;
108        }
109    }
110
111    /**
112     * Returns the default transform.
113     * 
114     * @return The default transform. 
115     */
116    @Override
117    public AffineTransform getDefaultTransform() {
118        return new AffineTransform();
119    }
120
121    /**
122     * Returns the normalizing transform.
123     * 
124     * @return The normalizing transform. 
125     */
126    @Override
127    public AffineTransform getNormalizingTransform() {
128        return new AffineTransform();
129    }
130    
131    /**
132     * Returns the bounds for this configuration.
133     * 
134     * @return The bounds. 
135     */
136    @Override
137    public Rectangle getBounds() {
138        return new Rectangle(this.width, this.height);
139    }
140    
141}