Example usage for javax.swing JFileChooser getCurrentDirectory

List of usage examples for javax.swing JFileChooser getCurrentDirectory

Introduction

In this page you can find the example usage for javax.swing JFileChooser getCurrentDirectory.

Prototype

public File getCurrentDirectory() 

Source Link

Document

Returns the current directory.

Usage

From source file:org.esa.snap.core.gpf.ui.OperatorMenu.java

private void preserveCurrentDirectory(JFileChooser fileChooser) {
    if (appContext != null) {
        String lastDir = fileChooser.getCurrentDirectory().getAbsolutePath();
        appContext.getPreferences().setPropertyString(lastDirPreferenceKey, lastDir);
    }/*w  w w  .j a v  a2 s  .  com*/
}

From source file:org.javaswift.cloudie.CloudiePanel.java

protected void onCreateStoredObject() {
    Container container = getSelectedContainer();
    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(true);
    chooser.setCurrentDirectory(lastFolder);
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File[] selectedFiles = chooser.getSelectedFiles();
        ops.createStoredObjects(container, selectedFiles, callback);
        lastFolder = chooser.getCurrentDirectory();
    }/*from   w  w w .  j a  v  a2s  . c o  m*/
}

From source file:org.parosproxy.paros.control.MenuFileControl.java

private void openFileBasedSession() {
    JFileChooser chooser = new JFileChooser(model.getOptionsParam().getUserDirectory());
    chooser.setFileHidingEnabled(false); // By default ZAP on linux puts timestamped sessions under a 'dot' directory 
    File file = null;/*from  ww w  .  j  av  a 2 s  .  c  om*/
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".session")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            // ZAP: Rebrand
            return Constant.messages.getString("file.format.zap.session");
        }
    });
    int rc = chooser.showOpenDialog(view.getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        try {
            file = chooser.getSelectedFile();
            if (file == null) {
                return;
            }
            model.getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
            log.info("opening session file " + file.getAbsolutePath());
            waitMessageDialog = view.getWaitMessageDialog(Constant.messages.getString("menu.file.loadSession"));
            control.openSession(file, this);
            waitMessageDialog.setVisible(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.parosproxy.paros.control.MenuFileControl.java

public void saveAsSession() {
    if (!informStopActiveActions()) {
        return;//  w w  w . j  ava  2s .c o  m
    }

    Session session = model.getSession();

    JFileChooser chooser = new JFileChooser(model.getOptionsParam().getUserDirectory());
    // ZAP: set session name as file name proposal
    File fileproposal = new File(session.getSessionName());
    if (session.getFileName() != null && session.getFileName().trim().length() > 0) {
        // if there is already a file name, use it
        fileproposal = new File(session.getFileName());
    }
    chooser.setSelectedFile(fileproposal);
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".session")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            // ZAP: Rebrand
            return Constant.messages.getString("file.format.zap.session");
        }
    });
    File file = null;
    int rc = chooser.showSaveDialog(view.getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return;
        }
        model.getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
        String fileName = file.getAbsolutePath();
        if (!fileName.endsWith(".session")) {
            fileName += ".session";
        }

        try {
            waitMessageDialog = view
                    .getWaitMessageDialog(Constant.messages.getString("menu.file.savingSession")); // ZAP: i18n
            control.saveSession(fileName, this);
            log.info("save as session file " + session.getFileName());
            waitMessageDialog.setVisible(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.parosproxy.paros.control.MenuFileControl.java

public void saveSnapshot() {
    String activeActions = wrapEntriesInLiTags(control.getExtensionLoader().getActiveActions());
    if (!activeActions.isEmpty()) {
        view.showMessageDialog(Constant.messages.getString("menu.file.snapshot.activeactions", activeActions));
        return;//from   ww w. java  2 s . c o  m
    }

    Session session = model.getSession();

    JFileChooser chooser = new JFileChooser(model.getOptionsParam().getUserDirectory());
    // ZAP: set session name as file name proposal
    File fileproposal = new File(session.getSessionName());
    if (session.getFileName() != null && session.getFileName().trim().length() > 0) {
        String proposedFileName;
        // if there is already a file name, use it and add a timestamp
        proposedFileName = StringUtils.removeEnd(session.getFileName(), ".session");
        proposedFileName += "-" + dateFormat.format(new Date()) + ".session";
        fileproposal = new File(proposedFileName);
    }
    chooser.setSelectedFile(fileproposal);
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".session")) {
                return true;
            }
            return false;
        }

        @Override
        public String getDescription() {
            return Constant.messages.getString("file.format.zap.session");
        }
    });
    File file = null;
    int rc = chooser.showSaveDialog(view.getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return;
        }
        model.getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
        String fileName = file.getAbsolutePath();
        if (!fileName.endsWith(".session")) {
            fileName += ".session";
        }

        try {
            waitMessageDialog = view
                    .getWaitMessageDialog(Constant.messages.getString("menu.file.savingSnapshot")); // ZAP: i18n
            control.snapshotSession(fileName, this);
            log.info("Snapshotting: " + session.getFileName() + " as " + fileName);
            waitMessageDialog.setVisible(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.parosproxy.paros.extension.history.PopupMenuExportMessage.java

private File getOutputFile() {

    JFileChooser chooser = new JFileChooser(extension.getModel().getOptionsParam().getUserDirectory());
    chooser.setFileFilter(new FileFilter() {
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            } else if (file.isFile() && file.getName().endsWith(".txt")) {
                return true;
            }//from www.  j  a  va  2  s  .c  o  m
            return false;
        }

        public String getDescription() {
            return "ASCII text file";
        }
    });
    File file = null;
    int rc = chooser.showSaveDialog(extension.getView().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return file;
        }
        extension.getModel().getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());
        String fileName = file.getAbsolutePath();
        if (!fileName.endsWith(".txt")) {
            fileName += ".txt";
            file = new File(fileName);
        }
        return file;

    }
    return file;
}

