001 /*
002 * This file is part of the Echo Point Project. This project is a
003 * collection of Components that have extended the Echo Web Application
004 * Framework Version 3.
005 *
006 * Version: MPL 1.1
007 *
008 * The contents of this file are subject to the Mozilla Public License Version
009 * 1.1 (the "License"); you may not use this file except in compliance with
010 * the License. You may obtain a copy of the License at
011 * http://www.mozilla.org/MPL/
012 *
013 * Software distributed under the License is distributed on an "AS IS" basis,
014 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015 * for the specific language governing rights and limitations under the
016 * License.
017 */
018
019 package echopoint.google.chart.internal;
020
021 import echopoint.google.chart.model.ChartData;
022 import echopoint.google.chart.model.Title;
023 import echopoint.internal.AbstractContainer;
024 import nextapp.echo.app.Component;
025
026 import java.util.ArrayList;
027 import java.util.Collection;
028
029 /**
030 * The abstract base class for the components that wrap the charts provided
031 * by <a href='http://code.google.com/apis/chart/'>Google Chart API</a>.
032 *
033 * @author Rakesh 2008-08-10
034 * @version $Id: AbstractChart.java 86 2008-11-09 14:44:29Z sptrakesh $
035 */
036 public abstract class AbstractChart<N extends Number> extends AbstractContainer
037 {
038 private static final long serialVersionUID = 1l;
039
040 /**
041 * The alternate text to display for the image and chart. This property
042 * may be styled.
043 */
044 public static final String PROPERTY_ALT = "alt";
045
046 /**
047 * The colour fill property for the chart. Refer to the colour fill
048 * and linear gradient notes for the Google Chart API to determine the
049 * proper formatted string values that may be specified for charts.
050 * This property is best styled using the same string values as documented
051 * by the chart api.
052 */
053 public static final String PROPERTY_FILL = "fill";
054
055 /**
056 * An array of {@link echopoint.google.chart.model.ChartData} model objects that
057 * are to be plotted. Note that all elements of the array should have the
058 * same type of model. Either all model elements must be simple (only xdata),
059 * or should have both xdata and ydata. This property cannot be styled.
060 */
061 public static final String PROPERTY_DATA = "data";
062
063 /**
064 * The title to display for chart. Must be of type {@link
065 * echopoint.google.chart.model.Title}. This property cannot be styled.
066 */
067 public static final String PROPERTY_TITLE = "title";
068
069 /**
070 * <b>AbstractChart</b> is <i>NOT</i> allowed to have any children.
071 *
072 * @see nextapp.echo.app.Component#isValidChild(nextapp.echo.app.Component)
073 */
074 @Override
075 public boolean isValidChild( final Component child )
076 {
077 return false;
078 }
079
080 /**
081 * Get the value of the {@link #PROPERTY_ALT} property.
082 *
083 * @return The value of the {@link #PROPERTY_ALT} property.
084 */
085 public String getAlt()
086 {
087 return (String) get( PROPERTY_ALT );
088 }
089
090 /**
091 * Set the value of the {@link #PROPERTY_ALT} property.
092 *
093 * @param alt The value to set for the property.
094 */
095 public void setAlt( final String alt )
096 {
097 set( PROPERTY_ALT, alt );
098 }
099
100 /**
101 * Get the value of the {@link #PROPERTY_FILL} property.
102 *
103 * @return The value of the {@link #PROPERTY_FILL} property.
104 */
105 public String getFill()
106 {
107 return (String) get( PROPERTY_FILL );
108 }
109
110 /**
111 * Set the value of the {@link #PROPERTY_FILL} property.
112 *
113 * @param fill The value to set for the property.
114 */
115 public void setFill( final String fill )
116 {
117 set( PROPERTY_FILL, fill );
118 }
119
120 /**
121 * Get the value of the {@link #PROPERTY_DATA} property.
122 *
123 * @return The value of the {@link #PROPERTY_DATA} property.
124 */
125 @SuppressWarnings( {"unchecked"} )
126 public Collection<ChartData<N>> getData()
127 {
128 return (Collection<ChartData<N>>) get( PROPERTY_DATA );
129 }
130
131 /**
132 * Set the value of the {@link #PROPERTY_DATA} property.
133 *
134 * @param data The collection of model objects.
135 */
136 public void setData( final Collection<ChartData<N>> data )
137 {
138 final Collection<ChartData<N>> collection =
139 new ArrayList<ChartData<N>>( data );
140 set( PROPERTY_DATA, collection );
141 }
142
143 /**
144 * Set the value of the {@link #PROPERTY_DATA} property using the specified
145 * single data model object instance.
146 *
147 * @see #setData( Collection )
148 * @param data The value to set for the property.
149 */
150 public void setData( final ChartData<N> data )
151 {
152 final Collection<ChartData<N>> collection = new ArrayList<ChartData<N>>();
153 collection.add( data );
154 setData( collection );
155 }
156
157 /**
158 * Get the value of the {@link #PROPERTY_TITLE} property.
159 *
160 * @return The value of the {@link #PROPERTY_TITLE} property.
161 */
162 public Title getTitle()
163 {
164 return (Title) get( PROPERTY_TITLE );
165 }
166
167 /**
168 * Set the value of the {@link #PROPERTY_TITLE} property.
169 *
170 * @param title The value to set for the property.
171 */
172 public void setTitle( final Title title )
173 {
174 set( PROPERTY_TITLE, title );
175 }
176 }