// ********************************************************************** // // // // BBN Technologies // 10 Moulton Street // Cambridge, MA 02138 // (617) 873-8000 // // Copyright (C) BBNT Solutions LLC. All rights reserved. // // // ********************************************************************** // // $Source: /cvs/openmap/openmap/src/openmap/com/bbn/openmap/layer/location/db/UnitData.java,v $ // $RCSfile: UnitData.java,v $ // $Revision: 1.4 $ // $Date: 2004/10/14 18:18:18 $ // $Author: dietrick $ // // ********************************************************************** package com.bbn.openmap.layer.location.generic; import java.awt.Color; import java.awt.Image; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import java.net.URL; import java.sql.*; import com.bbn.openmap.layer.location.db.*; import com.bbn.openmap.util.PropUtils; import com.bbn.openmap.omGraphics.OMGraphic; import com.bbn.openmap.omGraphics.OMRaster; /** * This class is responsible for retrieving Latitude and Longitude * Data from a table in a Database given a City/Town name, State. Also * it retrieves identifier of the object that would be used to * represent this City/Town on Map. For instance, identifier can be * either a url or a name that can be looked up somewhere else. *

* This class needs the RecordSet to be called with the following * query:
* select CITY (string), STATE (string), GRAPHIC (string, url or * graphic name), LATITUDE (float), LONGITUDE (float) from * LOCATION_TABLE (tablename where data is stored)
* The class is expecting the results in this order. */ public abstract class LocationDataRecordImpl implements LocationDataRecord { /* variables that would hold current values of record set */ protected int recID; protected String labelString; protected LocationColorFormatter.LocColorEntry colorFormatter; protected float latitude, longitude; public LocationDataRecordImpl() {} // ---------------------------------------------------------------- /** Modifier methods */ public void setRecID(int val) { recID = val;} public void setDisplayName(String val) { labelString = val;} public void setGraphicName(String val) { } public void setLatitude(float val) { latitude = val; } public void setLongitude(float val) { longitude = val; } public void setColorFormatter(LocationColorFormatter.LocColorEntry val) { colorFormatter = val; } // ---------------------------------------------------------------- /** Accessor methods */ public int getRecID() { return recID;} public String getDisplayName() { return labelString;} public String getGraphicName() { return ""; } public float getLatitude() { return latitude; } public float getLongitude() { return longitude; } public LocationColorFormatter.LocColorEntry getColorFormatter() { return colorFormatter; } // ---------------------------------------------------------------- public void setLocationColors(LocationColorFormatter colfmt, Object value) { if(colfmt != null && value != null) { setColorFormatter(colfmt.getEntry(value)); } } // ---------------------------------------------------------------- /** * Description string * @return String */ public String getDetails() { return toString();} // ---------------------------------------------------------------- /** * Default output string * @return String */ public String toString() { StringBuffer s = new StringBuffer(); s.append(getDisplayName()); s.append(" @ ( " + latitude + "," + longitude + ")"); return s.toString(); } // ---------------------------------------------------------------- /** * Get the color used for the location graphic. */ public Color getLocationColor(Color defcolor) { return defcolor;} // ---------------------------------------------------------------- /** * Get the color used for the label. */ public Color getLabelColor(Color defcolor) { return defcolor;} // ---------------------------------------------------------------- /** * Get the color used for the label. */ public OMGraphic getGraphic() { OMRaster retVal = new OMRaster(); retVal.setImageIcon(getImageIcon(null)); return retVal; } // ---------------------------------------------------------------- public String getImageUrl() { // ImageIcon icon = new ImageIcon(iconURL); return "file:///C:/J_Projects/GIS/openmap-4.6.3/src/openmap/com/bbn/openmap/layer/location/generic/CYAN16_D.png"; } // ---------------------------------------------------------------- public Image getImage() { Image img = java.awt.Toolkit.getDefaultToolkit().getImage(getImageUrl()); BufferedImage bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); // Graphics2D g = bi.createGraphics(); // g.drawImage(img); bi.createGraphics().drawImage(img, 0, 0, null); return bi; } // ---------------------------------------------------------------- public ImageIcon getImageIcon(LocationColorFormatter colfmt) { // ImageIcon icon = new ImageIcon(iconURL); return new ImageIcon(getImage()); } // ---------------------------------------------------------------- public URL getIcon(String iconurl) { try { return PropUtils.getResourceOrFileOrURL(null, iconurl); } catch (java.net.MalformedURLException mue) { throw new com.bbn.openmap.util.HandleError(mue); } } }