Changeset 44 in tmcsimulator for trunk/src/tmcsim/cadsimulator/viewer/SimulationStatusPanel.java
- Timestamp:
- 06/23/2016 06:30:20 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/cadsimulator/viewer/SimulationStatusPanel.java
r36 r44 5 5 import java.awt.Dimension; 6 6 import java.awt.Font; 7 import java.util.logging.Handler; 8 import java.util.logging.Level; 9 import java.util.logging.LogRecord; 10 import java.util.logging.Logger; 7 import java.util.Observable; 11 8 import javax.swing.BorderFactory; 12 9 import javax.swing.Box; … … 19 16 import javax.swing.border.EtchedBorder; 20 17 import javax.swing.border.TitledBorder; 18 import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus; 21 19 import tmcsim.common.CADEnums.PARAMICS_STATUS; 22 20 import tmcsim.common.CADEnums.SCRIPT_STATUS; … … 37 35 * </ul> 38 36 * 39 * @author Matthew Cechini 37 * @author Matthew Cechini, jdalbey 40 38 * @version 41 39 */ … … 45 43 46 44 /** 47 * Logging Handler to listen for Information and Error messages logged for 48 * the CAD Simulator. Received LogRecords are displayed in the info or error 49 * message Text Area. 50 * 51 * @author Matthew Cechini 52 */ 53 private class SimulatorErrorHandler extends Handler 54 { 55 56 public void close() throws SecurityException 57 { 58 } 59 60 public void flush() 61 { 62 } 63 64 public void publish(LogRecord rec) 65 { 66 StringBuffer msgBuffer = new StringBuffer(); 67 68 msgBuffer.append(rec.getSourceClassName() + "." 69 + rec.getSourceMethodName() + " = " 70 + rec.getMessage()); 71 72 if (rec.getLevel() == Level.INFO) 73 { 74 infoMessagesTA.setText(infoMessagesTA.getText() 75 + msgBuffer.toString() + "\n"); 76 } else 77 { 78 errorMessagesTA.setText(errorMessagesTA.getText() 79 + msgBuffer.toString() + "\n"); 80 } 81 } 45 * Refresh this view 46 * 47 * @param obs the Observable we are watching 48 */ 49 public void refresh(Observable obs) 50 { 51 CADSimulatorStatus status = (CADSimulatorStatus) obs; 52 termConnectedTF.setText(String.valueOf(status.getNumClients())); 53 String yesno = "No"; 54 // Should we show yes or no? 55 if (status.isSimManagerConnected()) 56 { 57 yesno = "Yes"; 58 } 59 managerConnectedTF.setText(yesno); 60 simulationClockLabel.setText(status.getCurrentTime()); 61 setScriptStatus(status.getScriptStatus()); 62 setParamicsStatus(status.getParamicsStatus()); 63 64 String netText = status.getParmicsNetworkID(); 65 if (netText.length() == 0) 66 { 67 netText = "None"; 68 } 69 setParamicsNetworkLoaded(netText); 70 71 String msgOut = status.getInfoMessages(); 72 infoMessagesTA.setText(msgOut); 73 errorMessagesTA.setText(status.getErrorMessages()); 82 74 } 83 75 /** … … 85 77 */ 86 78 private int numClientsConnected = 0; 87 /**88 * Logging ErrorHandler.89 */90 private SimulatorErrorHandler errorHandler;91 79 92 80 /** … … 102 90 initMessagesPanes(); 103 91 104 errorHandler = new SimulatorErrorHandler(); 105 Logger.getLogger("tmcsim.cadsimulator").addHandler(errorHandler); 106 107 CADSimulatorViewerBox = Box.createVerticalBox(); 108 CADSimulatorViewerBox.add(simulationTimeAndStatusBox); 109 CADSimulatorViewerBox.add(additionalInfoBox); 110 CADSimulatorViewerBox.add(infoMessagesPane); 111 CADSimulatorViewerBox.add(errorMessagesPane); 112 113 add(CADSimulatorViewerBox); 114 } 115 116 /** 117 * Method is called when a CAD Client disconnects from the CAD Simulator. 118 * The displayed number of connected clients is incremented by one. 119 */ 120 public void connectClient() 121 { 122 123 numClientsConnected++; 124 125 termConnectedTF.setText(String.valueOf(numClientsConnected)); 126 } 127 128 /** 129 * Method is called when a CAD Client disconnects from the CAD Simulator. 130 * The displayed number of connected clients is decremented by one. 131 */ 132 public void disconnectClient() 133 { 134 135 if (numClientsConnected > 0) 136 { 137 numClientsConnected--; 138 } 139 140 termConnectedTF.setText(String.valueOf(numClientsConnected)); 141 } 142 143 /** 144 * Method is called when Simulation Manager connects or disconnects. 145 * 146 * @param connection True if simulation manager is connected, false if not. 147 */ 148 public void setSimManagerStatus(boolean connection) 149 { 150 151 if (connection) 152 { 153 managerConnectedTF.setText("Yes"); 154 } else 155 { 156 managerConnectedTF.setText("No"); 157 } 158 159 } 160 161 /** 162 * Method called to convert current simulation time (parameter long value) 163 * to a string of format H:MM:SS. Time is then updated on GUI. 164 * 165 * @param seconds Long value of current time 166 */ 167 public void setTime(long seconds) 168 { 169 String time = new String(); 170 long timeSegment; 171 172 timeSegment = seconds / 3600; 173 time += String.valueOf(timeSegment) + ":"; 174 175 seconds = seconds % 3600; 176 177 timeSegment = seconds / 60; 178 if (timeSegment < 10) 179 { 180 time += "0"; 181 } 182 183 time += String.valueOf(timeSegment) + ":"; 184 seconds = seconds % 60; 185 186 timeSegment = seconds; 187 if (timeSegment < 10) 188 { 189 time += "0"; 190 } 191 192 time += String.valueOf(timeSegment); 193 194 simulationClockLabel.setText(time); 195 92 // errorHandler = new SimulatorErrorHandler(); 93 // Logger.getLogger("tmcsim.cadsimulator").addHandler(errorHandler); 94 95 cadSimulatorViewerBox = Box.createVerticalBox(); 96 cadSimulatorViewerBox.add(simulationTimeAndStatusBox); 97 cadSimulatorViewerBox.add(additionalInfoBox); 98 cadSimulatorViewerBox.add(infoMessagesPane); 99 cadSimulatorViewerBox.add(errorMessagesPane); 100 101 add(cadSimulatorViewerBox); 196 102 } 197 103 … … 206 112 protected void displayError(String errorMessage) 207 113 { 114 // Do we clear or append? 208 115 if (errorMessage == null) 209 116 { 210 117 errorMessagesTA.setText(""); 211 } else 118 } 119 else 212 120 { 213 121 errorMessagesTA.append(errorMessage + "\n"); … … 253 161 * </table> 254 162 */ 255 p ublicvoid setScriptStatus(SCRIPT_STATUS newStatus)256 { 257 163 private void setScriptStatus(SCRIPT_STATUS newStatus) 164 { 165 // Display text based on status value 258 166 switch (newStatus) 259 167 { … … 291 199 * or dropped. 292 200 */ 293 p ublicvoid setParamicsStatus(PARAMICS_STATUS newStatus)294 { 295 201 private void setParamicsStatus(PARAMICS_STATUS newStatus) 202 { 203 // Display text based on status value 296 204 switch (newStatus) 297 205 { … … 310 218 * @param networkID Unique ID for Paramics network that has been loaded. 311 219 */ 312 p ublicvoid setParamicsNetworkLoaded(String networkID)220 private void setParamicsNetworkLoaded(String networkID) 313 221 { 314 222 networkLoadedTF.setText(networkID); … … 325 233 simulationStatus = new JLabel("Simulation Status"); 326 234 simulationStatusText = new JLabel("No Script"); 235 simulationStatusText.setName("simulationStatusText"); 327 236 328 237 simulationTime.setLayout(new BorderLayout()); … … 470 379 private Box paramicsConnectedBox; 471 380 private Box networkLoadedBox; 472 private Box CADSimulatorViewerBox;381 private Box cadSimulatorViewerBox; 473 382 private Box simulationTimeAndStatusBox; 474 383 private Box simulationStatusBox;
Note: See TracChangeset
for help on using the changeset viewer.
