From e1515013ea38915fe1b155b5fa9f0d841d6a941f Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 16 Feb 2013 15:27:58 -0500 Subject: [PATCH 01/10] removing static methods and more housecleaning --- .../app/contrib/AdvertisedContribution.java | 45 ++++- .../app/contrib/ContributionListPanel.java | 135 +++++++-------- .../app/contrib/ContributionManager.java | 156 ++++-------------- .../app/contrib/ContributionType.java | 130 +++++++++------ .../app/contrib/InstalledContribution.java | 132 ++++++++++----- .../app/contrib/ModeContribution.java | 2 +- .../app/contrib/ToolContribution.java | 2 +- 7 files changed, 309 insertions(+), 293 deletions(-) diff --git a/app/src/processing/app/contrib/AdvertisedContribution.java b/app/src/processing/app/contrib/AdvertisedContribution.java index 68c0b29b7..1423e45e6 100644 --- a/app/src/processing/app/contrib/AdvertisedContribution.java +++ b/app/src/processing/app/contrib/AdvertisedContribution.java @@ -23,6 +23,10 @@ package processing.app.contrib; import java.io.*; import java.util.HashMap; +import java.util.zip.Adler32; +import java.util.zip.CheckedInputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import processing.app.Base; import processing.app.Editor; @@ -87,7 +91,7 @@ class AdvertisedContribution extends Contribution { // Unzip the file into the modes, tools, or libraries folder inside the // sketchbook. Unzipping to /tmp is problematic because it may be on // another file system, so move/rename operations will break. - File sketchbookContribFolder = type.getSketchbookContribFolder(); + File sketchbookContribFolder = type.getSketchbookFolder(); File tempFolder = null; try { @@ -97,20 +101,20 @@ class AdvertisedContribution extends Contribution { statusBar.setErrorMessage("Could not create a temporary folder to install."); return null; } - ContributionManager.unzip(contribArchive, tempFolder); + unzip(contribArchive, tempFolder); // Now go looking for a legit contrib inside what's been unpacked. File contribFolder = null; // Sometimes contrib authors place all their folders in the base directory // of the .zip file instead of in single folder as the guidelines suggest. - if (InstalledContribution.isCandidate(tempFolder, type)) { + if (type.isCandidate(tempFolder)) { contribFolder = tempFolder; } if (contribFolder == null) { // Find the first legitimate looking folder in what we just unzipped - contribFolder = InstalledContribution.findCandidate(tempFolder, type); + contribFolder = type.findCandidate(tempFolder); } InstalledContribution installedContrib = null; @@ -142,6 +146,39 @@ class AdvertisedContribution extends Contribution { } return installedContrib; } + + + static private void unzip(File zipFile, File dest) { + try { + FileInputStream fis = new FileInputStream(zipFile); + CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32()); + ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); + ZipEntry next = null; + while ((next = zis.getNextEntry()) != null) { + File currentFile = new File(dest, next.getName()); + if (next.isDirectory()) { + currentFile.mkdirs(); + } else { + currentFile.createNewFile(); + unzipEntry(zis, currentFile); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + static private void unzipEntry(ZipInputStream zin, File f) throws IOException { + FileOutputStream out = new FileOutputStream(f); + byte[] b = new byte[512]; + int len = 0; + while ((len = zin.read(b)) != -1) { + out.write(b, 0, len); + } + out.flush(); + out.close(); + } public boolean isInstalled() { diff --git a/app/src/processing/app/contrib/ContributionListPanel.java b/app/src/processing/app/contrib/ContributionListPanel.java index 4f51d46bb..047f96195 100644 --- a/app/src/processing/app/contrib/ContributionListPanel.java +++ b/app/src/processing/app/contrib/ContributionListPanel.java @@ -44,40 +44,33 @@ import processing.app.contrib.ContributionListing.ContributionChangeListener; public class ContributionListPanel extends JPanel implements Scrollable, ContributionChangeListener { - static public final String DELETION_MESSAGE = "This tool has " - + "been flagged for deletion. Restart all instances of the editor to " - + "finalize the removal process."; + static public final String DELETION_MESSAGE = + "This tool has been flagged for deletion. " + + "Restart Proessing to finalize the removal process."; static public final String INSTALL_FAILURE_TITLE = "Install Failed"; static public final String MALFORMED_URL_MESSAGE = - "The link fetched from Processing.org is invalid.\n" - + "You can still intall this library manually by visiting\n" - + "the library's website."; + "The link fetched from Processing.org is not valid.\n" + + "You can still install this library manually by visiting\n" + + "the library's website."; ContributionManagerDialog contribManager; - TreeMap panelByContribution; static private HyperlinkListener nullHyperlinkListener = new HyperlinkListener() { - - public void hyperlinkUpdate(HyperlinkEvent e) { - } + public void hyperlinkUpdate(HyperlinkEvent e) { } }; protected ContributionPanel selectedPanel; - protected JPanel statusPlaceholder; - ContributionListing.Filter permaFilter; - ContributionListing contribListing; + public ContributionListPanel(ContributionManagerDialog libraryManager, ContributionListing.Filter filter) { - super(); - this.contribManager = libraryManager; this.permaFilter = filter; @@ -102,6 +95,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib statusPlaceholder.setVisible(false); } + private void updatePanelOrdering() { int row = 0; for (Entry entry : panelByContribution.entrySet()) { @@ -125,8 +119,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib add(statusPlaceholder, c); } + public void contributionAdded(final Contribution contribution) { - if (permaFilter.matches(contribution)) { SwingUtilities.invokeLater(new Runnable() { @@ -141,10 +135,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib panelByContribution.put(contribution, newPanel); } - if (newPanel != null) { newPanel.setContribution(contribution); - add(newPanel); updatePanelOrdering(); updateColors(); @@ -154,8 +146,9 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } } + public void contributionRemoved(final Contribution contribution) { - SwingUtilities.invokeLater(new Runnable() { + EventQueue.invokeLater(new Runnable() { public void run() { synchronized (panelByContribution) { ContributionPanel panel = panelByContribution.get(contribution); @@ -172,11 +165,11 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib }); } + public void contributionChanged(final Contribution oldContrib, final Contribution newContrib) { - SwingUtilities.invokeLater(new Runnable() { - + EventQueue.invokeLater(new Runnable() { public void run() { synchronized (panelByContribution) { ContributionPanel panel = panelByContribution.get(oldContrib); @@ -409,45 +402,33 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib * Panel that expands and gives a brief overview of a library when clicked. */ private class ContributionPanel extends JPanel { - private static final int BUTTON_WIDTH = 100; - /** Should only be set through setContribution(), otherwise UI components - * will not be updated. */ - Contribution contrib; + /** + * Should only be set through setContribution(), + * otherwise UI components will not be updated. + */ + private Contribution contrib; - boolean alreadySelected; - - boolean enableHyperlinks; - - HyperlinkListener conditionalHyperlinkOpener; - - JTextPane headerText; - - JTextPane descriptionText; - - JTextPane updateNotificationLabel; - - JButton updateButton; - - JProgressBar installProgressBar; - - JButton installRemoveButton; - - JPopupMenu contextMenu; - - JMenuItem openFolder; + private boolean alreadySelected; + private boolean enableHyperlinks; + private HyperlinkListener conditionalHyperlinkOpener; + private JTextPane headerText; + private JTextPane descriptionText; + private JTextPane updateNotificationLabel; + private JButton updateButton; + private JProgressBar installProgressBar; + private JButton installRemoveButton; + private JPopupMenu contextMenu; + private JMenuItem openFolder; private HashSet htmlPanes; - private ActionListener removeActionListener; - private ActionListener installActionListener; - private ActionListener undoActionListener; + private ContributionPanel() { - htmlPanes = new HashSet(); enableHyperlinks = false; @@ -533,9 +514,10 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib }); } + /** - * Create the widgets for the header panel which is visible when the library - * panel is not clicked + * Create the widgets for the header panel which is visible when the + * library panel is not clicked. */ private void addPaneComponents() { setLayout(new GridBagLayout()); @@ -584,10 +566,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib descriptionPanel.add(descriptionText, dc); } - int margin = 5; - if (Base.isMacOS()) { - margin = 15; - } + int margin = Base.isMacOS() ? 15 : 5; { GridBagConstraints dc = new GridBagConstraints(); dc.gridx = 1; @@ -818,31 +797,31 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib try { URL downloadUrl = new URL(url); - installProgressBar.setVisible(true); + JProgressMonitor downloadProgress = new JProgressMonitor(installProgressBar) { + public void finishedAction() { + // Finished downloading library + } + }; + + JProgressMonitor installProgress = new JProgressMonitor(installProgressBar) { + public void finishedAction() { + // Finished installing library + resetInstallProgressBarState(); + installRemoveButton.setEnabled(true); + + if (isError()) { + contribManager.statusBar.setErrorMessage("An error occured when " + + "downloading the contribution."); + } + } + }; + ContributionManager.downloadAndInstall(contribManager.editor, - downloadUrl, ad, - new JProgressMonitor(installProgressBar) { - - public void finishedAction() { - // Finished downloading library - } - }, - new JProgressMonitor(installProgressBar) { - - public void finishedAction() { - // Finished installing library - resetInstallProgressBarState(); - installRemoveButton.setEnabled(true); - - if (isError()) { - contribManager.statusBar.setErrorMessage("An error occured when " - + "downloading the contribution."); - } - } - }, - contribManager.statusBar + downloadUrl, ad, + downloadProgress, installProgress, + contribManager.statusBar ); } catch (MalformedURLException e) { diff --git a/app/src/processing/app/contrib/ContributionManager.java b/app/src/processing/app/contrib/ContributionManager.java index 1a83e0309..19575aedc 100644 --- a/app/src/processing/app/contrib/ContributionManager.java +++ b/app/src/processing/app/contrib/ContributionManager.java @@ -23,9 +23,7 @@ package processing.app.contrib; import java.io.*; import java.net.URL; -import java.text.SimpleDateFormat; import java.util.*; -import java.util.zip.*; import processing.app.Base; import processing.app.Editor; @@ -65,7 +63,7 @@ public class ContributionManager { boolean doBackup = Preferences.getBoolean("contribution.backup.on_remove"); if (ContributionManager.requiresRestart(contribution)) { - if (!doBackup || (doBackup && backupContribution(editor, contribution, false, statusBar))) { + if (!doBackup || (doBackup && contribution.backupContribution(editor, false, statusBar))) { if (ContributionManager.setDeletionFlag(contribution)) { contribListing.replaceContribution(contribution, contribution); } @@ -73,7 +71,7 @@ public class ContributionManager { } else { boolean success = false; if (doBackup) { - success = backupContribution(editor, contribution, true, statusBar); + success = contribution.backupContribution(editor, true, statusBar); } else { Base.removeDir(contribution.getFolder()); success = !contribution.getFolder().exists(); @@ -117,12 +115,12 @@ public class ContributionManager { * old version of a contribution that is being updated). Must not be * null. */ - static public void downloadAndInstall(final Editor editor, - final URL url, - final AdvertisedContribution ad, - final JProgressMonitor downloadProgress, - final JProgressMonitor installProgress, - final ErrorWidget statusBar) { + static void downloadAndInstall(final Editor editor, + final URL url, + final AdvertisedContribution ad, + final JProgressMonitor downloadProgress, + final JProgressMonitor installProgress, + final ErrorWidget statusBar) { new Thread(new Runnable() { public void run() { @@ -461,86 +459,31 @@ public class ContributionManager { */ - /** - * Moves the given contribution to a backup folder. - * @param doDeleteOriginal - * true if the file should be moved to the directory, false if it - * should instead be copied, leaving the original in place - */ - static public boolean backupContribution(Editor editor, - InstalledContribution contribution, - boolean doDeleteOriginal, - ErrorWidget statusBar) { - - File backupFolder = null; - - switch (contribution.getType()) { - case LIBRARY: -// case LIBRARY_COMPILATION: - backupFolder = createLibraryBackupFolder(editor, statusBar); - break; - case MODE: - break; - case TOOL: - backupFolder = createToolBackupFolder(editor, statusBar); - break; - } - - if (backupFolder == null) return false; - - String libFolderName = contribution.getFolder().getName(); - - String prefix = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); - final String backupName = prefix + "_" + libFolderName; - File backupSubFolder = ContributionManager.getUniqueName(backupFolder, backupName); - -// try { -// FileUtils.moveDirectory(lib.folder, backupFolderForLib); -// return true; - - boolean success = false; - if (doDeleteOriginal) { - success = contribution.getFolder().renameTo(backupSubFolder); - } else { - try { - Base.copyDir(contribution.getFolder(), backupSubFolder); - success = true; - } catch (IOException e) { - } - } -// } catch (IOException e) { - if (!success) { - statusBar.setErrorMessage("Could not move contribution to backup folder."); - } - return success; - } - - - static public File createLibraryBackupFolder(Editor editor, ErrorWidget logger) { - File libraryBackupFolder = new File(Base.getSketchbookLibrariesFolder(), "old"); - return createBackupFolder(libraryBackupFolder, logger, - "Could not create backup folder for library."); - } - - - static public File createToolBackupFolder(Editor editor, ErrorWidget logger) { - File libraryBackupFolder = new File(Base.getSketchbookToolsFolder(), "old"); - return createBackupFolder(libraryBackupFolder, logger, - "Could not create backup folder for tool."); - } - - - static private File createBackupFolder(File backupFolder, - ErrorWidget logger, - String errorMessage) { - if (!backupFolder.exists() || !backupFolder.isDirectory()) { - if (!backupFolder.mkdirs()) { - logger.setErrorMessage(errorMessage); - return null; - } - } - return backupFolder; - } +// static public File createLibraryBackupFolder(Editor editor, ErrorWidget logger) { +// File libraryBackupFolder = new File(Base.getSketchbookLibrariesFolder(), "old"); +// return createBackupFolder(libraryBackupFolder, logger, +// "Could not create backup folder for library."); +// } +// +// +// static public File createToolBackupFolder(Editor editor, ErrorWidget logger) { +// File libraryBackupFolder = new File(Base.getSketchbookToolsFolder(), "old"); +// return createBackupFolder(libraryBackupFolder, logger, +// "Could not create backup folder for tool."); +// } +// +// +// static private File createBackupFolder(File backupFolder, +// ErrorWidget logger, +// String errorMessage) { +// if (!backupFolder.exists() || !backupFolder.isDirectory()) { +// if (!backupFolder.mkdirs()) { +// logger.setErrorMessage(errorMessage); +// return null; +// } +// } +// return backupFolder; +// } /** @@ -642,39 +585,6 @@ public class ContributionManager { } - public static void unzip(File zipFile, File dest) { - try { - FileInputStream fis = new FileInputStream(zipFile); - CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32()); - ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); - ZipEntry next = null; - while ((next = zis.getNextEntry()) != null) { - File currentFile = new File(dest, next.getName()); - if (next.isDirectory()) { - currentFile.mkdirs(); - } else { - currentFile.createNewFile(); - ContributionManager.unzipEntry(zis, currentFile); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - - private static void unzipEntry(ZipInputStream zin, File f) throws IOException { - FileOutputStream out = new FileOutputStream(f); - byte[] b = new byte[512]; - int len = 0; - while ((len = zin.read(b)) != -1) { - out.write(b, 0, len); - } - out.flush(); - out.close(); - } - - /** Returns true if the type of contribution requires the PDE to restart * when being removed. */ static public boolean requiresRestart(Contribution contrib) { diff --git a/app/src/processing/app/contrib/ContributionType.java b/app/src/processing/app/contrib/ContributionType.java index c52226b25..7f06578eb 100644 --- a/app/src/processing/app/contrib/ContributionType.java +++ b/app/src/processing/app/contrib/ContributionType.java @@ -22,42 +22,43 @@ package processing.app.contrib; import java.io.File; +import java.io.FileFilter; import processing.app.Base; public enum ContributionType { // LIBRARY, LIBRARY_COMPILATION, TOOL, MODE; - LIBRARY, TOOL, MODE; + LIBRARY, TOOL, MODE; - public String toString() { - switch (this) { - case LIBRARY: - return "library"; + public String toString() { + switch (this) { + case LIBRARY: + return "library"; // case LIBRARY_COMPILATION: // return "compilation"; - case TOOL: - return "tool"; - case MODE: - return "mode"; - } - return null; // should be unreachable - }; + case TOOL: + return "tool"; + case MODE: + return "mode"; + } + return null; // should be unreachable + }; - public String getFolderName() { - switch (this) { - case LIBRARY: - return "libraries"; + public String getFolderName() { + switch (this) { + case LIBRARY: + return "libraries"; // case LIBRARY_COMPILATION: // return "libraries"; - case TOOL: - return "tools"; - case MODE: - return "modes"; - } - return null; // should be unreachable + case TOOL: + return "tools"; + case MODE: + return "modes"; } + return null; // should be unreachable + } // public String getPropertiesName() { @@ -65,37 +66,74 @@ public enum ContributionType { // } - static public ContributionType fromName(String s) { - if (s != null) { - if ("library".equals(s.toLowerCase())) { - return LIBRARY; - } + static public ContributionType fromName(String s) { + if (s != null) { + if ("library".equals(s.toLowerCase())) { + return LIBRARY; + } // if ("compilation".equals(s.toLowerCase())) { // return LIBRARY_COMPILATION; // } - if ("tool".equals(s.toLowerCase())) { - return TOOL; - } - if ("mode".equals(s.toLowerCase())) { - return MODE; - } + if ("tool".equals(s.toLowerCase())) { + return TOOL; } - return null; - } - - - public File getSketchbookContribFolder() { - switch (this) { - case LIBRARY: - return Base.getSketchbookLibrariesFolder(); - case TOOL: - return Base.getSketchbookToolsFolder(); - case MODE: - return Base.getSketchbookModesFolder(); + if ("mode".equals(s.toLowerCase())) { + return MODE; } - return null; } + return null; + } + + public File getSketchbookFolder() { + switch (this) { + case LIBRARY: + return Base.getSketchbookLibrariesFolder(); + case TOOL: + return Base.getSketchbookToolsFolder(); + case MODE: + return Base.getSketchbookModesFolder(); + } + return null; + } + + + boolean isCandidate(File potential) { + return (potential.isDirectory() && + new File(potential, getFolderName()).exists()); + } + + + /** + * Return a list of directories that have the necessary subfolder for this + * contribution type. For instance, a list of folders that have a 'mode' + * subfolder if this is a ModeContribution. + */ + File[] listCandidates(File folder) { + return folder.listFiles(new FileFilter() { + public boolean accept(File potential) { + return isCandidate(potential); + } + }); + } + + + /** + * Return the first directory that has the necessary subfolder for this + * contribution type. For instance, the first folder that has a 'mode' + * subfolder if this is a ModeContribution. + */ + File findCandidate(File folder) { + File[] folders = listCandidates(folder); + + if (folders.length == 0) { + return null; + + } else if (folders.length > 1) { + Base.log("More than one " + toString() + " found inside " + folder.getAbsolutePath()); + } + return folders[0]; + } // static public boolean validName(String s) { // return "library".equals(s) || "tool".equals(s) || "mode".equals(s); diff --git a/app/src/processing/app/contrib/InstalledContribution.java b/app/src/processing/app/contrib/InstalledContribution.java index 51c1d451c..71b1ee5f4 100644 --- a/app/src/processing/app/contrib/InstalledContribution.java +++ b/app/src/processing/app/contrib/InstalledContribution.java @@ -24,6 +24,7 @@ package processing.app.contrib; import java.io.*; import java.net.URL; import java.net.URLClassLoader; +import java.text.SimpleDateFormat; import java.util.*; import java.util.zip.*; @@ -149,42 +150,42 @@ public abstract class InstalledContribution extends Contribution { */ - static protected boolean isCandidate(File potential, final ContributionType type) { - return (potential.isDirectory() && - new File(potential, type.getFolderName()).exists()); - } - - - /** - * Return a list of directories that have the necessary subfolder for this - * contribution type. For instance, a list of folders that have a 'mode' - * subfolder if this is a ModeContribution. - */ - static protected File[] listCandidates(File folder, final ContributionType type) { - return folder.listFiles(new FileFilter() { - public boolean accept(File potential) { - return isCandidate(potential, type); - } - }); - } - - - /** - * Return the first directory that has the necessary subfolder for this - * contribution type. For instance, the first folder that has a 'mode' - * subfolder if this is a ModeContribution. - */ - static protected File findCandidate(File folder, final ContributionType type) { - File[] folders = listCandidates(folder, type); - - if (folders.length == 0) { - return null; - - } else if (folders.length > 1) { - Base.log("More than one " + type.toString() + " found inside " + folder.getAbsolutePath()); - } - return folders[0]; - } +// static protected boolean isCandidate(File potential, final ContributionType type) { +// return (potential.isDirectory() && +// new File(potential, type.getFolderName()).exists()); +// } +// +// +// /** +// * Return a list of directories that have the necessary subfolder for this +// * contribution type. For instance, a list of folders that have a 'mode' +// * subfolder if this is a ModeContribution. +// */ +// static protected File[] listCandidates(File folder, final ContributionType type) { +// return folder.listFiles(new FileFilter() { +// public boolean accept(File potential) { +// return isCandidate(potential, type); +// } +// }); +// } +// +// +// /** +// * Return the first directory that has the necessary subfolder for this +// * contribution type. For instance, the first folder that has a 'mode' +// * subfolder if this is a ModeContribution. +// */ +// static protected File findCandidate(File folder, final ContributionType type) { +// File[] folders = listCandidates(folder, type); +// +// if (folders.length == 0) { +// return null; +// +// } else if (folders.length > 1) { +// Base.log("More than one " + type.toString() + " found inside " + folder.getAbsolutePath()); +// } +// return folders[0]; +// } InstalledContribution moveAndLoad(Editor editor, @@ -195,7 +196,7 @@ public abstract class InstalledContribution extends Contribution { String contribFolderName = getFolder().getName(); - File contribTypeFolder = getType().getSketchbookContribFolder(); + File contribTypeFolder = getType().getSketchbookFolder(); File contribFolder = new File(contribTypeFolder, contribFolderName); for (InstalledContribution oldContrib : oldContribs) { @@ -204,7 +205,7 @@ public abstract class InstalledContribution extends Contribution { if (ContributionManager.requiresRestart(oldContrib)) { // XXX: We can't replace stuff, soooooo.... do something different - if (!ContributionManager.backupContribution(editor, oldContrib, false, statusBar)) { + if (!oldContrib.backupContribution(editor, false, statusBar)) { return null; } } else { @@ -218,7 +219,7 @@ public abstract class InstalledContribution extends Contribution { "has been found in your sketchbook. Clicking “Yes”
"+ "will move the existing library to a backup folder
" + " in libraries/old before replacing it."); - if (result != JOptionPane.YES_OPTION || !ContributionManager.backupContribution(editor, oldContrib, true, statusBar)) { + if (result != JOptionPane.YES_OPTION || !oldContrib.backupContribution(editor, true, statusBar)) { return null; } } else { @@ -233,7 +234,7 @@ public abstract class InstalledContribution extends Contribution { } } } else { - if ((doBackup && !ContributionManager.backupContribution(editor, oldContrib, true, statusBar)) || + if ((doBackup && !oldContrib.backupContribution(editor, true, statusBar)) || (!doBackup && !oldContrib.getFolder().delete())) { return null; } @@ -256,6 +257,57 @@ public abstract class InstalledContribution extends Contribution { } + /** + * Moves the given contribution to a backup folder. + * @param doDeleteOriginal + * true if the file should be moved to the directory, false if it + * should instead be copied, leaving the original in place + */ + boolean backupContribution(Editor editor, + boolean doDeleteOriginal, + ErrorWidget statusBar) { + + boolean success = false; + File backupFolder = + createBackupFolder(statusBar, getType()); + + if (backupFolder != null) { + String libFolderName = getFolder().getName(); + String prefix = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + final String backupName = prefix + "_" + libFolderName; + File backupSubFolder = ContributionManager.getUniqueName(backupFolder, backupName); + + if (doDeleteOriginal) { + success = getFolder().renameTo(backupSubFolder); + } else { + try { + Base.copyDir(getFolder(), backupSubFolder); + success = true; + } catch (IOException e) { } + } + if (!success) { + statusBar.setErrorMessage("Could not move contribution to backup folder."); + } + } + return success; + } + + + static public File createBackupFolder(ErrorWidget status, ContributionType type) { + File backupFolder = new File(type.getSketchbookFolder(), "old"); + if (!backupFolder.isDirectory()) { + status.setErrorMessage("Remove the file named \"old\" from the " + + type.getFolderName() + " folder in the sketchbook."); + return null; + } + if (!backupFolder.exists() && !backupFolder.mkdirs()) { + status.setErrorMessage("Could not create a " + type + " backup folder."); + return null; + } + return backupFolder; + } + + public File getFolder() { return folder; } diff --git a/app/src/processing/app/contrib/ModeContribution.java b/app/src/processing/app/contrib/ModeContribution.java index 498ab3791..249f6d777 100644 --- a/app/src/processing/app/contrib/ModeContribution.java +++ b/app/src/processing/app/contrib/ModeContribution.java @@ -91,7 +91,7 @@ public class ModeContribution extends InstalledContribution { for (ModeContribution contrib : contribModes) { existing.put(contrib.getFolder(), contrib); } - File[] potential = listCandidates(modesFolder, ContributionType.MODE); + File[] potential = ContributionType.MODE.listCandidates(modesFolder); for (File folder : potential) { if (!existing.containsKey(folder)) { try { diff --git a/app/src/processing/app/contrib/ToolContribution.java b/app/src/processing/app/contrib/ToolContribution.java index 3406a71bc..55b4c70d8 100644 --- a/app/src/processing/app/contrib/ToolContribution.java +++ b/app/src/processing/app/contrib/ToolContribution.java @@ -69,7 +69,7 @@ public class ToolContribution extends InstalledContribution implements Tool { static public ArrayList loadAll(File toolsFolder) { - File[] list = listCandidates(toolsFolder, ContributionType.TOOL); + File[] list = ContributionType.TOOL.listCandidates(toolsFolder); ArrayList outgoing = new ArrayList(); for (File folder : list) { try { From 05c2c75cfe3bb73331ed0633e4ab378a311126b6 Mon Sep 17 00:00:00 2001 From: Casey Reas Date: Sat, 16 Feb 2013 13:08:34 -0800 Subject: [PATCH 02/10] Update to Esefera example, re: issue #34 --- .../Demos/Performance/Esfera/Esfera.pde | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) mode change 100755 => 100644 java/examples/Demos/Performance/Esfera/Esfera.pde diff --git a/java/examples/Demos/Performance/Esfera/Esfera.pde b/java/examples/Demos/Performance/Esfera/Esfera.pde old mode 100755 new mode 100644 index e6f12c130..1b84f291d --- a/java/examples/Demos/Performance/Esfera/Esfera.pde +++ b/java/examples/Demos/Performance/Esfera/Esfera.pde @@ -6,63 +6,63 @@ */ int cuantos = 16000; -pelo[] lista ; -float[] z = new float[cuantos]; -float[] phi = new float[cuantos]; -float[] largos = new float[cuantos]; +Pelo[] lista ; float radio = 200; float rx = 0; float ry =0; void setup() { size(1024, 768, P3D); - noSmooth(); - frameRate(120); + radio = height/3.5; - - lista = new pelo[cuantos]; - for (int i=0; i Date: Sat, 16 Feb 2013 16:59:25 -0500 Subject: [PATCH 03/10] more cleanups, removing static methods --- app/src/processing/app/Base.java | 44 +---- .../app/contrib/AdvertisedContribution.java | 2 +- .../processing/app/contrib/Contribution.java | 15 ++ .../app/contrib/ContributionListPanel.java | 40 ++-- .../app/contrib/ContributionListing.java | 28 ++- .../app/contrib/ContributionManager.java | 177 +++++------------- .../contrib/ContributionManagerDialog.java | 13 +- .../app/contrib/ContributionType.java | 61 +++++- .../app/contrib/InstalledContribution.java | 140 ++++++++++---- 9 files changed, 278 insertions(+), 242 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index bcc367043..7a74c188c 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -334,9 +334,7 @@ public class Base { // removeDir(contrib.getFolder()); // } // } - ContributionManager.checkDeletions(getSketchbookModesFolder()); - ContributionManager.checkDeletions(getSketchbookToolsFolder()); - + ContributionManager.deleteFlagged(); buildCoreModes(); rebuildContribModes(); @@ -362,37 +360,15 @@ public class Base { } } - libraryManagerFrame = new ContributionManagerDialog("Library Manager", - new ContributionListing.Filter() { - public boolean matches(Contribution contrib) { - return contrib.getType() == ContributionType.LIBRARY; -// return contrib.getType() == Contribution.Type.LIBRARY -// || contrib.getType() == Contribution.Type.LIBRARY_COMPILATION; - } - }); - toolManagerFrame = new ContributionManagerDialog("Tool Manager", - new ContributionListing.Filter() { - public boolean matches(Contribution contrib) { - return contrib.getType() == ContributionType.TOOL; - } - }); - modeManagerFrame = new ContributionManagerDialog("Mode Manager", - new ContributionListing.Filter() { - public boolean matches(Contribution contrib) { - return contrib.getType() == ContributionType.MODE; - } - }); - updateManagerFrame = new ContributionManagerDialog("Update Manager", - new ContributionListing.Filter() { - public boolean matches(Contribution contrib) { - if (contrib instanceof InstalledContribution) { - return ContributionListing.getInstance().hasUpdates(contrib); - } - - return false; - } - }); - + libraryManagerFrame = + new ContributionManagerDialog(ContributionType.LIBRARY); + toolManagerFrame = + new ContributionManagerDialog(ContributionType.TOOL); + modeManagerFrame = + new ContributionManagerDialog(ContributionType.MODE); + updateManagerFrame = + new ContributionManagerDialog(null); + // Make sure ThinkDifferent has library examples too nextMode.rebuildLibraryList(); diff --git a/app/src/processing/app/contrib/AdvertisedContribution.java b/app/src/processing/app/contrib/AdvertisedContribution.java index 1423e45e6..1fb2544ca 100644 --- a/app/src/processing/app/contrib/AdvertisedContribution.java +++ b/app/src/processing/app/contrib/AdvertisedContribution.java @@ -128,7 +128,7 @@ class AdvertisedContribution extends Contribution { if (!writePropertiesFile(propFile)) { // 1. contribFolder now has a legit contribution, load it to get info. InstalledContribution newContrib = - ContributionManager.load(editor.getBase(), contribFolder, type); + type.load(editor.getBase(), contribFolder); // 2. Check to make sure nothing has the same name already, // backup old if needed, then move things into place and reload. diff --git a/app/src/processing/app/contrib/Contribution.java b/app/src/processing/app/contrib/Contribution.java index 77590f47f..759b85537 100644 --- a/app/src/processing/app/contrib/Contribution.java +++ b/app/src/processing/app/contrib/Contribution.java @@ -90,4 +90,19 @@ abstract public class Contribution { abstract public boolean isInstalled(); + + + /** + * Returns true if the type of contribution requires the PDE to restart + * when being added or removed. + */ + public boolean requiresRestart() { + return getType() == ContributionType.TOOL || getType() == ContributionType.MODE; + } + + + /** Overridden by InstalledContribution. */ + boolean isDeletionFlagged() { + return false; + } } diff --git a/app/src/processing/app/contrib/ContributionListPanel.java b/app/src/processing/app/contrib/ContributionListPanel.java index 047f96195..099ac5d5a 100644 --- a/app/src/processing/app/contrib/ContributionListPanel.java +++ b/app/src/processing/app/contrib/ContributionListPanel.java @@ -40,6 +40,7 @@ import java.net.*; import processing.app.Base; import processing.app.contrib.ContributionListing.ContributionChangeListener; +import processing.core.PApplet; public class ContributionListPanel extends JPanel implements Scrollable, ContributionChangeListener { @@ -278,18 +279,21 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } } - static String toHex(Color c) { - StringBuilder hex = new StringBuilder(); - hex.append(Integer.toString(c.getRed(), 16)); - hex.append(Integer.toString(c.getGreen(), 16)); - hex.append(Integer.toString(c.getBlue(), 16)); - return hex.toString(); - } + +// static String toHex(Color c) { +// StringBuilder hex = new StringBuilder(); +// hex.append(Integer.toString(c.getRed(), 16)); +// hex.append(Integer.toString(c.getGreen(), 16)); +// hex.append(Integer.toString(c.getBlue(), 16)); +// return hex.toString(); +// } + public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } + /** * Amount to scroll to reveal a new page of items */ @@ -308,6 +312,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib return 0; } + /** * Amount to scroll to reveal the rest of something we are on or a new item */ @@ -458,8 +463,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib public void actionPerformed(ActionEvent e) { if (contrib instanceof InstalledContribution) { InstalledContribution installed = (InstalledContribution) contrib; - ContributionManager.unsetDeletionFlag(installed); - contribListing.replaceContribution(contrib, contrib); + installed.unsetDeletionFlag(); + contribListing.replaceContribution(contrib, contrib); // ?? } } }; @@ -472,9 +477,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib installProgressBar.setVisible(true); - ContributionManager.removeContribution(contribManager.editor, - (InstalledContribution) contrib, - new JProgressMonitor(installProgressBar) { + ((InstalledContribution) contrib).removeContribution(contribManager.editor, + new JProgressMonitor(installProgressBar) { public void finishedAction() { // Finished uninstalling the library resetInstallProgressBarState(); @@ -711,7 +715,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib StringBuilder description = new StringBuilder(); description.append(""); - boolean isFlagged = ContributionManager.isDeletionFlagSet(contrib); + boolean isFlagged = contrib.isDeletionFlagged(); if (isFlagged) { description.append(ContributionListPanel.DELETION_MESSAGE); } else { @@ -737,7 +741,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib versionText.append("To finish an update, reinstall this contribution after the restart."); } else { versionText.append("New version available!"); - if (ContributionManager.requiresRestart(contrib)) { + if (contrib.requiresRestart()) { versionText.append(" To update, first remove the current version."); } } @@ -750,7 +754,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } updateButton.setEnabled(true); - if (contrib != null && !ContributionManager.requiresRestart(contrib)) { + if (contrib != null && !contrib.requiresRestart()) { updateButton.setVisible(isSelected() && contribListing.hasUpdates(contrib)); } @@ -877,7 +881,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib // hyperlink, it will be opened as the mouse is released. enableHyperlinks = alreadySelected; - if (contrib != null && !ContributionManager.requiresRestart(contrib)) { + if (contrib != null && !contrib.requiresRestart()) { updateButton.setVisible(isSelected() && contribListing.hasUpdates(contrib)); } @@ -928,8 +932,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib if (doc instanceof HTMLDocument) { HTMLDocument html = (HTMLDocument) doc; StyleSheet stylesheet = html.getStyleSheet(); - stylesheet.addRule("body {color:" + ContributionListPanel.toHex(fg) + ";}"); - stylesheet.addRule("a {color:" + ContributionListPanel.toHex(fg) + "}"); + stylesheet.addRule("body {color:" + PApplet.hex(fg.getRGB()).substring(8) + ";}"); + stylesheet.addRule("a {color:" + PApplet.hex(fg.getRGB()).substring(8) + "}"); } } } diff --git a/app/src/processing/app/contrib/ContributionListing.java b/app/src/processing/app/contrib/ContributionListing.java index e02ecdccb..888538b80 100644 --- a/app/src/processing/app/contrib/ContributionListing.java +++ b/app/src/processing/app/contrib/ContributionListing.java @@ -487,7 +487,7 @@ public class ContributionListing { } - public ArrayList parseContribList(File f) { + ArrayList parseContribList(File f) { ArrayList outgoing = new ArrayList(); if (f != null && f.exists()) { @@ -534,10 +534,34 @@ public class ContributionListing { } - public static interface Filter { + static interface Filter { boolean matches(Contribution contrib); } + + /** + * Create a filter for a specific contribution type. + * @param type The type, or null for a generic update checker. + */ + static Filter createFilter(final ContributionType type) { + if (type == null) { + return new Filter() { + public boolean matches(Contribution contrib) { + return contrib.getType() == type; + } + }; + } else { + return new Filter() { + public boolean matches(Contribution contrib) { + if (contrib instanceof InstalledContribution) { + return ContributionListing.getInstance().hasUpdates(contrib); + } + return false; + } + }; + } + } + static Comparator contribComparator = new Comparator() { public int compare(Contribution o1, Contribution o2) { diff --git a/app/src/processing/app/contrib/ContributionManager.java b/app/src/processing/app/contrib/ContributionManager.java index 19575aedc..2bf8b6f41 100644 --- a/app/src/processing/app/contrib/ContributionManager.java +++ b/app/src/processing/app/contrib/ContributionManager.java @@ -23,12 +23,9 @@ package processing.app.contrib; import java.io.*; import java.net.URL; -import java.util.*; import processing.app.Base; import processing.app.Editor; -import processing.app.Library; -import processing.app.Preferences; interface ErrorWidget { @@ -37,7 +34,6 @@ interface ErrorWidget { public class ContributionManager { - static public final String DELETION_FLAG = "flagged_for_deletion"; static public final ContributionListing contribListing; static { @@ -45,65 +41,6 @@ public class ContributionManager { } - /** - * Non-blocking call to remove a contribution in a new thread. - */ - static public void removeContribution(final Editor editor, - final InstalledContribution contribution, - final ProgressMonitor pm, - final ErrorWidget statusBar) { - if (contribution != null) { - final ProgressMonitor progressMonitor = (pm != null) ? pm : new NullProgressMonitor(); - - new Thread(new Runnable() { - - public void run() { - progressMonitor.startTask("Removing", ProgressMonitor.UNKNOWN); - - boolean doBackup = Preferences.getBoolean("contribution.backup.on_remove"); - if (ContributionManager.requiresRestart(contribution)) { - - if (!doBackup || (doBackup && contribution.backupContribution(editor, false, statusBar))) { - if (ContributionManager.setDeletionFlag(contribution)) { - contribListing.replaceContribution(contribution, contribution); - } - } - } else { - boolean success = false; - if (doBackup) { - success = contribution.backupContribution(editor, true, statusBar); - } else { - Base.removeDir(contribution.getFolder()); - success = !contribution.getFolder().exists(); - } - - if (success) { - Contribution advertisedVersion = - contribListing.getAdvertisedContribution(contribution); - - if (advertisedVersion == null) { - contribListing.removeContribution(contribution); - } else { - contribListing.replaceContribution(contribution, - advertisedVersion); - } - } else { - // There was a failure backing up the folder - if (doBackup) { - - } else { - statusBar.setErrorMessage("Could not delete the contribution's files"); - } - } - } - refreshInstalled(editor); - progressMonitor.finished(); - } - }).start(); - } - } - - /** * Non-blocking call to download and install a contribution in a new thread. * @@ -198,39 +135,39 @@ public class ContributionManager { // } - static InstalledContribution load(Base base, File folder, ContributionType type) { - switch (type) { - case LIBRARY: - return new Library(folder); -// case LIBRARY_COMPILATION: -// return LibraryCompilation.create(folder); - case TOOL: - return ToolContribution.load(folder); - case MODE: - return ModeContribution.load(base, folder); - } - return null; - } - - - static ArrayList listContributions(ContributionType type, Editor editor) { - ArrayList contribs = new ArrayList(); - switch (type) { - case LIBRARY: - contribs.addAll(editor.getMode().contribLibraries); - break; -// case LIBRARY_COMPILATION: -// contribs.addAll(LibraryCompilation.list(editor.getMode().contribLibraries)); +// static InstalledContribution load(Base base, File folder, ContributionType type) { +// switch (type) { +// case LIBRARY: +// return new Library(folder); +//// case LIBRARY_COMPILATION: +//// return LibraryCompilation.create(folder); +// case TOOL: +// return ToolContribution.load(folder); +// case MODE: +// return ModeContribution.load(base, folder); +// } +// return null; +// } +// +// +// static ArrayList listContributions(ContributionType type, Editor editor) { +// ArrayList contribs = new ArrayList(); +// switch (type) { +// case LIBRARY: +// contribs.addAll(editor.getMode().contribLibraries); // break; - case TOOL: - contribs.addAll(editor.contribTools); - break; - case MODE: - contribs.addAll(editor.getBase().getModeContribs()); - break; - } - return contribs; - } +//// case LIBRARY_COMPILATION: +//// contribs.addAll(LibraryCompilation.list(editor.getMode().contribLibraries)); +//// break; +// case TOOL: +// contribs.addAll(editor.contribTools); +// break; +// case MODE: +// contribs.addAll(editor.getBase().getModeContribs()); +// break; +// } +// return contribs; +// } // static void initialize(InstalledContribution contribution, Base base) throws Exception { @@ -583,50 +520,20 @@ public class ContributionManager { return fileName; } - - - /** Returns true if the type of contribution requires the PDE to restart - * when being removed. */ - static public boolean requiresRestart(Contribution contrib) { - return contrib.getType() == ContributionType.TOOL || contrib.getType() == ContributionType.MODE; + + + static public void deleteFlagged() { + deleteFlagged(Base.getSketchbookLibrariesFolder()); + deleteFlagged(Base.getSketchbookModesFolder()); + deleteFlagged(Base.getSketchbookToolsFolder()); } - - static public boolean setDeletionFlag(InstalledContribution contrib) { - // Only returns false if the file already exists, so we can - // ignore the return value. - try { - new File(contrib.getFolder(), DELETION_FLAG).createNewFile(); - return true; - } catch (IOException e) { - return false; - } - } - - - static public boolean unsetDeletionFlag(InstalledContribution contrib) { - return new File(contrib.getFolder(), DELETION_FLAG).delete(); - } - - - static public boolean isDeletionFlagSet(Contribution contrib) { - if (contrib instanceof InstalledContribution) { - InstalledContribution installed = (InstalledContribution) contrib; - return isDeletionFlagSet(installed.getFolder()); - } - return false; - } - - - static public boolean isDeletionFlagSet(File folder) { - return new File(folder, DELETION_FLAG).exists(); - } - - - static public void checkDeletions(File root) { + + static private void deleteFlagged(File root) { File[] markedForDeletion = root.listFiles(new FileFilter() { public boolean accept(File folder) { - return (folder.isDirectory() && isDeletionFlagSet(folder)); + return (folder.isDirectory() && + InstalledContribution.isDeletionFlagged(folder)); } }); for (File folder : markedForDeletion) { diff --git a/app/src/processing/app/contrib/ContributionManagerDialog.java b/app/src/processing/app/contrib/ContributionManagerDialog.java index 30e6a8abf..e985d0c72 100644 --- a/app/src/processing/app/contrib/ContributionManagerDialog.java +++ b/app/src/processing/app/contrib/ContributionManagerDialog.java @@ -57,15 +57,12 @@ public class ContributionManagerDialog { ContributionListing contribListing; - public ContributionManagerDialog(String title, - ContributionListing.Filter filter) { - - this.title = title; - this.permaFilter = filter; - + public ContributionManagerDialog(ContributionType type) { + this.title = type.getTitle() + " Manager"; + this.permaFilter = ContributionListing.createFilter(type); + contribListing = ContributionListing.getInstance(); - - contributionListPanel = new ContributionListPanel(this, filter); + contributionListPanel = new ContributionListPanel(this, permaFilter); contribListing.addContributionListener(contributionListPanel); } diff --git a/app/src/processing/app/contrib/ContributionType.java b/app/src/processing/app/contrib/ContributionType.java index 7f06578eb..76b31eef9 100644 --- a/app/src/processing/app/contrib/ContributionType.java +++ b/app/src/processing/app/contrib/ContributionType.java @@ -23,8 +23,11 @@ package processing.app.contrib; import java.io.File; import java.io.FileFilter; +import java.util.ArrayList; import processing.app.Base; +import processing.app.Editor; +import processing.app.Library; public enum ContributionType { // LIBRARY, LIBRARY_COMPILATION, TOOL, MODE; @@ -44,6 +47,13 @@ public enum ContributionType { } return null; // should be unreachable }; + + + /** Return Mode for mode, Tool for tool, etc. */ + public String getTitle() { + String s = toString(); + return Character.toUpperCase(s.charAt(0)) + s.substring(1); + } public String getFolderName() { @@ -134,8 +144,49 @@ public enum ContributionType { } return folders[0]; } - -// static public boolean validName(String s) { -// return "library".equals(s) || "tool".equals(s) || "mode".equals(s); -// } - } \ No newline at end of file + + + InstalledContribution load(Base base, File folder) { + switch (this) { + case LIBRARY: + return new Library(folder); + case TOOL: + return ToolContribution.load(folder); + case MODE: + return ModeContribution.load(base, folder); + } + return null; + } + + + ArrayList listContributions(Editor editor) { + ArrayList contribs = new ArrayList(); + switch (this) { + case LIBRARY: + contribs.addAll(editor.getMode().contribLibraries); + break; + case TOOL: + contribs.addAll(editor.contribTools); + break; + case MODE: + contribs.addAll(editor.getBase().getModeContribs()); + break; + } + return contribs; + } + + + File createBackupFolder(ErrorWidget status) { + File backupFolder = new File(getSketchbookFolder(), "old"); + if (!backupFolder.isDirectory()) { + status.setErrorMessage("Remove the file named \"old\" from the " + + getFolderName() + " folder in the sketchbook."); + return null; + } + if (!backupFolder.exists() && !backupFolder.mkdirs()) { + status.setErrorMessage("Could not create a " + toString() + " backup folder."); + return null; + } + return backupFolder; + } +} \ No newline at end of file diff --git a/app/src/processing/app/contrib/InstalledContribution.java b/app/src/processing/app/contrib/InstalledContribution.java index 71b1ee5f4..5475cd20a 100644 --- a/app/src/processing/app/contrib/InstalledContribution.java +++ b/app/src/processing/app/contrib/InstalledContribution.java @@ -34,22 +34,12 @@ import processing.app.*; public abstract class InstalledContribution extends Contribution { -//public abstract class InstalledContribution implements Contribution { -// protected String name; // "pdf" or "PDF Export" -// protected String category; // "Sound" -// protected String 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 String prettyVersion; // "1.0.2" - - protected String id; // 1 - protected int latestVersion; // 103 + static public final String DELETION_FLAG = "flagged_for_deletion"; + + protected String id; // 1 + protected int latestVersion; // 103 protected File folder; - protected HashMap properties; - protected ClassLoader loader; @@ -192,7 +182,7 @@ public abstract class InstalledContribution extends Contribution { boolean confirmReplace, ErrorWidget statusBar) { ArrayList oldContribs = - ContributionManager.listContributions(getType(), editor); + getType().listContributions(editor); String contribFolderName = getFolder().getName(); @@ -203,9 +193,9 @@ public abstract class InstalledContribution extends Contribution { if ((oldContrib.getFolder().exists() && oldContrib.getFolder().equals(contribFolder)) || (oldContrib.getId() != null && oldContrib.getId().equals(getId()))) { - if (ContributionManager.requiresRestart(oldContrib)) { + if (oldContrib.requiresRestart()) { // XXX: We can't replace stuff, soooooo.... do something different - if (!oldContrib.backupContribution(editor, false, statusBar)) { + if (!oldContrib.backup(editor, false, statusBar)) { return null; } } else { @@ -219,7 +209,7 @@ public abstract class InstalledContribution extends Contribution { "has been found in your sketchbook. Clicking “Yes”
"+ "will move the existing library to a backup folder
" + " in libraries/old before replacing it."); - if (result != JOptionPane.YES_OPTION || !oldContrib.backupContribution(editor, true, statusBar)) { + if (result != JOptionPane.YES_OPTION || !oldContrib.backup(editor, true, statusBar)) { return null; } } else { @@ -234,7 +224,7 @@ public abstract class InstalledContribution extends Contribution { } } } else { - if ((doBackup && !oldContrib.backupContribution(editor, true, statusBar)) || + if ((doBackup && !oldContrib.backup(editor, true, statusBar)) || (!doBackup && !oldContrib.getFolder().delete())) { return null; } @@ -253,23 +243,20 @@ public abstract class InstalledContribution extends Contribution { " \"" + getName() + "\" to the sketchbook."); return null; } - return ContributionManager.load(editor.getBase(), contribFolder, getType()); + return getType().load(editor.getBase(), contribFolder); } /** * Moves the given contribution to a backup folder. - * @param doDeleteOriginal + * @param deleteOriginal * true if the file should be moved to the directory, false if it * should instead be copied, leaving the original in place */ - boolean backupContribution(Editor editor, - boolean doDeleteOriginal, - ErrorWidget statusBar) { + boolean backup(Editor editor, boolean deleteOriginal, ErrorWidget status) { boolean success = false; - File backupFolder = - createBackupFolder(statusBar, getType()); + File backupFolder = getType().createBackupFolder(status); if (backupFolder != null) { String libFolderName = getFolder().getName(); @@ -277,7 +264,7 @@ public abstract class InstalledContribution extends Contribution { final String backupName = prefix + "_" + libFolderName; File backupSubFolder = ContributionManager.getUniqueName(backupFolder, backupName); - if (doDeleteOriginal) { + if (deleteOriginal) { success = getFolder().renameTo(backupSubFolder); } else { try { @@ -286,25 +273,73 @@ public abstract class InstalledContribution extends Contribution { } catch (IOException e) { } } if (!success) { - statusBar.setErrorMessage("Could not move contribution to backup folder."); + status.setErrorMessage("Could not move contribution to backup folder."); } } return success; } - static public File createBackupFolder(ErrorWidget status, ContributionType type) { - File backupFolder = new File(type.getSketchbookFolder(), "old"); - if (!backupFolder.isDirectory()) { - status.setErrorMessage("Remove the file named \"old\" from the " + - type.getFolderName() + " folder in the sketchbook."); - return null; + /** + * Non-blocking call to remove a contribution in a new thread. + */ + void removeContribution(final Editor editor, + final ProgressMonitor pm, + final ErrorWidget statusBar) { +// final ContributionListing contribListing = ContributionListing.getInstance(); +// final ProgressMonitor progressMonitor = ; + + new Thread(new Runnable() { + public void run() { + remove(editor, + (pm != null) ? pm : new NullProgressMonitor(), + statusBar, + ContributionListing.getInstance()); + } + }).start(); + } + + + void remove(final Editor editor, + final ProgressMonitor pm, + final ErrorWidget statusBar, + final ContributionListing contribListing) { + pm.startTask("Removing", ProgressMonitor.UNKNOWN); + + boolean doBackup = Preferences.getBoolean("contribution.backup.on_remove"); + if (requiresRestart()) { + if (!doBackup || (doBackup && backup(editor, false, statusBar))) { + if (setDeletionFlag()) { + contribListing.replaceContribution(this, this); + } + } + } else { + boolean success = false; + if (doBackup) { + success = backup(editor, true, statusBar); + } else { + Base.removeDir(getFolder()); + success = !getFolder().exists(); + } + + if (success) { + Contribution advertisedVersion = + contribListing.getAdvertisedContribution(this); + + if (advertisedVersion == null) { + contribListing.removeContribution(this); + } else { + contribListing.replaceContribution(this, advertisedVersion); + } + } else { + // There was a failure backing up the folder + if (!doBackup) { + statusBar.setErrorMessage("Could not delete the contribution's files"); + } + } } - if (!backupFolder.exists() && !backupFolder.mkdirs()) { - status.setErrorMessage("Could not create a " + type + " backup folder."); - return null; - } - return backupFolder; + ContributionManager.refreshInstalled(editor); + pm.finished(); } @@ -316,6 +351,33 @@ public abstract class InstalledContribution extends Contribution { public boolean isInstalled() { return folder != null; } + + + boolean setDeletionFlag() { + // Only returns false if the file already exists, so we can + // ignore the return value. + try { + new File(getFolder(), DELETION_FLAG).createNewFile(); + return true; + } catch (IOException e) { + return false; + } + } + + + boolean unsetDeletionFlag() { + return new File(getFolder(), DELETION_FLAG).delete(); + } + + + boolean isDeletionFlagged() { + return isDeletionFlagged(getFolder()); + } + + + static boolean isDeletionFlagged(File folder) { + return new File(folder, DELETION_FLAG).exists(); + } // public String getCategory() { From b52563aed22fdb9da8dc097b2c549612d5465bde Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 16 Feb 2013 19:32:01 -0500 Subject: [PATCH 04/10] added mode to primitive PShape of type ARC --- core/src/processing/opengl/PGraphics2D.java | 2 +- core/src/processing/opengl/PGraphics3D.java | 2 +- core/src/processing/opengl/PShapeOpenGL.java | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/processing/opengl/PGraphics2D.java b/core/src/processing/opengl/PGraphics2D.java index 7b5bf9f0a..21a516554 100644 --- a/core/src/processing/opengl/PGraphics2D.java +++ b/core/src/processing/opengl/PGraphics2D.java @@ -389,7 +389,7 @@ public class PGraphics2D extends PGraphicsOpenGL { shape = new PShapeOpenGL(parent, PShape.PRIMITIVE); shape.setKind(ELLIPSE); } else if (kind == ARC) { - if (len != 6) { + if (len != 6 && len != 7) { showWarning("Wrong number of parameters"); return null; } diff --git a/core/src/processing/opengl/PGraphics3D.java b/core/src/processing/opengl/PGraphics3D.java index 1e0e4f12c..0880651cc 100644 --- a/core/src/processing/opengl/PGraphics3D.java +++ b/core/src/processing/opengl/PGraphics3D.java @@ -260,7 +260,7 @@ public class PGraphics3D extends PGraphicsOpenGL { shape = new PShapeOpenGL(parent, PShape.PRIMITIVE); shape.setKind(ELLIPSE); } else if (kind == ARC) { - if (len != 6) { + if (len != 6 && len != 7) { showWarning("Wrong number of parameters"); return null; } diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 4de45355d..2c22e7149 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -3416,7 +3416,7 @@ public class PShapeOpenGL extends PShape { d = params[3]; } - ellipseMode = CORNER; +// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); @@ -3428,20 +3428,24 @@ public class PShapeOpenGL extends PShape { protected void tessellateArc() { float a = 0, b = 0, c = 0, d = 0; float start = 0, stop = 0; - if (params.length == 6) { + int mode = 0; + if (params.length == 6 || params.length == 7) { a = params[0]; b = params[1]; c = params[2]; d = params[3]; start = params[4]; stop = params[5]; + if (params.length == 7) { + mode = (int)(params[6]); + } } - ellipseMode = CORNER; +// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addArc(a, b, c, d, start, stop, fill, stroke, ellipseMode); + inGeo.addArc(a, b, c, d, start, stop, fill, stroke, mode); tessellator.tessellateTriangleFan(); } From 96c811e11c461306d8655d6494c5c2d9fa9df20b Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 17 Feb 2013 07:26:45 -0500 Subject: [PATCH 05/10] fix for crash on startup --- .../app/contrib/ContributionManagerDialog.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/processing/app/contrib/ContributionManagerDialog.java b/app/src/processing/app/contrib/ContributionManagerDialog.java index e985d0c72..60b75d49e 100644 --- a/app/src/processing/app/contrib/ContributionManagerDialog.java +++ b/app/src/processing/app/contrib/ContributionManagerDialog.java @@ -44,7 +44,7 @@ public class ContributionManagerDialog { JFrame dialog; String title; - Filter permaFilter; + Filter filter; JComboBox categoryChooser; JScrollPane scrollPane; ContributionListPanel contributionListPanel; @@ -58,11 +58,14 @@ public class ContributionManagerDialog { public ContributionManagerDialog(ContributionType type) { - this.title = type.getTitle() + " Manager"; - this.permaFilter = ContributionListing.createFilter(type); - + if (type == null) { + title = "Update Manager"; + } else { + title = type.getTitle() + " Manager"; + } + filter = ContributionListing.createFilter(type); contribListing = ContributionListing.getInstance(); - contributionListPanel = new ContributionListPanel(this, permaFilter); + contributionListPanel = new ContributionListPanel(this, filter); contribListing.addContributionListener(contributionListPanel); } @@ -245,7 +248,7 @@ public class ContributionManagerDialog { if (categoryChooser != null) { ArrayList categories; categoryChooser.removeAllItems(); - categories = new ArrayList(contribListing.getCategories(permaFilter)); + categories = new ArrayList(contribListing.getCategories(filter)); // for (int i = 0; i < categories.size(); i++) { // System.out.println(i + " category: " + categories.get(i)); // } From c6f6dd65768429eae704433f5000b6bd6810cf48 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 17 Feb 2013 08:28:21 -0500 Subject: [PATCH 06/10] more work on contrib manager, still not ready --- app/src/processing/app/Base.java | 33 ++++ app/src/processing/app/Library.java | 2 +- ...bution.java => AvailableContribution.java} | 145 +++--------------- .../app/contrib/ContributionListPanel.java | 26 ++-- .../app/contrib/ContributionListing.java | 31 ++-- .../app/contrib/ContributionManager.java | 6 +- .../contrib/ContributionManagerDialog.java | 84 +++++----- .../app/contrib/ContributionType.java | 6 +- ...ntribution.java => LocalContribution.java} | 14 +- .../app/contrib/ModeContribution.java | 2 +- .../app/contrib/ProgressMonitor.java | 2 +- .../app/contrib/ToolContribution.java | 2 +- core/todo.txt | 7 + 13 files changed, 150 insertions(+), 210 deletions(-) rename app/src/processing/app/contrib/{AdvertisedContribution.java => AvailableContribution.java} (53%) rename app/src/processing/app/contrib/{InstalledContribution.java => LocalContribution.java} (94%) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 7a74c188c..5eb66ca64 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -2883,6 +2883,39 @@ public class Base { } } } + + + static public void unzip(File zipFile, File dest) { + try { + FileInputStream fis = new FileInputStream(zipFile); + CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32()); + ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); + ZipEntry next = null; + while ((next = zis.getNextEntry()) != null) { + File currentFile = new File(dest, next.getName()); + if (next.isDirectory()) { + currentFile.mkdirs(); + } else { + currentFile.createNewFile(); + unzipEntry(zis, currentFile); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + static protected void unzipEntry(ZipInputStream zin, File f) throws IOException { + FileOutputStream out = new FileOutputStream(f); + byte[] b = new byte[512]; + int len = 0; + while ((len = zin.read(b)) != -1) { + out.write(b, 0, len); + } + out.flush(); + out.close(); + } static public void log(Object from, String message) { diff --git a/app/src/processing/app/Library.java b/app/src/processing/app/Library.java index fbe3d82e6..2520bea15 100644 --- a/app/src/processing/app/Library.java +++ b/app/src/processing/app/Library.java @@ -7,7 +7,7 @@ import processing.app.contrib.*; import processing.core.*; -public class Library extends InstalledContribution { +public class Library extends LocalContribution { static final String[] platformNames = PConstants.platformNames; //protected File folder; // /path/to/shortname diff --git a/app/src/processing/app/contrib/AdvertisedContribution.java b/app/src/processing/app/contrib/AvailableContribution.java similarity index 53% rename from app/src/processing/app/contrib/AdvertisedContribution.java rename to app/src/processing/app/contrib/AvailableContribution.java index 1fb2544ca..dfd813f83 100644 --- a/app/src/processing/app/contrib/AdvertisedContribution.java +++ b/app/src/processing/app/contrib/AvailableContribution.java @@ -23,71 +23,45 @@ package processing.app.contrib; import java.io.*; import java.util.HashMap; -import java.util.zip.Adler32; -import java.util.zip.CheckedInputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; import processing.app.Base; import processing.app.Editor; import processing.core.PApplet; -class AdvertisedContribution extends Contribution { +/** + * A class to hold information about a Contribution that can be downloaded. + */ +class AvailableContribution extends Contribution { protected final ContributionType type; // Library, tool, etc. protected final String link; // Direct link to download the file - -// protected final String category; // "Sound" -// protected final String name; // "pdf" or "PDF Export" -// protected final String authorList; // [Ben Fry](http://benfry.com/) -// protected final String url; // http://processing.org -// protected final String sentence; // Write graphics to PDF files. -// protected final String paragraph; // -// protected final int version; // 102 -// protected final String prettyVersion; // "1.0.2" - public AdvertisedContribution(ContributionType type, HashMap exports) { - + public AvailableContribution(ContributionType type, HashMap params) { this.type = type; - name = exports.get("name"); - category = ContributionListing.getCategory(exports.get("category")); - authorList = exports.get("authorList"); - - url = exports.get("url"); - sentence = exports.get("sentence"); - paragraph = exports.get("paragraph"); - - int v = 0; - try { - v = Integer.parseInt(exports.get("version")); - } catch (NumberFormatException e) { - } - version = v; - - prettyVersion = exports.get("prettyVersion"); - - this.link = exports.get("download"); + this.link = params.get("download"); + + category = ContributionListing.getCategory(params.get("category")); + name = params.get("name"); + authorList = params.get("authorList"); + url = params.get("url"); + sentence = params.get("sentence"); + paragraph = params.get("paragraph"); + version = PApplet.parseInt(params.get("version"), 0); + prettyVersion = params.get("prettyVersion"); } /** * @param contribArchive * a zip file containing the library to install - * @param ad - * the advertised version of this library, if it was downloaded - * through the Contribution Manager. This is used to check the type - * of library being installed, and to replace the .properties file in - * the zip * @param confirmReplace * true to open a dialog asking the user to confirm removing/moving * the library when a library by the same name already exists * @return */ - public InstalledContribution install(Editor editor, File contribArchive, - boolean confirmReplace, - ErrorWidget statusBar) { - + public LocalContribution install(Editor editor, File contribArchive, + boolean confirmReplace, ErrorWidget status) { // Unzip the file into the modes, tools, or libraries folder inside the // sketchbook. Unzipping to /tmp is problematic because it may be on // another file system, so move/rename operations will break. @@ -98,10 +72,10 @@ class AdvertisedContribution extends Contribution { tempFolder = Base.createTempFolder(type.toString(), "tmp", sketchbookContribFolder); } catch (IOException e) { - statusBar.setErrorMessage("Could not create a temporary folder to install."); + status.setErrorMessage("Could not create a temporary folder to install."); return null; } - unzip(contribArchive, tempFolder); + Base.unzip(contribArchive, tempFolder); // Now go looking for a legit contrib inside what's been unpacked. File contribFolder = null; @@ -117,26 +91,26 @@ class AdvertisedContribution extends Contribution { contribFolder = type.findCandidate(tempFolder); } - InstalledContribution installedContrib = null; + LocalContribution installedContrib = null; if (contribFolder == null) { - statusBar.setErrorMessage("Could not find a " + type + " in the downloaded file."); + status.setErrorMessage("Could not find a " + type + " in the downloaded file."); } else { File propFile = new File(contribFolder, type + ".properties"); if (!writePropertiesFile(propFile)) { // 1. contribFolder now has a legit contribution, load it to get info. - InstalledContribution newContrib = + LocalContribution newContrib = type.load(editor.getBase(), contribFolder); // 2. Check to make sure nothing has the same name already, // backup old if needed, then move things into place and reload. installedContrib = - newContrib.moveAndLoad(editor, confirmReplace, statusBar); + newContrib.moveAndLoad(editor, confirmReplace, status); } else { - statusBar.setErrorMessage("Error overwriting .properties file."); + status.setErrorMessage("Error overwriting .properties file."); } } @@ -148,39 +122,6 @@ class AdvertisedContribution extends Contribution { } - static private void unzip(File zipFile, File dest) { - try { - FileInputStream fis = new FileInputStream(zipFile); - CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32()); - ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); - ZipEntry next = null; - while ((next = zis.getNextEntry()) != null) { - File currentFile = new File(dest, next.getName()); - if (next.isDirectory()) { - currentFile.mkdirs(); - } else { - currentFile.createNewFile(); - unzipEntry(zis, currentFile); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - - static private void unzipEntry(ZipInputStream zin, File f) throws IOException { - FileOutputStream out = new FileOutputStream(f); - byte[] b = new byte[512]; - int len = 0; - while ((len = zin.read(b)) != -1) { - out.write(b, 0, len); - } - out.flush(); - out.close(); - } - - public boolean isInstalled() { return false; } @@ -190,43 +131,6 @@ class AdvertisedContribution extends Contribution { return type; } - -// public String getTypeName() { -// return type.toString(); -// } -// -// public String getCategory() { -// return category; -// } -// -// public String getName() { -// return name; -// } -// -// public String getAuthorList() { -// return authorList; -// } -// -// public String getUrl() { -// return url; -// } -// -// public String getSentence() { -// return sentence; -// } -// -// public String getParagraph() { -// return paragraph; -// } -// -// public int getVersion() { -// return version; -// } -// -// public String getPrettyVersion() { -// return prettyVersion; -// } - /** * We overwrite the properties file with the curated version from the @@ -239,7 +143,6 @@ class AdvertisedContribution extends Contribution { public boolean writePropertiesFile(File propFile) { try { if (propFile.delete() && propFile.createNewFile() && propFile.setWritable(true)) { - //BufferedWriter bw = new BufferedWriter(new FileWriter(propFile)); PrintWriter writer = PApplet.createWriter(propFile); writer.println("name=" + getName()); diff --git a/app/src/processing/app/contrib/ContributionListPanel.java b/app/src/processing/app/contrib/ContributionListPanel.java index 099ac5d5a..224299a41 100644 --- a/app/src/processing/app/contrib/ContributionListPanel.java +++ b/app/src/processing/app/contrib/ContributionListPanel.java @@ -453,16 +453,16 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib installActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { - if (contrib instanceof AdvertisedContribution) { - installContribution((AdvertisedContribution) contrib); + if (contrib instanceof AvailableContribution) { + installContribution((AvailableContribution) contrib); } } }; undoActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { - if (contrib instanceof InstalledContribution) { - InstalledContribution installed = (InstalledContribution) contrib; + if (contrib instanceof LocalContribution) { + LocalContribution installed = (LocalContribution) contrib; installed.unsetDeletionFlag(); contribListing.replaceContribution(contrib, contrib); // ?? } @@ -471,13 +471,13 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib removeActionListener = new ActionListener() { public void actionPerformed(ActionEvent arg) { - if (contrib.isInstalled() && contrib instanceof InstalledContribution) { + if (contrib.isInstalled() && contrib instanceof LocalContribution) { updateButton.setEnabled(false); installRemoveButton.setEnabled(false); installProgressBar.setVisible(true); - ((InstalledContribution) contrib).removeContribution(contribManager.editor, + ((LocalContribution) contrib).removeContribution(contribManager.editor, new JProgressMonitor(installProgressBar) { public void finishedAction() { // Finished uninstalling the library @@ -494,8 +494,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib openFolder = new JMenuItem("Open Folder"); openFolder.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if (contrib instanceof InstalledContribution) { - File folder = ((InstalledContribution) contrib).getFolder(); + if (contrib instanceof LocalContribution) { + File folder = ((LocalContribution) contrib).getFolder(); Base.openFolder(folder); } } @@ -618,7 +618,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib public void actionPerformed(ActionEvent e) { updateButton.setEnabled(false); - AdvertisedContribution ad = contribListing + AvailableContribution ad = contribListing .getAdvertisedContribution(contrib); String url = ad.link; installContribution(ad, url); @@ -785,7 +785,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } - private void installContribution(AdvertisedContribution info) { + private void installContribution(AvailableContribution info) { if (info.link == null) { contribManager.statusBar.setErrorMessage("Your operating system " + "doesn't appear to be supported. You should visit the " @@ -795,7 +795,7 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib } } - private void installContribution(AdvertisedContribution ad, String url) { + private void installContribution(AvailableContribution ad, String url) { installRemoveButton.setEnabled(false); @@ -932,8 +932,8 @@ public class ContributionListPanel extends JPanel implements Scrollable, Contrib if (doc instanceof HTMLDocument) { HTMLDocument html = (HTMLDocument) doc; StyleSheet stylesheet = html.getStyleSheet(); - stylesheet.addRule("body {color:" + PApplet.hex(fg.getRGB()).substring(8) + ";}"); - stylesheet.addRule("a {color:" + PApplet.hex(fg.getRGB()).substring(8) + "}"); + stylesheet.addRule("body {color:" + PApplet.hex(fg.getRGB()).substring(2) + ";}"); + stylesheet.addRule("a {color:" + PApplet.hex(fg.getRGB()).substring(2) + "}"); } } } diff --git a/app/src/processing/app/contrib/ContributionListing.java b/app/src/processing/app/contrib/ContributionListing.java index 888538b80..4aca86d34 100644 --- a/app/src/processing/app/contrib/ContributionListing.java +++ b/app/src/processing/app/contrib/ContributionListing.java @@ -36,7 +36,7 @@ public class ContributionListing { File listingFile; ArrayList listeners; - ArrayList advertisedContributions; + ArrayList advertisedContributions; Map> librariesByCategory; ArrayList allContributions; boolean hasDownloadedLatestList; @@ -53,7 +53,7 @@ public class ContributionListing { private ContributionListing() { listeners = new ArrayList(); - advertisedContributions = new ArrayList(); + advertisedContributions = new ArrayList(); librariesByCategory = new HashMap>(); allContributions = new ArrayList(); downloadingListingLock = new ReentrantLock(); @@ -82,7 +82,6 @@ public class ContributionListing { for (Contribution contribution : advertisedContributions) { addContribution(contribution); } - Collections.sort(allContributions, contribComparator); } @@ -170,8 +169,8 @@ public class ContributionListing { } - public AdvertisedContribution getAdvertisedContribution(Contribution info) { - for (AdvertisedContribution advertised : advertisedContributions) { + public AvailableContribution getAdvertisedContribution(Contribution info) { + for (AvailableContribution advertised : advertisedContributions) { if (advertised.getType() == info.getType() && advertised.getName().equals(info.getName())) { return advertised; @@ -487,11 +486,11 @@ public class ContributionListing { } - ArrayList parseContribList(File f) { - ArrayList outgoing = new ArrayList(); + ArrayList parseContribList(File file) { + ArrayList outgoing = new ArrayList(); - if (f != null && f.exists()) { - String lines[] = PApplet.loadStrings(f); + if (file != null && file.exists()) { + String lines[] = PApplet.loadStrings(file); int start = 0; while (start < lines.length) { @@ -516,9 +515,9 @@ public class ContributionListing { System.arraycopy(lines, start, contribLines, 0, length); HashMap contribParams = new HashMap(); - Base.readSettings(f.getName(), contribLines, contribParams); + Base.readSettings(file.getName(), contribLines, contribParams); - outgoing.add(new AdvertisedContribution(contribType, contribParams)); + outgoing.add(new AvailableContribution(contribType, contribParams)); start = end + 1; // } else { // start++; @@ -547,16 +546,16 @@ public class ContributionListing { if (type == null) { return new Filter() { public boolean matches(Contribution contrib) { - return contrib.getType() == type; + if (contrib instanceof LocalContribution) { + return ContributionListing.getInstance().hasUpdates(contrib); + } + return false; } }; } else { return new Filter() { public boolean matches(Contribution contrib) { - if (contrib instanceof InstalledContribution) { - return ContributionListing.getInstance().hasUpdates(contrib); - } - return false; + return contrib.getType() == type; } }; } diff --git a/app/src/processing/app/contrib/ContributionManager.java b/app/src/processing/app/contrib/ContributionManager.java index 2bf8b6f41..26ef4c2a6 100644 --- a/app/src/processing/app/contrib/ContributionManager.java +++ b/app/src/processing/app/contrib/ContributionManager.java @@ -54,7 +54,7 @@ public class ContributionManager { */ static void downloadAndInstall(final Editor editor, final URL url, - final AdvertisedContribution ad, + final AvailableContribution ad, final JProgressMonitor downloadProgress, final JProgressMonitor installProgress, final ErrorWidget statusBar) { @@ -72,7 +72,7 @@ public class ContributionManager { if (!downloadProgress.isCanceled() && !downloadProgress.isError()) { installProgress.startTask("Installing...", ProgressMonitor.UNKNOWN); - InstalledContribution contribution = + LocalContribution contribution = ad.install(editor, contribZip, false, statusBar); if (contribution != null) { @@ -533,7 +533,7 @@ public class ContributionManager { File[] markedForDeletion = root.listFiles(new FileFilter() { public boolean accept(File folder) { return (folder.isDirectory() && - InstalledContribution.isDeletionFlagged(folder)); + LocalContribution.isDeletionFlagged(folder)); } }); for (File folder : markedForDeletion) { diff --git a/app/src/processing/app/contrib/ContributionManagerDialog.java b/app/src/processing/app/contrib/ContributionManagerDialog.java index 60b75d49e..3b7318a5e 100644 --- a/app/src/processing/app/contrib/ContributionManagerDialog.java +++ b/app/src/processing/app/contrib/ContributionManagerDialog.java @@ -39,7 +39,6 @@ import processing.app.contrib.ContributionListing.Filter; public class ContributionManagerDialog { - static final String ANY_CATEGORY = "All"; JFrame dialog; @@ -116,10 +115,10 @@ public class ContributionManagerDialog { } }); } - updateContributionListing(); } + /** * Close the window after an OK or Cancel. */ @@ -127,6 +126,7 @@ public class ContributionManagerDialog { dialog.dispose(); editor = null; } + /** Creates and arranges the Swing components in the dialog. */ private void createComponents() { @@ -243,6 +243,7 @@ public class ContributionManagerDialog { dialog.setMinimumSize(new Dimension(450, 400)); } + private void updateCategoryChooser() { if (categoryChooser != null) { @@ -262,6 +263,7 @@ public class ContributionManagerDialog { } } + private void registerDisposeListeners() { dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { @@ -289,19 +291,17 @@ public class ContributionManagerDialog { }); } - public void filterLibraries(String category, List filters) { - - List filteredLibraries = contribListing - .getFilteredLibraryList(category, filters); - + + protected void filterLibraries(String category, List filters) { + List filteredLibraries = + contribListing.getFilteredLibraryList(category, filters); contributionListPanel.filterLibraries(filteredLibraries); } + protected void updateContributionListing() { - if (editor == null) - return; - - ArrayList libraries = new ArrayList(editor.getMode().contribLibraries); + if (editor != null) { + ArrayList libraries = new ArrayList(editor.getMode().contribLibraries); // ArrayList compilations = LibraryCompilation.list(libraries); // // // Remove libraries from the list that are part of a compilations @@ -315,65 +315,63 @@ public class ContributionManagerDialog { // } // } - ArrayList contributions = new ArrayList(); - contributions.addAll(editor.contribTools); - contributions.addAll(libraries); + ArrayList contributions = new ArrayList(); + contributions.addAll(editor.contribTools); + contributions.addAll(libraries); // contributions.addAll(compilations); - contribListing.updateInstalledList(contributions); + contribListing.updateInstalledList(contributions); + } } - public void setFilterText(String filter) { + + protected void setFilterText(String filter) { if (filter == null || filter.isEmpty()) { filterField.setText(""); - filterField.isShowingHint = true; + filterField.showingHint = true; } else { filterField.setText(filter); - filterField.isShowingHint = false; + filterField.showingHint = false; } filterField.applyFilter(); - } + + + protected JPanel getPlaceholder() { + return contributionListPanel.statusPlaceholder; + } + class FilterField extends JTextField { - final static String filterHint = "Filter your search..."; - - boolean isShowingHint; - + boolean showingHint; List filters; public FilterField () { super(filterHint); - - isShowingHint = true; - + + showingHint = true; filters = new ArrayList(); - updateStyle(); addFocusListener(new FocusListener() { - public void focusLost(FocusEvent focusEvent) { if (filterField.getText().isEmpty()) { - isShowingHint = true; + showingHint = true; } - updateStyle(); } public void focusGained(FocusEvent focusEvent) { - if (isShowingHint) { - isShowingHint = false; + if (showingHint) { + showingHint = false; filterField.setText(""); } - updateStyle(); } }); getDocument().addDocumentListener(new DocumentListener() { - public void removeUpdate(DocumentEvent e) { applyFilter(); } @@ -399,11 +397,11 @@ public class ContributionManagerDialog { } public String getFilterText() { - return isShowingHint ? "" : getText(); + return showingHint ? "" : getText(); } public void updateStyle() { - if (isShowingHint) { + if (showingHint) { setText(filterHint); // setForeground(UIManager.getColor("TextField.light")); // too light @@ -416,12 +414,13 @@ public class ContributionManagerDialog { } } + public boolean hasAlreadyBeenOpened() { return dialog != null; } + class StatusPanel extends JPanel implements ErrorWidget { - String errorMessage; StatusPanel() { @@ -457,27 +456,22 @@ public class ContributionManagerDialog { errorMessage = message; setVisible(true); - JPanel placeholder = ContributionManagerDialog.this.contributionListPanel.statusPlaceholder; + JPanel placeholder = getPlaceholder(); Dimension d = getPreferredSize(); if (Base.isWindows()) { d.height += 5; placeholder.setPreferredSize(d); } placeholder.setVisible(true); - -// Rectangle rect = scrollPane.getViewport().getViewRect(); -// rect.x += d.height; -// scrollPane.getViewport().scrollRectToVisible(rect); } void clearErrorMessage() { errorMessage = null; repaint(); - ContributionManagerDialog.this.contributionListPanel.statusPlaceholder - .setVisible(false); + getPlaceholder().setVisible(false); } - } + } } diff --git a/app/src/processing/app/contrib/ContributionType.java b/app/src/processing/app/contrib/ContributionType.java index 76b31eef9..13db53832 100644 --- a/app/src/processing/app/contrib/ContributionType.java +++ b/app/src/processing/app/contrib/ContributionType.java @@ -146,7 +146,7 @@ public enum ContributionType { } - InstalledContribution load(Base base, File folder) { + LocalContribution load(Base base, File folder) { switch (this) { case LIBRARY: return new Library(folder); @@ -159,8 +159,8 @@ public enum ContributionType { } - ArrayList listContributions(Editor editor) { - ArrayList contribs = new ArrayList(); + ArrayList listContributions(Editor editor) { + ArrayList contribs = new ArrayList(); switch (this) { case LIBRARY: contribs.addAll(editor.getMode().contribLibraries); diff --git a/app/src/processing/app/contrib/InstalledContribution.java b/app/src/processing/app/contrib/LocalContribution.java similarity index 94% rename from app/src/processing/app/contrib/InstalledContribution.java rename to app/src/processing/app/contrib/LocalContribution.java index 5475cd20a..7a71e23ac 100644 --- a/app/src/processing/app/contrib/InstalledContribution.java +++ b/app/src/processing/app/contrib/LocalContribution.java @@ -33,7 +33,11 @@ import javax.swing.JOptionPane; import processing.app.*; -public abstract class InstalledContribution extends Contribution { +/** + * A contribution that has been downloaded to the disk, and may or may not + * be installed. + */ +public abstract class LocalContribution extends Contribution { static public final String DELETION_FLAG = "flagged_for_deletion"; protected String id; // 1 @@ -43,7 +47,7 @@ public abstract class InstalledContribution extends Contribution { protected ClassLoader loader; - public InstalledContribution(File folder) { + public LocalContribution(File folder) { this.folder = folder; // required for contributed modes, but not for built-in core modes @@ -178,10 +182,10 @@ public abstract class InstalledContribution extends Contribution { // } - InstalledContribution moveAndLoad(Editor editor, + LocalContribution moveAndLoad(Editor editor, boolean confirmReplace, ErrorWidget statusBar) { - ArrayList oldContribs = + ArrayList oldContribs = getType().listContributions(editor); String contribFolderName = getFolder().getName(); @@ -189,7 +193,7 @@ public abstract class InstalledContribution extends Contribution { File contribTypeFolder = getType().getSketchbookFolder(); File contribFolder = new File(contribTypeFolder, contribFolderName); - for (InstalledContribution oldContrib : oldContribs) { + for (LocalContribution oldContrib : oldContribs) { if ((oldContrib.getFolder().exists() && oldContrib.getFolder().equals(contribFolder)) || (oldContrib.getId() != null && oldContrib.getId().equals(getId()))) { diff --git a/app/src/processing/app/contrib/ModeContribution.java b/app/src/processing/app/contrib/ModeContribution.java index 249f6d777..44290d006 100644 --- a/app/src/processing/app/contrib/ModeContribution.java +++ b/app/src/processing/app/contrib/ModeContribution.java @@ -30,7 +30,7 @@ import processing.app.Base; import processing.app.Mode; -public class ModeContribution extends InstalledContribution { +public class ModeContribution extends LocalContribution { private Mode mode; diff --git a/app/src/processing/app/contrib/ProgressMonitor.java b/app/src/processing/app/contrib/ProgressMonitor.java index e3f55687c..78566cc5d 100644 --- a/app/src/processing/app/contrib/ProgressMonitor.java +++ b/app/src/processing/app/contrib/ProgressMonitor.java @@ -88,9 +88,9 @@ public interface ProgressMonitor { * task was cancelled. */ public void finished(); - } + abstract class AbstractProgressMonitor implements ProgressMonitor { boolean isCanceled = false; diff --git a/app/src/processing/app/contrib/ToolContribution.java b/app/src/processing/app/contrib/ToolContribution.java index 55b4c70d8..94715497e 100644 --- a/app/src/processing/app/contrib/ToolContribution.java +++ b/app/src/processing/app/contrib/ToolContribution.java @@ -31,7 +31,7 @@ import processing.app.Editor; import processing.app.tools.Tool; -public class ToolContribution extends InstalledContribution implements Tool { +public class ToolContribution extends LocalContribution implements Tool { private Tool tool; diff --git a/core/todo.txt b/core/todo.txt index 0249b4de2..5a9d0c3ab 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -73,6 +73,13 @@ A https://github.com/processing/processing/issues/1598 X http://code.google.com/p/processing/issues/detail?id=1560 A disable stroke perspective by default (but this didn't fix it) A fixed the disappearance, though still imperfect +A Fix get()/set() problems with images and OpenGL +A https://github.com/processing/processing/issues/1613 +X http://code.google.com/p/processing/issues/detail?id=1575 +o arc with large strokeWeight is very slow in P2D renderer +A marked WontFix, workaround is to create a PShape +A https://github.com/processing/processing/issues/1583 +A http://code.google.com/p/processing/issues/detail?id=1545 cleaning/earlier C textureWrap() CLAMP and REPEAT now added From 5c01de03ac302a44242e37f579e7b833d77f72cc Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 17 Feb 2013 09:54:56 -0500 Subject: [PATCH 07/10] fixed issue with transparency and PShader filters --- core/src/processing/opengl/PGL.java | 38 +++++++++++++------ .../processing/opengl/PGraphicsOpenGL.java | 7 +++- core/src/processing/opengl/Texture.java | 4 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 004a65b94..7bb8e7929 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -61,8 +61,6 @@ import processing.event.MouseEvent; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.event.InputEvent; -import com.jogamp.newt.event.WindowEvent; -import com.jogamp.newt.event.WindowUpdateEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.FBObject; import com.jogamp.opengl.util.AnimatorBase; @@ -630,6 +628,7 @@ public class PGL { canvasAWT = new GLCanvas(caps); canvasAWT.setBounds(0, 0, pg.width, pg.height); canvasAWT.setBackground(new Color(pg.backgroundColor, true)); + canvasAWT.setFocusable(true); pg.parent.setLayout(new BorderLayout()); pg.parent.add(canvasAWT, BorderLayout.CENTER); @@ -651,9 +650,7 @@ public class PGL { canvasNEWT = new NewtCanvasAWT(window); canvasNEWT.setBounds(0, 0, pg.width, pg.height); canvasNEWT.setBackground(new Color(pg.backgroundColor, true)); - - pg.parent.setLayout(new BorderLayout()); - pg.parent.add(canvasNEWT, BorderLayout.CENTER); + canvasNEWT.setFocusable(true); NEWTMouseListener mouseListener = new NEWTMouseListener(); window.addMouseListener(mouseListener); @@ -663,6 +660,9 @@ public class PGL { window.addWindowListener(winListener); canvasNEWT.addFocusListener(pg.parent); // So focus detection work. + pg.parent.setLayout(new BorderLayout()); + pg.parent.add(canvasNEWT, BorderLayout.CENTER); + capabilities = window.getChosenGLCapabilities(); canvas = canvasNEWT; canvasAWT = null; @@ -3237,6 +3237,7 @@ public class PGL { protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent, int peAction) { + if (!hasFocus) return; int modifiers = nativeEvent.getModifiers(); int peModifiers = modifiers & (InputEvent.SHIFT_MASK | @@ -3296,31 +3297,44 @@ public class PGL { pg.parent.postEvent(ke); } + boolean hasFocus = true; class NEWTWindowListener implements com.jogamp.newt.event.WindowListener { @Override - public void windowGainedFocus(WindowEvent arg0) { + public void windowGainedFocus(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("window gained focus"); pg.parent.focusGained(null); + hasFocus = true; } @Override - public void windowLostFocus(WindowEvent arg0) { + public void windowLostFocus(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("window lost focus"); pg.parent.focusLost(null); + hasFocus = false; } @Override - public void windowDestroyNotify(WindowEvent arg0) { } + public void windowDestroyNotify(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("destroy"); + } @Override - public void windowDestroyed(WindowEvent arg0) { } + public void windowDestroyed(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("destroyed"); + } @Override - public void windowMoved(WindowEvent arg0) { } + public void windowMoved(com.jogamp.newt.event.WindowEvent arg0) { + PApplet.println("moved"); + } @Override - public void windowRepaint(WindowUpdateEvent arg0) { } + public void windowRepaint(com.jogamp.newt.event.WindowUpdateEvent arg0) { + PApplet.println("window repaint"); + } @Override - public void windowResized(WindowEvent arg0) { } + public void windowResized(com.jogamp.newt.event.WindowEvent arg0) { } } // NEWT mouse listener diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 75826ed70..8e26e9999 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -4971,8 +4971,8 @@ public class PGraphicsOpenGL extends PGraphics { // color buffer into it. @Override public void loadPixels() { - if (sized) { - // Something wrong going on with threading, sized can never be true if the + if (primarySurface && sized) { + // Something wrong going on with threading, sized can never be true if // all the steps in a resize happen inside the Animation thread. return; } @@ -5397,6 +5397,8 @@ public class PGraphicsOpenGL extends PGraphics { textureMode = NORMAL; boolean prevStroke = stroke; stroke = false; +// int prevBlendMode = blendMode; +// blendMode(REPLACE); PolyTexShader prevTexShader = polyTexShader; polyTexShader = (PolyTexShader) shader; beginShape(QUADS); @@ -5414,6 +5416,7 @@ public class PGraphicsOpenGL extends PGraphics { stroke = prevStroke; lights = prevLights; textureMode = prevTextureMode; +// blendMode(prevBlendMode); if (!hints[DISABLE_DEPTH_TEST]) { pgl.enable(PGL.DEPTH_TEST); diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index f4eacf60a..32d9a648f 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -328,7 +328,6 @@ public class Texture implements PConstants { public void set(int[] pixels, int x, int y, int w, int h, int format) { if (pixels == null) { - pixels = null; PGraphics.showWarning("The pixels array is null."); return; } @@ -1283,6 +1282,9 @@ public class Texture implements PConstants { // FBO copy: pg.pushFramebuffer(); pg.setFramebuffer(tempFbo); + // Clear the color buffer to make sure that the alpha of the + pgl.clearColor(0, 0, 0, 0); + pgl.clear(PGL.COLOR_BUFFER_BIT); if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. From 76f3f807ffe336531209672a66f3366f3b6cae73 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 17 Feb 2013 12:30:01 -0500 Subject: [PATCH 08/10] set default ambient color from fill --- core/src/processing/core/PShape.java | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index 2fa801684..5865a026f 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -653,6 +653,11 @@ public class PShape implements PConstants { } fill = false; + fillColor = 0x0; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -665,6 +670,10 @@ public class PShape implements PConstants { fill = true; colorCalc(rgb); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -677,6 +686,10 @@ public class PShape implements PConstants { fill = true; colorCalc(rgb, alpha); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -689,6 +702,10 @@ public class PShape implements PConstants { fill = true; colorCalc(gray); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -701,6 +718,15 @@ public class PShape implements PConstants { fill = true; colorCalc(gray, alpha); fillColor = calcColor; + + if (!setAmbient) { + ambient(fillColor); + setAmbient = false; + } + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -713,6 +739,10 @@ public class PShape implements PConstants { fill = true; colorCalc(x, y, z); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } @@ -725,6 +755,10 @@ public class PShape implements PConstants { fill = true; colorCalc(x, y, z, a); fillColor = calcColor; + + if (!setAmbient) { + ambientColor = fillColor; + } } From e6989c6be051ee1a7aedc6fe1c33a275b81024a7 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 17 Feb 2013 14:35:15 -0500 Subject: [PATCH 09/10] Fixes #1498 --- core/src/processing/opengl/PGL.java | 2 +- core/src/processing/opengl/PShapeOpenGL.java | 28 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 7bb8e7929..fb3c1bc42 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -3237,7 +3237,7 @@ public class PGL { protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent, int peAction) { - if (!hasFocus) return; +// if (!hasFocus) return; int modifiers = nativeEvent.getModifiers(); int peModifiers = modifiers & (InputEvent.SHIFT_MASK | diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 2c22e7149..0fd9209e6 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -4436,8 +4436,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyVertices(int offset, int size) { tessGeo.updatePolyVerticesBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyVertex); + tessGeo.polyVerticesBuffer.position(4 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, tessGeo.polyVerticesBuffer); + tessGeo.polyVerticesBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4445,8 +4447,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyColors(int offset, int size) { tessGeo.updatePolyColorsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyColor); + tessGeo.polyColorsBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.polyColorsBuffer); + tessGeo.polyColorsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4454,8 +4458,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyNormals(int offset, int size) { tessGeo.updatePolyNormalsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyNormal); + tessGeo.polyNormalsBuffer.position(3 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 3 * offset * PGL.SIZEOF_FLOAT, 3 * size * PGL.SIZEOF_FLOAT, tessGeo.polyNormalsBuffer); + tessGeo.polyNormalsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4463,8 +4469,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyTexcoords(int offset, int size) { tessGeo.updatePolyTexcoordsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyTexcoord); + tessGeo.polyTexcoordsBuffer.position(2 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT, tessGeo.polyTexcoordsBuffer); + tessGeo.polyTexcoordsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4472,8 +4480,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyAmbient(int offset, int size) { tessGeo.updatePolyAmbientBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyAmbient); + tessGeo.polyAmbientBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.polyAmbientBuffer); + tessGeo.polyAmbientBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4481,8 +4491,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolySpecular(int offset, int size) { tessGeo.updatePolySpecularBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolySpecular); + tessGeo.polySpecularBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.polySpecularBuffer); + tessGeo.polySpecularBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4490,8 +4502,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyEmissive(int offset, int size) { tessGeo.updatePolyEmissiveBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyEmissive); + tessGeo.polyEmissiveBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.polyEmissiveBuffer); + tessGeo.polyEmissiveBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4499,8 +4513,10 @@ public class PShapeOpenGL extends PShape { protected void copyPolyShininess(int offset, int size) { tessGeo.updatePolyShininessBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPolyShininess); + tessGeo.polyShininessBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_FLOAT, size * PGL.SIZEOF_FLOAT, tessGeo.polyShininessBuffer); + tessGeo.polyShininessBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4508,8 +4524,10 @@ public class PShapeOpenGL extends PShape { protected void copyLineVertices(int offset, int size) { tessGeo.updateLineVerticesBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineVertex); + tessGeo.lineVerticesBuffer.position(4 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, tessGeo.lineVerticesBuffer); + tessGeo.lineVerticesBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4517,8 +4535,10 @@ public class PShapeOpenGL extends PShape { protected void copyLineColors(int offset, int size) { tessGeo.updateLineColorsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineColor); + tessGeo.lineColorsBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT, tessGeo.lineColorsBuffer); + tessGeo.lineColorsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4526,8 +4546,10 @@ public class PShapeOpenGL extends PShape { protected void copyLineAttributes(int offset, int size) { tessGeo.updateLineAttribsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glLineAttrib); + tessGeo.lineAttribsBuffer.position(4 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, tessGeo.lineAttribsBuffer); + tessGeo.lineAttribsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4535,8 +4557,10 @@ public class PShapeOpenGL extends PShape { protected void copyPointVertices(int offset, int size) { tessGeo.updatePointVerticesBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointVertex); + tessGeo.pointVerticesBuffer.position(4 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 4 * offset * PGL.SIZEOF_FLOAT, 4 * size * PGL.SIZEOF_FLOAT, tessGeo.pointVerticesBuffer); + tessGeo.pointVerticesBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4544,8 +4568,10 @@ public class PShapeOpenGL extends PShape { protected void copyPointColors(int offset, int size) { tessGeo.updatePointColorsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointColor); + tessGeo.pointColorsBuffer.position(offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, offset * PGL.SIZEOF_INT, size * PGL.SIZEOF_INT,tessGeo.pointColorsBuffer); + tessGeo.pointColorsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } @@ -4553,8 +4579,10 @@ public class PShapeOpenGL extends PShape { protected void copyPointAttributes(int offset, int size) { tessGeo.updatePointAttribsBuffer(offset, size); pgl.bindBuffer(PGL.ARRAY_BUFFER, glPointAttrib); + tessGeo.pointAttribsBuffer.position(2 * offset); pgl.bufferSubData(PGL.ARRAY_BUFFER, 2 * offset * PGL.SIZEOF_FLOAT, 2 * size * PGL.SIZEOF_FLOAT, tessGeo.pointAttribsBuffer); + tessGeo.pointAttribsBuffer.rewind(); pgl.bindBuffer(PGL.ARRAY_BUFFER, 0); } From fea7ded2727c2c0724c6fed84f9671c4443bc4fe Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 17 Feb 2013 14:36:19 -0500 Subject: [PATCH 10/10] PShape.setStroke() uses color(255) in GroupPShape example --- .../Topics/Create Shapes/GroupPShape/GroupPShape.pde | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/java/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde b/java/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde index 05592f8ff..a8cbd0ab9 100644 --- a/java/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde +++ b/java/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde @@ -45,17 +45,15 @@ void setup() { // Make a primitive (Rectangle) PShape PShape rectangle = createShape(RECT,-10,-10,20,20); rectangle.setFill(false); - rectangle.setStroke(255); + rectangle.setStroke(color(255)); // Add them all to the group group.addChild(star); group.addChild(path); - group.addChild(rectangle); // Rectangle is missing??? - + group.addChild(rectangle); } void draw() { - // We can access them individually via the group PShape PShape rectangle = group.getChild(2); // Shapes can be rotated