| 1 | package tmcsim.paramicslog.gui; |
|---|
| 2 | |
|---|
| 3 | import javax.swing.*; |
|---|
| 4 | import java.awt.event.WindowEvent; |
|---|
| 5 | import java.util.*; |
|---|
| 6 | |
|---|
| 7 | /** |
|---|
| 8 | * The UI for ParamicsLog. |
|---|
| 9 | * @author Nathaniel Lehrer |
|---|
| 10 | * @version |
|---|
| 11 | */ |
|---|
| 12 | public class ParamicsLogGUI extends JFrame implements Observer { |
|---|
| 13 | |
|---|
| 14 | /** The static instance */ |
|---|
| 15 | private static ParamicsLogGUI instance = new ParamicsLogGUI(); |
|---|
| 16 | |
|---|
| 17 | /** The text area to display the log in */ |
|---|
| 18 | private JTextArea textArea; |
|---|
| 19 | |
|---|
| 20 | /** Creates an instance of this class */ |
|---|
| 21 | public ParamicsLogGUI() { |
|---|
| 22 | |
|---|
| 23 | setupGUI(); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | /** Creates the UI */ |
|---|
| 27 | private void setupGUI() |
|---|
| 28 | { |
|---|
| 29 | try { |
|---|
| 30 | UIManager.setLookAndFeel( |
|---|
| 31 | UIManager.getSystemLookAndFeelClassName()); |
|---|
| 32 | } catch (Exception e) { |
|---|
| 33 | System.err.println("Couldn't use system look and feel."); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | this.addWindowListener(new java.awt.event.WindowAdapter() { |
|---|
| 37 | |
|---|
| 38 | public void windowClosing(WindowEvent e) |
|---|
| 39 | { |
|---|
| 40 | setVisible(false); |
|---|
| 41 | } |
|---|
| 42 | }); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | setTitle("Paramics Log"); |
|---|
| 46 | |
|---|
| 47 | textArea = new JTextArea(); |
|---|
| 48 | textArea.setColumns(60); |
|---|
| 49 | textArea.setRows(30); |
|---|
| 50 | JScrollPane scrollPane = new JScrollPane(textArea); |
|---|
| 51 | |
|---|
| 52 | getContentPane().add(scrollPane); |
|---|
| 53 | |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | /** Shows the UI window */ |
|---|
| 57 | public void display() |
|---|
| 58 | { |
|---|
| 59 | pack(); |
|---|
| 60 | setVisible(true); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * Updates the text area. If the observable class given is of type ParamicsLog then |
|---|
| 65 | * the log entries are displayed. |
|---|
| 66 | * @param o The model for this viewer. |
|---|
| 67 | * @param arg An argument that is not used. |
|---|
| 68 | */ |
|---|
| 69 | public void update(Observable o, Object arg) |
|---|
| 70 | { |
|---|
| 71 | if (o instanceof tmcsim.paramicslog.ParamicsLog) |
|---|
| 72 | { |
|---|
| 73 | textArea.setText(((tmcsim.paramicslog.ParamicsLog) o).getLog()); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | repaint(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * Accessor for the instance of ParamicsLogGUI. |
|---|
| 81 | * @return The instance of ParamicsLogGUI. |
|---|
| 82 | */ |
|---|
| 83 | public static ParamicsLogGUI getInstance() { |
|---|
| 84 | return instance; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | } |
|---|