Example usage for javax.swing JFileChooser getFileSystemView

List of usage examples for javax.swing JFileChooser getFileSystemView

Introduction

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

Prototype

public FileSystemView getFileSystemView() 

Source Link

Document

Returns the file system view.

Usage

From source file:se.cambio.cds.gdl.editor.controller.GDLEditor.java

public void saveCompiledGuideAsObject(byte[] compiledGuide, Guide guide) {
    GDLEditor controller = EditorManager.getActiveGDLEditor();
    String idGuide = controller.getIdGuide();
    if (idGuide == null) {
        idGuide = GDLEditorLanguageManager.getMessage("Guide");
    }//from   www .jav a  2 s .  co  m
    if (compiledGuide != null) {
        try {
            String guideSource = controller.serializeCurrentGuide();
            if (guideSource != null) {
                JFileChooser fileChooser = new JFileChooser();
                FileNameExtensionFilter filter = new FileNameExtensionFilter(
                        GDLEditorLanguageManager.getMessage("Guide"), new String[] { "guide" });
                fileChooser.setDialogTitle(GDLEditorLanguageManager.getMessage("SaveGuideAsObjectSD"));
                fileChooser.setFileFilter(filter);
                File file = new File(
                        fileChooser.getFileSystemView().getDefaultDirectory() + "/" + idGuide + ".guide");
                fileChooser.setSelectedFile(file);
                int result = fileChooser.showSaveDialog(EditorManager.getActiveEditorWindow());
                File guideFile = fileChooser.getSelectedFile();
                if (result != JFileChooser.CANCEL_OPTION) {
                    idGuide = guideFile.getName();
                    if (idGuide.endsWith(".guide")) {
                        idGuide = idGuide.substring(0, idGuide.length() - 6);
                    }
                    GuideDTO guideDTO = new GuideDTO(idGuide, guideSource, IOUtils.getBytes(guide),
                            compiledGuide, true, Calendar.getInstance().getTime());
                    ObjectOutputStream output = new ObjectOutputStream(
                            new BufferedOutputStream(new FileOutputStream(guideFile)));
                    try {
                        output.writeObject(guideDTO);
                    } catch (Exception e) {
                        ExceptionHandler.handle(e);
                    } finally {
                        output.close();
                    }
                }
            }
        } catch (Exception e) {
            ExceptionHandler.handle(e);
        }
    }
}

From source file:ui.FtpDialog.java

private void uploadFileBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadFileBtActionPerformed

    if (connected) {
        JFileChooser uploadFileChooser = new JFileChooser();
        uploadFileChooser.setPreferredSize(new Dimension(650, 450));

        File rootDirectory = new File("C:\\");

        uploadFileChooser// www . j a  v  a2s . c  o m
                .setCurrentDirectory(uploadFileChooser.getFileSystemView().getParentDirectory(rootDirectory));

        uploadFileChooser.setDialogTitle("File to upload");
        int result = uploadFileChooser.showOpenDialog(this);
        switch (result) {

        case JFileChooser.APPROVE_OPTION:
            selectedFile = uploadFileChooser.getSelectedFile();

            Trace.trc("File to upload: " + selectedFile.getName() + " File size: "
                    + FileUtils.byteCountToDisplaySize(selectedFile.length()));

            if (connected) {
                if (!selectedFile.equals(null)) {
                    try {
                        input = new FileInputStream(selectedFile);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    pb = new ProgressBar();
                    pb.execute();

                    uploadFileChooser.setVisible(false);

                } else {
                    JOptionPane.showMessageDialog(rootFrame, "No file to upload has been chosen!", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(rootFrame, "Not connected to a server, cannot upload file!",
                        "Error", JOptionPane.ERROR_MESSAGE);
            }
            break;

        case JFileChooser.CANCEL_OPTION:
            Trace.trc("Closing file chooser dialog");
            break;

        case JFileChooser.ERROR_OPTION:
            Trace.trc("An error occured");
            break;
        }

    } else {
        JOptionPane.showMessageDialog(rootFrame, "Not connected to a server, cannot upload file!", "Error",
                JOptionPane.ERROR_MESSAGE);
    }

}