net.sf.freecol.client.gui
Class Canvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLayeredPane
                  extended by javax.swing.JDesktopPane
                      extended by net.sf.freecol.client.gui.Canvas
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public final class Canvas
extends javax.swing.JDesktopPane

The main container for the other GUI components in FreeCol. This container is where the panels, dialogs and menus are added. In addition, this is the component in which the map graphics are displayed.
Displaying panels and a dialogs

Canvas contains methods to display various panels and dialogs. Most of these methods use i18n to get localized text. Here is an example:

 
 if (canvas.showConfirmDialog("choice.text", "choice.yes", "choice.no")) { //
 DO SOMETHING. }
 
 

where "choice.text", "choice.yes" and "choice.no" are keys for a localized message. See i18n for more information.
The difference between a panel and a dialog

When displaying a dialog, using a showXXXDialog, the calling thread will wait until that dialog is dismissed before returning. In contrast, a showXXXPanel-method returns immediatly.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JDesktopPane
javax.swing.JDesktopPane.AccessibleJDesktopPane
 
Nested classes/interfaces inherited from class javax.swing.JLayeredPane
javax.swing.JLayeredPane.AccessibleJLayeredPane
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String COPYRIGHT
           
static java.lang.String LICENSE
           
static java.lang.String REVISION
           
 
Fields inherited from class javax.swing.JDesktopPane
LIVE_DRAG_MODE, OUTLINE_DRAG_MODE
 
Fields inherited from class javax.swing.JLayeredPane
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
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
Canvas(FreeColClient client, java.awt.Rectangle bounds, GUI gui)
          The constructor to use.
 
