001 /*
002 * Copyright 2002-2006 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016 package org.springframework.richclient.application.splash;
017
018 import java.awt.BorderLayout;
019 import java.awt.Component;
020
021 import javax.swing.JPanel;
022 import javax.swing.JProgressBar;
023
024 import org.springframework.richclient.progress.ProgressBarProgressMonitor;
025 import org.springframework.richclient.progress.ProgressMonitor;
026 import org.springframework.util.Assert;
027
028 /**
029 * A lightweight splash-screen for displaying the progress of a GUI application startup process.
030 *
031 * <p>
032 * The splash screen produced by this class will be an undecorated, centered frame containing an image above a progress
033 * bar. It minimizes class loading so it is displayed immediately once the application is started.
034 * </p>
035 *
036 *
037 * @author Peter De Bruycker
038 */
039 public class ProgressSplashScreen extends SimpleSplashScreen implements MonitoringSplashScreen {
040 private JProgressBar progressBar;
041
042 private boolean showProgressLabel;
043
044 private ProgressMonitor progressMonitor;
045
046 private boolean indeterminate = true;
047
048 /**
049 * Creates a new {@code ProgressSplashScreen} that uses an underlying {@link ProgressBarProgressMonitor}.
050 */
051 public ProgressSplashScreen() {
052 }
053
054 /**
055 * Returns the flag that determines whether or not the progress bar will display updated textual info as it is
056 * provided by the progress monitor.
057 *
058 * @return The showProgressLabel flag.
059 */
060 public boolean isShowProgressLabel() {
061 return showProgressLabel;
062 }
063
064 /**
065 * Sets the flag that determines whether or not the progress bar will display updated textual info as it is provided
066 * by the progress monitor.
067 *
068 * @param showProgressLabel
069 */
070 public void setShowProgressLabel(boolean showProgressLabel) {
071 this.showProgressLabel = showProgressLabel;
072 }
073
074 /**
075 * Returns a component that displays an image above a progress bar.
076 *
077 * @return A splash screen containing an image and a progress bar, never null.
078 */
079 protected Component createContentPane() {
080 JPanel content = new JPanel(new BorderLayout());
081 Component component = super.createContentPane();
082 if(component != null)
083 content.add(component);
084
085 JProgressBar progressBar = getProgressBar();
086 progressBar.setIndeterminate(isIndeterminate());
087 progressBar.setStringPainted(isShowProgressLabel());
088
089 content.add(progressBar, BorderLayout.SOUTH);
090
091 return content;
092 }
093
094 public ProgressMonitor getProgressMonitor() {
095 if (progressMonitor == null) {
096 progressMonitor = new ProgressBarProgressMonitor(getProgressBar());
097 }
098 return progressMonitor;
099 }
100
101 /**
102 * Sets the progress monitor used by this splash screen.
103 *
104 * @param progressMonitor
105 * The progress monitor.
106 */
107 public void setProgressMonitor(ProgressMonitor progressMonitor) {
108 this.progressMonitor = progressMonitor;
109 }
110
111 /**
112 * Returns the progress bar.
113 *
114 * @return not null
115 */
116 protected JProgressBar getProgressBar() {
117 if (progressBar == null) {
118 progressBar = createProgressBar();
119 Assert.notNull(progressBar, "createProgressBar should not return null");
120 }
121 return progressBar;
122 }
123
124 protected JProgressBar createProgressBar() {
125 return new JProgressBar();
126 }
127
128 public boolean isIndeterminate() {
129 return indeterminate;
130 }
131
132 /**
133 * Determines whether the progress bar is in determinate or indeterminate mode. Default is true
134 *
135 * @param indeterminate
136 * <code>true</code> if the progress bar should change to indeterminate mode; <code>false</code> if
137 * it should revert to normal.
138 * @see JProgressBar#setIndeterminate(boolean)
139 */
140 public void setIndeterminate(boolean indeterminate) {
141 this.indeterminate = indeterminate;
142 }
143 }