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