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    
028    package org.jfree.beans.editors;
029    
030    import java.beans.PropertyEditorSupport;
031    
032    import org.jfree.ui.RectangleEdge;
033    
034    /**
035     * A JavaBeans property editor for the {@link RectangleEdge} class.
036     */
037    public class RectangleEdgeEditor extends PropertyEditorSupport {
038    
039        /**
040         * Returns a string representing the current value.  This will be one of
041         * the following:
042         * <ul>
043         *   <li>RectangleEdge.TOP</code></li>
044         *   <li>RectangleEdge.BOTTOM</code></li>
045         *   <li>RectangleEdge.LEFT</code></li>
046         *   <li>RectangleEdge.RIGHT</code></li>
047         * </ul>
048         * 
049         * @return A string representing the current value.
050         */
051        public String getAsText() {
052            RectangleEdge r = (RectangleEdge) getValue();
053            return r.toString();
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 (RectangleEdge.TOP.toString().equals(text)) {
066                setValue(RectangleEdge.TOP);
067            }
068            else if (RectangleEdge.BOTTOM.toString().equals(text)) {
069                setValue(RectangleEdge.BOTTOM);
070            }
071            else if (RectangleEdge.LEFT.toString().equals(text)) {
072                setValue(RectangleEdge.LEFT);
073            }
074            else if (RectangleEdge.RIGHT.toString().equals(text)) {
075                setValue(RectangleEdge.RIGHT);
076            }
077            else {
078                throw new IllegalArgumentException("Unrecognised 'text' argument.");
079            }
080        }
081        
082        /**
083         * Returns the valid string values for this property.
084         * 
085         * @return The valid string values for this property.
086         */
087        public String[] getTags() {
088            return new String[] {"RectangleEdge.TOP", "RectangleEdge.BOTTOM", 
089                    "RectangleEdge.LEFT", "RectangleEdge.RIGHT" };
090        }
091    
092        /**
093         * Returns a string for the property value.
094         * 
095         * @return A string for the property value.
096         */
097        public String getJavaInitializationString() {
098            RectangleEdge r = (RectangleEdge) getValue();
099            return "org.jfree.ui." + r.toString();
100        }
101    
102    }