Changeset 158 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui


Ignore:
Timestamp:
11/22/2019 04:22:14 PM (6 years ago)
Author:
jdalbey
Message:

ScriptBuilderFrame?.java added new helper method loadCHPunits(). SimulationScript?.java changed load units method to accept an InputStream? instead of a File.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        11build 
        22dist 
         3deploy 
  • trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java

    r157 r158  
    1616import java.awt.event.WindowEvent; 
    1717import java.io.File; 
     18import java.io.FileInputStream; 
    1819import java.io.IOException; 
    1920import java.io.FileNotFoundException; 
     21import java.io.InputStream; 
    2022import java.net.URI; 
     23import java.net.URISyntaxException; 
     24import java.net.URL; 
    2125import java.util.Observable; 
    2226import java.util.Observer; 
    2327import java.util.Properties; 
    2428import java.util.Random; 
     29import java.util.Scanner; 
    2530import java.util.logging.Level; 
    2631import java.util.logging.Logger; 
     
    5257public class ScriptBuilderFrame extends javax.swing.JFrame implements Observer 
    5358{ 
    54  
     59    private final static String kUnitsFilename = "resources/units_template.xml"; 
    5560    /** 
    5661     * The script model. 
     
    156161        script.addObserver(this); 
    157162        initComponents(); 
     163        loadCHPunits(); 
    158164        addCustomListeners(); 
    159165        //add to listener helper method 
     
    179185 
    180186    } 
    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    } 
    182203    /** 
    183204     * Put all custom non-generated listeners in this method 
    184205     */ 
    185206    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 
    190210        //listener for window closing 
    191211        this.addWindowListener(new WindowAdapter(){ 
     
    22152235    {//GEN-HEADEREND:event_fileNewActionPerformed 
    22162236        script = new SimulationScript(); 
    2217         String fileName = "units.xml"; 
    2218         File f = new File(fileName); 
    2219         script.loadUnitsFromFile(f); 
     2237        loadCHPunits(); 
    22202238        script.update(); 
    22212239        this.update(null, script); 
     
    23952413        if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 
    23962414        { 
    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            } 
    23992431        } 
    24002432    }//GEN-LAST:event_loadUnitsActionPerformed 
  • trunk/src/scriptbuilder/gui/application.properties

    r155 r158  
    1 #Wed, 20 Nov 2019 16:03:11 -0800 
     1#Fri, 22 Nov 2019 17:54:32 -0800 
    22 
    3 Application.revision=154 
     3Application.revision=156 
    44 
    5 Application.buildnumber=43 
     5Application.buildnumber=52 
    66 
    77Incidents.directory=Incidents 
Note: See TracChangeset for help on using the changeset viewer.