Refactored contribution manager to get rid of Info objects. Still has bugs though.

This commit is contained in:
pesckal
2011-07-27 05:31:36 +00:00
parent a394f60046
commit b099bbf55b
12 changed files with 542 additions and 414 deletions
-92
View File
@@ -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<String, String> propTable,
ContributionInfo info) {
info.category = "Unknown";
info.name = propTable.get("name");
String authors = propTable.get("authorList");
info.authorList = new ArrayList<Author>();
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<ContributionInfo> {
protected String category; // "Sound"
protected String name; // "pdf" or "PDF Export"
protected List<Author> authorList; // Ben Fry
protected String url; // http://processing.org
protected String sentence; // Write graphics to PDF files.
protected String paragraph; // <paragraph length description for site>
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;
}
}
}
@@ -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<ContributionInfo, ContributionPanel> contributionPanelsByInfo;
TreeMap<Contribution, ContributionPanel> 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<ContributionInfo, ContributionPanel>();
contributionPanelsByInfo = new TreeMap<Contribution, ContributionPanel>();
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<ContributionInfo, ContributionPanel> entry : contributionPanelsByInfo.entrySet()) {
for (Entry<Contribution, ContributionPanel> 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<ContributionInfo> filteredContributions) {
public void filterLibraries(List<Contribution> filteredContributions) {
synchronized (contributionPanelsByInfo) {
Set<ContributionInfo> hiddenPanels = new TreeSet(contributionPanelsByInfo.keySet());
Set<Contribution> 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<ContributionInfo, ContributionPanel> entry : contributionPanelsByInfo.entrySet()) {
for (Entry<Contribution, ContributionPanel> 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("<html><body><b>");
if (info.url == null) {
nameText.append(info.name);
if (info.getUrl() == null) {
nameText.append(info.getName());
} else {
nameText.append("<a href=\"" + info.url + "\">" + info.name + "</a>");
nameText.append("<a href=\"" + info.getUrl() + "\">" + info.getName() + "</a>");
}
nameText.append("</b>");
nameText.append(createAuthorString(info.authorList));
nameText.append(createAuthorString(info.getAuthorList()));
nameText.append("</body></html>");
headerText.setText(nameText.toString());
categoryLabel.setText("[" + info.category + "]");
categoryLabel.setText("[" + info.getCategory() + "]");
StringBuilder description = new StringBuilder();
description.append("<html><body>");
if (info.sentence != null)
description.append(info.sentence);
if (info.getSentence() != null)
description.append(info.getSentence());
description.append("</body></html>");
descriptionText.setText(description.toString());
setAlignment(descriptionText, StyleConstants.ALIGN_JUSTIFIED);
if (info.hasUpdates()) {
if (contributionManager.hasUpdates(info)) {
StringBuilder versionText = new StringBuilder();
versionText.append("<html><body><i>");
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) {
+81 -93
View File
@@ -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<ContributionChangeListener> listeners;
ArrayList<ContributionInfo> advertisedContributions;
ArrayList<Contribution> advertisedContributions;
Map<String, List<ContributionInfo>> librariesByCategory;
Map<String, List<Contribution>> librariesByCategory;
ArrayList<ContributionInfo> allLibraries;
ArrayList<Contribution> allLibraries;
public ContributionListing() {
listeners = new ArrayList<ContributionChangeListener>();
librariesByCategory = new HashMap<String, List<ContributionInfo>>();
allLibraries = new ArrayList<ContributionInfo>();
librariesByCategory = new HashMap<String, List<Contribution>>();
allLibraries = new ArrayList<Contribution>();
}
@@ -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<ContributionInfo> installedContributions) {
public void updateInstalledList(List<Contribution> 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<ContributionInfo> list = librariesByCategory.get(oldLib.category);
if (librariesByCategory.containsKey(oldLib.getCategory())) {
List<Contribution> 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<ContributionInfo> list = librariesByCategory.get(info.category);
if (librariesByCategory.containsKey(info.getCategory())) {
List<Contribution> list = librariesByCategory.get(info.getCategory());
list.add(info);
Collections.sort(list);
} else {
ArrayList<ContributionInfo> list = new ArrayList<ContributionInfo>();
ArrayList<Contribution> list = new ArrayList<Contribution>();
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<ContributionInfo> getAllContributions() {
return new ArrayList<ContributionInfo>(allLibraries);
public List<Contribution> getAllContributions() {
return new ArrayList<Contribution>(allLibraries);
}
public List<ContributionInfo> getLibararies(String category) {
ArrayList<ContributionInfo> libinfos = new ArrayList<ContributionInfo>(librariesByCategory.get(category));
public List<Contribution> getLibararies(String category) {
ArrayList<Contribution> libinfos =
new ArrayList<Contribution>(librariesByCategory.get(category));
Collections.sort(libinfos);
return libinfos;
}
public List<ContributionInfo> getFilteredLibraryList(String category, List<String> filters) {
ArrayList<ContributionInfo> filteredList = new ArrayList<ContributionInfo>(allLibraries);
public List<Contribution> getFilteredLibraryList(String category, List<String> filters) {
ArrayList<Contribution> filteredList = new ArrayList<Contribution>(allLibraries);
Iterator<ContributionInfo> it = filteredList.iterator();
Iterator<Contribution> 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<ContributionInfo> contributions;
ArrayList<Contribution> 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<ContributionInfo>();
contributions = new ArrayList<Contribution>();
sp.parse(input, this); // throws SAXException
} catch (ParserConfigurationException e) {
@@ -403,7 +383,7 @@ public class ContributionListing {
}
}
public ArrayList<ContributionInfo> getLibraries() {
public ArrayList<Contribution> 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;
}
}
+40 -40
View File
@@ -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<String> filters) {
List<ContributionInfo> filteredLibraries = contributionListing
List<Contribution> filteredLibraries = contributionListing
.getFilteredLibraryList(category, filters);
contributionListPanel.filterLibraries(filteredLibraries);
@@ -316,14 +315,14 @@ public class ContributionManager {
}
}
ArrayList<Contribution> contributions = new ArrayList<Contribution>();
ArrayList<InstalledContribution> contributions = new ArrayList<InstalledContribution>();
contributions.addAll(editor.contribTools);
contributions.addAll(libraries);
contributions.addAll(compilations);
ArrayList<ContributionInfo> infoList = new ArrayList<ContributionInfo>();
for (Contribution contribution : contributions) {
infoList.add(contribution.getInfo());
List<Contribution> infoList = new ArrayList<Contribution>();
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<ToolContribution> 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<Library> 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);
}
}
+6 -43
View File
@@ -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<String,String> exportTable = Base.readSettings(exportSettings);
info = new LibraryInfo();
info.library = this;
readProperties(exportTable, info);
if (info.name == null) {
info.name = folder.getName();
}
exportList = new HashMap<String, String[]>();
// 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;
}
}
+15 -60
View File
@@ -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<String> libraryNames;
ArrayList<Library> 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<String,String> propertiesTable = Base.readSettings(propertiesFile);
readProperties(propertiesTable, info);
if (info.name == null) {
info.name = folder.getName();
}
libraryNames = toList(properties.get("libraryNames"));
libraries = new ArrayList<Library>();
Library.list(folder, libraries, info.name);
Library.list(folder, libraries, name);
}
/**
@@ -43,36 +32,27 @@ public class LibraryCompilation extends Contribution {
private LibraryCompilation(ArrayList<Library> 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<String,String> 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<LibraryCompilation> list(ArrayList<Library> 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<String> 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;
}
}
+27 -42
View File
@@ -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<String,String> 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;
}
}
@@ -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<Author> authorList; // Ben Fry
public String url; // http://processing.org
public String sentence; // Write graphics to PDF files.
public String paragraph; // <paragraph length description for site>
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<Author> getAuthorList() {
return new ArrayList<Author>(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<String> toList(String string) {
List<String> list = new ArrayList<String>();
if (string != null) {
String[] listAsArray = string.split(";");
for (String element : listAsArray) {
list.add(element);
}
}
return list;
}
}
@@ -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<String> 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<Author> 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;
// }
}
@@ -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;
}
@@ -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<Contribution> {
// "Sound"
String getCategory();
// "pdf" or "PDF Export"
String getName();
// "Ben Fry"
List<Author> getAuthorList();
// "http://processing.org"
String getUrl();
// "Write graphics to PDF files."
String getSentence();
// <paragraph length description for site>
String getParagraph();
// 102
int getVersion();
// "1.0.2"
String getPrettyVersion();
boolean isInstalled();
Type getType();
public static enum Type {
LIBRARY, LIBRARY_COMPILATION, TOOL, MODE;
}
}
@@ -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<String, String> 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<Author>();
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;
}
}