Method Summary
 java.awt.Component add(java.awt.Component comp)
          Adds a component to this Canvas.
 void add(java.awt.Component comp, java.lang.Integer i)
          Adds a component to this Canvas.
 void add(java.awt.Component comp, java.lang.Integer i, boolean update)
          Adds a component to this Canvas.
 javax.swing.JInternalFrame addAsFrame(javax.swing.JComponent comp)
          Adds a component centered on this Canvas inside a frame.
 javax.swing.JInternalFrame addAsSimpleFrame(javax.swing.JComponent comp)
          Adds a component centered on this Canvas inside a frame.
 java.awt.Component addCentered(java.awt.Component comp)
          Adds a component centered on this Canvas.
 void addCentered(java.awt.Component comp, java.lang.Integer i)
          Adds a component centered on this Canvas.
 void closeMainPanel()
          Closes the MainPanel.
 void closeMenus()
          Closes all the menus that are currently open.
 void closeStatusPanel()
          Closes the StatusPanel.
 boolean confirmQuitDialog()
          Displays a "Are you sure you want to quit"-dialog in which the user may choose to quit or cancel.
 boolean containsInGameComponents()
          Checks if this Canvas contains any ingame components.
 void deactivateMovable(javax.swing.JComponent c)
          Removes the mouse listeners for moving the frame of the given component.
 void displayChatMessage(Player sender, java.lang.String message, boolean privateChat)
          Tells the map controls that a chat message was recieved.
 void displayChatMessage(java.lang.String message)
          Displays a chat message originating from this client.
 void errorMessage(java.lang.String messageID)
          Displays an error message.
 void errorMessage(java.lang.String messageID, java.lang.String message)
          Displays an error message.
 FreeColClient getClient()
          Returns the freeColClient.
 ClientOptionsDialog getClientOptionsDialog()
          Returns the ClientOptionsDialog.
 EuropePanel getEuropePanel()
          Gets the EuropePanel.
 GUI getGUI()
          Returns this Canvas's GUI.
 javax.swing.ImageIcon getImageIcon(java.lang.Object display)
           
 ImageProvider getImageProvider()
          Returns the image provider that is being used by this canvas.
 javax.swing.JMenuBar getJMenuBar()
          Gets the menu bar.
 LoadingSavegameDialog getLoadingSavegameDialog()
          Gets the LoadingSavegameDialog.
 MainPanel getMainPanel()
          Gets the MainPanel.
 int getMenuBarHeight()
          Gets the height of the menu bar.
 StartGamePanel getStartGamePanel()
          Gets the StartGamePanel that lies in this container.
 boolean isClientOptionsDialogShowing()
          Checks if the ClientOptionsDialog is visible.
 boolean isMapboardActionsEnabled()
          Checks if mapboard actions should be enabled.
 boolean isShowingSubPanel()
          Checks if this Canvas displaying another panel.
 void newGame()
          Displays a quit dialog and, if desired, logouts the current game and shows the new game panel.
 void paintComponent(java.awt.Graphics g)
          Paints this component.
 void quit()
          Quits the application.
 void refresh()
          Refreshes this Canvas visually.
 void refreshTile(int x, int y)
          Refreshes the screen at the specified Tile.
 void refreshTile(Map.Position p)
          Refreshes the screen at the specified Tile.
 void refreshTile(Tile t)
          Refreshes the screen at the specified Tile.
 void remove(java.awt.Component comp)
          Removes the given component from this Container.
 void remove(java.awt.Component comp, boolean update)
          Removes the given component from this Container.
 void removeInGameComponents()
          Removes components that is only used when in game.
 void resetFreeColMenuBar()
          Creates and sets a FreeColMenuBar on this Canvas.
 void returnToTitle()
          Closes all panels, changes the background and shows the main menu.
 void setJMenuBar(javax.swing.JMenuBar mb)
          Sets the menu bar.
 int showArmedUnitIndianSettlementDialog(IndianSettlement settlement)
          Displays a dialog that asks the user what he wants to do with his armed unit in the indian settlement.
 void showChatPanel()
          Displays the ChatPanel.
 java.lang.Object showChoiceDialog(java.lang.String text, java.lang.String cancelText, java.util.Iterator<?> iterator)
          Displays a dialog with a text and a cancel-button, in addition to buttons for each of the objects returned for the given Iterator.
 java.lang.Object showChoiceDialog(java.lang.String text, java.lang.String cancelText, java.lang.Object[] objects)
          Displays a dialog with a text and a cancel-button, in addition to buttons for each of the objects in the array.
 int showChooseFoundingFatherDialog(int[] possibleFoundingFathers)
          Shows a panel where the player may choose the next founding father to recruit.
 boolean showClientOptionsDialog()
          Displays a dialog for setting client options.
 void showColonyPanel(Colony colony)
          Displays the colony panel of the given Colony.
 void showColopediaPanel(int type)
          Shows a panel displaying Colopedia Information.
 void showColopediaPanel(int type, int action)
          Shows a panel displaying Colopedia Information.
 boolean showConfirmDialog(ModelMessage[] messages, java.lang.String okText, java.lang.String cancelText)
          Displays a dialog with a text and a ok/cancel option.
 boolean showConfirmDialog(java.lang.String text, java.lang.String okText, java.lang.String cancelText)
          Displays a dialog with a text and a ok/cancel option.
 boolean showConfirmDialog(java.lang.String text, java.lang.String okText, java.lang.String cancelText, java.lang.String[][] replace)
          Displays a dialog with a text and a ok/cancel option.
 void showDeclarationDialog()
          Shows the DeclarationDialog.
 int showEmigrationPanel()
          Shows the panel that allows the user to choose which unit will emigrate from Europe.
 void showEuropePanel()
          Displays the EuropePanel.
 boolean showEventDialog(int eventID)
          Shows the EventPanel.
 boolean showGameOptionsDialog(boolean editable)
          Displays a dialog for setting game options.
 boolean showInciteDialog(Player enemy, int amount)
          Displays a yes/no question to the user asking if he wants to pay the given amount to an indian tribe in order to have them declare war on the given player.
 void showIndianSettlementPanel(IndianSettlement settlement)
          Displays the indian settlement panel of the given IndianSettlement.
 void showInformationMessage(java.lang.String messageId)
          Shows a message with some information and an "OK"-button.
 void showInformationMessage(java.lang.String messageId, java.lang.String[][] replace)
          Shows a message with some information and an "OK"-button.
 java.lang.String showInputDialog(java.lang.String text, java.lang.String defaultValue, java.lang.String okText, java.lang.String cancelText)
          Displays a dialog with a text field and a ok/cancel option.
 java.io.File showLoadDialog(java.io.File directory)
          Displays a dialog where the user may choose a file.
 java.io.File showLoadDialog(java.io.File directory, javax.swing.filechooser.FileFilter[] fileFilters)
          Displays a dialog where the user may choose a file.
 boolean showLoadingSavegameDialog(boolean publicServer, boolean singleplayer)
          Displays a dialog for setting options when loading a savegame.
 void showMainPanel()
          Shows the MainPanel.
 boolean showMapGeneratorOptionsDialog(boolean editable)
          Displays a dialog for setting the map generator options.
 void showModelMessage(ModelMessage modelMessage)
          Displays a single ModelMessage.
 void showModelMessages(ModelMessage[] modelMessages)
          Displays a number of ModelMessages.
 boolean showMonarchPanel(int action, java.lang.String[][] replace)
          Displays the monarch action panel.
 void showNewGamePanel()
          Displays the NewGamePanel.
 void showOpenGamePanel()
          Shows the OpenGamePanel.
 void showPopup(javax.swing.JPopupMenu popup, int x, int y)
          Shows the given popup at the given position on the screen.
 boolean showPreCombatDialog(Unit attacker, Unit defender, Settlement settlement)
          Displays the showPreCombatDialog.
 int showPurchaseDialog()
          Displays the PurchaseDialog.
 boolean showRecruitDialog()
          Displays the RecruitDialog.
 void showReportPanel(java.lang.String classname)
          Shows a report panel.
 java.io.File showSaveDialog(java.io.File directory, java.lang.String defaultName)
          Displays a dialog where the user may choose a filename.
 java.io.File showSaveDialog(java.io.File directory, java.lang.String standardName, javax.swing.filechooser.FileFilter[] fileFilters, java.lang.String defaultName)
          Displays a dialog where the user may choose a filename.
 int showScoutIndianSettlementDialog(IndianSettlement settlement)
          Displays a dialog that asks the user what he wants to do with his scout in the indian settlement.
 void showServerListPanel(java.lang.String username, java.util.ArrayList<ServerInfo> serverList)
          Displays the ServerListPanel.
 void showStartGamePanel(Game game, Player player, boolean singlePlayerMode)
          Displays the StartGamePanel.
 void showStatusPanel(java.lang.String message)
          Shows a status message that cannot be dismissed.
 void showTilePanel(Tile tile)
          Displays the tile panel of the given Tile.
 void showTilePopup(Map.Position pos, int x, int y)
          Shows a tile popup.
 TradeRoute showTradeRouteDialog()
          Displays the TradeRouteDialog.
 boolean showTradeRouteInputDialog(TradeRoute route)
          Displays the TradeRouteInputDialog.
 boolean showTrainDialog()
          Displays the TrainDialog.
 void showTurnReport(java.util.ArrayList<ModelMessage> messages)
          Displays all model messages for the current turn.
 java.util.List<java.lang.Object> showUseMissionaryDialog(IndianSettlement settlement)
          Displays a dialog that asks the user what he wants to do with his missionary in the indian settlement.
 void showVictoryPanel()
          Displays the VictoryPanel.
 void showWarehouseDialog(Colony colony)
          Displays the WarehouseDialog.
 void updateGoldLabel()
          Updates the label displaying the current amount of gold.
 void updateJMenuBar()
          Updates the menu bar.
 
