-
Notifications
You must be signed in to change notification settings - Fork 45
/
SightingDetailsView.pde
139 lines (114 loc) · 4.33 KB
/
SightingDetailsView.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
static float MULTIPLICATOR_VALUE = 0.5556;
class SightingDetailsView extends View {
boolean showView = false;
List<Sighting> sightings;
Place place;
ScrollList sightingSList;
MultiLineText multiLineText;
SightingDetailsView(float x_, float y_, float w_, float h_)
{
super(x_, y_, w_, h_);
sightingSList = new ScrollList(5,15,200,175);
this.subviews.add(sightingSList);
multiLineText = new MultiLineText(230,79, w - 250,120);
this.subviews.add(multiLineText);
}
void setSightings(List<Sighting> _sightings){
sightings = _sightings;
sightingSList.removeAll();
for (int i = 0;i<sightings.size();i++){
sightingSList.add(shortDateFormat.format(sightings.get(i).localTime));
}
}
void drawContent()
{
textFont(font2,normalFontSize);
fill(viewBackgroundColor,230);
stroke(viewBackgroundColor,230);
rect(0,0, w, h);
textAlign(LEFT,TOP);
if (place!=null && sightings.size()>0){
fill(boldTextColor);
textSize(normalFontSize);
text(place.name + " (Total # of Sightings = " + place.sightingCount + ")",(w+230-textWidth(place.name + " (Total # of Sightings = " + place.sightingCount + ")"))/2,5);
Sighting newSighting = sightings.get(sightingSList.selectedIndex-1);
fill(textColor);
text("Local time: "+ dateTimeFormat.format(newSighting.localTime),230,25);
text("Reported time: " + dateFormat.format(newSighting.reportedTime),600,25);
String typeOfUFO = "Type of UFO: "+(newSighting.type).name;
text(typeOfUFO, 230,42);
text("Shape: " +newSighting.shapeName,600,42);
text("Weather Condition: "+ newSighting.weather,230,59);
text("Temperature: " + newSighting.temperature + " °F / " + str(int((MULTIPLICATOR_VALUE * (newSighting.temperature - 32))))+" °C",600,59);
// text("Full description: " + newSighting.description,230,79, w - 250,120);
//imageMode(CORNER);
// image((newSighting.type).icon,235 + textWidth(typeOfUFO),42,12,12);
if (!(multiLineText.value).equals("Full description: " + newSighting.description) && newSighting.description.length() > 0){
multiLineText.setValue("Full description: " + newSighting.description);
}
noStroke();
fill((newSighting.type).colr);
ellipse(235 + textWidth(typeOfUFO) + 6 ,42 + 6,12,12);
}
textSize(smallFontSize);
noFill();
stroke(textColor);
rect(w-46,4, 8, 9);
fill(textColor);
text("x",w-45,4);
text("Close",w-35,5);
textFont(font,normalFontSize);
}
boolean contentClicked(float lx, float ly)
{
if(lx > w-46 && lx < w - 5 && ly> 4 && ly < 16){
detailsAnimator.target(height);
}
return true;
}
}
class MultiLineText extends View {
String value = "";
VScroll tScroll;
int firstIndex = 0;
float tWidth = 0;
MultiLineText(float x_, float y_, float w_, float h_)
{
super(x_, y_, w_ , h_);
tScroll = new VScroll(w-12,0,12,h);
this.subviews.add(tScroll);
}
void setValue(String value){
this.value = value;
int nol = int(textWidth(value)/w);
int noltw = int(h / (textAscent() + textDescent())) ;
if (nol > noltw)
tWidth = w-20;
else
tWidth = w;
tScroll.linesXSpace = noltw;
tScroll.linesCount = int(textWidth(value) / tWidth);
tScroll.setCurrentLine(0);
}
void drawContent()
{
textFont(font2,normalFontSize);
textAlign(LEFT,TOP);
stroke(textColor);
fill(scrollListColor);
float vSpaceBtwLines = textAscent() + textDescent();
int charactersByLine = int(tWidth/textWidth("w"));
// println("current line " +tScroll.currentLine);
firstIndex = tScroll.currentLine * int(tWidth/textWidth("w"));
// println(value.length() + " " + charactersByLine);
fill(textColor);
for (int i = 0; i < tScroll.linesXSpace; i++) {
float y = vSpaceBtwLines*i;
if (value.length() > 0 && firstIndex + (i*charactersByLine) <= constrain(firstIndex + (i*charactersByLine) + charactersByLine,1,value.length()-1)){
String _str = trim(value.substring(firstIndex + (i*charactersByLine) , constrain(firstIndex + (i*charactersByLine) + charactersByLine,1,value.length()-1)));
text(_str, 0 , y);
}
}
textFont(font,normalFontSize);
}
}