From: Erik V. <ev...@us...> - 2012-02-23 14:37:48
|
LocalisedText.properties | 1 rails/ui/swing/GameUIManager.java | 48 ++++++++++++++++++++++++++++++-------- rails/ui/swing/GridPanel.java | 32 +++++++++++++++++++++++++ rails/ui/swing/StatusWindow.java | 18 ++++++++++++-- 4 files changed, 87 insertions(+), 12 deletions(-) New commits: commit 2f42c466d42059702851c5fc5130a732ccfd73c3 Author: Erik Vos <eri...@xs...> Date: Thu Feb 23 15:37:14 2012 +0100 Added StatusWindow File menu action to dump the (transposed) contents of the GameStatus panel into a semicolon-separated text file with ".status" extension. Any tooltips (with additional info) are included between braces. diff --git a/LocalisedText.properties b/LocalisedText.properties index ac4899b..ce07410 100644 --- a/LocalisedText.properties +++ b/LocalisedText.properties @@ -616,6 +616,7 @@ SAVE_AND_APPLY=Save/Apply SAVEAS=Save As ... SaveDialogTitle=Save Game. Info: Report of current players action copied to Clipboard. SaveFailed=Save failed, reason: {0} +SaveGameStatus=Save game status Select=Select SelectCompanyToMergeMinorInto=Select major company to merge minor {0} into SelectLoansToRepay=Select number of loans of {0} to repay diff --git a/rails/ui/swing/GameUIManager.java b/rails/ui/swing/GameUIManager.java index 7e59194..1c25557 100644 --- a/rails/ui/swing/GameUIManager.java +++ b/rails/ui/swing/GameUIManager.java @@ -1,13 +1,12 @@ package rails.ui.swing; -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.Toolkit; +import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.io.*; import java.text.SimpleDateFormat; import java.util.*; +import java.util.List; import javax.swing.*; import javax.swing.plaf.FontUIResource; @@ -100,7 +99,7 @@ public class GameUIManager implements DialogOwner { Logger.getLogger(GameUIManager.class.getPackage().getName()); private SplashWindow splashWindow = null; - + public GameUIManager() { } @@ -109,7 +108,7 @@ public class GameUIManager implements DialogOwner { this.splashWindow = splashWindow; splashWindow.notifyOfStep(SplashWindow.STEP_INIT_UI); - + instance = this; this.gameManager = gameManager; uiHints = gameManager.getUIHints(); @@ -207,7 +206,7 @@ public class GameUIManager implements DialogOwner { } else { reportWindow = new ReportWindowDynamic(this); } - + orWindow = new ORWindow(this, splashWindow); orUIManager = orWindow.getORUIManager(); @@ -250,7 +249,7 @@ public class GameUIManager implements DialogOwner { public void startLoadedGame() { gameUIInit(false); // false indicates reload - + splashWindow.notifyOfStep(SplashWindow.STEP_INIT_LOADED_GAME); processAction(new NullAction(NullAction.START_GAME)); statusWindow.setGameActions(); @@ -1019,6 +1018,34 @@ public class GameUIManager implements DialogOwner { } + public void saveGameStatus() { + + List<String> status = statusWindow.getGameStatus().getTextContents(); + + JFileChooser jfc = new JFileChooser(); + String filename = saveDirectory + "/" + savePrefix + "_" + + saveDateTimeFormat.format(new Date())+ ".status"; + + File proposedFile = new File(filename); + jfc.setSelectedFile(proposedFile); + + if (jfc.showSaveDialog(statusWindow) == JFileChooser.APPROVE_OPTION) { + File selectedFile = jfc.getSelectedFile(); + } + + try { + PrintWriter pw = new PrintWriter(filename); + + for (String line : status) pw.println(line) ; + + pw.close(); + + } catch (IOException e) { + log.error("Save failed", e); + DisplayBuffer.add(LocalText.getText("SaveFailed", e.getMessage())); + } + } + public void setSaveDirectory(String saveDirectory) { this.saveDirectory = saveDirectory; } @@ -1131,7 +1158,7 @@ public class GameUIManager implements DialogOwner { instance.initFontSettings(); instance.updateWindowsLookAndFeel(); } - + /** * Only set frame directly to visible if the splash phase is already over. * Otherwise, the splash framework remembers this visibility request and @@ -1159,7 +1186,7 @@ public class GameUIManager implements DialogOwner { } /** - * called when the splash process is completed + * called when the splash process is completed * (and visibility changes are not to be deferred any more) */ public void notifyOfSplashFinalization() { @@ -1174,9 +1201,10 @@ public class GameUIManager implements DialogOwner { public void packAndApplySizing(JFrame frame) { final JFrame finalFrame = frame; SwingUtilities.invokeLater(new Thread() { + @Override public void run() { finalFrame.pack(); - + WindowSettings ws = getWindowSettings(); Rectangle bounds = ws.getBounds(finalFrame); if (bounds.x != -1 && bounds.y != -1) finalFrame.setLocation(bounds.getLocation()); diff --git a/rails/ui/swing/GridPanel.java b/rails/ui/swing/GridPanel.java index ddc4582..a835007 100644 --- a/rails/ui/swing/GridPanel.java +++ b/rails/ui/swing/GridPanel.java @@ -16,6 +16,7 @@ import rails.game.*; import rails.game.model.ModelObject; import rails.game.state.BooleanState; import rails.ui.swing.elements.*; +import rails.util.Util; public abstract class GridPanel extends JPanel implements ActionListener, KeyListener { @@ -166,6 +167,37 @@ implements ActionListener, KeyListener { highlightedComps.clear(); } + /** Returns a string array, each element of which contains the text contents + * of one row, separated by semicolons. + */ + public List<String> getTextContents () { + + List<String> result = new ArrayList<String>(32); + StringBuilder b; + String text, tip; + if (fields == null || fields.length == 0) return result; + + for (int i=0; i<fields.length; i++) { + b = new StringBuilder(); + for (int j=0; j<fields[i].length; j++) { + if (j > 0) b.append(";"); + if (fields[i][j] instanceof JLabel) { + text = ((JLabel)fields[i][j]).getText(); + b.append (text == null ? "" : text); + if (fields[i][j] instanceof Field) { + tip = fields[i][j].getToolTipText(); + if (Util.hasValue(tip)) { + b.append("{").append(tip).append("}"); + } + } + } + } + result.add(b.toString().replaceAll("</?html>", "").replaceAll("<br>",",").replaceAll(" x ", "x")); + } + + return result; + } + public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_F1) { HelpWindow.displayHelp(GameManager.getInstance().getHelp()); diff --git a/rails/ui/swing/StatusWindow.java b/rails/ui/swing/StatusWindow.java index 48ee3bd..c0b6640 100644 --- a/rails/ui/swing/StatusWindow.java +++ b/rails/ui/swing/StatusWindow.java @@ -1,10 +1,10 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/ui/swing/StatusWindow.java,v 1.46 2010/06/15 20:16:54 evos Exp $*/ package rails.ui.swing; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Color; import java.awt.event.*; import java.util.*; -import java.util.List; import javax.swing.*; @@ -34,6 +34,8 @@ KeyListener, ActionPerformer { protected static final String AUTOSAVELOAD_CMD = "AutoSaveLoad"; + protected static final String SAVESTATUS_CMD = "SaveGameStatus"; + protected static final String EXPORT_CMD = "Export"; protected static final String UNDO_CMD = "Undo"; @@ -139,6 +141,15 @@ KeyListener, ActionPerformer { menuItem.setEnabled(true); fileMenu.add(menuItem); + menuItem = new JMenuItem(LocalText.getText("SaveGameStatus")); + menuItem.setActionCommand(SAVESTATUS_CMD); + menuItem.setMnemonic(KeyEvent.VK_G); + menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, + ActionEvent.ALT_MASK)); + menuItem.addActionListener(this); + menuItem.setEnabled(true); + fileMenu.add(menuItem); + // export menu item // exportItem = new ActionMenuItem(LocalText.getText("EXPORT")); // exportItem.setActionCommand(EXPORT_CMD); @@ -148,6 +159,7 @@ KeyListener, ActionPerformer { // fileMenu.add(exportItem); // fileMenu.addSeparator(); + menuItem = new JMenuItem(LocalText.getText("QUIT")); menuItem.setActionCommand(QUIT_CMD); menuItem.setMnemonic(KeyEvent.VK_Q); @@ -643,6 +655,8 @@ KeyListener, ActionPerformer { gameUIManager.configWindow.setVisible(((JMenuItem) actor.getSource()).isSelected()); } else if (command.equals(AUTOSAVELOAD_CMD)) { gameUIManager.autoSaveLoadGame(); + } else if (command.equals(SAVESTATUS_CMD)) { + gameUIManager.saveGameStatus(); } else if (executedAction == null) { ; } else if (executedAction instanceof GameAction) { |