Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
MessagesPane.java
Go to the documentation of this file.
1 // This file is part of MicropolisJ.
2 // Copyright (C) 2013 Jason Long
3 // Portions Copyright (C) 1989-2007 Electronic Arts Inc.
4 //
5 // MicropolisJ is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU GPLv3, with additional terms.
7 // See the README file, included in this distribution, for details.
8 
9 package micropolisj.gui;
10 
11 import java.util.ResourceBundle;
12 
13 import javax.swing.JTextPane;
14 import javax.swing.text.BadLocationException;
15 import javax.swing.text.StyledDocument;
16 
17 import micropolisj.engine.MicropolisMessage;
18 
19 public class MessagesPane extends JTextPane {
20  static ResourceBundle cityMessageStrings = ResourceBundle.getBundle("micropolisj.CityMessages");
21 
22  public MessagesPane() {
23  setEditable(false);
24  }
25 
26  public void appendCityMessage(MicropolisMessage message) {
27  appendMessageText(cityMessageStrings.getString(message.name()));
28  }
29 
30  void appendMessageText(String messageText) {
31  try {
32  StyledDocument doc = getStyledDocument();
33  if(doc.getLength() != 0) {
34  doc.insertString(doc.getLength(), "\n", null);
35  }
36  doc.insertString(doc.getLength(), messageText, null);
37  }
38  catch(BadLocationException e) {
39  throw new Error("unexpected", e);
40  }
41  }
42 }