1
- import java.io.File ;
1
+ import java.io.FileNotFoundException ;
2
+ import java.io.UnsupportedEncodingException ;
2
3
3
- Button enter, nojruby, check ;
4
- String processingRoot = " enter your processing root here" ; // edit this line in the sketch
4
+ Button enter, nojruby, winver ;
5
+ String suggestion = " Enter your processing root here: " ; // edit this line in the sketch
5
6
String done = " Done" ;
6
7
String OS = System . getProperty(" os.name" ). toLowerCase();
7
- String home, suggestion , separator, root, sketchbookPath;
8
+ String home, processingRoot , separator, root, sketchbookPath;
8
9
PFont font;
9
10
float rectX, rectX2, rectX3, rectY; // Position of buttons
10
11
float rectHeight = 30 ; // height of rect
@@ -16,10 +17,9 @@ int selectedColor, selectedColor2, selectedColor3;
16
17
boolean acceptOver = false ;
17
18
boolean noJruby = false ;
18
19
boolean selected = false ;
19
- boolean configCheck = false ;
20
+ boolean eightOne = false ;
20
21
String jruby = " true" ;
21
22
22
-
23
23
void setup () {
24
24
size (600 , 200 );
25
25
home = System . getProperty(" user.home" );
@@ -28,14 +28,15 @@ void setup() {
28
28
separator = System . getProperty(" file.separator" );
29
29
font = createFont (" Helvetica" , 18 );
30
30
if (OS . contains(" mac" )) {
31
- suggestion = " /Applications/Processing.app/Contents/Resources/Java" ;
31
+ processingRoot = " /Applications/Processing.app/Contents/Resources/Java" ;
32
32
sketchbookPath = home + separator + " Documents/Processing/sketchbook" ;
33
33
} else if (OS . contains(" windows" )) {
34
- sketchbookPath = home + separator + " Documents" + separator + " sketchbook" ;
35
- suggestion = home + separator + " processing-3.0" ;
34
+ sketchbookPath = (eightOne) ? home + separator + " Documents" + separator + " sketchbook"
35
+ : home + separator + " My Documents" + separator + " sketchbook" ;
36
+ processingRoot = home + separator + " processing-3.0" ;
36
37
} else {
37
38
sketchbookPath = home + separator + " sketchbook" ;
38
- suggestion = home + separator + " processing-3.0" ;
39
+ processingRoot = home + separator + " processing-3.0" ;
39
40
}
40
41
rectColor = color (140 );
41
42
rectColor2 = color (140 );
@@ -49,33 +50,34 @@ void setup() {
49
50
rectX = rectWidth + 20 ;
50
51
rectX2 = rectWidth + 150 ;
51
52
rectX3 = rectWidth + 300 ;
52
- rectY = height * 0.8 - rectHeight / 4 ;
53
+ rectY = height * 0.8f - rectHeight / 4 ;
53
54
enter = new Button (rectX2, rectY, rectWidth, rectHeight, " enter" );
54
55
nojruby = new Button (rectX, rectY, rectWidth, rectHeight, " nojruby" );
55
- check = new Button (rectX3, rectY, rectWidth, rectHeight, " check " );
56
+ winver = new Button (rectX3, rectY, rectWidth, rectHeight, " Win 8.1+ " );
56
57
}
57
58
59
+
58
60
void draw () {
59
61
background (200 );
60
62
fill (0 , 0 , 200 );
61
- text (" Suggestion:" , 35 , 28 );
62
- text (suggestion, 35 , 56 );
63
+ text (suggestion, 35 , 28 );
63
64
textFont (font, 18 );
64
65
fill (255 , 0 , 0 );
65
66
// this adds a blinking cursor after your text, at the expense of redrawing everything every frame
66
- text (processingRoot + (frameCount / 10 % 2 == 0 ? " _" : " " ), 35 , 100 );
67
+ text (processingRoot + (frameCount / 10 % 2 == 0 ? " _" : " " ), 35 , 56 );
67
68
fill (0 , 0 , 200 );
68
69
text (" Select nojruby to use jruby-complete by default" , 35 , 140 );
69
70
update(mouseX , mouseY );
71
+ // background(200);
70
72
71
73
if (acceptOver) {
72
74
enter. draw(rectHighlight);
73
75
nojruby. draw(rectHighlight2);
74
- check . draw(rectHighlight3);
76
+ winver . draw(rectHighlight3);
75
77
} else {
76
78
enter. draw(rectColor);
77
79
nojruby. draw(rectColor2);
78
- check . draw(rectColor3);
80
+ winver . draw(rectColor3);
79
81
}
80
82
}
81
83
@@ -86,23 +88,30 @@ void writeRoot() {
86
88
File file = new File (folder);
87
89
if (! file. exists()) {
88
90
if (file. mkdir()) {
89
- System . out. println(" Directory is created! " );
91
+ System . out. println(String . format( " Created directory: %s " , folder) );
90
92
} else {
91
- System . out. println(" Failed to create directory! " );
93
+ System . out. println(String . format( " Failed to create: %s " , folder) );
92
94
}
93
95
}
94
96
String config = folder + separator + " config.yml" ;
95
97
File yaml = new File (config);
96
-
97
98
if (! yaml. exists()) {
98
- PrintWriter writer = createWriter (config);
99
- writer. println(String . format(" PROCESSING_ROOT: %s" , processingRoot));
100
- writer. println(String . format(" JRUBY: %s" , jruby));
101
- writer. println(String . format(" sketchbook_path: %s" , sketchbookPath));
102
- processingRoot = done;
99
+ try {
100
+ PrintWriter writer = new PrintWriter (config, " UTF-8" );
101
+ writer. println(String . format(" PROCESSING_ROOT: %s" , processingRoot));
102
+ writer. println(String . format(" JRUBY: %s" , jruby));
103
+ writer. println(String . format(" sketchbook_path: %s" , sketchbookPath));
104
+ writer. close();
105
+ }
106
+ catch (FileNotFoundException ex) {
107
+ }
108
+ catch (UnsupportedEncodingException ex) {
109
+ }
103
110
}
111
+ processingRoot = done;
104
112
}
105
113
114
+
106
115
void keyReleased () {
107
116
if (key != CODED ) {
108
117
switch (key ) {
@@ -128,7 +137,6 @@ void update(float x, float y) {
128
137
}
129
138
130
139
131
-
132
140
void mouseClicked () {
133
141
update(mouseX , mouseY );
134
142
if (acceptOver) {
@@ -139,15 +147,14 @@ void mouseClicked() {
139
147
rectColor2 = selectedColor2;
140
148
rectHighlight2 = selectedColor2;
141
149
jruby = " false" ;
142
- } else if (! configCheck ) {
150
+ } else if (! eightOne ) {
143
151
rectColor3 = selectedColor3;
144
152
rectHighlight3 = selectedColor3;
145
- configCheck = true ;
153
+ eightOne = true ;
146
154
}
147
155
}
148
156
149
157
class Button {
150
-
151
158
float x, y, w, h;
152
159
String text;
153
160
@@ -170,4 +177,4 @@ class Button {
170
177
return (mouseX >= x && mouseX <= x + w
171
178
&& mouseY >= y && mouseY <= y + h);
172
179
}
173
- }
180
+ }
0 commit comments