Methods inherited from class javax.swing.JDesktopPane
getAccessibleContext, getAllFrames, getAllFramesInLayer, getDesktopManager, getDragMode, getSelectedFrame, getUI, getUIClassID, isOpaque, paramString, setDesktopManager, setDragMode, setSelectedFrame, setUI, updateUI
 
Methods inherited from class javax.swing.JLayeredPane
addImpl, getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, putLayer, remove, removeAll, setLayer, setLayer, setPosition
 
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, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, 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, update
 
Methods inherited from class java.awt.Container
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, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, 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, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

LICENSE

public static final java.lang.String LICENSE
See Also:
Constant Field Values

REVISION

public static final java.lang.String REVISION
See Also:
Constant Field Values
Constructor Detail

Canvas

public Canvas(FreeColClient client,
              java.awt.Rectangle bounds,
              GUI gui)
The constructor to use.

Parameters:
client - main control class.
bounds - The bounds of this Canvas.
gui - The object responsible of drawing the map onto this component.
Method Detail

getClientOptionsDialog

public ClientOptionsDialog getClientOptionsDialog()
Returns the ClientOptionsDialog.

Returns:
The ClientOptionsDialog
See Also:
ClientOptions

setJMenuBar

public void setJMenuBar(javax.swing.JMenuBar mb)
Sets the menu bar. The menu bar will be resized to fit the width of the gui and made visible.

Parameters:
mb - The menu bar.
See Also:
FreeColMenuBar

getJMenuBar

public javax.swing.JMenuBar getJMenuBar()
Gets the menu bar.

