Class PropertiesDialog
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,RootPaneContainer,WindowConstants
- Direct Known Subclasses:
ActionPanelPropertiesDialog,TabPanePropertiesDialog
- "Classic" style: this organizes properties into a tabbed pane, with each property category getting its own tab.
- "Action panel" style: this organizes properties into an ActionPanel on the left for navigation, with subcategories displayed in FormPanels on the right.
PropertiesDialog instances can be created manually, but it's generally better to go through AppProperties for managing your application's properties. The AppProperties class (or an application-specific derived instance) can handle auto-generating the PropertiesDialog for you.
- Since:
- swing-extras 1.8, 2024-12-30
- Author:
- scorbo2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialogNested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityTypeNested 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
FieldsModifier and TypeFieldDescriptionprotected Alignmentprotected intstatic final Alignmentstatic final intstatic final Stringstatic final intstatic final intprotected final KeyStrokeManagerstatic final intstatic final intprotected final Windowprotected final List<AbstractProperty> Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabledFields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPEFields 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, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPropertiesDialog(Window owner, String title, List<AbstractProperty> properties) Use the static factory methods to create a new PropertiesDialog instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected JPanelBuilds the ok/cancel button panel at the bottom.static PropertiesDialogcreateActionPanelDialog(Window owner, String title, List<AbstractProperty> properties, boolean addPanelHeaders) Returns a new PropertiesDialog instance with the "action panel" style, where properties are grouped into ActionGroups and laid out in an ActionPanel rather than a tabbed pane.static PropertiesDialogcreateClassicDialog(Window owner, String title, List<AbstractProperty> properties, boolean alwaysShowSubcategoryLabels) Creates and returns a "classic"-style PropertiesDialog, where each top-level category is represented as a tab in a tabbed pane, and subcategories are separated by header labels.voiddispose()Overridden so we can dispose our KeyStrokeManager when we're done.findFormField(String identifier) Returns the FormField with the given identifier if it exists anywhere on this dialog.protected abstract voidSets up the layout of this dialog and populates formPanelList with the FormPanels to be used in this dialog.protected abstract voidmakeFormPanelVisible(FormPanel formPanel) This will be invoked by our validation method in the case where a form validation error occurs.protected abstract voidSubclasses must implement this to populate the formPanels list with the FormPanels to be used in this dialog.setAlignment(Alignment alignment) Sets the preferred FormPanel alignment for all FormPanels on this dialog.setBorderMargin(int margin) Sets the preferred border margin for all FormPanels on this dialog.voidsetVisible(boolean visible) Overridden to update our position if the owner window moves.protected voidInvoked by the OK button.booleanReports whether this dialog was closed via the OK button, meaning that the form was validated and all values are acceptable.Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updateMethods inherited from class java.awt.Dialog
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, show, toBackMethods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, 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
-
Field Details
-
DIALOG_PROP
- See Also:
-
DEFAULT_ALIGNMENT
-
DEFAULT_BORDER_MARGIN
public static final int DEFAULT_BORDER_MARGIN- See Also:
-
INITIAL_WIDTH
public static final int INITIAL_WIDTH- See Also:
-
INITIAL_HEIGHT
public static final int INITIAL_HEIGHT- See Also:
-
MINIMUM_WIDTH
public static final int MINIMUM_WIDTH- See Also:
-
MINIMUM_HEIGHT
public static final int MINIMUM_HEIGHT- See Also:
-
owner
-
properties
-
formPanels
-
categories
-
subcategoriesByCategory
-
keyStrokeManager
-
alignment
-
borderMargin
protected int borderMargin
-
-
Constructor Details
-
PropertiesDialog
Use the static factory methods to create a new PropertiesDialog instance.- Parameters:
owner- The Window that owns this dialog. This is used to center the dialog over the owner.title- The title to show in the dialog header.properties- The list of properties that this dialog is meant to edit. Ideally, not empty or null.
-
-
Method Details
-
createClassicDialog
public static PropertiesDialog createClassicDialog(Window owner, String title, List<AbstractProperty> properties, boolean alwaysShowSubcategoryLabels) Creates and returns a "classic"-style PropertiesDialog, where each top-level category is represented as a tab in a tabbed pane, and subcategories are separated by header labels. This was the only style of PropertiesDialog in releases predating 2.8, and is offered here as an option for applications that don't want to switch to the new style.- Parameters:
owner- The Window that owns this dialog. This is used to center the dialog over the owner.title- The title to show in the dialog header.properties- The list of properties that this dialog is meant to edit. Ideally, not empty or null.alwaysShowSubcategoryLabels- Whether to show subcategory header labels even in the case where there's only one subcategory for a given category.- Returns:
- A new PropertiesDialog instance with the "classic" tabbed pane style.
-
createActionPanelDialog
public static PropertiesDialog createActionPanelDialog(Window owner, String title, List<AbstractProperty> properties, boolean addPanelHeaders) Returns a new PropertiesDialog instance with the "action panel" style, where properties are grouped into ActionGroups and laid out in an ActionPanel rather than a tabbed pane. This style was introduced in swing-extras 2.8, but is not mandatory - use createClassicDialog if you want to stick with the old style.You can get direct access to the ActionPanel for styling purposes by invoking getActionPanel() on the returned instance, with a class cast:
PropertiesDialog dialog = PropertiesDialog.createActionPanelDialog(owner, title, properties); ActionPanel actionPanel = ((ActionPanelPropertiesDialog)dialog).getActionPanel();Panel headers - In the ActionPanel style, you have the option to add header labels to each FormPanel. These headers will be generated based on the subcategory name. If your layout is self-explanatory, or you've already added your own LabelProperty instances, you can suppress these auto-generated header labels by setting addPanelHeaders to false.
- Parameters:
owner- The Window that owns this dialog. This is used to center the dialog over the owner.title- The title to show in the dialog header.properties- The list of properties that this dialog is meant to edit. Ideally, not empty or null.addPanelHeaders- Whether to add header labels to each FormPanel in the ActionPanel.- Returns:
- A new PropertiesDialog instance with the "action panel" style.
-
setAlignment
Sets the preferred FormPanel alignment for all FormPanels on this dialog. Can be invoked either before or after showing the dialog.- Parameters:
alignment- The preferred alignment to use for all FormPanels on this dialog. Cannot be null.- Returns:
- This PropertiesDialog instance, for chaining.
-
setBorderMargin
Sets the preferred border margin for all FormPanels on this dialog. Can be invoked either before or after showing the dialog.- Parameters:
margin- The preferred border margin to use for all FormPanels on this dialog. Cannot be negative.- Returns:
- This PropertiesDialog instance, for chaining.
-
populateFormPanels
protected abstract void populateFormPanels()Subclasses must implement this to populate the formPanels list with the FormPanels to be used in this dialog. You have access to the following class properties:- properties: the list of properties that this dialog is meant to edit.
- categories: the list of categories represented in the properties list.
- subcategoriesByCategory: a map of category name to list of subcategories for that category.
- formPanels: the (already created, but empty) List of formPanels to be populated.
Subclasses can decide how to break up the properties list into FormPanels as they see fit. The simplest example would be to simply put everything inline in one big FormPanel. A smarter example might be to use a tabbed pane with a tab for each category, or an ActionPanel with action groups for each category.
-
initLayout
protected abstract void initLayout()Sets up the layout of this dialog and populates formPanelList with the FormPanels to be used in this dialog. Descendant classes must implement this method. The expectation is that the subclass will populate the BorderLayout.CENTER region, but subclasses are also free to install something else in the NORTH, EAST, or WEST regions if they wish. The SOUTH region is reserved for our button panel. -
makeFormPanelVisible
This will be invoked by our validation method in the case where a form validation error occurs. Descendant classes must implement this method to make the given FormPanel visible to the user, so that they can see the validation errors and fix them. The details of how to do this will depend on how FormPanels are presented in this dialog, so it is left up to descendant classes.- Parameters:
formPanel- The FormPanel that contains validation errors that the user needs to fix.
-
setVisible
public void setVisible(boolean visible) Overridden to update our position if the owner window moves.- Overrides:
setVisiblein classDialog- Parameters:
visible- Whether to show or hide the dialog.
-
dispose
public void dispose()Overridden so we can dispose our KeyStrokeManager when we're done. -
wasOkayed
public boolean wasOkayed()Reports whether this dialog was closed via the OK button, meaning that the form was validated and all values are acceptable.- Returns:
- true if the form was validated and closed via the OK button, false otherwise.
-
findFormField
Returns the FormField with the given identifier if it exists anywhere on this dialog. Note that this method will return the first FormField that it finds with the given identifier. It shouldn't be possible to have multiple FormFields with the same identifier, but if this does happen, then all such fields after the first one found will be ignored by this method.- Parameters:
identifier- The string identifier of the field in question.- Returns:
- A FormField instance representing that field, or null if not found.
-
validateFormAndClose
protected void validateFormAndClose()Invoked by the OK button. Validates all FormPanels, and if any of them fail validation, makes the first one with errors visible. -
buildButtonPanel
Builds the ok/cancel button panel at the bottom. Currently not configurable.
-