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