Skip to content

Commit 42943b4

Browse files
committed
Added progressbar (from wiring)
1 parent 4c73aaf commit 42943b4

File tree

4 files changed

+102
-5
lines changed

4 files changed

+102
-5
lines changed

app/src/processing/app/Editor.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1841,9 +1841,11 @@ public void run() {
18411841
String appletClassName = sketch.build(false);
18421842
statusNotice("Done compiling.");
18431843
} catch (Exception e) {
1844+
status.unprogress();
18441845
statusError(e);
18451846
}
18461847

1848+
status.unprogress();
18471849
toolbar.deactivate(EditorToolbar.RUN);
18481850
}
18491851
}
@@ -1856,9 +1858,11 @@ public void run() {
18561858
String appletClassName = sketch.build(true);
18571859
statusNotice("Done compiling.");
18581860
} catch (Exception e) {
1861+
status.unprogress();
18591862
statusError(e);
18601863
}
18611864

1865+
status.unprogress();
18621866
toolbar.deactivate(EditorToolbar.RUN);
18631867
}
18641868
}
@@ -2334,7 +2338,7 @@ synchronized public void handleExport(final boolean usingProgrammer) {
23342338
//if (!handleExportCheckModified()) return;
23352339
toolbar.activate(EditorToolbar.EXPORT);
23362340
console.clear();
2337-
statusNotice("Uploading to I/O Board...");
2341+
status.progress("Uploading to I/O Board...");
23382342

23392343
new Thread(usingProgrammer ? exportAppHandler : exportHandler).start();
23402344
}
@@ -2363,10 +2367,12 @@ public void run() {
23632367
} catch (RunnerException e) {
23642368
//statusError("Error during upload.");
23652369
//e.printStackTrace();
2370+
status.unprogress();
23662371
statusError(e);
23672372
} catch (Exception e) {
23682373
e.printStackTrace();
23692374
}
2375+
status.unprogress();
23702376
uploading = false;
23712377
//toolbar.clear();
23722378
toolbar.deactivate(EditorToolbar.EXPORT);
@@ -2397,10 +2403,12 @@ public void run() {
23972403
} catch (RunnerException e) {
23982404
//statusError("Error during upload.");
23992405
//e.printStackTrace();
2406+
status.unprogress();
24002407
statusError(e);
24012408
} catch (Exception e) {
24022409
e.printStackTrace();
24032410
}
2411+
status.unprogress();
24042412
uploading = false;
24052413
//toolbar.clear();
24062414
toolbar.deactivate(EditorToolbar.EXPORT);

app/src/processing/app/EditorStatus.java

+75-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
4040
//static final int PROMPT = 2;
4141
//static final int EDIT = 3;
4242
static final int EDIT = 2;
43+
static final int PROGRESS = 5;
4344

4445
static final int YES = 1;
4546
static final int NO = 2;
@@ -66,6 +67,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
6667
JButton cancelButton;
6768
JButton okButton;
6869
JTextField editField;
70+
JProgressBar progressBar;
6971

7072
//Thread promptThread;
7173
int response;
@@ -76,16 +78,22 @@ public EditorStatus(Editor editor) {
7678
empty();
7779

7880
if (bgcolor == null) {
79-
bgcolor = new Color[3]; //4];
81+
bgcolor = new Color[6];
8082
bgcolor[0] = Theme.getColor("status.notice.bgcolor");
8183
bgcolor[1] = Theme.getColor("status.error.bgcolor");
8284
bgcolor[2] = Theme.getColor("status.edit.bgcolor");
85+
bgcolor[3] = null;
86+
bgcolor[4] = null;
87+
bgcolor[5] = Theme.getColor("status.notice.bgcolor");
8388

84-
fgcolor = new Color[3]; //4];
89+
fgcolor = new Color[6];
8590
fgcolor[0] = Theme.getColor("status.notice.fgcolor");
8691
fgcolor[1] = Theme.getColor("status.error.fgcolor");
8792
fgcolor[2] = Theme.getColor("status.edit.fgcolor");
88-
}
93+
fgcolor[3] = null;
94+
fgcolor[4] = null;
95+
fgcolor[5] = Theme.getColor("status.notice.fgcolor");
96+
}
8997
}
9098

9199

@@ -163,6 +171,54 @@ public void unedit() {
163171
empty();
164172
}
165173

174+
public void progress(String message)
175+
{
176+
mode = PROGRESS;
177+
this.message = message;
178+
progressBar.setIndeterminate(false);
179+
progressBar.setVisible(true);
180+
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
181+
repaint();
182+
}
183+
184+
185+
public void progressIndeterminate(String message)
186+
{
187+
mode = PROGRESS;
188+
this.message = message;
189+
progressBar.setIndeterminate(true);
190+
progressBar.setValue(50);
191+
progressBar.setVisible(true);
192+
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
193+
repaint();
194+
}
195+
196+
197+
public void progressNotice(String message) {
198+
//mode = NOTICE;
199+
this.message = message;
200+
//update();
201+
repaint();
202+
}
203+
204+
205+
public void unprogress()
206+
{
207+
if (Preferences.getBoolean("editor.beep.compile")) {
208+
Toolkit.getDefaultToolkit().beep();
209+
}
210+
progressBar.setVisible(false);
211+
progressBar.setValue(0);
212+
setCursor(null);
213+
//empty();
214+
}
215+
216+
217+
public void progressUpdate(int value)
218+
{
219+
progressBar.setValue(value);
220+
repaint();
221+
}
166222

