Class Desktop
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
BaseView internal frames.
Background rendering
An optional background color and/or tiled background image can be supplied
at creation time via createDesktop(Color, String).
Layout persistence
The desktop can save and restore the position, size, and visibility of every
registered BaseView to/from an XML properties file whose location is
determined by Environment.getConfigurationFile().
Two save methods are provided:
writeConfigurationFile()— writes silently, suitable for automatic saves on exit or via toolbar actions.writeConfigurationFileInteractive()— prompts the user to confirm before overwriting an existing file, suitable for an explicit "Save Layout…" menu action.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JDesktopPane
JDesktopPane.AccessibleJDesktopPaneNested classes/interfaces inherited from class javax.swing.JLayeredPane
JLayeredPane.AccessibleJLayeredPaneNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested 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
FieldsModifier and TypeFieldDescriptionstatic final intSentinel passed to operate-on-views methods to target all views.static final intSentinel passed to operate-on-views methods to target only the top-most view.Fields inherited from class javax.swing.JDesktopPane
LIVE_DRAG_MODE, OUTLINE_DRAG_MODEFields inherited from class javax.swing.JLayeredPane
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYERFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidApply the loaded configuration properties to all registered views.static DesktopcreateDesktop(Color background, String backgroundImage) Create the singleton desktop pane.voidDelete the layout configuration file after confirming with the user.static DesktopReturns the singletonDesktopinstance.Returns the properties loaded by the most recent call toloadConfigurationFile(), ornullif no configuration has been loaded.voidLoad the layout configuration file into memory.voidPaints the desktop background, tiling the background image if one was configured.voidNotify all registeredBaseViews that the application is about to exit, giving each view a chance to stop running tasks, flush state, etc.voidWrite the current view layout to the configuration file without prompting the user.voidWrite the current view layout to the configuration file, prompting the user to confirm before overwriting an existing file.Methods inherited from class javax.swing.JDesktopPane
addImpl, getAccessibleContext, getAllFrames, getAllFramesInLayer, getDesktopManager, getDragMode, getSelectedFrame, getUI, getUIClassID, paramString, remove, remove, removeAll, selectFrame, setComponentZOrder, setDesktopManager, setDragMode, setSelectedFrame, setUI, updateUIMethods inherited from class javax.swing.JLayeredPane
getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, putLayer, setLayer, setLayer, setPositionMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
ALL_VIEWS
public static final int ALL_VIEWSSentinel passed to operate-on-views methods to target all views.- See Also:
-
TOP_VIEW
public static final int TOP_VIEWSentinel passed to operate-on-views methods to target only the top-most view.- See Also:
-
-
Method Details
-
createDesktop
Create the singleton desktop pane.If the singleton already exists this method returns the existing instance unchanged; the arguments are ignored on subsequent calls.
- Parameters:
background- optional background colorbackgroundImage- optional path of a tiled background image resource- Returns:
- the singleton
Desktop
-
getInstance
Returns the singletonDesktopinstance.- Returns:
- the singleton, or
nullifcreateDesktop(Color, String)has not yet been called
-
paintComponent
Paints the desktop background, tiling the background image if one was configured.- Overrides:
paintComponentin classJComponent- Parameters:
g- the graphics context
-
loadConfigurationFile
public void loadConfigurationFile()Load the layout configuration file into memory.The file path is determined by
Environment.getConfigurationFile(). If the file does not exist, cannot be read, cannot be parsed, or is empty, this method is a no-op (the internal property set is cleared so that a subsequentconfigureViews()call is also a no-op).Call
configureViews()after this method to apply the loaded state to the registered views. -
getSavedProperties
Returns the properties loaded by the most recent call toloadConfigurationFile(), ornullif no configuration has been loaded.This is used by
ViewConfigurationto apply saved state to lazily-created views at the moment they are realized, since those views do not exist as frames whenconfigureViews()runs at startup.The returned object is the live internal instance; callers must not modify it.
- Returns:
- the loaded configuration properties, or
null
-
configureViews
public void configureViews()Apply the loaded configuration properties to all registered views.Each
JInternalFrameon the desktop that is aBaseViewhas its state restored viaBaseView.setFromProperties(Properties). This is a no-op ifloadConfigurationFile()has not been called or if the load produced no usable properties.VirtualViewis intentionally excluded: its position is always fixed at (0, 0) upper-left by the framework and must not be overridden by a saved layout. -
writeConfigurationFile
public void writeConfigurationFile()Write the current view layout to the configuration file without prompting the user.This is the preferred path for automatic saves (e.g. on application exit or via a toolbar button). It overwrites any existing file silently. For a save that confirms before overwriting, use
writeConfigurationFileInteractive().The file path is determined by
Environment.getConfigurationFile(). If the path cannot be determined, or if the write fails, the failure is logged and this method returns without throwing. -
writeConfigurationFileInteractive
public void writeConfigurationFileInteractive()Write the current view layout to the configuration file, prompting the user to confirm before overwriting an existing file.This method is intended for an explicit "Save Layout…" menu action where user confirmation is appropriate. For automatic/silent saves use
writeConfigurationFile()instead.On success a confirmation dialog informs the user of the saved path.
-
deleteConfigurationFile
public void deleteConfigurationFile()Delete the layout configuration file after confirming with the user.This is a no-op if no configuration file path can be determined or if the file does not exist.
-
prepareForExit
public void prepareForExit()Notify all registeredBaseViews that the application is about to exit, giving each view a chance to stop running tasks, flush state, etc.If this method is called from a thread other than the EDT it re-dispatches itself via
SwingUtilities.invokeLater(Runnable).
-