Changeset 44 in tmcsimulator for trunk/src/tmcsim/cadsimulator/CADSimulator.java


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

    r33 r44  
    11package tmcsim.cadsimulator; 
    22 
    3 import java.awt.event.WindowEvent; 
    4 import java.awt.event.WindowListener; 
    53import java.io.File; 
    64import java.io.FileInputStream; 
     
    108import java.util.Calendar; 
    119import java.util.Properties; 
    12 import java.util.logging.FileHandler; 
    1310import java.util.logging.Level; 
    1411import java.util.logging.Logger; 
    15  
    1612import javax.swing.JOptionPane; 
    1713import javax.swing.JWindow; 
    1814import javax.swing.UIManager; 
    1915import javax.xml.parsers.DocumentBuilderFactory; 
    20  
    2116import tmcsim.cadsimulator.db.CMSDiversionDB; 
    2217import tmcsim.cadsimulator.managers.ATMSManager; 
     
    2520import tmcsim.cadsimulator.managers.ParamicsSimulationManager; 
    2621import tmcsim.cadsimulator.managers.SimulationControlManager; 
    27 import tmcsim.cadsimulator.viewer.CADSimulatorViewer; 
    28 import tmcsim.client.cadclientgui.data.CADData; 
     22import tmcsim.cadsimulator.viewer.model.CADSimulatorModel; 
    2923import tmcsim.common.SimulationException; 
    30 import tmcsim.simulationmanager.SimulationManager; 
    31  
     24import tmcsim.interfaces.CADViewer; 
    3225 
    3326/** 
    34  * CADSimulator is main class for the CAD Simulator application.  At  
    35  * construction the Coordinator, CoordinatorViewer, and all CAD Simulator  
    36  * Managers are initialized and data relationships are established.   
    37  * Simulation control is managed through the Coordinator and Managers. 
    38  * The CADSimulator contains the instances of all Manager Objects that are used 
    39  * to control the Simulation flow of data.<br> 
     27 * CADSimulator is main class for the CAD Simulator application. At construction 
     28 * the Coordinator, CoordinatorViewer, and all CAD Simulator Managers are 
     29 * initialized and data relationships are established. Simulation control is 
     30 * managed through the Coordinator and Managers. The CADSimulator contains the 
     31 * instances of all Manager Objects that are used to control the Simulation flow 
     32 * of data.<br> 
    4033 * <br> 
    41  *  
    42  * The CADSimulator is initialized with a properties file containing the  
     34 * 
     35 * The CADSimulator is initialized with a properties file containing the 
    4336 * following data items:<br> 
    4437 * <code> 
    4538 * -----------------------------------------------------------------------------<br> 
    46  * CADClientPort          The port number to use for remote CAD Client connections.<br> 
    47  * CoordinatorRMIPort     The port number to use for binding the Coordinator.<br> 
    48  * CMSDiversionXML        The filepath for the xml file containing initialization data for the Diversion "database." 
    49  * AudioFileLocation      The root directory path where audio files are referenced from.<br> 
    50  * ParamicsProperties     The filepath for the properties file to initialize the ParamicsControlManager.<br> 
    51  * ATMSProperties         The filepath for the properties file to initialize the ATMSManager.<br> 
    52  * MediaProperties        The filepath for the properties file to initialize the MediaManager.<br> 
    53  * ErrorFile              The filename of the error file used for logging errors.<br> 
     39 * CADClientPort The port number to use for remote CAD Client connections.<br> 
     40 * CoordinatorRMIPort The port number to use for binding the Coordinator.<br> 
     41 * CMSDiversionXML The filepath for the xml file containing initialization data 
     42 * for the Diversion "database." AudioFileLocation The root directory path where 
     43 * audio files are referenced from.<br> 
     44 * ParamicsProperties The filepath for the properties file to initialize the 
     45 * ParamicsControlManager.<br> 
     46 * ATMSProperties The filepath for the properties file to initialize the 
     47 * ATMSManager.<br> 
     48 * MediaProperties The filepath for the properties file to initialize the 
     49 * MediaManager.<br> 
     50 * ErrorFile The filename of the error file used for logging errors.<br> 
    5451 * ----------------------------------------------------------------------------<br> 
    5552 * Example File:<br> 
    56  * CADClientPort          = 4444<br> 
    57  * CoordinatorRMIPort     = 4445<br> 
    58  * CMSDiversionXML        = ../data/cmsdiversions.xml<br> 
    59  * AudioFileLocation      = ../audio/<br> 
    60  * ParamicsProperties     = ../config/paramics.properties<br> 
    61  * ATMSProperties         = ../config/atms.properties<br> 
    62  * MediaProperties        = ../config/media.properties<br> 
    63  * ErrorFile              = cad_sim_error.xml<br> 
     53 * CADClientPort = 4444<br> 
     54 * CoordinatorRMIPort = 4445<br> 
     55 * CMSDiversionXML = ../data/cmsdiversions.xml<br> 
     56 * AudioFileLocation = ../audio/<br> 
     57 * ParamicsProperties = ../config/paramics.properties<br> 
     58 * ATMSProperties = ../config/atms.properties<br> 
     59 * MediaProperties = ../config/media.properties<br> 
     60 * ErrorFile = cad_sim_error.xml<br> 
    6461 * </code> 
    6562 * 
    66  * @author Matthew Cechini (mcechini@calpoly.edu) 
     63 * @author Matthew Cechini (mcechini@calpoly.edu) jdalbey 
    6764 * @version $Date: 2009/04/17 16:27:46 $ $Revision: 1.5 $ 
    6865 */ 
    69 public class CADSimulator { 
    70      
    71     /** Error logger. */ 
     66public class CADSimulator 
     67{ 
     68 
     69    private static final String CONFIG_FILE_NAME = "cad_simulator_config.properties"; 
     70    /** 
     71     * Error logger. 
     72     */ 
    7273    private static Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator"); 
    7374 
    7475    /** 
    75      * Enumeration containing properties name values.  See CADSimulator class  
     76     * Enumeration containing properties name values. See CADSimulator class 
    7677     * description for more information. 
     78     * 
    7779     * @author Matthew 
    7880     * @see CADSimulator 
    7981     */ 
    80     private static enum CAD_PROPERTIES { 
    81         /** RMI port to accept CAD Client connections. */ 
    82         CLIENT_PORT        ("CADClientPort"),        
    83         /** RMI port to bind the Coordinator to for RMI communication. */ 
    84         COOR_RMI_PORT      ("CoordinatorRMIPort"),   
    85          
    86         CAD_RMI_PORT       ("CADRmiPort"), 
    87         /** Filepath for xml file containing diversion data. */      
    88         CMS_XML_FILE       ("CMSDiversionXML"),  
    89         /** Filepath for xml file containing dvd control data. */ 
    90         DVD_XML_FILE       ("DVDPlayerXML"),     
    91         /** Filepath for xml file containing still image control data. */ 
    92         IMAGE_XML_FILE     ("StillImagesXML"), 
    93         /** Root directory path where audio files are referenced from. */ 
    94         AUDIO_LOCATION     ("AudioFileLocation"), 
    95         /** Filepath for the properties file to initialize the media manager. */ 
    96         MEDIA_PROP_FILE    ("MediaProperties"), 
    97         /** Filepath for the properties file to initialize the paramics control manager. */ 
    98         PARAMICS_PROP_FILE ("ParamicsProperties"), 
    99         /** Filepath for the properties file to initialize the atms manager. */ 
    100         ATMS_PROP_FILE     ("ATMSProperties"); 
    101          
     82    private static enum CAD_PROPERTIES 
     83    { 
     84 
     85        /** 
     86         * RMI port to accept CAD Client connections. 
     87         */ 
     88        CLIENT_PORT("CADClientPort"), 
     89        /** 
     90         * RMI port to bind the Coordinator to for RMI communication. 
     91         */ 
     92        COOR_RMI_PORT("CoordinatorRMIPort"), 
     93        CAD_RMI_PORT("CADRmiPort"), 
     94        /** 
     95         * Filepath for xml file containing diversion data. 
     96         */ 
     97        CMS_XML_FILE("CMSDiversionXML"), 
     98        /** 
     99         * Filepath for xml file containing dvd control data. 
     100         */ 
     101        DVD_XML_FILE("DVDPlayerXML"), 
     102        /** 
     103         * Filepath for xml file containing still image control data. 
     104         */ 
     105        IMAGE_XML_FILE("StillImagesXML"), 
     106        /** 
     107         * Root directory path where audio files are referenced from. 
     108         */ 
     109        AUDIO_LOCATION("AudioFileLocation"), 
     110        /** 
     111         * Filepath for the properties file to initialize the media manager. 
     112         */ 
     113        MEDIA_PROP_FILE("MediaProperties"), 
     114        /** 
     115         * Filepath for the properties file to initialize the paramics control 
     116         * manager. 
     117         */ 
     118        PARAMICS_PROP_FILE("ParamicsProperties"), 
     119        /** 
     120         * Filepath for the properties file to initialize the atms manager. 
     121         */ 
     122        ATMS_PROP_FILE("ATMSProperties"), 
     123        /** 
     124         * Class name of desired user interface. 
     125         */ 
     126        USER_INTERFACE("UserInterface"); 
    102127        public String name; 
    103          
    104         private CAD_PROPERTIES(String n) { 
    105             name = n; 
     128 
     129        private CAD_PROPERTIES(String nam) 
     130        { 
     131            name = nam; 
    106132        } 
    107133    }; 
    108          
    109              
    110     /** CADSimulatorViewer instance. */ 
    111     protected static CADSimulatorViewer theViewer; 
    112  
    113     /** Coordinator instance. */ 
    114     protected static  Coordinator theCoordinator; 
    115      
    116     /** SoundPlayer instance. */ 
    117     protected static  SoundPlayer theSoundPlayer = null; 
    118      
    119     /** SimulationControlManager instance. */ 
    120     protected static  SimulationControlManager theSimulationCntrlMgr = null; 
    121      
    122     /**  ParamicsSimulationManager instance. */ 
    123     protected static  ParamicsSimulationManager theParamicsSimMgr = null; 
    124      
    125     /** IncidentManager instance. */ 
    126     protected static  IncidentManager theIncidentMgr = null; 
    127      
    128     /** MediaManager instance. */    
    129     protected static  MediaManager theMediaMgr = null; 
    130      
    131     /** ATMSManager instance. */ 
    132     protected static  ATMSManager theATMSMgr = null;  
    133  
    134     /** Properties file for the CADSimulator. */ 
    135     private Properties cadSimulatorProperties;   
    136      
    137     private static final String CONFIG_FILE_NAME = "cad_simulator_config.properties"; 
    138  
    139     /** 
    140      * Constructor.  Load the Properties file and initialize all CAD Simulator 
    141      * Managers and establish Manager data relationships.  A  
    142      * CADSimulatorSocketHandler is instantiated and started to being  
    143      * listening for remote CAD connections.  The CMSDiversionDB is initialized 
    144      * with the XML data(incomplete design). 
    145      *  
     134    /** 
     135     * CADSimulatorViewer instance. 
     136     */ 
     137    protected static CADViewer theViewer; 
     138    //protected static CADSimulatorViewer theViewer; 
     139    //protected static CADConsoleViewer theConsole; 
     140    protected static CADSimulatorModel theModel; 
     141    /** 
     142     * Coordinator instance. 
     143     */ 
     144    protected static Coordinator theCoordinator; 
     145    /** 
     146     * SoundPlayer instance. 
     147     */ 
     148    protected static SoundPlayer theSoundPlayer = null; 
     149    /** 
     150     * SimulationControlManager instance. 
     151     */ 
     152    protected static SimulationControlManager theSimulationCntrlMgr = null; 
     153    /** 
     154     * ParamicsSimulationManager instance. 
     155     */ 
     156    protected static ParamicsSimulationManager theParamicsSimMgr = null; 
     157    /** 
     158     * IncidentManager instance. 
     159     */ 
     160    protected static IncidentManager theIncidentMgr = null; 
     161    /** 
     162     * MediaManager instance. 
     163     */ 
     164    protected static MediaManager theMediaMgr = null; 
     165    /** 
     166     * ATMSManager instance. 
     167     */ 
     168    protected static ATMSManager theATMSMgr = null; 
     169    /** 
     170     * Properties file for the CADSimulator. 
     171     */ 
     172    private Properties cadSimulatorProperties; 
     173 
     174    /** 
     175     * Constructor. Load the Properties file and initialize all CAD Simulator 
     176     * Managers and establish Manager data relationships. A 
     177     * CADSimulatorSocketHandler is instantiated and started to being listening 
     178     * for remote CAD connections. The CMSDiversionDB is initialized with the 
     179     * XML data(incomplete design). 
     180     * 
    146181     * @param propertiesFile Filename of CAD Simulator properties file. 
    147      * @throws SimulationException if there is an error in initializing the CAD Simulator. 
    148      */ 
    149     public CADSimulator(String propertiesFile) throws SimulationException { 
    150          
    151         try { 
     182     * @throws SimulationException if there is an error in initializing the CAD 
     183     * Simulator. 
     184     */ 
     185    public CADSimulator(String propertiesFile) throws SimulationException 
     186    { 
     187 
     188        try 
     189        { 
    152190            cadSimulatorProperties = new Properties(); 
    153191            cadSimulatorProperties.load(new FileInputStream(propertiesFile)); 
    154         } 
    155         catch (Exception e) {            
    156             cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Constructor",  
     192        } catch (Exception e) 
     193        { 
     194            cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Constructor", 
    157195                    "Exception in reading properties file.", e); 
    158              
    159             throw new SimulationException(SimulationException.INITIALIZE_ERROR, e);  
    160         } 
    161      
     196 
     197            throw new SimulationException(SimulationException.INITIALIZE_ERROR, e); 
     198        } 
     199 
    162200        //Create the Coordinator and register it for RMI communicator.  Start the 
    163201        //CAD Simulator Socket Handler to begin to accept connections from CAD Clients. 
    164         try { 
    165             theViewer             = new CADSimulatorViewer(); 
    166             theCoordinator        = new Coordinator(); 
     202        try 
     203        { 
     204            String userInterfaceName = 
     205                    cadSimulatorProperties.getProperty( 
     206                    CAD_PROPERTIES.USER_INTERFACE.name); 
     207            if (userInterfaceName == null) 
     208            { 
     209                cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Constructor", 
     210                        propertiesFile + " missing property for user interface."); 
     211                throw new SimulationException(SimulationException.INITIALIZE_ERROR); 
     212            } 
     213            try 
     214            { 
     215                Class uiClass = Class.forName(userInterfaceName); 
     216                theViewer = (CADViewer) uiClass.newInstance(); 
     217            } catch (Throwable exc) 
     218            { 
     219                cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Constructor", 
     220                        "Unable to instantiate user interface: " + userInterfaceName); 
     221                throw new SimulationException(SimulationException.INITIALIZE_ERROR); 
     222            } 
     223            theModel = new CADSimulatorModel(); 
     224            theModel.addObserver(theViewer); 
     225 
     226            theCoordinator = new Coordinator(theModel); 
     227 
    167228            startRegistry(Integer.parseInt( 
    168229                    cadSimulatorProperties.getProperty( 
    169                             CAD_PROPERTIES.COOR_RMI_PORT.name).trim())); 
     230                    CAD_PROPERTIES.COOR_RMI_PORT.name).trim())); 
    170231            startRegistry(Integer.parseInt( 
    171232                    cadSimulatorProperties.getProperty( 
    172                             CAD_PROPERTIES.CAD_RMI_PORT.name).trim())); 
    173  
    174             theSimulationCntrlMgr = new SimulationControlManager(theCoordinator);    
    175              
    176             theATMSMgr            = new ATMSManager( 
    177                     cadSimulatorProperties.getProperty( 
    178                             CAD_PROPERTIES.ATMS_PROP_FILE.name)); 
    179              
    180             theMediaMgr           = new MediaManager( 
    181                     cadSimulatorProperties.getProperty( 
    182                             CAD_PROPERTIES.MEDIA_PROP_FILE.name), 
    183                             theATMSMgr, theViewer); 
    184              
    185             theParamicsSimMgr     = new ParamicsSimulationManager( 
    186                     cadSimulatorProperties.getProperty( 
    187                             CAD_PROPERTIES.PARAMICS_PROP_FILE.name), 
    188                             theCoordinator, theMediaMgr);    
    189              
    190             theSoundPlayer        = new SoundPlayer( 
    191                     cadSimulatorProperties.getProperty( 
    192                             CAD_PROPERTIES.AUDIO_LOCATION.name)); 
     233                    CAD_PROPERTIES.CAD_RMI_PORT.name).trim())); 
     234 
     235            theSimulationCntrlMgr = new SimulationControlManager(theCoordinator); 
     236 
     237            theATMSMgr = new ATMSManager( 
     238                    cadSimulatorProperties.getProperty( 
     239                    CAD_PROPERTIES.ATMS_PROP_FILE.name)); 
     240 
     241            theMediaMgr = new MediaManager( 
     242                    cadSimulatorProperties.getProperty( 
     243                    CAD_PROPERTIES.MEDIA_PROP_FILE.name), 
     244                    theATMSMgr, theModel); 
     245 
     246            theParamicsSimMgr = new ParamicsSimulationManager( 
     247                    cadSimulatorProperties.getProperty( 
     248                    CAD_PROPERTIES.PARAMICS_PROP_FILE.name), 
     249                    theCoordinator, theMediaMgr); 
     250 
     251            theSoundPlayer = new SoundPlayer( 
     252                    cadSimulatorProperties.getProperty( 
     253                    CAD_PROPERTIES.AUDIO_LOCATION.name)); 
    193254            theSoundPlayer.start(); 
    194              
    195             theIncidentMgr        = new IncidentManager(theCoordinator, theSoundPlayer);     
    196              
     255 
     256            theIncidentMgr = new IncidentManager(theCoordinator, theSoundPlayer); 
     257 
    197258 
    198259            //Begin accepting Client connections 
    199260            CADSimulatorSocketHandler tmsh = new CADSimulatorSocketHandler( 
    200261                    Integer.parseInt(cadSimulatorProperties.getProperty( 
    201                             CAD_PROPERTIES.CLIENT_PORT.name).trim())); 
    202             tmsh.start();    
    203         }        
    204         catch (RemoteException e) { 
    205             cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Constructor",  
     262                    CAD_PROPERTIES.CLIENT_PORT.name).trim())); 
     263            tmsh.start(); 
     264        } catch (RemoteException e) 
     265        { 
     266            cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Constructor", 
    206267                    "Exception in starting Coordinator.", e); 
    207              
     268 
    208269            throw new SimulationException(SimulationException.BINDING, e); 
    209         }        
    210          
     270        } 
     271 
    211272        //Load CMS Diversion Information from the XML file 
    212         try {        
    213             if(cadSimulatorProperties.getProperty( 
    214                     CAD_PROPERTIES.CMS_XML_FILE.name) != null) { 
    215                     CMSDiversionDB.getInstance().loadFromXML( 
     273        try 
     274        { 
     275            if (cadSimulatorProperties.getProperty( 
     276                    CAD_PROPERTIES.CMS_XML_FILE.name) != null) 
     277            { 
     278                CMSDiversionDB.getInstance().loadFromXML( 
    216279                        DocumentBuilderFactory.newInstance().newDocumentBuilder() 
    217                             .parse(new File(cadSimulatorProperties.getProperty( 
    218                                     CAD_PROPERTIES.CMS_XML_FILE.name)))); 
    219             }            
    220         } 
    221         catch (Exception e)  
    222         { 
    223             cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Constructor",  
     280                        .parse(new File(cadSimulatorProperties.getProperty( 
     281                        CAD_PROPERTIES.CMS_XML_FILE.name)))); 
     282            } 
     283        } catch (Exception e) 
     284        { 
     285            cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Constructor", 
    224286                    "Exception in parsing CMSDiversion xml file.", e); 
    225              
    226             JOptionPane.showMessageDialog(new JWindow(), "Unable to open " +  
    227                     cadSimulatorProperties.getProperty(CAD_PROPERTIES.CMS_XML_FILE.name),  
    228                 "Initialization Error", JOptionPane.WARNING_MESSAGE);    
    229         } 
    230               
    231         theViewer.addWindowListener(new WindowListener() { 
    232             public void windowClosed(WindowEvent e)  {} 
    233             public void windowOpened(WindowEvent e)  {}             
    234             public void windowIconified(WindowEvent e)  {}          
    235             public void windowDeiconified(WindowEvent e)  {}     
    236             public void windowActivated(WindowEvent e)  {}                              
    237             public void windowDeactivated(WindowEvent e)  {}          
    238             public void windowClosing(WindowEvent e)  {    
    239                 System.exit(0); 
    240             }            
    241         }); 
    242          
     287 
     288            JOptionPane.showMessageDialog(new JWindow(), "Unable to open " 
     289                    + cadSimulatorProperties.getProperty(CAD_PROPERTIES.CMS_XML_FILE.name), 
     290                    "Initialization Error", JOptionPane.WARNING_MESSAGE); 
     291        } 
     292 
    243293        theViewer.setVisible(true); 
    244294 
    245     }  
    246      
    247     /** 
    248      * Binds the Coordinator to an RMI port so that the SimulationManager 
    249      * can communicate with it, and so that the Coordinator can perform RMI 
    250      * callback method calls.  The port numbers and RMI designators are parsed from 
    251      * the properties file file. 
     295    } 
     296 
     297    /** 
     298     * Binds the Coordinator to an RMI port so that the SimulationManager can 
     299     * communicate with it, and so that the Coordinator can perform RMI callback 
     300     * method calls. The port numbers and RMI designators are parsed from the 
     301     * properties file file. 
    252302     * 
    253303     * @param theCoor A reference to the Coordinator object. 
    254      * @throws SimulationException if there are errors in binding the RMI to  
    255      * a port and name. 
    256      */ 
    257     private void startRegistry(Integer regPort) throws SimulationException { 
    258          
    259         try{ 
    260             LocateRegistry.createRegistry(regPort);                              
    261              
     304     * @throws SimulationException if there are errors in binding the RMI to a 
     305     * port and name. 
     306     */ 
     307    private void startRegistry(Integer regPort) throws SimulationException 
     308    { 
     309 
     310        try 
     311        { 
     312//            if (LocateRegistry.getRegistry(regPort) == null) 
     313//            { 
     314            LocateRegistry.createRegistry(regPort); 
    262315            String registryURL = "rmi://localhost:" + regPort + "/coordinator"; 
    263316            Naming.rebind(registryURL, theCoordinator); 
    264         } 
    265         catch (Exception e) {            
     317//            } 
     318        } catch (Exception e) 
     319        { 
    266320            throw new SimulationException(SimulationException.BINDING, e); 
    267321        } 
     
    269323 
    270324    /** 
    271      * Method returns a String represetnation of the current time. String format 
    272      * is HHMM  
     325     * Method returns a String representation of the current time. String format 
     326     * is HHMM 
    273327     * 
    274328     * @return String representation of the current time. 
    275329     */ 
    276     public static String getCADTime() { 
    277         String time = new String();      
     330    public static String getCADTime() 
     331    { 
     332        String time = new String(); 
    278333 
    279334        Calendar rightNow = Calendar.getInstance(); 
    280          
    281         if(rightNow.get(Calendar.HOUR_OF_DAY) < 10) 
     335 
     336        if (rightNow.get(Calendar.HOUR_OF_DAY) < 10) 
     337        { 
    282338            time += "0"; 
    283          
     339        } 
     340 
    284341        time += (String.valueOf(rightNow.get(Calendar.HOUR_OF_DAY))); 
    285          
    286         if(rightNow.get(Calendar.MINUTE) < 10) 
     342 
     343        if (rightNow.get(Calendar.MINUTE) < 10) 
     344        { 
    287345            time += "0"; 
    288          
    289         time += (String.valueOf(rightNow.get(Calendar.MINUTE)));         
    290                              
    291         return time;         
    292     }            
    293      
    294     /** 
    295      * Returns a string representation of the current date.  String format is: 
     346        } 
     347 
     348        time += (String.valueOf(rightNow.get(Calendar.MINUTE))); 
     349 
     350        return time; 
     351    } 
     352 
     353    /** 
     354     * Returns a string representation of the current date. String format is: 
    296355     * MMDDYY 
    297356     * 
    298357     * @return String format of the date. 
    299358     */ 
    300     public static String getCADDate() { 
     359    public static String getCADDate() 
     360    { 
    301361        String date = new String(); 
    302          
     362 
    303363        Calendar rightNow = Calendar.getInstance(); 
    304          
     364 
    305365        //Months are zero referenced 
    306         if(rightNow.get(Calendar.MONTH) + 1 < 10) 
     366        if (rightNow.get(Calendar.MONTH) + 1 < 10) 
     367        { 
    307368            date += "0"; 
    308          
    309         date += (String.valueOf(rightNow.get(Calendar.MONTH)+ 1)); 
    310          
    311         if(rightNow.get(Calendar.DAY_OF_MONTH) < 10) 
     369        } 
     370 
     371        date += (String.valueOf(rightNow.get(Calendar.MONTH) + 1)); 
     372 
     373        if (rightNow.get(Calendar.DAY_OF_MONTH) < 10) 
     374        { 
    312375            date += "0"; 
    313          
    314         date += (String.valueOf(rightNow.get(Calendar.DAY_OF_MONTH)));       
    315                              
    316         if(rightNow.get(Calendar.YEAR) % 1000 < 10) 
     376        } 
     377 
     378        date += (String.valueOf(rightNow.get(Calendar.DAY_OF_MONTH))); 
     379 
     380        if (rightNow.get(Calendar.YEAR) % 1000 < 10) 
     381        { 
    317382            date += "0"; 
    318          
    319         date += (String.valueOf(rightNow.get(Calendar.YEAR) % 1000));                                
    320                              
    321         return date;     
    322          
     383        } 
     384 
     385        date += (String.valueOf(rightNow.get(Calendar.YEAR) % 1000)); 
     386 
     387        return date; 
     388 
    323389    } 
    324          
    325     /** 
    326      * Main class.  Instantiate a CAD Simulator with the properties file  
     390 
     391    /** 
     392     * Main class. Instantiate a CAD Simulator with the properties file 
    327393     * specified on the command line or the default properties file 
    328      *  
     394     * 
    329395     * @param args Command line arguments. 
    330396     */ 
    331     public static void main(String[] args) { 
    332         if(System.getProperty("CONFIG_DIR") == null){ 
    333                 System.setProperty("CONFIG_DIR", "config"); 
    334         } 
    335         try { 
     397    public static void main(String[] args) 
     398    { 
     399        if (System.getProperty("CONFIG_DIR") == null) 
     400        { 
     401            System.setProperty("CONFIG_DIR", "config"); 
     402        } 
     403        try 
     404        { 
    336405            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    337            new CADSimulator(System.getProperty("CONFIG_DIR") + System.getProperty("file.separator") + CONFIG_FILE_NAME); 
    338         } 
    339         catch (Exception e) { 
    340             cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Main",  
     406            String propFile = System.getProperty("CONFIG_DIR") 
     407                    + System.getProperty("file.separator") 
     408                    + CONFIG_FILE_NAME; 
     409            new CADSimulator(propFile); 
     410        } catch (Exception e) 
     411        { 
     412            cadSimLogger.logp(Level.SEVERE, "CADSimulator", "Main", 
    341413                    "Error initializing application.", e); 
    342              
    343             JOptionPane.showMessageDialog(new JWindow(), e.getMessage(),  
    344                     "Error - Program Exiting", JOptionPane.ERROR_MESSAGE);   
    345              
     414 
     415            JOptionPane.showMessageDialog(new JWindow(), e.getMessage(), 
     416                    "Error - Program Exiting", JOptionPane.ERROR_MESSAGE); 
     417 
    346418            System.exit(-1); 
    347419        } 
    348          
     420 
    349421    } 
    350 }  
     422} 
Note: See TracChangeset for help on using the changeset viewer.