KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > imageMap > ImageMapArea


1 /***********************************************************************************************
2  * File Info: $Id: ImageMapArea.java,v 1.1 2003/05/17 16:59:18 nathaniel_auvil Exp $
3  * Copyright (C) 2001
4  * Author: Nathaniel G. Auvil
5  * Contributor(s):
6  *
7  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
8  *
9  * Redistribution and use of this software and associated documentation
10  * ("Software"), with or without modification, are permitted provided
11  * that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain copyright
14  * statements and notices. Redistributions must also contain a
15  * copy of this document.
16  *
17  * 2. Redistributions in binary form must reproduce the
18  * above copyright notice, this list of conditions and the
19  * following disclaimer in the documentation and/or other
20  * materials provided with the distribution.
21  *
22  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to
23  * endorse or promote products derived from this Software without
24  * prior written permission of Nathaniel G. Auvil. For written
25  * permission, please contact nathaniel_auvil@users.sourceforge.net
26  *
27  * 4. Products derived from this Software may not be called "jCharts"
28  * nor may "jCharts" appear in their names without prior written
29  * permission of Nathaniel G. Auvil. jCharts is a registered
30  * trademark of Nathaniel G. Auvil.
31  *
32  * 5. Due credit should be given to the jCharts Project
33  * (http://jcharts.sourceforge.net/).
34  *
35  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS
36  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
37  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
38  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
39  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
40  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
42  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46  * OF THE POSSIBILITY OF SUCH DAMAGE.
47  ************************************************************************************************/

48
49 package org.krysalis.jcharts.imageMap;
50
51
52 import java.io.Serializable JavaDoc;
53 import java.awt.geom.Point2D JavaDoc;
54
55
56 /*****************************************************************************************
57  *
58  *
59  ******************************************************************************************/

60 public abstract class ImageMapArea implements Serializable JavaDoc
61 {
62     //---less overhead than creating Point Objects
63
int[] x;
64     int[] y;
65
66     private double value;
67     private String JavaDoc xAxisLabel;
68     private String JavaDoc legendLabel;
69
70
71     /***************************************************************************************
72      *
73      * @param numberOfPoints
74      * @param value
75      * @param xAxisLabel
76      * @param legendLabel
77      ****************************************************************************************/

78     ImageMapArea( int numberOfPoints, double value, String JavaDoc xAxisLabel, String JavaDoc legendLabel )
79     {
80         this.x=new int[ numberOfPoints ];
81         this.y=new int[ numberOfPoints ];
82
83         this.value=value;
84         this.xAxisLabel=xAxisLabel;
85         this.legendLabel=legendLabel;
86     }
87
88
89     /***************************************************************************************
90      *
91      * @param numberOfPoints
92      * @param point
93      * @param legendLabel
94      ****************************************************************************************/

95     ImageMapArea( int numberOfPoints, Point2D.Double JavaDoc point, String JavaDoc legendLabel )
96     {
97         this.x=new int[ numberOfPoints ];
98         this.y=new int[ numberOfPoints ];
99
100         this.value= point.getY();
101         this.xAxisLabel= Double.toString( point.getX() );
102         this.legendLabel=legendLabel;
103     }
104
105
106     /************************************************************************************
107      *
108      * @return AreaShape
109      ***********************************************************************************/

110     abstract AreaShape getAreaShape();
111
112
113     /***************************************************************************************
114      * Returns the number of x,y coordinate pairs stored for the area
115      *
116      * @return int
117      ****************************************************************************************/

118     public final int getNumberOfCoordinates()
119     {
120         return this.x.length;
121     }
122
123
124     /***************************************************************************************
125      * Returns the x coordinate at the specified index. Not returned as a Point Object so we
126      * can avoid uneeded Object creation/destruction overhead.
127      *
128      * @return int
129      ****************************************************************************************/

130     public final int getXCoordinate( int index )
131     {
132         return this.x[ index ];
133     }
134
135
136     /***************************************************************************************
137      * Returns the y coordinate at the specified index. Not returned as a Point Object so we
138      * can avoid uneeded Object creation/destruction overhead.
139      *
140      * @return int
141      ****************************************************************************************/

142     public final int getYCoordinate( int index )
143     {
144         return this.y[ index ];
145     }
146
147
148     /***************************************************************************************
149      * Returns the data set value represented by this map.
150      *
151      * @return double
152      ****************************************************************************************/

153     public final double getValue()
154     {
155         return this.value;
156     }
157
158
159     /***************************************************************************************
160      * Rather than create an AxisChart specifc map area class just for this field, i put it
161      * here. This is not applicable for PieCharts.
162      *
163      * @return String will return NULL for PieCharts
164      ****************************************************************************************/

165     public final String JavaDoc getXAxisLabel()
166     {
167         return this.xAxisLabel;
168     }
169
170
171     /***************************************************************************************
172      * Returns the legend label represented by this map area. Will be NULL if you did not
173      * pass a name to the data set constructor.
174      *
175      * @return String
176      ****************************************************************************************/

177     public final String JavaDoc getLengendLabel()
178     {
179         return this.legendLabel;
180     }
181
182
183     /***************************************************************************************
184      * Appends the coordinates to the passed html buffer. This is needed to facilitate the
185      * 'circle' map areas 'radius' value.
186      *
187      * @param html pass a reference to the StringBuffer so I can minimize Object creation
188      ****************************************************************************************/

189     protected void getCoordinates( StringBuffer JavaDoc html )
190     {
191         for( int i=0; i < this.x.length; i++ )
192         {
193             html.append( this.x[ i ] + "," + this.y[ i ] );
194             if( i + 1 != this.x.length )
195             {
196                 html.append( "," );
197             }
198         }
199     }
200
201
202     /**************************************************************************************************
203      * Returns a <pre><area shape="..." coords="....." + mapElementAttributes ></pre> HTML element.
204      * The mapElementAttributes frees this method from having to declare all attributes of the HTML map
205      * element.
206      *
207      * @param mapElementAttributes allows you to place any map attributes you want:
208      * href, alt, onClick, onMouseOver, etc...
209      * @return String the HTML
210      ***************************************************************************************************/

211     public final String JavaDoc toHTML( String JavaDoc mapElementAttributes )
212     {
213         StringBuffer JavaDoc html=new StringBuffer JavaDoc( 250 );
214
215         html.append( "<area" );
216         html.append( " shape=\"" + this.getAreaShape().getValue() + "\"" );
217
218         html.append( " coords=\"" );
219         this.getCoordinates( html );
220         html.append( "\" " );
221
222         html.append( mapElementAttributes );
223         html.append( ">\n" );
224
225         return html.toString();
226     }
227 }
228
Popular Tags