Class SwingGUI


  • public class SwingGUI
    extends GUI
    A wrapper providing functionality for the overall GUI using Java Swing.
    • Field Detail

      • EUROPE_CLASSES

        private static final java.util.List<java.lang.Class<? extends FreeColPanel>> EUROPE_CLASSES
        European subpanel classes.
      • DRAG_THRESHOLD

        private static final int DRAG_THRESHOLD
        Number of pixels that must be moved before a goto is enabled.
        See Also:
        Constant Field Values
      • graphicsDevice

        private final java.awt.GraphicsDevice graphicsDevice
        The graphics device to display to.
      • imageCache

        private final ImageCache imageCache
        A persistent image cache.
      • fixedImageLibrary

        private ImageLibrary fixedImageLibrary
        The fixed/unscaled image library used by panels et al.
      • scaledImageLibrary

        private ImageLibrary scaledImageLibrary
        The scaled image library used by the map.
      • tileViewer

        private TileViewer tileViewer
        This is the TileViewer instance used for tiles in panels. It uses the fixed ImageLibrary.
      • mapViewer

        private MapViewer mapViewer
        The MapViewer instance used by canvas to paint the main map. This does need to be scaled.
      • mapControls

        private MapControls mapControls
        The various sorts of map controls.
      • canvas

        private Canvas canvas
        The canvas that implements much of the functionality.
      • widgets

        private Widgets widgets
        The widgets wrapper that handles specific panels and dialogs.
      • dragPoint

        private java.awt.Point dragPoint
        Where the map was drag-clicked.
      • gotoStarted

        private boolean gotoStarted
        Has a goto operation started?
    • Constructor Detail

      • SwingGUI

        public SwingGUI​(FreeColClient freeColClient)
        Create the GUI.
        Parameters:
        freeColClient - The FreeColClient for the game.
    • Method Detail

      • animate

        private void animate​(Animation a,
                             javax.swing.JLabel unitLabel)
        Perform a single animation.
        Parameters:
        a - The Animation to perform.
        unitLabel - The unit label to animate.
      • animations

        private void animations​(java.util.List<Animation> animations)
        Perform some animations.
        Parameters:
        animations - The Animations to perform.
      • releaseUnitOutForAnimation

        private void releaseUnitOutForAnimation​(Unit unit,
                                                javax.swing.JLabel unitLabel)
      • prepareUnitLabelsForAnimation

        private java.util.List<javax.swing.JLabel> prepareUnitLabelsForAnimation​(java.util.List<Animation> animations)
      • getDragPoint

        private java.awt.Point getDragPoint()
        Gets the point at which the map was clicked for a drag.
        Returns:
        The Point where the mouse was initially clicked.
      • setDragPoint

        private void setDragPoint​(int x,
                                  int y)
        Sets the point at which the map was clicked for a drag.
        Parameters:
        x - The mouse x position.
        y - The mouse y position.
      • isDrag

        public boolean isDrag​(int x,
                              int y)
        Is mouse movement differnce above the drag threshold?
        Parameters:
        x - The new mouse x position.
        y - The new mouse y position.
        Returns:
        True if the mouse has been dragged.
      • changeViewMode

        private boolean changeViewMode​(GUI.ViewMode newViewMode)
        Change the view mode. Always stop the blinking cursor if leaving MOVE_UNITS mode, but leave turning it on to changeActiveUnit, as there is no point enabling it if the active unit is null.
        Parameters:
        newViewMode - The new ViewMode.
        Returns:
        True if the view mode changed.
      • changeActiveUnit

        private boolean changeActiveUnit​(Unit newUnit)
        Change the active unit. If the unit changes, cancel any current gotos.
        Parameters:
        newUnit - The new active Unit.
        Returns:
        True if the active unit changed.
      • changeSelectedTile

        private boolean changeSelectedTile​(Tile newTile,
                                           boolean refocus)
        Change the selected tile. Also moves the focus tile to the selected tile if it differs and either is not on screen, or with the focus override. When the selected tile moves, the cursor needs to be redrawn, so a refresh of the old (if any) and new (if any) tile occurs.
        Parameters:
        newTile - The new Tile to select.
        refocus - If true force a refocus on all tile changes.
        Returns:
        True if the tile was changed.
      • changeDone

        private void changeDone​(boolean update)
        Finish a view mode change.
        Parameters:
        update - Update the map controls if true.
      • getMapScale

        private final float getMapScale()
        Get the map scale. Used by:
        Returns:
        The scale for the (rescalable) map.
      • getPopupPosition

        private SwingGUI.PopupPosition getPopupPosition​(Tile tile)
        Get a rough position to place a dialog given a tile which we wish to remain visible.
        Parameters:
        tile - The Tile to expose.
        Returns:
        A suitable PopupPosition.
      • updateUnitPath

        private void updateUnitPath()
        Update the path for the active unit.
      • startGoto

        private void startGoto()
        Starts a goto operation.
      • stopGoto

        private PathNode stopGoto()
        Stops any ongoing goto operation.
        Returns:
        The old goto path if any.
      • updateGotoTile

        private void updateGotoTile​(Tile tile)
        Update the current goto to a given tile.
        Parameters:
        tile - The new goto Tile.
      • paintImmediately

        public void paintImmediately()
        Paint the whole canvas now.
      • refreshTile

        public void refreshTile​(Tile tile)
        Schedule a tile to be repainted.
        Overrides:
        refreshTile in class GUI
        Parameters:
        tile - The tile to paint.
      • resetMapZoom

        private void resetMapZoom()
        Reset the map zoom and refresh the canvas.
      • getFixedImageLibrary

        public ImageLibrary getFixedImageLibrary()
        Get the fixed image library for use on panels. Used by: ColonyPanel, ConstructionPanel, InfoPanel, certain UnitLabels.
        Overrides:
        getFixedImageLibrary in class GUI
        Returns:
        Null here, real implementations will override.
      • getScaledImageLibrary

        public ImageLibrary getScaledImageLibrary()
        Get the scaled image library for use on the map.
        Overrides:
        getScaledImageLibrary in class GUI
        Returns:
        Null here, real implementations will override.
      • isWindowed

        public boolean isWindowed()
        Is this GUI in windowed mode? Used by: DragListener for a nasty workaround that should go away
        Overrides:
        isWindowed in class GUI
        Returns:
        True by default, real implementations will override.
      • invokeNowOrLater

        public void invokeNowOrLater​(java.lang.Runnable runnable)
        Run in the EDT, either immediately if in it or later when it wakes up.
        Overrides:
        invokeNowOrLater in class GUI
        Parameters:
        runnable - A Runnable to run.
      • invokeNowOrWait

        public void invokeNowOrWait​(java.lang.Runnable runnable)
        Run in the EDT, either immediately or wait for it.
        Overrides:
        invokeNowOrWait in class GUI
        Parameters:
        runnable - A Runnable to run.
      • changeWindowedMode

        public void changeWindowedMode()
        Change the windowed mode (really a toggle). Used by: ChangeWindowedModeAction
        Overrides:
        changeWindowedMode in class GUI
      • installLookAndFeel

        public void installLookAndFeel​(java.lang.String fontName)
                                throws FreeColException
        Swing system and look-and-feel initialization. Used by: FreeColClient
        Overrides:
        installLookAndFeel in class GUI
        Parameters:
        fontName - An optional font name to be used.
        Throws:
        FreeColException - if the LAF is incompatible with the GUI.
      • quitGUI

        public void quitGUI()
        Quit the GUI. All that is required is to exit the full screen. Used by: FreeColClient.quit
        Overrides:
        quitGUI in class GUI
      • reconnectGUI

        public void reconnectGUI​(Unit active,
                                 Tile tile)
        Reset the GUI on reconnect. Used by: FreeColClient.restoreGUI
        Overrides:
        reconnectGUI in class GUI
        Parameters:
        active - An optional active Unit.
        tile - An optional Tile to focus on if there is no active unit.
      • removeInGameComponents

        public void removeInGameComponents()
        Remove all in-game components (i.e. all the Listeners). Used by: ContinueAction, ConnectController.{mainTitle,newGame} InGameController.loadGame, MapEditorController.newMap, StartMapAction
        Overrides:
        removeInGameComponents in class GUI
      • showOpeningVideo

        public void showOpeningVideo​(java.lang.String userMsg,
                                     java.lang.Runnable callback)
        Shows the VideoPanel. Used by: FreeColClient
        Overrides:
        showOpeningVideo in class GUI
        Parameters:
        userMsg - An optional user message.
        callback - A Runnable to run when the video completes.
      • startGUI

        public void startGUI​(java.awt.Dimension desiredWindowSize)
        Starts the GUI by creating and displaying the GUI-objects. Used by: FreeColClient
        Overrides:
        startGUI in class GUI
        Parameters:
        desiredWindowSize - The desired size of the GUI window.
      • getMapViewDimension

        public java.awt.Dimension getMapViewDimension()
        Overrides:
        getMapViewDimension in class GUI
      • startMapEditorGUI

        public void startMapEditorGUI()
        Start the GUI for the map editor. Used by: NewPanel
        Overrides:
        startMapEditorGUI in class GUI
      • animateUnitAttack

        public void animateUnitAttack​(Unit attacker,
                                      Unit defender,
                                      Tile attackerTile,
                                      Tile defenderTile,
                                      boolean success)
        Animate a unit attack. Used by: client InGameController
        Overrides:
        animateUnitAttack in class GUI
        Parameters:
        attacker - The attacking Unit.
        defender - The defending Unit.
        attackerTile - The Tile to show the attacker on.
        defenderTile - The Tile to show the defender on.
        success - Did the attack succeed?
      • animateUnitMove

        public void animateUnitMove​(Unit unit,
                                    Tile srcTile,
                                    Tile dstTile)
        Animate a unit move. Used by: client InGameController
        Overrides:
        animateUnitMove in class GUI
        Parameters:
        unit - The Unit that is moving.
        srcTile - The Tile the unit starts at.
        dstTile - The Tile the unit moves to.
      • refreshTilesForUnit

        private void refreshTilesForUnit​(Unit unit,
                                         Tile srcTile,
                                         Tile dstTile)
        Refreshes and repaints the unit and tiles.
        Parameters:
        unit - The Unit that may have moved, and which we should use the line-of-sight for invalidating tiles.
        srcTile - The source for the unit.
        dstTile - The destination tile for the unit.
      • confirm

        public boolean confirm​(Tile tile,
                               StringTemplate tmpl,
                               javax.swing.ImageIcon icon,
                               java.lang.String okKey,
                               java.lang.String cancelKey)
        General modal confirmation dialog.
        Overrides:
        confirm in class GUI
        Parameters:
        tile - An optional Tile to expose.
        tmpl - The StringTemplate explaining the choice.
        icon - An ImageIcon to display in dialog.
        okKey - A key for the message on the "ok" button.
        cancelKey - A key for the message on the "cancel" button.
        Returns:
        True if the "ok" button was selected.
      • getChoice

        protected <T> T getChoice​(Tile tile,
                                  StringTemplate tmpl,
                                  javax.swing.ImageIcon icon,
                                  java.lang.String cancelKey,
                                  java.util.List<ChoiceItem<T>> choices)
        General modal choice dialog.
        Overrides:
        getChoice in class GUI
        Type Parameters:
        T - The choice type.
        Parameters:
        tile - An optional Tile to expose.
        tmpl - A StringTemplate explaining the choice.
        icon - An optional ImageIcon to display in dialog.
        cancelKey - A key for the message on the "cancel" button.
        choices - A list a ChoiceItems to choose from.
        Returns:
        The selected value of the selected ChoiceItem, or null if cancelled.
      • getInput

        public java.lang.String getInput​(Tile tile,
                                         StringTemplate tmpl,
                                         java.lang.String defaultValue,
                                         java.lang.String okKey,
                                         java.lang.String cancelKey)
        General modal string input dialog.
        Overrides:
        getInput in class GUI
        Parameters:
        tile - An optional Tile to expose.
        tmpl - A StringTemplate explaining the choice.
        defaultValue - The default value to show initially.
        okKey - A key for the message on the "ok" button.
        cancelKey - A key for the message on the "cancel" button.
        Returns:
        The chosen value.
      • getFocus

        public Tile getFocus()
        Get the current focus tile. Used by: MiniMap.paintMap
        Overrides:
        getFocus in class GUI
        Returns:
        The focus Tile.
      • setFocus

        public void setFocus​(Tile tileToFocus)
        Set the current focus tile. Used by: CanvasMapEditorMouseListener, CenterAction, FindSettlementPanel, InfoPanel, MiniMap.focus, MapEditorController, SelectDestinationDialog.recenter
        Overrides:
        setFocus in class GUI
        Parameters:
        tileToFocus - The new focus Tile.
      • canZoomInMapControls

        public boolean canZoomInMapControls()
        Is the map able to zoom in further? Used by: MiniMapZoomInAction
        Overrides:
        canZoomInMapControls in class GUI
        Returns:
        True if the map can zoom in.
      • canZoomOutMapControls

        public boolean canZoomOutMapControls()
        Is the map able to zoom out further? Used by: MiniMapZoomOutAction
        Overrides:
        canZoomOutMapControls in class GUI
        Returns:
        True if the map can zoom out.
      • enableMapControls

        public void enableMapControls​(boolean enable)
        Enable the map controls. Used by: MapControlsAction.
        Overrides:
        enableMapControls in class GUI
        Parameters:
        enable - If true then enable.
      • miniMapToggleViewControls

        public void miniMapToggleViewControls()
        Toggle the view control. Used by: MiniMapToggleFogOfWarAction
        Overrides:
        miniMapToggleViewControls in class GUI
      • miniMapToggleFogOfWarControls

        public void miniMapToggleFogOfWarControls()
        Toggle the fog of war control. Used by: MiniMapToggleFogOfWarAction
        Overrides:
        miniMapToggleFogOfWarControls in class GUI
      • updateMapControls

        public void updateMapControls()
        Update the map controls, including the InfoPanel according to the view mode. Used by: client InGameController.updateGUI, MapEditorController
        Overrides:
        updateMapControls in class GUI
      • zoomInMapControls

        public void zoomInMapControls()
        Zoom in the map controls. Used by: MiniMapZoomInAction
        Overrides:
        zoomInMapControls in class GUI
      • zoomOutMapControls

        public void zoomOutMapControls()
        Zoom out the map controls. Used by: MiniMapZoomOutAction
        Overrides:
        zoomOutMapControls in class GUI
      • closeMenus

        public void closeMenus()
        Close any open menus. Used by: FreeColClient.skipTurns, client InGameController.{endTurn,setCurrentPlayer} MapEditorController, PreGameController
        Overrides:
        closeMenus in class GUI
      • updateMenuBar

        public void updateMenuBar()
        Update the menu bar. Used by: InGameController.updateGUI, MapEditorController, NewEmptyMapAction
        Overrides:
        updateMenuBar in class GUI
      • showPopupMenu

        public void showPopupMenu​(javax.swing.JPopupMenu menu,
                                  int x,
                                  int y)
        Display a popup menu. Used by: ColonyPanel, DragListener
        Overrides:
        showPopupMenu in class GUI
        Parameters:
        menu - The JPopupMenu to display.
        x - The menu x coordinate.
        y - The menu y coordinate.
      • setUnitPath

        public void setUnitPath​(PathNode path)
        Set the path for the active unit. Used by: TilePopup
        Overrides:
        setUnitPath in class GUI
        Parameters:
        path - The new unit path.
      • activateGotoPath

        public void activateGotoPath()
        Start/stop the goto path display. Used by: GotoTileAction
        Overrides:
        activateGotoPath in class GUI
      • clearGotoPath

        public void clearGotoPath()
        Stop the goto path display. Used by: client InGameController.askClearGotoOrders
        Overrides:
        clearGotoPath in class GUI
      • isGotoStarted

        public boolean isGotoStarted()
        Check if the user has GoTo mode enabled. Used by: CanvasMouseListener
        Overrides:
        isGotoStarted in class GUI
        Returns:
        True if the user has toggled GoTo mode.
      • performGoto

        public void performGoto​(Tile tile)
        Perform an immediate goto to a tile with the active unit. Used by: TilePopup
        Overrides:
        performGoto in class GUI
        Parameters:
        tile - The Tile to go to.
      • performGoto

        public void performGoto​(int x,
                                int y)
        Perform an immediate goto to a point on the map. Used by: CanvasMouseListener
        Overrides:
        performGoto in class GUI
        Parameters:
        x - The x coordinate of the goto destination (pixels).
        y - The x coordinate of the goto destination (pixels).
      • traverseGotoPath

        public void traverseGotoPath()
        Send the active unit along the current goto path as far as possible. Used by: CanvasMouseListener
        Overrides:
        traverseGotoPath in class GUI
      • updateGoto

        public void updateGoto​(int x,
                               int y,
                               boolean start)
        Update the goto path to a new position on the map. Used by: CanvasMouseMotionListener
        Overrides:
        updateGoto in class GUI
        Parameters:
        x - The x coordinate for the new goto path destination (pixels).
        y - The y coordinate for the new goto path destination (pixels).
        start - If true start a new goto if one is not underway.
      • prepareDrag

        public void prepareDrag​(int x,
                                int y)
        Prepare a drag from the given coordinates. This may turn into a goto if further drag motion is detected. Used by: CanvasMouseListener
        Overrides:
        prepareDrag in class GUI
        Parameters:
        x - Drag x coordinate (pixels).
        y - Drag x coordinate (pixels).
      • getScrollDirection

        public Direction getScrollDirection​(int x,
                                            int y,
                                            int scrollSpace,
                                            boolean ignoreTop)
        Work out what direction to scroll the map if a coordinate is close to an edge.
        Overrides:
        getScrollDirection in class GUI
        Parameters:
        x - The x coordinate.
        y - The y coordinate.
        scrollSpace - The clearance from the relevant edge
        ignoreTop - If the top should be ignored
        Returns:
        The Direction to scroll, or null if not.
      • scrollMap

        public boolean scrollMap​(Direction direction)
        Scroll the map in a given direction.
        Overrides:
        scrollMap in class GUI
        Parameters:
        direction - The Direction to scroll.
        Returns:
        True if scrolling can continue.
      • createTileImage

        public java.awt.image.BufferedImage createTileImage​(Tile tile,
                                                            Player player)
        Overrides:
        createTileImage in class GUI
      • displayColonyTiles

        public void displayColonyTiles​(java.awt.Graphics2D g2d,
                                       Tile[][] tiles,
                                       Colony colony)
        Display the ColonyTiles of a Colony. Used by: ColonyPanel.TilesPanel
        Overrides:
        displayColonyTiles in class GUI
        Parameters:
        g2d - A Graphics2D to draw to.
        tiles - The Tiles to display.
        colony - The enclosing Colony.
      • getViewMode

        public GUI.ViewMode getViewMode()
        Get the current view mode. Used by: MoveAction, ToggleViewModeAction
        Overrides:
        getViewMode in class GUI
        Returns:
        One of the view mode constants, or negative on error.
      • getActiveUnit

        public Unit getActiveUnit()
        Get the active unit. Used by: many
        Overrides:
        getActiveUnit in class GUI
        Returns:
        The current active Unit.
      • getSelectedTile

        public Tile getSelectedTile()
        Get the selected tile. Used by: MoveAction, TilePopupAction, ToggleViewModeAction
        Overrides:
        getSelectedTile in class GUI
        Returns:
        The selected Tile.
      • changeView

        public void changeView​(Tile tile)
        Change to terrain mode and select a tile. Used by: CanvasMapEditorMouseListener, client InGameController.{updateActiveUnit,moveTileCursor}
        Overrides:
        changeView in class GUI
        Parameters:
        tile - The Tile to select.
      • changeView

        public void changeView​(Unit unit,
                               boolean force)
        Change to move units mode, and select a unit. Used by: ChangeAction, DebugUtils, EndTurnDialog, client InGameController (several) MapEditorController, TilePopup, QuickActionMenu, UnitLabel
        Overrides:
        changeView in class GUI
        Parameters:
        unit - The Unit to select.
        force - Set true if the unit is the same, but *has* changed in some way (e.g. moves left).
      • changeView

        public void changeView​(MapTransform mt)
        Change to map transform mode, and select a transform. Used by: MapEditorController
        Overrides:
        changeView in class GUI
        Parameters:
        mt - The MapTransform to select.
      • changeView

        public void changeView()
        Change to end turn mode. Used by: client InGameController.updateActiveUnit
        Overrides:
        changeView in class GUI
      • canZoomInMap

        public boolean canZoomInMap()
        Can the map be zoomed in? Used by: ZoomInAction
        Overrides:
        canZoomInMap in class GUI
        Returns:
        True if the map can zoom in.
      • canZoomOutMap

        public boolean canZoomOutMap()
        Can the map be zoomed out? Used by: ZoomOutAction
        Overrides:
        canZoomOutMap in class GUI
        Returns:
        True if the map can zoom out.
      • zoomInMap

        public void zoomInMap()
        Zoom the map in. Used by: ZoomInAction
        Overrides:
        zoomInMap in class GUI
      • zoomOutMap

        public void zoomOutMap()
        Zoom the map out. Used by: ZoomOutAction
        Overrides:
        zoomOutMap in class GUI
      • changeMapScale

        private void changeMapScale​(float newScale)
      • reloadResources

        public void reloadResources()
        Reloads all images managed by ResourceManager.
        Overrides:
        reloadResources in class GUI
      • prepareResources

        public void prepareResources()
      • clickAt

        public void clickAt​(int count,
                            int x,
                            int y)
        Handle a click on the canvas. Used by: CanvasMouseListener
        Overrides:
        clickAt in class GUI
        Parameters:
        count - The click count.
        x - The x coordinate of the click.
        y - The y coordinate of the click.
      • closePanel

        public void closePanel​(java.lang.String panel)
        Close a panel. Used by: client InGameController.closehandler
        Overrides:
        closePanel in class GUI
        Parameters:
        panel - The identifier for the panel to close.
      • closeMainPanel

        public void closeMainPanel()
        Close the main panel if present. Used by: MapEditorController, PreGameController
        Overrides:
        closeMainPanel in class GUI
      • closeStatusPanel

        public void closeStatusPanel()
        Close the status panel if present. Used by: FreeColClient, MapEditorController, client InGameController, PreGameController
        Overrides:
        closeStatusPanel in class GUI
      • displayChat

        public void displayChat​(java.lang.String sender,
                                java.lang.String message,
                                java.awt.Color color,
                                boolean privateChat)
        Update with a new chat message. Used by: client InGameController.{chat,chatHandler}
        Overrides:
        displayChat in class GUI
        Parameters:
        sender - The message sender.
        message - The chat message.
        color - The message color.
        privateChat - True if the message is private.
      • displayObject

        public void displayObject​(FreeColObject fco)
        Show the appropriate panel for an object.
        Overrides:
        displayObject in class GUI
        Parameters:
        fco - The FreeColObject to display.
      • displayStartChat

        public void displayStartChat​(java.lang.String sender,
                                     java.lang.String message,
                                     boolean privateChat)
        A chat message was received during the pre-game setup. Used by: PreGameController.chatHandler
        Overrides:
        displayStartChat in class GUI
        Parameters:
        sender - The player who sent the chat message.
        message - The chat message.
        privateChat - True if the message is private.
      • isClientOptionsDialogShowing

        public boolean isClientOptionsDialogShowing()
        Checks if a client options dialog is present. Used by: FreeColAction.shouldBeEnabled
        Overrides:
        isClientOptionsDialogShowing in class GUI
        Returns:
        True if the client options are showing.
      • isPanelShowing

        public boolean isPanelShowing()
        Is another panel being displayed. Used by: many Actions
        Overrides:
        isPanelShowing in class GUI
        Returns:
        True if there is another panel present.
      • refresh

        public void refresh()
        Refresh the whole GUI. This is done by invalidating any cached rendering and then repainting the entire screen. Please use only when the entire map should be fully updated. Please use MapViewerRepaintManager.markAsDirty(Tile) and GUI.repaint() instead, if only parts of the map need to be updated.
        Overrides:
        refresh in class GUI
      • refreshPlayersTable

        public void refreshPlayersTable()
        Refresh the players table in the StartGamePanel. Used by: SetNationMessage.clientHandler
        Overrides:
        refreshPlayersTable in class GUI
      • removeComponent

        public void removeComponent​(java.awt.Component component)
        Remove a component from the GUI. Used by: Many panels to close themselves. TODO: is this right?
        Overrides:
        removeComponent in class GUI
        Parameters:
        component - The Component to remove.
      • removeDialog

        public void removeDialog​(FreeColDialog<?> fcd)
        Remove a dialog from the GUI. Used by: FreeColDialog.removeNotify
        Overrides:
        removeDialog in class GUI
        Parameters:
        fcd - The FreeColDialog to remove.
      • removeTradeRoutePanel

        public void removeTradeRoutePanel​(FreeColPanel panel)
        Remove a trade route panel and associated input on an associated TradeRouteInputPanel. Used by: TradeRoutePanel
        Overrides:
        removeTradeRoutePanel in class GUI
        Parameters:
        panel - The FreeColPanel to remove.
      • restoreSavedSize

        public void restoreSavedSize​(java.awt.Component comp,
                                     java.awt.Dimension size)
        Set dialog preferred size to saved size or to the given Dimension if no saved size was found. Call this method in the constructor of a FreeColPanel in order to remember its size and position. Used by: *Panel
        Overrides:
        restoreSavedSize in class GUI
        Parameters:
        comp - The Component to use.
        size - The Dimension to use as default.
      • showTilePopup

        public void showTilePopup​(Tile tile)
        Shows a tile popup for a given tile.
        Overrides:
        showTilePopup in class GUI
        Parameters:
        tile - The Tile where the popup occurred.
      • tileAt

        public Tile tileAt​(int x,
                           int y)
        Get the tile at given coordinate.
        Overrides:
        tileAt in class GUI
        Parameters:
        x - The x coordinate.
        y - The y coordinate.
        Returns:
        The Tile found.
      • updateEuropeanSubpanels

        public void updateEuropeanSubpanels()
        Update all panels derived from the EuropePanel. Used by: NewUnitPanel, RecruitUnitPanel
        Overrides:
        updateEuropeanSubpanels in class GUI
      • showBuildQueuePanel

        public FreeColPanel showBuildQueuePanel​(Colony colony)
        Show the build queue for a colony.
        Overrides:
        showBuildQueuePanel in class GUI
        Parameters:
        colony - The Colony to show a panel for.
        Returns:
        The build queue panel.
      • showCaptureGoodsDialog

        public void showCaptureGoodsDialog​(Unit unit,
                                           java.util.List<Goods> gl,
                                           DialogHandler<java.util.List<Goods>> handler)
        Show the dialog to select captured goods.
        Overrides:
        showCaptureGoodsDialog in class GUI
        Parameters:
        unit - The Unit capturing goods.
        gl - The list of Goods to choose from.
        handler - A DialogHandler for the dialog response.
      • showChatPanel

        public FreeColPanel showChatPanel()
        Show the chat panel.
        Overrides:
        showChatPanel in class GUI
        Returns:
        The panel shown.
      • showClientOptionsDialog

        public void showClientOptionsDialog()
        Show the client options dialog.
        Overrides:
        showClientOptionsDialog in class GUI
      • refreshGuiUsingClientOptions

        public void refreshGuiUsingClientOptions()
        Refreshes the GUI with settings from the client options.
        Overrides:
        refreshGuiUsingClientOptions in class GUI
      • determineMainFontSizeUsingClientOptions

        private int determineMainFontSizeUsingClientOptions​(int dpi)
      • determineScaleFactorUsingClientOptions

        private float determineScaleFactorUsingClientOptions​(int dpi)
      • showColonyPanel

        public FreeColPanel showColonyPanel​(Colony colony,
                                            Unit unit)
        Show the colony panel
        Overrides:
        showColonyPanel in class GUI
        Parameters:
        colony - The Colony to display.
        unit - An optional Unit to select within the panel.
        Returns:
        The panel shown.
      • showColopediaPanel

        public FreeColPanel showColopediaPanel​(java.lang.String nodeId)
        Show a colopedia panel.
        Overrides:
        showColopediaPanel in class GUI
        Parameters:
        nodeId - The identifier for the colopedia node to show.
        Returns:
        The panel shown.
      • showColorChooserPanel

        public FreeColPanel showColorChooserPanel​(java.awt.event.ActionListener al)
        Show a color chooser panel.
        Overrides:
        showColorChooserPanel in class GUI
        Parameters:
        al - An ActionListener to handle panel button presses.
        Returns:
        The panel shown.
      • showCompactLabourReport

        public FreeColPanel showCompactLabourReport​(LabourData.UnitData unitData)
        Show the compact labour report for the specified unit data.
        Overrides:
        showCompactLabourReport in class GUI
        Parameters:
        unitData - The UnitData to display.
        Returns:
        The panel shown.
      • showConfirmDeclarationDialog

        public java.util.List<java.lang.String> showConfirmDeclarationDialog()
        Confirm declaration of independence.
        Overrides:
        showConfirmDeclarationDialog in class GUI
        Returns:
        A list of new nation and country names.
      • showDeclarationPanel

        public void showDeclarationPanel​(java.lang.Runnable afterClosing)
        Show the declaration panel with the declaration of independence and an animated signature.
        Overrides:
        showDeclarationPanel in class GUI
        Parameters:
        afterClosing - A callback that is executed after the panel closes.
      • showDifficultyDialog

        public OptionGroup showDifficultyDialog​(Specification spec,
                                                OptionGroup group,
                                                boolean editable)
        Show a dialog for a difficulty option group.
        Overrides:
        showDifficultyDialog in class GUI
        Parameters:
        spec - The enclosing Specification.
        group - The OptionGroup to show.
        editable - If true, the option group can be edited.
        Returns:
        The (possibly modified) OptionGroup.
      • showDumpCargoDialog

        public void showDumpCargoDialog​(Unit unit,
                                        DialogHandler<java.util.List<Goods>> handler)
        Show a dialog to choose what goods to dump.
        Overrides:
        showDumpCargoDialog in class GUI
        Parameters:
        unit - The Unit that is dumping goods.
        handler - A callback to pass the dumped goods list to.
      • showEditOptionDialog

        public boolean showEditOptionDialog​(Option option)
        Show a dialog for editing an individual option.
        Overrides:
        showEditOptionDialog in class GUI
        Parameters:
        option - The Option to edit.
        Returns:
        True if the option edit was accepted.
      • showEmigrationDialog

        public void showEmigrationDialog​(Player player,
                                         boolean fountainOfYouth,
                                         DialogHandler<java.lang.Integer> handler)
        Show a dialog to handle emigration.
        Overrides:
        showEmigrationDialog in class GUI
        Parameters:
        player - The Player whose emigration state needs work.
        fountainOfYouth - True if a Fountain of Youth event occurred.
        handler - A callback to pass a selected emigration index to.
      • showEndTurnDialog

        public void showEndTurnDialog​(java.util.List<Unit> units,
                                      DialogHandler<java.lang.Boolean> handler)
        Show a dialog for the end of turn.
        Overrides:
        showEndTurnDialog in class GUI
        Parameters:
        units - A list of Units that can still move.
        handler - A callback to handle the user selected end turn state.
      • showErrorPanel

        public FreeColPanel showErrorPanel​(java.lang.String message,
                                           java.lang.Runnable callback)
        Show an error panel.
        Overrides:
        showErrorPanel in class GUI
        Parameters:
        message - The error message to display.
        callback - An optional Runnable to run on close.
        Returns:
        The panel shown.
      • showEventPanel

        public FreeColPanel showEventPanel​(java.lang.String header,
                                           java.lang.String image,
                                           java.lang.String footer)
        Show an event panel.
        Overrides:
        showEventPanel in class GUI
        Parameters:
        header - The title.
        image - A resource key for the image to display.
        footer - Optional footer text.
        Returns:
        The panel shown.
      • showFirstContactDialog

        public void showFirstContactDialog​(Player player,
                                           Player other,
                                           Tile tile,
                                           int settlementCount,
                                           DialogHandler<java.lang.Boolean> handler)
        Show a first contact dialog.
        Overrides:
        showFirstContactDialog in class GUI
        Parameters:
        player - The Player making contact.
        other - The Player being contacted.
        tile - The Tile where the contact occurs.
        settlementCount - A count of settlements described by the other player.
        handler - A callback to handle the player decision to be friendly.
      • showGameOptionsDialog

        public OptionGroup showGameOptionsDialog​(boolean editable)
        Show the Game options dialog.
        Overrides:
        showGameOptionsDialog in class GUI
        Parameters:
        editable - True if the options can be edited.
        Returns:
        The game options OptionGroup.
      • showHighScoresPanel

        public FreeColPanel showHighScoresPanel​(java.lang.String messageId,
                                                java.util.List<HighScore> scores)
        Show the high scores panel.
        Overrides:
        showHighScoresPanel in class GUI
        Parameters:
        messageId - The message identifier.
        scores - The HighScores to display.
        Returns:
        The panel shown.
      • showInformationPanel

        public FreeColPanel showInformationPanel​(FreeColObject displayObject,
                                                 StringTemplate template)
        Show an information message.
        Overrides:
        showInformationPanel in class GUI
        Parameters:
        displayObject - Optional object for displaying as an icon.
        template - The StringTemplate to display.
        Returns:
        The panel shown.
      • showLoadDialog

        public java.io.File showLoadDialog​(java.io.File directory,
                                           java.lang.String extension)
        Show a dialog where the user may choose a file.
        Overrides:
        showLoadDialog in class GUI
        Parameters:
        directory - The directory containing the files.
        extension - An extension to select with.
        Returns:
        The selected File.
      • showLoadingSavegameDialog

        public LoadingSavegameInfo showLoadingSavegameDialog​(boolean publicServer,
                                                             boolean singlePlayer)
        Show the LoadingSavegameDialog.
        Overrides:
        showLoadingSavegameDialog in class GUI
        Parameters:
        publicServer - FIXME
        singlePlayer - FIXME
        Returns:
        The LoadingSavegameInfo from the dialog.
      • showMainPanel

        public FreeColPanel showMainPanel​(java.lang.String userMsg)
        Show the main panel.
        Overrides:
        showMainPanel in class GUI
        Parameters:
        userMsg - An optional user message to display.
        Returns:
        The panel shown.
      • showMainTitle

        public void showMainTitle()
        Complete reset back to the main panel.
        Overrides:
        showMainTitle in class GUI
      • showMapGeneratorOptionsDialog

        public OptionGroup showMapGeneratorOptionsDialog​(boolean editable)
        Show the map generator options.
        Overrides:
        showMapGeneratorOptionsDialog in class GUI
        Parameters:
        editable - If true, allow edits.
        Returns:
        The map generator OptionGroup.
      • showMapSizeDialog

        public java.awt.Dimension showMapSizeDialog()
        Show the map size dialog.
        Overrides:
        showMapSizeDialog in class GUI
        Returns:
        The selected map size as a Dimension.
      • showModelMessages

        public FreeColPanel showModelMessages​(java.util.List<ModelMessage> modelMessages)
        Show model messages.
        Overrides:
        showModelMessages in class GUI
        Parameters:
        modelMessages - A list of ModelMessages to display.
        Returns:
        The panel shown.
      • showMonarchDialog

        public void showMonarchDialog​(Monarch.MonarchAction action,
                                      StringTemplate template,
                                      java.lang.String monarchKey,
                                      DialogHandler<java.lang.Boolean> handler)
        Show the monarch dialog.
        Overrides:
        showMonarchDialog in class GUI
        Parameters:
        action - The action the monarch is taking.
        template - A message template.
        monarchKey - The identifier for the monarch.
        handler - A callback to handle the user response to the monarch action.
      • showNamingDialog

        public void showNamingDialog​(StringTemplate template,
                                     java.lang.String defaultName,
                                     Unit unit,
                                     DialogHandler<java.lang.String> handler)
        Show the naming dialog.
        Overrides:
        showNamingDialog in class GUI
        Parameters:
        template - A message template.
        defaultName - The default name for the object.
        unit - The Unit that is naming.
        handler - A callback to handle the user response.
      • showNativeDemandDialog

        public void showNativeDemandDialog​(Unit unit,
                                           Colony colony,
                                           GoodsType type,
                                           int amount,
                                           DialogHandler<java.lang.Boolean> handler)
        Show the native demand dialog.
        Overrides:
        showNativeDemandDialog in class GUI
        Parameters:
        unit - The demanding Unit.
        colony - The Colony being demanded of.
        type - The GoodsType demanded (null for gold).
        amount - The amount of goods or gold demanded.
        handler - A callback to handle the user response.
      • showNegotiationDialog

        public DiplomaticTrade showNegotiationDialog​(FreeColGameObject our,
                                                     FreeColGameObject other,
                                                     DiplomaticTrade agreement,
                                                     StringTemplate comment)
        Show the negotiation dialog.
        Overrides:
        showNegotiationDialog in class GUI
        Parameters:
        our - Our FreeColGameObject that is negotiating.
        other - The other FreeColGameObject.
        agreement - The current DiplomaticTrade agreement.
        comment - An optional StringTemplate containing a commentary message.
        Returns:
        The negotiated DiplomaticTrade agreement.
      • showNewPanel

        public FreeColPanel showNewPanel​(Specification spec)
        Show the NewPanel.
        Overrides:
        showNewPanel in class GUI
        Parameters:
        spec - The Specification to use.
        Returns:
        The panel shown.
      • showParametersDialog

        public Parameters showParametersDialog()
        Show the parameter choice dialog.
        Overrides:
        showParametersDialog in class GUI
        Returns:
        The chosen parameters.
      • showPreCombatDialog

        public boolean showPreCombatDialog​(Unit attacker,
                                           FreeColGameObject defender,
                                           Tile tile)
        Show the pre-combat dialog.
        Overrides:
        showPreCombatDialog in class GUI
        Parameters:
        attacker - The Unit that is attacking.
        defender - The FreeColObject that is defending.
        tile - The Tile where the attack occurs.
        Returns:
        True if the player decided to attack.
      • showPurchasePanel

        public FreeColPanel showPurchasePanel()
        Displays the purchase panel.
        Overrides:
        showPurchasePanel in class GUI
        Returns:
        The panel shown.
      • showRecruitPanel

        public FreeColPanel showRecruitPanel()
        Displays the recruit panel.
        Overrides:
        showRecruitPanel in class GUI
        Returns:
        The panel shown.
      • showReportLabourDetailPanel

        public FreeColPanel showReportLabourDetailPanel​(UnitType unitType,
                                                        java.util.Map<UnitType,​java.util.Map<Location,​java.lang.Integer>> data,
                                                        TypeCountMap<UnitType> unitCount,
                                                        java.util.List<Colony> colonies)
        Display the labour detail panel.
        Overrides:
        showReportLabourDetailPanel in class GUI
        Parameters:
        unitType - The UnitType to display.
        data - The labour data.
        unitCount - A map of unit distribution.
        colonies - The list of player Colonys.
        Returns:
        The panel shown.
      • showReportTurnPanel

        public FreeColPanel showReportTurnPanel​(java.util.List<ModelMessage> messages)
        Show the Turn Report.
        Overrides:
        showReportTurnPanel in class GUI
        Parameters:
        messages - The ModelMessages that make up the report.
        Returns:
        The panel shown.
      • showRiverStyleDialog

        public java.lang.String showRiverStyleDialog​(java.util.List<java.lang.String> styles)
        Show the river style dialog.
        Overrides:
        showRiverStyleDialog in class GUI
        Parameters:
        styles - The river styles a choice is made from.
        Returns:
        The response returned by the dialog.
      • showSaveDialog

        public java.io.File showSaveDialog​(java.io.File directory,
                                           java.lang.String defaultName)
        Show the save dialog.
        Overrides:
        showSaveDialog in class GUI
        Parameters:
        directory - The directory containing the files.
        defaultName - The default game to save.
        Returns:
        The selected file.
      • showScaleMapSizeDialog

        public java.awt.Dimension showScaleMapSizeDialog()
        Show the map scale dialog.
        Overrides:
        showScaleMapSizeDialog in class GUI
        Returns:
        The map scale as a Dimension.
      • showSelectAmountDialog

        public int showSelectAmountDialog​(GoodsType goodsType,
                                          int available,
                                          int defaultAmount,
                                          boolean needToPay)
        Show a dialog allowing selecting an amount of goods.
        Overrides:
        showSelectAmountDialog in class GUI
        Parameters:
        goodsType - The GoodsType to select an amount of.
        available - The amount of goods available.
        defaultAmount - The amount to select to start with.
        needToPay - If true, check the player has sufficient funds.
        Returns:
        The amount selected.
      • showSelectDestinationDialog

        public Location showSelectDestinationDialog​(Unit unit)
        Show a dialog allowing the user to select a destination for a given unit.
        Overrides:
        showSelectDestinationDialog in class GUI
        Parameters:
        unit - The Unit to select a destination for.
        Returns:
        A destination for the unit, or null.
      • showSelectTributeAmountDialog

        public int showSelectTributeAmountDialog​(StringTemplate question,
                                                 int maximum)
        Show the select-tribute-amount dialog.
        Overrides:
        showSelectTributeAmountDialog in class GUI
        Parameters:
        question - a StringTemplate describing the amount of tribute to demand.
        maximum - The maximum amount available.
        Returns:
        The amount selected.
      • showServerListPanel

        public FreeColPanel showServerListPanel​(java.util.List<ServerInfo> serverList)
        Show the ServerListPanel.
        Overrides:
        showServerListPanel in class GUI
        Parameters:
        serverList - The list containing the servers retrieved from the metaserver.
        Returns:
        The panel shown.
      • showStartGamePanel

        public FreeColPanel showStartGamePanel​(Game game,
                                               Player player,
                                               boolean singlePlayerMode)
        Show the StartGamePanel.
        Overrides:
        showStartGamePanel in class GUI
        Parameters:
        game - The Game that is about to start.
        player - The Player using this client.
        singlePlayerMode - True to start a single player game.
        Returns:
        The panel shown.
      • showStatisticsPanel

        public FreeColPanel showStatisticsPanel​(java.util.Map<java.lang.String,​java.lang.String> serverStats,
                                                java.util.Map<java.lang.String,​java.lang.String> clientStats)
        Show the statistics panel.
        Overrides:
        showStatisticsPanel in class GUI
        Parameters:
        serverStats - A map of server statistics key,value pairs.
        clientStats - A map of client statistics key,value pairs.
        Returns:
        The panel shown.
      • showStatusPanel

        public FreeColPanel showStatusPanel​(java.lang.String message)
        Shows a status message which goes away when a new component is added.
        Overrides:
        showStatusPanel in class GUI
        Parameters:
        message - The text message to display on the status panel.
        Returns:
        The panel shown.
      • showTilePanel

        public FreeColPanel showTilePanel​(Tile tile)
        Show the tile panel for a given tile.
        Overrides:
        showTilePanel in class GUI
        Parameters:
        tile - The Tile to display.
        Returns:
        The panel shown.
      • showTradeRouteInputPanel

        public FreeColPanel showTradeRouteInputPanel​(TradeRoute newRoute)
        Show the trade route input panel for a given trade route.
        Overrides:
        showTradeRouteInputPanel in class GUI
        Parameters:
        newRoute - The TradeRoute to display.
        Returns:
        The panel shown.
      • showTradeRoutePanel

        public FreeColPanel showTradeRoutePanel​(Unit unit)
        Show a panel to select a trade route for a unit.
        Overrides:
        showTradeRoutePanel in class GUI
        Parameters:
        unit - An optional Unit to select a trade route for.
        Returns:
        The panel shown.
      • showTrainPanel

        public FreeColPanel showTrainPanel()
        Show the training panel.
        Overrides:
        showTrainPanel in class GUI
        Returns:
        The panel shown.
      • showVictoryDialog

        public void showVictoryDialog​(DialogHandler<java.lang.Boolean> handler)
        Show the victory dialog.
        Overrides:
        showVictoryDialog in class GUI
        Parameters:
        handler - A callback to handle the continuation decision.
      • showWarehouseDialog

        public boolean showWarehouseDialog​(Colony colony)
        Show the warehouse dialog for a colony. Run out of ColonyPanel, so the tile is already displayed.
        Overrides:
        showWarehouseDialog in class GUI
        Parameters:
        colony - The Colony to display.
        Returns:
        The response returned by the dialog.
      • showWorkProductionPanel

        public FreeColPanel showWorkProductionPanel​(Unit unit)
        Show the production of a unit.
        Overrides:
        showWorkProductionPanel in class GUI
        Parameters:
        unit - The Unit to display.
        Returns:
        The panel shown.
      • prepareShowingMainMenu

        public void prepareShowingMainMenu()
        Description copied from class: GUI
        Prepares showing the main menu by removing almost everything from the view.
        Overrides:
        prepareShowingMainMenu in class GUI