Changeset 6 in tmcsimulator for trunk/src/tmcsim/paramicscommunicator/gui/ParamicsCommunicatorGUI.java
- Timestamp:
- 04/20/2016 02:29:52 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/paramicscommunicator/gui/ParamicsCommunicatorGUI.java
r2 r6 11 11 import java.util.logging.LogRecord; 12 12 import java.util.logging.Logger; 13 14 13 import javax.swing.BorderFactory; 15 14 import javax.swing.Box; 16 15 import javax.swing.BoxLayout; 17 16 import javax.swing.JFrame; 17 import javax.swing.JMenuBar; 18 import javax.swing.JOptionPane; 18 19 import javax.swing.JScrollPane; 19 20 import javax.swing.JTabbedPane; 20 21 import javax.swing.JTextArea; 21 22 import tmcsim.common.RevisionNumber; 22 23 import tmcsim.paramicscommunicator.FileIOUpdate; 23 24 import tmcsim.paramicscommunicator.FileRegUpdate; 24 25 25 26 /** 26 * ParamicsCommunicatorGUI is the view class for the ParamicsCommunicator. 27 * The user interface shows a tab for each I/O reader or writer that has28 * been registered with the ParamicsCommunicator. The tab shows the29 * history of I/O reads and writes, and the unique information for the30 * target file and I/Ointerval.31 * 27 * ParamicsCommunicatorGUI is the view class for the ParamicsCommunicator. The 28 * user interface shows a tab for each I/O reader or writer that has been 29 * registered with the ParamicsCommunicator. The tab shows the history of I/O 30 * reads and writes, and the unique information for the target file and I/O 31 * interval. 32 * 32 33 * @author Matthew Cechini 33 34 * @version 34 35 */ 35 36 @SuppressWarnings("serial") 36 public class ParamicsCommunicatorGUI extends JFrame implements Observer { 37 38 /** 39 * Logging handler that writes all received log records to the 40 * error text area. 37 public class ParamicsCommunicatorGUI extends JFrame implements Observer 38 { 39 40 /** 41 * Logging handler that writes all received log records to the error text 42 * area. 43 * 41 44 * @author Matthew Cechini 42 45 */ 43 protected class ParamicsLoggerHandler extends Handler { 46 protected class ParamicsLoggerHandler extends Handler 47 { 44 48 45 49 DateFormat timeFormat = DateFormat.getTimeInstance(); 46 47 public void close() throws SecurityException { 48 } 49 50 public void flush() { 51 } 52 53 public void publish(LogRecord record) { 50 51 public void close() throws SecurityException 52 { 53 } 54 55 public void flush() 56 { 57 } 58 59 public void publish(LogRecord record) 60 { 54 61 StringBuffer errorBuf = new StringBuffer(); 55 62 56 63 errorBuf.append(timeFormat.format(new Date(record.getMillis()))); 57 errorBuf.append(" - " + record.getMessage() + "\n"); 58 59 errorTA.setText(errorTA.getText() + errorBuf.toString()); 60 } 61 } 62 63 /** Map of FileIOTableModel objects for each reader id. */ 64 errorBuf.append(" - " + record.getMessage() + "\n"); 65 66 errorTA.setText(errorTA.getText() + errorBuf.toString()); 67 } 68 } 69 /** 70 * Map of FileIOTableModel objects for each reader id. 71 */ 64 72 protected TreeMap<String, FileIOTableModel> readerTables; 65 66 /** Map of FileIOTableModel objects for each writer id. */ 73 /** 74 * Map of FileIOTableModel objects for each writer id. 75 */ 67 76 protected TreeMap<String, FileIOTableModel> writerTables; 68 69 /** 70 * Constructor. Initialize local lists, set up the logging handler and77 78 /** 79 * Constructor. Initialize local lists, set up the logging handler and 71 80 * initialize the GUI. 72 81 */ 73 public ParamicsCommunicatorGUI() { 82 public ParamicsCommunicatorGUI() 83 { 74 84 super("Paramics Communicator"); 75 85 76 86 readerTables = new TreeMap<String, FileIOTableModel>(); 77 87 writerTables = new TreeMap<String, FileIOTableModel>(); 78 88 79 89 Logger.getLogger("tmcsim.paramicscommunicator").addHandler(new ParamicsLoggerHandler()); 80 90 81 91 initializeGUI(); 82 } 83 84 /** 85 * Observer update method. If the update object is a FileIOUpdate object, 86 * update the TableModel corresponding to the unique I/O id. If the 87 * update object is a FileRegUpdate object, add a new tab if the 88 * registration type is REGISTER, or update an existing tab if the 89 * registration type is UNREGISTER. 90 */ 91 public void update(Observable o, Object arg) { 92 93 if(arg instanceof FileIOUpdate) { 94 95 try { 96 FileIOUpdate update = (FileIOUpdate)arg; 97 98 switch(update.ioType) { 92 } 93 94 /** 95 * Observer update method. If the update object is a FileIOUpdate object, 96 * update the TableModel corresponding to the unique I/O id. If the update 97 * object is a FileRegUpdate object, add a new tab if the registration type 98 * is REGISTER, or update an existing tab if the registration type is 99 * UNREGISTER. 100 */ 101 public void update(Observable o, Object arg) 102 { 103 104 if (arg instanceof FileIOUpdate) 105 { 106 107 try 108 { 109 FileIOUpdate update = (FileIOUpdate) arg; 110 111 switch (update.ioType) 112 { 99 113 case READ: 100 114 readerTables.get(update.ioID).addIOUpdate(update); … … 104 118 break; 105 119 } 106 } 107 catch (Exception e){120 } catch (Exception e) 121 { 108 122 Logger.getLogger("tmcsim.paramicscommunicator.gui").logp( 109 Level.SEVERE, "ParamicsCommunicatorGUI", "update", 123 Level.SEVERE, "ParamicsCommunicatorGUI", "update", 110 124 "Exception in receiving FileIOUpdate object.", e); 111 125 } 112 } 113 else if(arg instanceof FileRegUpdate) { 114 try { 115 FileRegUpdate update = (FileRegUpdate)arg; 116 117 switch(update.ioType) { 126 } else if (arg instanceof FileRegUpdate) 127 { 128 try 129 { 130 FileRegUpdate update = (FileRegUpdate) arg; 131 132 switch (update.ioType) 133 { 118 134 case READ: 119 switch(update.regType) { 135 switch (update.regType) 136 { 120 137 case REGISTER: 121 138 FileIOTableModel model = new FileIOTableModel(); 122 139 readerTables.put(update.ioID, model); 123 140 124 141 addTab(update, model); 125 142 break; … … 130 147 break; 131 148 case WRITE: 132 switch(update.regType) { 149 switch (update.regType) 150 { 133 151 case REGISTER: 134 152 FileIOTableModel model = new FileIOTableModel(); 135 153 writerTables.put(update.ioID, model); 136 154 137 155 addTab(update, model); 138 156 break; … … 140 158 //unregister 141 159 break; 142 } 160 } 143 161 break; 144 162 } 145 163 146 } 147 catch (Exception e){164 } catch (Exception e) 165 { 148 166 Logger.getLogger("tmcsim.paramicscommunicator.gui").logp( 149 Level.SEVERE, "ParamicsCommunicatorGUI", "update", 167 Level.SEVERE, "ParamicsCommunicatorGUI", "update", 150 168 "Exception in receiving FileRegUpdate object.", e); 151 169 } 152 } 153 } 154 155 private void initializeGUI() { 156 157 /* Added by Nathaniel Lehrer */ 158 this.setJMenuBar(new javax.swing.JMenuBar() { 159 { 160 javax.swing.JMenu fileMenu = new javax.swing.JMenu("File"); 161 javax.swing.JMenuItem logItem = new javax.swing.JMenuItem("Show Log"); 162 163 logItem.addActionListener(new java.awt.event.ActionListener() { 164 public void actionPerformed(java.awt.event.ActionEvent evt) { 165 tmcsim.paramicslog.gui.ParamicsLogGUI.getInstance().display(); 166 } 167 }); 168 169 fileMenu.add(logItem); 170 this.add(fileMenu); 170 } 171 } 172 173 private void initializeGUI() 174 { 175 176 JMenuBar menuBar = new JMenuBar(); 177 178 javax.swing.JMenu fileMenu = new javax.swing.JMenu("File"); 179 javax.swing.JMenuItem logItem = new javax.swing.JMenuItem("Show Log"); 180 181 logItem.addActionListener(new java.awt.event.ActionListener() 182 { 183 public void actionPerformed(java.awt.event.ActionEvent evt) 184 { 185 tmcsim.paramicslog.gui.ParamicsLogGUI.getInstance().display(); 171 186 } 172 187 }); 173 /* End Add by Nathaniel Lehrer */ 174 188 189 fileMenu.add(logItem); 190 menuBar.add(fileMenu); 191 192 javax.swing.JMenu helpMenu = new javax.swing.JMenu("Help"); 193 javax.swing.JMenuItem aboutItem = new javax.swing.JMenuItem("About"); 194 195 aboutItem.addActionListener(new java.awt.event.ActionListener() 196 { 197 public void actionPerformed(java.awt.event.ActionEvent evt) 198 { 199 String ver = RevisionNumber.getString(); 200 JOptionPane.showMessageDialog(rootPane, "Version: " + ver, "About", JOptionPane.INFORMATION_MESSAGE); 201 } 202 }); 203 204 helpMenu.add(aboutItem); 205 menuBar.add(helpMenu); 206 207 this.setJMenuBar(menuBar); 208 175 209 fileIOTabs = new JTabbedPane(); 176 210 fileIOTabs.setAlignmentX(Box.CENTER_ALIGNMENT); … … 180 214 fileIOTabs.setBorder(BorderFactory.createCompoundBorder( 181 215 BorderFactory.createTitledBorder( 182 BorderFactory.createRaisedBevelBorder(), "Registered I/O"),183 BorderFactory.createEmptyBorder(5,5,5,5)));184 216 BorderFactory.createRaisedBevelBorder(), "Registered I/O"), 217 BorderFactory.createEmptyBorder(5, 5, 5, 5))); 218 185 219 errorTA = new JTextArea(); 186 220 errorTA.setLineWrap(true); 187 221 188 222 errorPane = new JScrollPane(); 189 223 errorPane.setViewportView(errorTA); … … 191 225 errorPane.setBorder(BorderFactory.createCompoundBorder( 192 226 BorderFactory.createTitledBorder( 193 BorderFactory.createRaisedBevelBorder(), "Errors"),194 BorderFactory.createEmptyBorder(5,5,5,5)));195 196 227 BorderFactory.createRaisedBevelBorder(), "Errors"), 228 BorderFactory.createEmptyBorder(5, 5, 5, 5))); 229 230 197 231 Box guiBox = new Box(BoxLayout.Y_AXIS); 198 232 guiBox.add(fileIOTabs); 199 233 guiBox.add(Box.createVerticalStrut(10)); 200 234 guiBox.add(errorPane); 201 235 202 236 add(guiBox); 203 237 204 238 setMinimumSize(new Dimension(420, 680)); 205 239 setPreferredSize(new Dimension(420, 680)); … … 208 242 setVisible(true); 209 243 } 210 211 /** 212 * Method creates a new tab for the new I/O object. The tab is labeled244 245 /** 246 * Method creates a new tab for the new I/O object. The tab is labeled 213 247 * "Reader #" or "Writer #", where '#' is the I/O object's ID. 248 * 214 249 * @param update Initial update object. 215 * @param model TableModel for reader/writer that will display I/O operations. 216 */ 217 private void addTab(FileRegUpdate update, FileIOTableModel model) { 218 250 * @param model TableModel for reader/writer that will display I/O 251 * operations. 252 */ 253 private void addTab(FileRegUpdate update, FileIOTableModel model) 254 { 255 219 256 String tabName = null; 220 221 switch(update.ioType) { 257 258 switch (update.ioType) 259 { 222 260 case READ: 223 261 tabName = "Reader " + update.ioID; … … 227 265 break; 228 266 } 229 267 230 268 fileIOTabs.add(tabName, new ParamicsIOInfoPanel(update, model)); 231 269 } 232 233 270 private JTabbedPane fileIOTabs; 234 235 271 private JScrollPane errorPane; 236 237 272 private JTextArea errorTA; 238 239 273 }
Note: See TracChangeset
for help on using the changeset viewer.
