1- import java.io.File ;
1+ import java.io.FileNotFoundException ;
2+ import java.io.UnsupportedEncodingException ;
23
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
56String done = " Done" ;
67String OS = System . getProperty(" os.name" ). toLowerCase();
7- String home, suggestion , separator, root, sketchbookPath;
8+ String home, processingRoot , separator, root, sketchbookPath;
89PFont font;
910float rectX, rectX2, rectX3, rectY; // Position of buttons
1011float rectHeight = 30 ; // height of rect
@@ -16,10 +17,9 @@ int selectedColor, selectedColor2, selectedColor3;
1617boolean acceptOver = false ;
1718boolean noJruby = false ;
1819boolean selected = false ;
19- boolean configCheck = false ;
20+ boolean eightOne = false ;
2021String jruby = " true" ;
2122
22-
2323void setup () {
2424 size (600 , 200 );
2525 home = System . getProperty(" user.home" );
@@ -28,14 +28,15 @@ void setup() {
2828 separator = System . getProperty(" file.separator" );
2929 font = createFont (" Helvetica" , 18 );
3030 if (OS . contains(" mac" )) {
31- suggestion = " /Applications/Processing.app/Contents/Resources/Java" ;
31+ processingRoot = " /Applications/Processing.app/Contents/Resources/Java" ;
3232 sketchbookPath = home + separator + " Documents/Processing/sketchbook" ;
3333 } 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" ;
3637 } else {
3738 sketchbookPath = home + separator + " sketchbook" ;
38- suggestion = home + separator + " processing-3.0" ;
39+ processingRoot = home + separator + " processing-3.0" ;
3940 }
4041 rectColor = color (140 );
4142 rectColor2 = color (140 );
@@ -49,33 +50,34 @@ void setup() {
4950 rectX = rectWidth + 20 ;
5051 rectX2 = rectWidth + 150 ;
5152 rectX3 = rectWidth + 300 ;
52- rectY = height * 0.8 - rectHeight / 4 ;
53+ rectY = height * 0.8f - rectHeight / 4 ;
5354 enter = new Button (rectX2, rectY, rectWidth, rectHeight, " enter" );
5455 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+ " );
5657}
5758
59+
5860void draw () {
5961 background (200 );
6062 fill (0 , 0 , 200 );
61- text (" Suggestion:" , 35 , 28 );
62- text (suggestion, 35 , 56 );
63+ text (suggestion, 35 , 28 );
6364 textFont (font, 18 );
6465 fill (255 , 0 , 0 );
6566 // 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 );
6768 fill (0 , 0 , 200 );
6869 text (" Select nojruby to use jruby-complete by default" , 35 , 140 );
6970 update(mouseX , mouseY );
71+ // background(200);
7072
7173 if (acceptOver) {
7274 enter. draw(rectHighlight);
7375 nojruby. draw(rectHighlight2);
74- check . draw(rectHighlight3);
76+ winver . draw(rectHighlight3);
7577 } else {
7678 enter. draw(rectColor);
7779 nojruby. draw(rectColor2);
78- check . draw(rectColor3);
80+ winver . draw(rectColor3);
7981 }
8082}
8183
@@ -86,23 +88,30 @@ void writeRoot() {
8688 File file = new File (folder);
8789 if (! file. exists()) {
8890 if (file. mkdir()) {
89- System . out. println(" Directory is created! " );
91+ System . out. println(String . format( " Created directory: %s " , folder) );
9092 } else {
91- System . out. println(" Failed to create directory! " );
93+ System . out. println(String . format( " Failed to create: %s " , folder) );
9294 }
9395 }
9496 String config = folder + separator + " config.yml" ;
9597 File yaml = new File (config);
96-
9798 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+ }
103110 }
111+ processingRoot = done;
104112}
105113
114+
106115void keyReleased () {
107116 if (key != CODED ) {
108117 switch (key ) {
@@ -128,7 +137,6 @@ void update(float x, float y) {
128137}
129138
130139
131-
132140void mouseClicked () {
133141 update(mouseX , mouseY );
134142 if (acceptOver) {
@@ -139,15 +147,14 @@ void mouseClicked() {
139147 rectColor2 = selectedColor2;
140148 rectHighlight2 = selectedColor2;
141149 jruby = " false" ;
142- } else if (! configCheck ) {
150+ } else if (! eightOne ) {
143151 rectColor3 = selectedColor3;
144152 rectHighlight3 = selectedColor3;
145- configCheck = true ;
153+ eightOne = true ;
146154 }
147155}
148156
149157class Button {
150-
151158 float x, y, w, h;
152159 String text;
153160
@@ -170,4 +177,4 @@ class Button {
170177 return (mouseX >= x && mouseX <= x + w
171178 && mouseY >= y && mouseY <= y + h);
172179 }
173- }
180+ }
0 commit comments