net.sf.freecol.client.gui.panel
Class FreeColDialog<T>

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by net.sf.freecol.client.gui.panel.FreeColPanel
                      extended by net.sf.freecol.client.gui.panel.FreeColDialog<T>
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible
Direct Known Subclasses:
CaptureGoodsDialog, ChooseFoundingFatherDialog, ClientOptionsDialog, ConfirmDeclarationDialog, DeclarationDialog, EditSettlementDialog, EmigrationPanel, ErrorPanel, EventPanel, FindSettlementDialog, GameOptionsDialog, InformationDialog, LoadingSavegameDialog, MapGeneratorOptionsDialog, MonarchPanel, NegotiationDialog, PreCombatDialog, RecruitDialog, RiverStylePanel, SelectAmountDialog, SelectDestinationDialog, TradeRouteDialog, TradeRouteInputDialog, TrainDialog, WarehouseDialog

public class FreeColDialog<T>
extends FreeColPanel

Superclass for all dialogs in FreeCol. This class also contains methods to create simple dialogs.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class net.sf.freecol.client.gui.panel.FreeColPanel
CELLBORDER, emptyMargin, LEFTCELLBORDER, TOPCELLBORDER, TOPLEFTCELLBORDER
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
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
FreeColDialog(Canvas parent)
          Constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          This function analyses an event and calls the right methods to take care of the user's requests.
static
<T> FreeColDialog<ChoiceItem<T>>
createChoiceDialog(java.lang.String text, java.lang.String cancelText, java.util.List<ChoiceItem<T>> choices)
          Creates a new FreeColDialog with a text and a cancel-button, in addition to buttons for each of the objects in the given array.
static FreeColDialog<java.lang.Boolean> createConfirmDialog(java.lang.String[] texts, javax.swing.ImageIcon[] icons, java.lang.String okText, java.lang.String cancelText)
           
static FreeColDialog<java.lang.Boolean> createConfirmDialog(java.lang.String text, java.lang.String okText, java.lang.String cancelText)
          Creates a new FreeColDialog with a text and a ok/cancel option.
static FreeColDialog<java.lang.String> createInputDialog(java.lang.String text, java.lang.String defaultValue, java.lang.String okText, java.lang.String cancelText)
          Creates a new FreeColDialog with a text field and a ok/cancel option.
static FreeColDialog<java.io.File> createLoadDialog(java.io.File directory, javax.swing.filechooser.FileFilter[] fileFilters)
          Creates a new FreeColDialog in which the user may choose a savegame to load.
static FreeColDialog<java.awt.Dimension> createMapSizeDialog()
           
static FreeColDialog<java.io.File> createSaveDialog(java.io.File directory, java.lang.String standardName, javax.swing.filechooser.FileFilter[] fileFilters, java.lang.String defaultName)
          Creates a new FreeColDialog in which the user may choose the destination of the savegame.
static javax.swing.filechooser.FileFilter getFGOFileFilter()
          Returns a filter accepting "*.fgo".
static javax.swing.filechooser.FileFilter getFSGFileFilter()
          Returns a filter accepting "*.fsg".
static javax.swing.filechooser.FileFilter getGameOptionsFileFilter()
          Returns a filter accepting all files containing a GameOptions.
 T getResponse()
          Returns the response when set by setResponse(Object response).
 void initialize()
          Used for Polymorphism in Recruit, Purchase, Train Dialogs
 void resetResponse()
          Sets that no response has been given.
 void setResponse(T response)
          Sets the response and wakes up any thread waiting for this information.
 
Methods inherited from class net.sf.freecol.client.gui.panel.FreeColPanel
createEventForwardingMouseListener, createEventForwardingMouseMotionListener, enterPressesWhenFocused, getCanvas, getClient, getController, getDefaultHeader, getDefaultTextArea, getDefaultTextArea, getDefaultTextPane, getDefaultTextPane, getGame, getLibrary, getLinkButton, getModifierFormat, getMyPlayer, isEditable, requestFocus, setCancelComponent, setSavedSize, sortModifiers
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FreeColDialog

public FreeColDialog(Canvas parent)
Constructor.

Method Detail

setResponse

public void setResponse(T response)
Sets the response and wakes up any thread waiting for this information.

