/** * Open the dialog to load an file, swing based * * @return the file or null */ @Override public File[] openDialog(final boolean multiple, final boolean folder, FileFilter filter) { // folder selector? if (folder) { return super.openDialog(multiple, folder, filter); } final FileDialog d = new FileDialog(new Frame(), "", FileDialog.LOAD); d.setVisible(true); if (d.getFile() != null) { File f = new File(d.getDirectory(), d.getFile()); // is typ ok? if (folder && !f.isDirectory()) { f = f.getParentFile(); } // file filter? if (filter != null && !filter.accept(f)) { TaskDialogs.inform( null, I18N.t("File {0} has wrong format", f.getName()), I18N.t( "Please select in the file dialog only a file, who match {0}. {1} doesn't do this.", filter.getDescription(), f.getAbsoluteFile())); } return new File[] {f}; } return new File[] {}; }
/** Opens a save dialog box when the user selects "Save As" from the menu. */ public void actionPerformed(ActionEvent e) { FileDialog chooser = new FileDialog(frame, "Use a .png or .jpg extension", FileDialog.SAVE); chooser.setVisible(true); if (chooser.getFile() != null) { save(chooser.getDirectory() + File.separator + chooser.getFile()); } }
public void loadROM() { FileDialog fileDialog = new FileDialog(this); fileDialog.setMode(FileDialog.LOAD); fileDialog.setTitle("Select a ROM to load"); // should open last folder used, and if that doesn't exist, the folder it's running in final String path = PrefsSingleton.get().get("filePath", System.getProperty("user.dir", "")); final File startDirectory = new File(path); if (startDirectory.isDirectory()) { fileDialog.setDirectory(path); } // and if the last path used doesn't exist don't set the directory at all // and hopefully the jFileChooser will open somewhere usable // on Windows it does - on Mac probably not. fileDialog.setFilenameFilter(new NESFileFilter()); boolean wasInFullScreen = false; if (inFullScreen) { wasInFullScreen = true; // load dialog won't show if we are in full screen, so this fixes for now. toggleFullScreen(); } fileDialog.setVisible(true); if (fileDialog.getFile() != null) { PrefsSingleton.get().put("filePath", fileDialog.getDirectory()); loadROM(fileDialog.getDirectory() + fileDialog.getFile()); } if (wasInFullScreen) { toggleFullScreen(); } }
private void getDiretorio() { try { FileDialog fileDialog = new FileDialog(Aplicativo.telaPrincipal, "Selecionar diretorio."); fileDialog.setFile("*.txt"); fileDialog.setVisible(true); if (fileDialog.getDirectory() != null) { if (EXPORTAR == rgModo.getVlrInteger()) { txtDiretorio.setVlrString(fileDialog.getDirectory() + fileDialog.getFile()); status.setString("Buscar produtos para exportação ..."); btBuscarProdutos.setEnabled(true); btBuscarProdutos.requestFocus(); } else if (IMPORTAR == rgModo.getVlrInteger()) { txtDiretorio.setVlrString(fileDialog.getDirectory() + fileDialog.getFile()); status.setString("Importar produtos do arquivo " + fileDialog.getFile() + " ..."); btImportar.setEnabled(true); btImportar.requestFocus(); } } else { txtDiretorio.setVlrString(""); btDirtorio.requestFocus(); } } catch (Exception e) { e.printStackTrace(); } }
private void getFluffImage() { // copied from structureTab FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD); fDialog.setDirectory( new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar); fDialog.setLocationRelativeTo(this); fDialog.setVisible(true); if (fDialog.getFile() != null) { String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath(); relativeFilePath = "." + File.separatorChar + relativeFilePath.substring( new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1); getAero().getFluff().setMMLImagePath(relativeFilePath); } refresh.refreshPreview(); return; }
public File showDirOpenDialog(Component parent, File defaultDir) { if (Platform.isMacOS()) { System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog dialog = null; if (parent instanceof JFrame == false && parent instanceof JDialog == false) { parent = ((JComponent) parent).getTopLevelAncestor(); } if (parent instanceof JFrame) dialog = new FileDialog((JFrame) parent); else dialog = new FileDialog((JDialog) parent); if (defaultDir != null) dialog.setDirectory(defaultDir.getAbsolutePath()); dialog.setVisible(true); if (dialog.getDirectory() == null || dialog.getFile() == null) return null; File file = new File(dialog.getDirectory(), dialog.getFile()); System.setProperty("apple.awt.fileDialogForDirectories", "false"); return file; } else { JFileChooser chooser = new JFileChooser(); if (defaultDir != null) chooser.setCurrentDirectory(defaultDir); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.showOpenDialog(parent); File file = chooser.getSelectedFile(); return file; } }
public static void midi(Score paramScore) { FileDialog localFileDialog = new FileDialog(new Frame(), "Save as a MIDI file ...", 1); localFileDialog.setFile("jMusic_composition.mid"); localFileDialog.show(); if (localFileDialog.getFile() != null) { midi(paramScore, localFileDialog.getDirectory() + localFileDialog.getFile()); } }
public void actionPerformed(ActionEvent e) { if (e.getActionCommand() == "Open") { // open버튼을 눌렀다면 fdOpen.setVisible(true); System.out.println(fdOpen.getDirectory() + fdOpen.getFile()); } else { // save버튼을 눌렀다면 fdSave.setVisible(true); System.out.println(fdSave.getDirectory() + fdSave.getFile()); } }
/** * Open the dialog to load an file, swing based * * @return the file or null */ @Override public File saveDialog() { final FileDialog d = new FileDialog(new Frame(), "", FileDialog.SAVE); d.setVisible(true); if (d.getFile() != null) { return new File(d.getDirectory(), d.getFile()); } return null; }
@Override public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals("add")) { MultipleInputDialog inputDialog = new MultipleInputDialog(); data.add(inputDialog.getDialogCar()); } else if (command.equals("save")) { try { FileDialog fd = new FileDialog(Layout.this, "Válasszon egy célmappát", FileDialog.SAVE); fd.setVisible(true); String dir = fd.getDirectory(); String filename = fd.getFile(); FileOutputStream fileOut = new FileOutputStream(dir + filename); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(Layout.this.data); out.close(); fileOut.close(); System.out.println("save OK"); System.out.println("Kiirva 1/1 adat " + data.get(1).getOne()); } catch (IOException i) { i.printStackTrace(); } } else if (command.equals("load")) { try { FileDialog fd = new FileDialog(Layout.this, "Válasszon egy célmappát", FileDialog.LOAD); fd.setVisible(true); String dir = fd.getDirectory(); String filename = fd.getFile(); FileInputStream fileIn = new FileInputStream(dir + filename); ObjectInputStream in = new ObjectInputStream(fileIn); Layout.this.data = (ArrayList<Car>) in.readObject(); dataTable.repaint(); fileIn.close(); in.close(); System.out.println("beolvasva"); repaint(); System.out.println("olvasva 1/1 adat data-ban " + data.get(1).getOne()); } catch (IOException i) { i.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (command.equals("browse")) { FileDialog jf = new FileDialog(Layout.this, "Choose something", FileDialog.LOAD); jf.setVisible(true); } }
/** This method cannot be called directly. */ @Override public void actionPerformed(ActionEvent e) { FileDialog chooser = new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE); chooser.setVisible(true); String filename = chooser.getFile(); if (filename != null) { StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile()); } }
public String rChooseFile(Rengine re, int newFile) { FileDialog fd = new FileDialog( f, (newFile == 0) ? "Select a file" : "Select a new file", (newFile == 0) ? FileDialog.LOAD : FileDialog.SAVE); fd.show(); String res = null; if (fd.getDirectory() != null) res = fd.getDirectory(); if (fd.getFile() != null) res = (res == null) ? fd.getFile() : (res + fd.getFile()); return res; }
/** * Handles 'Save As' for a build. * * <p>This basically just duplicates the current build to a new location, and then calls 'Save'. * (needs to take the current state of the open files and save them to the new folder.. but not * save over the old versions for the old sketch..) * * <p>Also removes the previously-generated .class and .jar files, because they can cause trouble. */ public boolean saveAs() throws IOException { // get new name for folder FileDialog fd = new FileDialog(new Frame(), "Save file as...", FileDialog.SAVE); // default to the folder that this file is in fd.setDirectory(folder.getCanonicalPath()); fd.setFile(mainFilename); fd.setVisible(true); String parentDir = fd.getDirectory(); String newName = fd.getFile(); // user cancelled selection if (newName == null) return false; File folder = new File(parentDir); // Find base name if (newName.toLowerCase().endsWith(".gcode")) newName = newName.substring(0, newName.length() - 6); if (newName.toLowerCase().endsWith(".ngc")) newName = newName.substring(0, newName.length() - 4); if (newName.toLowerCase().endsWith(".stl")) newName = newName.substring(0, newName.length() - 4); if (newName.toLowerCase().endsWith(".obj")) newName = newName.substring(0, newName.length() - 4); if (newName.toLowerCase().endsWith(".dae")) newName = newName.substring(0, newName.length() - 4); BuildCode code = getCode(); if (code != null) { // grab the contents of the current tab before saving // first get the contents of the editor text area if (hasMainWindow) { if (code.isModified()) { code.program = editor.getText(); } } File newFile = new File(folder, newName + ".gcode"); code.saveAs(newFile); } BuildModel model = getModel(); if (model != null) { File newFile = new File(folder, newName + ".stl"); model.saveAs(newFile); } this.name = newName; this.mainFilename = fd.getFile(); this.folder = folder; return true; }
/** * Чтение таблицы из файла * * @param e */ public void actionPerformed(ActionEvent e) { load.setVisible(true); String fileName = load.getDirectory() + load.getFile(); try { if (load.getFile() == null) { throw new NullFileException(); } Load load = new Load(); load.LoadXML(fileName, masters, records); } catch (NullFileException ex) { JOptionPane.showMessageDialog(carsList, ex.getMessage()); } load.setFile("*.xml"); }
// public static final String showElementTreeAction = "showElementTree"; // ------------------------------------------------------------- public void openFile(String currDirStr, String currFileStr) { if (fileDialog == null) { fileDialog = new FileDialog(this); } fileDialog.setMode(FileDialog.LOAD); if (!(currDirStr.equals(""))) { fileDialog.setDirectory(currDirStr); } if (!(currFileStr.equals(""))) { fileDialog.setFile(currFileStr); } fileDialog.show(); String file = fileDialog.getFile(); // cancel pushed if (file == null) { return; } String directory = fileDialog.getDirectory(); File f = new File(directory, file); if (f.exists()) { Document oldDoc = getEditor().getDocument(); if (oldDoc != null) // oldDoc.removeUndoableEditListener(undoHandler); /* if (elementTreePanel != null) { elementTreePanel.setEditor(null); } */ getEditor().setDocument(new PlainDocument()); fileDialog.setTitle(file); Thread loader = new FileLoader(f, editor1.getDocument()); loader.start(); } }
/** This is the action listener method that the menu items invoke */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equals("quit")) { YesNoDialog d = new YesNoDialog( this, "Really Quit?", "Are you sure you want to quit?", "Yes", "No", null); d.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("yes")) System.exit(0); else textarea.append("Quit not confirmed\n"); } }); d.show(); } else if (command.equals("open")) { FileDialog d = new FileDialog(this, "Open File", FileDialog.LOAD); d.show(); // display the dialog and block until answered textarea.append("You selected file: " + d.getFile() + "\n"); d.dispose(); } else if (command.equals("about")) { InfoDialog d = new InfoDialog( this, "About", "This demo was written by David Flanagan\n" + "Copyright (c) 1997 O'Reilly & Associates"); d.show(); } }
void openEffect() { FileDialog dialog = new FileDialog(editor, "Open Effect", FileDialog.LOAD); if (lastDir != null) dialog.setDirectory(lastDir); dialog.setVisible(true); final String file = dialog.getFile(); final String dir = dialog.getDirectory(); if (dir == null || file == null || file.trim().length() == 0) return; lastDir = dir; ParticleEffect effect = new ParticleEffect(); try { effect.loadEmitters(Gdx.files.absolute(new File(dir, file).getAbsolutePath())); editor.effect = effect; emitterTableModel.getDataVector().removeAllElements(); editor.particleData.clear(); } catch (Exception ex) { System.out.println("Error loading effect: " + new File(dir, file).getAbsolutePath()); ex.printStackTrace(); JOptionPane.showMessageDialog(editor, "Error opening effect."); return; } for (ParticleEmitter emitter : effect.getEmitters()) { emitter.setPosition( editor.worldCamera.viewportWidth / 2, editor.worldCamera.viewportHeight / 2); emitterTableModel.addRow(new Object[] {emitter.getName(), true}); } editIndex = 0; emitterTable.getSelectionModel().setSelectionInterval(editIndex, editIndex); editor.reloadRows(); }
public static Action[] ReadProtocolbyDialog(JFrame parent) { // ???? ???? ??????¥á? ???? FileDialog fileDialog = new FileDialog(parent, "Select protocol file", FileDialog.LOAD); fileDialog.setFile("*.txt"); fileDialog.setVisible(true); String dir = fileDialog.getDirectory(); String file = fileDialog.getFile(); String path = dir + file; if (dir == null) { Action[] action = new Action[1]; action[0] = new Action(); return action; } BufferedReader in = null; ArrayList<String> inData = new ArrayList<String>(); String tempData = null; // ????¥ê??? ??????? ?¬à? try { in = new BufferedReader(new InputStreamReader(new FileInputStream(path))); while ((tempData = in.readLine()) != null) { inData.add(tempData); } } catch (Exception e) { e.printStackTrace(); } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } // PCR Protocol ???????? ??? // ?? ????? ?? ????? %PCR%, %END% ?? ????? ??? String start = inData.get(0); String end = inData.get(inData.size() - 1); int actionCount = inData.size() - 2; Action[] actions = new Action[actionCount]; if (!start.contains("%PCR%")) return null; if (!end.contains("%END")) return null; for (int i = 1; i < inData.size() - 1; i++) { String[] datas = inData.get(i).split("\t{1,}| {1,}"); actions[i - 1] = new Action(file); int j = 0; for (String temp : datas) { actions[i - 1].set(j++, temp); } } if (actions[0].getLabel() != null) Save_RecentProtocol(path); return actions; }
@Override public void actionPerformed(ActionEvent e) { Frame f = new Frame(); FileDialog fileChooser = new FileDialog(f, "Load", FileDialog.LOAD); fileChooser.setVisible(true); File targetFile = new File(fileChooser.getDirectory() + fileChooser.getFile()); if (fileChooser.getDirectory() == null) { return; } if (!targetFile.exists() || !targetFile.isFile()) { JOptionPane.showMessageDialog(null, "File invalid", "Error", JOptionPane.ERROR_MESSAGE); return; } boolean loaded = false; ResultOpinionExtractor resultOpinionExtractor = new ResultOpinionExtractor(targetFile); try { loaded = resultOpinionExtractor.load(); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (loaded) { statisticView.setOpinionResult(resultOpinionExtractor); } }
// 浏览数据库日志文件按钮单击事件 protected void do_logBrowButton_actionPerformed(ActionEvent arg0) { java.awt.FileDialog fd = new FileDialog(this); fd.setVisible(true); String filePath = fd.getDirectory() + fd.getFile(); if (filePath.endsWith(".LDF")) { logTextField.setText(filePath); } }
@Override public void execute() throws Exception { FileDialog fd = new FileDialog((Frame) context.getStage().getNativeWindow()); fd.setMode(FileDialog.LOAD); fd.setTitle("Import Other Graphics File"); fd.setVisible(true); if (fd.getFile() != null) { File file = new File(fd.getDirectory(), fd.getFile()); u.p("opening a file" + file); try { load(file); context.main.recentFiles.add(file); } catch (Exception e) { e.printStackTrace(); } } }
/** * The implementation that the other methods delegate to. This provides the caller with all * available options for customizing the <tt>JFileChooser</tt> instance. If a <tt>FileDialog</tt> * is displayed instead of a <tt>JFileChooser</tt> (on OS X, for example), most or all of these * options have no effect. * * @param parent the <tt>Component</tt> that should be the dialog's parent * @param titleKey the key for the locale-specific string to use for the file dialog title * @param approveKey the key for the locale-specific string to use for the approve button text * @param directory the directory to open the dialog to * @param mode the "mode" to open the <tt>JFileChooser</tt> in from the <tt>JFileChooser</tt> * class, such as <tt>JFileChooser.DIRECTORIES_ONLY</tt> * @param option the option to look for in the return code, such as * <tt>JFileChooser.APPROVE_OPTION</tt> * @param allowMultiSelect true if the chooser allows multiple files to be chosen * @param filter the <tt>FileFilter</tt> instance for customizing the files that are displayed -- * if this is null, no filter is used * @return the selected <tt>File</tt> instance, or <tt>null</tt> if a file was not selected * correctly */ public static List<File> getInput( Component parent, String titleKey, String approveKey, File directory, int mode, int option, boolean allowMultiSelect, final FileFilter filter) { if (!OSUtils.isAnyMac()) { JFileChooser fileChooser = getDirectoryChooser(titleKey, approveKey, directory, mode, filter); fileChooser.setMultiSelectionEnabled(allowMultiSelect); try { if (fileChooser.showOpenDialog(parent) != option) return null; } catch (NullPointerException npe) { // ignore NPE. can't do anything with it ... return null; } if (allowMultiSelect) { File[] chosen = fileChooser.getSelectedFiles(); if (chosen.length > 0) setLastInputDirectory(chosen[0]); return Arrays.asList(chosen); } else { File chosen = fileChooser.getSelectedFile(); setLastInputDirectory(chosen); return Collections.singletonList(chosen); } } else { FileDialog dialog; if (mode == JFileChooser.DIRECTORIES_ONLY) dialog = MacUtils.getFolderDialog(); else dialog = new FileDialog(GUIMediator.getAppFrame(), ""); dialog.setTitle(I18n.tr(titleKey)); if (filter != null) { FilenameFilter f = new FilenameFilter() { public boolean accept(File dir, String name) { return filter.accept(new File(dir, name)); } }; dialog.setFilenameFilter(f); } dialog.setVisible(true); String dirStr = dialog.getDirectory(); String fileStr = dialog.getFile(); if ((dirStr == null) || (fileStr == null)) return null; setLastInputDirectory(new File(dirStr)); // if the filter didn't work, pretend that the person picked // nothing File f = new File(dirStr, fileStr); if (filter != null && !filter.accept(f)) return null; return Collections.singletonList(f); } }
public OpenFile() { b1.addActionListener( e -> { d1.setVisible(true); System.out.println(d1.getDirectory() + d1.getFile()); }); b2.addActionListener( e -> { d2.setVisible(true); System.out.println(d2.getDirectory() + d2.getFile()); }); f.add(b1); f.add(b2, BorderLayout.SOUTH); f.pack(); f.setVisible(true); }
/** * Handles 'Save As' for a sketch. * * <p>This basically just duplicates the current sketch folder to a new location, and then calls * 'Save'. (needs to take the current state of the open files and save them to the new folder.. * but not save over the old versions for the old sketch..) * * <p>Also removes the previously-generated .class and .jar files, because they can cause trouble. */ public boolean saveAs() throws IOException { // get new name for folder FileDialog fd = new FileDialog(editor, "Save file as...", FileDialog.SAVE); if (isReadOnly()) { // default to the sketchbook folder fd.setDirectory(Base.preferences.get("sketchbook.path", null)); } else { // default to the parent folder of where this was fd.setDirectory(folder.getParent()); } fd.setFile(folder.getName()); fd.setVisible(true); String newParentDir = fd.getDirectory(); String newName = fd.getFile(); File newFolder = new File(newParentDir); // user cancelled selection if (newName == null) return false; if (!newName.endsWith(".gcode")) newName = newName + ".gcode"; // grab the contents of the current tab before saving // first get the contents of the editor text area if (current.modified) { current.program = editor.getText(); } // save the other tabs to their new location for (int i = 1; i < codeCount; i++) { File newFile = new File(newFolder, code[i].file.getName()); code[i].saveAs(newFile); } // save the hidden code to its new location for (int i = 0; i < hiddenCount; i++) { File newFile = new File(newFolder, hidden[i].file.getName()); hidden[i].saveAs(newFile); } // save the main tab with its new name File newFile = new File(newFolder, newName); code[0].saveAs(newFile); editor.handleOpenUnchecked( newFile.getPath(), currentIndex, editor.textarea.getSelectionStart(), editor.textarea.getSelectionEnd(), editor.textarea.getScrollPosition()); // Name changed, rebuild the sketch menus // editor.sketchbook.rebuildMenusAsync(); // let MainWindow know that the save was successful return true; }
public File loadFile() { if (chooser == null) { FileDialog d = new FileDialog(parent, title, FileDialog.LOAD); d.setFilenameFilter(filenameFilter); d.setVisible(true); String path = d.getFile(); if (path == null) return null; return new File(d.getDirectory() + d.getFile()); } else { int rst = chooser.showOpenDialog(parent); if (rst != JFileChooser.APPROVE_OPTION) { return null; } return chooser.getSelectedFile(); } }
private boolean saveAs(String xml) { FileDialog chooser = new FileDialog(frmPuzzledicePuzzleEditor, "Save", FileDialog.SAVE); chooser.setVisible(true); if (chooser.getFile() != null) { try { File saveFile = new File(chooser.getDirectory(), chooser.getFile()); BufferedWriter writer = new BufferedWriter(new FileWriter(saveFile)); writer.write(xml); writer.close(); _openFile = saveFile; return true; } catch (IOException ioe) { ioe.printStackTrace(); return false; } } return false; }
protected void showFileChooser() { File p; FileDialog fDlg; String fDir, fFile; // , fPath; // int i; Component win; for (win = this; !(win instanceof Frame); ) { win = SwingUtilities.getWindowAncestor(win); if (win == null) return; } p = getPath(); switch (type & PathField.TYPE_BASICMASK) { case PathField.TYPE_INPUTFILE: fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.LOAD); break; case PathField.TYPE_OUTPUTFILE: fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.SAVE); break; case PathField.TYPE_FOLDER: fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.SAVE); // fDlg = new FolderDialog( (Frame) win, dlgTxt ); break; default: fDlg = null; assert false : (type & PathField.TYPE_BASICMASK); break; } if (p != null) { fDlg.setFile(p.getName()); fDlg.setDirectory(p.getParent()); } if (filter != null) { fDlg.setFilenameFilter(filter); } showDialog(fDlg); fDir = fDlg.getDirectory(); fFile = fDlg.getFile(); if (((type & PathField.TYPE_BASICMASK) != PathField.TYPE_FOLDER) && (fDir == null)) { fDir = ""; } if ((fFile != null) && (fDir != null)) { if ((type & PathField.TYPE_BASICMASK) == PathField.TYPE_FOLDER) { p = new File(fDir); } else { p = new File(fDir + fFile); } setPathAndDispatchEvent(p); } fDlg.dispose(); }
private static String chooseFileByFileDialog(Dialog parentDialog, String title, int mode) { FileDialog fileDialog = new FileDialog(parentDialog, title, mode); fileDialog.setVisible(true); String selectedFile = fileDialog.getFile(); if (selectedFile != null) { return fileDialog.getDirectory() + selectedFile; } else { return null; } }
/** 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); } } }
public File getDir() { if (chooser == null) { System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog d = new FileDialog(parent, title, FileDialog.SAVE); d.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); String path = d.getFile(); if (path == null) return null; return new File(d.getDirectory() + d.getFile()); } else { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int rst = chooser.showSaveDialog(parent); if (rst != JFileChooser.APPROVE_OPTION) { return null; } return chooser.getSelectedFile(); } }