167223
/*
168224
public void update() {
@@ -369,6 +425,19 @@ public void keyTyped(KeyEvent event) {
369425
});
370426
add(editField);
371427
editField.setVisible(false);
428+
429+
progressBar = new JProgressBar(JScrollBar.HORIZONTAL);
430+
progressBar.setIndeterminate(false);
431+
if (Base.isMacOS()) {
432+
//progressBar.setBackground(bgcolor[PROGRESS]);
433+
//progressBar.putClientProperty("JProgressBar.style", "circular");
434+
}
435+
progressBar.setValue(0);
436+
progressBar.setBorderPainted(true);
437+
//progressBar.setStringPainted(true);
438+
add(progressBar);
439+
progressBar.setVisible(false);
440+
372441
}
373442
}
374443

@@ -385,11 +454,13 @@ protected void setButtonBounds() {
385454
//noButton.setLocation(noLeft, top);
386455
cancelButton.setLocation(cancelLeft, top);
387456
okButton.setLocation(noLeft, top);
457+
progressBar.setLocation(noLeft, top);
388458

389459
//yesButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
390460
//noButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
391461
cancelButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
392462
okButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
463+
progressBar.setSize(2*Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
393464

394465
// edit field height is awkward, and very different between mac and pc,
395466
// so use at least the preferred height for now.
@@ -398,6 +469,7 @@ protected void setButtonBounds() {
398469
int editTop = (1 + sizeH - editHeight) / 2; // add 1 for ceil
399470
editField.setBounds(yesLeft - Preferences.BUTTON_WIDTH, editTop,
400471
editWidth, editHeight);
472+
progressBar.setBounds(noLeft, editTop, editWidth, editHeight);
401473
}
402474

403475

app/src/processing/app/Sketch.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,7 @@ public String build(String buildPath, boolean verbose)
15071507
throws RunnerException {
15081508

15091509
// run the preprocessor
1510+
editor.status.progressUpdate(20);
15101511
String primaryClassName = preprocess(buildPath);
15111512

15121513
// compile the program. errors will happen as a RunnerException
@@ -1552,6 +1553,7 @@ public boolean exportApplet(String appletPath, boolean usingProgrammer)
15521553
appletFolder.mkdirs();
15531554

15541555
// build the sketch
1556+
editor.status.progressNotice("Compiling sketch...");
15551557
String foundName = build(appletFolder.getPath(), false);
15561558
// (already reported) error during export, exit this function
15571559
if (foundName == null) return false;
@@ -1565,12 +1567,18 @@ public boolean exportApplet(String appletPath, boolean usingProgrammer)
15651567
// return false;
15661568
// }
15671569

1570+
editor.status.progressNotice("Uploading...");
15681571
upload(appletFolder.getPath(), foundName, usingProgrammer);
1569-
1572+
editor.status.progressUpdate(100);
15701573
return true;
15711574
}
15721575

1576+
1577+
public void setCompilingProgress(int percent) {
1578+
editor.status.progressUpdate(percent);
1579+
}
15731580

1581+
15741582
protected void size(String buildPath, String suggestedClassName)
15751583
throws RunnerException {
15761584
long size = 0;

app/src/processing/app/debug/Compiler.java

+9
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public boolean compile(Sketch sketch,
111111

112112
// 0. include paths for core + all libraries
113113

114+
sketch.setCompilingProgress(20);
114115
List includePaths = new ArrayList();
115116
includePaths.add(corePath);
116117
if (pinsPath != null) includePaths.add(pinsPath);
@@ -120,6 +121,7 @@ public boolean compile(Sketch sketch,
120121

121122
// 1. compile the sketch (already in the buildPath)
122123

124+
sketch.setCompilingProgress(30);
123125
objectFiles.addAll(
124126
compileFiles(avrBasePath, buildPath, includePaths,
125127
findFilesInPath(buildPath, "S", false),
@@ -129,6 +131,7 @@ public boolean compile(Sketch sketch,
129131

130132
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
131133

134+
sketch.setCompilingProgress(40);
132135
for (File libraryFolder : sketch.getImportedLibraries()) {
133136
File outputFolder = new File(buildPath, libraryFolder.getName());
134137
File utilityFolder = new File(libraryFolder, "utility");
@@ -156,6 +159,7 @@ public boolean compile(Sketch sketch,
156159
// 3. compile the core, outputting .o files to <buildPath> and then
157160
// collecting them into the core.a library file.
158161

162+
sketch.setCompilingProgress(50);
159163
includePaths.clear();
160164
includePaths.add(corePath); // include path for core only
161165
if (pinsPath != null) includePaths.add(pinsPath);
@@ -180,6 +184,7 @@ public boolean compile(Sketch sketch,
180184

181185
// 4. link it all together into the .elf file
182186

187+
sketch.setCompilingProgress(60);
183188
List baseCommandLinker = new ArrayList(Arrays.asList(new String[] {
184189
avrBasePath + "avr-gcc",
185190
"-Os",
@@ -208,6 +213,7 @@ public boolean compile(Sketch sketch,
208213
List commandObjcopy;
209214

210215
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
216+
sketch.setCompilingProgress(70);
211217
commandObjcopy = new ArrayList(baseCommandObjcopy);
212218
commandObjcopy.add(2, "ihex");
213219
commandObjcopy.set(3, "-j");
@@ -221,13 +227,16 @@ public boolean compile(Sketch sketch,
221227
execAsynchronously(commandObjcopy);
222228

223229
// 6. build the .hex file
230+
sketch.setCompilingProgress(80);
224231
commandObjcopy = new ArrayList(baseCommandObjcopy);
225232
commandObjcopy.add(2, "ihex");
226233
commandObjcopy.add(".eeprom"); // remove eeprom data
227234
commandObjcopy.add(buildPath + File.separator + primaryClassName + ".elf");
228235
commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex");
229236
execAsynchronously(commandObjcopy);
230237

238+
sketch.setCompilingProgress(90);
239+
231240
return true;
232241
}
233242

0 commit comments

Comments
 (0)