├── LICENSE
├── README
├── README.md
├── UCSDGraphs.iml
├── data
├── airports
│ └── routesUA.dat
├── graders
│ ├── mod1
│ │ ├── graph1.txt
│ │ ├── graph1.txt.degrees
│ │ ├── graph2.txt
│ │ ├── graph2.txt.degrees
│ │ ├── graph3.txt
│ │ ├── graph3.txt.degrees
│ │ ├── graph4.txt
│ │ ├── graph4.txt.degrees
│ │ ├── graph5.txt
│ │ ├── graph6.txt
│ │ ├── routesUA.dat
│ │ ├── routesUA.dat.degrees
│ │ ├── routesUA.dat.twoaway
│ │ ├── ucsd.map
│ │ ├── ucsd.map.degrees
│ │ └── ucsd.map.twoaway
│ ├── mod2
│ │ ├── map1.txt
│ │ ├── map1.txt.answer
│ │ ├── map2.txt
│ │ ├── map2.txt.answer
│ │ ├── map3.txt
│ │ ├── map3.txt.answer
│ │ ├── ucsd.map
│ │ └── ucsd.map.answer
│ └── mod3
│ │ ├── map1.txt
│ │ ├── map1.txt.answer
│ │ ├── map2.txt
│ │ ├── map2.txt.answer
│ │ ├── map3.txt
│ │ ├── map3.txt.answer
│ │ ├── ucsd.map
│ │ └── ucsd.map.answer
├── intersections
│ ├── hollywood_large.intersections
│ ├── hollywood_small.intersections
│ ├── new_york.intersections
│ ├── newbury_small.intersections
│ ├── newbury_verysmall.intersections
│ ├── san_diego.intersections
│ └── ucsd.intersections
├── maps
│ ├── hollywood_large.map
│ ├── hollywood_small.map
│ ├── mapfiles.list
│ ├── new_york.map
│ ├── newbury_small.map
│ ├── newbury_verysmall.map
│ ├── san_diego.map
│ ├── ucsd.map
│ └── utc.map
├── mazes
│ └── maze1.maze
└── testdata
│ └── simpletest.map
├── libs
├── java-json.jar
├── javax.json-1.0.4.jar
└── jsoup-1.12.1.jar
└── src
├── application
├── CLabel.java
├── DataSet.java
├── GeoLabel.java
├── MapApp.java
├── MarkerManager.java
├── RouteVisualization.java
├── SelectManager.java
├── TestApp.java
├── controllers
│ ├── FetchController.java
│ └── RouteController.java
└── services
│ ├── GeneralService.java
│ └── RouteService.java
├── basicgraph
├── DegreeGrader.java
├── Graph.java
├── GraphAdjList.java
├── GraphAdjMatrix.java
└── GraphGrader.java
├── geography
├── GeographicPoint.java
└── RoadSegment.java
├── gmapsfx
├── ArrayTester.java
├── GoogleMapView.java
├── MapComponentInitializedListener.java
├── MapNotInitializedException.java
├── MapReadyListener.java
├── javascript
│ ├── IJavascriptRuntime.java
│ ├── IWebEngine.java
│ ├── JavaFxWebEngine.java
│ ├── JavascriptArray.java
│ ├── JavascriptEnum.java
│ ├── JavascriptFunction.java
│ ├── JavascriptFunctionLine.java
│ ├── JavascriptObject.java
│ ├── JavascriptRuntime.java
│ ├── event
│ │ ├── EventHandlers.java
│ │ ├── GFXEventHandler.java
│ │ ├── MapStateEventType.java
│ │ ├── StateEventHandler.java
│ │ ├── UIEventHandler.java
│ │ └── UIEventType.java
│ └── object
│ │ ├── Animation.java
│ │ ├── GMapObjectType.java
│ │ ├── GMapPoint.java
│ │ ├── GoogleMap.java
│ │ ├── InfoWindow.java
│ │ ├── InfoWindowOptions.java
│ │ ├── LatLong.java
│ │ ├── LatLongBounds.java
│ │ ├── MVCArray.java
│ │ ├── MapOptions.java
│ │ ├── MapShape.java
│ │ ├── MapTypeIdEnum.java
│ │ ├── Marker.java
│ │ ├── MarkerOptions.java
│ │ ├── MarkerShape.java
│ │ ├── Polyline.java
│ │ ├── PolylineOptions.java
│ │ ├── Projection.java
│ │ └── Size.java
├── service
│ ├── elevation
│ │ ├── ElevationResult.java
│ │ ├── ElevationService.java
│ │ ├── ElevationServiceCallback.java
│ │ ├── ElevationStatus.java
│ │ ├── LocationElevationRequest.java
│ │ └── PathElevationRequest.java
│ └── geocoding
│ │ └── GeocodingService.java
├── shapes
│ ├── ArcBuilder.java
│ ├── Circle.java
│ ├── CircleOptions.java
│ ├── FillableMapShapeOptions.java
│ ├── MapShapeOptions.java
│ ├── Polygon.java
│ ├── PolygonOptions.java
│ ├── Polyline.java
│ ├── PolylineOptions.java
│ ├── Rectangle.java
│ ├── RectangleOptions.java
│ └── StrokePosition.java
└── zoom
│ ├── MaxZoomResult.java
│ ├── MaxZoomService.java
│ ├── MaxZoomServiceCallback.java
│ └── MaxZoomStatus.java
├── html
├── index.html
├── main.js
├── routing.css
└── visual.js
├── mapmaker
├── DataFetcher.java
└── MapMaker.java
├── roadgraph
├── AStarGrader.java
├── CorrectAnswer.java
├── DijkstraGrader.java
├── MapGraph.java
├── MapGraphNode.java
└── SearchGrader.java
├── util
└── GraphLoader.java
└── week3example
├── Maze.java
├── MazeLoader.java
└── MazeNode.java
/README:
--------------------------------------------------------------------------------
1 | /-------------------------------------------------------------------------
2 | / Starter Code and GUI Application for Course 3 in the
3 | / Java Programming: Object Oriented Design of
4 | / Data Structures Specialization:
5 | /
6 | / Advanced Data Structures in Java
7 | / https://www.coursera.org/learn/advanced-data-structures
8 | /
9 | / Authored by UCSD MOOC Team:
10 | / Mia Minnes, Christine Alvarado, Leo Porter, Alec Brickner
11 | / and Adam Setters
12 | /
13 | / Date: 12/16/2015
14 | /-------------------------------------------------------------------------
15 |
16 | ---------------------------------------------------------[ DESCRIPTION ]--
17 |
18 | The files provided are skeleton code, as well as grading previews and
19 | testing files to be used in completing the course programming
20 | assignments. Additionally, you are provided a runnable JavaFX program
21 | which will help to test and demonstrate your implementations.
22 |
23 | -------------------------------------------------------[ FILES BY WEEK ]--
24 |
25 | Below are the files introduced in each week and used in each week
26 | of the course. See file for description...
27 |
28 | Week 1 : Introduction to the course and graphs
29 | ==============================================
30 | basicgraph.Graph.java
31 | basicgraph.GraphAdjList.java
32 | basicgraph.GraphAdjMatrix.java
33 |
34 | Week 2 : Class design and simple graph search
35 | ==================================================
36 | roadgraph.MapGraph.java
37 | week2example.Maze.java
38 | week2example.MazeLoader.java
39 | week2example.MazeNode.java
40 |
41 | Utility files
42 | =============
43 | geography.GeographicPoint.java
44 | geography.RoadSegment.java
45 | util.GraphLoader.java
46 |
47 | ---------------------------------------------------------------[ SETUP ]--
48 |
49 | Importing Project into eclipse:
50 | 1. Create a new Java Project in your workspace
51 | 2. Import the starter files:
52 | File -> Import -> Select "File System" -> Next -> Browse and set
53 | root directory to folder contents of zip were extracted to -> Finish
54 |
55 | Feel free to use another IDE or manually compile and run your programs.
56 | If you need help, google is your friend.
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Fastest Route Finder with BFS, Dijkstra(getting speed limit data from web) and also A Star Algorithms included.
2 | _this was the final homework for UCSD's Advanced Data Structures in Java._
3 |
4 | A basic shortest path finder between given two points. Dijkstra has the extra feature of getting data from web, to name it from opensourcemap, if the current coordinates does not have the info of maxspeed then continues to scan around 300 radius uses the closest info.
5 | Preferred
6 | 7+ Language Level
7 | SDK 1.8 because of javafx library
8 | jUnit
9 | and libs
10 |
11 | > ### **Example:**
12 |
13 | Given part of text is just a snapshot of some part.
14 |
15 |
--------------------------------------------------------------------------------
/UCSDGraphs.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph1.txt:
--------------------------------------------------------------------------------
1 | 10
2 | 0 1
3 | 1 2
4 | 2 3
5 | 3 4
6 | 4 5
7 | 5 6
8 | 6 7
9 | 7 8
10 | 8 9
11 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph1.txt.degrees:
--------------------------------------------------------------------------------
1 | 2 2 2 2 2 2 2 2 1 1
2 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph2.txt:
--------------------------------------------------------------------------------
1 | 10
2 | 0 1
3 | 1 2
4 | 2 3
5 | 3 4
6 | 4 5
7 | 5 6
8 | 6 7
9 | 7 8
10 | 8 9
11 | 1 0
12 | 2 1
13 | 3 2
14 | 4 3
15 | 5 4
16 | 6 5
17 | 7 6
18 | 8 7
19 | 9 8
20 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph2.txt.degrees:
--------------------------------------------------------------------------------
1 | 4 4 4 4 4 4 4 4 2 2
2 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph3.txt:
--------------------------------------------------------------------------------
1 | 10
2 | 0 1
3 | 0 2
4 | 0 3
5 | 0 4
6 | 0 5
7 | 0 6
8 | 0 7
9 | 0 8
10 | 0 9
11 | 1 0
12 | 2 0
13 | 3 0
14 | 4 0
15 | 5 0
16 | 6 0
17 | 7 0
18 | 8 0
19 | 9 0
20 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph3.txt.degrees:
--------------------------------------------------------------------------------
1 | 18 2 2 2 2 2 2 2 2 2
2 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph4.txt:
--------------------------------------------------------------------------------
1 | 10
2 | 0 1
3 | 0 2
4 | 0 3
5 | 0 4
6 | 0 5
7 | 0 6
8 | 0 7
9 | 0 8
10 | 0 9
11 | 1 0
12 | 2 0
13 | 3 0
14 | 4 0
15 | 5 0
16 | 6 0
17 | 7 0
18 | 8 0
19 | 9 0
20 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph4.txt.degrees:
--------------------------------------------------------------------------------
1 | 18 2 2 2 2 2 2 2 2 2
2 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph5.txt:
--------------------------------------------------------------------------------
1 | 11
2 | 0 1
3 | 0 2
4 | 0 3
5 | 0 4
6 | 0 5
7 | 1 6
8 | 2 7
9 | 3 8
10 | 4 9
11 | 5 10
12 |
--------------------------------------------------------------------------------
/data/graders/mod1/graph6.txt:
--------------------------------------------------------------------------------
1 | 11
2 | 0 1
3 | 0 2
4 | 0 3
5 | 0 4
6 | 0 5
7 | 1 6
8 | 2 7
9 | 3 8
10 | 4 9
11 | 5 10
12 |
--------------------------------------------------------------------------------
/data/graders/mod1/routesUA.dat.degrees:
--------------------------------------------------------------------------------
1 | 323 319 281 279 217 176 143 98 42 42 39 36 36 34 34 32 32 30 29 26 26 26 24 22 22 20 19 18 18 18 18 18 18 17 16 16 16 16 16 14 14 14 14 14 14 14 14 14 14 14 14 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 7 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1
2 |
--------------------------------------------------------------------------------
/data/graders/mod1/routesUA.dat.twoaway:
--------------------------------------------------------------------------------
1 | 6
2 | 20
3 | 29
4 | 31
5 | 33
6 | 41
7 | 42
8 | 50
9 | 65
10 | 68
11 | 70
12 | 73
13 | 83
14 | 86
15 | 89
16 | 112
17 | 113
18 | 115
19 | 124
20 | 26
21 | 130
22 | 163
23 | 164
24 | 167
25 | 51
26 | 172
27 | 174
28 | 131
29 | 132
30 | 133
31 | 182
32 | 183
33 | 184
34 | 185
35 | 186
36 | 187
37 | 188
38 | 27
39 | 189
40 | 190
41 | 191
42 | 72
43 | 30
44 | 43
45 | 192
46 | 193
47 | 194
48 | 195
49 | 138
50 | 196
51 | 197
52 | 198
53 | 199
54 | 200
55 | 201
56 | 28
57 | 8
58 | 202
59 | 203
60 | 140
61 | 204
62 | 205
63 | 206
64 | 207
65 | 141
66 | 9
67 | 208
68 | 44
69 | 209
70 | 210
71 | 211
72 | 212
73 | 142
74 | 143
75 | 213
76 | 214
77 | 215
78 | 58
79 | 144
80 | 216
81 | 217
82 | 218
83 | 219
84 | 220
85 | 145
86 | 146
87 | 221
88 | 80
89 | 222
90 | 223
91 | 224
92 | 225
93 | 1
94 | 226
95 | 227
96 | 148
97 | 228
98 | 229
99 | 230
100 | 231
101 | 232
102 | 233
103 | 234
104 | 235
105 | 236
106 | 237
107 | 238
108 | 152
109 | 239
110 | 240
111 | 241
112 | 242
113 | 153
114 | 34
115 | 10
116 | 243
117 | 244
118 | 245
119 | 246
120 | 247
121 | 248
122 | 14
123 | 249
124 | 154
125 | 156
126 | 250
127 | 251
128 | 252
129 | 253
130 | 254
131 | 255
132 | 256
133 | 62
134 | 257
135 | 258
136 | 259
137 | 260
138 | 45
139 | 6
140 | 11
141 | 15
142 | 18
143 | 19
144 | 31
145 | 32
146 | 42
147 | 50
148 | 65
149 | 68
150 | 78
151 | 83
152 | 84
153 | 88
154 | 89
155 | 97
156 | 109
157 | 113
158 | 114
159 | 116
160 | 119
161 | 122
162 | 26
163 | 157
164 | 129
165 | 159
166 | 130
167 | 164
168 | 168
169 | 361
170 | 51
171 | 171
172 | 172
173 | 176
174 | 177
175 | 132
176 | 7
177 | 133
178 | 262
179 | 184
180 | 185
181 | 187
182 | 27
183 | 323
184 | 72
185 | 43
186 | 277
187 | 336
188 | 337
189 | 195
190 | 339
191 | 341
192 | 138
193 | 279
194 | 139
195 | 281
196 | 200
197 | 356
198 | 359
199 | 201
200 | 360
201 | 28
202 | 202
203 | 140
204 | 366
205 | 286
206 | 141
207 | 9
208 | 208
209 | 367
210 | 368
211 | 369
212 | 44
213 | 287
214 | 288
215 | 289
216 | 210
217 | 333
218 | 370
219 | 212
220 | 292
221 | 142
222 | 143
223 | 213
224 | 214
225 | 371
226 | 372
227 | 58
228 | 373
229 | 144
230 | 374
231 | 375
232 | 376
233 | 145
234 | 146
235 | 377
236 | 91
237 | 296
238 | 80
239 | 378
240 | 223
241 | 224
242 | 225
243 | 1
244 | 297
245 | 379
246 | 147
247 | 226
248 | 298
249 | 227
250 | 148
251 | 230
252 | 380
253 | 301
254 | 232
255 | 92
256 | 234
257 | 381
258 | 306
259 | 150
260 | 152
261 | 382
262 | 261
263 | 240
264 | 307
265 | 241
266 | 308
267 | 153
268 | 34
269 | 10
270 | 245
271 | 246
272 | 247
273 | 310
274 | 311
275 | 248
276 | 383
277 | 384
278 | 14
279 | 249
280 | 154
281 | 385
282 | 386
283 | 156
284 | 387
285 | 250
286 | 251
287 | 388
288 | 252
289 | 389
290 | 390
291 | 391
292 | 392
293 | 253
294 | 254
295 | 62
296 | 257
297 | 260
298 | 45
299 | 393
300 | 394
301 | 6
302 | 22
303 | 41
304 | 50
305 | 65
306 | 78
307 | 86
308 | 89
309 | 113
310 | 128
311 | 26
312 | 164
313 | 51
314 | 7
315 | 133
316 | 262
317 | 27
318 | 190
319 | 43
320 | 336
321 | 354
322 | 200
323 | 28
324 | 8
325 | 395
326 | 202
327 | 397
328 | 399
329 | 85
330 | 206
331 | 141
332 | 287
333 | 209
334 | 143
335 | 214
336 | 218
337 | 145
338 | 146
339 | 91
340 | 80
341 | 222
342 | 223
343 | 1
344 | 226
345 | 298
346 | 148
347 | 230
348 | 232
349 | 92
350 | 304
351 | 234
352 | 238
353 | 261
354 | 240
355 | 241
356 | 242
357 | 404
358 | 34
359 | 10
360 | 246
361 | 247
362 | 248
363 | 14
364 | 405
365 | 406
366 | 251
367 | 407
368 | 62
369 | 408
370 | 257
371 | 45
372 | 95
373 | 0
374 | 6
375 | 15
376 | 25
377 | 32
378 | 33
379 | 42
380 | 46
381 | 50
382 | 52
383 | 53
384 | 61
385 | 68
386 | 83
387 | 86
388 | 89
389 | 3
390 | 110
391 | 111
392 | 113
393 | 115
394 | 116
395 | 118
396 | 120
397 | 122
398 | 124
399 | 26
400 | 129
401 | 130
402 | 160
403 | 164
404 | 361
405 | 51
406 | 172
407 | 173
408 | 131
409 | 132
410 | 7
411 | 133
412 | 265
413 | 184
414 | 185
415 | 90
416 | 269
417 | 270
418 | 274
419 | 27
420 | 189
421 | 72
422 | 332
423 | 43
424 | 192
425 | 335
426 | 340
427 | 138
428 | 279
429 | 280
430 | 139
431 | 284
432 | 200
433 | 358
434 | 201
435 | 28
436 | 8
437 | 202
438 | 140
439 | 366
440 | 286
441 | 403
442 | 141
443 | 9
444 | 368
445 | 44
446 | 287
447 | 210
448 | 211
449 | 413
450 | 142
451 | 143
452 | 363
453 | 213
454 | 214
455 | 293
456 | 58
457 | 144
458 | 417
459 | 216
460 | 376
461 | 219
462 | 145
463 | 146
464 | 377
465 | 91
466 | 295
467 | 296
468 | 80
469 | 222
470 | 223
471 | 224
472 | 297
473 | 419
474 | 226
475 | 298
476 | 227
477 | 148
478 | 228
479 | 230
480 | 380
481 | 92
482 | 302
483 | 303
484 | 304
485 | 234
486 | 305
487 | 235
488 | 306
489 | 150
490 | 364
491 | 151
492 | 152
493 | 240
494 | 241
495 | 308
496 | 420
497 | 365
498 | 153
499 | 34
500 | 10
501 | 243
502 | 247
503 | 310
504 | 311
505 | 248
506 | 14
507 | 249
508 | 421
509 | 422
510 | 423
511 | 154
512 | 314
513 | 315
514 | 155
515 | 156
516 | 250
517 | 424
518 | 252
519 | 267
520 | 253
521 | 254
522 | 93
523 | 94
524 | 319
525 | 256
526 | 62
527 | 257
528 | 258
529 | 259
530 | 425
531 | 260
532 | 45
533 | 95
534 | 6
535 | 12
536 | 22
537 | 42
538 | 50
539 | 65
540 | 86
541 | 89
542 | 112
543 | 113
544 | 120
545 | 13
546 | 123
547 | 26
548 | 164
549 | 51
550 | 132
551 | 7
552 | 133
553 | 188
554 | 27
555 | 190
556 | 72
557 | 43
558 | 336
559 | 284
560 | 200
561 | 28
562 | 8
563 | 395
564 | 140
565 | 85
566 | 342
567 | 206
568 | 141
569 | 9
570 | 287
571 | 209
572 | 411
573 | 142
574 | 143
575 | 214
576 | 215
577 | 418
578 | 218
579 | 145
580 | 146
581 | 91
582 | 80
583 | 222
584 | 223
585 | 225
586 | 1
587 | 426
588 | 226
589 | 298
590 | 227
591 | 148
592 | 230
593 | 231
594 | 232
595 | 304
596 | 234
597 | 427
598 | 236
599 | 306
600 | 238
601 | 261
602 | 240
603 | 241
604 | 242
605 | 404
606 | 34
607 | 247
608 | 248
609 | 14
610 | 249
611 | 154
612 | 406
613 | 428
614 | 251
615 | 254
616 | 62
617 | 257
618 | 260
619 | 429
620 | 45
621 | 95
622 |
--------------------------------------------------------------------------------
/data/graders/mod1/ucsd.map.degrees:
--------------------------------------------------------------------------------
1 | 6 6 6 6 5 3 2 2 2 2 2 1 1 1 1 1 1
2 |
--------------------------------------------------------------------------------
/data/graders/mod1/ucsd.map.twoaway:
--------------------------------------------------------------------------------
1 | 16
2 | 3
3 | 8
4 | 3
5 | 3
6 | 11
7 | 6
8 |
--------------------------------------------------------------------------------
/data/graders/mod2/map1.txt:
--------------------------------------------------------------------------------
1 | 0 0 1 1 "Road 1" edge
2 | 1 1 2 2 "Road 2" edge
3 | 2 2 3 3 "Road 3" edge
4 | 3 3 4 4 "Road 4" edge
5 | 4 4 5 5 "Road 5" edge
6 | 5 5 6 6 "Road 6" edge
7 |
--------------------------------------------------------------------------------
/data/graders/mod2/map1.txt.answer:
--------------------------------------------------------------------------------
1 | 7
2 | 6
3 | 0.0 0.0
4 | 1.0 1.0
5 | 2.0 2.0
6 | 3.0 3.0
7 | 4.0 4.0
8 | 5.0 5.0
9 | 6.0 6.0
10 |
--------------------------------------------------------------------------------
/data/graders/mod2/map2.txt:
--------------------------------------------------------------------------------
1 | 0 0 1 1 "Road 1" edge
2 | 1 1 2 2 "Road 2" edge
3 | 2 2 3 3 "Road 3" edge
4 | 3 3 4 4 "Road 4" edge
5 | 4 4 5 5 "Road 5" edge
6 | 5 5 6 6 "Road 6" edge
7 |
--------------------------------------------------------------------------------
/data/graders/mod2/map2.txt.answer:
--------------------------------------------------------------------------------
1 | 7
2 | 6
3 |
--------------------------------------------------------------------------------
/data/graders/mod2/map3.txt:
--------------------------------------------------------------------------------
1 | 0 0 0 1 "Road 1" edge
2 | 0 1 0 0 "Road 1" edge
3 | 0 1 0 2 "Road 2" edge
4 | 0 2 0 1 "Road 2" edge
5 | 0 2 1 2 "Road 3" edge
6 | 1 2 0 2 "Road 3" edge
7 | 1 2 2 2 "Road 4" edge
8 | 2 2 1 2 "Road 4" edge
9 | 2 2 2 1 "Road 5" edge
10 | 2 1 2 2 "Road 5" edge
11 | 2 1 2 0 "Road 6" edge
12 | 2 0 2 1 "Road 6" edge
13 | 2 0 1 0 "Road 7" edge
14 | 1 0 2 0 "Road 7" edge
15 | 1 0 0 0 "Road 8" edge
16 | 0 0 1 0 "Road 8" edge
17 |
--------------------------------------------------------------------------------
/data/graders/mod2/map3.txt.answer:
--------------------------------------------------------------------------------
1 | 8
2 | 16
3 | 0.0 0.0
4 | 0.0 1.0
5 | 0.0 2.0
6 | 1.0 2.0
7 |
--------------------------------------------------------------------------------
/data/graders/mod2/ucsd.map.answer:
--------------------------------------------------------------------------------
1 | 17
2 | 24
3 | 32.8756538 -117.2435715
4 | 32.8757495 -117.2430819
5 | 32.8741164 -117.2382689
6 | 32.8742087 -117.2381344
7 |
--------------------------------------------------------------------------------
/data/graders/mod3/map1.txt:
--------------------------------------------------------------------------------
1 | 0 0 1 1 "Road 1" edge
2 | 1 1 2 2 "Road 2" edge
3 | 2 2 3 3 "Road 3" edge
4 | 3 3 4 4 "Road 4" edge
5 | 4 4 5 5 "Road 5" edge
6 | 5 5 6 6 "Road 6" edge
7 | 0 0 -1 0 "Road 7" edge
8 | -1 0 -2 0 "Road 8" edge
9 | -2 0 -3 0 "Road 9" edge
10 |
--------------------------------------------------------------------------------
/data/graders/mod3/map1.txt.answer:
--------------------------------------------------------------------------------
1 | 0.0 0.0
2 | 1.0 1.0
3 | 2.0 2.0
4 | 3.0 3.0
5 | 4.0 4.0
6 | 5.0 5.0
7 | 6.0 6.0
8 |
--------------------------------------------------------------------------------
/data/graders/mod3/map2.txt:
--------------------------------------------------------------------------------
1 | 1 1 4 1 "main" edge
2 | 4 1 1 1 "main" edge
3 | 4 1 4 2 "state" edge
4 | 4 2 4 1 "state" edge
5 | 4 1 7 3 "front" edge
6 | 7 3 4 1 "front" edge
7 | 4 1 5 1 "main" edge
8 | 5 1 4 1 "main" edge
9 | 4 1 4 0 "state" edge
10 | 4 0 4 1 "state" edge
11 | 4 0 5 1 "short" edge
12 | 5 1 4 0 "short" edge
13 | 4 0 4 -1 "state" edge
14 | 4 -1 4 0 "state" edge
15 | 4 -1 8 -1 "south" edge
16 | 8 -1 4 -1 "south" edge
17 | 5 1 6.5 0 "first" edge
18 | 6.5 0 5 1 "first" edge
19 | 6.5 0 8 -1 "next" edge
20 | 8 -1 6.5 0 "next" edge
21 | 7 3 8 -1 "high" edge
22 | 8 -1 7 3 "high" edge
23 |
--------------------------------------------------------------------------------
/data/graders/mod3/map2.txt.answer:
--------------------------------------------------------------------------------
1 | 7.0 3.0
2 | 4.0 1.0
3 | 4.0 0.0
4 | 4.0 -1.0
5 |
--------------------------------------------------------------------------------
/data/graders/mod3/map3.txt:
--------------------------------------------------------------------------------
1 | 0 0 -1 1 "Zig" edge
2 | -1 1 1 2 "Zag" edge
3 | 1 2 0 3 "Left" edge
4 | 0 3 4 4 "Mid" edge
5 | 0 0 2 2 "Right" edge
6 | 2 2 4 4 "Right" edge
7 | 4 4 0 4 "Upper" edge
8 |
--------------------------------------------------------------------------------
/data/graders/mod3/map3.txt.answer:
--------------------------------------------------------------------------------
1 | 0.0 0.0
2 | 4.0 4.0
3 | 0.0 4.0
4 |
--------------------------------------------------------------------------------
/data/graders/mod3/ucsd.map.answer:
--------------------------------------------------------------------------------
1 | 32.8709815 -117.2434254
2 | 32.8710666 -117.2432407
3 | 32.8715162 -117.2422525
4 | 32.8717705 -117.2419172
5 | 32.8726064 -117.2418224
6 | 32.8741164 -117.2382689
7 | 32.8742087 -117.2381344
8 |
--------------------------------------------------------------------------------
/data/intersections/hollywood_small.intersections:
--------------------------------------------------------------------------------
1 | Lat: 34.108928, Lon: -118.3379696 Lat: 34.1085487, Lon: -118.337979
2 | Lat: 34.1089619, Lon: -118.3391174 Lat: 34.1076423, Lon: -118.3390137
3 | Lat: 34.1089619, Lon: -118.3391174 Lat: 34.1092817, Lon: -118.3391165
4 | Lat: 34.1089619, Lon: -118.3391174 Lat: 34.1087853, Lon: -118.3386925
5 | Lat: 34.1089619, Lon: -118.3391174 Lat: 34.10908, Lon: -118.3400346
6 | Lat: 34.1093056, Lon: -118.3379235 Lat: 34.1087853, Lon: -118.3386925
7 | Lat: 34.1093056, Lon: -118.3379235 Lat: 34.1093731, Lon: -118.3385801
8 | Lat: 34.1082145, Lon: -118.3444277 Lat: 34.1093925, Lon: -118.3400463
9 | Lat: 34.1092817, Lon: -118.3391165 Lat: 34.1089619, Lon: -118.3391174
10 | Lat: 34.1092817, Lon: -118.3391165 Lat: 34.1097672, Lon: -118.3391194
11 | Lat: 34.1092817, Lon: -118.3391165 Lat: 34.1093925, Lon: -118.3400463
12 | Lat: 34.1074342, Lon: -118.3400377 Lat: 34.1079022, Lon: -118.3410223
13 | Lat: 34.1076423, Lon: -118.3390137 Lat: 34.1089619, Lon: -118.3391174
14 | Lat: 34.1087853, Lon: -118.3386925 Lat: 34.1093056, Lon: -118.3379235
15 | Lat: 34.1087853, Lon: -118.3386925 Lat: 34.1085487, Lon: -118.337979
16 | Lat: 34.1087853, Lon: -118.3386925 Lat: 34.1089619, Lon: -118.3391174
17 | Lat: 34.1093925, Lon: -118.3400463 Lat: 34.10908, Lon: -118.3400346
18 | Lat: 34.1093925, Lon: -118.3400463 Lat: 34.1082145, Lon: -118.3444277
19 | Lat: 34.1093925, Lon: -118.3400463 Lat: 34.1092817, Lon: -118.3391165
20 | Lat: 34.1081907, Lon: -118.337113 Lat: 34.1085487, Lon: -118.337979
21 | Lat: 34.1097672, Lon: -118.3391194 Lat: 34.1092817, Lon: -118.3391165
22 | Lat: 34.1076233, Lon: -118.3411896 Lat: 34.1079022, Lon: -118.3410223
23 | Lat: 34.1076233, Lon: -118.3411896 Lat: 34.1065619, Lon: -118.3423929
24 | Lat: 34.1076233, Lon: -118.3411896 Lat: 34.1041261, Lon: -118.3393876
25 | Lat: 34.1093731, Lon: -118.3385801 Lat: 34.1093056, Lon: -118.3379235
26 | Lat: 34.1067247, Lon: -118.3391392 Lat: 34.10908, Lon: -118.3400346
27 | Lat: 34.1085487, Lon: -118.337979 Lat: 34.108928, Lon: -118.3379696
28 | Lat: 34.1085487, Lon: -118.337979 Lat: 34.1081907, Lon: -118.337113
29 | Lat: 34.1085487, Lon: -118.337979 Lat: 34.1087853, Lon: -118.3386925
30 | Lat: 34.10908, Lon: -118.3400346 Lat: 34.1093925, Lon: -118.3400463
31 | Lat: 34.10908, Lon: -118.3400346 Lat: 34.1089619, Lon: -118.3391174
32 | Lat: 34.10908, Lon: -118.3400346 Lat: 34.1079022, Lon: -118.3410223
33 | Lat: 34.10908, Lon: -118.3400346 Lat: 34.1067247, Lon: -118.3391392
34 | Lat: 34.1041261, Lon: -118.3393876 Lat: 34.1076233, Lon: -118.3411896
35 | Lat: 34.1065619, Lon: -118.3423929 Lat: 34.1076233, Lon: -118.3411896
36 | Lat: 34.1079022, Lon: -118.3410223 Lat: 34.10908, Lon: -118.3400346
37 | Lat: 34.1079022, Lon: -118.3410223 Lat: 34.1076233, Lon: -118.3411896
38 | Lat: 34.1079022, Lon: -118.3410223 Lat: 34.1074342, Lon: -118.3400377
39 |
--------------------------------------------------------------------------------
/data/intersections/newbury_verysmall.intersections:
--------------------------------------------------------------------------------
1 | Lat: 34.1842502, Lon: -118.94923 Lat: 34.1842742, Lon: -118.947663
2 | Lat: 34.1842502, Lon: -118.94923 Lat: 34.1832868, Lon: -118.9491068
3 | Lat: 34.1842502, Lon: -118.94923 Lat: 34.184898, Lon: -118.949349
4 | Lat: 34.185952, Lon: -118.949513 Lat: 34.1842742, Lon: -118.947663
5 | Lat: 34.185952, Lon: -118.949513 Lat: 34.184898, Lon: -118.949349
6 | Lat: 34.185952, Lon: -118.949513 Lat: 34.191625, Lon: -118.950069
7 | Lat: 34.1832868, Lon: -118.9491068 Lat: 34.1842502, Lon: -118.94923
8 | Lat: 34.184898, Lon: -118.949349 Lat: 34.1849616, Lon: -118.9485947
9 | Lat: 34.184898, Lon: -118.949349 Lat: 34.1842502, Lon: -118.94923
10 | Lat: 34.184898, Lon: -118.949349 Lat: 34.185952, Lon: -118.949513
11 | Lat: 34.182935, Lon: -118.945212 Lat: 34.1842902, Lon: -118.9456633
12 | Lat: 34.186876, Lon: -118.944755 Lat: 34.1842902, Lon: -118.9456633
13 | Lat: 34.1842742, Lon: -118.947663 Lat: 34.1842902, Lon: -118.9456633
14 | Lat: 34.1842742, Lon: -118.947663 Lat: 34.1842502, Lon: -118.94923
15 | Lat: 34.1842742, Lon: -118.947663 Lat: 34.185952, Lon: -118.949513
16 | Lat: 34.191625, Lon: -118.950069 Lat: 34.185952, Lon: -118.949513
17 | Lat: 34.1842902, Lon: -118.9456633 Lat: 34.182935, Lon: -118.945212
18 | Lat: 34.1842902, Lon: -118.9456633 Lat: 34.186876, Lon: -118.944755
19 | Lat: 34.1842902, Lon: -118.9456633 Lat: 34.1842742, Lon: -118.947663
20 | Lat: 34.1849616, Lon: -118.9485947 Lat: 34.184898, Lon: -118.949349
21 |
--------------------------------------------------------------------------------
/data/intersections/ucsd.intersections:
--------------------------------------------------------------------------------
1 | Lat: 32.8756538, Lon: -117.2435715 Lat: 32.8757495, Lon: -117.2430819
2 | Lat: 32.8756538, Lon: -117.2435715 Lat: 32.8755247, Lon: -117.2437787
3 | Lat: 32.8756538, Lon: -117.2435715 Lat: 32.8766947, Lon: -117.2436925
4 | Lat: 32.8755247, Lon: -117.2437787 Lat: 32.875336, Lon: -117.244034
5 | Lat: 32.8755247, Lon: -117.2437787 Lat: 32.8756538, Lon: -117.2435715
6 | Lat: 32.8757495, Lon: -117.2430819 Lat: 32.8741164, Lon: -117.2382689
7 | Lat: 32.8757495, Lon: -117.2430819 Lat: 32.8765435, Lon: -117.2435225
8 | Lat: 32.8757495, Lon: -117.2430819 Lat: 32.8756538, Lon: -117.2435715
9 | Lat: 32.8765435, Lon: -117.2435225 Lat: 32.8757495, Lon: -117.2430819
10 | Lat: 32.8747713, Lon: -117.2360131 Lat: 32.8742087, Lon: -117.2381344
11 | Lat: 32.8741164, Lon: -117.2382689 Lat: 32.8728698, Lon: -117.2379406
12 | Lat: 32.8741164, Lon: -117.2382689 Lat: 32.8757495, Lon: -117.2430819
13 | Lat: 32.8741164, Lon: -117.2382689 Lat: 32.8742087, Lon: -117.2381344
14 | Lat: 32.873833, Lon: -117.2435847 Lat: 32.8756538, Lon: -117.2435715
15 | Lat: 32.8762498, Lon: -117.2438229 Lat: 32.8755247, Lon: -117.2437787
16 | Lat: 32.8771038, Lon: -117.2360337 Lat: 32.8741164, Lon: -117.2382689
17 | Lat: 32.8742087, Lon: -117.2381344 Lat: 32.8747713, Lon: -117.2360131
18 | Lat: 32.8742087, Lon: -117.2381344 Lat: 32.8769858, Lon: -117.2359995
19 | Lat: 32.8742087, Lon: -117.2381344 Lat: 32.8741164, Lon: -117.2382689
20 | Lat: 32.8769858, Lon: -117.2359995 Lat: 32.8771038, Lon: -117.2360337
21 | Lat: 32.8728698, Lon: -117.2379406 Lat: 32.8725007, Lon: -117.2380045
22 | Lat: 32.8728698, Lon: -117.2379406 Lat: 32.8724213, Lon: -117.2379297
23 | Lat: 32.8724053, Lon: -117.2377174 Lat: 32.8742087, Lon: -117.2381344
24 | Lat: 32.875336, Lon: -117.244034 Lat: 32.8755247, Lon: -117.2437787
25 |
--------------------------------------------------------------------------------
/data/maps/mapfiles.list:
--------------------------------------------------------------------------------
1 | ucsd.map
2 | utc.map
3 | san_diego.map
4 | hollywood_large.map
5 | new_york.map
--------------------------------------------------------------------------------
/data/mazes/maze1.maze:
--------------------------------------------------------------------------------
1 | 4 4
2 |
3 | *
4 | **
5 |
--------------------------------------------------------------------------------
/data/testdata/simpletest.map:
--------------------------------------------------------------------------------
1 | 1.0 1.0 4.0 1.0 "main" "city street"
2 | 4.0 1.0 4.0 2.0 "state" "city street"
3 | 4.0 1.0 4.0 0.0 "state" "city street"
4 | 4.0 1.0 5.0 1.0 "main" "city street"
5 | 4.0 1.0 7.0 3.0 "front" "city street"
6 | 4.0 0.0 4.0 -1.0 "state" "city street"
7 | 4.0 0.0 5.0 1.0 "short" "connector"
8 | 7.0 3.0 8.0 -1.0 "high" "residential"
9 | 8.0 -1.0 4.0 -1.0 "south" "residential"
10 | 5.0 1.0 6.5 0.0 "first" "residential"
11 | 6.5 0.0 8.0 -1.0 "next" "residential"
12 | 4.0 1.0 1.0 1.0 "main" "city street"
13 | 4.0 2.0 4.0 1.0 "state" "city street"
14 | 4.0 0.0 4.0 1.0 "state" "city street"
15 | 5.0 1.0 4.0 1.0 "main" "city street"
16 | 7.0 3.0 4.0 1.0 "front" "city street"
17 | 8.0 -1.0 7.0 3.0 "high" "residential"
18 | 4.0 -1.0 8.0 -1.0 "south" "residential"
19 | 6.5 0.0 5.0 1.0 "first" "residential"
20 | 8.0 -1.0 6.5 0.0 "next" "residential"
21 | 4.0 -1.0 4.0 0.0 "state" "city street"
22 | 5.0 1.0 4.0 0.0 "short" "connector"
--------------------------------------------------------------------------------
/libs/java-json.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/salimt/GoogleMaps-Find-Fastest-Route-Algorithms/20405a7f2b0842b32968acf6d6157fa90a2bfa7b/libs/java-json.jar
--------------------------------------------------------------------------------
/libs/javax.json-1.0.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/salimt/GoogleMaps-Find-Fastest-Route-Algorithms/20405a7f2b0842b32968acf6d6157fa90a2bfa7b/libs/javax.json-1.0.4.jar
--------------------------------------------------------------------------------
/libs/jsoup-1.12.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/salimt/GoogleMaps-Find-Fastest-Route-Algorithms/20405a7f2b0842b32968acf6d6157fa90a2bfa7b/libs/jsoup-1.12.1.jar
--------------------------------------------------------------------------------
/src/application/CLabel.java:
--------------------------------------------------------------------------------
1 | package application;
2 |
3 | import javafx.beans.property.ObjectProperty;
4 | import javafx.beans.property.SimpleObjectProperty;
5 | import javafx.scene.Node;
6 | import javafx.scene.control.Label;
7 | import javafx.scene.paint.Color;
8 | import javafx.scene.paint.Paint;
9 |
10 | /**
11 | * Label which has an object property associated with it
12 | *
13 | * @author UCSD MOOC development team
14 | *
15 | * @param Type of object associated with label
16 | */
17 |
18 | public class CLabel extends Label {
19 | private ObjectProperty item = new SimpleObjectProperty(this, "item");
20 | private static final Paint RED = Color.web("#9E092F");
21 | private static final Paint GREEN = Color.web("#099E78");
22 |
23 | // CONSTRUCTORS
24 | public CLabel() {
25 | super();
26 | }
27 |
28 | public CLabel(String text, T item) {
29 | super(text);
30 |
31 | if(item != null)
32 | setItem(item);
33 | else
34 | setItem(null);
35 | }
36 |
37 | public CLabel(String text, Node graphic, T item) {
38 | super(text, graphic);
39 | if(item != null)
40 | setItem(item);
41 | else
42 | setItem(null);
43 |
44 | }
45 |
46 |
47 | /**
48 | * Used to update item when new item is set.
49 | *
50 | * @param item
51 | * @param empty
52 | */
53 | protected void updateView(T item, boolean empty) {
54 | if(item != null) {
55 | setText(item.toString());
56 | setTextFill(GREEN);
57 | }
58 | else {
59 | // TODO -- could change this to be more generic
60 | setText("Choose Point");
61 | setTextFill(RED);
62 | }
63 | }
64 |
65 | public final ObjectProperty itemProperty(){ return item; }
66 |
67 |
68 | public T getItem(){
69 | return item.get();
70 | }
71 |
72 | public void setItem(T newItem) {
73 | item.set(newItem);
74 | updateView(item.get(), true);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/application/DataSet.java:
--------------------------------------------------------------------------------
1 | package application;
2 |
3 | import java.util.HashMap;
4 | import java.util.HashSet;
5 | import java.util.Set;
6 |
7 | import geography.GeographicPoint;
8 | import util.GraphLoader;
9 |
10 | /**
11 | * Class to wrap the graph, current .map file map, and
12 | * other pertinent information about the map data sets
13 | *
14 | * @author UCSD MOOC development team
15 | *
16 | */
17 | public class DataSet {
18 | String filePath;
19 | roadgraph.MapGraph graph;
20 | Set intersections;
21 | private HashMap> roads;
22 | boolean currentlyDisplayed;
23 |
24 | public DataSet (String path) {
25 | this.filePath = path;
26 | graph = null;
27 | roads = null;
28 | currentlyDisplayed = false;
29 | }
30 |
31 | public void setGraph(roadgraph.MapGraph graph) {
32 | this.graph = graph;
33 | }
34 |
35 | public void setRoads(HashMap> roads) { this.roads = roads; }
36 | public roadgraph.MapGraph getGraph(){ return graph; }
37 |
38 | /** Return the intersections in this graph.
39 | * In order to keep it consistent, if getVertices in the graph returns something
40 | * other than null (i.e. it's been implemented) we get the vertices from
41 | * the graph itself. But if the graph hasn't been implemented, we return
42 | * the set of intersections we separately maintain specifically for this purpose.
43 | * @return The set of road intersections (vertices in the graph)
44 | */
45 | public Set getIntersections() {
46 | Set intersectionsFromGraph = graph.getVertices();
47 | if (intersectionsFromGraph == null) {
48 | return intersections;
49 | }
50 | else {
51 | return intersectionsFromGraph;
52 | }
53 | }
54 |
55 | public HashMap> getRoads() { return this.roads; }
56 |
57 | public void initializeGraph() {
58 | graph = new roadgraph.MapGraph();
59 | roads = new HashMap>();
60 | intersections = new HashSet();
61 | //TODO: change to use intersections for points in graph.
62 | GraphLoader.loadRoadMap(filePath, graph, roads, intersections);
63 | }
64 |
65 | public String getFilePath() {
66 | return this.filePath;
67 | }
68 |
69 |
70 | public Object[] getPoints() {
71 | Set pointSet = roads.keySet();
72 | return pointSet.toArray();
73 | }
74 |
75 | public boolean isDisplayed() {
76 | return this.currentlyDisplayed;
77 | }
78 |
79 | public void setDisplayed(boolean value) {
80 | this.currentlyDisplayed = value;
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/src/application/GeoLabel.java:
--------------------------------------------------------------------------------
1 | /** Small class to store a GeographicPoint
2 | * as a label
3 | * @author UCSD MOOC development team
4 | *
5 | */
6 |
7 | package application;
8 |
9 | import javafx.beans.property.ObjectProperty;
10 | import javafx.scene.paint.Color;
11 | import javafx.scene.paint.Paint;
12 |
13 | public class GeoLabel {
14 |
15 | private geography.GeographicPoint point;
16 | private static final Paint RED = Color.web("#9E092F");
17 | private static final Paint GREEN = Color.web("#099E78");
18 |
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/application/RouteVisualization.java:
--------------------------------------------------------------------------------
1 | /** Class to aid with route visualization for search
2 | *
3 | * @author UCSD MOOC development team
4 | *
5 | */
6 |
7 | package application;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | import gmapsfx.javascript.IJavascriptRuntime;
13 | import gmapsfx.javascript.JavascriptArray;
14 | import gmapsfx.javascript.JavascriptRuntime;
15 | import gmapsfx.javascript.object.GoogleMap;
16 | import gmapsfx.javascript.object.LatLong;
17 | import gmapsfx.javascript.object.LatLongBounds;
18 | import gmapsfx.javascript.object.Marker;
19 | import gmapsfx.javascript.object.MarkerOptions;
20 | import javafx.concurrent.Task;
21 | import javafx.scene.control.Button;
22 | import netscape.javascript.JSObject;
23 |
24 | public class RouteVisualization {
25 | List points;
26 | ArrayList markerList;
27 | MarkerManager manager;
28 | JavascriptArray markers;
29 | IJavascriptRuntime runtime;
30 |
31 |
32 |
33 |
34 | public RouteVisualization(MarkerManager manager) {
35 | points = new ArrayList();
36 | markerList = new ArrayList();
37 | this.manager = manager;
38 |
39 | }
40 |
41 | public void acceptPoint(geography.GeographicPoint point) {
42 | points.add(point);
43 |
44 | // System.out.println("accepted point : " + point);
45 | }
46 |
47 |
48 |
49 | public void startVisualization() {
50 |
51 | LatLongBounds bounds = new LatLongBounds();
52 | List latLongs = new ArrayList();
53 | JavascriptArray jsArray = new JavascriptArray();
54 | manager.hideIntermediateMarkers();
55 | manager.hideDestinationMarker();
56 | // manager.disableRouteButtons(true);
57 |
58 | // create JavascriptArray of points
59 | for(geography.GeographicPoint point : points) {
60 | LatLong ll = new LatLong(point.getX(), point.getY());
61 | MarkerOptions options = MarkerManager.createDefaultOptions(ll);
62 | Marker newMarker = new Marker(options);
63 | jsArray.push(newMarker);
64 | markerList.add(newMarker);
65 | bounds.extend(ll);
66 | }
67 |
68 | // fit map bounds to visualization
69 | manager.getMap().fitBounds(bounds);
70 |
71 | // get javascript runtime and execute animation
72 | runtime = JavascriptRuntime.getInstance();
73 | String command = runtime.getFunction("visualizeSearch", manager.getMap(), jsArray);
74 | // System.out.println(command);
75 |
76 | runtime.execute(command);
77 |
78 | // MapApp.showInfoAlert("Nodes visited :" , latLongs.size() +" nodes were visited in the search");
79 | manager.disableVisButton(true);
80 | // manager.disableRouteButtons(false);
81 |
82 |
83 | }
84 |
85 | public void clearMarkers() {
86 | for(Marker marker : markerList) {
87 | marker.setVisible(false);
88 | }
89 | }
90 |
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/application/SelectManager.java:
--------------------------------------------------------------------------------
1 | /** Class to manage items selected in the GUI
2 | *
3 | * @author UCSD MOOC development team
4 | *
5 | */
6 |
7 | package application;
8 | import application.services.GeneralService;
9 | import geography.GeographicPoint;
10 | import gmapsfx.javascript.object.Marker;
11 |
12 | public class SelectManager {
13 | private CLabel pointLabel;
14 | private CLabel startLabel;
15 | private CLabel destinationLabel;
16 | private Marker startMarker;
17 | private Marker destinationMarker;
18 | private Marker selectedMarker;
19 | private MarkerManager markerManager;
20 | private DataSet dataSet;
21 |
22 |
23 | public SelectManager() {
24 | startMarker = null;
25 | destinationMarker = null;
26 | selectedMarker = null;
27 | pointLabel = null;
28 | startLabel = null;
29 | destinationLabel = null;
30 | dataSet = null;
31 | }
32 |
33 |
34 | public void resetSelect() {
35 | markerManager.setSelectMode(true);
36 | }
37 | public void clearSelected() {
38 | selectedMarker = null;
39 | pointLabel.setItem(null);
40 | }
41 |
42 | public void setAndDisplayData(DataSet data) {
43 | setDataSet(data);
44 | //TODO - maybe if markerManager!= null?
45 | if(markerManager != null) {
46 | markerManager.displayDataSet();
47 | }
48 | else {
49 | System.err.println("Error : Marker Manager is null.");
50 | }
51 | }
52 |
53 | public void setMarkerManager(MarkerManager manager) { this.markerManager = manager; }
54 | public void setPoint(GeographicPoint point, Marker marker) {
55 | // System.out.println("inSetPoint.. passed : " + point);
56 | pointLabel.setItem(point);
57 | selectedMarker = marker;
58 | }
59 | public void setDataSet(DataSet dataSet) {
60 | this.dataSet = dataSet;
61 | if(markerManager != null) {
62 | markerManager.setDataSet(dataSet);
63 | }
64 | }
65 |
66 | public void setPointLabel(CLabel label) { this.pointLabel = label; }
67 | public void setStartLabel(CLabel label) { this.startLabel = label; }
68 | public void setDestinationLabel(CLabel label) { this.destinationLabel = label; }
69 |
70 | public GeographicPoint getPoint() { return pointLabel.getItem(); }
71 |
72 |
73 | public GeographicPoint getStart(){return startLabel.getItem();}
74 | public GeographicPoint getDestination(){return destinationLabel.getItem();}
75 | public void setStart() {
76 | if(pointLabel.getItem() != null) {
77 | GeographicPoint point = pointLabel.getItem();
78 | startLabel.setItem(point);
79 | markerManager.setStart(point);
80 | }
81 | }
82 |
83 | public void setDestination() {
84 | if(pointLabel.getItem() != null) {
85 | GeographicPoint point = pointLabel.getItem();
86 | destinationLabel.setItem(point);
87 | markerManager.setDestination(point);
88 | }
89 | }
90 |
91 |
92 |
93 | }
--------------------------------------------------------------------------------
/src/application/TestApp.java:
--------------------------------------------------------------------------------
1 | /** Basic Class to test UI components
2 | *
3 | * @author UCSD MOOC development team
4 | *
5 | */
6 | package application;
7 |
8 | import gmapsfx.GoogleMapView;
9 | import gmapsfx.MapComponentInitializedListener;
10 | import gmapsfx.javascript.object.GoogleMap;
11 | import gmapsfx.javascript.object.LatLong;
12 | import gmapsfx.javascript.object.MapOptions;
13 | import gmapsfx.javascript.object.MapTypeIdEnum;
14 | import gmapsfx.shapes.Polyline;
15 | import javafx.application.Application;
16 | import javafx.scene.Scene;
17 | import javafx.scene.layout.BorderPane;
18 | import javafx.stage.Stage;
19 |
20 | public class TestApp extends Application
21 | implements MapComponentInitializedListener {
22 | protected GoogleMapView mapComponent;
23 | protected GoogleMap map;
24 |
25 | @Override
26 | public void start(Stage primaryStage) throws Exception {
27 | mapComponent = new GoogleMapView();
28 | mapComponent.addMapInitializedListener(this);
29 |
30 | BorderPane bp = new BorderPane();
31 | Scene scene = new Scene(bp);
32 | bp.setCenter(mapComponent);
33 | primaryStage.setScene(scene);
34 | primaryStage.show();
35 | }
36 |
37 | public void mapInitialized() {
38 | LatLong center = new LatLong(34.0219, -118.4814);
39 |
40 | MapOptions options = new MapOptions();
41 | options.center(center)
42 | .mapMarker(false)
43 | .mapType(MapTypeIdEnum.ROADMAP)
44 | //maybe set false
45 | .mapTypeControl(true)
46 | .overviewMapControl(false)
47 | .panControl(true)
48 | .rotateControl(false)
49 | .scaleControl(false)
50 | .streetViewControl(false)
51 | .zoom(8)
52 | .zoomControl(true);
53 |
54 | map = mapComponent.createMap(options);
55 |
56 | Polyline p = new Polyline();
57 |
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/application/controllers/RouteController.java:
--------------------------------------------------------------------------------
1 | package application.controllers;
2 |
3 | import application.CLabel;
4 | import application.MapApp;
5 | import application.MarkerManager;
6 | import application.SelectManager;
7 | import application.services.RouteService;
8 | import javafx.scene.control.Button;
9 | import javafx.scene.control.RadioButton;
10 | import javafx.scene.control.ToggleGroup;
11 |
12 | import java.util.List;
13 |
14 | public class RouteController {
15 | // Strings for slider labels
16 | public static final int BFS = 3;
17 | public static final int A_STAR = 2;
18 | public static final int DIJ = 1;
19 | public static final int DISABLE = 0;
20 | public static final int START = 1;
21 | public static final int DESTINATION = 2;
22 |
23 | private int selectedToggle = DIJ;
24 |
25 | private RouteService routeService;
26 | private Button displayButton;
27 | private Button hideButton;
28 | private Button startButton;
29 | private Button resetButton;
30 | private Button destinationButton;
31 | private Button visualizationButton;
32 |
33 | private ToggleGroup group;
34 | private CLabel startLabel;
35 | private CLabel endLabel;
36 | private CLabel pointLabel;
37 | private SelectManager selectManager;
38 | private MarkerManager markerManager;
39 |
40 |
41 |
42 | public RouteController(RouteService routeService, Button displayButton, Button hideButton,
43 | Button resetButton, Button startButton, Button destinationButton,
44 | ToggleGroup group, List searchOptions, Button visualizationButton,
45 | CLabel startLabel, CLabel endLabel,
46 | CLabel pointLabel, SelectManager manager, MarkerManager markerManager) {
47 | // save parameters
48 | this.routeService = routeService;
49 | this.displayButton = displayButton;
50 | this.hideButton = hideButton;
51 | this.startButton = startButton;
52 | this.resetButton = resetButton;
53 | this.destinationButton = destinationButton;
54 | this.group = group;
55 | this.visualizationButton = visualizationButton;
56 |
57 | // maybe don't need references to labels;
58 | this.startLabel = startLabel;
59 | this.endLabel = endLabel;
60 | this.pointLabel = pointLabel;
61 | this.selectManager = manager;
62 | this.markerManager = markerManager;
63 |
64 | setupDisplayButtons();
65 | setupRouteButtons();
66 | setupVisualizationButton();
67 | setupLabels();
68 | setupToggle();
69 | //routeService.displayRoute("data/sampleroute.map");
70 | }
71 |
72 |
73 | private void setupDisplayButtons() {
74 | displayButton.setOnAction(e -> {
75 | if(startLabel.getItem() != null && endLabel.getItem() != null) {
76 | routeService.displayRoute(startLabel.getItem(), endLabel.getItem(), selectedToggle);
77 | }
78 | else {
79 | MapApp.showErrorAlert("Route Display Error", "Make sure to choose points for both start and destination.");
80 | }
81 | });
82 |
83 | hideButton.setOnAction(e -> {
84 | routeService.hideRoute();
85 | });
86 |
87 | //TODO -- implement
88 | resetButton.setOnAction( e -> {
89 |
90 | routeService.reset();
91 | });
92 | }
93 |
94 | private void setupVisualizationButton() {
95 | visualizationButton.setOnAction( e -> {
96 | markerManager.startVisualization();
97 | });
98 | }
99 |
100 | private void setupRouteButtons() {
101 | startButton.setOnAction(e -> {
102 | //System.out.println();
103 | selectManager.setStart();
104 | });
105 |
106 | destinationButton.setOnAction( e-> {
107 | selectManager.setDestination();
108 | });
109 | }
110 |
111 |
112 | private void setupLabels() {
113 |
114 |
115 | }
116 |
117 | private void setupToggle() {
118 | group.selectedToggleProperty().addListener( li -> {
119 | if(group.getSelectedToggle().getUserData().equals("Dijkstra")) {
120 | selectedToggle = DIJ;
121 | }
122 | else if(group.getSelectedToggle().getUserData().equals("A*")) {
123 | selectedToggle = A_STAR;
124 | }
125 | else if(group.getSelectedToggle().getUserData().equals("BFS")) {
126 | selectedToggle = BFS;
127 | }
128 | else {
129 | System.err.println("Invalid radio button selection");
130 | }
131 | });
132 | }
133 |
134 |
135 |
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/application/services/GeneralService.java:
--------------------------------------------------------------------------------
1 | package application.services;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.regex.Pattern;
6 |
7 | import application.DataSet;
8 | import application.MapApp;
9 | import application.MarkerManager;
10 | import application.SelectManager;
11 | import gmapsfx.GoogleMapView;
12 | import gmapsfx.javascript.object.GoogleMap;
13 | import gmapsfx.javascript.object.LatLong;
14 | import gmapsfx.javascript.object.LatLongBounds;
15 | import javafx.concurrent.Task;
16 | import javafx.scene.control.Alert;
17 | import javafx.scene.control.Button;
18 | import javafx.scene.control.ComboBox;
19 | import mapmaker.MapMaker;
20 |
21 | // class for map and general application services (file IO, etc.)
22 | public class GeneralService {
23 | // private static boolean singleton = false;
24 | private int currentState;
25 | private SelectManager selectManager;
26 | private GoogleMap map;
27 | private MarkerManager markerManager;
28 |
29 |
30 |
31 | private static final String DATA_FILE_PATTERN = "[\\w_]+.map";
32 | private static final String DATA_FILE_DIR_STR = "data/maps/";
33 |
34 | private List filenames;
35 | DataSet dataSet;
36 |
37 | public GeneralService(GoogleMapView mapComponent, SelectManager selectManager, MarkerManager markerManager) {
38 | // get map from GoogleMapView
39 | this.map = mapComponent.getMap();
40 | this.selectManager = selectManager;
41 | this.markerManager = markerManager;
42 | this.markerManager.setMap(map);
43 | filenames = new ArrayList();
44 |
45 | // uncomment to click map and print coordinates
46 | /*mapComponent.addUIEventHandler(UIEventType.click, (JSObject obj) -> {
47 | System.out.println(obj.getMember("latLng"));
48 | });*/
49 | }
50 |
51 |
52 | // writes geographic data flat file
53 | // parameters arr contains the coordinates of the bounds for the map region
54 | public boolean writeDataToFile(String filename, float[] arr) {
55 | MapMaker mm = new MapMaker(arr);
56 |
57 | // parse data and write to filename
58 | if(mm.parseData(filename)) {
59 | return true;
60 | }
61 |
62 | return false;
63 | }
64 |
65 | public static String getDataSetDirectory() { return GeneralService.DATA_FILE_DIR_STR; }
66 |
67 | // gets current bounds of map view
68 | public float[] getBoundsArray() {
69 | LatLong sw, ne;
70 | LatLongBounds bounds = map.getBounds();
71 |
72 | sw = bounds.getSouthWest();
73 | ne = bounds.getNorthEast();
74 |
75 | // [S, W, N, E]
76 | return new float[] {(float) sw.getLatitude(), (float) sw.getLongitude(),
77 | (float) ne.getLatitude(), (float) ne.getLongitude()};
78 | }
79 |
80 | public void addDataFile(String filename) {
81 | filenames.add(filename);
82 | }
83 |
84 | public void displayIntersections(DataSet dataset) {
85 | // remove old data set markers
86 | if(markerManager == null){
87 | System.out.println("failure!");
88 | }
89 | if(markerManager.getDataSet() != null) {
90 | markerManager.clearMarkers();
91 | markerManager.getDataSet().setDisplayed(false);
92 | }
93 |
94 | // display new data set
95 | selectManager.setAndDisplayData(dataset);
96 | dataset.setDisplayed(true);
97 |
98 | }
99 |
100 | public float boundsSize() {
101 | float[] bounds = getBoundsArray();
102 | return (bounds[2] - bounds[0]) * (bounds[3] - bounds[1]);
103 | }
104 |
105 | public boolean checkBoundsSize(double limit) {
106 | if (boundsSize() > limit) {
107 | return false;
108 | }
109 | return true;
110 | }
111 |
112 | /**
113 | * Check if file name matches pattern [filename].map
114 | *
115 | * @param str - path to check
116 | * @return string to use as path
117 | */
118 | public String checkDataFileName(String str) {
119 | if(Pattern.matches(DATA_FILE_PATTERN, str)) {
120 | return DATA_FILE_DIR_STR + str;
121 | }
122 | return null;
123 | }
124 |
125 | public void runFetchTask(String fName, ComboBox cb, Button button) {
126 | float[] arr = getBoundsArray();
127 |
128 | Task task = new Task() {
129 | @Override
130 | public String call() {
131 | if(writeDataToFile(fName, arr)) {
132 | return fName;
133 | }
134 |
135 | return "z" + fName;
136 |
137 | }
138 | };
139 |
140 |
141 |
142 | Alert fetchingAlert = MapApp.getInfoAlert("Loading : ", "Fetching data for current map area...");
143 | task.setOnSucceeded( e -> {
144 | if(task.getValue().equals(fName)) {
145 | addDataFile(fName);
146 |
147 | cb.getItems().add(new DataSet(fName));
148 | if(fetchingAlert.isShowing()) {
149 | fetchingAlert.close();
150 | }
151 | MapApp.showInfoAlert("Fetch completed : ", "Data set : \"" + fName + "\" written to file!");
152 | // System.out.println("Fetch Task Succeeded");
153 |
154 | }
155 | else {
156 | // System.out.println("Something went wrong, data not written to file : Task succeeded but fName returned differently");
157 |
158 | }
159 |
160 | button.setDisable(false);
161 |
162 | });
163 |
164 |
165 | task.setOnFailed( e -> {
166 |
167 | });
168 |
169 | task.setOnRunning(e -> {
170 | button.setDisable(true);
171 | fetchingAlert.showAndWait();
172 | });
173 |
174 |
175 | Thread fetchThread = new Thread(task);
176 | fetchThread.start();
177 | }
178 |
179 |
180 |
181 | public List getDataFiles() {
182 | return filenames;
183 | }
184 |
185 | public static String getFileRegex() {
186 | return GeneralService.DATA_FILE_PATTERN;
187 | }
188 |
189 |
190 | public void setState(int state) {
191 | currentState = state;
192 | }
193 |
194 |
195 | public double getState() { return currentState; }
196 |
197 |
198 | }
199 |
200 |
--------------------------------------------------------------------------------
/src/basicgraph/GraphAdjList.java:
--------------------------------------------------------------------------------
1 | package basicgraph;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /** A class that implements a directed graph.
9 | * The graph may have self-loops, parallel edges.
10 | * Vertices are labeled by integers 0 .. n-1
11 | * and may also have String labels.
12 | * The edges of the graph are not labeled.
13 | * Representation of edges via adjacency lists.
14 | *
15 | * @author UCSD MOOC development team and YOU
16 | *
17 | */
18 | public class GraphAdjList extends Graph {
19 |
20 |
21 | private Map> adjListsMap;
22 |
23 | /**
24 | * Create a new empty Graph
25 | */
26 | public GraphAdjList () {
27 | adjListsMap = new HashMap>();
28 | }
29 |
30 | /**
31 | * Implement the abstract method for adding a vertex.
32 | */
33 | public void implementAddVertex() {
34 | int v = getNumVertices();
35 | ArrayList neighbors = new ArrayList();
36 | adjListsMap.put(v, neighbors);
37 | }
38 |
39 | /**
40 | * Implement the abstract method for adding an edge.
41 | * @param v the index of the start point for the edge.
42 | * @param w the index of the end point for the edge.
43 | */
44 | public void implementAddEdge(int v, int w) {
45 | (adjListsMap.get(v)).add(w);
46 |
47 | }
48 |
49 | /**
50 | * Implement the abstract method for finding all
51 | * out-neighbors of a vertex.
52 | * If there are multiple edges between the vertex
53 | * and one of its out-neighbors, this neighbor
54 | * appears once in the list for each of these edges.
55 | *
56 | * @param v the index of vertex.
57 | * @return List a list of indices of vertices.
58 | */
59 | public List getNeighbors(int v) {
60 | return new ArrayList(adjListsMap.get(v));
61 | }
62 |
63 | /**
64 | * Implement the abstract method for finding all
65 | * in-neighbors of a vertex.
66 | * If there are multiple edges from another vertex
67 | * to this one, the neighbor
68 | * appears once in the list for each of these edges.
69 | *
70 | * @param v the index of vertex.
71 | * @return List a list of indices of vertices.
72 | */
73 | public List getInNeighbors(int v) {
74 | List inNeighbors = new ArrayList();
75 | for (int u : adjListsMap.keySet()) {
76 | //iterate through all edges in u's adjacency list and
77 | //add u to the inNeighbor list of v whenever an edge
78 | //with startpoint u has endpoint v.
79 | for (int w : adjListsMap.get(u)) {
80 | if (v == w) {
81 | inNeighbors.add(u);
82 | }
83 | }
84 | }
85 | return inNeighbors;
86 | }
87 |
88 |
89 | /**
90 | * Implement the abstract method for finding all
91 | * vertices reachable by two hops from v.
92 | *
93 | * @param v the index of vertex.
94 | * @return List a list of indices of vertices.
95 | */
96 | public List getDistance2(int v) {
97 | // XXX: Implement this method in week 2
98 | List distances = new ArrayList <>();
99 |
100 | for(Integer n: getNeighbors(v))
101 | distances.addAll(getNeighbors(n));
102 |
103 | return distances;
104 | }
105 |
106 | /**
107 | * Generate string representation of adjacency list
108 | * @return the String
109 | */
110 | public String adjacencyString() {
111 | String s = "Adjacency list";
112 | s += " (size " + getNumVertices() + "+" + getNumEdges() + " integers):";
113 |
114 | for (int v : adjListsMap.keySet()) {
115 | s += "\n\t"+v+": ";
116 | for (int w : adjListsMap.get(v)) {
117 | s += w+", ";
118 | }
119 | }
120 | return s;
121 | }
122 |
123 |
124 |
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/src/basicgraph/GraphAdjMatrix.java:
--------------------------------------------------------------------------------
1 | package basicgraph;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /** A class that implements a directed graph.
7 | * The graph may have self-loops, parallel edges.
8 | * Vertices are labeled by integers 0 .. n-1
9 | * and may also have String labels.
10 | * The edges of the graph are not labeled.
11 | * Representation of edges via an adjacency matrix.
12 | *
13 | * @author UCSD MOOC development team and YOU
14 | *
15 | */
16 | public class GraphAdjMatrix extends Graph {
17 |
18 | private final int defaultNumVertices = 5;
19 | private int[][] adjMatrix;
20 |
21 | /** Create a new empty Graph */
22 | public GraphAdjMatrix () {
23 | adjMatrix = new int[defaultNumVertices][defaultNumVertices];
24 | }
25 |
26 | /**
27 | * Implement the abstract method for adding a vertex.
28 | * If need to increase dimensions of matrix, double them
29 | * to amortize cost.
30 | */
31 | public void implementAddVertex() {
32 | int v = getNumVertices();
33 | if (v >= adjMatrix.length) {
34 | int[][] newAdjMatrix = new int[v*2][v*2];
35 | for (int i = 0; i < adjMatrix.length; i ++) {
36 | for (int j = 0; j < adjMatrix.length; j ++) {
37 | newAdjMatrix[i][j] = adjMatrix[i][j];
38 | }
39 | }
40 | adjMatrix = newAdjMatrix;
41 | }
42 | }
43 |
44 | /**
45 | * Implement the abstract method for adding an edge.
46 | * Allows for multiple edges between two points:
47 | * the entry at row v, column w stores the number of such edges.
48 | * @param v the index of the start point for the edge.
49 | * @param w the index of the end point for the edge.
50 | */
51 | public void implementAddEdge(int v, int w) {
52 | adjMatrix[v][w] += 1;
53 | }
54 |
55 | /**
56 | * Implement the abstract method for finding all
57 | * out-neighbors of a vertex.
58 | * If there are multiple edges between the vertex
59 | * and one of its out-neighbors, this neighbor
60 | * appears once in the list for each of these edges.
61 | *
62 | * @param v the index of vertex.
63 | * @return List a list of indices of vertices.
64 | */
65 | public List getNeighbors(int v) {
66 | List neighbors = new ArrayList();
67 | for (int i = 0; i < getNumVertices(); i ++) {
68 | for (int j=0; j< adjMatrix[v][i]; j ++) {
69 | neighbors.add(i);
70 | }
71 | }
72 | return neighbors;
73 | }
74 |
75 | /**
76 | * Implement the abstract method for finding all
77 | * in-neighbors of a vertex.
78 | * If there are multiple edges from another vertex
79 | * to this one, the neighbor
80 | * appears once in the list for each of these edges.
81 | *
82 | * @param v the index of vertex.
83 | * @return List a list of indices of vertices.
84 | */
85 | public List getInNeighbors(int v) {
86 | List inNeighbors = new ArrayList();
87 | for (int i = 0; i < getNumVertices(); i ++) {
88 | for (int j=0; j< adjMatrix[i][v]; j++) {
89 | inNeighbors.add(i);
90 | }
91 | }
92 | return inNeighbors;
93 | }
94 |
95 | /**
96 | * Implement the abstract method for finding all
97 | * vertices reachable by two hops from v.
98 | * Use matrix multiplication to record length 2 paths.
99 | *
100 | * @param v the index of vertex.
101 | * @return List a list of indices of vertices.
102 | */
103 | public List getDistance2(int v) {
104 | // XXX Implement this method in week 2
105 | List distances = new ArrayList <>();
106 | int[][] product = new int[getNumVertices()][getNumVertices()];
107 |
108 | for(int j=0; j0){
114 | for(int m=0; m geometryPoints;
20 |
21 | private String roadName;
22 | private String roadType;
23 |
24 | // Length in km
25 | private double length;
26 |
27 | public RoadSegment(GeographicPoint pt1, GeographicPoint pt2,
28 | List geometry, String roadName,
29 | String roadType, double length)
30 | {
31 | point1 = pt1;
32 | point2 = pt2;
33 | geometryPoints = new ArrayList(geometry);
34 | this.roadName = roadName;
35 | this.roadType = roadType;
36 | this.length = length;
37 | }
38 |
39 |
40 | /** Return all of the points from start to end in that order
41 | * on this segment.
42 | * @param start
43 | * @param end
44 | * @return
45 | */
46 | public List getPoints(GeographicPoint start,
47 | GeographicPoint end)
48 | {
49 | List allPoints = new ArrayList();
50 | if (point1.equals(start) && point2.equals(end)) {
51 | allPoints.add(start);
52 | allPoints.addAll(geometryPoints);
53 | allPoints.add(end);
54 | }
55 | else if (point2.equals(start) && point1.equals(end)) {
56 | allPoints.add(end);
57 | allPoints.addAll(geometryPoints);
58 | allPoints.add(start);
59 | Collections.reverse(allPoints);
60 | }
61 | else {
62 | throw new IllegalArgumentException("Start and end points do not "
63 | + "match end points of segment");
64 | }
65 |
66 | return allPoints;
67 | }
68 |
69 | /** Two road segments are equal if they have the same start and end points
70 | * and they have the same road name.
71 | */
72 | public boolean equals(Object o)
73 | {
74 | if (!(o instanceof RoadSegment)) {
75 | return false;
76 | }
77 |
78 | RoadSegment other = (RoadSegment)o;
79 | boolean ptsEqual = false;
80 | if (other.point1.equals(this.point1) && other.point2.equals(this.point2)) {
81 | ptsEqual = true;
82 | }
83 | if (other.point2.equals(this.point1) && other.point1.equals(this.point2))
84 | {
85 | ptsEqual = true;
86 | }
87 | return this.roadName.equals(other.roadName) && ptsEqual && this.length == other.length;
88 | }
89 |
90 | // get hashCode
91 | public int hashCode()
92 | {
93 | return point1.hashCode() + point2.hashCode();
94 | }
95 |
96 | // return road segment as String
97 | public String toString()
98 | {
99 | String toReturn = this.roadName + ", " +this.roadType;
100 | toReturn += " [" + point1;
101 | for (GeographicPoint p : this.geometryPoints) {
102 | toReturn += "; " + p;
103 | }
104 | toReturn += "; " + point2 + "]";
105 |
106 | return toReturn;
107 | }
108 |
109 | // get the length of the road segment
110 | public double getLength() { return this.length; }
111 |
112 |
113 | // given one end, return the other.
114 | public geography.GeographicPoint getOtherPoint(geography.GeographicPoint point) {
115 | if(point.equals(point1)) {
116 | return point2;
117 | }
118 | if(point.equals(point2)) {
119 | return point1;
120 | }
121 |
122 | System.out.println("ERROR!! : in RoadSegment::getOtherPoint Neither point matched");
123 | return null;
124 | }
125 |
126 |
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/src/gmapsfx/ArrayTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Geoff Capper.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package gmapsfx;
18 |
19 | import gmapsfx.javascript.JavaFxWebEngine;
20 | import gmapsfx.javascript.JavascriptArray;
21 | import gmapsfx.javascript.JavascriptObject;
22 | import gmapsfx.javascript.JavascriptRuntime;
23 | import javafx.application.Application;
24 | import javafx.application.Platform;
25 | import javafx.beans.value.ChangeListener;
26 | import javafx.beans.value.ObservableValue;
27 | import javafx.concurrent.Worker;
28 | import javafx.scene.Scene;
29 | import javafx.scene.layout.BorderPane;
30 | import javafx.scene.web.WebView;
31 | import javafx.stage.Stage;
32 | import netscape.javascript.JSObject;
33 |
34 | /**
35 | *
36 | * @author Geoff Capper
37 | */
38 | public class ArrayTester extends Application {
39 |
40 | protected WebView webview;
41 | protected JavaFxWebEngine webengine;
42 |
43 | @Override
44 | public void start(final Stage stage) throws Exception {
45 |
46 | webview = new WebView();
47 | webengine = new JavaFxWebEngine(webview.getEngine());
48 | JavascriptRuntime.setDefaultWebEngine( webengine );
49 |
50 | BorderPane bp = new BorderPane();
51 | bp.setCenter(webview);
52 |
53 | webengine.getLoadWorker().stateProperty().addListener(
54 | new ChangeListener() {
55 | public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
56 | if (newState == Worker.State.SUCCEEDED) {
57 | runTests();
58 | //Platform.exit();
59 | }
60 | }
61 | });
62 | webengine.load(getClass().getResource("/html/arrays.html").toExternalForm());
63 |
64 | Scene scene = new Scene(bp, 600, 600);
65 |
66 | stage.setScene(scene);
67 | stage.show();
68 |
69 | }
70 |
71 | private void runTests() {
72 |
73 | JSObject jsWin = (JSObject) webengine.executeScript("window");
74 | jsWin.call("displayTest", new Object[]{null});
75 |
76 | JavascriptArray ary = new JavascriptArray();
77 |
78 | int len = 0;
79 | for (int i = 0; i < 6; i++) {
80 | len = ary.push("String " + i);
81 | System.out.println("testArrays push " + i + " gives len: " + len);
82 | }
83 |
84 | System.out.println("testArrays toString: " + ary.toString());
85 |
86 | ary.reverse();
87 |
88 | System.out.println("testArrays reverse toString: " + ary.toString());
89 |
90 | ary.reverse();
91 |
92 | Object obj = ary.pop();
93 |
94 | System.out.println("testArrays popped: " + obj);
95 | System.out.println("testArrays popped toString: " + ary.toString());
96 |
97 | TestJSO jso = new TestJSO();
98 | jso.setTestName("Test 1");
99 |
100 | ary.unshift(jso);
101 |
102 | System.out.println("testArrays unshift JsO toString: " + ary.toString());
103 |
104 | Object jso1 = ary.shift();
105 |
106 | System.out.println("testArrays shift JsO: " + jso1);
107 | System.out.println("testArrays shift JsO reference equality: " + (jso == jso1));
108 | System.out.println("testArrays shift JsO toString: " + ary.toString());
109 |
110 | ary.push(jso);
111 | System.out.println("testArrays push JsO toString: " + ary.toString());
112 |
113 | jsWin.call("displayArray", ary);
114 |
115 | jso.setTestName("Altered Test 1");
116 |
117 | jsWin.call("displayArray", ary);
118 |
119 | System.out.println("testArrays alter JsO toString: " + ary.toString());
120 |
121 | Object jso2 = ary.get(ary.length() - 1);
122 | System.out.println("testArrays get JsO2: " + jso2);
123 |
124 | jsWin.call("iterateArray", ary);
125 |
126 | jsWin.call("displayTestEnd", new Object[]{null});
127 |
128 | }
129 |
130 |
131 | public static void main(String[] args) {
132 | System.setProperty("java.net.useSystemProxies", "true");
133 | launch(args);
134 | }
135 |
136 |
137 | class TestJSO extends JavascriptObject {
138 |
139 | public TestJSO() {
140 | super("Object");
141 | }
142 |
143 | public void setTestName(String testName) {
144 | setProperty("testName", testName);
145 | }
146 |
147 | public String getTestName() {
148 | return getProperty("testName", String.class);
149 | }
150 |
151 | @Override
152 | public String toString() {
153 | return getTestName();
154 | }
155 |
156 | }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/src/gmapsfx/MapComponentInitializedListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Lynden, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package gmapsfx;
18 |
19 | /**
20 | *
21 | * @author Rob Terpilowski
22 | */
23 | public interface MapComponentInitializedListener {
24 |
25 | public void mapInitialized();
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/gmapsfx/MapNotInitializedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Lynden, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package gmapsfx;
18 |
19 | /**
20 | *
21 | * @author Rob Terpilowski
22 | */
23 | public class MapNotInitializedException extends RuntimeException {
24 |
25 | public MapNotInitializedException() {
26 | super( "Map has not yet been initialized");
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/gmapsfx/MapReadyListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 GMapsFX.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package gmapsfx;
18 |
19 | /** A MapReadyListener is called when the MapOptions have been loaded and the
20 | * Javascript map object is set up ready to be accessed. While the MapType is
21 | * null many methods will cause errors, so this listener is notified when
22 | * projection_changed returns a non-null value, as this is expected to happen
23 | * after the MapType is set.
24 | *
25 | * @author Geoff Capper
26 | */
27 | public interface MapReadyListener {
28 |
29 | public void mapReady();
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/gmapsfx/javascript/IJavascriptRuntime.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Lynden, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package gmapsfx.javascript;
17 |
18 | import netscape.javascript.JSObject;
19 |
20 | /**
21 | * An interface for interacting with a JavaScript environment which includes
22 | * methods for building strings that represent functions and constructors as
23 | * well as providing a means to execute commands.
24 | *
25 | * @author Rob Terpilowski
26 | */
27 | public interface IJavascriptRuntime {
28 |
29 | /**
30 | * Execute the specified command returning a value (if any)
31 | *
32 | * @param command The JavaScript command to execute
33 | * @return The underlying JavaScript object that was returned by the script.
34 | */
35 | JSObject execute(String command);
36 |
37 | /**
38 | * Gets a constructor as a string which then can be passed to the execute().
39 | *
40 | * @param javascriptObjectType The type of JavaScript object to create
41 | * @param args The args of the constructor
42 | * @return A string which can be passed to the JavaScript environment to
43 | * create a new object.
44 | */
45 | String getConstructor(String javascriptObjectType, Object... args);
46 |
47 | /**
48 | * Gets an array parameter constructor as a String, which then can be
49 | * passed to the execute() method. Note, this is where the parameter to the
50 | * constructor is an array, rather than the varargs which are broken down
51 | * into separate parameters.
52 | *
53 | * @param javascriptObjectType type The type of JavaScript object array to create
54 | * @param ary The array elements
55 | * @return A string which can be passed to the JavaScript environment to
56 | * create a new array.
57 | */
58 | String getArrayConstructor(String javascriptObjectType, Object[] ary);
59 |
60 | /**
61 | * Gets a function as a String, which then can be passed to the
62 | * execute() method.
63 | *
64 | * @param variable The variable to invoke the function on.
65 | * @param function The function to invoke
66 | * @param args Arguments the function requires
67 | * @return A string which can be passed to the JavaScript environment to
68 | * invoke the function
69 | */
70 | String getFunction(String variable, String function, Object... args);
71 |
72 |
73 | /**
74 | * Gets a function as a String, which then can be passed to the
75 | * execute() method.
76 | *
77 | * @param function The function to invoke
78 | * @param args Arguments the function requires
79 | * @return A string which can be passed to the JavaScript environment to
80 | * invoke the function
81 | */
82 | String getFunction(String function, Object... args);
83 |
84 |
85 | /**
86 | * Gets an array function as a String, which then can be passed to the
87 | * execute() method.
88 | *
89 | * @param function The function to invoke
90 | * @param ary The array of arguments to pass to the function.
91 | * @return A string which can be passed to the JavaScript environment to
92 | * invoke the function
93 | */
94 | String getArrayFunction(String function, Object[] ary);
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/gmapsfx/javascript/IWebEngine.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package gmapsfx.javascript;
7 |
8 | import javafx.concurrent.Worker;
9 |
10 | /**
11 | * Provides an abstraction to the web engine, so that a mock engine can be utilized in unit tests, or a different web engine
12 | * could be utilized in future versions of this framework.
13 | *
14 | * @author Rob Terpilowski
15 | */
16 | public interface IWebEngine {
17 |
18 | /**
19 | * Executes the specified JavaScript Command
20 | *
21 | * @param command The command to execute
22 | * @return The object returned by the script (if any).
23 | */
24 | public Object executeScript(String command);
25 |
26 | /**
27 | * Gets a worked which will be notified when a web page has finished
28 | * loading.
29 | *
30 | * @return The worker
31 | */
32 | public Worker getLoadWorker();
33 |
34 | /**
35 | * Loads the specified URL
36 | *
37 | * @param url The URL to load in the engine.
38 | */
39 | public void load(String url);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/gmapsfx/javascript/JavaFxWebEngine.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package gmapsfx.javascript;
8 |
9 | import javafx.concurrent.Worker;
10 | import javafx.scene.web.WebEngine;
11 |
12 | /**
13 | * This class provides an implementation of the IWebEngine interface utilizing
14 | * a javafx.scene.web.WebEngine as the underlying engine.
15 | *
16 | * @author Rob Terpilowski
17 | */
18 | public class JavaFxWebEngine implements IWebEngine {
19 |
20 |
21 | protected WebEngine webEngine;
22 |
23 | /**
24 | * Builds a new engine utilizing the specified JavaFX WebEngine
25 | * @param engine The JavaFX WebEngine to use.
26 | */
27 | public JavaFxWebEngine( WebEngine engine ) {
28 | this.webEngine = engine;
29 | }
30 |
31 |
32 | /**
33 | * Executes the specified JavaScript Command
34 | * @param command The command to execute
35 | * @return The object returned by the script (if any).
36 | */
37 | @Override
38 | public Object executeScript(String command) {
39 | return webEngine.executeScript(command);
40 | }
41 |
42 | /**
43 | * Gets a worked which will be notified when a web page has finished loading.
44 | * @return The worker
45 | */
46 | @Override
47 | public Worker getLoadWorker() {
48 | return webEngine.getLoadWorker();
49 | }
50 |
51 | /**
52 | * Loads the specified URL
53 | * @param url The URL to load in the engine.
54 | */
55 | @Override
56 | public void load(String url) {
57 | webEngine.load(url);
58 | }
59 |
60 |
61 |
62 |
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/gmapsfx/javascript/JavascriptArray.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 GMapsFX.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package gmapsfx.javascript;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 | import netscape.javascript.JSObject;
22 |
23 | /** JavascriptObject implementation of an array.
24 | *
25 | * Return values are supplied as their raw return value from Javascript, unless
26 | * that value has previously been passed in to the array as a JavascriptObject.
27 | * The caller is then responsible for wrapping any new JSObjects in the
28 | * appropriate JavascriptObject, as they should know what is needed.
29 | *
30 | *
31 | *
32 | * @author Geoff Capper
33 | */
34 | public class JavascriptArray extends JavascriptObject {
35 |
36 | private final Map content = new HashMap<>();
37 |
38 | public JavascriptArray() {
39 | runtime.execute("var " + variableName + " = []");
40 | jsObject = runtime.execute(variableName);
41 | }
42 |
43 | public Object get(int idx) {
44 | Object obj = getJSObject().getSlot(idx);
45 | if (obj instanceof JSObject && content.containsKey((JSObject) obj)) {
46 | return (JavascriptObject) content.get((JSObject) obj);
47 | }
48 | return obj;
49 | }
50 |
51 | //concat() Joins two or more arrays, and returns a copy of the joined arrays
52 | //indexOf() Search the array for an element and returns its position
53 | public int indexOf(Object obj) {
54 | if (obj instanceof JavascriptObject) {
55 | return checkInteger(invokeJavascript("indexOf", ((JavascriptObject) obj).getJSObject()), -1);
56 | }
57 | return checkInteger(invokeJavascript("indexOf", obj), -1);
58 | }
59 |
60 | //join() Joins all elements of an array into a string
61 | //lastIndexOf() Search the array for an element, starting at the end, and returns its position
62 | public int lastIndexOf(Object obj) {
63 | if (obj instanceof JavascriptObject) {
64 | return checkInteger(invokeJavascript("lastIndexOf", ((JavascriptObject) obj).getJSObject()), -1);
65 | }
66 | return checkInteger(invokeJavascript("lastIndexOf", obj), -1);
67 | }
68 |
69 | //pop() Removes the last element of an array, and returns that element
70 | public Object pop() {
71 | //Object obj = jsObject.getSlot(jsLen - 1);
72 | Object obj = invokeJavascript("pop");
73 | if (obj instanceof JSObject && content.containsKey((JSObject) obj)) {
74 | return (JavascriptObject) content.get((JSObject) obj);
75 | }
76 | return obj;
77 | }
78 |
79 | //push() Adds new elements to the end of an array, and returns the new length
80 | public int push(Object obj) {
81 | if (obj instanceof JavascriptObject) {
82 | //jsObject.setSlot(length(), ((JavascriptObject) obj).getJSObject());
83 | content.put(((JavascriptObject) obj).getJSObject(), (JavascriptObject) obj);
84 | }
85 | return checkInteger(invokeJavascript("push", obj), 0);
86 | }
87 |
88 | //reverse() Reverses the order of the elements in an array
89 | public void reverse() {
90 | invokeJavascript("reverse");
91 | }
92 |
93 | //shift() Removes the first element of an array, and returns that element
94 | public Object shift() {
95 | Object obj = invokeJavascript("shift");
96 | if (obj instanceof JSObject && content.containsKey((JSObject) obj)) {
97 | return (JavascriptObject) content.get((JSObject) obj);
98 | }
99 | return obj;
100 | }
101 |
102 | //slice() Selects a part of an array, and returns the new array
103 |
104 | //sort() Sorts the elements of an array
105 | public void sort(String func) {
106 | if (func == null || func.isEmpty()) {
107 | Object ary = invokeJavascript("sort");
108 | } else {
109 | Object ary = invokeJavascript("sort", func);
110 | }
111 | }
112 |
113 | //splice() Adds/Removes elements from an array
114 | //toString() Converts an array to a string, and returns the result
115 | @Override
116 | public String toString() {
117 | return invokeJavascriptReturnValue("toString", String.class);
118 | }
119 |
120 | //unshift() Adds new elements to the beginning of an array, and returns the new length
121 | public int unshift(Object obj) {
122 | if (obj instanceof JavascriptObject) {
123 | //jsObject.setSlot(length(), ((JavascriptObject) obj).getJSObject());
124 | content.put(((JavascriptObject) obj).getJSObject(), (JavascriptObject) obj);
125 | }
126 | return checkInteger(invokeJavascript("unshift", obj), 0);
127 | }
128 |
129 | //valueOf()
130 |
131 | /** Get the length of the array. This returns the value from the underlying
132 | * Javascrpt object.
133 | *
134 | * @return
135 | */
136 | public int length() {
137 | return checkInteger(getProperty("length"), 0);
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/src/gmapsfx/javascript/JavascriptEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Lynden, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package gmapsfx.javascript;
17 |
18 | import netscape.javascript.JSObject;
19 |
20 | /**
21 | *
22 | * @author Rob Terpilowski
23 | */
24 | public class JavascriptEnum {
25 |
26 | protected IJavascriptRuntime runtime;
27 | protected String type;
28 | protected String name;
29 | protected Object value;
30 |
31 |
32 | protected JavascriptEnum(String type, String name) {
33 | this.type = type;
34 | this.name = name;
35 | runtime = JavascriptRuntime.getInstance();
36 |
37 | }
38 |
39 | public Object getEnumValue() {
40 | if (value == null) {
41 | JSObject jsObject = runtime.execute(type);
42 | value = jsObject.getMember(name);
43 | }
44 | return value;
45 | }
46 |
47 | public String getType() {
48 | return type;
49 | }
50 |
51 | public String getName() {
52 | return name;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/gmapsfx/javascript/JavascriptFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Lynden, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package gmapsfx.javascript;
17 |
18 | import java.util.List;
19 |
20 | /**
21 | *
22 | * @author robt
23 | */
24 | public class JavascriptFunction extends JavascriptObject {
25 |
26 | /**
27 | * Attempt to create a function as an object
28 | *
29 | * var myCallback = function( argX ) { someVariable.someMethod( argX );
30 | * someOtherVariable.someOtherMethod(); }
31 | */
32 | protected String functionName;
33 | protected List args;
34 | protected List functionLines;
35 |
36 | public JavascriptFunction(String functionName, List args, List functionLines) {
37 | this.functionName = functionName;
38 | this.args = args;
39 | this.functionLines = functionLines;
40 | }
41 |
42 | public String getFunctionAsString() {
43 | StringBuilder sb = new StringBuilder();
44 | sb.append(functionName).append("(");
45 | if (args.isEmpty()) {
46 | sb.append(")");
47 | } else {
48 | for (String arg : args) {
49 | sb.append(arg).append(",");
50 | }
51 | sb.deleteCharAt(sb.length() - 1);
52 | sb.append(")");
53 | }
54 | sb.append("{\n");
55 | for( JavascriptFunctionLine line : functionLines ) {
56 | sb.append( line.getFunctionLine() );
57 | }
58 | sb.append("}");
59 |
60 | return sb.toString();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/gmapsfx/javascript/JavascriptFunctionLine.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Lynden, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package gmapsfx.javascript;
18 |
19 | import java.util.List;
20 | import netscape.javascript.JSObject;
21 |
22 | /**
23 | *
24 | * @author robt
25 | */
26 | public class JavascriptFunctionLine {
27 |
28 | protected JSObject jsObject;
29 | protected JavascriptObject object;
30 | protected String method;
31 | protected List