|
From: <ste...@us...> - 2010-10-28 20:45:50
|
Revision: 1456
http://rails.svn.sourceforge.net/rails/?rev=1456&view=rev
Author: stefanfrey
Date: 2010-10-28 20:45:43 +0000 (Thu, 28 Oct 2010)
Log Message:
-----------
Added Clipboard export of recent actions at game save
Modified Paths:
--------------
trunk/18xx/LocalisedText.properties
trunk/18xx/rails/game/ReportBuffer.java
trunk/18xx/rails/ui/swing/GameUIManager.java
Modified: trunk/18xx/LocalisedText.properties
===================================================================
--- trunk/18xx/LocalisedText.properties 2010-10-28 18:57:43 UTC (rev 1455)
+++ trunk/18xx/LocalisedText.properties 2010-10-28 20:45:43 UTC (rev 1456)
@@ -523,6 +523,7 @@
SAVE=Save
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}
Select=Select
SelectCompanyToMergeMinorInto=Select major company to merge minor {0} into
Modified: trunk/18xx/rails/game/ReportBuffer.java
===================================================================
--- trunk/18xx/rails/game/ReportBuffer.java 2010-10-28 18:57:43 UTC (rev 1455)
+++ trunk/18xx/rails/game/ReportBuffer.java 2010-10-28 20:45:43 UTC (rev 1456)
@@ -32,13 +32,17 @@
private RoundI round = null;
private void addMessage(String message) {
- messages.add(Util.convertToHtml(message));
+ messages.add(message);
}
- private String getMessages() {
+ private String getMessages(boolean html) {
StringBuffer s = new StringBuffer();
for (String message:messages) {
- s.append(message);
+ if (html) {
+ s.append(Util.convertToHtml(message));
+ } else {
+ s.append(message);
+ }
}
return s.toString();
}
@@ -61,6 +65,7 @@
StringBuffer s = new StringBuffer();
boolean init = true;
for (String message:messages) {
+ message = Util.convertToHtml(message);
if (init) {
if (activeMessage) {
s.append("<span bgcolor=Yellow>" + ACTIVE_MESSAGE_INDICATOR) ;
@@ -80,12 +85,21 @@
return s.toString();
}
+ public String toText() {
+ StringBuffer s = new StringBuffer();
+ for (String message:messages) {
+ s.append(message + "\n");
+ }
+ return s.toString();
+ }
+
+
public String toString() {
StringBuffer s = new StringBuffer();
s.append("ReportItem for MoveStackIndex = " + index);
s.append(", player = " + player);
s.append(", round = " + round);
- s.append(", messages = "); s.append(getMessages());
+ s.append(", messages = "); s.append(getMessages(false));
return s.toString();
}
}
@@ -260,6 +274,40 @@
instance.clearFutureItems(index);
}
+ /**
+ * returns the latest report items
+ */
+ public static String getLatestReportItems(){
+ ReportBuffer instance = getInstance();
+
+ // search for a change of the player
+ Player currentPlayer = null;
+ int currentPlayerIndex = 0;
+ for (ReportItem item:instance.reportItems.values()) {
+ if (item.player != currentPlayer) {
+ currentPlayer = item.player;
+ currentPlayerIndex = item.index;
+ }
+ }
+
+ // start with that index and connect data
+ StringBuffer s = new StringBuffer();
+ int index = currentPlayerIndex;
+ do {
+ ReportItem item = instance.reportItems.get(index);
+ String text = item.toText();
+ String comment = instance.commentItems.get(index);
+ if (text == null && comment == null) continue;
+ // comments first
+ if (comment != null) {
+ s.append(item.player.getName() + " says: ' ");
+ s.append(comment + "'" + NEWLINE_STRING);
+ }
+ // text afterwards
+ if (text != null) s.append(text);
+ } while (instance.reportItems.containsKey(++index));
+ return s.toString();
+ }
public static String getReportItems() {
// activeIndex is the index one before the current index for the next action
Modified: trunk/18xx/rails/ui/swing/GameUIManager.java
===================================================================
--- trunk/18xx/rails/ui/swing/GameUIManager.java 2010-10-28 18:57:43 UTC (rev 1455)
+++ trunk/18xx/rails/ui/swing/GameUIManager.java 2010-10-28 20:45:43 UTC (rev 1456)
@@ -7,6 +7,9 @@
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -705,6 +708,7 @@
File proposedFile = new File(filename);
jfc.setSelectedFile(proposedFile);
+
if (jfc.showSaveDialog(statusWindow) == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
String filepath = selectedFile.getPath();
@@ -720,6 +724,11 @@
public void saveGame(GameAction saveAction) {
+ // copy latest report buffer entries to clipboard
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ StringSelection reportText = new StringSelection(ReportBuffer.getLatestReportItems());
+ clipboard.setContents(reportText, null);
+
JFileChooser jfc = new JFileChooser();
String filename;
if (providedName != null) {
@@ -737,6 +746,10 @@
File proposedFile = new File(filename);
jfc.setSelectedFile(proposedFile);
+
+ // allows adjustment of the save dialog title, to add hint about copy to clipboard
+ jfc.setDialogTitle(LocalText.getText("SaveDialogTitle"));
+
if (jfc.showSaveDialog(statusWindow) == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
String filepath = selectedFile.getPath();
@@ -747,6 +760,7 @@
saveAction.setFilepath(filepath);
processOnServer(saveAction);
}
+
}
public void setSaveDirectory(String saveDirectory) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|