Package org.faceless.pdf2.viewer2.util
Class DialogPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- org.faceless.pdf2.viewer2.util.DialogPanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
public class DialogPanel extends JPanel
General purpose Dialog with OK and (optionally) Cancel button and/or other buttons, intended to give a unified L&F to all dialogs in the viewer
Typically you would call addComponent, and if action needs to be done on accept or cancel you would override acceptDialog or cancelDialog. For a no-op on these buttons these should just return, otherwise they should call super.acceptDialog/cancelDialog.
Here's a fairly typical use case:final JTextField field = new JTextField(); DialogPanel panel = new DialogPanel() { public String validateDialog() { if (field.getLength() == 0) { return "Field can't be empty"; } return null; } } panel.addComponent(field); if (panel.showDialog(pdfviewer)) { // Do something with field.getValue(); }
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description DialogPanel()
Create a new DialogPanel with an OK and Cancel buttonDialogPanel(boolean cancancel)
Create a new DialogPanelDialogPanel(boolean canok, boolean cancancel)
Create a new DialogPanel
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acceptDialog()
Action to be called when the dialog is okayed.void
addButton(String name, String text, KeyStroke keystroke, Action action)
Add a button to the Dialogvoid
addButton(String name, KeyStroke keystroke, Action action)
Add a button to the Dialogvoid
addComponent(String label, JComponent component)
Add a component to the Dialog with the specified labelvoid
addComponent(JComponent component)
Add a component to the Dialog.void
cancelDialog()
Action to be called when the dialog is cancelled.void
setButtonText(String name, String text)
Set the text on the specified buttonvoid
setModal(boolean modal)
Set whether this dialog should be modal (the default) or notboolean
showDialog(Component root)
Show the Dialog with usual window decorationsboolean
showDialog(Component root, String title)
Show the Dialog with usual window decorations and the specified titleboolean
showUndecoratedDialog(Component root)
Show the Dialog with no window decorationsString
validateDialog()
Validate the dialog - if the dialog cannot be accepted, this method should return a not-null string.-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods 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, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods 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
-
-
-
-
Constructor Detail
-
DialogPanel
public DialogPanel()
Create a new DialogPanel with an OK and Cancel button
-
DialogPanel
public DialogPanel(boolean cancancel)
Create a new DialogPanel- Parameters:
cancancel
- whether a Cancel button should be added
-
DialogPanel
public DialogPanel(boolean canok, boolean cancancel)
Create a new DialogPanel- Parameters:
canok
- whether an OK button should be addedcancancel
- whether a Cancel button should be added
-
-
Method Detail
-
validateDialog
public String validateDialog()
Validate the dialog - if the dialog cannot be accepted, this method should return a not-null string. Subclasses should override.
-
addComponent
public void addComponent(JComponent component)
Add a component to the Dialog.
-
addComponent
public void addComponent(String label, JComponent component)
Add a component to the Dialog with the specified label
-
addButton
public void addButton(String name, KeyStroke keystroke, Action action)
Add a button to the Dialog- Parameters:
name
- the name of the button (also the button text)keystroke
- the keystroke to activate the button, or nullaction
- the action to perform on the button, or null to remove the existing button
-
addButton
public void addButton(String name, String text, KeyStroke keystroke, Action action)
Add a button to the Dialog- Parameters:
name
- the name of the buttontext
- the text to display on the buttonkeystroke
- the keystroke to activate the button, or nullaction
- the action to perform on the button, or null to remove the existing button
-
setButtonText
public void setButtonText(String name, String text)
Set the text on the specified button
-
setModal
public void setModal(boolean modal)
Set whether this dialog should be modal (the default) or not
-
cancelDialog
public void cancelDialog()
Action to be called when the dialog is cancelled. By default this closes and disposes of the dialog.
-
acceptDialog
public void acceptDialog()
Action to be called when the dialog is okayed. By default this callsvalidateDialog()
and if that returns null, close the dialog and set the response to true.
-
showUndecoratedDialog
public boolean showUndecoratedDialog(Component root)
Show the Dialog with no window decorations- Returns:
- true if the dialog was OK, false otherwise
-
showDialog
public boolean showDialog(Component root)
Show the Dialog with usual window decorations- Returns:
- true if the dialog was OK, false otherwise
-
-