From: Jonathan F. <jon...@ya...> - 2008-11-19 22:49:48
|
> If you know a better way than a JLabel to achieve the same effect, I'd like > to know it. This was the only way I could manage it. OK, done (appended) and it was much easier than I thought. In the process I destaticified some things, which felt like the right thing to do but please check it over. > I think a separate and well-readable window report is needed for various > reasons, not the least one being that, certainly in internet play, players > would like to see a written account of the game actions, not cluttered by > other log info. > The format is like game reports I have seen published on the Internet, and > indeed intended to be suitable for saving, emailing (PBEM), publishing etc. I think a next step might be to have the "game report" be separated from other debug logging by having it be completely regenerable from the same game history that undo uses. I've lost track--does the undo trail now include the entire game, or are there still unundoable actions that cause it to be truncated? -- Jonathan diff -r -x CVS -u --strip-trailing-cr 18xx.orig/rails/ui/swing/GameUIManager.java 18xx/rails/ui/swing/GameUIManager.java --- 18xx.orig/rails/ui/swing/GameUIManager.java 2008-06-30 13:35:29.000000000 -0700 +++ 18xx/rails/ui/swing/GameUIManager.java 2008-11-19 13:52:56.640625000 -0800 @@ -124,7 +124,7 @@ log.debug("==Result from server: " + result); activeWindow.displayServerMessage(); - ReportWindow.addLog(); + reportWindow.addLog(); // End of game checks if (gameManager.isGameOver()) { diff -r -x CVS -u --strip-trailing-cr 18xx.orig/rails/ui/swing/ORUIManager.java 18xx/rails/ui/swing/ORUIManager.java --- 18xx.orig/rails/ui/swing/ORUIManager.java 2008-10-12 07:36:44.000000000 -0700 +++ 18xx/rails/ui/swing/ORUIManager.java 2008-11-19 13:54:08.859375000 -0800 @@ -350,7 +350,7 @@ displayRemainingTiles(); } - ReportWindow.addLog(); + gameUIManager.reportWindow.addLog(); } /** Stub, can be overridden in subclasses */ diff -r -x CVS -u --strip-trailing-cr 18xx.orig/rails/ui/swing/ORWindow.java 18xx/rails/ui/swing/ORWindow.java --- 18xx.orig/rails/ui/swing/ORWindow.java 2008-06-30 13:35:29.000000000 -0700 +++ 18xx/rails/ui/swing/ORWindow.java 2008-11-19 13:54:20.078125000 -0800 @@ -77,7 +77,7 @@ setSize(800, 600); addWindowListener(this); - ReportWindow.addLog(); + gameUIManager.reportWindow.addLog(); } public ORUIManager getORUIManager() { diff -r -x CVS -u --strip-trailing-cr 18xx.orig/rails/ui/swing/ReportWindow.java 18xx/rails/ui/swing/ReportWindow.java --- 18xx.orig/rails/ui/swing/ReportWindow.java 2008-11-18 14:12:50.000000000 -0800 +++ 18xx/rails/ui/swing/ReportWindow.java 2008-11-19 13:57:43.781250000 -0800 @@ -15,29 +15,28 @@ public class ReportWindow extends JFrame implements WindowListener, KeyListener { private static final long serialVersionUID = 1L; - private JLabel message; + private JTextArea message; private JScrollPane messageScroller; private JScrollBar vbar; private JPanel messagePanel; - private static ReportWindow messageWindow; + private ReportWindow messageWindow; private GameManager gameManager; - private static StringBuffer buffer = new StringBuffer("<html></html>"); - public ReportWindow(GameManager gameManager) { messageWindow = this; this.gameManager = gameManager; - message = new JLabel(""); + message = new JTextArea(); + message.setEditable(false); + message.setLineWrap(false); message.setBackground(Color.WHITE); message.setOpaque(true); - message.setVerticalAlignment(SwingConstants.TOP); message.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); messagePanel = new JPanel(new GridBagLayout()); messageScroller = new JScrollPane(message, - ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, + ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); vbar = messageScroller.getVerticalScrollBar(); GridBagConstraints gbc = new GridBagConstraints(); @@ -55,12 +54,10 @@ } - public static void addLog() { + public void addLog() { String newText = ReportBuffer.get(); if (newText.length() > 0) { - buffer.insert(buffer.length() - 7, newText.replaceAll("\n", "<br>")); - - messageWindow.message.setText(buffer.toString()); + message.append(newText); SwingUtilities.invokeLater(new Runnable() { public void run() { messageWindow.vbar.setValue(messageWindow.vbar.getMaximum()); |