From a04cc2d4d2d669dfdbf178da45bad07fa9a60a43 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 25 Nov 2012 00:19:47 +0000 Subject: [PATCH] fix contrib maanger problems with empty list --- .../app/contrib/ContributionListing.java | 22 ++++---- .../contrib/ContributionManagerDialog.java | 24 ++++---- .../app/contrib/FileDownloader.java | 56 +++++++++---------- todo.txt | 30 +++++----- 4 files changed, 68 insertions(+), 64 deletions(-) diff --git a/app/src/processing/app/contrib/ContributionListing.java b/app/src/processing/app/contrib/ContributionListing.java index 493835973..98c9d47ed 100644 --- a/app/src/processing/app/contrib/ContributionListing.java +++ b/app/src/processing/app/contrib/ContributionListing.java @@ -34,15 +34,10 @@ import processing.core.PApplet; public class ContributionListing { ArrayList listeners; - ArrayList advertisedContributions; - Map> librariesByCategory; - ArrayList allContributions; - boolean hasDownloadedLatestList; - ReentrantLock downloadingListingLock; static protected final String validCategories[] = { @@ -204,19 +199,22 @@ public class ContributionListing { } public Set getCategories(Filter filter) { - Set ret = new HashSet(); + Set outgoing = new HashSet(); - Set cats = librariesByCategory.keySet(); - for (String cat : cats) { - for (Contribution contrib : librariesByCategory.get(cat)) { + Set categorySet = librariesByCategory.keySet(); + for (String categoryName : categorySet) { + for (Contribution contrib : librariesByCategory.get(categoryName)) { if (filter.matches(contrib)) { - ret.add(cat); + // TODO still not sure why category would be coming back null [fry] + // http://code.google.com/p/processing/issues/detail?id=1387 + if (categoryName != null && categoryName.trim().length() != 0) { + outgoing.add(categoryName); + } break; } } } - - return ret; + return outgoing; } public List getAllContributions() { diff --git a/app/src/processing/app/contrib/ContributionManagerDialog.java b/app/src/processing/app/contrib/ContributionManagerDialog.java index b9bf5ec0c..1a9e34d4d 100644 --- a/app/src/processing/app/contrib/ContributionManagerDialog.java +++ b/app/src/processing/app/contrib/ContributionManagerDialog.java @@ -249,16 +249,20 @@ public class ContributionManagerDialog { } private void updateCategoryChooser() { - if (categoryChooser == null) - return; - - ArrayList categories; - categoryChooser.removeAllItems(); - categories = new ArrayList(contribListing.getCategories(permaFilter)); - Collections.sort(categories); - categories.add(0, ContributionManagerDialog.ANY_CATEGORY); - for (String s : categories) { - categoryChooser.addItem(s); + if (categoryChooser != null) { + ArrayList categories; + categoryChooser.removeAllItems(); + categories = new ArrayList(contribListing.getCategories(permaFilter)); +// for (int i = 0; i < categories.size(); i++) { +// System.out.println(i + " category: " + categories.get(i)); +// } + Collections.sort(categories); +// categories.add(0, ContributionManagerDialog.ANY_CATEGORY); + categoryChooser.addItem(ContributionManagerDialog.ANY_CATEGORY); + for (String s : categories) { + categoryChooser.addItem(s); + } + categoryChooser.setEnabled(categories.size() != 0); } } diff --git a/app/src/processing/app/contrib/FileDownloader.java b/app/src/processing/app/contrib/FileDownloader.java index 567cce9af..005780514 100644 --- a/app/src/processing/app/contrib/FileDownloader.java +++ b/app/src/processing/app/contrib/FileDownloader.java @@ -34,52 +34,50 @@ import java.net.URLConnection; public class FileDownloader { /** - * Blocks until the file is downloaded or an error occurs. Returns true if the - * file was successfully downloaded, false otherwise + * Blocks until the file is downloaded or an error occurs. + * Returns true if the file was successfully downloaded, false otherwise. * * @param source - * the URL of the file to donwload + * the URL of the file to download * @param dest * the file on the local system where the file will be written. This * must be a file (not a directory), and must already exist. - * @param progressMonitor + * @param progress * @throws FileNotFoundException * if an error occurred downloading the file */ static public void downloadFile(URL source, File dest, - ProgressMonitor progressMonitor) { - + ProgressMonitor progress) { try { - URLConnection urlConn = source.openConnection(); - urlConn.setConnectTimeout(1000); - urlConn.setReadTimeout(5000); +// System.out.println("downloading file " + source); + URLConnection conn = source.openConnection(); + conn.setConnectTimeout(1000); + conn.setReadTimeout(5000); - // String expectedType1 = "application/x-zip-compressed"; - // String expectedType2 = "application/zip"; - // String type = urlConn.getContentType(); - // if (expectedType1.equals(type) || expectedType2.equals(type)) { - // } + // TODO this is often -1, may need to set progress to indeterminate + int fileSize = conn.getContentLength(); +// System.out.println("file size is " + fileSize); + progress.startTask("Downloading", fileSize); - int fileSize = urlConn.getContentLength(); - progressMonitor.startTask("Downloading", fileSize); - - InputStream in = urlConn.getInputStream(); + InputStream in = conn.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); + byte[] b = new byte[8192]; + int amount; + int total = 0; + while (!progress.isCanceled() && (amount = in.read(b)) != -1) { + out.write(b, 0, amount); + total += amount; + progress.setProgress(total); } + out.flush(); out.close(); + } catch (IOException ioe) { - progressMonitor.error(ioe); + progress.error(ioe); + ioe.printStackTrace(); } - - progressMonitor.finished(); + progress.finished(); +// System.out.println("done downloading"); } - } diff --git a/todo.txt b/todo.txt index 6d7a57999..afaac7a9e 100644 --- a/todo.txt +++ b/todo.txt @@ -25,18 +25,22 @@ X Sketch that exported to Linux doesn't get the command line arguments X http://code.google.com/p/processing/issues/detail?id=1359 X "electricScroll" feature causing weird jumps when double-clicking X http://code.google.com/p/processing/issues/detail?id=1055 -_ fix the debug stuff before shipping this out -_ DebugMode throwing exception about breakpoints when trying to save - -earlier -X The sketch name can't begin with '_' (underscore) -X http://code.google.com/p/processing/issues/detail?id=859 - +X crash during library download was causing empty library list +X http://code.google.com/p/processing/issues/detail?id=1093 X clientEvent() called even w/o data from server (with fix) X http://code.google.com/p/processing/issues/detail?id=189 X check on adding ip() method X http://code.google.com/p/processing/issues/detail?id=1228 + +_ fix the debug stuff before shipping this out +_ DebugMode throwing exception about breakpoints when trying to save + + +earlier +X The sketch name can't begin with '_' (underscore) +X http://code.google.com/p/processing/issues/detail?id=859 + _ if RuntimeException thrown, needs to check if it's a wrapped exception _ for instance, if there's a crash inside makeGraphics() @@ -78,15 +82,12 @@ _ change cmd line for OS X to use symlink? _ otherwise updates are going to require reinstall.. _ or that it's gonna need to parse and say "update command line?" +_ TextAreaDefaults - is editable in use? + 2.0 FINAL / library/tool/mode manager cleanup -_ a couple notes +_ make already installed libraries distinguishable in the list _ http://code.google.com/p/processing/issues/detail?id=1212 -_ complaint that dropdown list is too small -_ http://code.google.com/p/processing/issues/detail?id=1093 -_ TextAreaDefaults -_ is editable in use? -_ what's electricScroll? _ excessive CPU usage of PDE after using library manager _ http://code.google.com/p/processing/issues/detail?id=1036 _ confirmed to still be a problem with b5/6 @@ -99,6 +100,9 @@ _ list in the PDE would be updated automatically by querying a web service _ list on the website would be generated using the same web service _ All I would need to do is update web/contrib_generate/sources.conf _ and the rest would happen automatically. +_ alternating blue/white backgrounds aren't updated after changing filter +_ using "Add Library" requires restart of Processing before lib recognized +_ http://code.google.com/p/processing/issues/detail?id=1387 2.0 FINAL / new interface