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.beans.AxisScale;
033
034/**
035 * A JavaBeans property editor for the {@link AxisScale} class.
036 */
037public class AxisScaleEditor extends PropertyEditorSupport {
038
039    /**
040     * Returns a string representing the current value.  This will be one of
041     * <code>INTEGER</code> and <code>FLOAT</code>.
042     * 
043     * @return A string representing the current value.
044     */
045    public String getAsText() {
046        AxisScale as = (AxisScale) getValue();
047        if (as.equals(AxisScale.INTEGER)) {
048            return "INTEGER";
049        }
050        else if (as.equals(AxisScale.FLOAT)) {
051            return "FLOAT";
052        }
053        throw new IllegalStateException("Bad AxisScale.");
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 ("INTEGER".equals(text)) {
066            setValue(AxisScale.INTEGER);
067        }
068        else if ("FLOAT".equals(text)) {
069            setValue(AxisScale.FLOAT);
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[] {"INTEGER", "FLOAT"};
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        AxisScale as = (AxisScale) getValue();
092        return "org.jfree.beans." + as.toString();
093    }
094
095}