Changeset 455 in tmcsimulator


Ignore:
Timestamp:
07/18/2019 08:20:12 AM (7 years ago)
Author:
jdalbey
Message:

ConfigStatusTab? updated to fix @169.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/application.properties

    r448 r455  
    1 #Tue, 16 Jul 2019 08:06:49 -0700 
     1#Thu, 18 Jul 2019 09:49:25 -0700 
    22 
    3 Application.revision=447 
     3Application.revision=453 
    44 
    5 Application.buildnumber=160 
     5Application.buildnumber=165 
  • trunk/src/tmcsim/cadsimulator/CADServer.java

    r448 r455  
    33import java.io.File; 
    44import java.io.FileInputStream; 
     5import java.lang.reflect.Constructor; 
    56import java.rmi.Naming; 
    67import java.rmi.RemoteException; 
     
    239240            { 
    240241                Class uiClass = Class.forName(userInterfaceName); 
    241                 theViewer = (CADViewer) uiClass.newInstance(); 
     242                Constructor<?> cons = uiClass.getConstructor(String.class); 
     243                theViewer = (CADViewer) cons.newInstance(propertiesFile); 
    242244            } catch (Exception exc) 
    243245            { 
  • trunk/src/tmcsim/cadsimulator/viewer/CADConsoleViewer.java

    r123 r455  
    3636     * Constructor. 
    3737     */ 
    38     public CADConsoleViewer() 
     38    public CADConsoleViewer(String propertiesFile) 
    3939    { 
    4040        display = new PrintWriter(System.out, true); 
  • trunk/src/tmcsim/cadsimulator/viewer/CADServerViewer.java

    r365 r455  
    5858    */ 
    5959    private TrafficModelViewPanel trafficPanel; 
     60    /* 
     61     * Name of propertes file for this run of CAD Server. 
     62    */ 
     63    private String propertiesFile; 
    6064     
    6165    /** 
    6266     * Constructor. 
    6367     */ 
    64     public CADServerViewer() 
     68    public CADServerViewer(String propertiesFile) 
    6569    { 
    6670        super(); 
     71        this.propertiesFile = propertiesFile; 
    6772        setTitle("CAD Server " + RevisionNumber.getAppVersion()); 
    6873 
     
    111116        simulationPanel = new SimulationStatusPanel(); 
    112117        mediaPanel = new MediaStatusPanel(); 
    113         configPanel = new ConfigStatusTab(); 
     118        configPanel = new ConfigStatusTab(propertiesFile); 
    114119        trafficPanel = new TrafficModelViewPanel(); 
    115120 
  • trunk/src/tmcsim/cadsimulator/viewer/ConfigStatusTab.form

    r231 r455  
    1818  <SubComponents> 
    1919    <Component class="javax.swing.JComboBox" name="selectMenu"> 
    20       <Properties> 
    21         <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> 
    22           <StringArray count="5"> 
    23             <StringItem index="0" value="cad_simulator_config.properties"/> 
    24             <StringItem index="1" value="cad_simulator_media_config.properties"/> 
    25             <StringItem index="2" value="cad_simulator_paramics_config.properties"/> 
    26             <StringItem index="3" value="cad_simulator_smoketest_config.properties"/> 
    27             <StringItem index="4" value="traffic_model_config.properties"/> 
    28           </StringArray> 
    29         </Property> 
    30       </Properties> 
    3120      <AuxValues> 
    3221        <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/> 
  • trunk/src/tmcsim/cadsimulator/viewer/ConfigStatusTab.java

    r231 r455  
    77import java.io.FileInputStream; 
    88import java.io.FileNotFoundException; 
     9import java.io.IOException; 
    910import java.nio.file.FileSystems; 
    1011import java.nio.file.Path; 
     12import java.util.Properties; 
    1113import java.util.Scanner; 
     14import java.util.logging.Level; 
     15import java.util.logging.Logger; 
    1216import javax.swing.JComboBox; 
    1317import javax.swing.JFrame; 
     
    1620/** 
    1721 * ConfigStatusPanel displays the content of configuration files. 
     22 * A ComboBox allows the user to select from a list of current properties files. 
    1823 * 
    1924 * @author Drew Miller 
     
    2227public class ConfigStatusTab extends javax.swing.JPanel 
    2328{ 
    24     /** Root config directory name */ 
    25     private String configDir; 
    26      
     29    /** 
     30     * Properties file for the CAD Server. 
     31     */ 
     32    private Properties cadServerProperties; 
     33 
    2734    /** 
    2835     * Creates new form  
    2936     */ 
    30     public ConfigStatusTab() 
     37    public ConfigStatusTab(String propertiesFile) 
    3138    { 
    3239        initComponents(); 
    33         if (System.getProperty("CONFIG_DIR") == null) 
    34         { 
    35             System.setProperty("CONFIG_DIR", "config"); 
    36         } 
    37         configDir = System.getProperty("CONFIG_DIR"); 
    38         setupComboBox(); 
     40        createMenu(propertiesFile); 
     41        addMenuListener(); 
    3942        setupTextView(); 
    4043    } 
     44    /** Add the properties filenames to the combobox menu */ 
     45    private void createMenu(String propertiesFile) 
     46    { 
     47        selectMenu.addItem(propertiesFile); 
     48        try { 
     49            cadServerProperties = new Properties(); 
     50            cadServerProperties.load(new FileInputStream(propertiesFile)); 
     51            // Add each item that's a properties file to the menu 
     52            for (String propname: cadServerProperties.stringPropertyNames()) 
     53            { 
     54                String currVal = (String) cadServerProperties.get(propname); 
     55                if (currVal.endsWith(".properties")) 
     56                { 
     57                    selectMenu.addItem(currVal); 
     58                } 
     59            } 
     60        } catch (FileNotFoundException ex) { 
     61            Logger.getLogger(ConfigStatusTab.class.getName()).log(Level.SEVERE, null, ex); 
     62        } catch (IOException ex) { 
     63            Logger.getLogger(ConfigStatusTab.class.getName()).log(Level.SEVERE, null, ex); 
     64        }         
     65    } 
    4166 
     67    /** Determine complete path to file, given the filename */ 
     68    private Path getPathToFile(String fileName) 
     69    { 
     70        return FileSystems.getDefault().getPath(fileName); 
     71    } 
     72    /** Return the text from the given file */ 
    4273    private String getFileContent(Path pathToFile)  
    4374    { 
     
    5485            return "Error: config file not found."; 
    5586        } 
    56          
    5787    } 
    58  
    59     private Path getPathToFile(String fileName) 
    60     { 
    61         Path p = FileSystems.getDefault().getPath(configDir, fileName); 
    62         return p; 
    63     } 
    64     /** Refresh the display using the given config file */ 
     88    /** Refresh the display using the given properties file path */ 
    6589    private void updateDisplay(Path pathToFileName) 
    6690    { 
     
    6993    } 
    7094 
    71     /** Combo Box with names of config files for user to select */ 
    72     private void setupComboBox() 
     95    /** Add menu listener to the Combo Box */ 
     96    private void addMenuListener() 
    7397    { 
    7498        selectMenu.addActionListener(new ActionListener() 
     
    76100            public void actionPerformed(ActionEvent e) 
    77101            { 
     102                // Find which menu item was clicked 
    78103                JComboBox src = (JComboBox) e.getSource(); 
    79                 Path p = getPathToFile(src.getSelectedItem().toString()); 
     104                // Get the menu item string  
     105                String menuItem = src.getSelectedItem().toString(); 
     106                // Get the path to that file 
     107                Path p = getPathToFile(menuItem); 
     108                // Display the contents of that file 
    80109                updateDisplay(p); 
    81110            } 
    82  
    83111        }); 
    84112    } 
     
    89117        view.setLineWrap(true); 
    90118        view.setWrapStyleWord(true); 
    91         // Initialize with first config file in list 
     119        // Initially display the first config file in list 
    92120        Path path = getPathToFile(selectMenu.getItemAt(0)); 
    93121        view.setText(getFileContent(path)); 
     
    104132        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    105133        frame.setSize(1050, 450); 
    106         ConfigStatusTab pnl = new ConfigStatusTab(); 
     134        ConfigStatusTab pnl = new ConfigStatusTab("config/cad_simulator_config.properties"); 
    107135        frame.add(pnl); 
    108136        frame.setVisible(true); 
     
    115143    @SuppressWarnings("unchecked") 
    116144    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 
    117     private void initComponents() 
    118     { 
     145    private void initComponents() { 
    119146 
    120147        selectMenu = new javax.swing.JComboBox<>(); 
     
    123150 
    124151        setLayout(new java.awt.BorderLayout()); 
    125  
    126         selectMenu.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "cad_simulator_config.properties", "cad_simulator_media_config.properties", "cad_simulator_paramics_config.properties", "cad_simulator_smoketest_config.properties", "traffic_model_config.properties" })); 
    127152        add(selectMenu, java.awt.BorderLayout.PAGE_START); 
    128153 
  • trunk/test/tmcsim/cadsimulator/CADSimulatorConsoleDriver.java

    r123 r455  
    8383        CADSimulatorFixture.pause(500); 
    8484 
    85         cadSimLogger.logp(Level.SEVERE, "Someclass", "Somemethod", "Something bad happened."); 
     85        cadSimLogger.logp(Level.SEVERE, "Someclass", "Somemethod", "Sample error message."); 
    8686 
    8787        // Load a script file 
  • trunk/test/tmcsim/cadsimulator/CADSimulatorConsoleTest.java

    r449 r455  
    189189                + ". = Console Info Message.\n" 
    190190                + "-- Error Messages --\n" 
    191                 + "Someclass.Somemethod = Something bad happened.\n"; 
     191                + "Someclass.Somemethod = Sample error message.\n"; 
    192192        System.out.println("Error msg"); 
    193193        cadSimLogger = Logger.getLogger("tmcsim.cadsimulator"); 
    194         cadSimLogger.logp(Level.SEVERE, "Someclass", "Somemethod", "Something bad happened."); 
     194        cadSimLogger.logp(Level.SEVERE, "Someclass", "Somemethod", "Sample error message."); 
    195195        verify("Error message output incorrect: ", expected7); 
    196196        String expected6 = 
     
    205205                + ". = Console Info Message.\n" 
    206206                + "-- Error Messages --\n" 
    207                 + "Someclass.Somemethod = Something bad happened.\n"; 
     207                + "Someclass.Somemethod = Sample error message.\n"; 
    208208        System.out.println("Paramics connect"); 
    209209        app.theCoordinator.setParamicsStatus(CADEnums.PARAMICS_STATUS.CONNECTED); 
     
    222222                + ". = Console Info Message.\n" 
    223223                + "-- Error Messages --\n" 
    224                 + "Someclass.Somemethod = Something bad happened.\n"; 
     224                + "Someclass.Somemethod = Sample error message.\n"; 
    225225        String expected9 = 
    226226                "--- CAD Simulator ---\n" 
     
    234234                + ". = Console Info Message.\n" 
    235235                + "-- Error Messages --\n" 
    236                 + "Someclass.Somemethod = Something bad happened.\n"; 
     236                + "Someclass.Somemethod = Sample error message.\n"; 
    237237        System.out.println("Sim status"); 
    238238        // Load a script file - to put status at Ready 
  • trunk/test/tmcsim/cadsimulator/viewer/CADConsoleViewerTest.java

    r123 r455  
    2828    { 
    2929        super.setUp(); 
    30         console = new CADConsoleViewer(); 
     30        console = new CADConsoleViewer("config/cad_simulator_config.properties"); 
    3131        cadmodel = new CADSimulatorState(); 
    3232        cadmodel.addObserver(console); 
     
    175175                + "-- Info Messages --\n\n" 
    176176                + "-- Error Messages --\n" 
    177                 + "Someclass.Somemethod = Something bad happened.\n"; 
     177                + "Someclass.Somemethod = Sample error message.\n"; 
    178178        Logger cadSimLogger = Logger.getLogger("tmcsim.cadsimulator"); 
    179         cadSimLogger.logp(Level.SEVERE, "Someclass", "Somemethod", "Something bad happened."); 
     179        cadSimLogger.logp(Level.SEVERE, "Someclass", "Somemethod", "Sample error message."); 
    180180        verify("Error message output incorrect: ", expected7); 
    181181    } 
  • trunk/test/tmcsim/cadsimulator/viewer/CADSimulatorViewModelTest.java

    r228 r455  
    3030    { 
    3131        super.setUp(); 
    32         viewer = new CADServerViewer(); 
     32        viewer = new CADServerViewer("config/cad_simulator_config.properties"); 
    3333        cadwindow = new Window(viewer); 
    3434        model = new CADSimulatorState(); 
Note: See TracChangeset for help on using the changeset viewer.