source: tmcsimulator/trunk/src/archive/paramsim/paramicssimulator/gui/ParamicsSimulatorGUI.java @ 66

Revision 66, 3.7 KB checked in by jdalbey, 9 years ago (diff)

Import Paramics Simulator.

Line 
1package paramsim.paramicssimulator.gui;
2
3import java.awt.Dimension;
4import java.text.DateFormat;
5import java.util.Observable;
6import java.util.Observer;
7import java.util.logging.Handler;
8import java.util.logging.LogRecord;
9import java.util.logging.Logger;
10
11import javax.swing.BorderFactory;
12import javax.swing.Box;
13import javax.swing.BoxLayout;
14import javax.swing.JFrame;
15import javax.swing.JTabbedPane;
16
17import paramsim.paramicssimulator.ParamicsSimulator;
18import paramsim.paramicssimulator.ParamicsSimulatorLogMessage;
19
20/**
21 * A class which interfaces a ParamicsSimulator.
22 * Contains tabs for the controls, logs for all file IO performed by the Simulator, as well
23 * as an error log.
24 *
25 * @author Greg Eddington
26 */
27@SuppressWarnings("serial")
28public class ParamicsSimulatorGUI extends JFrame implements Observer
29{       
30        /** The tabs of the GUI **/
31        private JTabbedPane tabs;
32       
33        /** The Paramics Status Panel **/
34        private ParamicsLogPanel paramicsStatusPanel;
35       
36        /** The Camera Status Panel **/
37        private ParamicsLogPanel cameraStatusPanel;
38       
39        /** The Incident Panel **/
40        private ParamicsLogPanel incidentPanel;
41       
42        /** The Error Panel **/
43        private ParamicsLogPanel errorPanel;
44       
45        /** The Paramics Simulator the GUI is interfacing **/
46        private ParamicsSimulator simulator;
47       
48        /**
49         * Logging handler that writes all received log records to the
50         * error text area.
51         * @author Greg Eddington
52         */
53        protected class ParamicsSimulatorErrorLoggerHandler extends Handler
54        {
55                DateFormat timeFormat = DateFormat.getTimeInstance();
56                public void close() throws SecurityException {}
57                public void flush() {}
58                public void publish(LogRecord record) { errorPanel.write(record.getMessage()); }               
59        }
60
61        /**
62         * Creates a new GUI for the Paramics Simulator.
63         *
64         * @param simulator The Simulator to interface
65         */
66        public ParamicsSimulatorGUI(ParamicsSimulator simulator) 
67        {               
68                super("Paramics Simulator");
69       
70                // Set the logger handler
71                Logger.getLogger("paramsim.paramicssimulator").addHandler(new ParamicsSimulatorErrorLoggerHandler());
72               
73                this.simulator = simulator;
74               
75                initializeGUI();
76        }       
77       
78        /**
79         * Updates the GUI when something being observed changes.
80         *
81         * If the argument is a ParamicSimulatorLogMessage, switch on which log the message
82         * is for and update the appropriate log panel.
83         */
84        public void update(Observable o, Object arg) 
85        {       
86                if(arg instanceof ParamicsSimulatorLogMessage) 
87                {
88                        ParamicsSimulatorLogMessage logMessage = (ParamicsSimulatorLogMessage)arg;
89                        switch (logMessage.log)
90                        {
91                                case PARAMICS_STATUS:
92                                        paramicsStatusPanel.write(logMessage.message);
93                                        break;
94                                case CAMERA_STATUS:
95                                        cameraStatusPanel.write(logMessage.message);
96                                        break;
97                                case EXCHANGE:
98                                        incidentPanel.write(logMessage.message);
99                                        break;
100                        }
101                }
102        }
103       
104        /** Initializes the GUI **/
105        public void initializeGUI() 
106        {       
107                // Create tab layout
108                tabs = new JTabbedPane();
109                tabs.setAlignmentX(Box.CENTER_ALIGNMENT);
110                tabs.setMinimumSize(new Dimension(440, 440));
111                tabs.setPreferredSize(new Dimension(440, 440));
112                tabs.setMaximumSize(new Dimension(440, 440));
113                tabs.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
114               
115                Box guiBox = new Box(BoxLayout.Y_AXIS);
116                guiBox.add(tabs);
117                add(guiBox);
118       
119                // Add tabs
120                tabs.add("Control", new ParamicsControlPanel(simulator));
121                paramicsStatusPanel = new ParamicsLogPanel();
122                tabs.add("Paramics Status", paramicsStatusPanel);
123                cameraStatusPanel = new ParamicsLogPanel();
124                tabs.add("Camera Status", cameraStatusPanel);
125                incidentPanel = new ParamicsLogPanel();
126                tabs.add("Incidents", incidentPanel);
127                errorPanel = new ParamicsLogPanel();
128                tabs.add("Errors", errorPanel);
129               
130                // Set size
131                setMinimumSize(new Dimension(450, 450));
132                setPreferredSize(new Dimension(450, 450));
133                setResizable(false);
134                pack();
135                setVisible(true);
136        }
137}
Note: See TracBrowser for help on using the repository browser.