From 915de2efe8a17d5f922c0783fdbce2edb9bfcf3f Mon Sep 17 00:00:00 2001 From: pesckal Date: Sun, 10 Jul 2011 13:15:43 +0000 Subject: [PATCH] Removed libraries are removed from list (if unadvertised) and can be installed again using install button (if advertised) --- app/src/processing/app/LibraryListPanel.java | 62 ++++++++++++-------- app/src/processing/app/LibraryListing.java | 23 +++++++- app/src/processing/app/LibraryManager.java | 2 +- 3 files changed, 62 insertions(+), 25 deletions(-) diff --git a/app/src/processing/app/LibraryListPanel.java b/app/src/processing/app/LibraryListPanel.java index c65879b3b..197ea9571 100644 --- a/app/src/processing/app/LibraryListPanel.java +++ b/app/src/processing/app/LibraryListPanel.java @@ -158,7 +158,7 @@ public class LibraryListPanel extends JPanel implements Scrollable { filters)) { for (LibraryPanel libPanel : libPanels) { - if (libPanel.libInfo.equals(lib)) { + if (libPanel.info.equals(lib)) { libPanel.setVisible(true); hiddenPanels.remove(libPanel); } @@ -380,12 +380,28 @@ public class LibraryListPanel extends JPanel implements Scrollable { public void rebuild() { for (LibraryPanel libPanel : libPanels) { - if (libPanel.libInfo.isInstalled()) { - libPanel.useRemoveAction(); + if (libPanel.info.isInstalled()) { + if (libPanel.info.library.folder.exists()) { + libPanel.useRemoveAction(); + } else { + libraries.removeLibrary(libPanel.info); + + String libName = libPanel.info.name; + LibraryInfo newLibInfo = libraries.getAdvertisedLibrary(libName); + + if (newLibInfo == null) { + remove(libPanel); + } else { + libPanel.info = newLibInfo; + libPanel.useInstalledAction(); + } + } } else { libPanel.useInstalledAction(); } } + + updateUI(); } /** @@ -412,7 +428,7 @@ public class LibraryListPanel extends JPanel implements Scrollable { ActionListener removeAction; ActionListener installLibAction; - LibraryInfo libInfo; + LibraryInfo info; JTextPane headerLabel; @@ -427,7 +443,7 @@ public class LibraryListPanel extends JPanel implements Scrollable { boolean isSelected; private LibraryPanel(LibraryInfo libInfo) { - this.libInfo = libInfo; + this.info = libInfo; okayToOpenHyperLink = false; hyperlinkOpener = new ConditionalHyperlinkListener(); @@ -520,7 +536,7 @@ public class LibraryListPanel extends JPanel implements Scrollable { public void actionPerformed(ActionEvent arg) { installOrRemove.setEnabled(false); - libraryManager.uninstallLibrary(libInfo.library); + libraryManager.uninstallLibrary(info.library); installOrRemove.setEnabled(true); } }; @@ -530,7 +546,7 @@ public class LibraryListPanel extends JPanel implements Scrollable { public void actionPerformed(ActionEvent arg) { installOrRemove.setEnabled(false); try { - URL url = new URL(libInfo.link); + URL url = new URL(info.link); installProgressBar.setVisible(true); @@ -572,20 +588,20 @@ public class LibraryListPanel extends JPanel implements Scrollable { private String createAuthorString() { StringBuilder authors = new StringBuilder(); - if (libInfo.authorList != null && !libInfo.authorList.isEmpty()) { + if (info.authorList != null && !info.authorList.isEmpty()) { authors.append(" by "); - for (int i = 0; i < libInfo.authorList.size(); i++) { - Author author = libInfo.authorList.get(i); + for (int i = 0; i < info.authorList.size(); i++) { + Author author = info.authorList.get(i); if (author.url == null) { authors.append(author.name); } else { authors.append("" + author.name + ""); } - if (i + 2 < libInfo.authorList.size()) { + if (i + 2 < info.authorList.size()) { authors.append(", "); - } else if (i + 2 == libInfo.authorList.size()) { - if (libInfo.authorList.size() > 2) { + } else if (i + 2 == info.authorList.size()) { + if (info.authorList.size() > 2) { authors.append(", and "); } else { authors.append(" and "); @@ -680,10 +696,10 @@ public class LibraryListPanel extends JPanel implements Scrollable { StringBuilder header = new StringBuilder(); header.append(""); header.append(""); - if (libInfo.url == null) { - header.append(libInfo.name); + if (info.url == null) { + header.append(info.name); } else { - header.append("" + libInfo.name + ""); + header.append("" + info.name + ""); } header.append(""); header.append(createAuthorString()); @@ -698,7 +714,7 @@ public class LibraryListPanel extends JPanel implements Scrollable { c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; - categoryLabel = new JLabel("[" + libInfo.category + "]"); + categoryLabel = new JLabel("[" + info.category + "]"); categoryLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 7)); add(categoryLabel, c); @@ -725,14 +741,14 @@ public class LibraryListPanel extends JPanel implements Scrollable { StringBuilder description = new StringBuilder(); description.append(""); - if (libInfo.sentence != null) - description.append(libInfo.sentence); + if (info.sentence != null) + description.append(info.sentence); - if (libInfo.sentence != null && libInfo.paragraph != null) + if (info.sentence != null && info.paragraph != null) description.append(" "); - if (libInfo.sentence != null && libInfo.paragraph != null) - description.append(libInfo.paragraph); + if (info.sentence != null && info.paragraph != null) + description.append(info.paragraph); description.append(""); descriptionText.setText(description.toString()); @@ -770,7 +786,7 @@ public class LibraryListPanel extends JPanel implements Scrollable { rightPane.add(Box.createVerticalGlue()); installOrRemove = new JButton(); - if (libInfo.isInstalled()) { + if (info.isInstalled()) { useRemoveAction(); } else { useInstalledAction(); diff --git a/app/src/processing/app/LibraryListing.java b/app/src/processing/app/LibraryListing.java index 4c38917df..fd2995377 100644 --- a/app/src/processing/app/LibraryListing.java +++ b/app/src/processing/app/LibraryListing.java @@ -37,6 +37,8 @@ import processing.app.Library.LibraryInfo.Author; public class LibraryListing { + ArrayList advertisedLibraries; + Map> librariesByCategory; ArrayList allLibraries; @@ -57,7 +59,8 @@ public class LibraryListing { hasDownloadedList = true; LibraryXmlParser xmlParser = new LibraryXmlParser(xmlFile); - updateList(xmlParser.getLibraries()); + advertisedLibraries = xmlParser.getLibraries(); + updateList(advertisedLibraries); Collections.sort(allLibraries); @@ -105,6 +108,24 @@ public class LibraryListing { Collections.sort(allLibraries); } + + public void removeLibrary(LibraryInfo info) { + if (librariesByCategory.containsKey(info.category)) { + librariesByCategory.get(info.category).remove(info); + } + allLibraries.remove(info); + } + + public LibraryInfo getAdvertisedLibrary(String libName) { + for (LibraryInfo libInfo : advertisedLibraries) { + if (libInfo.name.equals(libName)) { + return libInfo; + } + } + + return null; + } + public Set getCategories() { return librariesByCategory.keySet(); diff --git a/app/src/processing/app/LibraryManager.java b/app/src/processing/app/LibraryManager.java index 27eb30bc2..0eee6194e 100644 --- a/app/src/processing/app/LibraryManager.java +++ b/app/src/processing/app/LibraryManager.java @@ -684,7 +684,7 @@ public class LibraryManager { ArrayList info = installLibrary(libFile); if (info != null) { - libraryPanel.libInfo = info.get(0).info; + libraryPanel.info = info.get(0).info; } refreshInstalled();