/
AirportMarker.java
executable file
·101 lines (79 loc) · 2.36 KB
/
AirportMarker.java
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
package module6;
import java.util.List;
import java.util.ArrayList;
import de.fhpotsdam.unfolding.data.Feature;
import de.fhpotsdam.unfolding.data.PointFeature;
import de.fhpotsdam.unfolding.marker.SimpleLinesMarker;
import processing.core.PConstants;
import processing.core.PGraphics;
/**
* A class to represent AirportMarkers on a world map.
*
* @author Adam Setters and the UC San Diego Intermediate Software Development
* MOOC team
*
*/
public class AirportMarker extends CommonMarker implements Comparable<AirportMarker>{
public List<SimpleLinesMarker> routes;
public AirportMarker(Feature city) {
super(((PointFeature)city).getLocation(), city.getProperties());
routes = new ArrayList<SimpleLinesMarker>();
}
@Override
public void drawMarker(PGraphics pg, float x, float y) {
int outRoutes = routesNum();
if (outRoutes < 10) {
pg.fill(204, 255, 255);
pg.stroke(204, 255, 255);
} else if (outRoutes > 30) {
pg.fill(0, 51, 51);
pg.stroke(0, 51, 51);
} else {
pg.fill(0, 153, 153);
pg.stroke(0, 153, 153);
}
pg.ellipse(x, y, 3, 3);
}
@Override
public void showTitle(PGraphics pg, float x, float y) {
// show rectangle with title
String title = getName() + " " + getCode() + " " + getCity() + " " + getCountry();
pg.pushStyle();
pg.rectMode(PConstants.CORNER);
pg.stroke(110);
pg.fill(255,255,255);
pg.rect(x, y + 15, pg.textWidth(title) +6, 18, 5);
pg.textAlign(PConstants.LEFT, PConstants.TOP);
pg.fill(0);
pg.text(title, x + 3 , y +18);
pg.popStyle();
// show routes
}
public int compareTo(AirportMarker marker) {
int diff = this.routesNum() - marker.routesNum();
return -diff;
}
public String toString() {
String title = getName() + " " + getCode() + " " + getCity() + " " + getCountry();
title = title + " Has " + routesNum() + " routes.";
return title;
}
public void addRoute(SimpleLinesMarker sl) {
routes.add(sl);
}
public String getName() {
return getProperty("name").toString();
}
public String getCode() {
return getProperty("code").toString();
}
public String getCity() {
return getProperty("city").toString();
}
public String getCountry() {
return getProperty("country").toString();
}
private int routesNum() {
return routes.size();
}
}