From source file:org.parosproxy.paros.extension.history.PopupMenuExportResponse.java

private File getOutputFile(HttpMessage msg) {

    String filename = "";
    try {//from  w w w. j  a  v a 2  s.  co m
        filename = msg.getRequestHeader().getURI().getPath();
        int pos = filename.lastIndexOf("/");
        filename = filename.substring(pos);
    } catch (Exception e) {
    }
    JFileChooser chooser = new JFileChooser(extension.getModel().getOptionsParam().getUserDirectory());
    if (filename.length() > 0) {
        chooser.setSelectedFile(new File(filename));
    }

    File file = null;
    int rc = chooser.showSaveDialog(extension.getView().getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return file;
        }

        extension.getModel().getOptionsParam().setUserDirectory(chooser.getCurrentDirectory());

        return file;

    }
    return file;
}

From source file:org.p_vcd.ui.VcdDialog.java

private void selectFileButton() {
    JFileChooser fc = new JFileChooser();
    fc.setMultiSelectionEnabled(false);// w w  w  . j  a  v  a2s. c  o  m
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setFileFilter(
            new FileNameExtensionFilter("images and videos", Parameters.get().getImageAndVideoExtensions()));
    File def = Parameters.get().getDefaultDir_QuerySelection();
    if (def != null)
        fc.setCurrentDirectory(def);
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        Parameters.get().updateDefaultDir_QuerySelection(fc.getCurrentDirectory());
        queryFile = fc.getSelectedFile();
        lbl_queryFile.setText(queryFile.getAbsolutePath());
        radio_queryFile.setSelected(true);
    }
}

From source file:org.tmpotter.ui.ActionHandler.java

/**
 * Save project as specified filename.//from  w  w w  . j  a  v  a 2  s .c  o m
 */
private void saveProjectAs() {
    File outFile = new File(modelMediator.getProjectName().concat(".tmpx"));
    try {
        boolean save = false;
        boolean cancel = false;
        while (!save && !cancel) {
            final JFileChooser fc = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("TMX File", "tmpx");
            fc.setFileFilter(filter);
            boolean nameOfUser = false;
            while (!nameOfUser) {
                fc.setLocation(230, 300);
                fc.setCurrentDirectory(RuntimePreferences.getUserHome());
                fc.setDialogTitle(getString("DLG.SAVEAS"));
                fc.setMultiSelectionEnabled(false);
                fc.setSelectedFile(outFile);
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                RuntimePreferences.setUserHome(fc.getCurrentDirectory());
                int returnVal;
                returnVal = fc.showSaveDialog(parent);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    outFile = fc.getSelectedFile();
                    if (!outFile.getName().endsWith(".tmpx")) {
                        outFile = new File(outFile.getName().concat(".tmpx"));
                    }
                    nameOfUser = true;
                } else {
                    nameOfUser = true;
                    cancel = true;
                }
            }
            int selected;
            if (nameOfUser && !cancel) {
                if (outFile.exists()) {
                    final Object[] options = { getString("BTN.SAVE"), getString("BTN.CANCEL") };
                    selected = JOptionPane.showOptionDialog(parent, getString("MSG.FILE_EXISTS"),
                            getString("MSG.WARNING"), JOptionPane.OK_CANCEL_OPTION,
                            JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                    if (selected == 0) {
                        save = true;
                    }
                } else {
                    save = true;
                }
            }
        }
        if (save) {
            cleanTmData();
            ProjectProperties prop = modelMediator.getProjectProperties();
            prop.setFilePathProject(outFile);
            TmxpWriter.writeTmxp(prop, tmData.getDocumentOriginal(), tmData.getDocumentTranslation());
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(parent, JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.tmpotter.ui.ActionHandler.java

/**
 * Action entry points.//from  w w w  . j av a2  s .co  m
 * <p>
 * All action entry points named with +ActionPerformed().
 */
public void onFileOpen() {
    final JFileChooser fc = new JFileChooser();
    File filePath = RuntimePreferences.getUserHome();
    fc.setCurrentDirectory(filePath);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Project File(.tmpx)", "tmpx");
    fc.setFileFilter(filter);
    fc.setMultiSelectionEnabled(false);
    final int returnVal = fc.showOpenDialog(parent);
    filePath = fc.getCurrentDirectory();
    RuntimePreferences.setUserHome(filePath);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        filePath = fc.getSelectedFile();

        if (filePath.getName().endsWith(".tmpx") && filePath.exists()) {
            try {
                final FileInputStream fr = new FileInputStream(filePath);
                fr.close();
                onOpenFile(filePath);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(parent, getString("MSG.ERROR.FILE_NOTFOUND"),
                        getString("MSG.ERROR"), JOptionPane.ERROR_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(parent, getString("MSG.ERROR.FILE_NOTFOUND"), getString("MSG.ERROR"),
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}