From 036dd1edfa81b825865a7cbf3d8397cea1713e8c Mon Sep 17 00:00:00 2001 From: Stian Grenborgen Date: Sat, 6 Jan 2024 19:03:16 +0100 Subject: [PATCH] Various fixes to the map editor and action logic. * Store panel positions and sizes (if enabled) in more cases (for example, before closing all panels when starting a new game or creating a new map). * Don't store sizes and positions for fullscreen panels. * Adds title to map editor frames. * Plays the default music playlist in the editor. * Add an action/menu item for disabling/enabling the tile transform panel in the meap editor. --- data/strings/FreeColMessages.properties | 3 +- .../client/control/MapEditorController.java | 10 ++ src/net/sf/freecol/client/gui/Canvas.java | 23 +++++ src/net/sf/freecol/client/gui/GUI.java | 12 +++ src/net/sf/freecol/client/gui/SwingGUI.java | 31 ++++++- .../client/gui/action/ActionManager.java | 1 + .../gui/action/ChangeWindowedModeAction.java | 2 +- .../gui/action/DisplayBordersAction.java | 2 +- .../gui/action/DisplayFogOfWarAction.java | 2 +- .../client/gui/action/DisplayGridAction.java | 2 +- .../gui/action/DisplayTileTextAction.java | 2 +- .../client/gui/action/MapControlsAction.java | 21 +++-- .../action/MapEditorTransformPanelAction.java | 68 ++++++++++++++ .../client/gui/action/NewEmptyMapAction.java | 4 + .../client/gui/action/SelectableAction.java | 49 ++-------- .../gui/action/SelectableOptionAction.java | 92 +++++++++++++++++++ .../client/gui/menu/FreeColMenuBar.java | 14 ++- .../client/gui/menu/MapEditorMenuBar.java | 2 + .../client/gui/panel/CornerMapControls.java | 19 +++- 19 files changed, 291 insertions(+), 68 deletions(-) create mode 100644 src/net/sf/freecol/client/gui/action/MapEditorTransformPanelAction.java create mode 100644 src/net/sf/freecol/client/gui/action/SelectableOptionAction.java diff --git a/data/strings/FreeColMessages.properties b/data/strings/FreeColMessages.properties index f55cf46dd..2fa7980e7 100644 --- a/data/strings/FreeColMessages.properties +++ b/data/strings/FreeColMessages.properties @@ -392,6 +392,7 @@ loadAction.accelerator=L loadAction.name=Load mapControlsAction.accelerator=control M mapControlsAction.name=Map Controls +mapEditorTransformPanelAction.name=Tile Transform mapEditorAction.name=Map Editor mapGeneratorOptionsAction.accelerator=shift F12 mapGeneratorOptionsAction.name=Show Map Generator Options @@ -3612,7 +3613,7 @@ loadingSavegameDialog.name=Loading Save game mapEditor.loadedWithMods=You have started the map editor with active mods that contain specification changes. Please note that the same mods need to be manually activated by every user that loads maps that are using anything new from a mod.\n\nYou can go back to the main menu and deactivate any mods through the Preferences if this was not intentional. # MapEditorTransformPanel -mapEditorTransformPanel.title=Paint +mapEditorTransformPanel.title=Tile Transform mapEditorTransformPanel.chooseResource=Choose resource mapEditorTransformPanel.majorRiver=Major river mapEditorTransformPanel.minorRiver=Minor river diff --git a/src/net/sf/freecol/client/control/MapEditorController.java b/src/net/sf/freecol/client/control/MapEditorController.java index c0386ae4d..8d4d9631f 100644 --- a/src/net/sf/freecol/client/control/MapEditorController.java +++ b/src/net/sf/freecol/client/control/MapEditorController.java @@ -32,6 +32,7 @@ import javax.swing.SwingUtilities; import javax.xml.stream.XMLStreamException; import net.sf.freecol.FreeCol; +import net.sf.freecol.client.ClientOptions; import net.sf.freecol.client.FreeColClient; import net.sf.freecol.client.gui.GUI; import net.sf.freecol.client.gui.panel.MiniMap; // FIXME: should go away @@ -48,6 +49,8 @@ import net.sf.freecol.common.model.Specification; import net.sf.freecol.common.model.StringTemplate; import net.sf.freecol.common.model.Tile; import net.sf.freecol.common.option.MapGeneratorOptions; +import net.sf.freecol.common.resources.AudioResource; +import net.sf.freecol.common.resources.ResourceManager; import net.sf.freecol.server.FreeColServer; import net.sf.freecol.server.generator.MapGenerator; import net.sf.freecol.server.model.ServerGame; @@ -164,6 +167,11 @@ public final class MapEditorController extends FreeColClientHolder { //fcc.changeClientState(true); //gui.changeView((Tile)null); gui.startMapEditorGUI(); + final AudioResource defaultPlaylist = ResourceManager.getAudioResource("sound.music.playlist.default", true); + if (defaultPlaylist != null) { + getFreeColClient().getSoundController().setDefaultPlaylist(defaultPlaylist.getAllAudio()); + } + getFreeColClient().getSoundController().playMusic(null); if (specificationChanges) { gui.showInformationPanel("mapEditor.loadedWithMods"); @@ -327,6 +335,8 @@ public final class MapEditorController extends FreeColClientHolder { SwingUtilities.invokeLater(() -> { gui.closeStatusPanel(); gui.setFocus(game.getMap().getTile(1,1)); + gui.enableEditorTransformPanel(true); + gui.enableMapControls(getClientOptions().getBoolean(ClientOptions.DISPLAY_MAP_CONTROLS)); gui.updateMenuBar(); gui.refresh(); }); diff --git a/src/net/sf/freecol/client/gui/Canvas.java b/src/net/sf/freecol/client/gui/Canvas.java index c0ddfcdab..b352ca6ec 100644 --- a/src/net/sf/freecol/client/gui/Canvas.java +++ b/src/net/sf/freecol/client/gui/Canvas.java @@ -1167,6 +1167,13 @@ public final class Canvas extends JDesktopPane { * requested type, or null if none found. */ public T getExistingFreeColPanel(Class type) { + for (JInternalFrame f : getAllFrames()) { + for (Component c2 : f.getContentPane().getComponents()) { + if (type.isAssignableFrom(c2.getClass())) { + return type.cast(c2); + } + } + } for (Component c1 : getComponents()) { if (c1 instanceof JInternalFrame) { for (Component c2 : ((JInternalFrame)c1).getContentPane() @@ -1188,6 +1195,22 @@ public final class Canvas extends JDesktopPane { return null; } + public boolean isAddedAsPanelFrameOrIcon(Class clazz) { + for (JInternalFrame f : getAllFrames()) { + for (Component c2 : f.getContentPane().getComponents()) { + if (clazz.isAssignableFrom(c2.getClass())) { + return true; + } + } + } + for (Component c1 : getComponents()) { + if (clazz.isAssignableFrom(c1.getClass())) { + return true; + } + } + return false; + } + public boolean isAddedAsPanelFrameOrIcon(Component component) { for (JInternalFrame f : getAllFrames()) { for (Component c2 : f.getContentPane().getComponents()) { diff --git a/src/net/sf/freecol/client/gui/GUI.java b/src/net/sf/freecol/client/gui/GUI.java index e019bbf17..17c859197 100644 --- a/src/net/sf/freecol/client/gui/GUI.java +++ b/src/net/sf/freecol/client/gui/GUI.java @@ -1158,6 +1158,18 @@ public class GUI extends FreeColClientHolder { */ public void startMapEditorGUI() {} + /** + * Shows the map editor transform panel. + */ + public void enableEditorTransformPanel(boolean shouldDisplayPanel) {} + + /** + * Checks if the map editor transform panel is being displayed. + */ + public boolean isShowingMapEditorTransformPanel() { + return false; + } + // Animation handling diff --git a/src/net/sf/freecol/client/gui/SwingGUI.java b/src/net/sf/freecol/client/gui/SwingGUI.java index 8402d2105..988304199 100644 --- a/src/net/sf/freecol/client/gui/SwingGUI.java +++ b/src/net/sf/freecol/client/gui/SwingGUI.java @@ -60,6 +60,7 @@ import net.sf.freecol.client.ClientOptions; import net.sf.freecol.client.FreeColClient; import net.sf.freecol.client.control.MapTransform; import net.sf.freecol.client.control.SoundController; +import net.sf.freecol.client.gui.action.MapEditorTransformPanelAction; import net.sf.freecol.client.gui.animation.Animation; import net.sf.freecol.client.gui.animation.Animations; // Special dialogs and panels @@ -71,12 +72,14 @@ import net.sf.freecol.client.gui.mapviewer.MapAsyncPainter; import net.sf.freecol.client.gui.mapviewer.MapViewer; import net.sf.freecol.client.gui.mapviewer.MapViewerState; import net.sf.freecol.client.gui.mapviewer.TileViewer; +import net.sf.freecol.client.gui.panel.BuildQueuePanel; import net.sf.freecol.client.gui.panel.ColonyPanel; import net.sf.freecol.client.gui.panel.CornerMapControls; import net.sf.freecol.client.gui.panel.FreeColImageBorder; import net.sf.freecol.client.gui.panel.FreeColPanel; import net.sf.freecol.client.gui.panel.InformationPanel; import net.sf.freecol.client.gui.panel.MapControls; +import net.sf.freecol.client.gui.panel.MapEditorTransformPanel; import net.sf.freecol.client.gui.panel.PurchasePanel; import net.sf.freecol.client.gui.panel.RecruitPanel; import net.sf.freecol.client.gui.panel.StartGamePanel; @@ -123,6 +126,7 @@ import net.sf.freecol.common.option.LanguageOption; import net.sf.freecol.common.option.LanguageOption.Language; import net.sf.freecol.common.option.Option; import net.sf.freecol.common.option.OptionGroup; +import net.sf.freecol.common.resources.AudioResource; import net.sf.freecol.common.resources.ImageCache; import net.sf.freecol.common.resources.ImageResource; import net.sf.freecol.common.resources.ResourceManager; @@ -831,7 +835,7 @@ public class SwingGUI extends GUI { this.mapViewer.getMapViewerBounds().setFocus(tile); enableMapControls(false); - enableMapControls(getClientOptions().getBoolean(ClientOptions.DISPLAY_MAP_CONTROLS)); + enableMapControls(getGame() != null && getGame().getMap() != null && getClientOptions().getBoolean(ClientOptions.DISPLAY_MAP_CONTROLS)); refresh(); } @@ -916,7 +920,30 @@ public class SwingGUI extends GUI { resetMapZoom(); // Reset zoom to the default mapViewer.getMapViewerState().setActiveUnit(null); this.canvas.startMapEditorGUI(); - this.canvas.showMapEditorTransformPanel(); + enableEditorTransformPanel(getGame() != null && getGame().getMap() != null); + enableMapControls(getGame() != null && getGame().getMap() != null && getClientOptions().getBoolean(ClientOptions.DISPLAY_MAP_CONTROLS)); + updateMenuBar(); + } + + /** + * {@inheritDoc} + */ + @Override + public void enableEditorTransformPanel(boolean shouldDisplayPanel) { + final MapEditorTransformPanel panel = this.canvas.getExistingFreeColPanel(MapEditorTransformPanel.class); + if (shouldDisplayPanel && panel == null) { + this.canvas.showMapEditorTransformPanel(); + } else if (!shouldDisplayPanel && panel != null) { + this.canvas.removeFromCanvas(panel); + } // else: ignore. + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isShowingMapEditorTransformPanel() { + return this.canvas.isAddedAsPanelFrameOrIcon(MapEditorTransformPanel.class); } diff --git a/src/net/sf/freecol/client/gui/action/ActionManager.java b/src/net/sf/freecol/client/gui/action/ActionManager.java index a266ed53a..c64d78508 100644 --- a/src/net/sf/freecol/client/gui/action/ActionManager.java +++ b/src/net/sf/freecol/client/gui/action/ActionManager.java @@ -119,6 +119,7 @@ public class ActionManager extends OptionGroup { add(new LoadAction(freeColClient)); add(new MapControlsAction(freeColClient)); add(new MapEditorAction(freeColClient)); + add(new MapEditorTransformPanelAction(freeColClient)); add(new MiniMapToggleViewAction(freeColClient)); add(new MiniMapToggleViewAction(freeColClient, true)); add(new MiniMapToggleFogOfWarAction(freeColClient)); diff --git a/src/net/sf/freecol/client/gui/action/ChangeWindowedModeAction.java b/src/net/sf/freecol/client/gui/action/ChangeWindowedModeAction.java index fe9243ca5..b15e80c9d 100644 --- a/src/net/sf/freecol/client/gui/action/ChangeWindowedModeAction.java +++ b/src/net/sf/freecol/client/gui/action/ChangeWindowedModeAction.java @@ -28,7 +28,7 @@ import net.sf.freecol.client.gui.GUI; /** * An action for toggling between full-screen and windowed mode. */ -public final class ChangeWindowedModeAction extends SelectableAction { +public final class ChangeWindowedModeAction extends SelectableOptionAction { public static final String id = "changeWindowedModeAction"; diff --git a/src/net/sf/freecol/client/gui/action/DisplayBordersAction.java b/src/net/sf/freecol/client/gui/action/DisplayBordersAction.java index 0ce27cc42..03fe9906a 100644 --- a/src/net/sf/freecol/client/gui/action/DisplayBordersAction.java +++ b/src/net/sf/freecol/client/gui/action/DisplayBordersAction.java @@ -30,7 +30,7 @@ import net.sf.freecol.client.FreeColClient; /** * An action to toggle the display of national borders. */ -public class DisplayBordersAction extends SelectableAction { +public class DisplayBordersAction extends SelectableOptionAction { public static final String id = "displayBordersAction"; diff --git a/src/net/sf/freecol/client/gui/action/DisplayFogOfWarAction.java b/src/net/sf/freecol/client/gui/action/DisplayFogOfWarAction.java index 9bf63e3e6..6492ffefc 100644 --- a/src/net/sf/freecol/client/gui/action/DisplayFogOfWarAction.java +++ b/src/net/sf/freecol/client/gui/action/DisplayFogOfWarAction.java @@ -31,7 +31,7 @@ import net.sf.freecol.common.option.GameOptions; /** * An action to toggle the display of national borders. */ -public class DisplayFogOfWarAction extends SelectableAction { +public class DisplayFogOfWarAction extends SelectableOptionAction { public static final String id = "displayFogOfWarAction"; diff --git a/src/net/sf/freecol/client/gui/action/DisplayGridAction.java b/src/net/sf/freecol/client/gui/action/DisplayGridAction.java index 7547b4ff2..2e978675b 100644 --- a/src/net/sf/freecol/client/gui/action/DisplayGridAction.java +++ b/src/net/sf/freecol/client/gui/action/DisplayGridAction.java @@ -30,7 +30,7 @@ import net.sf.freecol.client.FreeColClient; /** * An action to toggle the display of the map grid. */ -public class DisplayGridAction extends SelectableAction { +public class DisplayGridAction extends SelectableOptionAction { public static final String id = "displayGridAction"; diff --git a/src/net/sf/freecol/client/gui/action/DisplayTileTextAction.java b/src/net/sf/freecol/client/gui/action/DisplayTileTextAction.java index 10e94454c..725e636fa 100644 --- a/src/net/sf/freecol/client/gui/action/DisplayTileTextAction.java +++ b/src/net/sf/freecol/client/gui/action/DisplayTileTextAction.java @@ -34,7 +34,7 @@ import static net.sf.freecol.common.util.StringUtils.*; /** * Display text over tiles. */ -public final class DisplayTileTextAction extends SelectableAction { +public final class DisplayTileTextAction extends SelectableOptionAction { public static final String id = "displayTileTextAction."; diff --git a/src/net/sf/freecol/client/gui/action/MapControlsAction.java b/src/net/sf/freecol/client/gui/action/MapControlsAction.java index 69da7d557..fef5d291c 100644 --- a/src/net/sf/freecol/client/gui/action/MapControlsAction.java +++ b/src/net/sf/freecol/client/gui/action/MapControlsAction.java @@ -21,8 +21,6 @@ package net.sf.freecol.client.gui.action; import java.awt.event.ActionEvent; -import javax.swing.AbstractButton; - import net.sf.freecol.client.ClientOptions; import net.sf.freecol.client.FreeColClient; @@ -30,7 +28,7 @@ import net.sf.freecol.client.FreeColClient; /** * An action for displaying the map controls. */ -public class MapControlsAction extends SelectableAction { +public class MapControlsAction extends SelectableOptionAction { public static final String id = "mapControlsAction"; @@ -55,10 +53,20 @@ public class MapControlsAction extends SelectableAction { @Override public void update() { super.update(); - - getGUI().enableMapControls(isEnabled() && isSelected()); } + /** + * {@inheritDoc} + */ + @Override + protected boolean shouldBeEnabled() { + return super.shouldBeEnabled() && getGame() != null && getGame().getMap() != null; + } + + @Override + protected boolean shouldBeSelected() { + return getOption(); + } // Interface ActionListener @@ -67,8 +75,7 @@ public class MapControlsAction extends SelectableAction { */ @Override public void actionPerformed(ActionEvent ae) { - setSelected(((AbstractButton)ae.getSource()).isSelected()); + getGUI().enableMapControls(isEnabled() && isSelected()); setOption(isSelected()); - update(); } } diff --git a/src/net/sf/freecol/client/gui/action/MapEditorTransformPanelAction.java b/src/net/sf/freecol/client/gui/action/MapEditorTransformPanelAction.java new file mode 100644 index 000000000..90e833d88 --- /dev/null +++ b/src/net/sf/freecol/client/gui/action/MapEditorTransformPanelAction.java @@ -0,0 +1,68 @@ +/** + * Copyright (C) 2002-2022 The FreeCol Team + * + * This file is part of FreeCol. + * + * FreeCol is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * FreeCol is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FreeCol. If not, see . + */ + +package net.sf.freecol.client.gui.action; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractButton; + +import net.sf.freecol.client.ClientOptions; +import net.sf.freecol.client.FreeColClient; + + +/** + * An action for displaying the map controls. + */ +public class MapEditorTransformPanelAction extends SelectableAction { + + public static final String id = "mapEditorTransformPanelAction"; + + + /** + * Creates this action. + * + * @param freeColClient The {@code FreeColClient} for the game. + */ + public MapEditorTransformPanelAction(FreeColClient freeColClient) { + super(freeColClient, id); + setSelected(isSelected()); + } + + + @Override + protected boolean shouldBeEnabled() { + return freeColClient.isMapEditor() && getGame() != null && getGame().getMap() != null; + } + + @Override + protected boolean shouldBeSelected() { + return getGUI().isShowingMapEditorTransformPanel(); + } + + // Interface ActionListener + + /** + * {@inheritDoc} + */ + @Override + public void actionPerformed(ActionEvent ae) { + getGUI().enableEditorTransformPanel(isEnabled() && isSelected()); + } +} diff --git a/src/net/sf/freecol/client/gui/action/NewEmptyMapAction.java b/src/net/sf/freecol/client/gui/action/NewEmptyMapAction.java index 6dd7af5d0..53faf036f 100644 --- a/src/net/sf/freecol/client/gui/action/NewEmptyMapAction.java +++ b/src/net/sf/freecol/client/gui/action/NewEmptyMapAction.java @@ -22,7 +22,9 @@ package net.sf.freecol.client.gui.action; import java.awt.Dimension; import java.awt.event.ActionEvent; +import net.sf.freecol.client.ClientOptions; import net.sf.freecol.client.FreeColClient; +import net.sf.freecol.client.gui.GUI; import net.sf.freecol.common.model.Map; import net.sf.freecol.common.model.Tile; @@ -68,6 +70,8 @@ public class NewEmptyMapAction extends MapboardAction { Map map = getFreeColClient().getFreeColServer() .generateEmptyMap(size.width, size.height); Tile tile = map.getTile(size.width/2, size.height/2); + getGUI().enableEditorTransformPanel(true); + getGUI().enableMapControls(getClientOptions().getBoolean(ClientOptions.DISPLAY_MAP_CONTROLS)); getGUI().setFocus(tile); getGUI().updateMenuBar(); getGUI().refresh(); diff --git a/src/net/sf/freecol/client/gui/action/SelectableAction.java b/src/net/sf/freecol/client/gui/action/SelectableAction.java index 7991be846..797900a85 100644 --- a/src/net/sf/freecol/client/gui/action/SelectableAction.java +++ b/src/net/sf/freecol/client/gui/action/SelectableAction.java @@ -19,64 +19,27 @@ package net.sf.freecol.client.gui.action; -import java.util.logging.Level; +import javax.swing.Action; import net.sf.freecol.client.FreeColClient; -import net.sf.freecol.client.ClientOptions; /** - * An action for selecting one of several options. + * An action for a boolean value. */ public abstract class SelectableAction extends MapboardAction { public static final String id = "selectableAction"; - private final String optionId; - - protected boolean selected = false; - /** * Creates this action. * * @param freeColClient The {@code FreeColClient} for the game. * @param id The object identifier. - * @param optionId The identifier of a boolean client option. */ - protected SelectableAction(FreeColClient freeColClient, - String id, String optionId) { + protected SelectableAction(FreeColClient freeColClient, String id) { super(freeColClient, id); - - this.optionId = optionId; - } - - - /** - * Get the value of the underlying option. - * - * @return The option value. - */ - public final boolean getOption() { - ClientOptions co = freeColClient.getClientOptions(); - if (co != null && optionId != null) { - try { - return co.getBoolean(optionId); - } catch (Exception e) { - logger.log(Level.WARNING, "Failure with option: " + optionId, e); - } - } - return false; - } - - /** - * Set the option value. - * - * @param value The new boolean value. - */ - public final void setOption(boolean value) { - ClientOptions co = freeColClient.getClientOptions(); - if (co != null && optionId != null) co.setBoolean(optionId, value); } /** @@ -85,7 +48,7 @@ public abstract class SelectableAction extends MapboardAction { * @return True if this action is selected. */ public final boolean isSelected() { - return selected; + return Boolean.TRUE.equals(getValue(Action.SELECTED_KEY)); } /** @@ -94,7 +57,7 @@ public abstract class SelectableAction extends MapboardAction { * @param b The new selection value. */ public final void setSelected(boolean b) { - this.selected = b; + putValue(Action.SELECTED_KEY, b); } /** @@ -105,7 +68,7 @@ public abstract class SelectableAction extends MapboardAction { * @return True of this action should be selected. */ protected boolean shouldBeSelected() { - return getOption(); + return isSelected(); } diff --git a/src/net/sf/freecol/client/gui/action/SelectableOptionAction.java b/src/net/sf/freecol/client/gui/action/SelectableOptionAction.java new file mode 100644 index 000000000..dd814b992 --- /dev/null +++ b/src/net/sf/freecol/client/gui/action/SelectableOptionAction.java @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2002-2022 The FreeCol Team + * + * This file is part of FreeCol. + * + * FreeCol is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * FreeCol is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FreeCol. If not, see . + */ + +package net.sf.freecol.client.gui.action; + +import java.util.logging.Level; + +import net.sf.freecol.client.FreeColClient; +import net.sf.freecol.client.ClientOptions; + + +/** + * An action for selecting one of several options. + */ +public abstract class SelectableOptionAction extends SelectableAction { + + public static final String id = "selectableOptionAction"; + + private final String optionId; + + protected boolean selected = false; + + + /** + * Creates this action. + * + * @param freeColClient The {@code FreeColClient} for the game. + * @param id The object identifier. + * @param optionId The identifier of a boolean client option. + */ + protected SelectableOptionAction(FreeColClient freeColClient, + String id, String optionId) { + super(freeColClient, id); + + this.optionId = optionId; + } + + + /** + * Get the value of the underlying option. + * + * @return The option value. + */ + public final boolean getOption() { + ClientOptions co = freeColClient.getClientOptions(); + if (co != null && optionId != null) { + try { + return co.getBoolean(optionId); + } catch (Exception e) { + logger.log(Level.WARNING, "Failure with option: " + optionId, e); + } + } + return false; + } + + /** + * Set the option value. + * + * @param value The new boolean value. + */ + public final void setOption(boolean value) { + ClientOptions co = freeColClient.getClientOptions(); + if (co != null && optionId != null) co.setBoolean(optionId, value); + } + + /** + * Should this action be selected? + * + * Override this in subclasses. + * + * @return True of this action should be selected. + */ + protected boolean shouldBeSelected() { + return getOption(); + } +} diff --git a/src/net/sf/freecol/client/gui/menu/FreeColMenuBar.java b/src/net/sf/freecol/client/gui/menu/FreeColMenuBar.java index a58a95af0..ed62416df 100644 --- a/src/net/sf/freecol/client/gui/menu/FreeColMenuBar.java +++ b/src/net/sf/freecol/client/gui/menu/FreeColMenuBar.java @@ -19,7 +19,6 @@ package net.sf.freecol.client.gui.menu; -import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; @@ -41,6 +40,7 @@ import net.sf.freecol.client.gui.action.ColopediaAction; import net.sf.freecol.client.gui.action.ColopediaAction.PanelType; import net.sf.freecol.client.gui.action.FreeColAction; import net.sf.freecol.client.gui.action.SelectableAction; +import net.sf.freecol.client.gui.action.SelectableOptionAction; import net.sf.freecol.client.gui.panel.FreeColImageBorder; import net.sf.freecol.client.gui.panel.Utility; import net.sf.freecol.common.util.ImageUtils; @@ -166,7 +166,6 @@ public abstract class FreeColMenuBar extends JMenuBar { * @return The menu item. */ protected JCheckBoxMenuItem getCheckBoxMenuItem(String actionId) { - JCheckBoxMenuItem rtn = null; FreeColAction action = am.getFreeColAction(actionId); @@ -175,11 +174,10 @@ public abstract class FreeColMenuBar extends JMenuBar { rtn.setAction(action); rtn.setOpaque(false); - rtn.setSelected(((SelectableAction)am.getFreeColAction(actionId)) - .isSelected()); - } else - logger.finest("Could not create menu item. [" + actionId - + "] not found."); + //rtn.setSelected(((SelectableAction) am.getFreeColAction(actionId)).isSelected()); + } else { + logger.finest("Could not create menu item. [" + actionId + "] not found."); + } return rtn; } @@ -202,7 +200,7 @@ public abstract class FreeColMenuBar extends JMenuBar { rtn.setAction(action); rtn.setOpaque(false); - rtn.setSelected(((SelectableAction) am.getFreeColAction(actionId)).isSelected()); + rtn.setSelected(((SelectableOptionAction) am.getFreeColAction(actionId)).isSelected()); group.add(rtn); } else { logger.finest("Could not create menu item. [" + actionId diff --git a/src/net/sf/freecol/client/gui/menu/MapEditorMenuBar.java b/src/net/sf/freecol/client/gui/menu/MapEditorMenuBar.java index 10c2100a2..8d9193c98 100644 --- a/src/net/sf/freecol/client/gui/menu/MapEditorMenuBar.java +++ b/src/net/sf/freecol/client/gui/menu/MapEditorMenuBar.java @@ -33,6 +33,7 @@ import net.sf.freecol.client.gui.action.DisplayGridAction; import net.sf.freecol.client.gui.action.DisplayTileTextAction; import net.sf.freecol.client.gui.action.DisplayTileTextAction.DisplayText; import net.sf.freecol.client.gui.action.MapControlsAction; +import net.sf.freecol.client.gui.action.MapEditorTransformPanelAction; import net.sf.freecol.client.gui.action.NewAction; import net.sf.freecol.client.gui.action.NewEmptyMapAction; import net.sf.freecol.client.gui.action.OpenAction; @@ -130,6 +131,7 @@ public class MapEditorMenuBar extends FreeColMenuBar { menu.setMnemonic(KeyEvent.VK_V); menu.add(getCheckBoxMenuItem(MapControlsAction.id)); + menu.add(getCheckBoxMenuItem(MapEditorTransformPanelAction.id)); menu.add(getCheckBoxMenuItem(DisplayGridAction.id)); menu.add(getCheckBoxMenuItem(ChangeWindowedModeAction.id)); diff --git a/src/net/sf/freecol/client/gui/panel/CornerMapControls.java b/src/net/sf/freecol/client/gui/panel/CornerMapControls.java index 9f6b5e46c..e3ced9dfb 100644 --- a/src/net/sf/freecol/client/gui/panel/CornerMapControls.java +++ b/src/net/sf/freecol/client/gui/panel/CornerMapControls.java @@ -32,8 +32,10 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import javax.swing.JComponent; +import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import net.miginfocom.swing.MigLayout; import net.sf.freecol.client.ClientOptions; @@ -301,8 +303,13 @@ public final class CornerMapControls extends MapControls { @Override public List getComponentsPresent() { List ret = new ArrayList<>(); - ret.add(this.infoPanel); - ret.add(this.miniMapPanel); + + if (isShowingOrIconified(this.infoPanel)) { + ret.add(this.infoPanel); + } + if (isShowingOrIconified(this.miniMapPanel)) { + ret.add(this.miniMapPanel); + } final boolean rose = getClientOptions() .getBoolean(ClientOptions.DISPLAY_COMPASS_ROSE); if (rose && this.compassRose.isShowing()) ret.add(this.compassRose); @@ -311,4 +318,12 @@ public final class CornerMapControls extends MapControls { } return ret; } + + private boolean isShowingOrIconified(JComponent panel) { + final JInternalFrame f = (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class, panel); + if (f != null && f.isIcon()) { + return true; + } + return panel.isShowing(); + } }