-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileTreeAnimation.pde
216 lines (175 loc) · 3.97 KB
/
FileTreeAnimation.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import java.util.Iterator;
import java.util.HashSet;
import pbox2d.*;
import org.jbox2d.common.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.dynamics.*;
import org.jbox2d.dynamics.joints.*;
import controlP5.*;
PBox2D box2d;
ArrayList<CCommit> commits;
int prevCommitId;
CFileTree tree;
ControlP5 ui;
Textarea infoText;
CommitTimer timer;
String projectName;
// CButton nextButton;
void setup()
{
size(displayWidth, displayHeight, P2D);
ui = new ControlP5(this);
infoText = ui.addTextarea("info")
.setPosition(10, 10)
.setSize(200, 400)
.setFont(createFont("arial",16))
.setLineHeight(20)
.setColor(color(0xffffffff))
.setColorBackground(color(155));
hideInfoText();
box2d = new PBox2D(this);
box2d.createWorld();
box2d.setGravity(0, 0);
commits = new ArrayList<CCommit>();
load();
tree = null;
// nextButton = new CButton("Next", new PVector(width/2, 20), 50, 25);
timer = new CommitTimer();
drawFirstCommit();
}
void mouseMoved()
{
Iterator it = tree.fileIt();
while (it.hasNext ())
{
CFile file = (CFile)it.next();
if (file.contains(mouseX, mouseY))
{
file.inputState = ObjectInputState.HOVER;
}
else
{
file.inputState = ObjectInputState.NONE;
}
}
}
void mouseClicked()
{
tree.resetCurrentDirectory();
hideInfoText();
clearInfoText();
Iterator it = tree.fileIt();
while(it.hasNext())
{
CFile file = (CFile)it.next();
if (file.contains(mouseX, mouseY))
{
tree.currentDirectory(file);
updateInfoText(file);
}
}
}
void draw()
{
background(0);
noSmooth();
box2d.step();
tree.display();
}
void updateInfoText(CFile file)
{
clearInfoText();
if (!infoText.isVisible())
{
showInfoText();
}
String info = "Project name: "+"\n"+
" "+tree.name()+"\n"+
"\n"+
"\n"+
"Filename: "+file.name()+"\n"+
"File type: "+file.typeAsString()+"\n"+
"Number of children: "+file.numChildren()+"\n"
;
infoText.setText(info);
}
void clearInfoText()
{
infoText.setText("");
}
void hideInfoText()
{
infoText.hide();
}
void showInfoText()
{
infoText.show();
}
void load()
{
println("loading xml....");
XML xml = loadXML("commits.xml");
XML[] commitElements = xml.getChildren("commit");
XML root = commitElements[0].getParent();
projectName = root.getString("name");
for (int i = 0; i < commitElements.length; i++)
{
println("parsing commit.");
XML commitElement = commitElements[i];
CCommit commit = new CCommit(commitElement.getInt("id"));
XML[] fileElements = commitElement.getChildren("file");
for (int k = 0; k < fileElements.length; k++)
{
println("parsing commit files.");
commit.addFileName(fileElements[k].getContent());
}
commits.add(commit);
}
println("done loading xml.");
}
void drawFirstCommit()
{
println("loading first commit.");
// create the file tree for the project.
tree = new CFileTree(projectName);
// get the first commit.
for (CCommit commit : commits)
{
if (commit.id() == 0)
{
prevCommitId = commit.id();
Iterator it = commit.fileNameIt();
while (it.hasNext ())
{
String s = (String)it.next();
tree.addFileWithName(s);
}
}
}
timer.start();
}
void drawNextCommit()
{
tree.resetCurrentDirectory();
int currId = prevCommitId + 1;
for (CCommit commit : commits)
{
if (commit.id() == currId)
{
println("parsing commit number: "+currId);
prevCommitId = commit.id();
Iterator it = commit.fileNameIt();
while (it.hasNext ())
{
String s = (String)it.next();
tree.addFileWithName(s);
}
}
if (commits.size() == currId)
{
timer.running = false;
println("no more commits found.");
return;
}
}
}