- Fix : Restored update() method to LogBookViewer so that Log is updated correctly with Undo and Reset Game actions.

master
Lodici 2013-10-31 11:18:16 +00:00
parent 0c12639268
commit 164534875a
2 changed files with 24 additions and 7 deletions

View File

@ -475,6 +475,7 @@ public class GameController implements ILogBookListener {
} else {
game.gotoLastUndoPoint();
}
gamePanel.getLogBookViewer().update();
}
public void haltGame() {

View File

@ -23,6 +23,7 @@ public class LogBookViewer extends JPanel {
FontsAndBorders.EMPTY_BORDER
);
private static final int MAX_LINES=200;
private static final int INCREMENT=108;
private final MagicLogBook logBook;
@ -60,17 +61,32 @@ public class LogBookViewer extends JPanel {
}
public MagicLogBook getLogBook() {
return logBook;
}
public void addMagicMessage(MagicMessage magicMessage) {
final int maxWidth = getWidth() - 175;
final MessagePanel panel = new MessagePanel(magicMessage, maxWidth);
panel.setOpaque(false);
panel.setBorder(SEPARATOR_BORDER);
messagePanel.add(panel, 0);
public void update() {
messagePanel.removeAll();
synchronized (logBook) {
int index = logBook.size() - 1;
for (int lines = MAX_LINES; lines > 0 && index >= 0; lines--, index--) {
messagePanel.add(getNewMessagePanel(logBook.get(index)));
}
}
revalidate();
scrollPane.getVerticalScrollBar().setValue(0);
}
public void addMagicMessage(MagicMessage magicMessage) {
messagePanel.add(getNewMessagePanel(magicMessage), 0);
scrollPane.getVerticalScrollBar().setValue(0);
}
private MessagePanel getNewMessagePanel(MagicMessage message) {
final int maxWidth = getWidth() - 175;
final MessagePanel panel = new MessagePanel(message, maxWidth);
panel.setOpaque(false);
panel.setBorder(SEPARATOR_BORDER);
return panel;
}
}