Returns:
The menu bar.
See Also:
FreeColMenuBar

updateGoldLabel

public void updateGoldLabel()
Updates the label displaying the current amount of gold.


paintComponent

public void paintComponent(java.awt.Graphics g)
Paints this component. This method will use GUI.display(java.awt.Graphics2D) to draw the map/background on this component.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - The Graphics context in which to draw this component.
See Also:
GUI.display(java.awt.Graphics2D)

getMenuBarHeight

public int getMenuBarHeight()
Gets the height of the menu bar.

Returns:
The menubar + any borders.

showStartGamePanel

public void showStartGamePanel(Game game,
                               Player player,
                               boolean singlePlayerMode)
Displays the StartGamePanel.

Parameters:
game - The Game that is about to start.
player - The Player using this client.
singlePlayerMode - 'true' if the user wants to start a single player game, 'false' otherwise.
See Also:
StartGamePanel

showServerListPanel

public void showServerListPanel(java.lang.String username,
                                java.util.ArrayList<ServerInfo> serverList)
Displays the ServerListPanel.

Parameters:
username - The username that should be used when connecting to one of the servers on the list.
serverList - The list containing the servers retrived from the metaserver.
See Also:
ServerListPanel

showVictoryPanel

public void showVictoryPanel()
Displays the VictoryPanel.

See Also:
VictoryPanel

showWarehouseDialog

public void showWarehouseDialog(Colony colony)
Displays the WarehouseDialog.

See Also:
WarehouseDialog

showChatPanel

public void showChatPanel()
Displays the ChatPanel.

See Also:
ChatPanel

showNewGamePanel

public void showNewGamePanel()
Displays the NewGamePanel.

See Also:
NewPanel

showTurnReport

public void showTurnReport(java.util.ArrayList<ModelMessage> messages)
Displays all model messages for the current turn.

Parameters:
messages - A list of messages to display.

showModelMessage

public void showModelMessage(ModelMessage modelMessage)
Displays a single ModelMessage.

Parameters:
modelMessage - The message to display.

showModelMessages

public void showModelMessages(ModelMessage[] modelMessages)
Displays a number of ModelMessages.

Parameters:
modelMessages -

getImageIcon

public javax.swing.ImageIcon getImageIcon(java.lang.Object display)

showDeclarationDialog

public void showDeclarationDialog()
Shows the DeclarationDialog.

See Also:
DeclarationDialog

showConfirmDialog

public boolean showConfirmDialog(java.lang.String text,
                                 java.lang.String okText,
                                 java.lang.String cancelText)
Displays a dialog with a text and a ok/cancel option.

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:
true if the user clicked the "ok"-button and false otherwise.
See Also:
FreeColDialog

showConfirmDialog

public boolean showConfirmDialog(java.lang.String text,
                                 java.lang.String okText,
                                 java.lang.String cancelText,
                                 java.lang.String[][] replace)
Displays a dialog with a text and a ok/cancel option.

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.
replace - An array of strings that will be inserted somewhere in the text.
Returns:
true if the user clicked the "ok"-button and false otherwise.
See Also:
FreeColDialog

showPreCombatDialog

public boolean showPreCombatDialog(Unit attacker,
                                   Unit defender,
                                   Settlement settlement)
Displays the showPreCombatDialog.

Parameters:
attacker - an Unit value
defender - an Unit value
settlement - a Settlement value
Returns:
a boolean value

showConfirmDialog

public boolean showConfirmDialog(ModelMessage[] messages,
                                 java.lang.String okText,
                                 java.lang.String cancelText)
Displays a dialog with a text and a ok/cancel option.

Parameters:
messages - The messages that explains the choice for the user.
okText - The text displayed on the "ok"-button.
cancelText - The text displayed on the "cancel"-button.
Returns:
true if the user clicked the "ok"-button and false otherwise.
See Also:
FreeColDialog

isClientOptionsDialogShowing

public boolean isClientOptionsDialogShowing()
Checks if the ClientOptionsDialog is visible.

Returns:
true if no internal frames are open.

isMapboardActionsEnabled

public boolean isMapboardActionsEnabled()
Checks if mapboard actions should be enabled.

Returns:
true if no internal frames are open.

isShowingSubPanel

public boolean isShowingSubPanel()
Checks if this Canvas displaying another panel.

Note that the previous implementation could throw exceptions in some cases, thus the change.

Returns:
true if the Canvas is displaying an internal frame.

