List of usage examples for javax.swing JFileChooser getCurrentDirectory
public File getCurrentDirectory()
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java
/** * * @throws IOException/* w w w. j av a2s . com*/ */ private void createPdf(JFreeChart chart) throws IOException { // choose directory to save pdf file JFileChooser chooseDirectory = new JFileChooser(); chooseDirectory.setDialogTitle("Choose a directory to save the report"); chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooseDirectory.setSelectedFile(new File("chart rose plot" + ".pdf")); // in response to the button click, show open dialog int returnVal = chooseDirectory.showSaveDialog(angleDirectPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File directory = chooseDirectory.getCurrentDirectory(); PdfSwingWorker pdfSwingWorker = new PdfSwingWorker(directory, chooseDirectory.getSelectedFile().getName(), chart); pdfSwingWorker.execute(); } else { singleCellPreProcessingController.showMessage("Open command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JButton createCaptureButton() { JButton capture = new JButton("Capture"); capture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(currentDir); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new PngFileFilter()); int result = chooser.showSaveDialog(GraphViewerPanel.this); if (result == JFileChooser.APPROVE_OPTION) { currentDir = chooser.getCurrentDirectory(); String absolutePath = chooser.getSelectedFile().getAbsolutePath(); if (!absolutePath.endsWith(".png")) { absolutePath += ".png"; }/*from w ww . j a v a 2 s .c o m*/ try { vv.setDoubleBuffered(false); writeToImageFile(absolutePath); vv.setDoubleBuffered(true); } catch (AWTException e1) { e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } // captureToFile(absolutePath); // writeJPEGImage(absolutePath + ".JPEG"); // captureScreen(absolutePath); } } }); return capture; }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JButton createSaveButton() { JButton save = new JButton("Save"); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PersistentLayout pl = (PersistentLayout) vv.getGraphLayout(); try { JFileChooser chooser = new JFileChooser(currentDir); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new LayoutFileFilter()); int result = chooser.showSaveDialog(GraphViewerPanel.this); if (result == JFileChooser.APPROVE_OPTION) { currentDir = chooser.getCurrentDirectory(); String absolutePath = chooser.getSelectedFile().getAbsolutePath(); if (!absolutePath.endsWith(".layout")) { absolutePath += ".layout"; }//from w ww .j a va2 s .c o m pl.persist(absolutePath); } } catch (IOException e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(GraphViewerPanel.this, "Error saving layout: " + e1.getMessage()); } } }); return save; }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JButton createLoadButton() { JButton load = new JButton("Load"); load.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { PersistentLayout pl = (PersistentLayout) vv.getGraphLayout(); try { JFileChooser chooser = new JFileChooser(currentDir); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new LayoutFileFilter()); int result = chooser.showOpenDialog(GraphViewerPanel.this); if (result == JFileChooser.APPROVE_OPTION) { currentDir = chooser.getCurrentDirectory(); String absolutePath = chooser.getSelectedFile().getAbsolutePath(); if (!absolutePath.endsWith(".layout")) { absolutePath += ".layout"; }/*from ww w. java 2 s .c om*/ pl.restore(absolutePath); vv.repaint(); } } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(GraphViewerPanel.this, "Error restoring layout: " + e1.getMessage()); } } }); return load; }
From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java
/** * */// ww w .j a v a 2 s .c o m public void editConnection() { // Create a file chooser with the current directory set to the // application home JFileChooser fileDialog = new JFileChooser(PreferencesStore.get(PREF_CONNECTION_FILE_DIRECTORY, System.getProperty("sshtools.home", System.getProperty("user.home")))); fileDialog.setFileFilter(connectionFileFilter); // Show it int ret = fileDialog.showOpenDialog(this); // If we've approved the selection then process if (ret == fileDialog.APPROVE_OPTION) { PreferencesStore.put(PREF_CONNECTION_FILE_DIRECTORY, fileDialog.getCurrentDirectory().getAbsolutePath()); // Get the file File f = fileDialog.getSelectedFile(); // Load the profile SshToolsConnectionProfile p = new SshToolsConnectionProfile(); try { p.open(f); if (editConnection(p)) { saveConnection(false, f, p); } } catch (IOException ioe) { showErrorMessage(this, "Failed to load connection profile.", "Error", ioe); } } }
From source file:au.org.ala.delta.editor.DeltaEditor.java
public File selectFile(boolean open) { File selectedFile = null;/*w w w . j ava 2 s.c o m*/ JFileChooser chooser = new JFileChooser(); if (_lastDirectory != null) { chooser.setCurrentDirectory(_lastDirectory); } chooser.setFileFilter(new FileNameExtensionFilter("Delta Editor files *.dlt", DELTA_FILE_EXTENSION)); int dialogResult; if (open) { dialogResult = chooser.showOpenDialog(getMainFrame()); } else { dialogResult = chooser.showSaveDialog(getMainFrame()); } if (dialogResult == JFileChooser.APPROVE_OPTION) { selectedFile = chooser.getSelectedFile(); _lastDirectory = chooser.getCurrentDirectory(); } return selectedFile; }
From source file:gui.QTLResultsPanel.java
void saveTXT() { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(Prefs.gui_dir)); fc.setDialogTitle("Save QTL Results"); while (fc.showSaveDialog(MsgBox.frm) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // Make sure it has an appropriate extension if (!file.exists()) { if (file.getName().indexOf(".") == -1) { file = new File(file.getPath() + ".csv"); }//from w w w . ja v a 2 s . com } // Confirm overwrite if (file.exists()) { int response = MsgBox.yesnocan(file + " already exists.\nDo " + "you want to replace it?", 1); if (response == JOptionPane.NO_OPTION) { continue; } else if (response == JOptionPane.CANCEL_OPTION || response == JOptionPane.CLOSED_OPTION) { return; } } // Otherwise it's ok to save... Prefs.gui_dir = "" + fc.getCurrentDirectory(); saveTXTFile(file); return; } }
From source file:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java
private void exportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportButtonActionPerformed if (_key == null) { JOptionPane.showMessageDialog(null, "Please select the Session ID to export, using the drop down list", "Error", JOptionPane.ERROR_MESSAGE); return;//from w w w . jav a 2 s . c om } JFileChooser jfc = new JFileChooser(Preferences.getPreference("WebScarab.DefaultDirectory")); jfc.setDialogTitle("Select a directory to write the sessionids into"); int returnVal = jfc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File file = jfc.getSelectedFile(); try { _sa.exportIDSToCSV(_key, file); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, new String[] { "Error exporting session identifiers", ioe.getMessage() }, "Error", JOptionPane.ERROR_MESSAGE); } } File dir = jfc.getCurrentDirectory(); if (dir != null) Preferences.setPreference("WebScarab.DefaultDirectory", dir.getAbsolutePath()); }
From source file:de.juwimm.cms.content.panel.PanDocuments.java
private void upload(String prosa, Integer unit, Integer viewComponentId, Integer documentId) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JFileChooser fc = new JFileChooser(); int ff = fc.getChoosableFileFilters().length; FileFilter[] fft = fc.getChoosableFileFilters(); for (int i = 0; i < ff; i++) { fc.removeChoosableFileFilter(fft[i]); }//www. j ava 2s . c o m fc.addChoosableFileFilter(new DocumentFilter()); fc.setAccessory(new ImagePreview(fc)); fc.setDialogTitle(prosa); fc.setMultiSelectionEnabled(true); fc.setCurrentDirectory(Constants.LAST_LOCAL_UPLOAD_DIR); int returnVal = fc.showDialog(this, Messages.getString("panel.content.documents.addDocument")); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fc.getSelectedFiles(); uploadFiles(files, unit, viewComponentId, documentId); Constants.LAST_LOCAL_UPLOAD_DIR = fc.getCurrentDirectory(); } this.setCursor(Cursor.getDefaultCursor()); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ImageFrame.java
protected File askUserForImageFile() { ImageFilter imageFilter = new ImageFilter(); JFileChooser fileChooser = new JFileChooser( WorkbenchTask.getDefaultDirPath(WorkbenchTask.IMAGES_FILE_PATH)); fileChooser.setFileFilter(imageFilter); fileChooser.setDialogTitle(getResourceString("WB_CHOOSE_IMAGE")); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int userAction = fileChooser.showOpenDialog(this); AppPreferences localPrefs = AppPreferences.getLocalPrefs(); // remember the directory the user was last in localPrefs.put(WorkbenchTask.IMAGES_FILE_PATH, fileChooser.getCurrentDirectory().getAbsolutePath()); if (userAction == JFileChooser.APPROVE_OPTION) { String fullPath = fileChooser.getSelectedFile().getAbsolutePath(); if (imageFilter.isImageFile(fullPath)) { return fileChooser.getSelectedFile(); }/* w w w . j a v a 2 s . c om*/ } // if for any reason (user cancelled) we got to this point... return null; }