Class 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 is where lower level graphics coordination occurs. Specific panels and dialogs are over in Widgets (TODO) with a few exceptions.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Canvas.ToolBoxFrame
      A class for frames being used as tool boxes.
      • 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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.swing.Timer animationTimer
      A timer triggering repaints in order to display animations on the CanvasMapViewer.
      private CanvasMapViewer canvasMapViewer
      The panel used for displaying the map and drawing the background of this class.
      private java.util.List<FreeColDialog<?>> dialogs
      The dialogs in view.
      private FreeColClient freeColClient
      The game client.
      static java.awt.Cursor GO_CURSOR
      The cursor to show for goto operations.
      private java.awt.GraphicsDevice graphicsDevice
      The graphics device to display to.
      private GrayLayer greyLayer
      The special overlay used when it is not the player turn.
      private static java.util.logging.Logger logger  
      private MainPanel mainPanel
      The main panel.
      private MapControls mapControls
      The various sorts of map controls.
      private MapViewer mapViewer
      The component that displays the map.
      private static int MAXTRY
      Number of tries to find a clear spot on the canvas.
      private java.awt.Dimension oldSize
      Remember the current size (from getSize()), check for changes.
      private FreeColFrame parentFrame
      The parent frame, either a window or the full screen.
      private boolean windowed
      Is the canvas in windowed mode?
      • 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

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor Description
      Canvas​(FreeColClient freeColClient, java.awt.GraphicsDevice graphicsDevice, java.awt.Dimension desiredSize, MapViewer mapViewer, MapControls mapControls)
      The constructor to use.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private javax.swing.JInternalFrame addAsFrame​(javax.swing.JComponent comp, boolean toolBox, SwingGUI.PopupPosition popupPosition, boolean resizable)
      Adds a component on this Canvas inside a frame.
      private void addCentered​(java.awt.Component comp, java.lang.Integer layer)
      Adds a component centered on this Canvas.
      boolean addMapControls()
      Add the map controls.
      private void addToCanvas​(java.awt.Component comp, java.lang.Integer layer)
      Adds a component to this Canvas updating the menus.
      private void addToLayer​(java.awt.Component comp, java.lang.Integer layer)
      Adds a component to this Canvas.
      void animationLabel​(javax.swing.JLabel label, boolean add)
      Add and remove animation labels.
      private static boolean checkWindowed​(java.awt.GraphicsDevice gd, java.awt.Dimension desiredSize)
      Determine whether to use full screen or windowed mode.
      private java.awt.Point chooseLocation​(java.awt.Component comp, int width, int height, SwingGUI.PopupPosition popupPosition)
      Choose a location for a component.
      void closeMainPanel()
      Closes the MainPanel.
      void closeMenus()
      Closes all the menus that are currently open.
      void closePanel​(java.lang.String panel)
      Close a panel by class name.
      private FreeColFrame createFrame​(javax.swing.JMenuBar menuBar, java.awt.Rectangle windowBounds)
      Create a new frame with a given menu bar and bounds.
      private void destroyFrame()
      Destroy the current frame.
      void dialogAdd​(FreeColDialog<?> fcd)
      Add a dialog to the current dialog list.
      void dialogRemove​(FreeColDialog<?> fcd)
      Remove a dialog from the current dialog list.
      private java.awt.Point getClearSpace​(int x, int y, int w, int h, int tries)
      Try to find some free space on the canvas for a component, starting at x,y.
      FreeColDialog<?> getExistingFreeColDialog​(java.lang.Class<?> type)
      Get a currentlydisplayed FreeColDialog of a given type.
      <T extends FreeColPanel>
      T
      getExistingFreeColPanel​(java.lang.Class<T> type)
      Gets a currently displayed FreeColPanel of a given type.
      private javax.swing.JInternalFrame getInternalFrame​(java.awt.Component c)
      Gets the internal frame for the given component.
      java.awt.Component getMatchingComponent​(java.util.function.Predicate<java.awt.Component> pred)
      Gets any currently displayed component matching a predicate.
      FreeColFrame getParentFrame()
      Get the parent frame.
      private java.awt.Point getSavedPosition​(java.awt.Component comp)
      Gets the saved position of a component.
      private java.awt.Dimension getSavedSize​(java.awt.Component comp)
      Get the saved size of a component.
      java.awt.Component getShowingPanel()
      Get any panel this Canvas is displaying.
      void initializeInGame()
      In game initializations.
      boolean isWindowed()
      Are we in windowed mode?
      void mainTitle()
      Closes all panels, changes the background and shows the main menu.
      private boolean nothingShowing()
      Is nothing showing?
      private void notifyClose​(java.awt.Component c, javax.swing.JInternalFrame jif)
      A component is closing.
      void paintComponent​(java.awt.Graphics g)
      void paintJustTheMapImmediately()  
      void playVideo​(java.lang.String videoId, boolean muteAudio, java.lang.Runnable runnable)
      Play the opening video.
      void prepareShowingMainMenu()  
      void quit()
      Quit the canvas.
      void remove​(java.awt.Component comp)
      void removeFromCanvas​(java.awt.Component comp)
      Removes the given component from this canvas without updating the menu bar.
      void removeInGameComponents()
      Removes components that is only used when in game.
      boolean removeMapControls()
      Remove the map controls.
      void resetMenuBar()
      Reset the menu bar.
      void restoreSavedSize​(java.awt.Component comp, java.awt.Dimension d)
      Set preferred size to saved size, or to the given Dimension if no saved size was found.
      private void saveInteger​(java.lang.String className, java.lang.String key, int value)
      Save an int value to the saved ClientOptions, using the name of the components class plus the given key as and identifier.
      private void savePosition​(java.awt.Component comp, java.awt.Point position)
      Save the position of a component.
      private void saveSize​(java.awt.Component comp, java.awt.Dimension size)
      Save the size of a component.
      <T> T showFreeColDialog​(FreeColDialog<T> dialog, SwingGUI.PopupPosition pos)
      Displays the given dialog, optionally making sure a tile is visible.
      FreeColPanel showFreeColPanel​(FreeColPanel panel, SwingGUI.PopupPosition popupPosition, boolean resizable)
      Displays a FreeColPanel at a generalized position.
      FreeColPanel showMainPanel()
      Shows the MainPanel.
      void showMapEditorTransformPanel()
      Display the map editor transform panel.
      void startMapEditorGUI()
      Map editor initialization.
      void toggleFrame()
      Toggle the frame between windowed and non-windowed modes.
      private void toggleWindowed()
      Toggle windowed flag.
      void updateMenuBar()
      Update the menu bar.
      private void updateSize()  
      <T> void viewFreeColDialog​(FreeColDialog<T> freeColDialog, SwingGUI.PopupPosition pos)
      Displays the given dialog, optionally making sure a tile is visible.
      • Methods inherited from class javax.swing.JDesktopPane

        addImpl, getAccessibleContext, getAllFrames, getAllFramesInLayer, getDesktopManager, getDragMode, getSelectedFrame, getUI, getUIClassID, paramString, remove, removeAll, selectFrame, setComponentZOrder, setDesktopManager, setDragMode, setSelectedFrame, setUI, updateUI
      • Methods inherited from class javax.swing.JLayeredPane

        getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, putLayer, 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, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingOrigin, 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, 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, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • MAXTRY

        private static final int MAXTRY
        Number of tries to find a clear spot on the canvas.
        See Also:
        Constant Field Values
      • GO_CURSOR

        public static final java.awt.Cursor GO_CURSOR
        The cursor to show for goto operations.
      • freeColClient

        private final FreeColClient freeColClient
        The game client.
      • graphicsDevice

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

        private boolean windowed
        Is the canvas in windowed mode?
      • parentFrame

        private FreeColFrame parentFrame
        The parent frame, either a window or the full screen.
      • oldSize

        private java.awt.Dimension oldSize
        Remember the current size (from getSize()), check for changes.
      • mapViewer

        private final MapViewer mapViewer
        The component that displays the map. Ideally this would be completely separate, but the displayMap (and possibly changeSize) call/s means we must retain a reference to the map viewer. We also use it for the Cursor, which remains in MapViewer so that displayMap can draw it when active needed.
      • mapControls

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

        private GrayLayer greyLayer
        The special overlay used when it is not the player turn.
      • dialogs

        private final java.util.List<FreeColDialog<?>> dialogs
        The dialogs in view.
      • mainPanel

        private MainPanel mainPanel
        The main panel. Remember this because getExistingFreeColPanel gets confused across switches between the game and the map editor which makes it hard to remove.
      • canvasMapViewer

        private CanvasMapViewer canvasMapViewer
        The panel used for displaying the map and drawing the background of this class.
      • animationTimer

        private javax.swing.Timer animationTimer
        A timer triggering repaints in order to display animations on the CanvasMapViewer.
    • Constructor Detail

      • Canvas

        public Canvas​(FreeColClient freeColClient,
                      java.awt.GraphicsDevice graphicsDevice,
                      java.awt.Dimension desiredSize,
                      MapViewer mapViewer,
                      MapControls mapControls)
        The constructor to use.
        Parameters:
        freeColClient - The FreeColClient for the game.
        graphicsDevice - The GraphicsDevice to display on.
        desiredSize - The desired size of the parent frame.
        mapViewer - The object responsible of drawing the map.
        mapControls - The controls on the map.
    • Method Detail

      • updateSize

        private void updateSize()
      • toggleWindowed

        private void toggleWindowed()
        Toggle windowed flag.
      • createFrame

        private FreeColFrame createFrame​(javax.swing.JMenuBar menuBar,
                                         java.awt.Rectangle windowBounds)
        Create a new frame with a given menu bar and bounds.
        Parameters:
        menuBar - The new frames JMenuBar.
        windowBounds - The new frame bounding Rectangle.
        Returns:
        The new FreeColFrame.
      • destroyFrame

        private void destroyFrame()
        Destroy the current frame.
      • checkWindowed

        private static boolean checkWindowed​(java.awt.GraphicsDevice gd,
                                             java.awt.Dimension desiredSize)
        Determine whether to use full screen or windowed mode.
        Parameters:
        gd - The GraphicsDevice to display to.
        desiredSize - An optional window Dimension.
        Returns:
        True if windowed mode is to be used, false for full screen.
      • addAsFrame

        private javax.swing.JInternalFrame addAsFrame​(javax.swing.JComponent comp,
                                                      boolean toolBox,
                                                      SwingGUI.PopupPosition popupPosition,
                                                      boolean resizable)
        Adds a component on this Canvas inside a frame.
        Parameters:
        comp - The component to add to the canvas.
        toolBox - Should be set to true if the resulting frame is used as a toolbox (that is: it should not be counted as a frame).
        popupPosition - A preferred PopupPosition.
        resizable - Whether this component can be resized.
        Returns:
        The JInternalFrame that was created and added.
      • addCentered

        private void addCentered​(java.awt.Component comp,
                                 java.lang.Integer layer)
        Adds a component centered on this Canvas.
        Parameters:
        comp - The Component to add to this canvas.
        layer - The layer to add the component to (see JLayeredPane).
      • addToLayer

        private void addToLayer​(java.awt.Component comp,
                                java.lang.Integer layer)
        Adds a component to this Canvas.
        Parameters:
        comp - The Component to add to this canvas.
        layer - The layer to add the component to (see JLayeredPane).
      • addToCanvas

        private void addToCanvas​(java.awt.Component comp,
                                 java.lang.Integer layer)
        Adds a component to this Canvas updating the menus.
        Parameters:
        comp - The Component to add to this canvas.
        layer - The layer to add the component to (see JLayeredPane).
      • getInternalFrame

        private javax.swing.JInternalFrame getInternalFrame​(java.awt.Component c)
        Gets the internal frame for the given component.
        Parameters:
        c - The Component.
        Returns:
        The given component if this is an internal frame or the first parent that is an internal frame. Returns null if no internal frame is found.
      • nothingShowing

        private boolean nothingShowing()
        Is nothing showing?
        Returns:
        True if no dialog or panel is being shown.
      • chooseLocation

        private java.awt.Point chooseLocation​(java.awt.Component comp,
                                              int width,
                                              int height,
                                              SwingGUI.PopupPosition popupPosition)
        Choose a location for a component.
        Parameters:
        comp - The Component to place.
        width - The component width to use.
        height - The component height to use.
        popupPosition - An optional PopupPosition hint.
        Returns:
        A suitable Point to place the component.
      • getClearSpace

        private java.awt.Point getClearSpace​(int x,
                                             int y,
                                             int w,
                                             int h,
                                             int tries)
        Try to find some free space on the canvas for a component, starting at x,y.
        Parameters:
        x - A starting x coordinate.
        y - A starting y coordinate.
        w - The component width to use.
        h - The component height to use.
        tries - The number of attempts to find a clear space.
        Returns:
        A Point to place the component at or null on failure.
      • getSavedPosition

        private java.awt.Point getSavedPosition​(java.awt.Component comp)
        Gets the saved position of a component.
        Parameters:
        comp - The Component to use.
        Returns:
        The saved position as a Point, or null if no saved position is found.
      • getSavedSize

        private java.awt.Dimension getSavedSize​(java.awt.Component comp)
        Get the saved size of a component.
        Parameters:
        comp - The Component to use.
        Returns:
        A Dimension for the component or null if no saved size is found.
      • saveInteger

        private void saveInteger​(java.lang.String className,
                                 java.lang.String key,
                                 int value)
        Save an int value to the saved ClientOptions, using the name of the components class plus the given key as and identifier.
        Parameters:
        className - The class name for the component.
        key - The key to save.
        value - The value to save.
      • savePosition

        private void savePosition​(java.awt.Component comp,
                                  java.awt.Point position)
        Save the position of a component.
        Parameters:
        comp - The Component to use.
        position - The position to save.
      • saveSize

        private void saveSize​(java.awt.Component comp,
                              java.awt.Dimension size)
        Save the size of a component.
        Parameters:
        comp - The Component to use.
        size - The Dimension to save.
      • notifyClose

        private void notifyClose​(java.awt.Component c,
                                 javax.swing.JInternalFrame jif)
        A component is closing. Some components need position and size to be saved.
        Parameters:
        c - The closing Component.
        jif - The enclosing JInternalFrame.
      • removeInGameComponents

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

        public void startMapEditorGUI()
        Map editor initialization.
      • initializeInGame

        public void initializeInGame()
        In game initializations.
      • quit

        public void quit()
        Quit the canvas.
      • restoreSavedSize

        public void restoreSavedSize​(java.awt.Component comp,
                                     java.awt.Dimension d)
        Set 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.
        Parameters:
        comp - The Component to use.
        d - The Dimension to use as default.
      • animationLabel

        public void animationLabel​(javax.swing.JLabel label,
                                   boolean add)
        Add and remove animation labels.
        Parameters:
        label - A JLabel for an animation.
        add - If true, add the label, else remove it.
      • closePanel

        public void closePanel​(java.lang.String panel)
        Close a panel by class name.
        Parameters:
        panel - The panel to close.
      • dialogAdd

        public void dialogAdd​(FreeColDialog<?> fcd)
        Add a dialog to the current dialog list.
        Parameters:
        fcd - The dialog to add.
      • dialogRemove

        public void dialogRemove​(FreeColDialog<?> fcd)
        Remove a dialog from the current dialog list.
        Parameters:
        fcd - The dialog to remove.
      • getExistingFreeColDialog

        public FreeColDialog<?> getExistingFreeColDialog​(java.lang.Class<?> type)
        Get a currentlydisplayed FreeColDialog of a given type.
        Parameters:
        type - The class of dialog to look for.
        Returns:
        The FreeColDialog found, or null if none present.
      • getExistingFreeColPanel

        public <T extends FreeColPanel> T getExistingFreeColPanel​(java.lang.Class<T> type)
        Gets a currently displayed FreeColPanel of a given type.
        Type Parameters:
        T - The actual panel type.
        Parameters:
        type - The type of FreeColPanel to look for.
        Returns:
        A currently displayed FreeColPanel of the requested type, or null if none found.
      • getMatchingComponent

        public java.awt.Component getMatchingComponent​(java.util.function.Predicate<java.awt.Component> pred)
        Gets any currently displayed component matching a predicate.
        Parameters:
        pred - The predicate to apply.
        Returns:
        The first match for the predicate, or null if none found.
      • getShowingPanel

        public java.awt.Component getShowingPanel()
        Get any panel this Canvas is displaying.
        Returns:
        A Component the Canvas is displaying, or null if none found.
      • removeFromCanvas

        public void removeFromCanvas​(java.awt.Component comp)
        Removes the given component from this canvas without updating the menu bar.
        Parameters:
        comp - The Component to remove.
      • showFreeColDialog

        public <T> T showFreeColDialog​(FreeColDialog<T> dialog,
                                       SwingGUI.PopupPosition pos)
        Displays the given dialog, optionally making sure a tile is visible.
        Type Parameters:
        T - The type to be returned from the dialog.
        Parameters:
        dialog - The FreeColDialog to be displayed
        pos - A PopupPosition for the dialog.
        Returns:
        The reponse returned by the dialog.
      • showFreeColPanel

        public FreeColPanel showFreeColPanel​(FreeColPanel panel,
                                             SwingGUI.PopupPosition popupPosition,
                                             boolean resizable)
        Displays a FreeColPanel at a generalized position.
        Parameters:
        panel - FreeColPanel, panel to show
        popupPosition - PopupPosition The generalized position to place the panel.
        resizable - Should the panel be resizable?
        Returns:
        The panel.
      • viewFreeColDialog

        public <T> void viewFreeColDialog​(FreeColDialog<T> freeColDialog,
                                          SwingGUI.PopupPosition pos)
        Displays the given dialog, optionally making sure a tile is visible.
        Type Parameters:
        T - The type to be returned from the dialog.
        Parameters:
        freeColDialog - The dialog to be displayed
        pos - A PopupPosition for the dialog.
      • isWindowed

        public boolean isWindowed()
        Are we in windowed mode?
        Returns:
        True if in windowed mode.
      • getParentFrame

        public FreeColFrame getParentFrame()
        Get the parent frame. Do not use this except inside Widgets (which is really just an extension of Canvas).
        Returns:
        The parent FreeColFrame.
      • toggleFrame

        public void toggleFrame()
        Toggle the frame between windowed and non-windowed modes.
      • addMapControls

        public boolean addMapControls()
        Add the map controls.
        Returns:
        True if any were added.
      • removeMapControls

        public boolean removeMapControls()
        Remove the map controls.
        Returns:
        True if any were removed.
      • closeMenus

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

        public void resetMenuBar()
        Reset the menu bar.
      • updateMenuBar

        public void updateMenuBar()
        Update the menu bar.
      • playVideo

        public void playVideo​(java.lang.String videoId,
                              boolean muteAudio,
                              java.lang.Runnable runnable)
        Play the opening video.
        Parameters:
        videoId - An identifier for the video content.
        muteAudio - Mute if true.
        runnable - A Runnable to run on completion.
      • closeMainPanel

        public void closeMainPanel()
        Closes the MainPanel.
      • mainTitle

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

        public FreeColPanel showMainPanel()
        Shows the MainPanel.
        Returns:
        The main panel.
      • prepareShowingMainMenu

        public void prepareShowingMainMenu()
      • showMapEditorTransformPanel

        public void showMapEditorTransformPanel()
        Display the map editor transform panel.
      • paintJustTheMapImmediately

        public void paintJustTheMapImmediately()
      • paintComponent

        public void paintComponent​(java.awt.Graphics g)
        Overrides:
        paintComponent in class javax.swing.JComponent
      • remove

        public void remove​(java.awt.Component comp)
        Overrides:
        remove in class javax.swing.JDesktopPane