/** Set the template file path. */ private boolean setTemplateFile(String pathStr) { File templateFile = new File(templateCh.getSelectedPath(pathStr)); if (!templateFile.getName().toLowerCase().endsWith(".tpl")) { final String templateCaption = ResourceHandler.getMessage("nottemplatefile_dialog.caption"); MessageFormat formatter = new MessageFormat(ResourceHandler.getMessage("nottemplatefile_dialog.info0")); final String errorMessage = formatter.format(new Object[] {templateFile.getName()}); String defaultTemplateName = PluginConverter.getDefaultTemplateFileName(); JOptionPane.showMessageDialog(this, errorMessage, templateCaption, JOptionPane.ERROR_MESSAGE); templateCh.select(templateCh.getPreviousSelection()); return false; } try { converter.setTemplateFilePath(templateCh.getSelectedPath(pathStr)); } catch (FileNotFoundException e) { // TO-DO: found it, but it's not a file. // TO-DO: Throw up a Dialog -- "Not a valid file, resetting to default file" final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption0"); MessageFormat formatter; String info_msg; if (pathStr.equals("")) { info_msg = ResourceHandler.getMessage("notdirectory_dialog.info5"); } else { formatter = new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info1")); info_msg = formatter.format(new Object[] {pathStr}); } final String info = info_msg; JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE); return false; } return true; }
/** 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(); } }); }
/** Handle ItemEvents. */ public void itemStateChanged(ItemEvent e) { final String dialog_title = ResourceHandler.getMessage("template_dialog.title"); Component target = (Component) e.getSource(); if (target == recursiveCheckBox) { converter.setRecurse(recursiveCheckBox.isSelected()); } else if (target == staticVersioningRadioButton || target == dynamicVersioningRadioButton) { converter.setStaticVersioning(staticVersioningRadioButton.isSelected()); } else if (target == templateCh && (e.getStateChange() == e.SELECTED)) { // Process only when item is Selected // Get the current template selection String choiceStr = (String) templateCh.getSelectedItem(); // If the user chooses 'other', display a file dialog to allow // them to select a template file. if (choiceStr.equals(TemplateFileChoice.OTHER_STR)) { String templatePath = null; FileDialog fd = new FileDialog(this, dialog_title, FileDialog.LOAD); fd.show(); // Capture the path entered, if any. if (fd.getDirectory() != null && fd.getFile() != null) { templatePath = fd.getDirectory() + fd.getFile(); } // If the template file is valid add it and select it. if (templatePath != null && setTemplateFile(templatePath)) { if (!templateCh.testIfInList(templatePath)) { templateCh.addItem(templatePath); } templateCh.select(templatePath); } else { templateCh.select(templateCh.getPreviousSelection()); } fd.dispose(); } else { templateCh.select(choiceStr); } } }
/** 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(); } }