Parameters:
response - The object that should be returned by getResponse().

getResponse

public T getResponse()
Returns the response when set by setResponse(Object response). Waits the thread until then.

Returns:
The object as set by setResponse(T).

resetResponse

public void resetResponse()
Sets that no response has been given.


createChoiceDialog

public static <T> FreeColDialog<ChoiceItem<T>> createChoiceDialog(java.lang.String text,
                                                                  java.lang.String cancelText,
                                                                  java.util.List<ChoiceItem<T>> choices)
Creates a new FreeColDialog with a text and a cancel-button, in addition to buttons for each of the objects in the given array.

Parameters:
text - The text that explains the choice for the user.
cancelText - The text displayed on the "cancel"-button.
choices - The ChoiceItems.
Returns:
The FreeColDialog.
See Also:
ChoiceItem

createConfirmDialog

public static FreeColDialog<java.lang.Boolean> createConfirmDialog(java.lang.String text,
                                                                   java.lang.String okText,
                                                                   java.lang.String cancelText)
Creates a new FreeColDialog with a text and a ok/cancel option. The "ok"-option calls setResponse(new Boolean(true)) and the "cancel"-option calls setResponse(new Boolean(false)).

Parameters:
text - The text that explains the choice for the user.
okText - The text displayed on the "ok"-button.
cancelText - The text displayed on the "cancel"-button.
Returns:
The FreeColDialog.

createConfirmDialog

public static FreeColDialog<java.lang.Boolean> createConfirmDialog(java.lang.String[] texts,
                                                                   javax.swing.ImageIcon[] icons,
                                                                   java.lang.String okText,
                                                                   java.lang.String cancelText)

createInputDialog

public static FreeColDialog<java.lang.String> createInputDialog(java.lang.String text,
                                                                java.lang.String defaultValue,
                                                                java.lang.String okText,
                                                                java.lang.String cancelText)
Creates a new FreeColDialog with a text field and a ok/cancel option. The "ok"-option calls setResponse(textField.getText()) and the "cancel"-option calls setResponse(null).

Parameters:
text - The text that explains the action to the user.
defaultValue - The default value appearing in the text field.
okText - The text displayed on the "ok"-button.
cancelText - The text displayed on the "cancel"-button.
Returns:
The FreeColDialog.

createMapSizeDialog

public static FreeColDialog<java.awt.Dimension> createMapSizeDialog()

createLoadDialog

public static FreeColDialog<java.io.File> createLoadDialog(java.io.File directory,
                                                           javax.swing.filechooser.FileFilter[] fileFilters)
Creates a new FreeColDialog in which the user may choose a savegame to load.

Parameters:
directory - The directory to display when choosing the file.
fileFilters - The available file filters in the dialog.
Returns:
The FreeColDialog.

createSaveDialog

public static FreeColDialog<java.io.File> createSaveDialog(java.io.File directory,
                                                           java.lang.String standardName,
                                                           javax.swing.filechooser.FileFilter[] fileFilters,
                                                           java.lang.String defaultName)
Creates a new FreeColDialog in which the user may choose the destination of the savegame.

Parameters:
directory - The directory to display when choosing the name.
standardName - This extension will be added to the specified filename (if not added by the user).
fileFilters - The available file filters in the dialog.
defaultName - Default filename for the savegame.
Returns:
The FreeColDialog.

getFSGFileFilter

public static javax.swing.filechooser.FileFilter getFSGFileFilter()
Returns a filter accepting "*.fsg".

Returns:
The filter.

getFGOFileFilter

public static javax.swing.filechooser.FileFilter getFGOFileFilter()
Returns a filter accepting "*.fgo".

Returns:
The filter.

getGameOptionsFileFilter

public static javax.swing.filechooser.FileFilter getGameOptionsFileFilter()
Returns a filter accepting all files containing a GameOptions. That is; both "*.fgo" and "*.fsg".

Returns:
The filter.

initialize

public void initialize()
Used for Polymorphism in Recruit, Purchase, Train Dialogs


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
This function analyses an event and calls the right methods to take care of the user's requests.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Overrides:
actionPerformed in class FreeColPanel
Parameters:
event - The incoming ActionEvent.