- Timestamp:
- 03/15/2017 02:25:16 PM (9 years ago)
- Location:
- trunk/src/tmcsim/client
- Files:
-
- 2 edited
-
CADClockDisplay.java (modified) (20 diffs)
-
CADClockView.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/client/CADClockDisplay.java
r57 r61 1 1 package tmcsim.client; 2 2 3 import java.awt.event.WindowEvent;4 import java.awt.event.WindowListener;5 3 import java.io.FileInputStream; 6 4 import java.io.FileOutputStream; … … 9 7 import java.rmi.RemoteException; 10 8 import java.rmi.server.UnicastRemoteObject; 9 import java.text.SimpleDateFormat; 10 import java.util.Date; 11 11 import java.util.Properties; 12 12 import java.util.Vector; 13 import java.util.concurrent.TimeUnit; 13 14 import java.util.logging.Level; 14 15 import java.util.logging.Logger; 15 16 16 import javax.swing.JFrame;17 17 import javax.swing.JOptionPane; 18 18 import javax.swing.JWindow; … … 20 20 21 21 import tmcsim.client.cadclientgui.CADClientGUI; 22 import tmcsim.client.cadclientgui.CardfileReader;23 import tmcsim.client.cadclientgui.GUIScriptReader;24 import tmcsim.client.cadclientgui.data.CADData;25 import tmcsim.client.cadclientgui.screens.Login;26 import tmcsim.client.cadclientgui.screens.ScreenManager;27 import tmcsim.common.CADEnums;28 22 import tmcsim.common.SimulationException; 29 23 import tmcsim.interfaces.CADClientInterface; … … 43 37 * <code> 44 38 * -----------------------------------------------------------------------------<br> 45 * Host Name The host name where the CAD Simulator is located.<br>46 * Port Number The port number that the CAD Simulator is bound on.<br>47 * CAD Position The integer (>= 0) position for this CAD Client.<br>48 * CAD User ID The unique user id for this CAD Client.<br>49 * Error File Filename of error logging file.<br>39 * Host Name The host name where the CAD Simulator is located.<br> 40 * Port Number The port number that the CAD Simulator is bound on.<br> 41 * CAD Position The integer (>= 0) position for this CAD Client.<br> 42 * CAD User ID The unique user id for this CAD Client.<br> 43 * Error File Filename of error logging file.<br> 50 44 * -----------------------------------------------------------------------------<br> 51 45 * Example File: <br> 52 * CADSimulatorHost = localhost<br>46 * CADSimulatorHost = localhost<br> 53 47 * CADSimulatorSocketPort = 4444<br> 54 48 * CADPosition = 1 <br> 55 * CADUserID = A12345<br>56 * ErrorFile = cad_client_err.txt<br>49 * CADUserID = A12345<br> 50 * ErrorFile = cad_client_err.txt<br> 57 51 * </code> 58 * 52 * 59 53 * @author Matthew Cechini (mcechini@calpoly.edu) 60 54 * @version $Date: 2009/04/17 16:27:47 $ $Revision: 1.8 $ 61 55 */ 62 63 56 public class CADClockDisplay extends UnicastRemoteObject implements 64 CADClientInterface { 65 66 /** Error logger. */ 57 CADClientInterface 58 { 59 60 /** 61 * Error logger. 62 */ 67 63 private static Logger cadClientLogger = Logger.getLogger("tmcsim.client"); 68 64 … … 70 66 * Enumeration containing properties name values. See CADClient class 71 67 * description for more information. 72 * 68 * 73 69 * @author Matthew Cechini 74 70 * @see CADClient 75 71 */ 76 private static enum PROPERTIES { 72 private static enum PROPERTIES 73 { 74 77 75 CAD_SIM_HOST("CADSimulatorHost"), CAD_SIM_PORT("CADSimulatorSocketPort"), CAD_RMI_PORT( 78 "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID( 79 "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE( 80 "DisplayType"); 81 76 "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID( 77 "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE( 78 "DisplayType"); 82 79 public String name; 83 80 84 private PROPERTIES(String n) { 81 private PROPERTIES(String n) 82 { 85 83 name = n; 86 84 } 87 85 } 88 89 86 /** 90 87 * CADClientSocket Object to handle socket communication between the Client … … 92 89 */ 93 90 private CADClientSocket theClientSocket; 94 95 /** Instance of the CADClientModel. */ 91 /** 92 * Instance of the CADClientModel. 93 */ 96 94 private CADClientModel theClientScreenModel; 97 98 /** Instance of the CADClockView. */ 95 /** 96 * Instance of the CADClockView. 97 */ 99 98 private CADClockView theClientScreenView; 100 101 99 /** 102 100 * Instance of the CADCLientGUI Replaces CADClockView 103 101 */ 104 102 private CADClientGUI theClientGUI; 105 106 /** Properties object for the CADClient class. */ 103 /** 104 * Properties object for the CADClient class. 105 */ 107 106 private Properties cadClientProp; 108 109 /** RMI interface for communication with the remote Coordinator. */ 107 /** 108 * RMI interface for communication with the remote Coordinator. 109 */ 110 110 private static CoordinatorInterface theCoorInt; 111 112 /** reference to itself to be used for disconnecting from CADSimulator */ 111 /** 112 * reference to itself to be used for disconnecting from CADSimulator 113 */ 113 114 private CADClientInterface client = this; 114 115 115 private static final String CONFIG_FILE_NAME = "cad_client_config.properties"; 116 117 private String formatInterval(final long l) 118 { 119 final long hr = TimeUnit.SECONDS.toHours(l); 120 final long min = TimeUnit.SECONDS.toMinutes(l - TimeUnit.HOURS.toSeconds(hr)); 121 final long sec = TimeUnit.SECONDS.toSeconds(l - TimeUnit.HOURS.toSeconds(hr) - TimeUnit.MINUTES.toSeconds(min)); 122 return String.format("%02d:%02d:%02d", hr, min, sec); 123 } 116 124 117 125 /** … … 122 130 * and userID read in from the properties file. The ClientScreenView is then 123 131 * created and initialized and set as an observer of the model. 124 * 132 * 125 133 * A thread is created with the runnable ClientScreenModel and is started. 126 134 * When this thread is no longer alive, or the ClientScrenView and 127 135 * CADClientSocket are closed. The program then exits. 128 * 129 * @param propertiesFile 130 * File path (absolute or relative) to the properties file 131 * containing configuration data. 136 * 137 * @param propertiesFile File path (absolute or relative) to the properties 138 * file containing configuration data. 132 139 */ 133 140 public CADClockDisplay(String propertiesFile) throws SimulationException, 134 RemoteException { 141 RemoteException 142 { 135 143 if (!verifyProperties(propertiesFile)) 144 { 136 145 System.exit(0); 146 } 137 147 138 148 connect(cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name).trim(), 139 149 cadClientProp.getProperty(PROPERTIES.CAD_RMI_PORT.name).trim()); 140 150 141 // Instantiate the Socket and Model Objects.142 theClientSocket = new CADClientSocket(cadClientProp.getProperty(143 PROPERTIES.CAD_SIM_HOST.name).trim(),144 Integer.parseInt(cadClientProp.getProperty(145 PROPERTIES.CAD_SIM_PORT.name).trim()));146 theClientScreenModel = new CADClientModel();147 theClientScreenModel.initializeScreen(theClientSocket.getInputStream(),148 theClientSocket.getOutputStream());149 150 // Register this CAD Client with the Simulation Manager151 theClientScreenModel.register(Integer.parseInt(cadClientProp152 .getProperty(PROPERTIES.CLIENT_CAD_POS.name)), cadClientProp153 .getProperty(PROPERTIES.CLIENT_USER_ID.name));154 155 151 // Instantiate the CADScreenView and set up the model-view observer 156 152 // relationship. 157 theClientScreenView = new CADClockView(theClientScreenModel); 158 theClientScreenModel.addObserver(theClientScreenView); 153 theClientScreenView = new CADClockView(); 159 154 theClientScreenView.setVisible(true); 155 156 try 157 { 158 while (true) 159 { 160 long simtime = theCoorInt.getCurrentSimulationTime(); 161 //System.out.println("" + formatInterval(simtime)); 162 theClientScreenView.updateTime("" + formatInterval(simtime)); 163 Thread.sleep(1000); 164 } 165 } catch (InterruptedException ex) 166 { 167 Logger.getLogger(CADClockDisplay.class.getName()).log(Level.SEVERE, null, ex); 168 } 169 160 170 // Create the CAD Client thread to run the CADClientModel Object. 161 Thread clientThread = new Thread(theClientScreenModel);162 clientThread.start();163 164 // TODO: set up model-view relationship similar to ClientView and165 // ScreenView166 // Can repurpose the old model, but may be better to copy over and167 // modify in parallel168 // This is required to perform powerline commands on the data169 // theClientGUI = new CADClientGUI();170 171 // Each screen of the UI should have a reference to either it's parent172 // object or the main client173 // This ensures they all have access to each other and the data model174 // theClientGUI.screen = new ScreenManager(theCoorInt);175 // theClientGUI.login = new Login();176 // theClientGUI.client = this;177 178 // setup keyboard settings for CAD Client179 // if (cadClientProp.getProperty(PROPERTIES.KEYBOARD_TYPE.name).trim()180 // .equals("CAD")) {181 // CADEnums.CAD_KEYS.setupCADKeyboard();182 // }183 // // STD184 // else {185 // CADEnums.CAD_KEYS.setupStandardKeyboard();186 // }187 //188 // theClientScreenModel.addObserver(theClientScreenView);189 //190 // // Initialize the display191 // if (cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name).equals(192 // "FULL_SCREEN")) {193 //194 // theClientScreenView.addWindowListener(new WindowListener() {195 // public void windowClosed(WindowEvent e) {196 // }197 //198 // public void windowOpened(WindowEvent e) {199 // }200 //201 // public void windowIconified(WindowEvent e) {202 // }203 //204 // public void windowDeiconified(WindowEvent e) {205 // }206 //207 // public void windowActivated(WindowEvent e) {208 // }209 //210 // public void windowDeactivated(WindowEvent e) {211 // }212 //213 // public void windowClosing(WindowEvent e) {214 //215 // try {216 // theClientSocket.closeSocket();217 // } catch (SimulationException se) {218 // }219 //220 // System.exit(0);221 // }222 // });223 //224 // theClientScreenView.initWindow();225 // theClientScreenView.setVisible(false);226 // } else {227 // JFrame cadFrame = new JFrame("CAD Client");228 // cadFrame.add(theClientScreenView.initBox());229 // cadFrame.setSize(800, 600);230 //231 // cadFrame.addWindowListener(new WindowListener() {232 // public void windowClosed(WindowEvent e) {233 // }234 //235 // public void windowOpened(WindowEvent e) {236 // }237 //238 // public void windowIconified(WindowEvent e) {239 // }240 //241 // public void windowDeiconified(WindowEvent e) {242 // }243 //244 // public void windowActivated(WindowEvent e) {245 // }246 //247 // public void windowDeactivated(WindowEvent e) {248 // }249 //250 // public void windowClosing(WindowEvent e) {251 //252 // try {253 // theClientSocket.closeSocket();254 // } catch (SimulationException se) {255 // }256 //257 // System.exit(0);258 // }259 // });260 //261 // cadFrame.setVisible(true);262 // }263 //264 // // Create the CAD Client thread to run the CADClientModel Object.265 171 // Thread clientThread = new Thread(theClientScreenModel); 266 172 // clientThread.start(); 267 173 174 268 175 ensureProperShutdown(); 269 176 } … … 272 179 * Connect to the Coordinator's RMI object, and register this object for 273 180 * callback with the Coordinator. 274 * 275 * @param hostname 276 * Host name of the CAD Simulator. 277 * @param portNumber 278 * Port number of the CAD Simulator RMI communication. 279 * @throws SimulationException 280 * if there is an error creating the RMI connection. 181 * 182 * @param hostname Host name of the CAD Simulator. 183 * @param portNumber Port number of the CAD Simulator RMI communication. 184 * @throws SimulationException if there is an error creating the RMI 185 * connection. 281 186 */ 282 187 protected void connect(String hostname, String portNumber) 283 throws SimulationException { 188 throws SimulationException 189 { 284 190 285 191 String coorIntURL = ""; 286 192 287 try { 193 try 194 { 288 195 coorIntURL = "rmi://" + hostname + ":" + portNumber 289 196 + "/coordinator"; 290 197 theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL); 291 198 theCoorInt.registerForCallback(this); 292 } catch (Exception e) { 199 } catch (Exception e) 200 { 293 201 throw new SimulationException(SimulationException.CAD_SIM_CONNECT, 294 202 e); … … 302 210 * the properties file. If the user cancels the process of entering these 303 211 * values, the verification fails. 304 * 305 * @param propertiesFile 306 * File path (absolute or relative) to the properties file 307 * containing configuration data. 212 * 213 * @param propertiesFile File path (absolute or relative) to the properties 214 * file containing configuration data. 308 215 * @return True if the properties file is valid, false if not. 309 * @throws SimulationException 310 * if there is an exception in verifying the properties file, or 311 * if the user cancels input. 216 * @throws SimulationException if there is an exception in verifying the 217 * properties file, or if the user cancels input. 312 218 */ 313 219 private boolean verifyProperties(String propertiesFile) 314 throws SimulationException { 220 throws SimulationException 221 { 315 222 316 223 // Load the properties file. 317 try { 224 try 225 { 318 226 cadClientProp = new Properties(); 319 227 cadClientProp.load(new FileInputStream(propertiesFile)); 320 } catch (Exception e) { 228 } catch (Exception e) 229 { 321 230 cadClientLogger.logp(Level.SEVERE, "SimulationManager", 322 231 "Constructor", "Exception in reading properties file.", e); … … 325 234 e); 326 235 } 327 236 328 237 329 238 // Ensure that the properties file does not have null values for the 330 239 // CAD Simulator's connection information. 331 240 if (cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name) == null 332 || cadClientProp.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null) { 241 || cadClientProp.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null) 242 { 333 243 cadClientLogger.logp(Level.SEVERE, "SimulationManager", 334 244 "Constructor", "Null value in properties file."); … … 336 246 } 337 247 338 try { 248 try 249 { 339 250 // If the properties file does not specify a CAD position, prompt 340 251 // the … … 342 253 // new properties values to the file. If the user cancels, else 343 254 // throw an exception. 344 if (cadClientProp.getProperty(PROPERTIES.CLIENT_CAD_POS.name) == null) { 255 if (cadClientProp.getProperty(PROPERTIES.CLIENT_CAD_POS.name) == null) 256 { 345 257 if (getCADPosition()) 258 { 346 259 cadClientProp.store(new FileOutputStream(propertiesFile), 347 260 ""); 348 else 261 } else 262 { 349 263 throw new SimulationException( 350 264 SimulationException.INITIALIZE_ERROR); 265 } 351 266 } 352 267 … … 356 271 // new properties values to the file. If the user cancels, else 357 272 // throw an exception. 358 if (cadClientProp.getProperty(PROPERTIES.CLIENT_USER_ID.name) == null) { 273 if (cadClientProp.getProperty(PROPERTIES.CLIENT_USER_ID.name) == null) 274 { 359 275 if (getUserID()) 276 { 360 277 cadClientProp.store(new FileOutputStream(propertiesFile), 361 278 ""); 362 else 279 } else 280 { 363 281 throw new SimulationException( 364 282 SimulationException.INITIALIZE_ERROR); 365 } 366 } catch (IOException ioe) { 283 } 284 } 285 } catch (IOException ioe) 286 { 367 287 cadClientLogger.logp(Level.SEVERE, "SimulationManager", 368 288 "Constructor", … … 374 294 if (cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name) == null 375 295 || (!cadClientProp.getProperty(PROPERTIES.DISPLAY_TYPE.name) 376 .equals("FULL_SCREEN") && !cadClientProp.getProperty( 377 PROPERTIES.DISPLAY_TYPE.name).equals("FRAME"))) { 296 .equals("FULL_SCREEN") && !cadClientProp.getProperty( 297 PROPERTIES.DISPLAY_TYPE.name).equals("FRAME"))) 298 { 378 299 cadClientLogger.logp(Level.SEVERE, "SimulationManager", 379 300 "Constructor", "Invalid display type."); … … 388 309 * the user cancels the method returns false, else the Properties object is 389 310 * updated and true is returned. 390 * 311 * 391 312 * @return True if the user successfully selected a CAD position, false if 392 * not. 393 */ 394 private boolean getCADPosition() { 313 * not. 314 */ 315 private boolean getCADPosition() 316 { 395 317 396 318 Vector<Integer> positions = new Vector<Integer>(); 397 319 for (int i = 0; i < 10; i++) 320 { 398 321 positions.add(i); 322 } 399 323 400 324 Object cadPos = null; 401 325 402 while (true) { 326 while (true) 327 { 403 328 cadPos = JOptionPane.showInputDialog(null, 404 329 "Please assign this workstation a CAD position number.", … … 407 332 408 333 // If the user pressed cancel, confirm the exit and return false. 409 if (cadPos == null) { 334 if (cadPos == null) 335 { 410 336 if (JOptionPane 411 337 .showConfirmDialog( 412 null, 413 "CAD Client cannot load until a valid CAD " 414 + "position has been selected. Do you wish to " 415 + "cancel loading the CAD Client?", 416 "Confirm Exit", JOptionPane.YES_NO_OPTION, 417 JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 338 null, 339 "CAD Client cannot load until a valid CAD " 340 + "position has been selected. Do you wish to " 341 + "cancel loading the CAD Client?", 342 "Confirm Exit", JOptionPane.YES_NO_OPTION, 343 JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 344 { 418 345 return false; 419 } 420 // Else the user selected a CAD position, exit the loop. 421 else { 346 } 347 } // Else the user selected a CAD position, exit the loop. 348 else 349 { 422 350 break; 423 351 } … … 433 361 * cancels the method returns false, else the Properties object is updated 434 362 * and true is returned. 435 * 363 * 436 364 * @return True if the user successfully selected a CAD position, false if 437 * not. 438 */ 439 private boolean getUserID() { 365 * not. 366 */ 367 private boolean getUserID() 368 { 440 369 String cadUID = null; 441 370 442 while (true) { 371 while (true) 372 { 443 373 cadUID = JOptionPane.showInputDialog(null, 444 374 "Please assign this workstation a 6-character CAD " 445 + "User ID.", "CAD User ID Asignment",375 + "User ID.", "CAD User ID Asignment", 446 376 JOptionPane.QUESTION_MESSAGE); 447 377 448 378 // /If the user pressed cancel, confirm the exit and return false. 449 if (cadUID == null) { 379 if (cadUID == null) 380 { 450 381 if (JOptionPane.showConfirmDialog(null, 451 382 "CAD Client cannot load until a valid User ID " 452 + "has been entered. Do you wish to "453 + "cancel loading the CAD Client?",383 + "has been entered. Do you wish to " 384 + "cancel loading the CAD Client?", 454 385 "Confirm Exit", JOptionPane.YES_NO_OPTION, 455 386 JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) 387 { 456 388 return false; 457 } 458 // If the user does not enter a valid User ID, notify and reprompt. 459 else if (cadUID.length() != 6) { 389 } 390 } // If the user does not enter a valid User ID, notify and reprompt. 391 else if (cadUID.length() != 6) 392 { 460 393 JOptionPane.showMessageDialog(null, 461 394 "The User ID must be 6 characters.", "Invalid User ID", 462 395 JOptionPane.WARNING_MESSAGE); 463 } 464 // Else the user entered a valid value, exit the loop.465 else{396 } // Else the user entered a valid value, exit the loop. 397 else 398 { 466 399 break; 467 400 } … … 475 408 * Construct the CADClient with the properties file path, either from the 476 409 * command line arguments or default. 477 * 478 * @param args 479 * Command line arguments. 480 */ 481 public static void main(String[] args) { 482 if(System.getProperty("CONFIG_DIR") == null){ 483 System.setProperty("CONFIG_DIR", "config"); 484 } 485 486 try { 410 * 411 * @param args Command line arguments. 412 */ 413 public static void main(String[] args) 414 { 415 if (System.getProperty("CONFIG_DIR") == null) 416 { 417 System.setProperty("CONFIG_DIR", "config"); 418 } 419 420 try 421 { 487 422 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 488 423 new CADClockDisplay(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 489 490 } catch (Exception e) { 424 425 } catch (Exception e) 426 { 491 427 cadClientLogger.logp(Level.SEVERE, "SimulationManager", "Main", 492 428 "Error initializing application."); … … 500 436 } 501 437 502 public void refresh() { 438 public void refresh() 439 { 503 440 theClientGUI.screen.refreshScreens(); 504 441 } 505 442 506 public void ensureProperShutdown() { 507 Runtime.getRuntime().addShutdownHook(new Thread() { 508 public void run() { 509 try { 443 public void ensureProperShutdown() 444 { 445 Runtime.getRuntime().addShutdownHook(new Thread() 446 { 447 public void run() 448 { 449 try 450 { 510 451 theCoorInt.unregisterForCallback(client); 511 } catch (RemoteException e) { 452 } catch (RemoteException e) 453 { 512 454 e.printStackTrace(); 513 455 } … … 515 457 }); 516 458 } 517 518 459 } -
trunk/src/tmcsim/client/CADClockView.java
r58 r61 1 1 package tmcsim.client; 2 2 3 import java.awt.BorderLayout;4 3 import java.awt.Color; 5 4 import java.awt.Dimension; … … 9 8 import java.util.Observable; 10 9 import java.util.Observer; 11 import java.util.TreeMap;12 import java.util.logging.Level;13 10 import java.util.logging.Logger; 14 11 … … 20 17 import javax.swing.JOptionPane; 21 18 import javax.swing.JPanel; 22 import javax.swing.JTextPane;23 19 import javax.swing.WindowConstants; 24 import javax.xml.parsers.DocumentBuilderFactory;25 26 import org.w3c.dom.Document;27 import org.w3c.dom.Element;28 29 import tmcsim.cadmodels.BlankScreenModel;30 import tmcsim.cadmodels.CADScreenModel;31 import tmcsim.cadmodels.IncidentBoardModel;32 import tmcsim.cadmodels.IncidentInquiryModel;33 import tmcsim.cadmodels.IncidentSummaryModel;34 import tmcsim.cadmodels.RoutedMessageModel;35 import tmcsim.client.cadscreens.IB_IncidentBoard;36 import tmcsim.client.cadscreens.II_IncidentInquiry;37 import tmcsim.client.cadscreens.SA_IncidentSummary;38 import tmcsim.client.cadscreens.TO_RoutedMessage;39 import tmcsim.client.cadscreens.view.CADCommandLineView;40 import tmcsim.client.cadscreens.view.CADFooterView;41 import tmcsim.client.cadscreens.view.CADMainView;42 20 import tmcsim.common.ObserverMessage; 43 import tmcsim.common.CADEnums.ARROW;44 21 import tmcsim.common.CADEnums.CADScreenNum; 45 import tmcsim.common.CADEnums.CAD_ERROR; 46 import tmcsim.common.CADEnums.CAD_KEYS; 47 import tmcsim.common.CADProtocol.CAD_CLIENT_CMD; 48 import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus; 22 import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus; 49 23 50 24 /** 51 25 * The CADClientView class is the view component to the CAD Client application. 52 26 * 53 * This view class observers the CADClientModel, listening for updates 54 * from the CAD Simulator. Updates includes the current55 * CAD time */27 * This view class observers the CADClientModel, listening for updates from the 28 * CAD Simulator. Updates includes the current CAD time 29 */ 56 30 @SuppressWarnings("serial") 57 public class CADClockView extends JFrame implements KeyListener, Observer { 58 59 /** Error Logger. */ 31 public class CADClockView extends JFrame 32 { 33 34 /** 35 * Error Logger. 36 */ 60 37 private static Logger cadLogger = Logger.getLogger("tmcsim.client"); 61 62 /** Reference to the CADClient model object. */63 private CADClientModel theModel = null;64 65 /** Current CAD Screen number. */66 private CADScreenNum currentScreenNum = null;67 38 private JPanel mainPane; 68 39 private JLabel currentTime; 69 40 70 41 /** 71 42 * Constructor. Build panes, add key listeners, and set up observer 72 43 * relationship between the footer and main panes. 73 * 74 * @param position 75 * The CAD position for this client terminal. 44 * 45 * @param position The CAD position for this client terminal. 76 46 */ 77 public CADClockView(CADClientModel mod) { 47 public CADClockView() 48 { 78 49 super("CAD Client"); 79 50 this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 80 theModel = mod;81 51 currentTime = new JLabel("0:00:00"); 82 52 CADSimulatorStatus status = new CADSimulatorStatus(); … … 84 54 currentTime.setText(simtime); 85 55 currentTime.setAlignmentX(Box.CENTER_ALIGNMENT); 86 currentTime.setFont(new Font("Geneva", Font.BOLD, 70)); 56 currentTime.setFont(new Font("Geneva", Font.BOLD, 70)); 87 57 mainPane = new JPanel(); 88 58 setSize(new Dimension(730, 455)); … … 90 60 setMinimumSize(new Dimension(730, 455)); 91 61 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); 92 mainPane.setBorder(BorderFactory.createLineBorder(Color.black)); 62 mainPane.setBorder(BorderFactory.createLineBorder(Color.black)); 93 63 mainPane.setBackground(Color.LIGHT_GRAY); 94 64 mainPane.add(currentTime); 95 add(mainPane); 65 add(mainPane); 96 66 pack(); 97 67 } 98 68 99 /** 100 * Observable update method. The CADClientView class is an observer of the 101 * CADClientModel. If the model sends a null object, it is signifying that 102 * it has shut down. In this case, an error message should be shown to prompt 103 * the user to restart the CAD Client. If the update object is an 104 * ObserverMessage object, the following actions are to be taken: 105 * 106 *<table cellpadding="2" cellspacing="2" border="1" 107 * style="text-align: left; width: 250px;"> 108 * <tbody> 109 * <tr> 110 * <th>Message Type</th> 111 * <th>Message Data</th> 112 * <th>Action Taken</th> 113 * </tr> 114 * <tr> 115 * <td>TIME_UPDATE<br></td> 116 * <td>Time String<br></td> 117 * <td>Update the footer pane with the new time.</td> 118 * </tr> 119 * </tbody> 120 *</table> 121 */ 122 public void update(Observable o, Object arg) { 123 124 125 if(arg == null) 126 { 127 JOptionPane.showMessageDialog(this, 128 "Connection to the CAD Simulator has been lost. " + 129 "Restart the CAD Client.", "Connection Error", 130 JOptionPane.ERROR_MESSAGE); 131 return; 132 } 133 134 ObserverMessage oMessage = (ObserverMessage)arg; 135 136 switch(oMessage.type) { 137 // Time updates occur once a minute 138 case TIME_UPDATE: 139 currentTime.setText("" + (String)oMessage.value); 140 break; 141 } 69 public void updateTime(String msg) 70 { 71 currentTime.setText(msg); 142 72 } 143 144 @Override 145 public void keyTyped(KeyEvent e) 146 { 147 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 148 } 149 150 @Override 151 public void keyPressed(KeyEvent e) 152 { 153 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 154 } 155 156 @Override 157 public void keyReleased(KeyEvent e) 158 { 159 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 160 } 161 162 163 164 } 73 }
Note: See TracChangeset
for help on using the changeset viewer.
