forked from nothinglabs/proftweak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proftweak.pde
941 lines (741 loc) · 23.7 KB
/
proftweak.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
import java.util.Set;
import java.util.Arrays;
import java.io.*;
import java.awt.*;
import java.awt.font.*;
import g4p_controls.*;
JSONObject json;
ArrayList MasterVariableArray;
ArrayList MasterTextBoxArray;
ArrayList MasterTextLabelArray;
String[] commonSettings = new String[0];
GSlider sdrBack;
GButton ShowAllButton;
GButton SaveTempButton;
GButton SaveButton;
GButton SaveNewButton;
GTextField newProfileTextBox;
GLabel statusTitle;
GDropList profileSelector;
GTextArea profilenotes;
long startTimer = 0;
long statusTimer = 0;
float Voffset = 0;
int indent = 0;
int lastSlider = 0;
int itemSpacing = 15;
int buttonX = 410;
int buttonWidth = 240;
int windowHeight = 720;
boolean showall = false;
boolean drawSelectBox = false;
float selectBoxY;
String profileDir;
String pathForCurrentProfile;
boolean badThingHappenedSoShuttingDown = false;
Font labelFont = new Font("Dialog", Font.PLAIN, 13);
Font boldLabelFont = new Font("Dialog", Font.PLAIN, 13);
Font entryFont = new Font("Dialog", Font.BOLD, 13);
//main structure for storing parsed json info
class JSONEntry {
String name;
ArrayList dataObjectArray;
JSONObject JSObject;
JSONEntry(String i_name, ArrayList i_dataObjectArray, JSONObject i_JSObject)
{
name = i_name;
dataObjectArray = i_dataObjectArray;
JSObject = i_JSObject;
}
}
//scroll stuff
public void handleSliderEvents(GValueControl slider, GEvent event) {
//boost frame rate whenever we get an event
makeAppResponsive();
Voffset ++;
int slideMove = slider.getValueI() - lastSlider;
for (int y = 0; y < MasterTextBoxArray.size(); y++)
{
GAbstractControl controlToScroll = (GAbstractControl)MasterTextBoxArray.get(y);
controlToScroll.moveTo(controlToScroll.getX(), controlToScroll.getY() - slideMove);
}
for (int y = 0; y < MasterTextLabelArray.size(); y++)
{
GAbstractControl controlToScroll = (GAbstractControl)MasterTextLabelArray.get(y);
controlToScroll.moveTo(controlToScroll.getX(), controlToScroll.getY() - slideMove);
}
lastSlider = slider.getValueI();
selectBoxY = selectBoxY - slideMove;
}
//set color of text fields depending on if they're boolean, string or number
void setEntryColor(GEditableTextControl myTextArea)
{
if (myTextArea.getText().equals("true") || myTextArea.getText().equals("false"))
{
myTextArea.setLocalColorScheme(7);
}
else
{
try
{
Float.valueOf(myTextArea.getText()).floatValue();
myTextArea.setLocalColorScheme(5);
}
catch(Exception e) {
myTextArea.setLocalColorScheme(1);
}
finally {
}
}
}
//make app response once events are detected - doing this because java / processing SUCK CPU if allowed to
void makeAppResponsive()
{
frameRate(60);
startTimer = millis();
}
//generates list of makerware profiles
ArrayList getProfiles() {
ArrayList<File> filesList = new ArrayList<File>();
try
{
String folderPath = profileDir;
if (folderPath != null) {
File file = new File(folderPath);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory())
{
filesList.add(files[i]);
}
}
}
}
catch(Exception e) {
if (badThingHappenedSoShuttingDown == false)
{
G4P.showMessage(this, "I couldn't find your profile folder. Try setting it manually in proftweak.json.", "Uh oh", G4P.WARNING);
badThingHappenedSoShuttingDown = true;
exit();
}
}
finally {
}
return(filesList);
}
//updates profile selecting gui - optionally choosing specified profile
void displayProfileList(String profileToSelect)
{
String x[] = new String[1000];
int indexOfItemToSelect = 1;
int arrayIndex = 0;
ArrayList<File> filesList = getProfiles();
for (File f : filesList) {
println(f.getName());
x[arrayIndex] = f.getName();
if (f.getName().equals(profileToSelect)) indexOfItemToSelect = arrayIndex;
arrayIndex++;
}
profileSelector.setItems(x, indexOfItemToSelect);
if (filesList.size() == 0)
{
if (badThingHappenedSoShuttingDown == false)
{
G4P.showMessage(this, "Before using ProfTweak - you need to create a custom profile in Makerware. If you've already done this - try setting your profile folder manually in proftweak.json.", "Uh oh", G4P.WARNING);
badThingHappenedSoShuttingDown = true;
exit();
}
}
}
//initial app setup
void setup() {
JSONObject settings = loadJSONObject("proftweak.json");
profileDir = settings.getString("profileFolder");
JSONArray commonSettingsJS = (settings.getJSONArray("commonSettings"));
for (int y = 0; y < commonSettingsJS.size(); y++)
{
print((String)commonSettingsJS.getString(y));
commonSettings = append(commonSettings, (String)commonSettingsJS.getString(y));
}
if (profileDir.equals(""))
{
if (platform == MACOSX) {
profileDir = System.getProperty("user.home")+"/Things/Profiles/";
}
else if (platform == WINDOWS) {
println("WINDOWS");
profileDir = System.getProperty("user.home")+"/My Things/Profiles/";
}
else if (platform == LINUX) {
println("LINUX");
}
}
print(profileDir);
size(667, windowHeight);
frameRate(60);
noSmooth();
background(0);
fill(255);
G4P.setGlobalColorScheme(15);
GLabel profileLabel = new GLabel(this, 388, 84, 300, 18, "Current profile:");
profileLabel.setFont(new Font("Dialog", Font.PLAIN, 14));
profileLabel.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
profileLabel.setLocalColorScheme(9);
profileSelector = new GDropList(this, 390, 103, 260, 18 * (5 + 1), 5);
profileSelector.setLocalColorScheme(6);
//status line
statusTitle = new GLabel(this, 398, 650, 260, 17, "");
statusTitle.setFont(new Font("Dialog", Font.BOLD, 15));
statusTitle.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
statusTitle.setLocalColorScheme(7);
//did we get a profile name on the command line?
String requestedProfileName = "";
if (args.length > 0)
{
try {
String pathDelim = "/";
if (platform == WINDOWS) pathDelim = "\\";
requestedProfileName = args[args.length - 1];
String fileEntities[] = split(requestedProfileName, pathDelim);
requestedProfileName = fileEntities[fileEntities.length - 2];
}
catch(Exception e) {
}
finally {
}
}
displayProfileList(requestedProfileName);
//scroll bar
sdrBack = new GSlider(this, 360, 442, 185, 18, 18);
sdrBack.setLimits(0, 255, 0);
sdrBack.setRotation(-PI/2);
sdrBack.setTextOrientation(G4P.ORIENT_RIGHT);
sdrBack.setEasing(0);
sdrBack.setLocalColorScheme(6);
GButton RefreshButton = new GButton(this, 567, 83, 85, 17, "Refresh List");
RefreshButton.tag = "RefreshButton";
SaveButton = new GButton(this, buttonX, 126, buttonWidth, 30, "Save Current Profile");
SaveButton.tag = "SaveButton";
GLabel newProfNameTitle = new GLabel(this, 388, 165, 230, 17, "Name for new profile:");
newProfNameTitle.setFont(new Font("Dialog", Font.PLAIN, 14));
newProfNameTitle.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
newProfNameTitle.setLocalColorScheme(9);
newProfileTextBox = new GTextField(this, 390, 183, 260, 17);
newProfileTextBox.setFont(new Font("Dialog", Font.PLAIN, 13));
newProfileTextBox.setLocalColorScheme(3);
newProfileTextBox.tag = "newprofilename";
setEntryColor(newProfileTextBox);
SaveNewButton = new GButton(this, buttonX, 205, buttonWidth, 30, "Save As New Profile");
SaveNewButton.tag = "SaveNewButton";
SaveTempButton = new GButton(this, buttonX, 255, buttonWidth, 30, "Save As 'ProfTweakTemp' Profile");
SaveTempButton.tag = "SaveTempButton";
GLabel profNotesLabel = new GLabel(this, 388, 300, 200, 17, "Notes:");
profNotesLabel.setFont(new Font("Dialog", Font.PLAIN, 13));
profNotesLabel.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
profNotesLabel.setLocalColorScheme(9);
profilenotes = new GTextArea(this, 390, 317, 260, 87);
profilenotes.setFont(new Font("Dialog", Font.PLAIN, 13));
profilenotes.setLocalColorScheme(5);
profilenotes.tag = "profilenotes";
ShowAllButton = new GButton(this, buttonX, 430, buttonWidth, 30, "Show All Profile Settings");
ShowAllButton.tag = "ShowAllButton";
ShowAllButton.setText("Show All Profile Settings");
GButton ShowDocs = new GButton(this, buttonX, 480, buttonWidth, 30, "Profile Reference (makerbot.com)");
ShowDocs.tag = "ShowDocs";
GButton showProfiles = new GButton(this, buttonX, 530, buttonWidth, 30, "Open Profile Folder");
showProfiles.tag = "showProfiles";
GButton nothingButton = new GButton(this, buttonX, 580, buttonWidth, 30, "Visit nothinglabs.com (project info)");
nothingButton.tag = "nothingButton";
GLabel appTitle = new GLabel(this, 385, 20, 200, 17, "ProfTweak");
appTitle.setFont(new Font("Dialog", Font.BOLD, 20));
appTitle.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
appTitle.setLocalColorScheme(9);
GLabel appDesc = new GLabel(this, 385, 40, 300, 14, "A MakerWare profile editor");
appDesc.setFont(new Font("Dialog", Font.BOLD, 14));
appDesc.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
appDesc.setLocalColorScheme(9);
GLabel appCredit = new GLabel(this, 385, 55, 300, 18, "By Rich Olson / nothinglabs.com");
appCredit.setFont(new Font("Dialog", Font.BOLD, 14));
appCredit.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
appCredit.setLocalColorScheme(9);
MasterVariableArray = new ArrayList();
MasterTextLabelArray = new ArrayList();
MasterTextBoxArray = new ArrayList();
if (setJSONPath()) parseAndRenderJSON();
}
boolean setJSONPath()
{
try
{
pathForCurrentProfile = profileDir + profileSelector.getSelectedText() + "/miracle.json";
print(pathForCurrentProfile);
json = loadJSONObject(pathForCurrentProfile);
return (true);
}
catch(Exception e) {
showMessage("Profile Load FAILED", 9000);
G4P.showMessage(this, "Error: That profile doesn't seem valid (unable to open miracle.json).", "Uh oh", G4P.WARNING);
return (false);
}
finally {
}
}
void parseAndRenderJSON()
{
for (int y = 0; y < MasterTextBoxArray.size(); y++)
{
GAbstractControl controlToHide = (GAbstractControl)MasterTextBoxArray.get(y);
controlToHide.setVisible(false);
}
for (int y = 0; y < MasterTextLabelArray.size(); y++)
{
GAbstractControl controlToHide = (GAbstractControl)MasterTextLabelArray.get(y);
controlToHide.setVisible(false);
}
MasterVariableArray = new ArrayList();
lastSlider = 0;
sdrBack.setLimits(0, 255, 0);
drawSelectBox = false;
indent = 0;
Voffset = 0;
profilenotes.setText("");
if (json != null) ParseJSONObjectToMainArray(json);
int scrollLimit = (int)((Voffset * itemSpacing) - windowHeight) + 150;
if (scrollLimit < 0) scrollLimit = 150;
sdrBack.setLimits(0, scrollLimit, 0);
}
public void handleDropListEvents(GDropList list, GEvent event) {
makeAppResponsive();
if (setJSONPath()) parseAndRenderJSON();
}
void keyPressed() {
if (key == ESC) {
key = 0;
}
}
void draw() {
background(0);
fill(255);
if (drawSelectBox == true)
{
fill(255, 0, 0, 63);
rect(20, selectBoxY, 270, itemSpacing);
}
if ((millis() - startTimer) > 10000)
{
frameRate(4);
}
if ((millis() - statusTimer) > 0)
{
statusTitle.setText("");
}
}
//re-use text fields we've hidden
GTextField getTextFieldFromArray()
{
GTextField textFieldToReturn;
for (int z=0; z < MasterTextBoxArray.size(); z++)
{
textFieldToReturn = (GTextField)MasterTextBoxArray.get(z);
if (!textFieldToReturn.isVisible()) return textFieldToReturn;
}
//make new text field if we couldn't find a hidden one
print("making new text field");
textFieldToReturn = new GTextField(this, 250, Voffset * itemSpacing, 100, 16);
MasterTextBoxArray.add(textFieldToReturn);
print (textFieldToReturn);
return (textFieldToReturn);
}
GLabel getLabelFromArray()
{
GLabel labelToReturn;
for (int z=0; z < MasterTextLabelArray.size(); z++)
{
labelToReturn = (GLabel)MasterTextLabelArray.get(z);
if (!labelToReturn.isVisible()) return labelToReturn;
}
//make new label if we couldn't find a hidden one
print("making new label");
labelToReturn = new GLabel(this, 10 + indent * 15, (Voffset * itemSpacing), 230, 15, "");
MasterTextLabelArray.add(labelToReturn);
print (labelToReturn);
return (labelToReturn);
}
void addItem(JSONEntry JSONAddition)
{
Voffset = Voffset + 1;
MasterVariableArray.add(JSONAddition);
GLabel lblStyleInstr;
lblStyleInstr = getLabelFromArray();
lblStyleInstr.moveTo(10 + indent * 15, (Voffset * itemSpacing));
lblStyleInstr.setVisible(true);
lblStyleInstr.setText(JSONAddition.name);
lblStyleInstr.setFont(labelFont);
lblStyleInstr.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
lblStyleInstr.setLocalColorScheme(9);
String value = "" + JSONAddition.dataObjectArray.get(0) + "";
GTextField txaSample;
txaSample = getTextFieldFromArray();
txaSample.moveTo(250, Voffset * itemSpacing);
txaSample.setVisible(true);
txaSample.setFont(entryFont);
txaSample.setText(value);
txaSample.setLocalColorScheme(3);
txaSample.tag = "" + MasterVariableArray.size();
setEntryColor(txaSample);
}
void addLabel(String TextLabel)
{
Voffset = Voffset + 1;
//if (indent == 1) Voffset = Voffset + 0.25;
GLabel lblStyleInstr;
lblStyleInstr = getLabelFromArray();
lblStyleInstr.moveTo(10 + indent * 15, (Voffset * itemSpacing));
lblStyleInstr.setVisible(true);
lblStyleInstr.setText(TextLabel);
lblStyleInstr.setFont(boldLabelFont);
lblStyleInstr.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
lblStyleInstr.setLocalColorScheme(7);
}
public void handleTextEvents(GEditableTextControl textarea, GEvent event) {
makeAppResponsive();
println(event + " " +textarea);
if (event == GEvent.GETS_FOCUS)
{
drawSelectBox = true;
selectBoxY = textarea.getY();
}
if (textarea.tag == "newprofilename")
{
drawSelectBox = false;
}
if (textarea.tag == "profilenotes")
{
drawSelectBox = false;
json.setString("myProfileNotes", textarea.getText());
}
if (event == GEvent.CHANGED)
{
JSONEntry entryBeingEditted = (JSONEntry)MasterVariableArray.get(Integer.parseInt(textarea.tag) - 1);
println (textarea.getText());
//bolean??
if (textarea.getText().equals("true"))
{
entryBeingEditted.JSObject.setBoolean(entryBeingEditted.name, true);
println ("set to true");
}
else
{
if (textarea.getText().equals("false"))
{
entryBeingEditted.JSObject.setBoolean(entryBeingEditted.name, false);
println ("set to false");
}
else
{
//maybe it's an int...
boolean itsanINT = false;
try
{
Integer.parseInt(textarea.getText());
itsanINT = true;
}
catch(Exception e) {
print("not an int");
}
finally {
}
if (itsanINT == true)
{
entryBeingEditted.JSObject.setInt(entryBeingEditted.name, Integer.parseInt(textarea.getText()));
println ("its a integer");
}
else
{
//maybe it's a float...
boolean itsaFLOAT = false;
try
{
Float.valueOf(textarea.getText()).floatValue();
itsaFLOAT = true;
}
catch(Exception e) {
println("not a float");
}
finally {
}
if (itsaFLOAT == true)
{
entryBeingEditted.JSObject.setDouble(entryBeingEditted.name, Float.valueOf(textarea.getText()).floatValue());
println ("its a float");
}
//it's a string
else
{
entryBeingEditted.JSObject.setString(entryBeingEditted.name, textarea.getText());
}
}
}
}
setEntryColor(textarea);
}
}
Object[] filterArray(Object[] myNames)
{
Object[] filteredNames = new Object[0];
for (int z = 0; z < commonSettings.length; z++)
{
String setting = commonSettings[z];
for (int x = 0; x < myNames.length; x++)
{
if (myNames[x].equals(setting))
{
filteredNames = (Object [])append(filteredNames, myNames[x]);
//add spacers
if (z < commonSettings.length -1)
{
if ((commonSettings[z + 1]).equals("-EMPTY_SPACE-")) filteredNames = (Object [])append(filteredNames, "-EMPTY_SPACE-");
}
}
}
}
return filteredNames;
}
void ParseJSONObjectToMainArray(JSONObject JSObject)
{
indent = indent + 1;
Set i = JSObject.keys();
Object[] myNames = i.toArray(new String[0]);
if (showall == true)
{
Arrays.sort( myNames );
}
else
{
myNames = filterArray(myNames);
}
for (int x = 0; x < myNames.length; x++)
{
if (((String)myNames[x]).equals("-EMPTY_SPACE-")) addLabel("");
if (((String)myNames[x]).equals("myProfileNotes"))
{
profilenotes.setText(JSObject.getString((String)myNames[x]));
}
else
{
//Number value
try
{
ArrayList DataObjectArray = new ArrayList();
DataObjectArray.add(JSObject.getFloat((String)myNames[x]));
JSONEntry JSONAddition = new JSONEntry((String)myNames[x], DataObjectArray, JSObject);
//println(JSONAddition.name+ " " +JSONAddition.dataObjectArray.get(0));
addItem(JSONAddition);
}
catch(Exception e) {
}
finally {
}
//Boolean
try
{
ArrayList DataObjectArray = new ArrayList();
DataObjectArray.add(JSObject.getBoolean((String)myNames[x]));
JSONEntry JSONAddition = new JSONEntry((String)myNames[x], DataObjectArray, JSObject);
//println(JSONAddition.name+ " " +JSONAddition.dataObjectArray.get(0));
addItem(JSONAddition);
}
catch(Exception e) {
}
finally {
}
//string
try
{
ArrayList DataObjectArray = new ArrayList();
DataObjectArray.add(JSObject.getString((String)myNames[x]));
JSONEntry JSONAddition = new JSONEntry((String)myNames[x], DataObjectArray, JSObject);
//println(JSONAddition.name+ " " +JSONAddition.dataObjectArray.get(0));
addItem(JSONAddition);
}
catch(Exception e) {
}
finally {
}
//JSON Object
try
{
JSONObject JSOFromEntryObject = JSObject.getJSONObject((String)myNames[x]);
addLabel((String)myNames[x]);
//println((String)myNames[x]);
ParseJSONObjectToMainArray(JSOFromEntryObject);
}
catch(Exception e) {
}
finally {
}
//JSON Array
try
{
JSONArray JSArrayFromEntryObject = JSObject.getJSONArray((String)myNames[x]);
for (int y = 0; y < JSArrayFromEntryObject.size(); y++)
{
try
{
JSONObject objectFromArray = JSArrayFromEntryObject.getJSONObject(y);
addLabel((String)myNames[x] + " (" + y + ")");
ParseJSONObjectToMainArray(objectFromArray);
}
catch(Exception e) {
}
finally {
}
}
}
catch(Exception e) {
}
finally {
}
}
}
indent = indent - 1;
showMessage("Profile Loaded", 3000);
}
void showMessage(String message, int showTime)
{
print (message);
statusTitle.setText(message);
statusTimer = millis() + showTime;
}
public void handleButtonEvents(GButton button, GEvent event) {
makeAppResponsive();
if (event == GEvent.CLICKED) {
print ("button clicked:");
println (button);
if (button.tag == "SaveButton")
{
try {
saveJSONObject(json, pathForCurrentProfile);
showMessage("Profile Saved", 3000);
}
catch (Exception e) {
G4P.showMessage(this, "Save Failed...", "Uh oh", G4P.WARNING);
showMessage("Save Failed...", 3000);
}
finally {
}
}
if (button.tag == "RefreshButton")
{
String currentProfileName = profileSelector.getSelectedText();
displayProfileList(currentProfileName);
if (!profileSelector.getSelectedText().equals(currentProfileName))
{
if (setJSONPath()) parseAndRenderJSON();
}
showMessage("Profile List Refreshed", 3000);
}
if (button.tag == "showProfiles")
{
String launchProfile = "file:///" + profileDir;
launchProfile = launchProfile.replace("\\", "/");
launchProfile = launchProfile.replaceAll(" ", "%20");
print (launchProfile);
link(launchProfile);
}
if (button.tag == "ShowDocs")
{
link("http://www.makerbot.com/support/makerware/documentation/slicer/");
}
if (button.tag == "SaveTempButton" || button.tag == "SaveNewButton")
{
String saveNameText = "ProfTweakTemp";
if (button.tag == "SaveNewButton")
{
println("saving new profile:");
saveNameText = newProfileTextBox.getText();
saveNameText = saveNameText.replace("\\", "");
saveNameText = saveNameText.replace("/", "");
saveNameText = saveNameText.replace("%", "");
saveNameText = saveNameText.replace("&", "");
saveNameText = saveNameText.replace("*", "");
saveNameText = saveNameText.replace("?", "");
saveNameText = saveNameText.replace(":", "");
saveNameText = saveNameText.replace(">", "");
saveNameText = saveNameText.replace("<", "");
saveNameText = saveNameText.replace("|", "");
saveNameText = saveNameText.replace("\"", "");
newProfileTextBox.setText(saveNameText);
println(saveNameText);
}
try {
if ((newProfileTextBox.getText().equals("") || newProfileTextBox.getText().equals(" ")) && button.tag == "SaveNewButton")
{
G4P.showMessage(this, "Please enter a valid profile name.", "Uh oh", G4P.WARNING);
}
else
{
File f = new File(profileDir + saveNameText);
f.mkdir();
saveJSONObject(json, profileDir + saveNameText + "/miracle.json");
JCopy cp = new JCopy();
File f1 = new File(profileDir + profileSelector.getSelectedText() + "/end.gcode");
File f2 = new File(profileDir + saveNameText + "/end.gcode");
cp.copyFile(f1, f2);
f1 = new File(profileDir + profileSelector.getSelectedText() + "/start.gcode");
f2 = new File(profileDir + saveNameText + "/start.gcode");
cp.copyFile(f1, f2);
f1 = new File(profileDir + profileSelector.getSelectedText() + "/profile.json");
f2 = new File(profileDir + saveNameText + "/profile.json");
cp.copyFile(f1, f2);
if (button.tag == "SaveNewButton")
{
displayProfileList(newProfileTextBox.getText());
newProfileTextBox.setText("");
setJSONPath();
}
showMessage("Profile Saved", 3000);
}
}
catch (Exception e) {
showMessage("Save Failed.", 3000);
G4P.showMessage(this, "Save Failed! Your original profile may have been missing a required file.", "Uh oh", G4P.WARNING);
}
finally {
}
}
if (button.tag == "ShowAllButton")
{
showall = !showall;
parseAndRenderJSON();
statusTitle.setText("");
if (showall == true)
{
ShowAllButton.setText("Show Only Common Profile Settings");
}
else
{
ShowAllButton.setText("Show All Profile Settings");
}
}
if (button.tag == "nothingButton")
{
link("http://www.nothinglabs.com");
}
}
}
public class JCopy {
JCopy() {
}
public void copyFile(File in, File out) throws Exception {
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while ( (i=fis.read (buf))!=-1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
}
}