Class Widgets


  • public final class Widgets
    extends java.lang.Object
    Container for all the higher level dialogs and panels. Moved here so that Canvas is more manageable.
    • Field Detail

      • logger

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

        private final FreeColClient freeColClient
        The game client.
      • canvas

        private final Canvas canvas
        The canvas to write to.
    • Constructor Detail

      • Widgets

        public Widgets​(FreeColClient freeColClient,
                       Canvas canvas)
        Create this wrapper class.
        Parameters:
        freeColClient - The enclosing FreeColClient.
        canvas - The Canvas to call out to.
    • Method Detail

      • confirm

        public boolean confirm​(StringTemplate tmpl,
                               javax.swing.ImageIcon icon,
                               java.lang.String okKey,
                               java.lang.String cancelKey,
                               SwingGUI.PopupPosition pos)
        Show a modal dialog with a text and a ok/cancel option.
        Parameters:
        tmpl - A StringTemplate to explain the choice.
        icon - An optional icon to display.
        okKey - The text displayed on the "ok"-button.
        cancelKey - The text displayed on the "cancel"-button.
        pos - A PopupPosition for the dialog.
        Returns:
        True if the user clicked the "ok"-button.
      • getChoice

        public <T> T getChoice​(StringTemplate tmpl,
                               javax.swing.ImageIcon icon,
                               java.lang.String cancelKey,
                               java.util.List<ChoiceItem<T>> choices,
                               SwingGUI.PopupPosition pos)
        Show a modal dialog with text and a choice of options.
        Type Parameters:
        T - The type to be returned from the dialog.
        Parameters:
        tmpl - A SringTemplate that explains the choice for the user.
        icon - An optional icon to display.
        cancelKey - Key for the text of the optional cancel button.
        choices - The List containing the ChoiceItems to create buttons for.
        pos - A PopupPosition for the dialog.
        Returns:
        The corresponding member of the values array to the selected option, or null if no choices available.
      • getInput

        public java.lang.String getInput​(StringTemplate tmpl,
                                         java.lang.String defaultValue,
                                         java.lang.String okKey,
                                         java.lang.String cancelKey,
                                         SwingGUI.PopupPosition pos)
        Show a modal dialog with a text field and a ok/cancel option.
        Parameters:
        tmpl - A StringTemplate that explains the action to the user.
        defaultValue - The default value appearing in the text field.
        okKey - A key displayed on the "ok"-button.
        cancelKey - A key displayed on the optional "cancel"-button.
        pos - A PopupPosition for the dialog.
        Returns:
        The text the user entered, or null if cancelled.
      • showAboutPanel

        public FreeColPanel showAboutPanel()
        Show the AboutPanel.
        Returns:
        The panel shown.
      • showBuildQueuePanel

        public FreeColPanel showBuildQueuePanel​(Colony colony)
        Show the BuildQueuePanel for a given colony.
        Parameters:
        colony - The Colony to show the build queue of.
        Returns:
        The panel shown.
      • showCaptureGoodsDialog

        public void showCaptureGoodsDialog​(Unit unit,
                                           java.util.List<Goods> gl,
                                           DialogHandler<java.util.List<Goods>> handler)
        Show the CaptureGoodsDialog.
        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.
        Returns:
        The panel shown.
      • showChooseFoundingFatherDialog

        public void showChooseFoundingFatherDialog​(java.util.List<FoundingFather> ffs,
                                                   DialogHandler<FoundingFather> handler)
        Show the ChooseFoundingFatherDialog.
        Parameters:
        ffs - The FoundingFathers to choose from.
        handler - A DialogHandler for the dialog response.
      • showColopediaPanel

        public FreeColPanel showColopediaPanel​(java.lang.String nodeId)
        Show the colopedia entry for a given node.
        Parameters:
        nodeId - The node identifier to display.
        Returns:
        The panel shown.
      • showColorChooserPanel

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

        public FreeColPanel showCompactLabourReport()
        Show the compact labour report.
        Returns:
        The panel shown.
      • showCompactLabourReport

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

        public java.util.List<java.lang.String> showConfirmDeclarationDialog()
        Show a dialog to confirm a declaration of independence.
        Returns:
        A list of names for a new nation.
      • showDeclarationPanel

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

        public OptionGroup showDifficultyDialog​(Specification spec,
                                                OptionGroup group,
                                                boolean editable)
        Show the difficulty dialog for a given group.
        Parameters:
        spec - The enclosing Specification.
        group - The OptionGroup containing the difficulty.
        editable - If the options should be editable.
        Returns:
        The resulting OptionGroup.
      • showDumpCargoDialog

        public void showDumpCargoDialog​(Unit unit,
                                        SwingGUI.PopupPosition pos,
                                        DialogHandler<java.util.List<Goods>> handler)
        Show the DumpCargoDialog.
        Parameters:
        unit - The Unit that is dumping.
        pos - A PopupPosition for the dialog.
        handler - A DialogHandler for the dialog response.
      • showEditOptionDialog

        public boolean showEditOptionDialog​(Option op)
        Show the EditOptionDialog.
        Parameters:
        op - The Option to edit.
        Returns:
        The response returned by the dialog.
      • showEditSettlementDialog

        public IndianSettlement showEditSettlementDialog​(IndianSettlement is)
        Show the EditSettlementDialog.
        Parameters:
        is - The IndianSettlement to edit.
        Returns:
        The response returned by the dialog.
      • showEmigrationDialog

        public void showEmigrationDialog​(Player player,
                                         boolean fountainOfYouth,
                                         DialogHandler<java.lang.Integer> handler)
        Show the panel that allows the user to choose which unit will emigrate from Europe.
        Parameters:
        player - The Player whose unit is emigrating.
        fountainOfYouth - Is this dialog displayed as a result of a fountain of youth.
        handler - A DialogHandler for the dialog response.
      • showEndTurnDialog

        public void showEndTurnDialog​(java.util.List<Unit> units,
                                      DialogHandler<java.lang.Boolean> handler)
        Show the EndTurnDialog with given units that could still move.
        Parameters:
        units - A list of Units that could still move.
        handler - A DialogHandler for the dialog response.
      • showErrorPanel

        public FreeColPanel showErrorPanel​(java.lang.String message)
        Show an error message.
        Parameters:
        message - The message to display.
        Returns:
        The panel shown.
      • showEuropePanel

        public FreeColPanel showEuropePanel​(java.lang.Runnable callback)
        Show the EuropePanel.
        Parameters:
        callback - An optional closing callback to add.
        Returns:
        The panel shown.
      • showEventPanel

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

        public FreeColPanel showFindSettlementPanel()
        Show the FindSettlementPanel.
        Returns:
        The panel shown.
      • showFirstContactDialog

        public void showFirstContactDialog​(Player player,
                                           Player other,
                                           Tile tile,
                                           int settlementCount,
                                           SwingGUI.PopupPosition pos,
                                           DialogHandler<java.lang.Boolean> handler)
        Show the first contact dialog (which is really just a non-modal confirm dialog).
        Parameters:
        player - The Player making contact.
        other - The Player to contact.
        tile - An optional Tile on offer.
        settlementCount - The number of settlements the other player has (from the server, other.getNumberOfSettlements() is wrong here!).
        pos - A PopupPosition for the dialog.
        handler - A DialogHandler for the dialog response.
      • showGameOptionsDialog

        public OptionGroup showGameOptionsDialog​(boolean editable)
        Show the GameOptionsDialog.
        Parameters:
        editable - Should the game options be editable?
        Returns:
        The OptionGroup selected.
      • showHighScoresPanel

        public FreeColPanel showHighScoresPanel​(java.lang.String messageId,
                                                java.util.List<HighScore> scores)
        Show the high scores panel.
        Parameters:
        messageId - An optional message to add to the high scores panel.
        scores - The list of HighScores to display.
        Returns:
        The panel shown.
      • showIndianSettlementPanel

        public FreeColPanel showIndianSettlementPanel​(IndianSettlement is,
                                                      SwingGUI.PopupPosition pos)
        Show the panel of the given native settlement.
        Parameters:
        is - The IndianSettlement to display.
        pos - A PopupPosition for the panel.
        Returns:
        The panel shown.
      • showInformationPanel

        public FreeColPanel showInformationPanel​(FreeColObject displayObject,
                                                 SwingGUI.PopupPosition pos,
                                                 javax.swing.ImageIcon icon,
                                                 StringTemplate tmpl)
        Show a message with some information and an "OK"-button.
        Parameters:
        displayObject - Optional object for displaying.
        pos - A PopupPosition for the panel.
        icon - The icon to display for the object.
        tmpl - The StringTemplate to display.
        Returns:
        The panel shown.
      • showLoadDialog

        public java.io.File showLoadDialog​(java.io.File directory,
                                           javax.swing.filechooser.FileFilter[] filters)
        Show a dialog where the user may choose a file.
        Parameters:
        directory - The directory containing the files.
        filters - FileFilters for suitable files.
        Returns:
        The selected File.
      • showLoadingSavegameDialog

        public LoadingSavegameInfo showLoadingSavegameDialog​(boolean pubSer,
                                                             boolean single)
        Show a dialog for setting options when loading a savegame. The settings can be retrieved directly from LoadingSavegameDialog after calling this method.
        Parameters:
        pubSer - Default value.
        single - Default value.
        Returns:
        The LoadingSavegameInfo if the dialog was accepted, or null otherwise.
      • showLogFilePanel

        public FreeColPanel showLogFilePanel()
        Show a panel containing the log file.
        Returns:
        The panel shown.
      • showMapGeneratorOptionsDialog

        public OptionGroup showMapGeneratorOptionsDialog​(boolean editable)
        Show the map generator options dialog.
        Parameters:
        editable - Should these options be editable.
        Returns:
        The OptionGroup as edited.
      • showMapSizeDialog

        public java.awt.Dimension showMapSizeDialog()
        Show the map size dialog.
        Returns:
        The response returned by the dialog.
      • showMonarchDialog

        public void showMonarchDialog​(Monarch.MonarchAction action,
                                      StringTemplate tmpl,
                                      java.lang.String monarchKey,
                                      DialogHandler<java.lang.Boolean> handler)
        Show the monarch dialog.
        Parameters:
        action - The MonarchAction underway.
        tmpl - The StringTemplate describing the situation.
        monarchKey - The resource key for the monarch image.
        handler - A DialogHandler for the dialog response.
      • showNamingDialog

        public void showNamingDialog​(StringTemplate tmpl,
                                     java.lang.String defaultName,
                                     SwingGUI.PopupPosition pos,
                                     DialogHandler<java.lang.String> handler)
        Show a dialog to set a new name for something.
        Parameters:
        tmpl - A StringTemplate for the message to explain the dialog.
        defaultName - The default name.
        pos - A PopupPosition for the dialog.
        handler - A DialogHandler for the dialog response.
      • showNativeDemandDialog

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

        public DiplomaticTrade showNegotiationDialog​(FreeColGameObject our,
                                                     FreeColGameObject other,
                                                     DiplomaticTrade agreement,
                                                     StringTemplate comment,
                                                     SwingGUI.PopupPosition pos)
        Show the NegotiationDialog.
        Parameters:
        our - Our FreeColGameObject that is negotiating.
        other - The other FreeColGameObject.
        agreement - The current DiplomaticTrade agreement.
        comment - An optional StringTemplate containing a commentary message.
        pos - A PopupPosition for the dialog.
        Returns:
        An updated agreement.
      • showNewPanel

        public FreeColPanel showNewPanel​(Specification specification)
        Show the NewPanel for a given optional specification.
        Parameters:
        specification - The Specification to use.
        Returns:
        The panel shown.
      • showParametersDialog

        public Parameters showParametersDialog()
        Show the parameters dialog.
        Returns:
        The response returned by the dialog.
      • showPreCombatDialog

        public boolean showPreCombatDialog​(Unit attacker,
                                           FreeColGameObject defender,
                                           SwingGUI.PopupPosition pos)
        Show a dialog to confirm a combat.
        Parameters:
        attacker - The attacker Unit.
        defender - The defender.
        pos - A PopupPosition for the dialog.
        Returns:
        True if the combat is to proceed.
      • showPurchasePanel

        public FreeColPanel showPurchasePanel()
        Show the purchase panel.
        Returns:
        The panel shown.
      • showRecruitPanel

        public FreeColPanel showRecruitPanel()
        Show the recruit panel.
        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)
        Show the labour detail panel.
        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.
      • showRiverStyleDialog

        public java.lang.String showRiverStyleDialog​(java.util.List<java.lang.String> styles)
        Show the river style dialog.
        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,
                                           javax.swing.filechooser.FileFilter[] filters,
                                           java.lang.String defaultName)
        Show a dialog where the user may choose a filename.
        Parameters:
        directory - The directory containing the files in which the user may overwrite.
        filters - FileFilters for acceptable file names.
        defaultName - Default filename for the savegame.
        Returns:
        The selected File.
      • showScaleMapSizeDialog

        public java.awt.Dimension showScaleMapSizeDialog()
        Show the scale map size dialog.
        Returns:
        The response returned by the dialog.
      • showSelectAmountDialog

        public int showSelectAmountDialog​(GoodsType goodsType,
                                          int available,
                                          int defaultAmount,
                                          boolean needToPay)
        Show the select-amount dialog.
        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,
                                                    SwingGUI.PopupPosition pos)
        Show a dialog allowing the user to select a destination for a given unit.
        Parameters:
        unit - The Unit to select a destination for.
        pos - A PopupPosition for the dialog.
        Returns:
        A destination for the unit, or null.
      • showServerListPanel

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

        public int showSelectTributeAmountDialog​(StringTemplate question,
                                                 int maximum)
        Show the select-tribute-amount dialog.
        Parameters:
        question - a stringtemplate describing the amount of tribute to demand.
        maximum - The maximum amount available.
        Returns:
        The amount selected.
      • 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.
        Parameters:
        serverStats - A map of server statistics key,value pairs.
        clientStats - A map of client statistics key,value pairs.
        Returns:
        The panel shown.
      • showTilePanel

        public FreeColPanel showTilePanel​(Tile tile)
        Show the tile panel for a given tile.
        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.
        Parameters:
        newRoute - The TradeRoute to display.
        Returns:
        The panel shown.
      • showTradeRoutePanel

        public FreeColPanel showTradeRoutePanel​(Unit unit,
                                                SwingGUI.PopupPosition pos)
        Show a panel to select a trade route for a unit.
        Parameters:
        unit - An optional Unit to select a trade route for.
        pos - A PopupPosition for the panel.
        Returns:
        The panel shown.
      • showTrainPanel

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

        public void showVictoryDialog​(DialogHandler<java.lang.Boolean> handler)
        Show the victory dialog.
        Parameters:
        handler - A DialogHandler for the dialog response.
      • showWarehouseDialog

        public boolean showWarehouseDialog​(Colony colony)
        Show the warehouse dialog for a colony. Run out of ColonyPanel, so the tile is already displayed.
        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.
        Parameters:
        unit - The Unit to display.
        Returns:
        The panel shown.
      • showReportCargoPanel

        public FreeColPanel showReportCargoPanel()
      • showReportColonyPanel

        public FreeColPanel showReportColonyPanel​(boolean compact)
      • showReportContinentalCongressPanel

        public FreeColPanel showReportContinentalCongressPanel()
      • showReportEducationPanel

        public FreeColPanel showReportEducationPanel()
      • showReportExplorationPanel

        public FreeColPanel showReportExplorationPanel()
      • showReportForeignAffairPanel

        public FreeColPanel showReportForeignAffairPanel()
      • showReportHistoryPanel

        public FreeColPanel showReportHistoryPanel()
      • showReportIndianPanel

        public FreeColPanel showReportIndianPanel()
      • showReportLabourPanel

        public FreeColPanel showReportLabourPanel()
      • showReportMilitaryPanel

        public FreeColPanel showReportMilitaryPanel()
      • showReportNavalPanel

        public FreeColPanel showReportNavalPanel()
      • showReportProductionPanel

        public FreeColPanel showReportProductionPanel()
      • showReportReligiousPanel

        public FreeColPanel showReportReligiousPanel()
      • showReportRequirementsPanel

        public FreeColPanel showReportRequirementsPanel()
      • showReportTradePanel

        public FreeColPanel showReportTradePanel()
      • showReportTurnPanel

        public FreeColPanel showReportTurnPanel​(java.util.List<ModelMessage> messages)
        Show the turn report.
        Parameters:
        messages - The ModelMessages to show.
        Returns:
        The FreeColPanel displayed.