Ignore:
Timestamp:
06/23/2016 06:30:20 PM (10 years ago)
Author:
jdalbey
Message:

MultiFile? commit: Add CADViewer Interface and change CADSimulator to Observer Pattern.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/cadsimulator/viewer/SimulationStatusPanel.java

    r36 r44  
    55import java.awt.Dimension; 
    66import 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; 
     7import java.util.Observable; 
    118import javax.swing.BorderFactory; 
    129import javax.swing.Box; 
     
    1916import javax.swing.border.EtchedBorder; 
    2017import javax.swing.border.TitledBorder; 
     18import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus; 
    2119import tmcsim.common.CADEnums.PARAMICS_STATUS; 
    2220import tmcsim.common.CADEnums.SCRIPT_STATUS; 
     
    3735 * </ul> 
    3836 * 
    39  * @author Matthew Cechini 
     37 * @author Matthew Cechini, jdalbey 
    4038 * @version 
    4139 */ 
     
    4543 
    4644    /** 
    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()); 
    8274    } 
    8375    /** 
     
    8577     */ 
    8678    private int numClientsConnected = 0; 
    87     /** 
    88      * Logging ErrorHandler. 
    89      */ 
    90     private SimulatorErrorHandler errorHandler; 
    9179 
    9280    /** 
     
    10290        initMessagesPanes(); 
    10391 
    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); 
    196102    } 
    197103 
     
    206112    protected void displayError(String errorMessage) 
    207113    { 
     114        // Do we clear or append? 
    208115        if (errorMessage == null) 
    209116        { 
    210117            errorMessagesTA.setText(""); 
    211         } else 
     118        } 
     119        else 
    212120        { 
    213121            errorMessagesTA.append(errorMessage + "\n"); 
     
    253161     * </table> 
    254162     */ 
    255     public void setScriptStatus(SCRIPT_STATUS newStatus) 
    256     { 
    257  
     163    private void setScriptStatus(SCRIPT_STATUS newStatus) 
     164    { 
     165        // Display text based on status value 
    258166        switch (newStatus) 
    259167        { 
     
    291199     * or dropped. 
    292200     */ 
    293     public void setParamicsStatus(PARAMICS_STATUS newStatus) 
    294     { 
    295  
     201    private void setParamicsStatus(PARAMICS_STATUS newStatus) 
     202    { 
     203        // Display text based on status value 
    296204        switch (newStatus) 
    297205        { 
     
    310218     * @param networkID Unique ID for Paramics network that has been loaded. 
    311219     */ 
    312     public void setParamicsNetworkLoaded(String networkID) 
     220    private void setParamicsNetworkLoaded(String networkID) 
    313221    { 
    314222        networkLoadedTF.setText(networkID); 
     
    325233        simulationStatus = new JLabel("Simulation Status"); 
    326234        simulationStatusText = new JLabel("No Script"); 
     235        simulationStatusText.setName("simulationStatusText"); 
    327236 
    328237        simulationTime.setLayout(new BorderLayout()); 
     
    470379    private Box paramicsConnectedBox; 
    471380    private Box networkLoadedBox; 
    472     private Box CADSimulatorViewerBox; 
     381    private Box cadSimulatorViewerBox; 
    473382    private Box simulationTimeAndStatusBox; 
    474383    private Box simulationStatusBox; 
Note: See TracChangeset for help on using the changeset viewer.