mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Better handling of contribution manager when disconnected from network.
Removed pop-ups, changed when file is downloaded, added boolean to indicate when the advertised list is actually downloaded.
This commit is contained in:
@@ -45,25 +45,28 @@ public class ContributionListing {
|
||||
|
||||
ArrayList<Contribution> allContributions;
|
||||
|
||||
private Comparator<Contribution> contribComparator;
|
||||
boolean hasDownloadedLatestList;
|
||||
|
||||
static Comparator<Contribution> contribComparator = new Comparator<Contribution>() {
|
||||
public int compare(Contribution o1, Contribution o2) {
|
||||
return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
|
||||
}
|
||||
};
|
||||
|
||||
public ContributionListing() {
|
||||
listeners = new ArrayList<ContributionChangeListener>();
|
||||
advertisedContributions = new ArrayList<AdvertisedContribution>();
|
||||
librariesByCategory = new HashMap<String, List<Contribution>>();
|
||||
allContributions = new ArrayList<Contribution>();
|
||||
|
||||
contribComparator = new Comparator<Contribution>() {
|
||||
public int compare(Contribution o1, Contribution o2) {
|
||||
return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
|
||||
}
|
||||
};
|
||||
hasDownloadedLatestList = false;
|
||||
}
|
||||
|
||||
|
||||
public void setAdvertisedList(File xmlFile) {
|
||||
|
||||
ContributionXmlParser xmlParser = new ContributionXmlParser(xmlFile);
|
||||
advertisedContributions = xmlParser.getLibraries();
|
||||
advertisedContributions.clear();
|
||||
advertisedContributions.addAll(xmlParser.getLibraries());
|
||||
for (Contribution contribution : advertisedContributions) {
|
||||
addContribution(contribution);
|
||||
}
|
||||
@@ -325,6 +328,10 @@ public class ContributionListing {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasDownloadedLatestList() {
|
||||
return hasDownloadedLatestList;
|
||||
}
|
||||
|
||||
public static interface ContributionChangeListener {
|
||||
|
||||
@@ -377,6 +384,7 @@ public class ContributionListing {
|
||||
|
||||
File xmlFile = downloader.getFile();
|
||||
if (xmlFile != null) {
|
||||
hasDownloadedLatestList = true;
|
||||
setAdvertisedList(xmlFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,25 +94,27 @@ public class ContributionManager {
|
||||
|
||||
contributionListPanel = new ContributionListPanel(this);
|
||||
contribListing.addContributionListener(contributionListPanel);
|
||||
|
||||
JProgressBar progressBar = contributionListPanel.getSetupProgressBar();
|
||||
contribListing.getAdvertisedContributions(new JProgressMonitor(progressBar) {
|
||||
|
||||
@Override
|
||||
public void finishedAction() {
|
||||
synchronized (contribListing) {
|
||||
updateContributionListing();
|
||||
updateCategoryChooser();
|
||||
|
||||
progressBar.setVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void showFrame(Editor editor) {
|
||||
this.editor = editor;
|
||||
|
||||
if (!contribListing.hasDownloadedLatestList()) {
|
||||
JProgressBar progressBar = contributionListPanel.getSetupProgressBar();
|
||||
contribListing.getAdvertisedContributions(new JProgressMonitor(progressBar) {
|
||||
|
||||
@Override
|
||||
public void finishedAction() {
|
||||
synchronized (contribListing) {
|
||||
updateContributionListing();
|
||||
updateCategoryChooser();
|
||||
|
||||
progressBar.setVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateContributionListing();
|
||||
|
||||
if (dialog == null) {
|
||||
|
||||
@@ -73,17 +73,8 @@ public class FileDownloader implements Runnable {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
if (downloadFile(url, dest, progressMonitor)) {
|
||||
libFile = dest;
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Base.showWarning("Trouble downloading file",
|
||||
"The file was not found on the server.\n", null);
|
||||
} catch (IOException e) {
|
||||
Base.showWarning("Trouble downloading file",
|
||||
"An error occured while downloading the file:\n"
|
||||
+ e.getMessage(), e);
|
||||
if (downloadFile(url, dest, progressMonitor)) {
|
||||
libFile = dest;
|
||||
}
|
||||
|
||||
if (post != null) {
|
||||
@@ -104,37 +95,43 @@ public class FileDownloader implements Runnable {
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
protected boolean downloadFile(URL source, File dest,
|
||||
ProgressMonitor progressMonitor)
|
||||
throws IOException, FileNotFoundException {
|
||||
|
||||
URLConnection urlConn = source.openConnection();
|
||||
urlConn.setConnectTimeout(1000);
|
||||
urlConn.setReadTimeout(5000);
|
||||
|
||||
// String expectedType1 = "application/x-zip-compressed";
|
||||
// String expectedType2 = "application/zip";
|
||||
// String type = urlConn.getContentType();
|
||||
// if (expectedType1.equals(type) || expectedType2.equals(type)) {
|
||||
// }
|
||||
|
||||
int fileSize = urlConn.getContentLength();
|
||||
progressMonitor.startTask("Downloading", fileSize);
|
||||
|
||||
InputStream in = urlConn.getInputStream();
|
||||
FileOutputStream out = new FileOutputStream(dest);
|
||||
|
||||
byte[] b = new byte[256];
|
||||
int bytesDownloaded = 0, len;
|
||||
while (!progressMonitor.isCanceled() && (len = in.read(b)) != -1) {
|
||||
out.write(b, 0, len);
|
||||
bytesDownloaded += len;
|
||||
|
||||
progressMonitor.setProgress(bytesDownloaded);
|
||||
}
|
||||
out.close();
|
||||
|
||||
if (!progressMonitor.isCanceled()) {
|
||||
return true;
|
||||
ProgressMonitor progressMonitor) {
|
||||
try {
|
||||
URLConnection urlConn = source.openConnection();
|
||||
urlConn.setConnectTimeout(1000);
|
||||
urlConn.setReadTimeout(5000);
|
||||
|
||||
// String expectedType1 = "application/x-zip-compressed";
|
||||
// String expectedType2 = "application/zip";
|
||||
// String type = urlConn.getContentType();
|
||||
// if (expectedType1.equals(type) || expectedType2.equals(type)) {
|
||||
// }
|
||||
|
||||
int fileSize = urlConn.getContentLength();
|
||||
progressMonitor.startTask("Downloading", fileSize);
|
||||
|
||||
InputStream in = urlConn.getInputStream();
|
||||
FileOutputStream out = new FileOutputStream(dest);
|
||||
|
||||
byte[] b = new byte[256];
|
||||
int bytesDownloaded = 0, len;
|
||||
while (!progressMonitor.isCanceled() && (len = in.read(b)) != -1) {
|
||||
out.write(b, 0, len);
|
||||
bytesDownloaded += len;
|
||||
|
||||
progressMonitor.setProgress(bytesDownloaded);
|
||||
}
|
||||
out.close();
|
||||
|
||||
if (!progressMonitor.isCanceled()) {
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("An error occured while downloading the file "
|
||||
+ source.toExternalForm());
|
||||
// Base.showWarning("Trouble downloading file",
|
||||
// "An error occured while downloading the file:\n"
|
||||
// + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user