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/CADSimulatorViewer.java

    r36 r44  
    66import java.awt.event.KeyEvent; 
    77import java.awt.event.WindowEvent; 
     8import java.io.IOException; 
     9import java.util.Observable; 
     10import java.util.Properties; 
     11import java.util.logging.Level; 
     12import java.util.logging.Logger; 
    813import javax.swing.JFrame; 
    914import javax.swing.JMenu; 
     
    1318import javax.swing.JTabbedPane; 
    1419import javax.swing.KeyStroke; 
    15 import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate; 
    16 import tmcsim.cadsimulator.videocontrol.DVDTitleUpdate; 
    1720import tmcsim.cadsimulator.viewer.actions.ExitAction; 
    18 import tmcsim.common.CADEnums.PARAMICS_STATUS; 
    19 import tmcsim.common.CADEnums.SCRIPT_STATUS; 
    20 import tmcsim.common.RevisionNumber; 
     21import tmcsim.cadsimulator.viewer.model.CADMediaStatus; 
     22import tmcsim.cadsimulator.viewer.model.CADSimulatorStatus; 
     23import tmcsim.interfaces.CADViewer; 
    2124 
    2225/** 
     
    3033 */ 
    3134@SuppressWarnings("serial") 
    32 public class CADSimulatorViewer extends JFrame 
     35public class CADSimulatorViewer extends JFrame implements CADViewer 
    3336{ 
    3437 
     
    4548     */ 
    4649    private ConfigStatusPanel configPanel; 
     50 
    4751    /** 
    4852     * Constructor. 
    4953     */ 
    50      
    5154    public CADSimulatorViewer() 
    5255    { 
    53         super("CAD Simulator"); 
     56        super(); 
     57        setTitle("CAD Simulator " + getAppVersion()); 
    5458 
    5559        initComponents(); 
     
    5761 
    5862    /** 
    59      * @see SimulationStatusPanel 
     63     * Read the version number from the application properties. The file 
     64     * 'application.properties' is generated by build.xml. 
     65     * 
     66     * @return a version string obtained from application.properties file, or 
     67     * "Version: unknown" if an IOerror prevents us from reading the file. 
    6068     */ 
    61     public void connectClient() 
     69    private String getAppVersion() 
    6270    { 
    63         simulationPanel.connectClient(); 
    64     } 
    65  
    66     /** 
    67      * @see SimulationStatusPanel 
    68      */ 
    69     public void disconnectClient() 
    70     { 
    71         simulationPanel.disconnectClient(); 
    72     } 
    73  
    74     /** 
    75      * @see SimulationStatusPanel 
    76      */ 
    77     public void setSimManagerStatus(boolean connection) 
    78     { 
    79         simulationPanel.setSimManagerStatus(connection); 
    80     } 
    81  
    82     /** 
    83      * @see SimulationStatusPanel 
    84      */ 
    85     public void setTime(long seconds) 
    86     { 
    87         simulationPanel.setTime(seconds); 
    88     } 
    89  
    90     /** 
    91      * @see SimulationStatusPanel 
    92      */ 
    93     public void setScriptStatus(SCRIPT_STATUS newStatus) 
    94     { 
    95         simulationPanel.setScriptStatus(newStatus); 
    96     } 
    97  
    98     /** 
    99      * @see SimulationStatusPanel 
    100      */ 
    101     public void setParamicsStatus(PARAMICS_STATUS newStatus) 
    102     { 
    103         simulationPanel.setParamicsStatus(newStatus); 
    104     } 
    105  
    106     /** 
    107      * @see SimulationStatusPanel 
    108      */ 
    109     public void setParamicsNetworkLoaded(String networkID) 
    110     { 
    111         simulationPanel.setParamicsNetworkLoaded(networkID); 
    112     } 
    113  
    114     /** 
    115      * @see MediaStatusPanel 
    116      */ 
    117     public void updateDVDStatus(DVDStatusUpdate update) 
    118     { 
    119         mediaPanel.updateDVDStatus(update); 
    120     } 
    121  
    122     /** 
    123      * @see MediaStatusPanel 
    124      */ 
    125     public void updateDVDTitle(DVDTitleUpdate update) 
    126     { 
    127         mediaPanel.updateDVDTitle(update); 
     71        String propfilename = "/tmcsim/application.properties"; 
     72        String propKey = "Application.revision"; 
     73        String version = "unknown"; 
     74        try 
     75        { 
     76            Properties props = new Properties(); 
     77            props.load(this.getClass().getResourceAsStream(propfilename)); 
     78            version = (String) props.get(propKey); 
     79        } catch (IOException ex) 
     80        { 
     81            Logger.getLogger("tmcsim/cadsimulator").log(Level.SEVERE, 
     82                    "CADSimulatorView.getAppVersion()", 
     83                    "IOError reading " + propfilename); 
     84        } 
     85        return "revision: " + version; 
    12886    } 
    12987 
     
    147105        if (evt.getID() == WindowEvent.WINDOW_CLOSING) 
    148106        { 
    149             int option = JOptionPane.showConfirmDialog(null, 
    150                     "Closing the CAD Simulator will stop the current " 
    151                     + "simulation.  Do you wish to continue exiting?", 
    152                     "Confirm Exit", 
    153                     JOptionPane.YES_NO_OPTION); 
    154  
    155             if (option != JOptionPane.NO_OPTION) 
    156             { 
    157                 System.exit(0); 
    158             } 
     107//            int option = JOptionPane.showConfirmDialog(null, 
     108//                    "Closing the CAD Simulator will stop the current " 
     109//                    + "simulation.  Do you wish to continue exiting?", 
     110//                    "Confirm Exit", 
     111//                    JOptionPane.YES_NO_OPTION); 
     112// 
     113//            if (option != JOptionPane.NO_OPTION) 
     114//            { 
     115            System.exit(0); 
     116//            } 
    159117        } 
    160118    } 
     
    196154            public void actionPerformed(java.awt.event.ActionEvent evt) 
    197155            { 
    198                 String ver = RevisionNumber.getString(); 
     156                String ver = "";//RevisionNumber.getString(); 
    199157                JOptionPane.showMessageDialog(rootPane, "Version: " + ver, "About", JOptionPane.INFORMATION_MESSAGE); 
    200158            } 
     
    208166        pack(); 
    209167        setResizable(true); 
     168        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    210169    } 
    211170    private JTabbedPane cadSimTabbedPane; 
     
    213172    private JMenu fileMenu; 
    214173    private JMenuItem exitMenuItem; 
     174 
     175    @Override 
     176    public void update(Observable obs, Object obj) 
     177    { 
     178        if (obs instanceof CADSimulatorStatus) 
     179        { 
     180            simulationPanel.refresh(obs); 
     181        } 
     182        if (obs instanceof CADMediaStatus) 
     183        { 
     184            mediaPanel.refresh(obs); 
     185        } 
     186    } 
    215187} 
Note: See TracChangeset for help on using the changeset viewer.