From 7a719e1b5e152e1debb0b3c56d14dfecdcc242f2 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 5 Nov 2016 14:05:07 -0400 Subject: [PATCH] trying to clean up DetailPanel --- .../processing/app/contrib/DetailPanel.java | 132 +++++++----------- app/src/processing/app/ui/Toolkit.java | 12 +- core/src/processing/core/PApplet.java | 6 + core/todo.txt | 2 + java/src/processing/mode/java/Compiler.java | 4 +- todo.txt | 22 +-- 6 files changed, 85 insertions(+), 93 deletions(-) diff --git a/app/src/processing/app/contrib/DetailPanel.java b/app/src/processing/app/contrib/DetailPanel.java index 69adc841e..703e1b041 100644 --- a/app/src/processing/app/contrib/DetailPanel.java +++ b/app/src/processing/app/contrib/DetailPanel.java @@ -62,6 +62,8 @@ import processing.app.ui.Toolkit; * Panel that expands and gives a brief overview of a library when clicked. */ class DetailPanel extends JPanel { + Base base; + static public final String REMOVE_RESTART_MESSAGE = String.format("%s", Language.text("contrib.messages.remove_restart")); @@ -104,7 +106,9 @@ class DetailPanel extends JPanel { private JButton installRemoveButton; private JPopupMenu contextMenu; private JMenuItem openFolder; + private JPanel barButtonCardPane; + private CardLayout barButtonCardLayout; private ActionListener removeActionListener; private ActionListener installActionListener; @@ -123,6 +127,8 @@ class DetailPanel extends JPanel { } listPanel = contributionListPanel; + // TODO this accessor is dreadful + base = listPanel.contributionTab.editor.getBase(); barButtonCardPane = new JPanel(); enableHyperlinks = false; @@ -130,10 +136,8 @@ class DetailPanel extends JPanel { conditionalHyperlinkOpener = new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - if (enableHyperlinks) { - if (e.getURL() != null) { - Platform.openURL(e.getURL().toString()); - } + if (enableHyperlinks && e.getURL() != null) { + Platform.openURL(e.getURL().toString()); } } } @@ -228,26 +232,19 @@ class DetailPanel extends JPanel { if (UIManager.getLookAndFeel().getID().equals("Nimbus")) { descriptionPane.setBackground(new Color(0, 0, 0, 0)); } -// stripTextSelectionListeners(descriptionBlock); descriptionPane.setBorder(new EmptyBorder(4, 7, 7, 7)); descriptionPane.setHighlighter(null); add(descriptionPane, BorderLayout.CENTER); - JPanel updateBox = new JPanel(); //new BoxLayout(filterPanel, BoxLayout.X_AXIS) + JPanel updateBox = new JPanel(); updateBox.setLayout(new BorderLayout()); notificationLabel = new JLabel(); notificationLabel.setInheritsPopupMenu(true); notificationLabel.setVisible(false); notificationLabel.setOpaque(false); - // not needed after changing to JLabel -// notificationBlock.setContentType("text/html"); -// notificationBlock.setHighlighter(null); -// setTextStyle(notificationBlock); -// notificationLabel.setFont(new Font("Verdana", Font.ITALIC, 10)); notificationLabel.setFont(Toolkit.getSansFont(12, Font.PLAIN)); -// stripTextSelectionListeners(notificationBlock); { updateButton = new JButton("Update"); @@ -279,7 +276,8 @@ class DetailPanel extends JPanel { rightPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1)); add(rightPane, BorderLayout.EAST); - barButtonCardPane.setLayout(new CardLayout()); + barButtonCardLayout = new CardLayout(); + barButtonCardPane.setLayout(barButtonCardLayout); barButtonCardPane.setInheritsPopupMenu(true); barButtonCardPane.setOpaque(false); barButtonCardPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1)); @@ -312,7 +310,6 @@ class DetailPanel extends JPanel { JPanel barPane = new JPanel(); barPane.setOpaque(false); -// barPane.add(installProgressBar); JPanel buttonPane = new JPanel(); buttonPane.setOpaque(false); @@ -320,8 +317,7 @@ class DetailPanel extends JPanel { barButtonCardPane.add(buttonPane, BUTTON_CONSTRAINT); barButtonCardPane.add(barPane, PROGRESS_BAR_CONSTRAINT); - - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT); + barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT); rightPane.add(barButtonCardPane); @@ -355,7 +351,6 @@ class DetailPanel extends JPanel { rightPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1)); add(rightPane, BorderLayout.EAST); - if (updateButton.isVisible() && !removeInProgress && !contrib.isDeletionFlagged()) { JPanel updateRemovePanel = new JPanel(); updateRemovePanel.setLayout(new FlowLayout()); @@ -368,21 +363,18 @@ class DetailPanel extends JPanel { JPanel barPane = new JPanel(); barPane.setOpaque(false); barPane.setInheritsPopupMenu(true); -// barPane.add(installProgressBar); rightPane.add(barPane); - if (updateInProgress) - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT); - - } - else { + if (updateInProgress) { + barButtonCardLayout.show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT); + } + } else { updateBox.add(updateButton, BorderLayout.EAST); barButtonCardPane.removeAll(); JPanel barPane = new JPanel(); barPane.setOpaque(false); barPane.setInheritsPopupMenu(true); -// barPane.add(installProgressBar); JPanel buttonPane = new JPanel(); buttonPane.setOpaque(false); @@ -391,34 +383,33 @@ class DetailPanel extends JPanel { barButtonCardPane.add(buttonPane, BUTTON_CONSTRAINT); barButtonCardPane.add(barPane, PROGRESS_BAR_CONSTRAINT); - if (installInProgress || removeInProgress || updateInProgress) - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT); - else - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT); - + if (installInProgress || removeInProgress || updateInProgress) { + barButtonCardLayout.show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT); + } else { + barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT); + } rightPane.add(barButtonCardPane); } - Dimension d = installProgressBar.getPreferredSize(); - Dimension d2 = installRemoveButton.getPreferredSize(); - d.width = DetailPanel.BUTTON_WIDTH; - d.height = Math.max(d.height,d2.height); - rightPane.setMinimumSize(d); - rightPane.setPreferredSize(d); + Dimension progressDim = installProgressBar.getPreferredSize(); + Dimension installDim = installRemoveButton.getPreferredSize(); + progressDim.width = DetailPanel.BUTTON_WIDTH; + progressDim.height = Math.max(progressDim.height, installDim.height); + rightPane.setMinimumSize(progressDim); + rightPane.setPreferredSize(progressDim); } private void setExpandListener(Component component, MouseListener expandListener) { - if (component instanceof JButton) { - // This will confuse the button, causing it to stick on OS X - // https://github.com/processing/processing/issues/3172 - return; - } - component.addMouseListener(expandListener); - if (component instanceof Container) { - for (Component child : ((Container) component).getComponents()) { - setExpandListener(child, expandListener); + // If it's a JButton, adding the listener will make this stick on OS X + // https://github.com/processing/processing/issues/3172 + if (!(component instanceof JButton)) { + component.addMouseListener(expandListener); + if (component instanceof Container) { + for (Component child : ((Container) component).getComponents()) { + setExpandListener(child, expandListener); + } } } } @@ -427,8 +418,9 @@ class DetailPanel extends JPanel { private void blurContributionPanel(Component component) { component.setFocusable(false); component.setEnabled(false); - if (component instanceof JComponent) + if (component instanceof JComponent) { ((JComponent) component).setToolTipText(INCOMPATIBILITY_BLUR); + } if (component instanceof Container) { for (Component child : ((Container) component).getComponents()) { blurContributionPanel(child); @@ -589,10 +581,11 @@ class DetailPanel extends JPanel { resetInstallProgressBarState(); installRemoveButton.setEnabled(!contrib.isUpdateFlagged()); - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT); + barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT); installInProgress = false; - if(updateInProgress) + if (updateInProgress) { updateInProgress = !updateInProgress; + } updateButton.setVisible(contribListing.hasUpdates(contrib) && !contrib.isUpdateFlagged()); setSelected(true); } @@ -607,10 +600,11 @@ class DetailPanel extends JPanel { if (isError()) { listPanel.contributionTab.statusPanel.setErrorMessage(Language.text("contrib.download_error")); } - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT); + barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT); installInProgress = false; - if(updateInProgress) + if (updateInProgress) { updateInProgress = !updateInProgress; + } updateButton.setVisible(contribListing.hasUpdates(contrib) && !contrib.isUpdateFlagged()); setSelected(true); } @@ -620,8 +614,7 @@ class DetailPanel extends JPanel { } }; - ContributionManager.downloadAndInstall(listPanel.contributionTab.editor.getBase(), - downloadUrl, ad, + ContributionManager.downloadAndInstall(base, downloadUrl, ad, downloadProgress, installProgress, listPanel.contributionTab.statusPanel); @@ -629,26 +622,11 @@ class DetailPanel extends JPanel { Messages.showWarning(Language.text("contrib.errors.install_failed"), Language.text("contrib.errors.malformed_url"), e); // not sure why we'd re-enable the button if it had an error... -// installRemoveButton.setEnabled(true); + //installRemoveButton.setEnabled(true); } } - // This doesn't actually seem to work? - /* - static void stripTextSelectionListeners(JEditorPane editorPane) { - for (MouseListener listener : editorPane.getMouseListeners()) { - String className = listener.getClass().getName(); - if (className.endsWith("MutableCaretEvent") || - className.endsWith("DragListener") || - className.endsWith("BasicCaret")) { - editorPane.removeMouseListener(listener); - } - } - } - */ - - protected void resetInstallProgressBarState() { installProgressBar.setString(Language.text("contrib.progress.starting")); installProgressBar.setIndeterminate(false); @@ -763,14 +741,15 @@ class DetailPanel extends JPanel { * Sets coloring based on whether installed or not; * also makes ugly blue HTML links into the specified color (black). */ - static void setForegroundStyle(JTextPane textPane, boolean installed, boolean selected) { + static void setForegroundStyle(JTextPane textPane, + boolean installed, boolean selected) { Document doc = textPane.getDocument(); if (doc instanceof HTMLDocument) { HTMLDocument html = (HTMLDocument) doc; StyleSheet stylesheet = html.getStyleSheet(); - String c = (installed && !selected) ? "#555555" : "#000000"; // slightly grayed when installed -// String c = "#000000"; // just make them both black + // slightly grayed when installed + String c = (installed && !selected) ? "#555555" : "#000000"; stylesheet.addRule("body { color:" + c + "; }"); stylesheet.addRule("a { color:" + c + "; }"); } @@ -784,7 +763,7 @@ class DetailPanel extends JPanel { StyleSheet stylesheet = html.getStyleSheet(); stylesheet.addRule("body { " + " margin: 0; padding: 0;" + - " font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;" + + " font-family: " + Toolkit.getSansFontName() + ", Arial, Helvetica, sans-serif;" + " font-size: 100%;" + "font-size: 0.95em; " + "}"); } @@ -808,7 +787,7 @@ class DetailPanel extends JPanel { public void install() { listPanel.contributionTab.statusPanel.clearMessage(); installInProgress = true; - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT); + barButtonCardLayout.show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT); if (contrib instanceof AvailableContribution) { installContribution((AvailableContribution) contrib); contribListing.replaceContribution(contrib, contrib); @@ -817,7 +796,6 @@ class DetailPanel extends JPanel { public void update() { - listPanel.contributionTab.statusPanel.clearMessage(); updateInProgress = true; if (contrib.getType().requiresRestart()) { @@ -851,12 +829,7 @@ class DetailPanel extends JPanel { boolean isModeActive = false; if (contrib.getType() == ContributionType.MODE) { ModeContribution m = (ModeContribution) contrib; - //Iterator iter = listPanel.contribManager.editor.getBase().getEditors().iterator(); - //while (iter.hasNext()) { - // TODO there's gotta be a cleaner way to do this accessor - Base base = listPanel.contributionTab.editor.getBase(); for (Editor e : base.getEditors()) { - //Editor e = iter.next(); if (e.getMode().equals(m.getMode())) { isModeActive = true; break; @@ -872,8 +845,7 @@ class DetailPanel extends JPanel { } }; ((LocalContribution) contrib) - .removeContribution(listPanel.contributionTab.editor.getBase(), - progress, listPanel.contributionTab.statusPanel); + .removeContribution(base, progress, listPanel.contributionTab.statusPanel); } else { updateButton.setEnabled(false); installRemoveButton.setEnabled(false); diff --git a/app/src/processing/app/ui/Toolkit.java b/app/src/processing/app/ui/Toolkit.java index d6c20911e..d8378acd4 100644 --- a/app/src/processing/app/ui/Toolkit.java +++ b/app/src/processing/app/ui/Toolkit.java @@ -900,7 +900,8 @@ public class Toolkit { static public String getMonoFontName() { if (monoFont == null) { - getMonoFont(12, Font.PLAIN); // load a dummy version + // create a dummy version if the font has never been loaded (rare) + getMonoFont(12, Font.PLAIN); } return monoFont.getName(); } @@ -950,6 +951,15 @@ public class Toolkit { } + static public String getSansFontName() { + if (sansFont == null) { + // create a dummy version if the font has never been loaded (rare) + getSansFont(12, Font.PLAIN); + } + return sansFont.getName(); + } + + static public Font getSansFont(int size, int style) { if (sansFont == null) { try { diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index dcd9ee781..1f5790b79 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -1194,6 +1194,7 @@ public class PApplet implements PConstants { * */ public void pixelDensity(int density) { + println(density + " " + this.pixelDensity); if (density != this.pixelDensity) { if (insideSettings("pixelDensity", density)) { if (density != 1 && density != 2) { @@ -1205,6 +1206,11 @@ public class PApplet implements PConstants { } else { this.pixelDensity = density; } + } else { + System.err.println("not inside settings"); + // this should only be reachable when not running in the PDE, + // so saying it's a settings()--not just setup()--issue should be ok + throw new RuntimeException("pixelDensity() can only be used inside settings()"); } } } diff --git a/core/todo.txt b/core/todo.txt index e72a1fdb5..d06732855 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -4,6 +4,8 @@ andres X automatic detection of POINT and LINE shaders fails X https://github.com/processing/processing/issues/4725 +X show warning when frameRate() less than 1 is called with P2D and P3D +X https://github.com/processing/processing/issues/4716 _ TRIANGLE_STRIP not working correctly with createShape() and default renderer diff --git a/java/src/processing/mode/java/Compiler.java b/java/src/processing/mode/java/Compiler.java index c62b4c000..43095c893 100644 --- a/java/src/processing/mode/java/Compiler.java +++ b/java/src/processing/mode/java/Compiler.java @@ -211,8 +211,8 @@ public class Compiler { String suggestion = importSuggestions.get(what); if (suggestion != null) { System.err.println("You may need to add \"import " + suggestion + ";\" to the top of your sketch."); - System.err.println("To make sketches more portable, imports that are not part of the Processing API have been removed from Processing 2.0."); - System.err.println("See the changes page for more information: http://wiki.processing.org/w/Changes"); + System.err.println("To make sketches more portable, imports that are not part of the Processing API were removed in Processing 2."); + System.err.println("See the changes page for more information: https://github.com/processing/processing/wiki/Changes"); } } diff --git a/todo.txt b/todo.txt index fe5532bef..7854022cf 100755 --- a/todo.txt +++ b/todo.txt @@ -12,6 +12,9 @@ X missing version number putting 'null' in the ui X https://github.com/processing/processing-docs/issues/478 X https://github.com/processing/processing/issues/4696 X https://github.com/processing/processing/pull/4712 +o replace appbundler with the Java 8 packager +o appbundler is no longer being developed by Oracle, switch to "packager" +X https://github.com/processing/processing/issues/3071 contribs X Up-to-date status disappears after filter is removed @@ -22,6 +25,15 @@ X https://github.com/processing/processing/issues/4704 X Fixes the removal of redundant contribution and update related issues X https://github.com/processing/processing/pull/4086 +_ fix appbundler problems due to rollback +_ https://github.com/processing/processing/issues/3790 +_ the rollback re-introduces two bugs (serial export and scrolling) +_ and any other changes later than 16 November 2014: +_ https://github.com/processing/processing/commits/master/build/macosx/appbundler.jar +_ https://github.com/processing/processing/commits/master/build/macosx/appbundler/native/main.m +_ https://github.com/processing/processing/commit/fa27b983e76fdbc5c4c1451a1f0d854c652b1639 +_ https://bitbucket.org/infinitekind/appbundler + _ 'version' should be x.y or x.y.z, not some extra long string _ enforce this by disallowing spaces? on the import script? @@ -916,16 +928,6 @@ DIST / Mac OS X _ client properties _ https://developer.apple.com/library/mac/technotes/tn2007/tn2196.html _ built-in images: http://nadeausoftware.com/articles/2008/12/mac_java_tip_how_access_mac_specific_nsimage_icons -_ replace appbundler with the Java 8 packager -_ https://github.com/processing/processing/issues/3071 -_ fix appbundler problems due to rollback -_ https://github.com/processing/processing/issues/3790 -_ appbundler is no longer being developed by Oracle, switch to "packager" -_ this re-introduces two bugs (serial export and scrolling) -_ and any other changes later than 16 November 2014: -_ https://github.com/processing/processing/commits/master/build/macosx/appbundler.jar -_ https://github.com/processing/processing/commits/master/build/macosx/appbundler/native/main.m -_ https://github.com/processing/processing/commit/fa27b983e76fdbc5c4c1451a1f0d854c652b1639 _ Update QuickLook plugin for Processing 3 _ https://github.com/processing/processing/issues/3261 _ Find a long-term solution for OS X bundler to address signing/symlink issues