Package io.github.jonestimd.swing.window
Class FrameManager<Key extends WindowInfo>
- java.lang.Object
-
- io.github.jonestimd.swing.window.FrameManager<Key>
-
- Type Parameters:
Key
- The class defining the window types (typically anenum
)
public class FrameManager<Key extends WindowInfo> extends java.lang.Object
Manages an application's windows. This class creates window and initializes their menu bar with theWindows
andHelp
menus. This class updates theWindows
menu whenever another window is opened or closed. Typically, menu items for opening new windows are created usingFrameAction
. Non-singleton windows can be reused by overridingApplicationWindowAction.matches(StatusFrame)
.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
WINDOWS_MENU_KEY
-
Constructor Summary
Constructors Constructor Description FrameManager(java.util.ResourceBundle bundle, java.util.function.Function<Key,? extends java.awt.Container> singletonPanelSupplier, java.util.Map<Key,PanelFactory<? extends ApplicationWindowAction<Key>>> panelFactories, java.util.function.Function<java.awt.Window,java.awt.Dialog> aboutDialogSupplier)
Create a FrameManager that uses defaultStatusFrame
s.FrameManager(java.util.ResourceBundle bundle, java.util.function.Function<Key,? extends java.awt.Container> singletonPanelSupplier, java.util.Map<Key,PanelFactory<? extends ApplicationWindowAction<Key>>> panelFactories, java.util.function.Function<java.awt.Window,java.awt.Dialog> aboutDialogSupplier, java.util.function.BiFunction<java.util.ResourceBundle,java.lang.String,StatusFrame> frameFactory)
Create a FrameManager that uses customStatusFrame
s.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFrame(StatusFrame frame, java.awt.Container contentPane)
java.awt.Container
addFrame(StatusFrame frame, Key windowType)
Add an existing non-singleton window to this manager and initialize its content pane.void
addSingletonFrame(Key key, StatusFrame frame)
Register a singleton window.protected StatusFrame
createFrame(ApplicationWindowAction<Key> action)
Create and display a non-singleton window.int
getFrameCount()
StatusFrame
onWindowEvent(ApplicationWindowAction<Key> action)
Display a singleton window or create a new instance of a non-singleton window.StatusFrame
showFrame(ApplicationWindowAction<Key> action)
Make a non-singleton window visible or, if it is already visible, bring it to the front.StatusFrame
showSingletonFrame(Key key)
Make a singleton window visible or, if it is already visible, bring it to the front.
-
-
-
Field Detail
-
WINDOWS_MENU_KEY
protected static final java.lang.String WINDOWS_MENU_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FrameManager
public FrameManager(java.util.ResourceBundle bundle, java.util.function.Function<Key,? extends java.awt.Container> singletonPanelSupplier, java.util.Map<Key,PanelFactory<? extends ApplicationWindowAction<Key>>> panelFactories, java.util.function.Function<java.awt.Window,java.awt.Dialog> aboutDialogSupplier)
Create a FrameManager that uses defaultStatusFrame
s.- Parameters:
bundle
- theResourceBundle
to use for localization of the windowssingletonPanelSupplier
- a function that returns the content panels of the singleton windowspanelFactories
- a map of the factories for the content panels of the non-singleton windowsaboutDialogSupplier
- a factory for creating theAbout
dialog
-
FrameManager
public FrameManager(java.util.ResourceBundle bundle, java.util.function.Function<Key,? extends java.awt.Container> singletonPanelSupplier, java.util.Map<Key,PanelFactory<? extends ApplicationWindowAction<Key>>> panelFactories, java.util.function.Function<java.awt.Window,java.awt.Dialog> aboutDialogSupplier, java.util.function.BiFunction<java.util.ResourceBundle,java.lang.String,StatusFrame> frameFactory)
Create a FrameManager that uses customStatusFrame
s.- Parameters:
bundle
- theResourceBundle
to use for localization of the windowssingletonPanelSupplier
- a function that returns the content panels of the singleton windowspanelFactories
- a map of the factories for the content panels of the non-singleton windowsaboutDialogSupplier
- a factory for creating theAbout
dialogframeFactory
- a factory for creatingStatusFrame
s for the windows
-
-
Method Detail
-
onWindowEvent
public StatusFrame onWindowEvent(ApplicationWindowAction<Key> action)
Display a singleton window or create a new instance of a non-singleton window.- Parameters:
action
- action describing the window- Returns:
- the matching window
-
addSingletonFrame
public void addSingletonFrame(Key key, StatusFrame frame)
Register a singleton window.- Parameters:
key
- the window typeframe
- the window- Throws:
java.lang.IllegalArgumentException
- if another window has already been registered for the specifiedkey
-
showSingletonFrame
public StatusFrame showSingletonFrame(Key key)
Make a singleton window visible or, if it is already visible, bring it to the front.- Parameters:
key
- the window type- Returns:
- the singleton window
-
showFrame
public StatusFrame showFrame(ApplicationWindowAction<Key> action)
Make a non-singleton window visible or, if it is already visible, bring it to the front.- Parameters:
action
- the action that identifies the window- Returns:
- the window
-
createFrame
protected StatusFrame createFrame(ApplicationWindowAction<Key> action)
Create and display a non-singleton window.- Parameters:
action
- the window action specifying the type of window- Returns:
- the new window
-
addFrame
public java.awt.Container addFrame(StatusFrame frame, Key windowType)
Add an existing non-singleton window to this manager and initialize its content pane.- Parameters:
frame
- the windowwindowType
- the window type- Returns:
- the new content pane
-
addFrame
public void addFrame(StatusFrame frame, java.awt.Container contentPane)
-
getFrameCount
public int getFrameCount()
-
-