org.valkyriercp.application.splash.ProgressSplashScreen Maven / Gradle / Ivy
package org.valkyriercp.application.splash;
import org.springframework.util.Assert;
import org.valkyriercp.progress.*;
import javax.swing.*;
import javax.swing.ProgressMonitor;
import java.awt.*;
/**
* A lightweight splash-screen for displaying the progress of a GUI application startup process.
*
*
* The splash screen produced by this class will be an undecorated, centered frame containing an image above a progress
* bar. It minimizes class loading so it is displayed immediately once the application is started.
*
*
*
* @author Peter De Bruycker
*/
public class ProgressSplashScreen extends SimpleSplashScreen implements MonitoringSplashScreen {
private JProgressBar progressBar;
private boolean showProgressLabel;
private org.valkyriercp.progress.ProgressMonitor progressMonitor;
private boolean indeterminate = true;
/**
* Creates a new {@code ProgressSplashScreen} that uses an underlying {@link ProgressBarProgressMonitor}.
*/
public ProgressSplashScreen() {
}
/**
* Returns the flag that determines whether or not the progress bar will display updated textual info as it is
* provided by the progress monitor.
*
* @return The showProgressLabel flag.
*/
public boolean isShowProgressLabel() {
return showProgressLabel;
}
/**
* Sets the flag that determines whether or not the progress bar will display updated textual info as it is provided
* by the progress monitor.
*
* @param showProgressLabel
*/
public void setShowProgressLabel(boolean showProgressLabel) {
this.showProgressLabel = showProgressLabel;
}
/**
* Returns a component that displays an image above a progress bar.
*
* @return A splash screen containing an image and a progress bar, never null.
*/
protected Component createContentPane() {
JPanel content = new JPanel(new BorderLayout());
Component component = super.createContentPane();
if(component != null)
content.add(component);
JProgressBar progressBar = getProgressBar();
progressBar.setIndeterminate(isIndeterminate());
progressBar.setStringPainted(isShowProgressLabel());
content.add(progressBar, BorderLayout.SOUTH);
return content;
}
public org.valkyriercp.progress.ProgressMonitor getProgressMonitor() {
if (progressMonitor == null) {
progressMonitor = new ProgressBarProgressMonitor(getProgressBar());
}
return progressMonitor;
}
/**
* Sets the progress monitor used by this splash screen.
*
* @param progressMonitor
* The progress monitor.
*/
public void setProgressMonitor(org.valkyriercp.progress.ProgressMonitor progressMonitor) {
this.progressMonitor = progressMonitor;
}
/**
* Returns the progress bar.
*
* @return not null
*/
protected JProgressBar getProgressBar() {
if (progressBar == null) {
progressBar = createProgressBar();
Assert.notNull(progressBar, "createProgressBar should not return null");
}
return progressBar;
}
protected JProgressBar createProgressBar() {
return new JProgressBar();
}
public boolean isIndeterminate() {
return indeterminate;
}
/**
* Determines whether the progress bar is in determinate or indeterminate mode. Default is true
*
* @param indeterminate
* true
if the progress bar should change to indeterminate mode; false
if
* it should revert to normal.
* @see JProgressBar#setIndeterminate(boolean)
*/
public void setIndeterminate(boolean indeterminate) {
this.indeterminate = indeterminate;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy