Changeset 455 in tmcsimulator for trunk/src/tmcsim/cadsimulator/viewer/ConfigStatusTab.java
- Timestamp:
- 07/18/2019 08:20:12 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/cadsimulator/viewer/ConfigStatusTab.java
r231 r455 7 7 import java.io.FileInputStream; 8 8 import java.io.FileNotFoundException; 9 import java.io.IOException; 9 10 import java.nio.file.FileSystems; 10 11 import java.nio.file.Path; 12 import java.util.Properties; 11 13 import java.util.Scanner; 14 import java.util.logging.Level; 15 import java.util.logging.Logger; 12 16 import javax.swing.JComboBox; 13 17 import javax.swing.JFrame; … … 16 20 /** 17 21 * ConfigStatusPanel displays the content of configuration files. 22 * A ComboBox allows the user to select from a list of current properties files. 18 23 * 19 24 * @author Drew Miller … … 22 27 public class ConfigStatusTab extends javax.swing.JPanel 23 28 { 24 /** Root config directory name */ 25 private String configDir; 26 29 /** 30 * Properties file for the CAD Server. 31 */ 32 private Properties cadServerProperties; 33 27 34 /** 28 35 * Creates new form 29 36 */ 30 public ConfigStatusTab( )37 public ConfigStatusTab(String propertiesFile) 31 38 { 32 39 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(); 39 42 setupTextView(); 40 43 } 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 } 41 66 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 */ 42 73 private String getFileContent(Path pathToFile) 43 74 { … … 54 85 return "Error: config file not found."; 55 86 } 56 57 87 } 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 */ 65 89 private void updateDisplay(Path pathToFileName) 66 90 { … … 69 93 } 70 94 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() 73 97 { 74 98 selectMenu.addActionListener(new ActionListener() … … 76 100 public void actionPerformed(ActionEvent e) 77 101 { 102 // Find which menu item was clicked 78 103 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 80 109 updateDisplay(p); 81 110 } 82 83 111 }); 84 112 } … … 89 117 view.setLineWrap(true); 90 118 view.setWrapStyleWord(true); 91 // Initial ize withfirst config file in list119 // Initially display the first config file in list 92 120 Path path = getPathToFile(selectMenu.getItemAt(0)); 93 121 view.setText(getFileContent(path)); … … 104 132 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 105 133 frame.setSize(1050, 450); 106 ConfigStatusTab pnl = new ConfigStatusTab( );134 ConfigStatusTab pnl = new ConfigStatusTab("config/cad_simulator_config.properties"); 107 135 frame.add(pnl); 108 136 frame.setVisible(true); … … 115 143 @SuppressWarnings("unchecked") 116 144 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 117 private void initComponents() 118 { 145 private void initComponents() { 119 146 120 147 selectMenu = new javax.swing.JComboBox<>(); … … 123 150 124 151 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" }));127 152 add(selectMenu, java.awt.BorderLayout.PAGE_START); 128 153
Note: See TracChangeset
for help on using the changeset viewer.
