-
Notifications
You must be signed in to change notification settings - Fork 1
/
SearchView.pde
184 lines (160 loc) · 5.56 KB
/
SearchView.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// This class is used to draw the Center View for Graph View
class SearchView extends View {
// Code used for the Search Box
// Control P5 Variables
// Code used for search box
public boolean searchActivated = false;
public String textValue = "";
public Textfield myTextfield;
public String searching = "";
public int startResult = 0;
public int numBoxes = 16;
public int endResult = numBoxes;
public int stringSelected = -1;
public ArrayList<String> searchResults;
public String dragged = "";
public int draggedIndex = -1;
int boxStart = 30;
SearchView(float x_, float y_, float w_, float h_)
{
super(x_, y_, w_, h_);
// Searchbox Setting up
controlP5.setColorBackground(0);
strokeWeight(2);
controlP5.setColorActive(tabColor2);
myTextfield = controlP5.addTextfield("", int(x), int(y), int(w), 30);
myTextfield.valueLabel().setFont(ControlP5.grixel);
myTextfield.setFocus(false);
searchResults = new ArrayList<String>();
for (int i = 0; i< bandNames.size(); i++) {
searchResults.add(""+i);
}
endResult = numBoxes;
//System.out.println(searchResults.size());
}
SearchView(float x_, float y_, float w_, float h_, int numBoxes_)
{
super(x_, y_, w_, h_);
numBoxes = numBoxes_;
endResult = numBoxes;
// Searchbox Setting up
controlP5.setColorBackground(0);
strokeWeight(2);
controlP5.setColorActive(tabColor2);
myTextfield = controlP5.addTextfield("", int(x), int(y), int(w), 30);
myTextfield.valueLabel().setFont(ControlP5.grixel);
myTextfield.setFocus(false);
searchResults = new ArrayList<String>();
for (int i = 0; i< bandNames.size(); i++) {
searchResults.add(""+i);
}
//System.out.println(searchResults.size());
}
void drawContent()
{
rectMode(CORNER);
strokeWeight(1);
stroke(tabColor2);
fill(draggableContentBoxColor);
textAlign(CENTER);
rect(0, 0, w, h);
textFont(fbold);
textSize(22);
int y2 = boxStart;
for (int i = startResult; i< searchResults.size() && i<= endResult; i++) {
fill(draggableContentBoxColor, 100);
rect(0, y2, w, 30 );
fill(menuColor1);
// fill(textColor1);
//textFont(fbold);
textSize(12);
String t = bandNames.get(Integer.parseInt(searchResults.get(i)));
if (t.length()>25)
t = t.substring(0, 26)+"...";
// System.out.println(t);
text(t, w/2, y2+20);
y2 = y2 + 30;
}
textAlign(LEFT, TOP);
textSize(largeFontSize);
if (endResult < searchResults.size()-1) {
fill(tabColor2);
image(nextArrow, w - 100, h - 30);
text("Next", w - 100 + 40, h - 2*normalFontSize);
}
if (startResult > 0) {
fill(tabColor2);
image(prevArrow, 10, h - 30);
text("Previous", 40, h - 2*normalFontSize);
}
textFont(f2);
}
boolean contentClicked(float lx, float ly)
{
if ((lx >= w - 100 && lx <= w - 100 + textWidth("Next") && ly >= h - 2*normalFontSize && ly <= h) ||
(lx >= w - 100 + textWidth("Next") + 10 && lx <= w - 100 + textWidth("Next") + 10 + 30 && ly >= h - 30 && ly <= h)) { // Click on Next
startResult = constrain(startResult+numBoxes, 0, searchResults.size()-1);
endResult = constrain(endResult+numBoxes, numBoxes, searchResults.size()-1);
}
if ((lx >= 10 && lx <= 30 + 10 && ly >= h - 2*normalFontSize && ly <= h) ||
(lx >= 40 && lx <= 40 + textWidth("Previous") && ly >= h - 30 && ly <= h)) {
startResult = constrain(startResult-numBoxes, 0, searchResults.size()-1);
endResult = constrain(endResult-numBoxes, numBoxes, searchResults.size()-1);
}
return true;
}
boolean keypressed() {
startResult = 0;
endResult = numBoxes;
if (myTextfield.isFocus()) {
if (key != CODED && key == '\b' && searching.length()>0) {
searching = searching.substring(0, searching.length()-1);
if (searching.length()==1 && searching.equals(""))
searching = "";
}
else {
char c = (char)key;
if ((c >= 'a' && c <= 'z') || (c >= 65 && c <= 90) || (c >= '0' && c <= '9') || (c == ' ') || (c == '-') || (c == '.'))
searching = searching+ key;
else
if (c == 10)
searching = "";
}
searchResults = new ArrayList<String>();
// System.out.pr
for (int i = 0; i<bandNames.size(); i++) {
String tolower = bandNames.get(i).toLowerCase();
if (tolower.contains(searching.toLowerCase())) {
// System.out.println(tolower+" BUT "+searching.toLowerCase());
searchResults.add(""+i);
// System.out.println(searchResults.size());
// System.out.println(track.getName());
}
}
}
return myTextfield.isFocus();
}
boolean contentPressed(float lx, float ly)
{
if (lx >= 0 && lx <= w && ly >= boxStart && ly <= boxStart +((numBoxes+2)*boxStart) && dragged.equals("")) {
stringSelected = ((int)ly + boxStart)/30;
stringSelected = stringSelected-2+startResult;
System.out.println(stringSelected);
}
return true;
}
boolean contentDragged(float lx, float ly) {
handleMouse( lx, ly);
return true;
}
void handleMouse(float lx, float ly) {
System.out.println(lx +" "+ly );
if (dragged.equals("") && stringSelected != -1) {
draggingContent = true;
if (stringSelected <= endResult && stringSelected >= startResult && stringSelected <searchResults.size()) {
dragged = bandNames.get(Integer.parseInt(searchResults.get(stringSelected)));
draggedIndex = stringSelected;
}
}
}
}