View Javadoc
1 /* ------------------------------------------------------------------- 2 GeoVISTA Center (Penn State, Dept. of Geography) 3 Java source file for the class GeoDataWestCoast 4 Copyright (c), 2002, GeoVISTA Center 5 All Rights Reserved. 6 Original Author: Frank Hardisty 7 $Author: hardisty $ 8 $Id: GeoDataWestCoast.java,v 1.2 2003/04/25 17:44:57 hardisty Exp $ 9 $Date: 2003/04/25 17:44:57 $ 10 Reference: Document no: 11 ___ ___ 12 ------------------------------------------------------------------- * 13 */ 14 15 16 package edu.psu.geovista.data.geog; 17 import java.awt.*; 18 import java.awt.event.*; 19 import javax.swing.event.*; 20 import edu.psu.geovista.io.geog.*; 21 import edu.psu.geovista.db.dbase.*; 22 import edu.psu.geovista.io.csv.*; 23 24 import java.net.*; 25 import java.io.*; 26 27 /*** 28 * Reads shapefiles from included resources 29 * 30 * Object[0] = names of variables 31 * 0bject[1] = data (double[], int[], or String[]) 32 * 0bject[1] = data (double[], int[], or String[]) 33 * ... 34 * Object[n-1] = the shapefile data 35 * 36 * also see DBaseFile, ShapeFile 37 * 38 */ 39 public class GeoDataWestCoast { 40 41 public static final String COMMAND_DATA_SET_MADE = "dataMade"; 42 43 private transient DataSetForApps dataForApps; 44 private transient EventListenerList listenerList; 45 46 public GeoDataWestCoast() { 47 super(); 48 listenerList = new EventListenerList(); 49 this.dataForApps = this.makeDataSetForApps(); 50 this.fireActionPerformed(COMMAND_DATA_SET_MADE); 51 } 52 53 private DataSetForApps makeDataSetForApps(){ 54 Object[] shpData = null; 55 try { 56 57 Class cl = this.getClass(); 58 59 InputStream isCSV = cl.getResourceAsStream("resources/westcoast.csv"); 60 GeogCSVReader csv = new GeogCSVReader(); 61 Object[] csvData = csv.readFile(isCSV); 62 63 shpData = new Object[csvData.length + 1]; 64 for (int i = 0; i < csvData.length; i++) { 65 shpData[i] = csvData[i]; 66 } 67 68 InputStream isSHP = cl.getResourceAsStream("resources/westCoast.shp"); 69 shpData[csvData.length] = new ShapeFile(isSHP); 70 71 } catch (Exception ex) { 72 ex.printStackTrace(); 73 } 74 //this.fireActionPerformed(COMMAND_DATA_SET_MADE); 75 this.dataForApps = new DataSetForApps(); 76 dataForApps.setDataObject(shpData); 77 return dataForApps; 78 79 } 80 81 //private Object[] makeDataSet(String fileName){ 82 // this.makeDataSetForApps(fileName); 83 // return dataForApps.getDataObjectOriginal(); 84 //} 85 86 private String removeExtension(String fileName){ 87 String removed = fileName; 88 int index = fileName.lastIndexOf("."); 89 if (index > -1) { //if it was found 90 int len = fileName.length(); 91 removed = fileName.substring(0,index); 92 } 93 return removed; 94 } 95 96 public void setDataForApps (DataSetForApps dataForApps) { 97 this.dataForApps = dataForApps; 98 } 99 public DataSetForApps getDataForApps() { 100 return this.dataForApps; 101 } 102 103 public Object[] getDataSet() { 104 return this.dataForApps.getDataObjectOriginal(); 105 106 } 107 108 109 /*** 110 * implements ActionListener 111 */ 112 public void addActionListener(ActionListener l) { 113 //System.out.println("GeoDataWestCoast.addActionListener, Hi!!"); 114 listenerList.add(ActionListener.class, l); 115 this.fireActionPerformed(COMMAND_DATA_SET_MADE); 116 117 } 118 119 /*** 120 * removes an ActionListener from the button 121 */ 122 public void removeActionListener(ActionListener l) { 123 listenerList.remove(ActionListener.class, l); 124 } 125 126 /*** 127 * Notify all listeners that have registered interest for 128 * notification on this event type. The event instance 129 * is lazily created using the parameters passed into 130 * the fire method. 131 * @see EventListenerList 132 */ 133 protected void fireActionPerformed(String command) { 134 // Guaranteed to return a non-null array 135 Object[] listeners = listenerList.getListenerList(); 136 ActionEvent e = null; 137 // Process the listeners last to first, notifying 138 // those that are interested in this event 139 for (int i = listeners.length - 2; i >= 0; i -= 2) { 140 if (listeners[i] == ActionListener.class) { 141 // Lazily create the event: 142 if (e == null) { 143 e = new ActionEvent(this, 144 ActionEvent.ACTION_PERFORMED, 145 command); 146 } 147 ((ActionListener)listeners[i + 1]).actionPerformed(e); 148 } 149 } 150 } 151 152 }

This page was automatically generated by Maven