/** * Constructs a new TranslatorComponent with the given filters of the source and destination * files. */ public TranslatorComponent(FileFilter sourceFilter, FileFilter destFilter) { this.sourceFilter = sourceFilter; this.destFilter = destFilter; init(); jbInit(); source.setName("Source"); destination.setName("Destination"); sourceFileChooser = new JFileChooser(); sourceFileChooser.setFileFilter(sourceFilter); destFileChooser = new JFileChooser(); destFileChooser.setFileFilter(destFilter); source.enableUserInput(); destination.disableUserInput(); }
// saves the destination file private void saveDest() { int returnVal = destFileChooser.showDialog(this, "Save Destination File"); if (returnVal == JFileChooser.APPROVE_OPTION) { if (destFileChooser.getSelectedFile().exists()) { Object[] options = {"Yes", "No", "Cancel"}; int pressedButtonValue = JOptionPane.showOptionDialog( (JFrame) this, "File exists. Replace it ?", "Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (pressedButtonValue != JOptionPane.YES_OPTION) return; } String fileName = destFileChooser.getSelectedFile().getAbsolutePath(); notifyHackTranslatorListeners(HackTranslatorEvent.SAVE_DEST, fileName); } }
// loads a source file private void loadSource() { int returnVal = sourceFileChooser.showDialog(this, "Load Source File"); if (returnVal == JFileChooser.APPROVE_OPTION) notifyHackTranslatorListeners( HackTranslatorEvent.SOURCE_LOAD, sourceFileChooser.getSelectedFile().getAbsolutePath()); }
public void setDestinationName(String name) { destFileChooser.setName(name); destFileChooser.setSelectedFile(new File(name)); }
public void setSourceName(String name) { sourceFileChooser.setName(name); sourceFileChooser.setSelectedFile(new File(name)); }
public void setWorkingDir(File file) { sourceFileChooser.setCurrentDirectory(file); destFileChooser.setCurrentDirectory(file); }