showGameOptionsDialog

public boolean showGameOptionsDialog(boolean editable)
Displays a dialog for setting game options.

Returns:
true if the game options have been modified, and false otherwise.

getLoadingSavegameDialog

public LoadingSavegameDialog getLoadingSavegameDialog()
Gets the LoadingSavegameDialog.

Returns:
The LoadingSavegameDialog.

showLoadingSavegameDialog

public boolean showLoadingSavegameDialog(boolean publicServer,
                                         boolean singleplayer)
Displays a dialog for setting options when loading a savegame. The settings can be retrived directly from LoadingSavegameDialog after calling this method.

Parameters:
publicServer - Default value.
singleplayer - Default value.
Returns:
true if the "ok"-button was pressed and false otherwise.

showClientOptionsDialog

public boolean showClientOptionsDialog()
Displays a dialog for setting client options.

Returns:
true if the client options have been modified, and false otherwise.

showMapGeneratorOptionsDialog

public boolean showMapGeneratorOptionsDialog(boolean editable)
Displays a dialog for setting the map generator options.

Parameters:
editable - The options are only allowed to be changed if this variable is true.
Returns:
true if the options have been modified, and false otherwise.

showLoadDialog

public java.io.File showLoadDialog(java.io.File directory)
Displays a dialog where the user may choose a file. This is the same as calling:

showLoadDialog(directory, new FileFilter[] {FreeColDialog.getFSGFileFilter()});

Parameters:
directory - The directory containing the files.
Returns:
The File.
See Also:
FreeColDialog

showLoadDialog

public java.io.File showLoadDialog(java.io.File directory,
                                   javax.swing.filechooser.FileFilter[] fileFilters)
Displays a dialog where the user may choose a file.

Parameters:
directory - The directory containing the files.
fileFilters - The file filters which the user can select in the dialog.
Returns:
The File.
See Also:
FreeColDialog

showSaveDialog

public java.io.File showSaveDialog(java.io.File directory,
                                   java.lang.String defaultName)
Displays a dialog where the user may choose a filename. This is the same as calling:

showSaveDialog(directory, new FileFilter[] {FreeColDialog.getFSGFileFilter()}, defaultName);

Parameters:
directory - The directory containing the files in which the user may overwrite.
defaultName - Default filename for the savegame.
Returns:
The File.
See Also:
FreeColDialog

showSaveDialog

public java.io.File showSaveDialog(java.io.File directory,
                                   java.lang.String standardName,
                                   javax.swing.filechooser.FileFilter[] fileFilters,
                                   java.lang.String defaultName)
Displays a dialog where the user may choose a filename.

Parameters:
directory - The directory containing the files in which the user may overwrite.
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 File.
See Also:
FreeColDialog

showScoutIndianSettlementDialog

public int showScoutIndianSettlementDialog(IndianSettlement settlement)
Displays a dialog that asks the user what he wants to do with his scout in the indian settlement.

Parameters:
settlement - The indian settlement that is being scouted.
Returns:
FreeColDialog.SCOUT_INDIAN_SETTLEMENT_CANCEL if the action was cancelled, FreeColDialog.SCOUT_INDIAN_SETTLEMENT_SPEAK if he wants to speak with the chief, FreeColDialog.SCOUT_INDIAN_SETTLEMENT_TRIBUTE if he wants to demand tribute, FreeColDialog.SCOUT_INDIAN_SETTLEMENT_ATTACK if he wants to attack the settlement.

showArmedUnitIndianSettlementDialog

public int showArmedUnitIndianSettlementDialog(IndianSettlement settlement)
Displays a dialog that asks the user what he wants to do with his armed unit in the indian settlement.

Parameters:
settlement - The indian settlement that is going to be attacked or demanded.
Returns:
FreeColDialog.SCOUT_INDIAN_SETTLEMENT_CANCEL if the action was cancelled, FreeColDialog.SCOUT_INDIAN_SETTLEMENT_TRIBUTE if he wants to demand tribute, FreeColDialog.SCOUT_INDIAN_SETTLEMENT_ATTACK if he wants to attack the settlement.

showUseMissionaryDialog

public java.util.List<java.lang.Object> showUseMissionaryDialog(IndianSettlement settlement)
Displays a dialog that asks the user what he wants to do with his missionary in the indian settlement.

