@SuppressWarnings("unchecked")
  private void setInputFile() {
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      kwa.createProgressBar();
      params = new ParameterSet(); // Resets all parameters 
      // TODO Reset the GUI to match the newly reset parameters
      params.inputFile = fileChooser.getSelectedFile();
      inputFilenameText.setText(params.inputFile.getAbsolutePath());
 
      //Set the output file by default to the same as the input file (can be changed)
      int extensionIndex = params.inputFile.getAbsolutePath().lastIndexOf(".");
      if (extensionIndex == 0) {
        extensionIndex = params.inputFile.getAbsolutePath().length();
      }
      outputFilenameText.setText(params.inputFile.getAbsolutePath().substring(0, extensionIndex)
                                 + " map" + ".kml");
      params.outputFile = new File(outputFilenameText.getText());

      lfr = new ListFileReader(params.inputFile, params);
      kwa.setProgressBar(50);

      /* Clear out the existing items in all of the dropdown boxes (will be the defaults
       * if this is the first time the user is choosing an inputfile*/
      latField.removeAllItems();
      longField.removeAllItems();
      labelField.removeAllItems();
      nameField.removeAllItems();
      sizeField.removeAllItems();
      colorField.removeAllItems();
      startDateField.removeAllItems();
      endDateField.removeAllItems();

      // Populate all of the dropdown boxes with the list of column headers of the inputfile 
      for (String item : params.inputHeaders) {
        latField.addItem(item);
        longField.addItem(item);
        labelField.addItem(item);
        nameField.addItem(item);
        sizeField.addItem(item);
        colorField.addItem(item);
        startDateField.addItem(item);
        endDateField.addItem(item);
      }
      // Add a final item to size and color dropdown boxes: instances
      sizeField.addItem("Instances");
      colorField.addItem("Instances");

      /* Sets the dropdown boxes to a guess at the right default values based on column header
       *names*/ 
      latField.setSelectedIndex(lfr.latC);
      longField.setSelectedIndex(lfr.longC);
      labelField.setSelectedIndex(lfr.labelC);
      nameField.setSelectedIndex(lfr.nameC);
      sizeField.setSelectedIndex(lfr.sizeC);
      colorField.setSelectedIndex(lfr.colorC);
      if(lfr.hasEpiWeek){
        System.out.println("thar be epi-weeks, matey");
        startDateField.setSelectedIndex(lfr.epiWeekC);
        params.hasEpiWeek = true;
        params.inputEpiWeekC = lfr.epiWeekC;
        this.daysPerEventModel.setValue(7);
      }else{
        startDateField.setSelectedIndex(lfr.startDateC);
      }
      
      // Enables some of the greyed-out stuff in the GUI now that there's an inputfile
      outputFilenameChooserButton.setEnabled(true);
      outputFilenameText.setEnabled(true);
      identifyLatAndLongColumns.setEnabled(true);
      latL.setEnabled(true);
      longL.setEnabled(true);
      latField.setEnabled(true);
      longField.setEnabled(true);
      labelL.setEnabled(true);
      labelField.setEnabled(true);
      defaultIconSizeL.setEnabled(true);
      defaultIconSizeSp.setEnabled(true);
      variableIconSizeCB.setEnabled(true);
      variableIconColorCB.setEnabled(true);
      defaultIconColorChooserButton.setEnabled(true);
      //legendCB.setEnabled(true);
      animateCB.setEnabled(true);
      labelColorChooserButton.setEnabled(true);
      labelCB.setEnabled(true);
      labelSizeL.setEnabled(true);
      labelSizeSp.setEnabled(true);
      gazetteerExistsCB.setEnabled(true);
      nameField.setEnabled(true);
      previewButton.setEnabled(true);
      iconFilenameChooserButton.setEnabled(true);
      iconFilenameText.setEnabled(true);
      createKmlButton.setEnabled(true);
      createKmzButton.setEnabled(true);
 
      params.inputStartDateC = startDateField.getSelectedIndex();
      
      /* Check to see if lat and long columns are set; will have happened
       * automatically if there are columns named appropriately for lat and long.
       * Don't know if this is necessary now...*/
      // TODO use booleans instead of this clumsy check
      if((lfr.latC>0 || lfr.longC>0) && lfr.latC != lfr.longC){
        params.longColumnExists = true;
        params.latColumnExists = true;
        System.out.println("found lat and long columns");
      }else{
        params.longColumnExists = false;
        params.latColumnExists = false;
        System.out.println("didn't find lat and long columns");
        }
      if(params.gazetteerExists){
        GazetteerFileLinker gzf = new GazetteerFileLinker(params);
        gzf.link();
        if(gzf.orphanList.length() > 0){
          kwa.createReportPopupWithTextField(gzf.orphanList);
        }
      }else{
        params.dataSetLinked = false;
      }
      refreshDisplayPanel();

      // Pretty cheesy, but keeps the progress bar visible until input file choice dealt with.
      // A better system would have this bar updating as the ListFileReader churns through the 
      // input file. 
      kwa.setProgressBar(100);
      kwa.destroyProgressBar();
    } else {
      System.out.println("Open command cancelled by user.");
    }
  }