diff --git a/app/src/processing/app/Contribution.java b/app/src/processing/app/Contribution.java deleted file mode 100644 index 13d31b1e7..000000000 --- a/app/src/processing/app/Contribution.java +++ /dev/null @@ -1,92 +0,0 @@ -package processing.app; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import processing.app.Contribution.ContributionInfo.Author; - -public abstract class Contribution { - - abstract ContributionInfo getInfo(); - - abstract File getFolder(); - - public static void readProperties(HashMap propTable, - ContributionInfo info) { - - info.category = "Unknown"; - - info.name = propTable.get("name"); - - String authors = propTable.get("authorList"); - info.authorList = new ArrayList(); - if (authors != null) { - String[] authorNames = authors.split(";"); - for (String authorName : authorNames) { - Author author = new Author(); - author.name = authorName.trim(); - - info.authorList.add(author); - } - } - - info.url = propTable.get("url"); - info.sentence = propTable.get("sentence"); - info.paragraph = propTable.get("paragraph"); - - try { - info.version = Integer.parseInt(propTable.get("version")); - } catch (NumberFormatException e) { - } - info.prettyVersion = propTable.get("prettyVersion"); - - } - - public static abstract class ContributionInfo implements Comparable { - - protected String category; // "Sound" - protected String name; // "pdf" or "PDF Export" - protected List authorList; // Ben Fry - protected String url; // http://processing.org - protected String sentence; // Write graphics to PDF files. - protected String paragraph; // - protected int version; // 102 - protected int latestVersion; // 103 - protected String prettyVersion; // "1.0.2" - - protected String link = ""; - - public static class Author { - public String name; - - public String url; - - } - - public int compareTo(ContributionInfo o) { - return name.toLowerCase().compareTo(o.name.toLowerCase()); - } - - public abstract ContributionType getType(); - - public static enum ContributionType { - LIBRARY, LIBRARY_COMPILATION, TOOL, MODE; - } - - public abstract boolean isInstalled(); - - /** - * @return the contribution associated with this data, or null if it is not - * installed - */ - public abstract Contribution getContribution(); - - public boolean hasUpdates() { - return latestVersion > version && link != null; - } - - } - -} diff --git a/app/src/processing/app/ContributionListPanel.java b/app/src/processing/app/ContributionListPanel.java index 7a08b33ac..9d5757456 100644 --- a/app/src/processing/app/ContributionListPanel.java +++ b/app/src/processing/app/ContributionListPanel.java @@ -36,10 +36,8 @@ import java.awt.event.*; import java.awt.*; import java.net.*; -import processing.app.Contribution.ContributionInfo; -import processing.app.Contribution.ContributionInfo.Author; -import processing.app.Contribution.ContributionInfo.ContributionType; import processing.app.ContributionListing.ContributionChangeListener; +import processing.app.contribution.*; public class ContributionListPanel extends JPanel implements Scrollable, ContributionChangeListener { @@ -54,7 +52,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib JProgressBar setupProgressBar; - TreeMap contributionPanelsByInfo; + TreeMap contributionPanelsByInfo; private static HyperlinkListener nullHyperlinkListener = new HyperlinkListener() { @@ -83,7 +81,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib setBackground(UIManager.getColor("List.background")); } - contributionPanelsByInfo = new TreeMap(); + contributionPanelsByInfo = new TreeMap(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; @@ -98,7 +96,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } - public void contributionAdded(ContributionInfo contributionInfo) { + public void contributionAdded(Contribution contributionInfo) { setupProgressBar.setVisible(false); @@ -114,7 +112,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib if (newPanel != null) { - newPanel.setContributionInfo(contributionInfo); + newPanel.setContribution(contributionInfo); add(newPanel); updatePanelOrdering(); @@ -124,7 +122,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib private void updatePanelOrdering() { int row = 0; - for (Entry entry : contributionPanelsByInfo.entrySet()) { + for (Entry entry : contributionPanelsByInfo.entrySet()) { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; @@ -135,7 +133,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } } - public void contributionRemoved(ContributionInfo contributionInfo) { + public void contributionRemoved(Contribution contributionInfo) { synchronized (contributionPanelsByInfo) { ContributionPanel panel = contributionPanelsByInfo.get(contributionInfo); @@ -147,13 +145,13 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib updateUI(); } - public void contributionChanged(ContributionInfo oldInfo, ContributionInfo newInfo) { + public void contributionChanged(Contribution oldInfo, Contribution newInfo) { synchronized (contributionPanelsByInfo) { ContributionPanel panel = contributionPanelsByInfo.get(oldInfo); contributionPanelsByInfo.remove(oldInfo); - panel.setContributionInfo(newInfo); + panel.setContribution(newInfo); contributionPanelsByInfo.put(newInfo, panel); add(panel); @@ -162,13 +160,13 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib updatePanelOrdering(); } - public void filterLibraries(List filteredContributions) { + public void filterLibraries(List filteredContributions) { synchronized (contributionPanelsByInfo) { - Set hiddenPanels = new TreeSet(contributionPanelsByInfo.keySet()); + Set hiddenPanels = new TreeSet(contributionPanelsByInfo.keySet()); - for (ContributionInfo info : filteredContributions) { + for (Contribution info : filteredContributions) { ContributionPanel panel = contributionPanelsByInfo.get(info); if (panel != null) { @@ -177,7 +175,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } } - for (ContributionInfo info : hiddenPanels) { + for (Contribution info : hiddenPanels) { ContributionPanel panel = contributionPanelsByInfo.get(info); if (panel != null) { panel.setVisible(false); @@ -211,7 +209,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib int count = 0; synchronized (contributionPanelsByInfo) { - for (Entry entry : contributionPanelsByInfo.entrySet()) { + for (Entry entry : contributionPanelsByInfo.entrySet()) { ContributionPanel panel = entry.getValue(); if (panel.isVisible() && panel.isSelected()) { @@ -335,9 +333,9 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib private static final int BUTTON_WIDTH = 100; - /** Should only be set through setContributionInfo(), otherwise UI components + /** Should only be set through setContribution(), otherwise UI components * will not be updated. */ - ContributionInfo info; + Contribution info; boolean alreadySelected; @@ -390,26 +388,29 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib installActionListener = new ActionListener() { public void actionPerformed(ActionEvent arg) { - installContribution(info, info.link); + if (info instanceof AdvertisedContribution) { + installContribution((AdvertisedContribution) info); + } } }; removeActionListener = new ActionListener() { public void actionPerformed(ActionEvent arg) { - updateButton.setEnabled(false); - installOrRemoveButton.setEnabled(false); - - installProgressBar.setVisible(true); - contributionManager.removeContribution(info.getContribution(), - new JProgressMonitor(installProgressBar) { + if (info.isInstalled() && info instanceof InstalledContribution) { + updateButton.setEnabled(false); + installOrRemoveButton.setEnabled(false); - public void finishedAction() { - // Finished uninstalling the library - resetInstallProgressBarState(); - installOrRemoveButton.setEnabled(true); - } - }); - + installProgressBar.setVisible(true); + contributionManager.removeContribution((InstalledContribution) info, + new JProgressMonitor(installProgressBar) { + + public void finishedAction() { + // Finished uninstalling the library + resetInstallProgressBarState(); + installOrRemoveButton.setEnabled(true); + } + }); + } } }; @@ -551,7 +552,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib public void actionPerformed(ActionEvent e) { updateButton.setEnabled(false); - installContribution(info, info.link); + // XXX: There is a bug here. The advertised library will be 'replaced' instead + installContribution((AdvertisedContribution) contributionManager.contributionListing.getAdvertisedContribution(info)); } }); descriptionPanel.add(updateButton, c); @@ -619,7 +621,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } } - public void setContributionInfo(ContributionInfo info) { + public void setContribution(Contribution info) { this.info = info; @@ -627,28 +629,28 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib StringBuilder nameText = new StringBuilder(); nameText.append(""); - if (info.url == null) { - nameText.append(info.name); + if (info.getUrl() == null) { + nameText.append(info.getName()); } else { - nameText.append("" + info.name + ""); + nameText.append("" + info.getName() + ""); } nameText.append(""); - nameText.append(createAuthorString(info.authorList)); + nameText.append(createAuthorString(info.getAuthorList())); nameText.append(""); headerText.setText(nameText.toString()); - categoryLabel.setText("[" + info.category + "]"); + categoryLabel.setText("[" + info.getCategory() + "]"); StringBuilder description = new StringBuilder(); description.append(""); - if (info.sentence != null) - description.append(info.sentence); + if (info.getSentence() != null) + description.append(info.getSentence()); description.append(""); descriptionText.setText(description.toString()); setAlignment(descriptionText, StyleConstants.ALIGN_JUSTIFIED); - if (info.hasUpdates()) { + if (contributionManager.hasUpdates(info)) { StringBuilder versionText = new StringBuilder(); versionText.append(""); versionText.append("New version available!"); @@ -673,7 +675,9 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } - private void installContribution(ContributionInfo info, String url) { + private void installContribution(AdvertisedContribution info) { + + String url = info.link; installOrRemoveButton.setEnabled(false); try { @@ -784,7 +788,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib // hyperlink, it will be opened as the mouse is released. enableHyperlinks = alreadySelected; - updateButton.setVisible(isSelected() && info.hasUpdates()); + updateButton.setVisible(isSelected() && contributionManager.hasUpdates(info)); installOrRemoveButton.setVisible(isSelected()); for (JTextPane textPane : htmlPanes) { diff --git a/app/src/processing/app/ContributionListing.java b/app/src/processing/app/ContributionListing.java index 80702e832..495562918 100644 --- a/app/src/processing/app/ContributionListing.java +++ b/app/src/processing/app/ContributionListing.java @@ -32,28 +32,24 @@ import javax.xml.parsers.*; import org.xml.sax.*; import org.xml.sax.helpers.*; -import processing.app.Contribution.ContributionInfo; -import processing.app.Contribution.ContributionInfo.Author; -import processing.app.Contribution.ContributionInfo.ContributionType; -import processing.app.Library.LibraryInfo; -import processing.app.LibraryCompilation.LibraryCompilationInfo; -import processing.app.ToolContribution.ToolInfo; +import processing.app.contribution.*; +import processing.app.contribution.Contribution.Type; public class ContributionListing { ArrayList listeners; - ArrayList advertisedContributions; + ArrayList advertisedContributions; - Map> librariesByCategory; + Map> librariesByCategory; - ArrayList allLibraries; + ArrayList allLibraries; public ContributionListing() { listeners = new ArrayList(); - librariesByCategory = new HashMap>(); - allLibraries = new ArrayList(); + librariesByCategory = new HashMap>(); + allLibraries = new ArrayList(); } @@ -61,7 +57,7 @@ public class ContributionListing { ContributionXmlParser xmlParser = new ContributionXmlParser(xmlFile); advertisedContributions = xmlParser.getLibraries(); - for (ContributionInfo info : advertisedContributions) { + for (Contribution info : advertisedContributions) { addContribution(info); } @@ -69,40 +65,18 @@ public class ContributionListing { } - /** - * If a the given contribution has a version of it which is advertised. This - * method sets the latestVersion and category for the contribution. - */ - public void getInformationFromAdvertised(ContributionInfo contribution) { - - ContributionInfo advertised = getAdvertisedContribution(contribution.name, - contribution.getType()); - - if (advertised != null) { - // Merge information from the advertised and local versions. - if (advertised.category != null) { - contribution.category = advertised.category; - } - if (advertised.link != null) { - contribution.link = advertised.link; - } - contribution.latestVersion = advertised.version; - } - } - /** * Adds the installed libraries to the listing of libraries, replacing any * pre-existing libraries by the same name as one in the list. */ - public void updateInstalledList(List installedContributions) { + public void updateInstalledList(List installedContributions) { - for (ContributionInfo contribution : installedContributions) { - - getInformationFromAdvertised(contribution); + for (Contribution contribution : installedContributions) { boolean found = false; - for (ContributionInfo existing : allLibraries) { - if (existing.name.equals(contribution.name) && existing.getType() == contribution.getType()) { + for (Contribution existing : allLibraries) { + if (existing.getName().equals(contribution.getName()) + && existing.getType() == contribution.getType()) { replaceContribution(existing, contribution); found = true; break; @@ -117,14 +91,14 @@ public class ContributionListing { } - public void replaceContribution(ContributionInfo oldLib, ContributionInfo newLib) { + public void replaceContribution(Contribution oldLib, Contribution newLib) { if (oldLib == null || newLib == null) { return; } - if (librariesByCategory.containsKey(oldLib.category)) { - List list = librariesByCategory.get(oldLib.category); + if (librariesByCategory.containsKey(oldLib.getCategory())) { + List list = librariesByCategory.get(oldLib.getCategory()); for (int i = 0; i < list.size(); i++) { if (list.get(i) == oldLib) { @@ -142,17 +116,17 @@ public class ContributionListing { notifyChange(oldLib, newLib); } - public void addContribution(ContributionInfo info) { + public void addContribution(Contribution info) { - if (librariesByCategory.containsKey(info.category)) { - List list = librariesByCategory.get(info.category); + if (librariesByCategory.containsKey(info.getCategory())) { + List list = librariesByCategory.get(info.getCategory()); list.add(info); Collections.sort(list); } else { - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList(); list.add(info); - librariesByCategory.put(info.category, list); + librariesByCategory.put(info.getCategory(), list); } allLibraries.add(info); @@ -161,22 +135,27 @@ public class ContributionListing { Collections.sort(allLibraries); } - public void removeContribution(ContributionInfo info) { - if (librariesByCategory.containsKey(info.category)) { - librariesByCategory.get(info.category).remove(info); + public void removeContribution(Contribution info) { + if (librariesByCategory.containsKey(info.getCategory())) { + librariesByCategory.get(info.getCategory()).remove(info); } allLibraries.remove(info); notifyRemove(info); } - public ContributionInfo getAdvertisedContribution(String contributionName, - ContributionType contributionType) { + // XXX: Could probably make this return AdvertisedContribution + public Contribution getAdvertisedContribution(Contribution info) { + return getAdvertisedContribution(info.getName(), info.getType()); + } + + public Contribution getAdvertisedContribution(String contributionName, + Contribution.Type contributionType) { - for (ContributionInfo advertised : advertisedContributions) { + for (Contribution advertised : advertisedContributions) { if (advertised.getType() == contributionType - && advertised.name.equals(contributionName)) { + && advertised.getName().equals(contributionName)) { return advertised; } @@ -190,24 +169,25 @@ public class ContributionListing { return librariesByCategory.keySet(); } - public List getAllContributions() { - return new ArrayList(allLibraries); + public List getAllContributions() { + return new ArrayList(allLibraries); } - public List getLibararies(String category) { - ArrayList libinfos = new ArrayList(librariesByCategory.get(category)); + public List getLibararies(String category) { + ArrayList libinfos = + new ArrayList(librariesByCategory.get(category)); Collections.sort(libinfos); return libinfos; } - public List getFilteredLibraryList(String category, List filters) { - ArrayList filteredList = new ArrayList(allLibraries); + public List getFilteredLibraryList(String category, List filters) { + ArrayList filteredList = new ArrayList(allLibraries); - Iterator it = filteredList.iterator(); + Iterator it = filteredList.iterator(); while (it.hasNext()) { - ContributionInfo libInfo = it.next(); + Contribution libInfo = it.next(); - if (category != null && !category.equals(libInfo.category)) { + if (category != null && !category.equals(libInfo.getCategory())) { it.remove(); } else { for (String filter : filters) { @@ -223,11 +203,11 @@ public class ContributionListing { return filteredList; } - private boolean matches(ContributionInfo info, String filter) { + private boolean matches(Contribution info, String filter) { // Maybe this can be fancy some other time if (filter.equals("has:update") || filter.equals("has:updates")) { - return info.hasUpdates(); + return hasUpdates(info); } if (filter.equals("is:installed")) { return info.isInstalled(); @@ -246,32 +226,32 @@ public class ContributionListing { return true; } - for (Author author : info.authorList) { + for (Author author : info.getAuthorList()) { if (author.name.toLowerCase().matches(filter)) { return true; } } - return info.sentence != null && info.sentence.toLowerCase().matches(filter) - || info.paragraph != null && info.paragraph.toLowerCase().matches(filter) - || info.category != null && info.category.toLowerCase().matches(filter) - || info.name != null && info.name.toLowerCase().matches(filter); + return info.getSentence() != null && info.getSentence().toLowerCase().matches(filter) + || info.getParagraph() != null && info.getParagraph().toLowerCase().matches(filter) + || info.getCategory() != null && info.getCategory().toLowerCase().matches(filter) + || info.getName() != null && info.getName().toLowerCase().matches(filter); } - private void notifyRemove(ContributionInfo ContributionInfo) { + private void notifyRemove(Contribution Contribution) { for (ContributionChangeListener listener : listeners) { - listener.contributionRemoved(ContributionInfo); + listener.contributionRemoved(Contribution); } } - private void notifyAdd(ContributionInfo ContributionInfo) { + private void notifyAdd(Contribution Contribution) { for (ContributionChangeListener listener : listeners) { - listener.contributionAdded(ContributionInfo); + listener.contributionAdded(Contribution); } } - private void notifyChange(ContributionInfo oldLib, ContributionInfo newLib) { + private void notifyChange(Contribution oldLib, Contribution newLib) { for (ContributionChangeListener listener : listeners) { listener.contributionChanged(oldLib, newLib); } @@ -298,11 +278,11 @@ public class ContributionListing { public static interface ContributionChangeListener { - public void contributionAdded(ContributionInfo ContributionInfo); + public void contributionAdded(Contribution Contribution); - public void contributionRemoved(ContributionInfo ContributionInfo); + public void contributionRemoved(Contribution Contribution); - public void contributionChanged(ContributionInfo oldLib, ContributionInfo newLib); + public void contributionChanged(Contribution oldLib, Contribution newLib); } @@ -367,11 +347,11 @@ public class ContributionListing { final static String TOOL_TAG = "tool"; //final static String MODE_TAG = "mode"; - ArrayList contributions; + ArrayList contributions; String currentCategoryName; - ContributionInfo currentInfo; + AdvertisedContribution currentInfo; ContributionXmlParser(File xmlFile) { SAXParserFactory spf = SAXParserFactory.newInstance(); @@ -382,7 +362,7 @@ public class ContributionListing { InputSource input = new InputSource(new FileReader(xmlFile)); - contributions = new ArrayList(); + contributions = new ArrayList(); sp.parse(input, this); // throws SAXException } catch (ParserConfigurationException e) { @@ -403,7 +383,7 @@ public class ContributionListing { } } - public ArrayList getLibraries() { + public ArrayList getLibraries() { return contributions; } @@ -415,21 +395,17 @@ public class ContributionListing { currentCategoryName = attributes.getValue("name"); } else if (LIBRARY_TAG.equals(qName)) { - currentInfo = new LibraryInfo(); + currentInfo = new AdvertisedContribution(Type.LIBRARY); setCommonAttributes(attributes); } else if (LIBRARY_COMPILATION_TAG.equals(qName)) { - LibraryCompilationInfo compilationInfo = new LibraryCompilationInfo(); - String[] names = attributes.getValue("libraryNames").split(";"); - for (int i = 0; i < names.length; i++) { - names[i] = names[i].trim(); - } - compilationInfo.libraryNames = Arrays.asList(names); - currentInfo = compilationInfo; + currentInfo = new AdvertisedContribution(Type.LIBRARY_COMPILATION); + String names = attributes.getValue("libraryNames"); + currentInfo.libraryNames = AbstractContribution.toList(names); setCommonAttributes(attributes); } else if (TOOL_TAG.equals(qName)) { - currentInfo = new ToolInfo(); + currentInfo = new AdvertisedContribution(Type.TOOL); setCommonAttributes(attributes); } else if ("author".equals(qName)) { @@ -492,12 +468,24 @@ public class ContributionListing { } public boolean hasUpdates() { - for (ContributionInfo info : allLibraries) { - if (info.hasUpdates()) { + for (Contribution info : allLibraries) { + if (hasUpdates(info)) { return true; } } return false; } + + public boolean hasUpdates(Contribution contribution) { + if (contribution.isInstalled()) { + Contribution advertised = getAdvertisedContribution(contribution); + if (advertised == null) + return false; + + return advertised.getVersion() > contribution.getVersion(); + } + + return false; + } } diff --git a/app/src/processing/app/ContributionManager.java b/app/src/processing/app/ContributionManager.java index 7bf32ac14..6adef5c45 100644 --- a/app/src/processing/app/ContributionManager.java +++ b/app/src/processing/app/ContributionManager.java @@ -38,8 +38,7 @@ import javax.imageio.ImageIO; import javax.swing.*; import javax.swing.event.*; -import processing.app.Contribution.ContributionInfo; -import processing.app.Contribution.ContributionInfo.ContributionType; +import processing.app.contribution.*; public class ContributionManager { @@ -163,7 +162,7 @@ public class ContributionManager { } } - public Image getContributionIcon(ContributionType type) { + public Image getContributionIcon(Contribution.Type type) { if (contributionIcons == null) return null; @@ -296,7 +295,7 @@ public class ContributionManager { public void filterLibraries(String category, List filters) { - List filteredLibraries = contributionListing + List filteredLibraries = contributionListing .getFilteredLibraryList(category, filters); contributionListPanel.filterLibraries(filteredLibraries); @@ -316,14 +315,14 @@ public class ContributionManager { } } - ArrayList contributions = new ArrayList(); + ArrayList contributions = new ArrayList(); contributions.addAll(editor.contribTools); contributions.addAll(libraries); contributions.addAll(compilations); - ArrayList infoList = new ArrayList(); - for (Contribution contribution : contributions) { - infoList.add(contribution.getInfo()); + List infoList = new ArrayList(); + for (InstalledContribution contribution : contributions) { + infoList.add(contribution); } contributionListing.updateInstalledList(infoList); @@ -332,7 +331,7 @@ public class ContributionManager { /** * Non-blocking call to remove a contribution in a new thread. */ - public void removeContribution(final Contribution contribution, + public void removeContribution(final InstalledContribution contribution, final JProgressMonitor pm) { new Thread(new Runnable() { @@ -341,13 +340,13 @@ public class ContributionManager { pm.startTask("Removing", ProgressMonitor.UNKNOWN); if (contribution != null) { if (backupContribution(contribution)) { - ContributionInfo advertisedVersion = contributionListing - .getAdvertisedContribution(contribution.getInfo().name, contribution.getInfo().getType()); + Contribution advertisedVersion = contributionListing + .getAdvertisedContribution(contribution.getName(), contribution.getType()); if (advertisedVersion == null) { - contributionListing.removeContribution(contribution.getInfo()); + contributionListing.removeContribution(contribution); } else { - contributionListing.replaceContribution(contribution.getInfo(), advertisedVersion); + contributionListing.replaceContribution(contribution, advertisedVersion); } } } @@ -362,7 +361,7 @@ public class ContributionManager { * Non-blocking call to download and install a contribution in a new thread. */ public void downloadAndInstall(URL url, - final ContributionInfo info, + final Contribution info, final JProgressMonitor downloadProgressMonitor, final JProgressMonitor installProgressMonitor) { @@ -381,7 +380,7 @@ public class ContributionManager { installProgressMonitor.startTask("Installing", ProgressMonitor.UNKNOWN); - Contribution contribution = null; + InstalledContribution contribution = null; switch (info.getType()) { case LIBRARY: contribution = installLibrary(contributionFile, false); @@ -395,8 +394,8 @@ public class ContributionManager { } if (contribution != null) { - contributionListing.getInformationFromAdvertised(contribution.getInfo()); - contributionListing.replaceContribution(info, contribution.getInfo()); + // XXX contributionListing.getInformationFromAdvertised(contribution); get the category at least + contributionListing.replaceContribution(info, contribution); refreshInstalled(); } @@ -422,7 +421,7 @@ public class ContributionManager { return null; } - String folderName = compilation.info.name; + String folderName = compilation.getName(); File libraryDestination = editor.getBase().getSketchbookLibrariesFolder(); File dest = new File(libraryDestination, folderName); @@ -439,8 +438,7 @@ public class ContributionManager { if (!errorEncountered) { // Install it, return it if (parentDir.renameTo(dest)) { - compilation.folder = dest; - return compilation; + return LibraryCompilation.create(dest); } } @@ -572,7 +570,7 @@ public class ContributionManager { ArrayList oldTools = editor.contribTools; - String toolFolderName = newTool.folder.getName(); + String toolFolderName = newTool.getFolder().getName(); File toolDestination = editor.getBase().getSketchbookToolsFolder(); File newToolDest = new File(toolDestination, toolFolderName); @@ -582,7 +580,7 @@ public class ContributionManager { // XXX: Handle other cases when installing libraries. // -What if a library by the same name is already installed? // -What if newLibDest exists, but isn't used by an existing library? - if (oldTool.folder.exists() && oldTool.folder.equals(newToolDest)) { + if (oldTool.getFolder().exists() && oldTool.getFolder().equals(newToolDest)) { if (!backupContribution(oldTool)) { return null; @@ -591,11 +589,11 @@ public class ContributionManager { } // Move newLib to the sketchbook library folder - if (newTool.folder.renameTo(newToolDest)) { + if (newTool.getFolder().renameTo(newToolDest)) { return ToolContribution.getTool(newToolDest); } else { Base.showWarning("Trouble moving new tool to the sketchbook", - "Could not move tool \"" + newTool.info.name + "\" to " + "Could not move tool \"" + newTool.getName() + "\" to " + newToolDest.getAbsolutePath() + ".\n", null); } @@ -617,11 +615,7 @@ public class ContributionManager { if (discoveredLibs != null && discoveredLibs.size() == 1) { Library discoveredLib = discoveredLibs.get(0); - if (installLibrary(discoveredLib, confirmReplace)) { - return discoveredLib; - } else { - return null; - } + return installLibrary(discoveredLib, confirmReplace); } else { // Diagnose the problem and notify the user if (discoveredLibs == null) { @@ -651,11 +645,11 @@ public class ContributionManager { * ask the user if it's okay to replace the library. If false, the * library is always replaced with the new copy. */ - protected boolean installLibrary(Library newLib, boolean confirmReplace) { + protected Library installLibrary(Library newLib, boolean confirmReplace) { ArrayList oldLibs = editor.getMode().contribLibraries; - String libFolderName = newLib.folder.getName(); + String libFolderName = newLib.getFolder().getName(); File libraryDestination = editor.getBase().getSketchbookLibrariesFolder(); File newLibDest = new File(libraryDestination, libFolderName); @@ -667,7 +661,7 @@ public class ContributionManager { // XXX: Handle other cases when installing libraries. // -What if a library by the same name is already installed? // -What if newLibDest exists, but isn't used by an existing library? - if (oldLib.folder.exists() && oldLib.folder.equals(newLibDest)) { + if (oldLib.getFolder().exists() && oldLib.getFolder().equals(newLibDest)) { int result = 0; if (confirmReplace) { @@ -680,7 +674,7 @@ public class ContributionManager { } if (!confirmReplace || result == JOptionPane.YES_OPTION) { if (!backupContribution(oldLib)) { - return false; + return null; } } else { doInstall = false; @@ -690,9 +684,8 @@ public class ContributionManager { if (doInstall) { // Move newLib to the sketchbook library folder - if (newLib.folder.renameTo(newLibDest)) { - newLib.folder = newLibDest; - return true; + if (newLib.getFolder().renameTo(newLibDest)) { + return new Library(newLibDest, null); // try { // FileUtils.copyDirectory(newLib.folder, libFolder); // FileUtils.deleteQuietly(newLib.folder); @@ -705,7 +698,7 @@ public class ContributionManager { } } - return false; + return null; } public void refreshInstalled() { @@ -716,11 +709,11 @@ public class ContributionManager { /** * Moves the given contribution to a backup folder. */ - private boolean backupContribution(Contribution contribution) { + private boolean backupContribution(InstalledContribution contribution) { File backupFolder = null; - switch (contribution.getInfo().getType()) { + switch (contribution.getType()) { case LIBRARY: case LIBRARY_COMPILATION: backupFolder = createLibraryBackupFolder(); @@ -746,7 +739,7 @@ public class ContributionManager { return true; } else { // } catch (IOException e) { - Base.showWarning("Trouble creating backup of old \"" + contribution.getInfo().name + "\" library", + Base.showWarning("Trouble creating backup of old \"" + contribution.getName() + "\" library", "Could not move library to backup folder:\n" + backupFolderForLib.getAbsolutePath(), null); return false; @@ -938,6 +931,13 @@ public class ContributionManager { public boolean hasAlreadyBeenOpened() { return dialog != null; } + + public boolean hasUpdates(Contribution info) { + if (contributionListing == null) + return false; + + return contributionListing.hasUpdates(info); + } } diff --git a/app/src/processing/app/Library.java b/app/src/processing/app/Library.java index 742cb490b..c178ae87c 100644 --- a/app/src/processing/app/Library.java +++ b/app/src/processing/app/Library.java @@ -3,18 +3,17 @@ package processing.app; import java.io.*; import java.util.*; +import processing.app.contribution.*; import processing.core.*; -public class Library extends Contribution { +public class Library extends InstalledContribution { static final String[] platformNames = PConstants.platformNames; - protected File folder; // /path/to/shortname + //protected File folder; // /path/to/shortname protected File libraryFolder; // shortname/library protected File examplesFolder; // shortname/examples protected File referenceFile; // shortname/reference/index.html - protected LibraryInfo info; - /** Subfolder for grouping libraries in a menu. */ protected String group; @@ -76,7 +75,7 @@ public class Library extends Contribution { public Library(File folder, String subfolder) { - this.folder = folder; + super(folder); this.group = subfolder; libraryFolder = new File(folder, "library"); @@ -86,13 +85,6 @@ public class Library extends Contribution { File exportSettings = new File(libraryFolder, "export.txt"); HashMap exportTable = Base.readSettings(exportSettings); - info = new LibraryInfo(); - info.library = this; - readProperties(exportTable, info); - if (info.name == null) { - info.name = folder.getName(); - } - exportList = new HashMap(); // get the list of files just in the library root @@ -248,16 +240,6 @@ public class Library extends Contribution { } - public ContributionInfo getInfo() { - return info; - } - - - public String getName() { - return info.name; - } - - public boolean hasExamples() { return examplesFolder.exists(); } @@ -273,11 +255,6 @@ public class Library extends Contribution { } - public File getFolder() { - return folder; - } - - public String getPath() { return folder.getAbsolutePath(); } @@ -457,23 +434,9 @@ public class Library extends Contribution { } } } - - public static class LibraryInfo extends ContributionInfo { - - protected Library library; - - public ContributionType getType() { - return ContributionType.LIBRARY; - } - - public boolean isInstalled() { - return library != null; - } - - public Contribution getContribution() { - return library; - } + public Type getType() { + return Type.LIBRARY; } } diff --git a/app/src/processing/app/LibraryCompilation.java b/app/src/processing/app/LibraryCompilation.java index e552a3eda..2f10d54b9 100644 --- a/app/src/processing/app/LibraryCompilation.java +++ b/app/src/processing/app/LibraryCompilation.java @@ -3,33 +3,22 @@ package processing.app; import java.io.*; import java.util.*; -public class LibraryCompilation extends Contribution { - - File folder; +import processing.app.contribution.*; + +public class LibraryCompilation extends InstalledContribution { + + List libraryNames; ArrayList libraries; - /** Properties for this library compilation. */ - LibraryCompilationInfo info; - private LibraryCompilation(File folder) throws IOException { - this.folder = folder; + super(folder); - File propertiesFile = new File(folder, "properties.txt"); - - info = new LibraryCompilationInfo(); - info.compilation = this; - - HashMap propertiesTable = Base.readSettings(propertiesFile); - readProperties(propertiesTable, info); - if (info.name == null) { - info.name = folder.getName(); - } + libraryNames = toList(properties.get("libraryNames")); libraries = new ArrayList(); - Library.list(folder, libraries, info.name); - + Library.list(folder, libraries, name); } /** @@ -43,36 +32,27 @@ public class LibraryCompilation extends Contribution { private LibraryCompilation(ArrayList libraries) throws IllegalArgumentException { + super(null); + this.libraries = libraries; if (libraries == null || libraries.isEmpty()) { throw new IllegalArgumentException("No libraries given"); } - folder = libraries.get(0).folder.getParentFile(); + folder = libraries.get(0).getFolder().getParentFile(); String group = libraries.get(0).group; for (Library lib : libraries) { if (!group.equals(lib.group)) { throw new IllegalArgumentException("Libraries are not all in the same group"); } - if (!folder.equals(lib.folder.getParentFile())) { + if (!folder.equals(lib.getFolder().getParentFile())) { throw new IllegalArgumentException("Libraries do not all have the same parent folder"); } } - File propertiesFile = new File(folder, "properties.txt"); - - - info = new LibraryCompilationInfo(); - info.compilation = this; - - HashMap propertiesTable = Base.readSettings(propertiesFile); - readProperties(propertiesTable, info); - if (info.name == null) { - info.name = group; - } - + // XXX; Uhg, I wish we could just call super here. Should this constructor even exist? } public static ArrayList list(ArrayList libraries) { @@ -114,33 +94,8 @@ public class LibraryCompilation extends Contribution { return null; } - ContributionInfo getInfo() { - return info; - } - - File getFolder() { - return folder; - } - - public static class LibraryCompilationInfo extends ContributionInfo { - - protected LibraryCompilation compilation; - - protected List libraryNames; - - public ContributionType getType() { - return ContributionType.LIBRARY_COMPILATION; - } - - public boolean isInstalled() { - // TODO: Check that the right number of libraries are installed - return compilation != null; - } - - public Contribution getContribution() { - return compilation; - } - + public Type getType() { + return Type.LIBRARY_COMPILATION; } } diff --git a/app/src/processing/app/ToolContribution.java b/app/src/processing/app/ToolContribution.java index bb4eb7c27..9daf4171a 100644 --- a/app/src/processing/app/ToolContribution.java +++ b/app/src/processing/app/ToolContribution.java @@ -1,3 +1,25 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2004-11 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + 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; import java.io.*; @@ -5,16 +27,13 @@ import java.net.*; import java.util.*; import java.util.zip.*; +import processing.app.contribution.*; import processing.app.tools.Tool; -public class ToolContribution extends Contribution implements Tool { +public class ToolContribution extends InstalledContribution implements Tool { Tool tool; - ToolInfo info; - - File folder; - static public ToolContribution getTool(File folder) { try { ToolContribution tool = new ToolContribution(folder); @@ -26,19 +45,7 @@ public class ToolContribution extends Contribution implements Tool { } private ToolContribution(File folder) throws Exception { - this.folder = folder; - - // XXX: This is repeated in LibraryCompilcation.java - File propertiesFile = new File(folder, "properties.txt"); - - info = new ToolInfo(); - info.tool = this; - - HashMap propertiesTable = Base.readSettings(propertiesFile); - readProperties(propertiesTable, info); - if (info.name == null) { - info.name = folder.getName(); - } + super(folder); File toolDirectory = new File(folder, "tool"); // add dir to classpath for .classes @@ -160,14 +167,6 @@ public class ToolContribution extends Contribution implements Tool { } } - ContributionInfo getInfo() { - return info; - } - - File getFolder() { - return folder; - } - public void init(Editor editor) { tool.init(editor); } @@ -180,22 +179,8 @@ public class ToolContribution extends Contribution implements Tool { return tool.getMenuTitle(); } - public static class ToolInfo extends ContributionInfo { - - ToolContribution tool; - - public ContributionType getType() { - return ContributionType.TOOL; - } - - public boolean isInstalled() { - return tool != null; - } - - public Contribution getContribution() { - return tool; - } - + public Type getType() { + return Type.TOOL; } } diff --git a/app/src/processing/app/contribution/AbstractContribution.java b/app/src/processing/app/contribution/AbstractContribution.java new file mode 100644 index 000000000..9f07c2d49 --- /dev/null +++ b/app/src/processing/app/contribution/AbstractContribution.java @@ -0,0 +1,94 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2004-11 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + 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.contribution; + +import java.util.*; + +public abstract class AbstractContribution implements Contribution { + + public String name; // "pdf" or "PDF Export" + public String category; // "Sound" + public List authorList; // Ben Fry + public String url; // http://processing.org + public String sentence; // Write graphics to PDF files. + public String paragraph; // + public int version; // 102 + public int latestVersion; // 103 + public String prettyVersion; // "1.0.2" + + public String getCategory() { + return category; + } + + public String getName() { + return name; + } + + public List getAuthorList() { + return new ArrayList(authorList); + } + + public String getUrl() { + return url; + } + + public String getSentence() { + return sentence; + } + + public String getParagraph() { + return paragraph; + } + + public int getVersion() { + return version; + } + + public int getLatestVersion() { + return latestVersion; + } + + public String getPrettyVersion() { + return prettyVersion; + } + + public int compareTo(Contribution o) { + return getName().toLowerCase().compareTo(o.getName().toLowerCase()); + } + + /** + * @param string semicolin separated list of strings + * @return List containing the trimmed elements from input string + */ + public static List toList(String string) { + List list = new ArrayList(); + if (string != null) { + String[] listAsArray = string.split(";"); + for (String element : listAsArray) { + list.add(element); + } + } + return list; + } + +} diff --git a/app/src/processing/app/contribution/AdvertisedContribution.java b/app/src/processing/app/contribution/AdvertisedContribution.java new file mode 100644 index 000000000..6836df070 --- /dev/null +++ b/app/src/processing/app/contribution/AdvertisedContribution.java @@ -0,0 +1,61 @@ +package processing.app.contribution; + +import java.util.List; + +public class AdvertisedContribution extends AbstractContribution { + + protected Type type; + + public String link; + + public List libraryNames; + + public AdvertisedContribution(Type type) { + this.type = type; + } + + public boolean isInstalled() { + return false; + } + + public Type getType() { + return type; + } + +// public void setName(String name) { +// this.name = name; +// } +// +// public void setCategory(String category) { +// this.category = category; +// } +// +// public void setAuthorList(List authorList) { +// this.authorList = authorList; +// } +// +// public void setUrl(String url) { +// this.url = url; +// } +// +// public void setSentence(String sentence) { +// this.sentence = sentence; +// } +// +// public void setParagraph(String paragraph) { +// this.paragraph = paragraph; +// } +// +// public void setVersion(int version) { +// this.version = version; +// } +// +// public void setLatestVersion(int latestVersion) { +// this.latestVersion = latestVersion; +// } +// +// public void setPrettyVersion(String prettyVersion) { +// this.prettyVersion = prettyVersion; +// } + +} diff --git a/app/src/processing/app/contribution/Author.java b/app/src/processing/app/contribution/Author.java new file mode 100644 index 000000000..83dbe6711 --- /dev/null +++ b/app/src/processing/app/contribution/Author.java @@ -0,0 +1,30 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2004-11 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + 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.contribution; + +public class Author { + public String name; + + public String url; + +} diff --git a/app/src/processing/app/contribution/Contribution.java b/app/src/processing/app/contribution/Contribution.java new file mode 100644 index 000000000..4674e9495 --- /dev/null +++ b/app/src/processing/app/contribution/Contribution.java @@ -0,0 +1,60 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2004-11 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + 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.contribution; + +import java.util.List; + +public interface Contribution extends Comparable { + // "Sound" + String getCategory(); + + // "pdf" or "PDF Export" + String getName(); + + // "Ben Fry" + List getAuthorList(); + + // "http://processing.org" + String getUrl(); + + // "Write graphics to PDF files." + String getSentence(); + + // + String getParagraph(); + + // 102 + int getVersion(); + + // "1.0.2" + String getPrettyVersion(); + + boolean isInstalled(); + + Type getType(); + + public static enum Type { + LIBRARY, LIBRARY_COMPILATION, TOOL, MODE; + } + +} diff --git a/app/src/processing/app/contribution/InstalledContribution.java b/app/src/processing/app/contribution/InstalledContribution.java new file mode 100644 index 000000000..802ab6272 --- /dev/null +++ b/app/src/processing/app/contribution/InstalledContribution.java @@ -0,0 +1,80 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2004-11 Ben Fry and Casey Reas + Copyright (c) 2001-04 Massachusetts Institute of Technology + + 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.contribution; + +import java.io.File; +import java.util.*; + +import processing.app.*; + +public abstract class InstalledContribution extends AbstractContribution { + + protected File folder; + + protected HashMap properties; + + public InstalledContribution(File folder) { + + this.folder = folder; + + if (folder != null) { + File propertiesFile = new File(folder, "contribution.properties"); + + properties = Base.readSettings(propertiesFile); + category = "Unknown"; + + name = properties.get("name"); + if (name == null) { + name = folder.getName(); + } + + String authors = properties.get("authorList"); + authorList = new ArrayList(); + for (String authorName : toList(authors)) { + Author author = new Author(); + author.name = authorName.trim(); + + authorList.add(author); + } + + url = properties.get("url"); + sentence = properties.get("sentence"); + paragraph = properties.get("paragraph"); + + try { + version = Integer.parseInt(properties.get("version")); + } catch (NumberFormatException e) { + } + prettyVersion = properties.get("prettyVersion"); + } + } + + public File getFolder() { + return folder; + } + + public boolean isInstalled() { + return folder != null; + } + +}