Example #1
0
  /** Handle ActionEvents. */
  public void actionPerformed(ActionEvent e) {
    Component target = (Component) e.getSource();

    if (target == dirBttn) {
      JFileChooser chooser = new JFileChooser();

      // Gabe Boys: Changed form just dirs to files and dirs
      chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

      try {
        chooser.setCurrentDirectory(new File(dirTF.getText()));
      } catch (Exception ex) {
      }

      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        dirTF.setText(chooser.getSelectedFile().getAbsolutePath());

        // Gabe Boys : If the source is a file set the backupPath to the directory instead of the
        // file
        if (!chooser.getSelectedFile().isDirectory()) {
          backupTF.setText(chooser.getSelectedFile().getParentFile().getAbsolutePath() + "_BAK");
        } else {
          backupTF.setText(chooser.getSelectedFile().getAbsolutePath() + "_BAK");
        }
      }
    } else if (target == backupBttn) {
      JFileChooser chooser = new JFileChooser();
      chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

      try {
        chooser.setCurrentDirectory(new File(backupTF.getText()));
      } catch (Exception ex) {
      }

      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        backupTF.setText(chooser.getSelectedFile().getAbsolutePath());
      }
    } else if (target == optionMenuItem) {
      showOptionDialog();
    } else if (target == helpMenuItem) {
      showHelpDialog();
    } else if (target == runBttn) {
      boolean noExeceptionThrown = true;
      noExeceptionThrown = setDirectory();

      if (noExeceptionThrown == true) {
        if (!testSourceVsBackup()) {
          // Set backup
          convertSet.setBackupPath(new File(backupTF.getText()));

          noExeceptionThrown =
              (setTemplateFile((String) templateCh.getSelectedItem()) && noExeceptionThrown);

          if (noExeceptionThrown) (new ProgressGUI(converter)).setVisible(true);
        }
      }
    } else if (target == exitMenuItem) {
      converter.persistConverterSetting();
      quit();
    } else if (target == aboutMenuItem) {
      showAboutDialog();
    }
  }