    001/* ===========================================================
    002 * Orson Charts : a 3D chart library for the Java(tm) platform
    003 * ===========================================================
    004 *
    005 * (C)opyright 2013-2016, by Object Refinery Limited.  All rights reserved.
    006 *
    007 * http://www.object-refinery.com/orsoncharts/index.html
    008 *
    009 * This program is free software: you can redistribute it and/or modify
    010 * it under the terms of the GNU General Public License as published by
    011 * the Free Software Foundation, either version 3 of the License, or
    012 * (at your option) any later version.
    013 *
    014 * This program is distributed in the hope that it will be useful,
    015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    017 * GNU General Public License for more details.
    018 *
    019 * You should have received a copy of the GNU General Public License
    020 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    021 *
    022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
    023 * Other names may be trademarks of their respective owners.]
    024 *
    025 * If you do not wish to be bound by the terms of the GPL, an alternative
    026 * commercial license can be purchased.  For details, please see visit the
    027 * Orson Charts home page:
    028 *
    029 * http://www.object-refinery.com/orsoncharts/index.html
    030 *
    031 */
    032
    033package com.orsoncharts;
    034
    035import java.util.Map;
    036
    037/**
    038 * Special rendering hints that used internally by Orson Charts to provide
    039 * links between rendered items and the chart elements that they represent.
    040 * Most {@code Graphics2D} implementations will ignore these hints but
    041 * some, for example the {@code SVGGraphics2D} class in
    042 * <a href="http://www.jfree.org/jfreesvg">JFreeSVG</a>, will use the hints
    043 * to drive the output content.
    044 *
    045 * @since 1.3
    046 */
    047public final class Chart3DHints {
    048
    049    private Chart3DHints() {
    050        // no need to instantiate this
    051    }
    052
    053    /**
    054     * The key for a hint to signal the beginning of an element.  The value
    055     * should be a string containing the element id or, alternatively, a Map
    056     * containing the 'id' (String) and 'ref' (String in JSON format).
    057     */
    058    public static final Key KEY_BEGIN_ELEMENT = new Chart3DHints.Key(0);
    059
    060    /**
    061     * The key for a hint that ends an element.
    062     */
    063    public static final Key KEY_END_ELEMENT = new Chart3DHints.Key(1);
    064
    065    /**
    066     * A key for rendering hints that can be used with Orson Charts (in
    067     * addition to the regular Java2D rendering hints).
    068     */
    069    public static class Key extends java.awt.RenderingHints.Key {
    070
    071        /**
    072         * Creates a new key.
    073         *
    074         * @param privateKey  the private key.
    075         */
    076        public Key(int privateKey) {
    077            super(privateKey);
    078        }
    079
    080        /**
    081         * Returns {@code true} if {@code val} is a value that is
    082         * compatible with this key, and {@code false} otherwise.
    083         *
    084         * @param val  the value ({@code null} permitted).
    085         *
    086         * @return A boolean.
    087         */
    088        @Override
    089        public boolean isCompatibleValue(Object val) {
    090            switch (intKey()) {
    091                case 0:
    092                    return val == null || val instanceof String
    093                            || val instanceof Map;
    094                case 1:
    095                    return val == null || val instanceof Object;
    096                default:
    097                    throw new RuntimeException("Not possible!");
    098            }
    099        }
    100    }
    101
    102}