001: /***********************************************************************************************
002: * File Info: $Id: ImageMapArea.java,v 1.1 2003/05/17 16:59:18 nathaniel_auvil Exp $
003: * Copyright (C) 2001
004: * Author: Nathaniel G. Auvil
005: * Contributor(s):
006: *
007: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
008: *
009: * Redistribution and use of this software and associated documentation
010: * ("Software"), with or without modification, are permitted provided
011: * that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain copyright
014: * statements and notices. Redistributions must also contain a
015: * copy of this document.
016: *
017: * 2. Redistributions in binary form must reproduce the
018: * above copyright notice, this list of conditions and the
019: * following disclaimer in the documentation and/or other
020: * materials provided with the distribution.
021: *
022: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to
023: * endorse or promote products derived from this Software without
024: * prior written permission of Nathaniel G. Auvil. For written
025: * permission, please contact nathaniel_auvil@users.sourceforge.net
026: *
027: * 4. Products derived from this Software may not be called "jCharts"
028: * nor may "jCharts" appear in their names without prior written
029: * permission of Nathaniel G. Auvil. jCharts is a registered
030: * trademark of Nathaniel G. Auvil.
031: *
032: * 5. Due credit should be given to the jCharts Project
033: * (http://jcharts.sourceforge.net/).
034: *
035: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS
036: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
037: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
038: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
039: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
040: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
041: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
042: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
043: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
044: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
045: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
046: * OF THE POSSIBILITY OF SUCH DAMAGE.
047: ************************************************************************************************/package org.krysalis.jcharts.imageMap;
048:
049: import java.io.Serializable;
050: import java.awt.geom.Point2D;
051:
052: /*****************************************************************************************
053: *
054: *
055: ******************************************************************************************/
056: public abstract class ImageMapArea implements Serializable {
057: //---less overhead than creating Point Objects
058: int[] x;
059: int[] y;
060:
061: private double value;
062: private String xAxisLabel;
063: private String legendLabel;
064:
065: /***************************************************************************************
066: *
067: * @param numberOfPoints
068: * @param value
069: * @param xAxisLabel
070: * @param legendLabel
071: ****************************************************************************************/
072: ImageMapArea(int numberOfPoints, double value, String xAxisLabel,
073: String legendLabel) {
074: this .x = new int[numberOfPoints];
075: this .y = new int[numberOfPoints];
076:
077: this .value = value;
078: this .xAxisLabel = xAxisLabel;
079: this .legendLabel = legendLabel;
080: }
081:
082: /***************************************************************************************
083: *
084: * @param numberOfPoints
085: * @param point
086: * @param legendLabel
087: ****************************************************************************************/
088: ImageMapArea(int numberOfPoints, Point2D.Double point,
089: String legendLabel) {
090: this .x = new int[numberOfPoints];
091: this .y = new int[numberOfPoints];
092:
093: this .value = point.getY();
094: this .xAxisLabel = Double.toString(point.getX());
095: this .legendLabel = legendLabel;
096: }
097:
098: /************************************************************************************
099: *
100: * @return AreaShape
101: ***********************************************************************************/
102: abstract AreaShape getAreaShape();
103:
104: /***************************************************************************************
105: * Returns the number of x,y coordinate pairs stored for the area
106: *
107: * @return int
108: ****************************************************************************************/
109: public final int getNumberOfCoordinates() {
110: return this .x.length;
111: }
112:
113: /***************************************************************************************
114: * Returns the x coordinate at the specified index. Not returned as a Point Object so we
115: * can avoid uneeded Object creation/destruction overhead.
116: *
117: * @return int
118: ****************************************************************************************/
119: public final int getXCoordinate(int index) {
120: return this .x[index];
121: }
122:
123: /***************************************************************************************
124: * Returns the y coordinate at the specified index. Not returned as a Point Object so we
125: * can avoid uneeded Object creation/destruction overhead.
126: *
127: * @return int
128: ****************************************************************************************/
129: public final int getYCoordinate(int index) {
130: return this .y[index];
131: }
132:
133: /***************************************************************************************
134: * Returns the data set value represented by this map.
135: *
136: * @return double
137: ****************************************************************************************/
138: public final double getValue() {
139: return this .value;
140: }
141:
142: /***************************************************************************************
143: * Rather than create an AxisChart specifc map area class just for this field, i put it
144: * here. This is not applicable for PieCharts.
145: *
146: * @return String will return NULL for PieCharts
147: ****************************************************************************************/
148: public final String getXAxisLabel() {
149: return this .xAxisLabel;
150: }
151:
152: /***************************************************************************************
153: * Returns the legend label represented by this map area. Will be NULL if you did not
154: * pass a name to the data set constructor.
155: *
156: * @return String
157: ****************************************************************************************/
158: public final String getLengendLabel() {
159: return this .legendLabel;
160: }
161:
162: /***************************************************************************************
163: * Appends the coordinates to the passed html buffer. This is needed to facilitate the
164: * 'circle' map areas 'radius' value.
165: *
166: * @param html pass a reference to the StringBuffer so I can minimize Object creation
167: ****************************************************************************************/
168: protected void getCoordinates(StringBuffer html) {
169: for (int i = 0; i < this .x.length; i++) {
170: html.append(this .x[i] + "," + this .y[i]);
171: if (i + 1 != this .x.length) {
172: html.append(",");
173: }
174: }
175: }
176:
177: /**************************************************************************************************
178: * Returns a <pre><area shape="..." coords="....." + mapElementAttributes ></pre> HTML element.
179: * The mapElementAttributes frees this method from having to declare all attributes of the HTML map
180: * element.
181: *
182: * @param mapElementAttributes allows you to place any map attributes you want:
183: * href, alt, onClick, onMouseOver, etc...
184: * @return String the HTML
185: ***************************************************************************************************/
186: public final String toHTML(String mapElementAttributes) {
187: StringBuffer html = new StringBuffer(250);
188:
189: html.append("<area");
190: html
191: .append(" shape=\"" + this .getAreaShape().getValue()
192: + "\"");
193:
194: html.append(" coords=\"");
195: this .getCoordinates(html);
196: html.append("\" ");
197:
198: html.append(mapElementAttributes);
199: html.append(">\n");
200:
201: return html.toString();
202: }
203: }
|