Beispiel #1
0
  /**
   * Used to initialize the componenets. Also called after every event that is required to update
   * other fields.
   */
  public void setup() {
    if (firstTime) {
      defaultDirBackupPath = convertSet.getBackupPath().getPath();
      defaultOneFileBackupPath = System.getProperty("user.dir");
      firstTime = false;
    }

    dirTF.setText(convertSet.getSourcePath().getPath());
    recursiveCheckBox.setSelected(converter.isRecurse());
    if (converter.isStaticVersioning()) {
      staticVersioningRadioButton.setSelected(true);
    } else {
      dynamicVersioningRadioButton.setSelected(true);
    }
    backupTF.setText(defaultDirBackupPath);
  }
Beispiel #2
0
  /**
   * Pop-up a Dialog if the source and backup fields are the same. Returns true if the source and
   * backup remain the same.
   */
  private boolean testSourceVsBackup() {
    if (dirTF.getText().equals(backupTF.getText())) {
      final String caption = ResourceHandler.getMessage("caption.warning");

      MessageFormat formatter =
          new MessageFormat(ResourceHandler.getMessage("warning_dialog.info"));
      final String info = formatter.format(new Object[] {backupTF.getText()});

      int n = JOptionPane.showConfirmDialog(this, info, caption, JOptionPane.WARNING_MESSAGE);

      if (n == JOptionPane.YES_OPTION) {
        backupTF.setText(backupTF.getText() + "_BAK");

        return false;
      } else if (n == JOptionPane.NO_OPTION) return true;
    }

    return false;
  }
Beispiel #3
0
  /** Returns false if Exception is thrown. */
  private boolean setDirectory() {
    String pathStr = dirTF.getText().trim();
    if (pathStr.equals("")) pathStr = System.getProperty("user.dir");
    try {
      File dirPath = new File(pathStr);
      if (!dirPath.isDirectory()) {
        if (!dirPath.exists()) {
          if (recursiveCheckBox.isSelected())
            throw new NotDirectoryException(dirPath.getAbsolutePath());
          else throw new NotFileException(dirPath.getAbsolutePath());
        } else {
          convertSet.setFile(dirPath);
          convertSet.setDestinationPath(dirPath.getParentFile());
        }
      } else {
        // Set the descriptors
        setMatchingFileNames();

        FlexFilter flexFilter = new FlexFilter();
        flexFilter.addDescriptors(descriptors);
        flexFilter.setFilesOnly(!recursiveCheckBox.isSelected());

        convertSet.setSourcePath(dirPath, flexFilter);
        convertSet.setDestinationPath(dirPath);
      }
    } catch (NotDirectoryException e1) {
      final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption1");

      MessageFormat formatter;
      String info_msg;
      if (pathStr.equals("")) {
        info_msg = ResourceHandler.getMessage("notdirectory_dialog.info5");
      } else {
        formatter = new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info0"));
        info_msg = formatter.format(new Object[] {pathStr});
      }
      final String info = info_msg;

      JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE);
      return false;
    } catch (NotFileException e2) {
      final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption0");

      MessageFormat formatter =
          new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info1"));
      final String info = formatter.format(new Object[] {pathStr});

      JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE);
      return false;
    }

    return true; // no exception thrown
  }
Beispiel #4
0
  /** Set the matching descriptors. */
  private void setMatchingFileNames() {
    StringTokenizer st = new StringTokenizer(matchingTF.getText(), ",");

    int numTokens = st.countTokens();

    if (numTokens == 0) {
      descriptors = new String[1];
      descriptors[0] = "*";
      return;
    }

    descriptors = new String[numTokens];

    int i = 0;
    while (st.hasMoreElements()) {
      descriptors[i++] = st.nextToken().trim();
    }
  }
Beispiel #5
0
  /** Add listeners to components. */
  private void addListeners() {
    dirBttn.addActionListener(this);
    backupBttn.addActionListener(this);
    runBttn.addActionListener(this);

    recursiveCheckBox.addItemListener(this);
    templateCh.addItemListener(this);

    dirTF.addActionListener(this);

    staticVersioningRadioButton.addItemListener(this);
    dynamicVersioningRadioButton.addItemListener(this);

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            quit();
          }
        });
  }
Beispiel #6
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();
    }
  }