- Timestamp:
- 11/22/2019 04:22:14 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
src/scriptbuilder/gui/ScriptBuilderFrame.java (modified) (6 diffs)
-
src/scriptbuilder/gui/application.properties (modified) (1 diff)
-
src/scriptbuilder/structures/SimulationScript.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 1 1 build 2 2 dist 3 deploy
-
- Property svn:ignore
-
trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java
r157 r158 16 16 import java.awt.event.WindowEvent; 17 17 import java.io.File; 18 import java.io.FileInputStream; 18 19 import java.io.IOException; 19 20 import java.io.FileNotFoundException; 21 import java.io.InputStream; 20 22 import java.net.URI; 23 import java.net.URISyntaxException; 24 import java.net.URL; 21 25 import java.util.Observable; 22 26 import java.util.Observer; 23 27 import java.util.Properties; 24 28 import java.util.Random; 29 import java.util.Scanner; 25 30 import java.util.logging.Level; 26 31 import java.util.logging.Logger; … … 52 57 public class ScriptBuilderFrame extends javax.swing.JFrame implements Observer 53 58 { 54 59 private final static String kUnitsFilename = "resources/units_template.xml"; 55 60 /** 56 61 * The script model. … … 156 161 script.addObserver(this); 157 162 initComponents(); 163 loadCHPunits(); 158 164 addCustomListeners(); 159 165 //add to listener helper method … … 179 185 180 186 } 181 187 /** Load the template file of standard CHP units into the script. 188 * These units generally appear before any script events. 189 */ 190 private void loadCHPunits() 191 { 192 // Read the file of CHP unit names 193 // This works within NetBeans or it can be run from the Jar file. 194 URL url = this.getClass().getResource("/"+kUnitsFilename); 195 InputStream inStream; 196 try { 197 inStream = url.openStream(); 198 script.loadUnitsFromFile(inStream); 199 } catch (IOException ex) { 200 Logger.getLogger(ScriptBuilderFrame.class.getName()).log(Level.SEVERE, null, ex); 201 } 202 } 182 203 /** 183 204 * Put all custom non-generated listeners in this method 184 205 */ 185 206 private void addCustomListeners(){ 186 187 String fileName = "src/resources/units_template.xml"; 188 File unitFile = new File(fileName); 189 script.loadUnitsFromFile(unitFile); 207 208 209 190 210 //listener for window closing 191 211 this.addWindowListener(new WindowAdapter(){ … … 2215 2235 {//GEN-HEADEREND:event_fileNewActionPerformed 2216 2236 script = new SimulationScript(); 2217 String fileName = "units.xml"; 2218 File f = new File(fileName); 2219 script.loadUnitsFromFile(f); 2237 loadCHPunits(); 2220 2238 script.update(); 2221 2239 this.update(null, script); … … 2395 2413 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 2396 2414 { 2397 //load script with values from the selected file 2398 script.loadUnitsFromFile(fc.getSelectedFile()); 2415 InputStream is = null; 2416 try { 2417 // create an input stream from the selected file 2418 File pf = fc.getSelectedFile(); 2419 is = new FileInputStream(pf); 2420 //load script with units from the selected file 2421 script.loadUnitsFromFile(is); 2422 } catch (FileNotFoundException ex) { 2423 Logger.getLogger(ScriptBuilderFrame.class.getName()).log(Level.SEVERE, null, ex); 2424 } finally { 2425 try { 2426 is.close(); 2427 } catch (IOException ex) { 2428 Logger.getLogger(ScriptBuilderFrame.class.getName()).log(Level.SEVERE, null, ex); 2429 } 2430 } 2399 2431 } 2400 2432 }//GEN-LAST:event_loadUnitsActionPerformed -
trunk/src/scriptbuilder/gui/application.properties
r155 r158 1 # Wed, 20 Nov 2019 16:03:11-08001 #Fri, 22 Nov 2019 17:54:32 -0800 2 2 3 Application.revision=15 43 Application.revision=156 4 4 5 Application.buildnumber= 435 Application.buildnumber=52 6 6 7 7 Incidents.directory=Incidents -
trunk/src/scriptbuilder/structures/SimulationScript.java
r155 r158 207 207 /** 208 208 * Load in an existing list of units from an XML file. 209 * @param fthe file containing the units210 */ 211 public void loadUnitsFromFile( File f){209 * @param inStream the input stream for the file containing the units 210 */ 211 public void loadUnitsFromFile(java.io.InputStream inStream){ 212 212 try 213 213 { 214 SAXParserFactory.newInstance().newSAXParser().parse( f, sh);214 SAXParserFactory.newInstance().newSAXParser().parse(inStream, sh); 215 215 units.addAll(sh.getUnits()); 216 216 }
Note: See TracChangeset
for help on using the changeset viewer.
