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.chart.axis.AxisLocation;
033
034 /**
035 * A JavaBeans property editor for the {@link AxisLocation} class.
036 */
037 public class AxisLocationEditor extends PropertyEditorSupport {
038
039 /**
040 * Returns a string representing the current value.
041 *
042 * @return A string representing the current value.
043 */
044 public String getAsText() {
045 AxisLocation l = (AxisLocation) getValue();
046 if (AxisLocation.BOTTOM_OR_LEFT.equals(l)) {
047 return "BOTTOM OR LEFT";
048 }
049 else if (AxisLocation.BOTTOM_OR_RIGHT.equals(l)) {
050 return "BOTTOM OR RIGHT";
051 }
052 else if (AxisLocation.TOP_OR_LEFT.equals(l)) {
053 return "TOP OR LEFT";
054 }
055 else if (AxisLocation.TOP_OR_RIGHT.equals(l)) {
056 return "TOP OR RIGHT";
057 }
058 throw new RuntimeException("Unrecognised location.");
059 }
060
061 /**
062 * Sets the current value by parsing the supplied string.
063 *
064 * @param text the string value.
065 *
066 * @throws IllegalArgumentException if <code>text</code> is not one of
067 * the values listed in {@link #getAsText()}.
068 */
069 public void setAsText(String text) throws IllegalArgumentException {
070 if ("BOTTOM OR LEFT".equals(text)) {
071 setValue(AxisLocation.BOTTOM_OR_LEFT);
072 }
073 else if ("BOTTOM OR RIGHT".equals(text)) {
074 setValue(AxisLocation.BOTTOM_OR_RIGHT);
075 }
076 else if ("TOP OR LEFT".equals(text)) {
077 setValue(AxisLocation.TOP_OR_LEFT);
078 }
079 else if ("TOP OR RIGHT".equals(text)) {
080 setValue(AxisLocation.TOP_OR_RIGHT);
081 }
082 else {
083 throw new IllegalArgumentException("Unrecognised 'text' argument.");
084 }
085 }
086
087 /**
088 * Returns the valid string values for this property.
089 *
090 * @return The valid string values for this property.
091 */
092 public String[] getTags() {
093 return new String[] {"TOP OR LEFT", "TOP OR RIGHT", "BOTTOM OR LEFT",
094 "BOTTOM OR RIGHT"};
095 }
096
097 /**
098 * Returns a string for the property value.
099 *
100 * @return A string for the property value.
101 */
102 public String getJavaInitializationString() {
103 AxisLocation l = (AxisLocation) getValue();
104 return "org.jfree.chart.axis." + l.toString();
105 }
106
107 }