Package ca.corbett.extras.progress
Class SplashProgressWindow
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
javax.swing.JWindow
ca.corbett.extras.progress.SplashProgressWindow
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,RootPaneContainer
Normally the SplashScreen that comes with AWT is good enough for an application, but if the
app has some costly process to go through before the UI is shown, it is useful to be able to
show a progress bar with the splash screen, to give the user some idea of how startup is going.
- Since:
- 2022-05-10
- Author:
- scorbo2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JWindow
JWindow.AccessibleJWindowNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
Fields inherited from class javax.swing.JWindow
accessibleContext, rootPane, rootPaneCheckingEnabledFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionSplashProgressWindow(Color fgColor, Color bgColor, BufferedImage splashImage) If you do have an application logo image at the ready, use this constructor to display a splash screen based on the given image.SplashProgressWindow(Frame owner, Color fgColor, Color bgColor, BufferedImage splashImage) Very generally, the SplashProgressWindow will never have a parent frame, as it is intended to be used as a standalone splash screen on application startup.SplashProgressWindow(Frame owner, String appName, LogoProperty config) Very generally, the SplashProgressWindow will never have a parent frame, as it is intended to be used as a standalone splash screen on application startup.SplashProgressWindow(String appName, LogoProperty config) If you don't have an application logo image at the ready, use this constructor to dynamically generate one on the fly (using LogoGenerator). -
Method Summary
Modifier and TypeMethodDescriptionvoidinitializeProgressBar(int totalStepCount) Configures the progress bar for the given number of work steps.voidrunWorker(SimpleProgressWorker worker) Executes the given worker thread and listens to it for progress updates.voidsetProgress(int value) Updates the progress bar to the given step number.voidshowFakeProgress(int steps, int stepDelay) Maybe you don't have a lengthy operation to perform on startup, but you still want to use the SplashProgressWindow to make it look like you're doing something.voidshowFakeProgress(int steps, int stepDelay, AbstractAction action) Maybe you don't have a lengthy operation to perform on startup, but you still want to use the SplashProgressWindow to make it look like you're doing something.Methods inherited from class javax.swing.JWindow
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setGlassPane, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update, windowInitMethods inherited from class java.awt.Window
addNotify, addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBackground, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setOpacity, setShape, setSize, setSize, setType, setVisible, show, toBack, toFrontMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
SplashProgressWindow
If you don't have an application logo image at the ready, use this constructor to dynamically generate one on the fly (using LogoGenerator). You must supply enough information about the app to make this possible.- Parameters:
appName- The name of the application.config- The LogoConfig instance containing cosmetic parameters for the logo image.
-
SplashProgressWindow
Very generally, the SplashProgressWindow will never have a parent frame, as it is intended to be used as a standalone splash screen on application startup. But, for testing purposes (or perhaps for some custom scenario), this constructor is offered as a way to set a parent frame for it.- Parameters:
owner- The owning Frame (can be null for no owner).appName- The name of the application (used as logo text)config- The LogoConfig instance containing cosmetic parameters for the logo image.
-
SplashProgressWindow
If you do have an application logo image at the ready, use this constructor to display a splash screen based on the given image. You must still supply a background and foreground color so the progress bar can be styled to match the logo image.- Parameters:
fgColor- The foreground colour for the progress bar.bgColor- The background colour for the progress bar.splashImage- The application logo image. Window dimensions will be based on this image's dimensions.
-
SplashProgressWindow
Very generally, the SplashProgressWindow will never have a parent frame, as it is intended to be used as a standalone splash screen on application startup. But, for testing purposes (or perhaps for some custom scenario), this constructor is offered as a way to set a parent frame for it.- Parameters:
fgColor- The foreground colour for the progress bar.bgColor- The background colour for the progress bar.splashImage- The application logo image. Window dimensions will be based on this image's dimensions.
-
-
Method Details
-
showFakeProgress
public void showFakeProgress(int steps, int stepDelay) Maybe you don't have a lengthy operation to perform on startup, but you still want to use the SplashProgressWindow to make it look like you're doing something. This method will show the window and start a dummy worker thread to simulate some activity, based on the desired number of progress steps and the given delay between steps. When the "work" completes, the splash window will be disposed automatically.This method returns immediately, while the "work" is still in progress. If you want to be notified when the splash window has finished, you can either do the math based on steps*stepDelay or instead invoke showFakeProgress(int,int,AbstractAction).
- Parameters:
steps- How many steps of progress to fake.stepDelay- The desired delay, in milliseconds, between each work step.
-
runWorker
Executes the given worker thread and listens to it for progress updates. Auto-wires the progress bar on this window and updates it as the work progresses. When the work completes, disposes this window. Progress errors are simply ignored here. You can add your own MultiProgressAdapter to the worker before passing it in here if you wish to respond to errors.- Parameters:
worker- Any SimpleProgressWorker implementation.
-
showFakeProgress
Maybe you don't have a lengthy operation to perform on startup, but you still want to use the SplashProgressWindow to make it look like you're doing something. This method will show the window and start a dummy worker thread to simulate some activity, based on the desired number of progress steps and the given delay between steps. When the "work" completes, the splash window will be disposed automatically.The AbstractAction that you supply will be triggered when the "work" is complete.
- Parameters:
steps- How many steps of progress to fake.stepDelay- The desired delay, in milliseconds, between each work step.action- An AbstractAction to be fired when the fake work is done.
-
initializeProgressBar
public void initializeProgressBar(int totalStepCount) Configures the progress bar for the given number of work steps. You must call this before showing the window.- Parameters:
totalStepCount- The total number of steps for the progress bar.
-
setProgress
public void setProgress(int value) Updates the progress bar to the given step number. Make sure you invoke initializeProgressBar() first.- Parameters:
value- The current progress value.
-