// called when the load script button is pressed. private void scriptPressed() { int returnVal = fileChooser.showDialog(this, "Load Script"); if (returnVal == JFileChooser.APPROVE_OPTION) { notifyControllerListeners( ControllerEvent.SCRIPT_CHANGE, fileChooser.getSelectedFile().getAbsoluteFile()); scriptComponent.setContents(fileChooser.getSelectedFile().getAbsolutePath()); } }
// ask user for script file and name of new profile // return false if user cancelled operation private boolean getNewWkldInput( JFileChooser chooser, Object[] optionDlgMsg, StringBuffer name, StringBuffer scriptFile) { // let user select script file with queries boolean fileOk = false; int retval; File file = null; FileReader reader = null; while (!fileOk) { if ((retval = chooser.showDialog(this, "Ok")) != 0) { return false; } file = chooser.getSelectedFile(); try { reader = new FileReader(file.getPath()); fileOk = true; scriptFile.append(file.getPath()); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog( this, "Selected script file does not exist", "Error: New Profile", JOptionPane.ERROR_MESSAGE); } } // let user select filename for profile int response = JOptionPane.showOptionDialog( this, optionDlgMsg, "New Profile", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (response != JOptionPane.OK_OPTION) { return false; } JTextField textFld = (JTextField) optionDlgMsg[1]; name.append(file.getParent() + "/" + textFld.getText()); return true; }
/** * Show the selector for selecting the default folder. * * @return true if the user selected a default folder and false if not. */ protected boolean showDefaultFolderSelector() throws Exception { final JFileChooser selector = new JFileChooser(_activeFileChooser.getCurrentDirectory()); selector.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); final String title = (_subfolderName == null) ? "Default Folder" : "Default Parent Folder of " + _subfolderName; selector.setDialogTitle(title); final int status = selector.showDialog(_view, "Make Default"); switch (status) { case JFileChooser.APPROVE_OPTION: final File defaultFolder = selector.getSelectedFile(); if (defaultFolder != null) { _folderTracker.cacheURL(defaultFolder.toURI().toURL()); return true; } else { return false; } default: return false; } }