I am running a lot of automated tests to check that my AI `improvements' actually improve. Speeding this up is worthwhile, so I made a brutal patch to make headless mode work again, which yielded a 20% speed up[1].
The patch (attached) just informs the GUI object when headless mode is required, and prefixes every GUI use of canvas et al with "if (headless) return" or thereabouts. Before committing though, I have to wonder if there is a better way of doing this. Any thoughts folks, particularly Paolo:-). Cheers, Mike Pope [1] Further suggesting that we are spending a lot of time in I/O and XML converters.
signature.asc
Description: This is a digitally signed message part.
diff --git a/src/net/sf/freecol/client/FreeColClient.java b/src/net/sf/freecol/client/FreeColClient.java
index b9275de..7281096 100644
--- a/src/net/sf/freecol/client/FreeColClient.java
+++ b/src/net/sf/freecol/client/FreeColClient.java
@@ -43,6 +43,7 @@ import net.sf.freecol.client.gui.plaf.FreeColLookAndFeel;
import net.sf.freecol.client.networking.UserServerAPI;
import net.sf.freecol.common.FreeColException;
import net.sf.freecol.common.FreeColSeed;
+import net.sf.freecol.common.debug.FreeColDebugger;
import net.sf.freecol.common.io.FreeColDataFile;
import net.sf.freecol.common.io.FreeColDirectories;
import net.sf.freecol.common.io.FreeColModFile;
@@ -150,21 +151,6 @@ public final class FreeColClient {
final String splashFilename,
final boolean showOpeningVideo,
final String fontName) {
- gui = new GUI(this);
- serverAPI = new UserServerAPI(gui);
-
- // Look for base data directory. Failure is fatal.
- File baseDirectory = FreeColDirectories.getBaseDirectory();
- if (!baseDirectory.exists() || !baseDirectory.isDirectory()) {
- System.err.println("Could not find base data directory: "
- + baseDirectory.getName());
- System.err.println(" The data files could not be found by FreeCol. Please make sure");
- System.err.println(" they are present. If FreeCol is looking in the wrong directory");
- System.err.println(" then run the game with a command-line parameter:\n");
- System.err.println(" --freecol-data <data-directory>\n");
- System.exit(1);
- }
-
// headless mode is enable for the test suite, where it now
// works again.
// TODO: It would be nice to have it useful for running full
@@ -172,15 +158,44 @@ public final class FreeColClient {
// probably still borked. Fix.
headless = "true".equals(System.getProperty("java.awt.headless",
"false"));
+ if (headless) {
+ if (savedGame == null) {
+ System.err.println("Headless mode requires a saved game.");
+ System.exit(1);
+ }
+ if (!FreeColDebugger.isInDebugMode()
+ || FreeColDebugger.getDebugRunTurns() <= 0) {
+ System.err.println("Headless mode is requires a debug run.");
+ System.exit(1);
+ }
+ }
+ gui = new GUI(this, headless);
+ serverAPI = new UserServerAPI(gui);
mapEditor = false;
+ // Look for base data directory. Failure is fatal.
+ File baseDirectory = FreeColDirectories.getBaseDirectory();
+ if (!baseDirectory.exists() || !baseDirectory.isDirectory()) {
+ System.err.println("Could not find base data directory: "
+ + baseDirectory.getName()
+ + "\n The data files could not be found by FreeCol."
+ + "\n Please make sure they are present."
+ + "\n If FreeCol is looking in the wrong directory"
+ + "\n then run the game with a command-line parameter:"
+ + "\n --freecol-data <data-directory>\n");
+ System.exit(1);
+ }
+
+
gui.displaySpashScreen(splashFilename);
// Determine the window size.
gui.setWindowed(size != null);
- final Dimension windowSize = (size == null) ? null
- : (size.width <= 0 || size.height <= 0) ? gui.determineWindowSize()
+ final Dimension windowSize = (size == null)
+ ? null
+ : (size.width <= 0 || size.height <= 0)
+ ? gui.determineWindowSize()
: size;
logger.info("Window size is " + windowSize);
@@ -228,28 +243,30 @@ public final class FreeColClient {
}
if (font == null) font = ResourceManager.getFont("NormalFont");
- // Swing system and look-and-feel initialization.
- try {
- FreeColLookAndFeel fclaf
- = new FreeColLookAndFeel(FreeColDirectories.getDataDirectory());
- FreeColLookAndFeel.install(fclaf, font);
- } catch (FreeColException e) {
- logger.log(Level.SEVERE, "Unable to install FreeCol look-and-feel.",
- e);
- System.err.println("Unable to install FreeCol look-and-feel.");
- System.exit(1);
- }
+ if (!headless) {
+ // Swing system and look-and-feel initialization.
+ try {
+ FreeColLookAndFeel fclaf
+ = new FreeColLookAndFeel(FreeColDirectories.getDataDirectory());
+ FreeColLookAndFeel.install(fclaf, font);
+ } catch (FreeColException e) {
+ logger.log(Level.SEVERE, "Unable to install FreeCol look-and-feel.",
+ e);
+ System.err.println("Unable to install FreeCol look-and-feel.");
+ System.exit(1);
+ }
- // Once resources are in place, get preloading started.
- if (!headless)
+ // Once resources are in place, get preloading started.
ResourceManager.preload(windowSize);
- // Start the GUI.
- gui.hideSplashScreen();
+ // Start the GUI.
+ gui.hideSplashScreen();
+ }
+
SwingUtilities.invokeLater(new Runnable() {
public void run() {
gui.startGUI(windowSize, sound, showOpeningVideo,
- savedGame != null);
+ savedGame != null);
}
});
diff --git a/src/net/sf/freecol/client/gui/GUI.java b/src/net/sf/freecol/client/gui/GUI.java
index 216127e..c913c4a 100644
--- a/src/net/sf/freecol/client/gui/GUI.java
+++ b/src/net/sf/freecol/client/gui/GUI.java
@@ -123,7 +123,7 @@ public class GUI {
*/
private static final int DEFAULT_WINDOW_SPACE = 50;
-
+
public static final int MOVE_UNITS_MODE = 0;
@@ -140,7 +140,7 @@ public class GUI {
private Canvas canvas;
private MapViewer mapViewer;
-
+
private MapControls mapControls;
/**
@@ -160,12 +160,23 @@ public class GUI {
private JWindow splash;
- public GUI(FreeColClient freeColClient) {
+ private boolean headless = false;
+
+
+ /**
+ * Make a new GUI.
+ *
+ * @param freeColClient The parent client.
+ * @param headless Should we run in headless mode.
+ */
+ public GUI(FreeColClient freeColClient, boolean headless) {
this.freeColClient = freeColClient;
+ this.headless = headless;
this.imageLibrary = new ImageLibrary();
}
public void activateGotoPath() {
+ if (headless) return;
Unit unit = getActiveUnit();
// Action should be disabled if there is no active unit, but make sure
@@ -194,13 +205,15 @@ public class GUI {
/**
* Verifies if the client can play sounds.
- * @return boolean <b>true</b> if and only if client sound player has an instance
+ *
+ * @return True if and only if client sound player has an instance
*/
public boolean canPlaySound() {
return soundPlayer != null;
}
public void centerActiveUnit() {
+ if (headless) return;
mapViewer.centerActiveUnit();
}
@@ -210,6 +223,7 @@ public class GUI {
* and <code>false</code> for fullscreen mode.
*/
public void changeWindowedMode(boolean windowed) {
+ if (headless) return;
JMenuBar menuBar = null;
if (frame != null) {
menuBar = frame.getJMenuBar();
@@ -220,9 +234,10 @@ public class GUI {
frame.dispose();
}
setWindowed(windowed);
-
- this.frame = FreeColFrame.createFreeColFrame(freeColClient, canvas, gd, windowed);
-
+
+ this.frame = FreeColFrame.createFreeColFrame(freeColClient, canvas,
+ gd, windowed);
+
frame.setJMenuBar(menuBar);
frame.setCanvas(canvas);
frame.updateBounds(getWindowBounds());
@@ -233,18 +248,22 @@ public class GUI {
}
public void closeMainPanel() {
+ if (headless) return;
canvas.closeMainPanel();
}
public void closeMenus() {
+ if (headless) return;
canvas.closeMenus();
}
public void closeStatusPanel() {
+ if (headless) return;
canvas.closeStatusPanel();
}
public boolean containsInGameComponents() {
+ if (headless) return false;
return canvas.containsInGameComponents();
}
@@ -257,6 +276,7 @@ public class GUI {
}
public void displayChat(String senderNme, String message, boolean privateChat) {
+ if (headless) return;
canvas.displayChat(senderNme, message, privateChat);
}
@@ -273,6 +293,7 @@ public class GUI {
*/
public void displayChatMessage(Player player, String message,
boolean privateChat) {
+ if (headless) return;
mapViewer.addMessage(new GUIMessage(player.getName() + ": " + message,
imageLibrary.getColor(player)));
@@ -280,6 +301,7 @@ public class GUI {
}
public void displaySpashScreen(final String splashFilename) {
+ if (headless) return;
splash = null;
if (splashFilename != null) {
try {
@@ -301,23 +323,24 @@ public class GUI {
}
public void errorMessage(String messageId) {
+ if (headless) return;
canvas.errorMessage(messageId);
}
public void errorMessage(String messageID, String message) {
+ if (headless) return;
canvas.errorMessage(messageID, message);
-
}
public void executeWithUnitOutForAnimation(final Unit unit,
final Tile sourceTile,
final OutForAnimationCallback r) {
+ if (headless) return;
mapViewer.executeWithUnitOutForAnimation(unit, sourceTile, r);
}
public Unit getActiveUnit() {
- if (mapViewer == null)
- return null;
+ if (mapViewer == null) return null;
return mapViewer.getActiveUnit();
}
@@ -330,12 +353,12 @@ public class GUI {
}
public int getCurrentViewMode() {
+ if (headless) return -1;
return mapViewer.getView();
}
public Tile getFocus() {
- if (mapViewer == null)
- return null;
+ if (mapViewer == null) return null;
return mapViewer.getFocus();
}
@@ -349,10 +372,10 @@ public class GUI {
}
public LoadingSavegameDialog getLoadingSavegameDialog() {
+ if (headless) return null;
return canvas.getLoadingSavegameDialog();
}
-
public float getMapScale() {
return mapViewer.getMapScale();
}
@@ -382,6 +405,7 @@ public class GUI {
}
public void hideSplashScreen() {
+ if (headless) return;
if (splash != null) {
splash.setVisible(false);
splash.dispose();
@@ -392,12 +416,12 @@ public class GUI {
return canvas != null && !canvas.isClientOptionsDialogShowing();
}
-
public boolean isMapboardActionsEnabled() {
return canvas != null && canvas.isMapboardActionsEnabled();
}
public boolean isShowingSubPanel() {
+ if (headless) return false;
return canvas.isShowingSubPanel();
}
@@ -405,20 +429,20 @@ public class GUI {
return windowed;
}
-
public boolean onScreen(Tile tileToCheck) {
return mapViewer.onScreen(tileToCheck);
}
public void paintImmediatelyCanvasIn(Rectangle rectangle) {
+ if (headless) return;
canvas.paintImmediately(rectangle);
}
public void paintImmediatelyCanvasInItsBounds() {
+ if (headless) return;
canvas.paintImmediately(canvas.getBounds());
}
-
/**
* Plays some sound. Parameter == null stops playing a sound.
*
@@ -439,19 +463,21 @@ public class GUI {
}
}
-
public void quit() throws Exception {
+ if (headless) return;
if (!isWindowed()) {
- gd.setFullScreenWindow(null);
+ gd.setFullScreenWindow(null);
}
}
public void refresh() {
+ if (headless) return;
mapViewer.forceReposition();
canvas.refresh();
}
public void refreshPlayersTable() {
+ if (headless) return;
canvas.refreshPlayersTable();
}
@@ -461,28 +487,34 @@ public class GUI {
* @param t The tile to refresh.
*/
public void refreshTile(Tile t) {
+ if (headless) return;
if (t.getX() >= 0 && t.getY() >= 0) {
canvas.repaint(mapViewer.getTileBounds(t));
}
}
public void removeFromCanvas(Component component) {
+ if (headless) return;
canvas.remove(component);
}
public void removeInGameComponents() {
+ if (headless) return;
canvas.removeInGameComponents();
}
public void requestFocusForSubPanel() {
+ if (headless) return;
canvas.getShowingSubPanel().requestFocus();
}
public boolean requestFocusInWindow() {
+ if (headless) return false;
return canvas.requestFocusInWindow();
}
public void resetMenuBar() {
+ if (headless) return;
JMenuBar menuBar = frame.getJMenuBar();
if (menuBar != null) {
((FreeColMenuBar) menuBar).reset();
@@ -490,10 +522,12 @@ public class GUI {
}
public void returnToTitle() {
+ if (headless) return;
canvas.returnToTitle();
}
public void scaleMap(float delta) {
+ if (headless) return;
mapViewer.scaleMap(delta);
refresh();
}
@@ -515,430 +549,528 @@ public class GUI {
}
public void setupInGameMenuBar() {
- frame.setJMenuBar(new InGameMenuBar(freeColClient, this));
- frame.paintAll(canvas.getGraphics());
+ if (headless) return;
+ if (frame != null) {
+ frame.setJMenuBar(new InGameMenuBar(freeColClient, this));
+ frame.paintAll(canvas.getGraphics());
+ }
}
public void setupMenuBarToNull() {
- frame.setJMenuBar(null);
+ if (headless) return;
+ if (frame != null) frame.setJMenuBar(null);
}
- public void setUpMouseListenersForCanvas(){
+ public void setUpMouseListenersForCanvas() {
+ if (headless) return;
canvas.addMouseListener(new CanvasMouseListener(freeColClient, canvas, mapViewer));
canvas.addMouseMotionListener(new CanvasMouseMotionListener(freeColClient, mapViewer));
}
public void setWindowed(boolean windowed) {
this.windowed = windowed;
-
}
public void showAboutPanel() {
+ if (headless) return;
canvas.showAboutPanel();
}
public ScoutIndianSettlementAction showArmedUnitIndianSettlementDialog(IndianSettlement settlement) {
+ if (headless) return null;
return canvas.showArmedUnitIndianSettlementDialog(settlement);
}
public BoycottAction showBoycottedGoodsDialog(Goods goods, Europe europe) {
+ if (headless) return null;
return canvas.showBoycottedGoodsDialog(goods, europe);
}
public void showBuildQueuePanel(Colony colony) {
+ if (headless) return;
canvas.showBuildQueuePanel(colony);
}
public void showBuildQueuePanel(Colony colony, Runnable callBack) {
+ if (headless) return;
canvas.showBuildQueuePanel(colony, callBack);
}
public BuyAction showBuyDialog(Unit unit, Settlement settlement,
Goods goods, int gold, boolean canBuy) {
+ if (headless) return null;
return canvas.showBuyDialog(unit, settlement, goods, gold, canBuy);
}
public List<Goods> showCaptureGoodsDialog(Unit winner, List<Goods> loot) {
+ if (headless) return null;
return canvas.showCaptureGoodsDialog(winner, loot);
}
public void showChatPanel() {
+ if (headless) return;
canvas.showChatPanel();
}
public <T> T showChoiceDialog(Tile tile, String text, String cancelText,
List<ChoiceItem<T>> choices) {
+ if (headless) return null;
return canvas.showChoiceDialog(tile, text, cancelText, choices);
}
public MonarchAction showChoiceMonarchActionDialog(String monarchTitle, List<ChoiceItem<MonarchAction>> actions) {
+ if (headless) return null;
return canvas.showChoiceMonarchActionDialog(monarchTitle, actions);
}
public FoundingFather showChooseFoundingFatherDialog(List<ChoiceItem<FoundingFather>> fathers, String fatherTitle) {
+ if (headless) return null;
return canvas.showChooseFoundingFatherDialog(fathers, fatherTitle);
}
public FoundingFather showChooseFoundingFatherDialog(List<FoundingFather> ffs) {
+ if (headless) return null;
return canvas.showChooseFoundingFatherDialog(ffs);
}
public ClaimAction showClaimDialog(Tile tile, Player player, int price,
Player owner, boolean canAccept) {
+ if (headless) return null;
return canvas.showClaimDialog(tile, player, price, owner, canAccept);
}
public OptionGroup showClientOptionsDialog() {
+ if (headless) return null;
return canvas.showClientOptionsDialog();
}
public ColonyPanel showColonyPanel(Colony colony) {
+ if (headless) return null;
return canvas.showColonyPanel(colony);
}
public void showColonyPanel(Colony colony, Runnable callback) {
+ if (headless) return;
canvas.showColonyPanel(colony, callback);
}
public void showColopediaPanel(String nodeId) {
+ if (headless) return;
canvas.showColopediaPanel(nodeId);
}
public void showCompactLabourReport() {
+ if (headless) return;
canvas.showCompactLabourReport();
}
public void showCompactLabourReport(UnitData unitData) {
+ if (headless) return;
canvas.showCompactLabourReport(unitData);
}
public List<String> showConfirmDeclarationDialog() {
+ if (headless) return null;
return canvas.showConfirmDeclarationDialog();
}
public boolean showConfirmDialog(String text, String okText, String cancelText) {
+ if (headless) return false;
return canvas.showConfirmDialog(text, okText, cancelText);
}
public boolean showConfirmDialog(Tile tile, ModelMessage[] messages,
String okText, String cancelText) {
+ if (headless) return false;
return canvas.showConfirmDialog(tile, messages, okText, cancelText);
}
public boolean showConfirmDialog(Tile tile, StringTemplate text,
String okText, String cancelText) {
+ if (headless) return false;
return canvas.showConfirmDialog(tile, text, okText, cancelText);
}
public void showDeclarationDialog() {
+ if (headless) return;
canvas.showDeclarationDialog();
}
public void showDifficultyDialog(boolean editable) {
+ if (headless) return;
canvas.showDifficultyDialog(editable);
}
public OptionGroup showDifficultyDialog(Specification specification) {
+ if (headless) return null;
return canvas.showDifficultyDialog(specification);
}
public List<Goods> showDumpCargoDialog(Unit unit) {
+ if (headless) return null;
return canvas.showDumpCargoDialog(unit);
}
-
public boolean showEditOptionDialog(Option option) {
+ if (headless) return false;
return canvas.showEditOptionDialog(option);
}
public int showEmigrationPanel(boolean fountainOfYouth) {
+ if (headless) return -1;
return canvas.showEmigrationPanel(fountainOfYouth);
}
public boolean showEndTurnDialog(List<Unit> units) {
+ if (headless) return false;
return canvas.showEndTurnDialog(units);
}
public int showEuropeDialog(EuropePanel.EuropeAction europeAction) {
+ if (headless) return -1;
return canvas.showEuropeDialog(europeAction);
}
public void showEuropePanel() {
+ if (headless) return;
canvas.showEuropePanel();
}
public void showEventPanel(EventType type) {
+ if (headless) return;
canvas.showEventPanel(type);
}
public void showFindSettlementDialog() {
+ if (headless) return;
canvas.showFindSettlementDialog();
}
public void showGameOptionsDialog(boolean editable, boolean loadCustomOptions) {
+ if (headless) return;
canvas.showGameOptionsDialog(editable, loadCustomOptions);
}
public void showHighScoresPanel(String messageId) {
+ if (headless) return;
canvas.showHighScoresPanel(messageId);
}
public void showIndianSettlementPanel(IndianSettlement indianSettlement) {
+ if (headless) return;
canvas.showIndianSettlementPanel(indianSettlement);
}
-
public TradeAction showIndianSettlementTradeDialog(Settlement settlement,
boolean canBuy,
boolean canSell,
boolean canGift) {
+ if (headless) return null;
return canvas.showIndianSettlementTradeDialog(settlement, canBuy, canSell, canGift);
}
public void showInformationMessage(FreeColObject displayObject, String messageId) {
+ if (headless) return;
canvas.showInformationMessage(displayObject, messageId);
}
public void showInformationMessage(FreeColObject displayObject, StringTemplate template) {
+ if (headless) return;
canvas.showInformationMessage(displayObject, template);
}
public void showInformationMessage(ModelMessage message) {
+ if (headless) return;
canvas.showInformationMessage(message);
}
public void showInformationMessage(String messageId) {
+ if (headless) return;
canvas.showInformationMessage(messageId);
}
public void showInformationMessage(StringTemplate template) {
+ if (headless) return;
canvas.showInformationMessage(template);
}
public String showInputDialog(Tile tile, StringTemplate text, String defaultValue,
String okText, String cancelText,
boolean rejectEmptyString) {
+ if (headless) return null;
return canvas.showInputDialog(tile, text, defaultValue, okText, cancelText, rejectEmptyString);
}
public File showLoadDialog(File directory) {
+ if (headless) return null;
return canvas.showLoadDialog(directory);
}
public File showLoadDialog(File directory, FileFilter[] fileFilters) {
+ if (headless) return null;
return canvas.showLoadDialog(directory, fileFilters);
}
public boolean showLoadingSavegameDialog(boolean publicServer, boolean singlePlayer) {
+ if (headless) return false;
return canvas.showLoadingSavegameDialog(publicServer, singlePlayer);
}
-
public void showLogFilePanel() {
+ if (headless) return;
canvas.showLogFilePanel();
}
public void showMainPanel() {
+ if (headless) return;
canvas.showMainPanel();
}
public OptionGroup showMapGeneratorOptionsDialog(OptionGroup mgo, boolean editable, boolean loadCustomOptions){
+ if (headless) return null;
return canvas.showMapGeneratorOptionsDialog(mgo, editable, loadCustomOptions);
}
public Dimension showMapSizeDialog() {
+ if (headless) return null;
return canvas.showMapSizeDialog();
}
public void showModelMessages(ModelMessage... modelMessages) {
+ if (headless) return;
canvas.showModelMessages(modelMessages);
}
public boolean showMonarchPanelDialog(MonarchAction action, StringTemplate replace) {
+ if (headless) return false;
return canvas.showMonarchPanelDialog(action, replace);
}
public DiplomaticTrade showNegotiationDialog(Unit unit, Settlement settlement, DiplomaticTrade agreement) {
+ if (headless) return null;
return canvas.showNegotiationDialog(unit, settlement, agreement);
}
public void showNewPanel() {
+ if (headless) return;
canvas.showNewPanel();
}
public void showNewPanel(Specification specification) {
+ if (headless) return;
canvas.showNewPanel(specification);
}
public boolean showPreCombatDialog(FreeColGameObject attacker,
FreeColGameObject defender,
Tile tile) {
+ if (headless) return false;
return canvas.showPreCombatDialog(attacker, defender, tile);
}
public void showReportCargoPanel() {
+ if (headless) return;
canvas.showReportCargoPanel();
}
public void showReportColonyPanel() {
+ if (headless) return;
canvas.showReportColonyPanel();
}
public void showReportContinentalCongressPanel() {
+ if (headless) return;
canvas.showReportContinentalCongressPanel();
}
public void showReportEducationPanel() {
+ if (headless) return;
canvas.showReportEducationPanel();
}
public void showReportExplorationPanel() {
+ if (headless) return;
canvas.showReportExplorationPanel();
}
public void showReportForeignAffairPanel() {
+ if (headless) return;
canvas.showReportForeignAffairPanel();
}
public void showReportHistoryPanel() {
+ if (headless) return;
canvas.showReportHistoryPanel();
}
public void showReportIndianPanel() {
+ if (headless) return;
canvas.showReportIndianPanel();
}
- public void showReportLabourDetailPanel(UnitType unitType, Map<UnitType, Map<Location, Integer>> data,
- TypeCountMap<UnitType> unitCount, List<Colony> colonies) {
+ public void showReportLabourDetailPanel(UnitType unitType,
+ Map<UnitType, Map<Location, Integer>> data,
+ TypeCountMap<UnitType> unitCount,
+ List<Colony> colonies) {
+ if (headless) return;
canvas.showReportLabourDetailPanel(unitType, data, unitCount, colonies);
-
}
-
public void showReportLabourPanel() {
+ if (headless) return;
canvas.showReportLabourPanel();
}
public void showReportMilitaryPanel() {
+ if (headless) return;
canvas.showReportMilitaryPanel();
}
public void showReportNavalPanel() {
+ if (headless) return;
canvas.showReportNavalPanel();
}
public void showReportProductionPanel() {
+ if (headless) return;
canvas.showReportProductionPanel();
}
public void showReportReligiousPanel() {
+ if (headless) return;
canvas.showReportReligiousPanel();
}
public void showReportRequirementsPanel() {
+ if (headless) return;
canvas.showReportRequirementsPanel();
}
public void showReportTradePanel() {
+ if (headless) return;
canvas.showReportTradePanel();
}
public void showReportTurnPanel(ModelMessage... messages) {
+ if (headless) return;
canvas.showReportTurnPanel(messages);
}
public File showSaveDialog(File directory, String defaultName) {
+ if (headless) return null;
return canvas.showSaveDialog(directory, defaultName);
}
- public File showSaveDialog(File directory, String standardName, FileFilter[] fileFilters, String defaultName) {
- return canvas.showSaveDialog(directory, standardName, fileFilters, defaultName);
+ public File showSaveDialog(File directory, String standardName,
+ FileFilter[] fileFilters, String defaultName) {
+ if (headless) return null;
+ return canvas.showSaveDialog(directory, standardName,
+ fileFilters, defaultName);
}
public ScoutColonyAction showScoutForeignColonyDialog(Colony colony,
- Unit unit,
- boolean canNegotiate) {
+ Unit unit,
+ boolean canNegotiate) {
+ if (headless) return null;
return canvas.showScoutForeignColonyDialog(colony, unit, canNegotiate);
}
-
-
-
- public ScoutIndianSettlementAction showScoutIndianSettlementDialog(IndianSettlement settlement, String number) {
+ public ScoutIndianSettlementAction showScoutIndianSettlementDialog(IndianSettlement settlement,
+ String number) {
+ if (headless) return null;
return canvas.showScoutIndianSettlementDialog(settlement, number);
}
- public int showSelectAmountDialog(GoodsType goodsType, int available, int defaultAmount, boolean needToPay) {
- return canvas.showSelectAmountDialog(goodsType, available, defaultAmount, needToPay);
+ public int showSelectAmountDialog(GoodsType goodsType, int available,
+ int defaultAmount, boolean needToPay) {
+ if (headless) return -1;
+ return canvas.showSelectAmountDialog(goodsType, available,
+ defaultAmount, needToPay);
}
public Location showSelectDestinationDialog(Unit unit) {
+ if (headless) return null;
return canvas.showSelectDestinationDialog(unit);
}
public SellAction showSellDialog(Unit unit, Settlement settlement,
Goods goods, int gold) {
+ if (headless) return null;
return canvas.showSellDialog(unit, settlement, goods, gold);
}
- public void showServerListPanel(String username, List<ServerInfo> serverList) {
+ public void showServerListPanel(String username,
+ List<ServerInfo> serverList) {
+ if (headless) return;
canvas.showServerListPanel(username, serverList);
}
- public <T> T showSimpleChoiceDialog(Tile tile,
- String text, String cancelText,
- List<T> objects) {
+ public <T> T showSimpleChoiceDialog(Tile tile, String text,
+ String cancelText, List<T> objects) {
+ if (headless) return null;
return canvas.showSimpleChoiceDialog(tile, text, cancelText, objects);
}
- public void showStartGamePanel(Game game, Player player, boolean singlePlayerMode) {
+ public void showStartGamePanel(Game game, Player player,
+ boolean singlePlayerMode) {
+ if (headless) return;
canvas.showStartGamePanel(game, player, singlePlayerMode);
}
-
public void showStatisticsPanel() {
+ if (headless) return;
canvas.showStatisticsPanel();
}
public void showStatusPanel(String message) {
+ if (headless) return;
canvas.showStatusPanel(message);
}
public void showTilePanel(Tile tile) {
+ if (headless) return;
canvas.showTilePanel(tile);
}
public void showTilePopUpAtSelectedTile() {
+ if (headless) return;
canvas.showTilePopup(getSelectedTile(),
- mapViewer.getCursor().getCanvasX(),
- mapViewer.getCursor().getCanvasY());
+ mapViewer.getCursor().getCanvasX(),
+ mapViewer.getCursor().getCanvasY());
}
public boolean showTradeRouteDialog(Unit unit) {
+ if (headless) return false;
return canvas.showTradeRouteDialog(unit);
}
public boolean showTradeRouteInputDialog(TradeRoute newRoute) {
+ if (headless) return false;
return canvas.showTradeRouteInputDialog(newRoute);
}
public MissionaryAction showUseMissionaryDialog(Unit unit,
- IndianSettlement settlement,
- boolean canEstablish,
- boolean canDenounce) {
- return canvas.showUseMissionaryDialog(unit, settlement, canEstablish, canDenounce);
+ IndianSettlement settlement,
+ boolean canEstablish,
+ boolean canDenounce) {
+ if (headless) return null;
+ return canvas.showUseMissionaryDialog(unit, settlement,
+ canEstablish, canDenounce);
}
public void showVictoryPanel() {
+ if (headless) return;
canvas.showVictoryPanel();
}
public boolean showWarehouseDialog(Colony colony) {
+ if (headless) return false;
return canvas.showWarehouseDialog(colony);
}
public void showWorkProductionPanel(Unit unit) {
+ if (headless) return;
canvas.showWorkProductionPanel(unit);
}
@@ -951,7 +1083,7 @@ public class GUI {
final boolean loadGame) {
final ClientOptions opts = freeColClient.getClientOptions();
// Prepare the sound system.
- if (sound) {
+ if (sound && !headless) {
final AudioMixerOption amo
= (AudioMixerOption) opts.getOption(ClientOptions.AUDIO_MIXER);
final PercentageOption volume
@@ -969,30 +1101,29 @@ public class GUI {
this.soundPlayer = null;
}
- if (GraphicsEnvironment.isHeadless()) {
- logger.info("It seems that the GraphicsEnvironment is headless!");
- }
- this.gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
- if (!isWindowed()) {
- if (!gd.isFullScreenSupported()) {
- String fullscreenNotSupported =
- "\nIt seems that full screen mode is not fully supported for this" +
- "\nGraphicsDevice. Please try the \"--windowed\" option if you\nexperience" +
- "any graphical problems while running FreeCol.";
- logger.info(fullscreenNotSupported);
- System.out.println(fullscreenNotSupported);
- /*
- * We might want this behavior later: logger.warning("It seems
- * that full screen mode is not supported for this
- * GraphicsDevice! Using windowed mode instead."); windowed =
- * true; setWindowed(true); frame = new
- * WindowedFrame(size);
- */
+ if (!headless) {
+ this.gd = GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getDefaultScreenDevice();
+ if (!isWindowed()) {
+ if (!gd.isFullScreenSupported()) {
+ String fullscreenNotSupported =
+ "\nIt seems that full screen mode is not fully supported for this" +
+ "\nGraphicsDevice. Please try the \"--windowed\" option if you\nexperience" +
+ "any graphical problems while running FreeCol.";
+ logger.info(fullscreenNotSupported);
+ System.out.println(fullscreenNotSupported);
+ }
+ Rectangle bounds = gd.getDefaultConfiguration().getBounds();
+ innerWindowSize = new Dimension(bounds.width - bounds.x, bounds.height - bounds.y);
}
- Rectangle bounds = gd.getDefaultConfiguration().getBounds();
- innerWindowSize = new Dimension(bounds.width - bounds.x, bounds.height - bounds.y);
}
+ this.mapViewer = new MapViewer(freeColClient, this, innerWindowSize,
+ imageLibrary);
+ // Try keeping the map viewer for headless mode, so the active unit
+ // logic can work, but the Canvas is out.
+ if (headless) return;
+
// Work around a Java 2D bug that seems to be X11 specific.
// According to:
// http://www.oracle.com/technetwork/java/javase/index-142560.html
@@ -1027,15 +1158,17 @@ public class GUI {
}
});
- this.mapViewer = new MapViewer(freeColClient, this, innerWindowSize, imageLibrary);
- this.canvas = new Canvas(freeColClient, this, innerWindowSize, mapViewer);
- this.colonyTileGUI = new MapViewer(freeColClient, this, innerWindowSize, imageLibrary);
+ this.canvas = new Canvas(freeColClient, this, innerWindowSize,
+ mapViewer);
+ this.colonyTileGUI = new MapViewer(freeColClient, this,
+ innerWindowSize, imageLibrary);
changeWindowedMode(isWindowed());
frame.setIconImage(ResourceManager.getImage("FrameIcon.image"));
// Now that there is a canvas, prepare for language changes.
- LanguageOption o = (LanguageOption) freeColClient.getClientOptions().getOption(ClientOptions.LANGUAGE);
+ LanguageOption o = (LanguageOption)freeColClient.getClientOptions()
+ .getOption(ClientOptions.LANGUAGE);
if (o != null) {
o.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
@@ -1108,6 +1241,7 @@ public class GUI {
* @return True if the unit should proceed to move.
*/
public boolean confirmAbandonEducation(Unit unit, boolean checkStudent) {
+ if (headless) return true;
StringTemplate message = unit.getAbandonEducationMessage(checkStudent);
return message == null
|| showConfirmDialog(unit.getTile(), message,
@@ -1115,42 +1249,47 @@ public class GUI {
}
public void updateGameOptions() {
+ if (headless) return;
canvas.updateGameOptions();
}
public void updateMapGeneratorOptions() {
+ if (headless) return;
canvas.updateMapGeneratorOptions();
}
public void updateMenuBar() {
+ if (headless) return;
if (frame != null && frame.getJMenuBar() != null) {
- ((FreeColMenuBar) frame.getJMenuBar()).update();
+ ((FreeColMenuBar)frame.getJMenuBar()).update();
}
}
-
private void setupMapEditorMenuBar() {
+ if (headless) return;
frame.setJMenuBar(new MapEditorMenuBar(freeColClient, this));
}
private void setupMouseListenerForMapEditor() {
- CanvasMapEditorMouseListener listener = new CanvasMapEditorMouseListener(freeColClient, this, canvas);
+ if (headless) return;
+ CanvasMapEditorMouseListener listener
+ = new CanvasMapEditorMouseListener(freeColClient, this, canvas);
canvas.addMouseListener(listener);
canvas.addMouseMotionListener(listener);
}
public Parameters showParametersDialog() {
+ if (headless) return null;
return canvas.showParametersDialog();
}
public MapSize showScaleMapSizeDialog() {
+ if (headless) return null;
return canvas.showScaleMapSizeDialog();
}
-
-
-
public void showMapControls(boolean value) {
+ if (headless) return;
if (value && freeColClient.isInGame()) {
if (mapControls == null) {
try {
@@ -1178,12 +1317,11 @@ public class GUI {
}
}
}
-
+
public void updateMapControls() {
- if (mapControls != null)
- mapControls.update();
+ if (mapControls != null) mapControls.update();
}
-
+
public void updateMapControlsInCanvas() {
if (mapControls != null && mapControls.isShowing()) {
mapControls.removeFromComponent(canvas);
@@ -1191,16 +1329,14 @@ public class GUI {
}
}
-
-
public void zoomInMapControls() {
- mapControls.zoomIn();
+ if (mapControls != null) mapControls.zoomIn();
}
-
+
public void zoomOutMapControls() {
- mapControls.zoomOut();
+ if (mapControls != null) mapControls.zoomOut();
}
-
+
public boolean canZoomInMapControls() {
return mapControls != null && mapControls.canZoomInMapControls();
}
@@ -1208,8 +1344,7 @@ public class GUI {
public boolean canZoomOutMapControls() {
return mapControls != null && mapControls.canZoomOutMapControls();
}
-
-
+
/**
* Common utility routine to retrieve animation speed.
*
@@ -1224,16 +1359,17 @@ public class GUI {
}
public void animateUnitAttack(Unit unit, Unit defender, boolean success) {
+ if (headless) return;
Animations.unitAttack(this, unit, defender, success);
-
}
- public void animateUnitMove(Unit unit, Tile sourceTile, Tile destinationTile) {
- Animations.unitMove(this, unit, sourceTile, destinationTile);
-
+ public void animateUnitMove(Unit unit, Tile src, Tile dst) {
+ if (headless) return;
+ Animations.unitMove(this, unit, src, dst);
}
-
+
public BufferedImage createMiniMapThumbNail() {
+ if (headless) return null;
MiniMap miniMap = new MiniMap(freeColClient, this);
miniMap.setTileSize(MiniMap.MAX_TILE_SIZE);
int width = freeColClient.getGame().getMap().getWidth()
@@ -1254,5 +1390,4 @@ public class GUI {
scaledImage.createGraphics().drawImage(image, 0, 0, (int) scaledWidth, 64, null);
return scaledImage;
}
-
}
diff --git a/src/net/sf/freecol/client/gui/panel/DefaultTransferHandler.java b/src/net/sf/freecol/client/gui/panel/DefaultTransferHandler.java
index 09d1c48..ef464fa 100644
--- a/src/net/sf/freecol/client/gui/panel/DefaultTransferHandler.java
+++ b/src/net/sf/freecol/client/gui/panel/DefaultTransferHandler.java
@@ -385,7 +385,7 @@ public final class DefaultTransferHandler extends TransferHandler {
dragAction = NONE;
}
- if (dragAction != NONE && !GraphicsEnvironment.isHeadless()) {
+ if (dragAction != NONE) {
if (recognizer == null) {
recognizer = new FreeColDragGestureRecognizer(new FreeColDragHandler());
}
------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________ Freecol-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freecol-developers