Parameters:
settlement - The indian settlement that is being visited.
Returns:
ArrayList with an Integer and optionally a Player refencing the player to attack in case of "incite indians". Integer can be any of: FreeColDialog.MISSIONARY_ESTABLISH if he wants to establish a mission, FreeColDialog.MISSIONARY_DENOUNCE_AS_HERESY if he wants to denounce the existing (foreign) mission as heresy, FreeColDialog.MISSIONARY_INCITE_INDIANS if he wants to incite the indians (requests their support for war against another European power), FreeColDialog.MISSIONARY_CANCEL if the action was cancelled.

showInciteDialog

public boolean showInciteDialog(Player enemy,
                                int amount)
Displays a yes/no question to the user asking if he wants to pay the given amount to an indian tribe in order to have them declare war on the given player.

Parameters:
enemy - The european player to attack.
amount - The amount of gold to pay.
Returns:
true if the players wants to pay, false otherwise.

showInputDialog

public java.lang.String showInputDialog(java.lang.String text,
                                        java.lang.String defaultValue,
                                        java.lang.String okText,
                                        java.lang.String cancelText)
Displays a dialog with a text field and a ok/cancel option.

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. Use null to disable the cancel-option.
Returns:
The text the user have entered or null if the user chose to cancel the action.
See Also:
FreeColDialog

showChoiceDialog

public java.lang.Object showChoiceDialog(java.lang.String text,
                                         java.lang.String cancelText,
                                         java.util.Iterator<?> iterator)
Displays a dialog with a text and a cancel-button, in addition to buttons for each of the objects returned for the given Iterator.

Parameters:
text - The text that explains the choice for the user.
cancelText - The text displayed on the "cancel"-button.
iterator - The Iterator containing the objects to create buttons for.
Returns:
The choosen object, or null for the cancel-button.

showChoiceDialog

public java.lang.Object showChoiceDialog(java.lang.String text,
                                         java.lang.String cancelText,
                                         java.lang.Object[] objects)
Displays a dialog with a text and a cancel-button, in addition to buttons for each of the objects in the array.

Parameters:
text - The text that explains the choice for the user.
cancelText - The text displayed on the "cancel"-button.
objects - The array containing the objects to create buttons for.
Returns:
The choosen object, or null for the cancel-button.

showStatusPanel

public void showStatusPanel(java.lang.String message)
Shows a status message that cannot be dismissed. The panel will be removed when another component is added to this Canvas. This includes all the showXXX-methods. In addition, closeStatusPanel() and closeMenus() also removes this panel.

Parameters:
message - The text message to display on the status panel.
See Also:
StatusPanel

closeStatusPanel

public void closeStatusPanel()
Closes the StatusPanel.

See Also:
showStatusPanel(java.lang.String)

showColopediaPanel

public void showColopediaPanel(int type)
Shows a panel displaying Colopedia Information.

Parameters:
type - The type of colopedia panel to display.

showColopediaPanel

public void showColopediaPanel(int type,
                               int action)
Shows a panel displaying Colopedia Information.

Parameters:
type - The type of colopedia panel to display.
action - The details to display.

showReportPanel

public void showReportPanel(java.lang.String classname)
Shows a report panel.

Parameters:
classname - The class name of the report panel to be displayed.

showChooseFoundingFatherDialog

public int showChooseFoundingFatherDialog(int[] possibleFoundingFathers)
Shows a panel where the player may choose the next founding father to recruit.

Parameters:
possibleFoundingFathers - The different founding fathers the player may choose.
Returns:
The founding father the player has chosen.
See Also:
FoundingFather

showEventDialog

public boolean showEventDialog(int eventID)
Shows the EventPanel.

Parameters:
eventID - The type of EventPanel to be displayed.
Returns:
true.

showEuropePanel

public void showEuropePanel()
Displays the EuropePanel.

See Also:
EuropePanel

showRecruitDialog

public boolean showRecruitDialog()
Displays the RecruitDialog. Does not return from this method before the panel is closed.


showPurchaseDialog

public int showPurchaseDialog()
Displays the PurchaseDialog. Does not return from this method before the panel is closed.


showTrainDialog

public boolean showTrainDialog()
Displays the TrainDialog. Does not return from this method before the panel is closed.


showTradeRouteDialog

public TradeRoute showTradeRouteDialog()
Displays the TradeRouteDialog. Does not return from this method before the panel is closed.


showTradeRouteInputDialog

public boolean showTradeRouteInputDialog(TradeRoute route)
Displays the TradeRouteInputDialog. Does not return from this method before the panel is closed.


