mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
remove extra ContribProgressMonitor class
This commit is contained in:
@@ -480,7 +480,7 @@ public class Base {
|
||||
new UpdateCheck(this);
|
||||
|
||||
ContributionListing cl = ContributionListing.getInstance();
|
||||
cl.downloadAvailableList(this, new ContribProgressMonitor() { });
|
||||
cl.downloadAvailableList(this, new ContribProgressBar(null));
|
||||
long t9 = System.currentTimeMillis();
|
||||
// System.out.println("base took " + (t2-t1) + " " + (t3-t2) + " " + (t4-t3) +
|
||||
// " " + (t5-t4) + " t6-t5=" + (t6-t5) + " " + (t7-t6) + " handleNew=" + (t8-t7) + " " + (t9-t8) + " ms");
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2013-20 The Processing Foundation
|
||||
Copyright (c) 2013-22 The Processing Foundation
|
||||
Copyright (c) 2011-12 Ben Fry and Casey Reas
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
@@ -31,28 +31,51 @@ import javax.swing.JProgressBar;
|
||||
// This code seems like it's adapted from old example code found on the web.
|
||||
// https://github.com/processing/processing4/issues/351
|
||||
|
||||
abstract class ContribProgressBar extends ContribProgressMonitor {
|
||||
public class ContribProgressBar {
|
||||
static private final int UNKNOWN = -1;
|
||||
|
||||
JProgressBar progressBar;
|
||||
|
||||
int progress = 0;
|
||||
int max;
|
||||
|
||||
boolean finished = false;
|
||||
boolean canceled = false;
|
||||
boolean error = false;
|
||||
Exception exception;
|
||||
|
||||
|
||||
public ContribProgressBar(JProgressBar progressBar) {
|
||||
this.progressBar = progressBar;
|
||||
}
|
||||
|
||||
|
||||
public void startTask(String name) {
|
||||
startTask(name, UNKNOWN);
|
||||
}
|
||||
|
||||
|
||||
public void startTask(String name, int maxValue) {
|
||||
finished = false;
|
||||
progressBar.setString(name);
|
||||
progressBar.setIndeterminate(maxValue == UNKNOWN);
|
||||
progressBar.setMaximum(maxValue);
|
||||
|
||||
if (progressBar != null) {
|
||||
progressBar.setString(name);
|
||||
progressBar.setIndeterminate(maxValue == UNKNOWN);
|
||||
progressBar.setMaximum(maxValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setProgress(int value) {
|
||||
super.setProgress(value);
|
||||
progressBar.setValue(value);
|
||||
progress = value;
|
||||
if (progressBar != null) {
|
||||
progressBar.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public final void finished() {
|
||||
super.finished();
|
||||
finished = true;
|
||||
try {
|
||||
EventQueue.invokeAndWait(this::finishedAction);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -67,11 +90,17 @@ abstract class ContribProgressBar extends ContribProgressMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void finishedAction();
|
||||
|
||||
@Override
|
||||
public void finishedAction() { }
|
||||
|
||||
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
|
||||
public final void cancel() {
|
||||
super.cancel();
|
||||
canceled = true;
|
||||
try {
|
||||
EventQueue.invokeAndWait(this::cancelAction);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -86,5 +115,17 @@ abstract class ContribProgressBar extends ContribProgressMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void cancelAction() { }
|
||||
|
||||
|
||||
public boolean isError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
public void error(Exception e) {
|
||||
error = true;
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2013-15 The Processing Foundation
|
||||
Copyright (c) 2011-12 Ben Fry and Casey Reas
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
package processing.app.contrib;
|
||||
|
||||
|
||||
// I suspect this code can mostly be replaced with built-in Swing functions.
|
||||
// This code seems like it's adapted from old example code found on the web.
|
||||
// https://github.com/processing/processing4/issues/351
|
||||
|
||||
public abstract class ContribProgressMonitor {
|
||||
static final int UNKNOWN = -1;
|
||||
boolean canceled = false;
|
||||
boolean error = false;
|
||||
boolean finished = false;
|
||||
Exception exception;
|
||||
int max;
|
||||
int progress = 0;
|
||||
|
||||
public void startTask(String name, int maxValue) {
|
||||
}
|
||||
|
||||
public void setProgress(int value) {
|
||||
progress = value;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public boolean isCanceled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
canceled = true;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public Exception getException() {
|
||||
return exception;
|
||||
}
|
||||
|
||||
public void error(Exception e) {
|
||||
error = true;
|
||||
exception = e;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public void finished() {
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ public class ContributionListing {
|
||||
* Only one instance will run at a time.
|
||||
*/
|
||||
public void downloadAvailableList(final Base base,
|
||||
final ContribProgressMonitor progress) {
|
||||
final ContribProgressBar progress) {
|
||||
|
||||
// TODO: replace with SwingWorker [jv]
|
||||
new Thread(() -> {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ContributionManager {
|
||||
* @return true if the file was successfully downloaded, false otherwise.
|
||||
*/
|
||||
static boolean download(URL source, byte[] post,
|
||||
File dest, ContribProgressMonitor progress) {
|
||||
File dest, ContribProgressBar progress) {
|
||||
boolean success = false;
|
||||
try {
|
||||
HttpURLConnection conn = (HttpURLConnection) source.openConnection();
|
||||
@@ -154,7 +154,7 @@ public class ContributionManager {
|
||||
download(url, null, contribZip, downloadProgress);
|
||||
|
||||
if (!downloadProgress.isCanceled() && !downloadProgress.isError()) {
|
||||
installProgress.startTask(Language.text("contrib.progress.installing"), ContribProgressMonitor.UNKNOWN);
|
||||
installProgress.startTask(Language.text("contrib.progress.installing"));
|
||||
final LocalContribution contribution =
|
||||
ad.install(base, contribZip, false, status);
|
||||
|
||||
|
||||
@@ -384,7 +384,7 @@ public abstract class LocalContribution extends Contribution {
|
||||
* Non-blocking call to remove a contribution in a new thread.
|
||||
*/
|
||||
void removeContribution(final Base base,
|
||||
final ContribProgressMonitor pm,
|
||||
final ContribProgressBar pm,
|
||||
final StatusPanel status) {
|
||||
// TODO: replace with SwingWorker [jv]
|
||||
new Thread(() -> remove(base, pm, status, ContributionListing.getInstance()), "Contribution Uninstaller").start();
|
||||
@@ -392,10 +392,10 @@ public abstract class LocalContribution extends Contribution {
|
||||
|
||||
|
||||
void remove(final Base base,
|
||||
final ContribProgressMonitor pm,
|
||||
final ContribProgressBar pm,
|
||||
final StatusPanel status,
|
||||
final ContributionListing contribListing) {
|
||||
pm.startTask("Removing", ContribProgressMonitor.UNKNOWN);
|
||||
pm.startTask("Removing");
|
||||
|
||||
boolean doBackup = Preferences.getBoolean("contribution.backup.on_remove");
|
||||
if (getType() == ContributionType.MODE) {
|
||||
|
||||
@@ -183,7 +183,7 @@ public class ManagerFrame {
|
||||
//as there is only one instance of contribListing and it should be present in this class
|
||||
final ContributionTab activeTab = getActiveTab();
|
||||
|
||||
ContribProgressMonitor progress =
|
||||
ContribProgressBar progress =
|
||||
new ContribProgressBar(activeTab.progressBar) {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -159,11 +159,6 @@ class StatusPanelDetail {
|
||||
}
|
||||
|
||||
|
||||
// private boolean isSelected() {
|
||||
// return listPanel.getSelectedPanel() == this;
|
||||
// }
|
||||
|
||||
|
||||
protected void install() {
|
||||
clearStatusMessage();
|
||||
installInProgress = true;
|
||||
@@ -198,8 +193,8 @@ class StatusPanelDetail {
|
||||
progressBar.setVisible(true);
|
||||
progressBar.setIndeterminate(true);
|
||||
|
||||
ContribProgressBar monitor = new RemoveProgressBar(progressBar);
|
||||
getLocalContrib().removeContribution(getBase(), monitor, getStatusPanel());
|
||||
ContribProgressBar progress = new RemoveProgressBar(progressBar);
|
||||
getLocalContrib().removeContribution(getBase(), progress, getStatusPanel());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,8 +211,7 @@ class StatusPanelDetail {
|
||||
resetProgressBar();
|
||||
AvailableContribution ad =
|
||||
contribListing.getAvailableContribution(contrib);
|
||||
String url = ad.link;
|
||||
installContribution(ad, url);
|
||||
installContribution(ad, ad.link);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
2
todo.txt
2
todo.txt
@@ -18,6 +18,8 @@ X implement updateTheme()
|
||||
X remove the extra 2-pixel line at the top
|
||||
o currently uses prepareGraphics(), do we need to remove that?
|
||||
X looks like nope, that was sorted out separately
|
||||
X remove extra ContribProgressMonitor class
|
||||
_ removing the current Mode will cause an exception when opening a sketch
|
||||
_ allow update of the current Mode
|
||||
|
||||
_ an incompatible Mode prevents the PDE from quitting after last window is closed
|
||||
|
||||
Reference in New Issue
Block a user