From 4892690e4ec97f058548e71f877fa84e45b69777 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Tue, 29 Sep 2015 21:10:02 -0400 Subject: [PATCH] implementing new splash screen, sorting out other static init problems --- app/src/processing/app/BaseSplash.java | 24 ++++++ app/src/processing/app/Language.java | 8 ++ app/src/processing/app/Sketch.java | 4 +- app/src/processing/app/ui/About.java | 32 ++++---- app/src/processing/app/ui/EditorStatus.java | 3 +- .../processing/app/ui/PreferencesFrame.java | 11 +-- app/src/processing/app/ui/SplashWindow.java | 75 +++++++++++-------- app/src/processing/app/ui/Toolkit.java | 24 +++--- build/build.xml | 8 +- .../processing/mode/java/MarkerColumn.java | 15 ++-- todo.txt | 42 +++++++---- 11 files changed, 164 insertions(+), 82 deletions(-) create mode 100644 app/src/processing/app/BaseSplash.java diff --git a/app/src/processing/app/BaseSplash.java b/app/src/processing/app/BaseSplash.java new file mode 100644 index 000000000..39848de5e --- /dev/null +++ b/app/src/processing/app/BaseSplash.java @@ -0,0 +1,24 @@ +package processing.app; + +import java.io.File; + +import processing.app.ui.SplashWindow; +import processing.app.ui.Toolkit; + + +public class BaseSplash { + static public void main(String[] args) { + try { + final boolean hidpi = Toolkit.highResDisplay(); + final String filename = "lib/about-" + (hidpi ? 2 : 1) + "x.png"; + File splashFile = Platform.getContentFile(filename); + SplashWindow.splash(splashFile.toURI().toURL(), hidpi); + SplashWindow.invokeMain("processing.app.Base", args); + SplashWindow.disposeSplash(); + } catch (Exception e) { + e.printStackTrace(); + // !@#!@$$! umm + //SplashWindow.invokeMain("processing.app.Base", args); + } + } +} \ No newline at end of file diff --git a/app/src/processing/app/Language.java b/app/src/processing/app/Language.java index 5fab731c1..23a35349a 100644 --- a/app/src/processing/app/Language.java +++ b/app/src/processing/app/Language.java @@ -212,6 +212,14 @@ public class Language { } + /** + * @param which either yes, no, cancel, ok, or browse + */ + static public String getPrompt(String which) { + return Language.text("prompt." + which); + } + + /** Get all available languages */ static public Map getLanguages() { return init().languages; diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 570a6c66c..8adcb7993 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -401,8 +401,8 @@ public class Sketch { JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[] { - Toolkit.PROMPT_OK, - Toolkit.PROMPT_CANCEL }, + Language.getPrompt("ok"), + Language.getPrompt("cancel") }, field); if (userReply == JOptionPane.OK_OPTION) { diff --git a/app/src/processing/app/ui/About.java b/app/src/processing/app/ui/About.java index 553d09ce2..4eda1206f 100644 --- a/app/src/processing/app/ui/About.java +++ b/app/src/processing/app/ui/About.java @@ -23,28 +23,31 @@ package processing.app.ui; import java.awt.Color; -import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.RenderingHints; import java.awt.Window; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import javax.swing.ImageIcon; + import processing.app.Base; public class About extends Window { - Image image; + ImageIcon icon; int width, height; public About(Frame frame) { super(frame); + icon = Toolkit.getLibIconX("about"); + width = icon.getIconWidth(); + height = icon.getIconHeight(); + + /* if (Toolkit.highResDisplay()) { image = Toolkit.getLibImage("about-2x.jpg"); //$NON-NLS-1$ width = image.getWidth(null) / 2; @@ -54,6 +57,7 @@ public class About extends Window { width = image.getWidth(null); height = image.getHeight(null); } + */ addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { @@ -61,21 +65,23 @@ public class About extends Window { } }); - Dimension screen = Toolkit.getScreenSize(); - setBounds((screen.width-width)/2, (screen.height-height)/2, width, height); +// Dimension screen = Toolkit.getScreenSize(); +// setBounds((screen.width-width)/2, (screen.height-height)/2, width, height); + setLocationRelativeTo(null); setVisible(true); } public void paint(Graphics g) { - g.drawImage(image, 0, 0, width, height, null); + g.drawImage(icon.getImage(), 0, 0, width, height, null); - Graphics2D g2 = (Graphics2D) g; - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); +// Graphics2D g2 = (Graphics2D) g; +// g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, +// RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); - g.setFont(new Font("SansSerif", Font.PLAIN, 10)); //$NON-NLS-1$ + g.setFont(Toolkit.getSansFont(Font.PLAIN, 10)); + //g.setFont(new Font("SansSerif", Font.PLAIN, 10)); //$NON-NLS-1$ g.setColor(Color.white); - g.drawString(Base.getVersionName(), 90, 29); + g.drawString(Base.getVersionName(), 26, 29); } } \ No newline at end of file diff --git a/app/src/processing/app/ui/EditorStatus.java b/app/src/processing/app/ui/EditorStatus.java index 60d884f4a..aab3b99ee 100644 --- a/app/src/processing/app/ui/EditorStatus.java +++ b/app/src/processing/app/ui/EditorStatus.java @@ -31,6 +31,7 @@ import java.awt.event.MouseEvent; import javax.swing.plaf.basic.BasicSplitPaneDivider; import javax.swing.plaf.basic.BasicSplitPaneUI; +import processing.app.Language; import processing.app.Mode; import processing.app.Platform; import processing.core.PApplet; @@ -265,7 +266,7 @@ public class EditorStatus extends BasicSplitPaneDivider { //JPanel { if (indeterminate) { //int x = cancelButton.getX(); //int w = cancelButton.getWidth(); - int w = Toolkit.BUTTON_WIDTH; + int w = Toolkit.getButtonWidth(); int x = getWidth() - RIGHT_MARGIN - w; int y = getHeight() / 3; int h = getHeight() / 3; diff --git a/app/src/processing/app/ui/PreferencesFrame.java b/app/src/processing/app/ui/PreferencesFrame.java index cb1050bbd..a712f0ce3 100644 --- a/app/src/processing/app/ui/PreferencesFrame.java +++ b/app/src/processing/app/ui/PreferencesFrame.java @@ -109,7 +109,7 @@ public class PreferencesFrame { sketchbookLocationField = new JTextField(40); - browseButton = new JButton(Toolkit.PROMPT_BROWSE); + browseButton = new JButton(Language.getPrompt("browse")); browseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { File dflt = new File(sketchbookLocationField.getText()); @@ -362,7 +362,7 @@ public class PreferencesFrame { // [ OK ] [ Cancel ] - okButton = new JButton(Toolkit.PROMPT_OK); + okButton = new JButton(Language.getPrompt("ok")); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { applyFrame(); @@ -370,13 +370,14 @@ public class PreferencesFrame { } }); - JButton cancelButton = new JButton(Toolkit.PROMPT_CANCEL); + JButton cancelButton = new JButton(Language.getPrompt("cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { disposeFrame(); } }); + final int buttonWidth = Toolkit.getButtonWidth(); layout.setHorizontalGroup(layout.createSequentialGroup() // sequential group for border + mainContent + border .addGap(BORDER) .addGroup(layout.createParallelGroup() // parallel group for rest of the components @@ -431,8 +432,8 @@ public class PreferencesFrame { .addComponent(preferencePathLabel) .addComponent(preferenceHintLabel) .addGroup(GroupLayout.Alignment.TRAILING,layout.createSequentialGroup() // Trailing so that the buttons are to the right - .addComponent(okButton, Toolkit.BUTTON_WIDTH, GroupLayout.DEFAULT_SIZE, Toolkit.BUTTON_WIDTH) // Ok and Cancel buttton are now of size BUTTON_WIDTH - .addComponent(cancelButton, Toolkit.BUTTON_WIDTH, GroupLayout.DEFAULT_SIZE, Toolkit.BUTTON_WIDTH) + .addComponent(okButton, buttonWidth, GroupLayout.DEFAULT_SIZE, buttonWidth) // Ok and Cancel buttton are now of size BUTTON_WIDTH + .addComponent(cancelButton, buttonWidth, GroupLayout.DEFAULT_SIZE, buttonWidth) )) .addGap(BORDER) ); diff --git a/app/src/processing/app/ui/SplashWindow.java b/app/src/processing/app/ui/SplashWindow.java index 8a49d2385..83f8f4e53 100644 --- a/app/src/processing/app/ui/SplashWindow.java +++ b/app/src/processing/app/ui/SplashWindow.java @@ -1,3 +1,5 @@ +package processing.app.ui; + /* * @(#)SplashWindow.java 2.2.1 2006-05-27 * @@ -9,10 +11,16 @@ * without having to attribute to Werner Randelshofer. */ -import java.awt.*; -import java.awt.event.*; -import java.net.*; -import java.io.*; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.MediaTracker; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.net.URL; /** * A Splash window. @@ -42,12 +50,12 @@ public class SplashWindow extends Window { * (Singleton design pattern). */ private static SplashWindow instance; - + /** * The splash image which is displayed on the splash window. */ private Image image; - + /** * This attribute indicates whether the method * paint(Graphics) has been called at least once since the @@ -62,23 +70,23 @@ public class SplashWindow extends Window { * @see #splash */ private boolean paintCalled = false; - + /** * Creates a new instance. * @param parent the parent of the window. * @param image the splash image. */ - private SplashWindow(Frame parent, Image image) { + private SplashWindow(Frame parent, Image image, boolean hidpi) { super(parent); this.image = image; - + // Load the image MediaTracker mt = new MediaTracker(this); mt.addImage(image,0); try { mt.waitForID(0); } catch(InterruptedException ie){} - + // Abort on failure if (mt.isErrorID(0)) { setSize(0,0); @@ -89,17 +97,21 @@ public class SplashWindow extends Window { } return; } - + // Center the window on the screen int imgWidth = image.getWidth(this); int imgHeight = image.getHeight(this); + + if (hidpi) { + imgWidth /= 2; + imgHeight /= 2; + } setSize(imgWidth, imgHeight); - Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); - setLocation( - (screenDim.width - imgWidth) / 2, - (screenDim.height - imgHeight) / 2 - ); - +// Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); +// setLocation((screenDim.width - imgWidth) / 2, +// (screenDim.height - imgHeight) / 2); + setLocationRelativeTo(null); + // Users shall be able to close the splash window by // clicking on its display area. This mouse listener // listens for mouse clicks and disposes the splash window. @@ -119,7 +131,7 @@ public class SplashWindow extends Window { }; addMouseListener(disposeOnClick); } - + /** * Updates the display area of the window. */ @@ -134,8 +146,8 @@ public class SplashWindow extends Window { * Paints the image on the window. */ public void paint(Graphics g) { - g.drawImage(image, 0, 0, this); - + g.drawImage(image, 0, 0, getWidth(), getHeight(), this); + // Notify method splash that the window // has been painted. // Note: To improve performance we do not enter @@ -145,21 +157,21 @@ public class SplashWindow extends Window { synchronized (this) { notifyAll(); } } } - + /** * Open's a splash window using the specified image. * @param image The splash image. */ - public static void splash(Image image) { + public static void splash(Image image, boolean hidpi) { if (instance == null && image != null) { Frame f = new Frame(); - + // Create the splash image - instance = new SplashWindow(f, image); - + instance = new SplashWindow(f, image, hidpi); + // Show the window. - instance.show(); - + instance.setVisible(true); + // Note: To make sure the user gets a chance to see the // splash window we wait until its paint method has been // called at least once by the AWT event dispatcher thread. @@ -175,16 +187,17 @@ public class SplashWindow extends Window { } } } + /** * Open's a splash window using the specified image. * @param imageURL The url of the splash image. */ - public static void splash(URL imageURL) { + public static void splash(URL imageURL, boolean hidpi) { if (imageURL != null) { - splash(Toolkit.getDefaultToolkit().createImage(imageURL)); + splash(Toolkit.getDefaultToolkit().createImage(imageURL), hidpi); } } - + /** * Closes the splash window. */ @@ -194,7 +207,7 @@ public class SplashWindow extends Window { instance = null; } } - + /** * Invokes the main method of the provided class name. * @param args the command line arguments diff --git a/app/src/processing/app/ui/Toolkit.java b/app/src/processing/app/ui/Toolkit.java index 199aeae41..2d6458070 100644 --- a/app/src/processing/app/ui/Toolkit.java +++ b/app/src/processing/app/ui/Toolkit.java @@ -80,20 +80,13 @@ import processing.app.Preferences; * @author fry */ public class Toolkit { + /* static public final String PROMPT_YES = Language.text("prompt.yes"); static public final String PROMPT_NO = Language.text("prompt.no"); static public final String PROMPT_CANCEL = Language.text("prompt.cancel"); static public final String PROMPT_OK = Language.text("prompt.ok"); static public final String PROMPT_BROWSE = Language.text("prompt.browse"); - - /** - * Standardized width for buttons. Mac OS X 10.3 wants 70 as its default, - * Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper. - * This is now stored in the languages file since this may need to be larger - * for languages that are consistently wider than English. - */ - static public int BUTTON_WIDTH = - Integer.parseInt(Language.text("preferences.button.width")); + */ static final java.awt.Toolkit awtToolkit = java.awt.Toolkit.getDefaultToolkit(); @@ -113,6 +106,19 @@ public class Toolkit { ActionEvent.SHIFT_MASK | SHORTCUT_KEY_MASK; + /** + * Standardized width for buttons. Mac OS X 10.3 wants 70 as its default, + * Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper. + * This is now stored in the languages file since this may need to be larger + * for languages that are consistently wider than English. + */ + static public int getButtonWidth() { + // Made into a method so that calling Toolkit methods doesn't require + // the languages to be loaded, and with that, Base initialized completely + return Integer.parseInt(Language.text("preferences.button.width")); + } + + /** * A software engineer, somewhere, needs to have their abstraction * taken away. Who crafts the sort of API that would require a diff --git a/build/build.xml b/build/build.xml index 319591914..4ff38830e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -514,7 +514,7 @@ shortVersion="${version}" version="${revision}" javafx="true" - mainClassName="processing.app.Base"> + mainClassName="processing.app.BaseSplash"> + + + -