showColonyPanel

public void showColonyPanel(Colony colony)
Displays the colony panel of the given Colony.

Parameters:
colony - The colony whose panel needs to be displayed.
See Also:
ColonyPanel

showIndianSettlementPanel

public void showIndianSettlementPanel(IndianSettlement settlement)
Displays the indian settlement panel of the given IndianSettlement.

Parameters:
settlement - The indian settlement whose panel needs to be displayed.
See Also:
IndianSettlement

showTilePanel

public void showTilePanel(Tile tile)
Displays the tile panel of the given Tile.

Parameters:
tile - The tile whose panel needs to be displayed.
See Also:
Tile

showMonarchPanel

public boolean showMonarchPanel(int action,
                                java.lang.String[][] replace)
Displays the monarch action panel.

Parameters:
action - The monarch action.
replace - The replacement strings.
Returns:
true or false
See Also:
Monarch

showEmigrationPanel

public int showEmigrationPanel()
Shows the panel that allows the user to choose which unit will emigrate from Europe. This method may only be called if the user has William Brewster in congress.

Returns:
The emigrant that was chosen by the user.

updateJMenuBar

public void updateJMenuBar()
Updates the menu bar.


resetFreeColMenuBar

public void resetFreeColMenuBar()
Creates and sets a FreeColMenuBar on this Canvas.

See Also:
FreeColMenuBar

remove

public void remove(java.awt.Component comp)
Removes the given component from this Container.

Overrides:
remove in class java.awt.Container
Parameters:
comp - The component to remove from this Container.

remove

public void remove(java.awt.Component comp,
                   boolean update)
Removes the given component from this Container.

Parameters:
comp - The component to remove from this Container.
update - The Canvas will be enabled, the graphics repainted and both the menubar and the actions will be updated if this parameter is true.

add

public java.awt.Component add(java.awt.Component comp)
Adds a component to this Canvas.

Overrides:
add in class java.awt.Container
Parameters:
comp - The component to add to this ToEuropePanel.
Returns:
The component argument.

addCentered

public java.awt.Component addCentered(java.awt.Component comp)
Adds a component centered on this Canvas. Removes the statuspanel if visible (and comp != statusPanel).

Parameters:
comp - The component to add to this ToEuropePanel.
Returns:
The component argument.

addAsFrame

public javax.swing.JInternalFrame addAsFrame(javax.swing.JComponent comp)
Adds a component centered on this Canvas inside a frame. Removes the statuspanel if visible (and comp != statusPanel).

Parameters:
comp - The component to add to this ToEuropePanel.
i - The layer to add the component to (see JLayeredPane).
Returns:
The JInternalFrame that was created and added.

addAsSimpleFrame

public javax.swing.JInternalFrame addAsSimpleFrame(javax.swing.JComponent comp)
Adds a component centered on this Canvas inside a frame. Removes the statuspanel if visible (and comp != statusPanel). The frame cannot be moved or resized.

Parameters:
comp - The component to add to this ToEuropePanel.
i - The layer to add the component to (see JLayeredPane).
Returns:
The JInternalFrame that was created and added.

deactivateMovable

public void deactivateMovable(javax.swing.JComponent c)
Removes the mouse listeners for moving the frame of the given component.

Parameters:
c - The component the listeneres should be removed from.

addCentered

public void addCentered(java.awt.Component comp,
                        java.lang.Integer i)
Adds a component centered on this Canvas. Removes the statuspanel if visible (and comp != statusPanel).

Parameters:
comp - The component to add to this ToEuropePanel.
i - The layer to add the component to (see JLayeredPane).

add

public void add(java.awt.Component comp,
                java.lang.Integer i)
Adds a component to this Canvas. Removes the statuspanel if visible (and comp != statusPanel).

Parameters:
comp - The component to add to this ToEuropePanel.
i - The layer to add the component to (see JLayeredPane).

add

public void add(java.awt.Component comp,
                java.lang.Integer i,
                boolean update)
Adds a component to this Canvas. Removes the statuspanel if visible (and comp != statusPanel).

Parameters:
comp - The component to add to this ToEuropePanel.
i - The layer to add the component to (see JLayeredPane).

getEuropePanel

public EuropePanel getEuropePanel()
Gets the EuropePanel.

Returns:
The EuropePanel.

showPopup

