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