-
Notifications
You must be signed in to change notification settings - Fork 45
/
cs424p3.pde
296 lines (243 loc) · 8.44 KB
/
cs424p3.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import org.khelekore.prtree.*;
View rootView;
PFont font;
PFont font2;
HBar hbar;
HBar hbar2;
Animator settingsAnimator;
Animator detailsAnimator;
PApplet papplet;
MapView mapv;
GraphContainer graphContainer;
GraphView graphView;
Button graphButton;
ListBox graphModeList;
boolean graphOn;
SettingsView settingsView;
SightingDetailsView sightingDetailsView;
DateFormat dateTimeFormat= new SimpleDateFormat("EEEE, MMMM dd, yyyy HH:mm");
DateFormat dateFormat= new SimpleDateFormat("EEEE, MMMM dd, yyyy");
DateFormat shortDateFormat= new SimpleDateFormat("MM/dd/yyyy HH:mm");
DateFormat dbDateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
color backgroundColor = 0;
color textColor = 255;
color boldTextColor = #FFFF00;
color titleTextColor = 0;
color viewBackgroundColor = #2D2A36;
color airportAreaColor = #FFA500;
color militaryBaseColor = #CC0000;
color weatherStationColor = #FFFF00;
color infoBoxBackground = #000000;
//color[] UFOColors = {#FFFF00,#00FF00,#00FFFF,#FF8000,#800FFF,#FF0000,};
color[] UFOColors = {#0000FF,#FF6600,#00FFFF,#FF0000,#FFFF00,#00FF00,#800FFF};
int normalFontSize = 13;
int smallFontSize = 10 ;
int largeFontSize = 15;
String[] monthLabelsToPrint = {"January","February","March","April","May","June","July","August","September","October","November","December"};
String[] monthLabels = {"01","02","03","04","05","06","07","08","09","10","11","12"};
String[] yearLabels = {"'00","'01","'02","'03","'04","'05","'06","'07","'08","'09","'10","'11"};
String[] yearLabelsToPrint = {"2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011"};
String[] timeLabels = {"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"};
String[] UFOTypeLabels = {"UFOType 1","UFOType 2","UFOType 3","UFOType 4","UFOType 5","UFOType 6","UFOType 7"};
String[] UFOImages = {"blue.png","green.png","star.png","orange.png","purple.png","red.png","yellow.png"};
PImage airplaneImage;
PImage militaryBaseImage;
PImage weatherStationImage;
Map<Integer,SightingType> sightingTypeMap = new LinkedHashMap<Integer, SightingType>();
Map<Integer,State> stateMap = new HashMap<Integer,State>();
Map<Integer,Place> cityMap = new HashMap<Integer,Place>();
Map<Integer,Place> airportMap = new HashMap<Integer,Place>();
Map<Integer,Place> militaryBaseMap = new HashMap<Integer,Place>();
Map<Integer,Place> weatherStationMap = new HashMap<Integer,Place>();
PRTree<Place> cityTree;
PRTree<Place> airportTree;
PRTree<Place> militaryBaseTree;
PRTree<Place> weatherStationTree;
Map<SightingType, Checkbox> typeCheckboxMap;
Sighting clickedSighting;
Boolean showAirports=false;
Boolean showMilitaryBases = false;
Boolean showWeatherStation = false;
Boolean showByStates = true;
Boolean btwMonths = false;
Boolean btwTime = false;
String byType = "";
Boolean isDragging = false;
SightingsFilter activeFilter;
DataSource data;
boolean playing = false;
Player player;
void setup()
{
size(1000, 700); // OPENGL seems to be slower than the default
// setupG2D();
papplet = this;
smooth();
/* load data */
if (sketchPath == null) // applet
data = new WebDataSource("http://young-mountain-2805.heroku.com/"); //dataPath("jsontest")
else // application
data = new SQLiteDataSource();
data.loadSightingTypes();
activeFilter = new SightingsFilter();
data.loadStates();
data.loadCities();
data.loadAirports();
data.loadMilitaryBases();
data.loadWeatherStations();
data.reloadCitySightingCounts();
data.loadCityDistances();
updateStateSightingCounts();
buildPlaceTree();
/* setup UI */
rootView = new View(0, 0, width, height);
font = loadFont("Helvetica-20.vlw");
font2 = loadFont("Courier-20.vlw");
airplaneImage = loadImage("plane.png");
militaryBaseImage = loadImage("militars.png");
weatherStationImage = loadImage("irkickflash2.png");
mapv = new MapView(0,0,width,height);
rootView.subviews.add(mapv);
settingsView = new SettingsView(0,-80,width,125);
rootView.subviews.add(settingsView);
sightingDetailsView = new SightingDetailsView(0,height,width,200);
rootView.subviews.add(sightingDetailsView);
settingsAnimator = new Animator(settingsView.y);
detailsAnimator = new Animator(sightingDetailsView.y);
// I want to add true multitouch support, but let's have this as a stopgap for now
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
rootView.mouseWheel(mouseX, mouseY, evt.getWheelRotation());
}
});
graphContainer = new GraphContainer(0, 20, width, height-20);
graphButton = new Button(0, 0, width, 20, "Click here to show the Graphs");
rootView.subviews.add(graphButton);
graphOn = false;
}
void buttonClicked(Button button)
{
if (button == graphButton) {
graphOn = !graphOn;
if (graphOn){
rootView.subviews.add(graphContainer);
button.label = "Click here to show the Map";
graphContainer.updateValuesGraph();
}
else{
rootView.subviews.remove(graphContainer);
button.label = "Click here to show the Graphs";
}
}
}
void buttonClicked(Checkbox button)
{
if (graphOn)
graphContainer.updateValuesMap();
for (Entry<SightingType, Checkbox> entry : typeCheckboxMap.entrySet()) {
entry.getKey().setActive(entry.getValue().value);
}
btwTime = settingsView.timeCheckbox.value;
btwMonths = settingsView.monthCheckbox.value;
updateFilter();
if (showAirports != settingsView.showAirportCB.value || showMilitaryBases != settingsView.showMilitaryBasesCB.value
|| showWeatherStation != settingsView.showWeatherStationCB.value || showByStates != settingsView.showByStatesCB.value){
showAirports = settingsView.showAirportCB.value;
showMilitaryBases = settingsView.showMilitaryBasesCB.value;
showWeatherStation = settingsView.showWeatherStationCB.value;
showByStates = settingsView.showByStatesCB.value;
mapv.rebuildOverlay();
}
if (showByStates)
detailsAnimator.target(height);
}
void listClicked(ListBox lb, int index, Object item)
{
if (lb == graphModeList) {
graphView.setActiveMode((String)item);
String _item = (String)item;
if (!_item.equals("Year") && !_item.equals("Season") && !_item.equals("Month") && !_item.equals("Time of day")){
graphContainer.graphAnimator.target(graphContainer.h-120);
}
else{
graphContainer.graphAnimator.target(graphContainer.h-5);
}
}
}
void startPlaying()
{
playing = true;
player = new Player();
settingsView.playBarAnimator.target(100);
}
void stopPlaying()
{
playing = false;
player = null;
settingsView.playBarAnimator.target(0);
}
void draw()
{
background(backgroundColor);
Animator.updateAll();
settingsView.y = settingsAnimator.value;
sightingDetailsView.y = detailsAnimator.value;
settingsView.playBar.w = settingsView.playBarAnimator.value;
rootView.draw();
}
void mousePressed()
{
rootView.mousePressed(mouseX, mouseY);
}
void mouseDragged()
{
isDragging = true;
rootView.mouseDragged(mouseX, mouseY);
}
void mouseClicked()
{
rootView.mouseClicked(mouseX, mouseY);
}
/* returns true if filter changed */
boolean updateFilter()
{
SightingsFilter newFilter = new SightingsFilter();
newFilter.viewMinYear = 2000 + settingsView.yearSlider.minIndex();
newFilter.viewMaxYear = 2000 + settingsView.yearSlider.maxIndex();
if (btwMonths) {
newFilter.viewMinMonth = 1 + settingsView.monthSlider.minIndex();
newFilter.viewMaxMonth = 1 + settingsView.monthSlider.maxIndex();
}
if (btwTime) {
newFilter.viewMinHour = settingsView.timeSlider.minIndex();
newFilter.viewMaxHour = settingsView.timeSlider.maxIndex();
}
Set<SightingType> activeTypes = new HashSet<SightingType>();
for (SightingType type : sightingTypeMap.values()) {
if (type.active) activeTypes.add(type);
}
newFilter.activeTypes = activeTypes;
if (!newFilter.equals(activeFilter)) {
println(activeFilter + " -> " + newFilter);
boolean reload = !newFilter.equalsIgnoringTypes(activeFilter);
activeFilter = newFilter;
if (reload) {
data.reloadCitySightingCounts();
updateStateSightingCounts();
} else {
println("recomputing totals");
updateCitySightingTotals();
updateStateSightingTotals();
}
mapv.rebuildOverlay();
detailsAnimator.target(height);
return true;
}
else return false;
}
void mouseReleased(){
if (isDragging) {
updateFilter();
}
isDragging = false;
}