Changeset 127 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui/IncidentPaletteFrame.java


Ignore:
Timestamp:
09/26/2017 01:44:55 PM (9 years ago)
Author:
bmcguffin
Message:

Location of incidents folder now settable in application.properties file.

if the program fails to locate the incidents folder, an error message is displayed to the user with suggestions for fixing the error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/gui/IncidentPaletteFrame.java

    r103 r127  
    99import java.io.File; 
    1010import java.io.FileFilter; 
     11import java.io.IOException; 
    1112import java.text.SimpleDateFormat; 
    1213import java.time.LocalDate; 
    1314import java.util.ArrayList; 
    1415import java.util.Date; 
     16import java.util.Properties; 
    1517import java.util.TimeZone; 
     18import java.util.logging.Level; 
     19import java.util.logging.Logger; 
     20import javax.swing.JOptionPane; 
    1621import javax.swing.JPanel; 
    1722import javax.swing.JScrollPane; 
     
    2631public class IncidentPaletteFrame extends javax.swing.JFrame 
    2732{ 
     33     
     34    private String incDir; 
    2835 
    2936    private SimulationScript script; 
     
    6269        initComponents(); 
    6370 
    64         incidentList = loadIncidentsFromFiles("Incidents"); 
     71        String propfilename = "/scriptbuilder/gui/application.properties"; 
     72        String propKey = "Incidents.directory"; 
     73        incDir = ""; 
     74        // Load the application properties (created by build.xml) 
     75        try 
     76        { 
     77            Properties props = new Properties(); 
     78            props.load(this.getClass().getResourceAsStream(propfilename)); 
     79            incDir = (String) props.get(propKey); 
     80        } 
     81        catch (IOException ex) 
     82        { 
     83            Logger.getLogger("scriptbuilder.gui").log(Level.SEVERE, 
     84                    "IncidentPaletteFrame.loadIncidentsFromFiles." 
     85                    + " IOError reading " + propfilename); 
     86        } 
     87 
     88        incidentList = loadIncidentsFromFiles(incDir); 
    6589 
    6690        refresh(); 
     
    81105        }); 
    82106 
     107        //If the folder isn't correct then just hand back an empty list 
     108        if (!folder.exists()) 
     109        { 
     110            JOptionPane.showMessageDialog(this,  
     111                    "Unable to locate folder of existing incidents.\n" 
     112                  + "Folder \""+incDir+"\" should have been included in the\n" 
     113                  + "ScriptBuilder.zip file you downloaded.\n" 
     114                  + "TO FIX: Close the ScriptBuilder program and run it from\n" 
     115                  + "the same directory where you opened the .zip file.\n\n" 
     116                  + "(If the problem persists, contact the developers.)", "Missing Folder: \""+incDir+"\"", JOptionPane.ERROR_MESSAGE); 
     117            return newList; 
     118        } 
     119         
    83120        incidentFiles = folder.listFiles(); 
    84121 
     
    211248        }); 
    212249 
    213         txtSearchFilter.setText("Search..."); 
     250        txtSearchFilter.addActionListener(new java.awt.event.ActionListener() 
     251        { 
     252            public void actionPerformed(java.awt.event.ActionEvent evt) 
     253            { 
     254                txtSearchFilterActionPerformed(evt); 
     255            } 
     256        }); 
    214257 
    215258        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 
     
    389432        this.dispose(); 
    390433    }//GEN-LAST:event_btnClosePaletteActionPerformed 
     434 
     435    private void txtSearchFilterActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_txtSearchFilterActionPerformed 
     436    {//GEN-HEADEREND:event_txtSearchFilterActionPerformed 
     437        // TODO add your handling code here: 
     438    }//GEN-LAST:event_txtSearchFilterActionPerformed 
    391439 
    392440 
Note: See TracChangeset for help on using the changeset viewer.