public void showPopup(javax.swing.JPopupMenu popup,
                      int x,
                      int y)
Shows the given popup at the given position on the screen.

Parameters:
popup - The JPopupMenu to show.
x - The x-coordinate at which to show the popup.
y - The y-coordinate at which to show the popup.

showTilePopup

public void showTilePopup(Map.Position pos,
                          int x,
                          int y)
Shows a tile popup.

Parameters:
pos - The coordinates of the Tile where the popup occured.
x - The x-coordinate on the screen where the popup needs to be placed.
y - The y-coordinate on the screen where the popup needs to be placed.
See Also:
TilePopup

errorMessage

public void errorMessage(java.lang.String messageID)
Displays an error message.

Parameters:
messageID - The i18n-keyname of the error message to display.

errorMessage

public void errorMessage(java.lang.String messageID,
                         java.lang.String message)
Displays an error message.

Parameters:
messageID - The i18n-keyname of the error message to display.
message - An alternativ message to display if the resource specified by messageID is unavailable.

showInformationMessage

public void showInformationMessage(java.lang.String messageId)
Shows a message with some information and an "OK"-button.

Parameters:
messageId - The messageId of the message to display.

showInformationMessage

public void showInformationMessage(java.lang.String messageId,
                                   java.lang.String[][] replace)
Shows a message with some information and an "OK"-button.

Example:
canvas.showInformationMessage("noNeedForTheGoods", new String[][] {{"%goods%", goods.getName()}});

Parameters:
messageId - The messageId of the message to display.
replace - All occurances of replace[i][0] in the message gets replaced by replace[i][1].

refresh

public void refresh()
Refreshes this Canvas visually.


refreshTile

public void refreshTile(int x,
                        int y)
Refreshes the screen at the specified Tile.

Parameters:
x - The x-coordinate of the Tile to refresh.
y - The y-coordinate of the Tile to refresh.

refreshTile

public void refreshTile(Tile t)
Refreshes the screen at the specified Tile.

Parameters:
t - The tile to refresh.

refreshTile

public void refreshTile(Map.Position p)
Refreshes the screen at the specified Tile.

Parameters:
p - The position of the tile to refresh.

getImageProvider

public ImageProvider getImageProvider()
Returns the image provider that is being used by this canvas.

Returns:
The image provider that is being used by this canvas.

closeMenus

public void closeMenus()
Closes all the menus that are currently open.


showMainPanel

public void showMainPanel()
Shows the MainPanel.

See Also:
MainPanel

getMainPanel

public MainPanel getMainPanel()
Gets the MainPanel.

Returns:
The MainPanel.
See Also:
MainPanel

closeMainPanel

public void closeMainPanel()
Closes the MainPanel.


showOpenGamePanel

public void showOpenGamePanel()
Shows the OpenGamePanel.


getStartGamePanel

public StartGamePanel getStartGamePanel()
Gets the StartGamePanel that lies in this container.

Returns:
The StartGamePanel.
See Also:
StartGamePanel

displayChatMessage

public void displayChatMessage(Player sender,
                               java.lang.String message,
                               boolean privateChat)
Tells the map controls that a chat message was recieved.

Parameters:
sender - The player who sent the chat message to the server.
message - The chat message.
privateChat - 'true' if the message is a private one, 'false' otherwise.
See Also:
GUIMessage

displayChatMessage

public void displayChatMessage(java.lang.String message)
Displays a chat message originating from this client.

Parameters:
message - The chat message.

quit

public void quit()
Quits the application. This method uses confirmQuitDialog() in order to get a "Are you sure"-confirmation from the user.


returnToTitle

public void returnToTitle()
Closes all panels, changes the background and shows the main menu.


removeInGameComponents

public void removeInGameComponents()
Removes components that is only used when in game.


containsInGameComponents

public boolean containsInGameComponents()
Checks if this Canvas contains any ingame components.

Returns:
true if there is a single ingame component.

confirmQuitDialog

public boolean confirmQuitDialog()
Displays a "Are you sure you want to quit"-dialog in which the user may choose to quit or cancel.

Returns:
true if the user desides to quit and false otherwise.

getGUI

public GUI getGUI()
Returns this Canvas's GUI.

Returns:
The GUI.

getClient

public FreeColClient getClient()
Returns the freeColClient.

Returns:
The freeColClient associated with this Canvas.

newGame

public void newGame()
Displays a quit dialog and, if desired, logouts the current game and shows the new game panel.