001/* ======================================================
002 * Orson : a free chart beans library based on JFreeChart
003 * ======================================================
004 *
005 * (C) Copyright 2007, by Object Refinery Limited.
006 *
007 * Project Info:  not-yet-released
008 *
009 * This library is free software; you can redistribute it and/or modify it 
010 * under the terms of the GNU Lesser General Public License as published by 
011 * the Free Software Foundation; either version 2.1 of the License, or 
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but 
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022 * USA.  
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025 * in the United States and other countries.]
026 */
027
028package org.jfree.beans.editors;
029
030import java.beans.PropertyEditorSupport;
031
032import org.jfree.util.Rotation;
033
034/**
035 * A JavaBeans property editor for the {@link Rotation} class.
036 */
037public class RotationEditor extends PropertyEditorSupport {
038
039    /**
040     * Returns a string representing the current value.  This will be one of
041     * <code>Rotation.CLOCKWISE</code> and <code>Rotation.ANTICLOCKWISE</code>.
042     * 
043     * @return A string representing the current value.
044     */
045    public String getAsText() {
046        Rotation r = (Rotation) getValue();
047        if (Rotation.CLOCKWISE.equals(r)) {
048            return "CLOCKWISE";
049        }
050        else if (Rotation.ANTICLOCKWISE.equals(r)) {
051            return "ANTICLOCKWISE";
052        }
053        else throw new RuntimeException("Bad Rotation instance.");
054    }
055    
056    /**
057     * Sets the current value by parsing the supplied string.
058     * 
059     * @param text  the string value.
060     * 
061     * @throws IllegalArgumentException if <code>text</code> is not one of
062     *     the values listed in {@link #getAsText()}.
063     */
064    public void setAsText(String text) throws IllegalArgumentException {
065        if ("CLOCKWISE".equals(text)) {
066            setValue(Rotation.CLOCKWISE);
067        }
068        else if ("ANTICLOCKWISE".equals(text)) {
069            setValue(Rotation.ANTICLOCKWISE);
070        }
071        else {
072            throw new IllegalArgumentException("Unrecognised 'text' argument.");
073        }
074    }
075    
076    /**
077     * Returns the valid string values for this property.
078     * 
079     * @return The valid string values for this property.
080     */
081    public String[] getTags() {
082        return new String[] {"CLOCKWISE", "ANTICLOCKWISE"};
083    }
084
085    /**
086     * Returns a string for the property value.
087     * 
088     * @return A string for the property value.
089     */
090    public String getJavaInitializationString() {
091        Rotation r = (Rotation) getValue();
092        if (Rotation.CLOCKWISE.equals(r)) {
093            return "org.jfree.util.Rotation.CLOCKWISE";
094        }
095        else if (Rotation.ANTICLOCKWISE.equals(r)) {
096            return "org.jfree.util.Rotation.ANTICLOCKWISE";
097        }
098        return null;
099    }
100
101}