From: <mat...@us...> - 2006-10-18 08:20:49
|
Revision: 1516 http://svn.sourceforge.net/spring-rich-c/?rev=1516&view=rev Author: mathiasbr Date: 2006-10-18 01:20:34 -0700 (Wed, 18 Oct 2006) Log Message: ----------- Improve handling of SplashScreens splash() and dispose() final again createSplashContentPane renamed to createContentPane and return type changed to java.awt.Component AbstractSplashScreen can handle null return values of createContentPane Modified Paths: -------------- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/AbstractSplashScreen.java trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/ProgressSplashScreen.java trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/SimpleSplashScreen.java Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/AbstractSplashScreen.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/AbstractSplashScreen.java 2006-10-17 10:42:10 UTC (rev 1515) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/AbstractSplashScreen.java 2006-10-18 08:20:34 UTC (rev 1516) @@ -15,6 +15,7 @@ */ package org.springframework.richclient.application.splash; +import java.awt.Component; import java.awt.Image; import java.awt.Toolkit; import java.net.URL; @@ -35,7 +36,7 @@ * * <p> * The splash screen produced by this class will be an undecorated, centered - * frame containing the component provided by {@link #createSplashContentPane()}, + * frame containing the component provided by {@link #createContentPane()}, * which is the only method that subclasses need to implement. * </p> * @@ -51,7 +52,8 @@ private JFrame frame; private MessageSource messageSource; private String iconResourcePath; - private static final Log logger = LogFactory.getLog(AbstractSplashScreen.class); + + protected final Log logger = LogFactory.getLog(getClass()); /** * Returns the location of the image to be used as the icon for the splash @@ -101,7 +103,7 @@ this.messageSource = messageSource; } - public void dispose() { + public final void dispose() { if (frame != null) { frame.dispose(); @@ -112,15 +114,11 @@ /** * Creates and displays an undecorated, centered splash screen containing the - * component provided by {@link #createSplashContentPane()}. If this instance + * component provided by {@link #createContentPane()}. If this instance * has been provided with a {@link MessageSource}, it will be used to retrieve * the splash screen's frame title under the key {@value #SPLASH_TITLE_KEY}. - * - * @throws NoSuchMessageException if a {@link MessageSource} has been set - * on this instance and it is unable to find a message under the key - * {@value #SPLASH_TITLE_KEY}. */ - public void splash() { + public final void splash() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.setUndecorated(true); @@ -128,10 +126,10 @@ frame.setTitle(loadFrameTitle()); frame.setIconImage(loadFrameIcon()); - JComponent content = createSplashContentPane(); - Assert.notNull(content, "Splash content cannot be null"); - - frame.getContentPane().add(content); + Component content = createContentPane(); + if(content != null) { + frame.getContentPane().add(content); + } frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); @@ -166,9 +164,10 @@ } /** - * Returns the component to be displayed in the splash screen's main frame. - * - * @return The content pane component, never null. + * Returns the component to be displayed in the splash screen's main frame. If the returned value is null the frame + * for the splash screen will still be created but will not have any content + * + * @return The content pane component. Can be null. */ - protected abstract JComponent createSplashContentPane(); + protected abstract Component createContentPane(); } Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/ProgressSplashScreen.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/ProgressSplashScreen.java 2006-10-17 10:42:10 UTC (rev 1515) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/ProgressSplashScreen.java 2006-10-18 08:20:34 UTC (rev 1516) @@ -16,6 +16,7 @@ package org.springframework.richclient.application.splash; import java.awt.BorderLayout; +import java.awt.Component; import javax.swing.JComponent; import javax.swing.JPanel; @@ -56,7 +57,7 @@ * * @return The showProgressLabel flag. */ - public boolean getShowProgressLabel() { + public boolean isShowProgressLabel() { return showProgressLabel; } @@ -75,13 +76,15 @@ * * @return A splash screen containing an image and a progress bar, never null. */ - protected JComponent createSplashContentPane() { + protected Component createContentPane() { JPanel content = new JPanel(new BorderLayout()); - content.add(super.createSplashContentPane()); + Component component = super.createContentPane(); + if(component != null) + content.add(component); JProgressBar progressBar = getProgressBar(); progressBar.setIndeterminate(isIndeterminate()); - progressBar.setStringPainted(getShowProgressLabel()); + progressBar.setStringPainted(isShowProgressLabel()); content.add(progressBar, BorderLayout.SOUTH); Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/SimpleSplashScreen.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/SimpleSplashScreen.java 2006-10-17 10:42:10 UTC (rev 1515) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/splash/SimpleSplashScreen.java 2006-10-18 08:20:34 UTC (rev 1516) @@ -15,6 +15,7 @@ */ package org.springframework.richclient.application.splash; +import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; @@ -43,8 +44,6 @@ private String imageResourcePath; - private boolean imageLoaded = false; - private static final Log logger = LogFactory.getLog(SimpleSplashScreen.class); /** @@ -91,15 +90,8 @@ public void setImageResourcePath(String path) { Assert.hasText(path, "The splash screen image resource path is required"); this.imageResourcePath = path; - this.imageLoaded = false; } - public void splash() { - if (getImage() != null) { - super.splash(); - } - } - /** * Load image from path. * @@ -118,9 +110,8 @@ } protected Image getImage() { - if(!imageLoaded && imageResourcePath != null) { + if(image == null && imageResourcePath != null) { image = loadImage(imageResourcePath); - imageLoaded = true; } return image; } @@ -172,7 +163,11 @@ /** * Returns a component that displays an image in a canvas. */ - protected JComponent createSplashContentPane() { - return new ImageCanvas(getImage()); + protected Component createContentPane() { + Image image = getImage(); + if(image != null) { + return new ImageCanvas(image); + } + return null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |