Example usage for javax.swing JFileChooser SAVE_DIALOG

List of usage examples for javax.swing JFileChooser SAVE_DIALOG

Introduction

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

Prototype

int SAVE_DIALOG

To view the source code for javax.swing JFileChooser SAVE_DIALOG.

Click Source Link

Document

Type value indicating that the JFileChooser supports a "Save" file operation.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.showDialog(new JFrame(""), null);
    File curFile = chooser.getSelectedFile();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    MyFileChooser chooser = new MyFileChooser();
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    final JDialog dialog = chooser.createDialog(null);
    chooser.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent evt) {
            JFileChooser chooser = (JFileChooser) evt.getSource();
            if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
                dialog.setVisible(false);
            } else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
                dialog.setVisible(false);
            }/*  w  w w.j a  va 2s . c om*/
        }
    });

    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            dialog.setVisible(false);
        }
    });

    dialog.setVisible(true);
}

From source file:com.decypher.threadsclient.JPanelChart.java

private String getFolder() {
    JFileChooser folderPick = new JFileChooser();
    folderPick.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    folderPick.setDialogType(JFileChooser.SAVE_DIALOG);
    folderPick.setMultiSelectionEnabled(false);
    String selected;//from   ww  w .jav  a 2s . c o  m
    int returnVal = folderPick.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        selected = folderPick.getSelectedFile().getPath();
    } else {
        selected = "";
    }
    return selected;
}

From source file:com.townsfolkdesigns.jfugue.JFuguePlugin.java

public static void saveMusicString(View view, String musicString) {
    //Macros.message(view, "Saving Music String - musicString: " + musicString);
    Buffer buffer = view.getBuffer();
    VFSFileChooserDialog fileChooser = new VFSFileChooserDialog(view, buffer.getPath(),
            JFileChooser.SAVE_DIALOG, false);
    String[] selectedFiles = fileChooser.getSelectedFiles();
    if (selectedFiles != null && selectedFiles.length > 0) {
        String filePath = selectedFiles[0];
        //Macros.message(view, "Saving Music String - filePath: " + filePath);
        if (!filePath.endsWith("mid")) {
            filePath += ".mid";
        }//w w  w .j  a  v a 2 s .com
        //Macros.message(view, "Saving Music String - filePath: " + filePath);
        File file = new File(filePath);
        Pattern pattern = new Pattern(musicString);
        Player player = JFuguePlayerFactory.createJFuguePlayer();
        try {
            player.saveMidi(pattern, file);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:de.ep3.ftpc.controller.portal.CrawlerDownloadController.java

@Override
public void mouseClicked(MouseEvent e) {
    CrawlerResultsItem.PreviewPanel previewPanel = (CrawlerResultsItem.PreviewPanel) e.getSource();
    CrawlerResult crawlerResult = previewPanel.getCrawlerResult();
    CrawlerFile crawlerFile = crawlerResult.getFile();

    FTPClient ftpClient = crawlerResult.getFtpClient();

    if (ftpClient.isConnected()) {
        JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadWhileConnected"), null,
                JOptionPane.ERROR_MESSAGE);
        return;// ww  w . ja va  2 s.c om
    }

    String fileExtension = crawlerFile.getExtension();

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter chooserFilter = new FileNameExtensionFilter(
            i18n.translate("fileType", fileExtension.toUpperCase()), crawlerFile.getExtension());

    chooser.setApproveButtonText(i18n.translate("buttonSave"));
    chooser.setDialogTitle(i18n.translate("fileDownloadTo"));
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setFileFilter(chooserFilter);
    chooser.setSelectedFile(new File(crawlerFile.getName()));

    int selection = chooser.showSaveDialog(portalFrame);

    if (selection == JFileChooser.APPROVE_OPTION) {
        File fileToSave = chooser.getSelectedFile();

        Server relatedServer = crawlerResult.getServer();

        try {
            ftpClient.connect(relatedServer.need("server.ip"),
                    Integer.parseInt(relatedServer.need("server.port")));

            int replyCode = ftpClient.getReplyCode();

            if (!FTPReply.isPositiveCompletion(replyCode)) {
                throw new IOException(i18n.translate("crawlerServerRefused"));
            }

            if (relatedServer.has("user.name")) {
                String userName = relatedServer.get("user.name");
                String userPassword = "";

                if (relatedServer.hasTemporary("user.password")) {
                    userPassword = relatedServer.getTemporary("user.password");
                }

                boolean loggedIn = ftpClient.login(userName, userPassword);

                if (!loggedIn) {
                    throw new IOException(i18n.translate("crawlerServerAuthFail"));
                }
            }

            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            /* Download file */

            InputStream is = ftpClient.retrieveFileStream(crawlerFile.getFullName());

            if (is != null) {

                byte[] rawFile = new byte[(int) crawlerFile.getSize()];

                int i = 0;

                while (true) {
                    int b = is.read();

                    if (b == -1) {
                        break;
                    }

                    rawFile[i] = (byte) b;
                    i++;

                    /* Occasionally update the download progress */

                    if (i % 1024 == 0) {
                        int progress = Math.round((((float) i) / crawlerFile.getSize()) * 100);

                        status.add(i18n.translate("crawlerDownloadProgress", progress));
                    }
                }

                is.close();
                is = null;

                if (!ftpClient.completePendingCommand()) {
                    throw new IOException();
                }

                Files.write(fileToSave.toPath(), rawFile);
            }

            /* Logout and disconnect */

            ftpClient.logout();

            tryDisconnect(ftpClient);

            status.add(i18n.translate("crawlerDownloadDone"));
        } catch (IOException ex) {
            tryDisconnect(ftpClient);

            JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadFailed", ex.getMessage()),
                    null, JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:grafix.principal.Comandos.java

static public void cmdSalvarConfiguracao() {
    ControleRegistro.alertaRegistro();/*  w  ww . j  av  a  2s .  c  o m*/
    JFileChooser chooser = new JFileChooser(new File(ConfiguracoesGrafix.PASTA_TEMPLATES));
    chooser.setSelectedFile(new File(ConfiguracoesGrafix.EXTENSAO_TEMPLATES));
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    int returnVal = chooser.showSaveDialog(Controle.getTela());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
            Controle.getConfiguracoesUsuario().setNome(file.getName());
            Controle.salvarConfiguracoesUsuario(true);
            LeitorArquivoConfiguracao.getInstance().criarCopia(file);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    Controle.getTela().getComboConfiguracoes().popularCombo();
}

From source file:net.sf.jabref.external.MoveFileAction.java

@Override
public void actionPerformed(ActionEvent event) {
    int selected = editor.getSelectedRow();

    if (selected == -1) {
        return;//from ww  w.  j  a va2s .c  om
    }

    FileListEntry entry = editor.getTableModel().getEntry(selected);

    // Check if the current file exists:
    String ln = entry.link;
    boolean httpLink = ln.toLowerCase(Locale.ENGLISH).startsWith("http");
    if (httpLink) {
        // TODO: notify that this operation cannot be done on remote links
        return;
    }

    // Get an absolute path representation:
    List<String> dirs = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory();
    int found = -1;
    for (int i = 0; i < dirs.size(); i++) {
        if (new File(dirs.get(i)).exists()) {
            found = i;
            break;
        }
    }
    if (found < 0) {
        JOptionPane.showMessageDialog(frame, Localization.lang("File_directory_is_not_set_or_does_not_exist!"),
                MOVE_RENAME, JOptionPane.ERROR_MESSAGE);
        return;
    }
    File file = new File(ln);
    if (!file.isAbsolute()) {
        file = FileUtil.expandFilename(ln, dirs).orElse(null);
    }
    if ((file != null) && file.exists()) {
        // Ok, we found the file. Now get a new name:
        String extension = null;
        if (entry.type.isPresent()) {
            extension = "." + entry.type.get().getExtension();
        }

        File newFile = null;
        boolean repeat = true;
        while (repeat) {
            repeat = false;
            String chosenFile;
            if (toFileDir) {
                // Determine which name to suggest:
                String suggName = FileUtil
                        .createFileNameFromPattern(eEditor.getDatabase(), eEditor.getEntry(),
                                Globals.journalAbbreviationLoader, Globals.prefs)
                        .concat(entry.type.isPresent() ? "." + entry.type.get().getExtension() : "");
                CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Move file to file directory?"),
                        Localization.lang("Rename to '%0'", suggName),
                        Globals.prefs.getBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR));
                int answer;
                // Only ask about renaming file if the file doesn't have the proper name already:
                if (suggName.equals(file.getName())) {
                    answer = JOptionPane.showConfirmDialog(frame,
                            Localization.lang("Move file to file directory?"), MOVE_RENAME,
                            JOptionPane.YES_NO_OPTION);
                } else {
                    answer = JOptionPane.showConfirmDialog(frame, cbm, MOVE_RENAME, JOptionPane.YES_NO_OPTION);
                }
                if (answer != JOptionPane.YES_OPTION) {
                    return;
                }
                Globals.prefs.putBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR, cbm.isSelected());
                StringBuilder sb = new StringBuilder(dirs.get(found));
                if (!dirs.get(found).endsWith(File.separator)) {
                    sb.append(File.separator);
                }
                if (cbm.isSelected()) {
                    // Rename:
                    sb.append(suggName);
                } else {
                    // Do not rename:
                    sb.append(file.getName());
                }
                chosenFile = sb.toString();
            } else {
                chosenFile = FileDialogs.getNewFile(frame, file, Collections.singletonList(extension),
                        JFileChooser.SAVE_DIALOG, false);
            }
            if (chosenFile == null) {
                return; // canceled
            }
            newFile = new File(chosenFile);
            // Check if the file already exists:
            if (newFile.exists() && (JOptionPane.showConfirmDialog(frame,
                    Localization.lang("'%0' exists. Overwrite file?", newFile.getName()), MOVE_RENAME,
                    JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION)) {
                if (toFileDir) {
                    return;
                } else {
                    repeat = true;
                }
            }
        }

        if (!newFile.equals(file)) {
            try {
                boolean success = file.renameTo(newFile);
                if (!success) {
                    success = FileUtil.copyFile(file, newFile, true);
                }
                if (success) {
                    // Remove the original file:
                    if (!file.delete()) {
                        LOGGER.info("Cannot delete original file");
                    }
                    // Relativise path, if possible.
                    String canPath = new File(dirs.get(found)).getCanonicalPath();
                    if (newFile.getCanonicalPath().startsWith(canPath)) {
                        if ((newFile.getCanonicalPath().length() > canPath.length()) && (newFile
                                .getCanonicalPath().charAt(canPath.length()) == File.separatorChar)) {

                            String newLink = newFile.getCanonicalPath().substring(1 + canPath.length());
                            editor.getTableModel().setEntry(selected,
                                    new FileListEntry(entry.description, newLink, entry.type));
                        } else {
                            String newLink = newFile.getCanonicalPath().substring(canPath.length());
                            editor.getTableModel().setEntry(selected,
                                    new FileListEntry(entry.description, newLink, entry.type));
                        }

                    } else {
                        String newLink = newFile.getCanonicalPath();
                        editor.getTableModel().setEntry(selected,
                                new FileListEntry(entry.description, newLink, entry.type));
                    }
                    eEditor.updateField(editor);
                    //JOptionPane.showMessageDialog(frame, Globals.lang("File moved"),
                    //        Globals.lang("Move/Rename file"), JOptionPane.INFORMATION_MESSAGE);
                    frame.output(Localization.lang("File moved"));
                } else {
                    JOptionPane.showMessageDialog(frame, Localization.lang("Move file failed"), MOVE_RENAME,
                            JOptionPane.ERROR_MESSAGE);
                }

            } catch (SecurityException | IOException ex) {
                LOGGER.warn("Could not move file", ex);
                JOptionPane.showMessageDialog(frame,
                        Localization.lang("Could not move file '%0'.", file.getAbsolutePath())
                                + ex.getMessage(),
                        MOVE_RENAME, JOptionPane.ERROR_MESSAGE);
            }

        }
    } else {
        // File doesn't exist, so we can't move it.
        JOptionPane.showMessageDialog(frame, Localization.lang("Could not find file '%0'.", entry.link),
                Localization.lang("File not found"), JOptionPane.ERROR_MESSAGE);
    }

}

From source file:net.sf.jabref.gui.preftabs.PreferencesDialog.java

public PreferencesDialog(JabRefFrame parent) {
    super(parent, Localization.lang("JabRef preferences"), false);
    JabRefPreferences prefs = JabRefPreferences.getInstance();
    frame = parent;//from w w  w  .  j av  a2 s.  c  om

    main = new JPanel();
    JPanel mainPanel = new JPanel();
    JPanel lower = new JPanel();

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(lower, BorderLayout.SOUTH);

    final CardLayout cardLayout = new CardLayout();
    main.setLayout(cardLayout);

    List<PrefsTab> tabs = new ArrayList<>();
    tabs.add(new GeneralTab(prefs));
    tabs.add(new NetworkTab(prefs));
    tabs.add(new FileTab(frame, prefs));
    tabs.add(new FileSortTab(prefs));
    tabs.add(new EntryEditorPrefsTab(frame, prefs));
    tabs.add(new GroupsPrefsTab(prefs));
    tabs.add(new AppearancePrefsTab(prefs));
    tabs.add(new ExternalTab(frame, this, prefs));
    tabs.add(new TablePrefsTab(prefs));
    tabs.add(new TableColumnsTab(prefs, parent));
    tabs.add(new LabelPatternPrefTab(prefs, parent.getCurrentBasePanel()));
    tabs.add(new PreviewPrefsTab(prefs));
    tabs.add(new NameFormatterTab(prefs));
    tabs.add(new ImportSettingsTab(prefs));
    tabs.add(new XmpPrefsTab(prefs));
    tabs.add(new AdvancedTab(prefs));

    // add all tabs
    tabs.forEach(tab -> main.add((Component) tab, tab.getTabName()));

    mainPanel.setBorder(BorderFactory.createEtchedBorder());

    String[] tabNames = tabs.stream().map(PrefsTab::getTabName).toArray(String[]::new);
    JList<String> chooser = new JList<>(tabNames);
    chooser.setBorder(BorderFactory.createEtchedBorder());
    // Set a prototype value to control the width of the list:
    chooser.setPrototypeCellValue("This should be wide enough");
    chooser.setSelectedIndex(0);
    chooser.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Add the selection listener that will show the correct panel when
    // selection changes:
    chooser.addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        String o = chooser.getSelectedValue();
        cardLayout.show(main, o);
    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new GridLayout(4, 1));
    buttons.add(importPreferences, 0);
    buttons.add(exportPreferences, 1);
    buttons.add(showPreferences, 2);
    buttons.add(resetPreferences, 3);

    JPanel westPanel = new JPanel();
    westPanel.setLayout(new BorderLayout());
    westPanel.add(chooser, BorderLayout.CENTER);
    westPanel.add(buttons, BorderLayout.SOUTH);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(main, BorderLayout.CENTER);
    mainPanel.add(westPanel, BorderLayout.WEST);

    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ok.addActionListener(new OkAction());
    CancelAction cancelAction = new CancelAction();
    cancel.addActionListener(cancelAction);
    lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(lower);
    buttonBarBuilder.addGlue();
    buttonBarBuilder.addButton(ok);
    buttonBarBuilder.addButton(cancel);
    buttonBarBuilder.addGlue();

    // Key bindings:
    KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction);

    // Import and export actions:
    exportPreferences.setToolTipText(Localization.lang("Export preferences to file"));
    exportPreferences.addActionListener(e -> {
        String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")),
                Collections.singletonList(".xml"), JFileChooser.SAVE_DIALOG, false);
        if (filename == null) {
            return;
        }
        File file = new File(filename);
        if (!file.exists() || (JOptionPane.showConfirmDialog(PreferencesDialog.this,
                Localization.lang("'%0' exists. Overwrite file?", file.getName()),
                Localization.lang("Export preferences"),
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)) {

            try {
                prefs.exportPreferences(filename);
            } catch (JabRefException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Export preferences"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    importPreferences.setToolTipText(Localization.lang("Import preferences from file"));
    importPreferences.addActionListener(e -> {
        String filename = FileDialogs.getNewFile(frame, new File(System.getProperty("user.home")),
                Collections.singletonList(".xml"), JFileChooser.OPEN_DIALOG, false);
        if (filename != null) {
            try {
                prefs.importPreferences(filename);
                updateAfterPreferenceChanges();
                JOptionPane.showMessageDialog(PreferencesDialog.this,
                        Localization.lang("You must restart JabRef for this to come into effect."),
                        Localization.lang("Import preferences"), JOptionPane.WARNING_MESSAGE);
            } catch (JabRefException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Import preferences"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    showPreferences.addActionListener(
            e -> new PreferencesFilterDialog(new JabRefPreferencesFilter(Globals.prefs), frame)
                    .setVisible(true));
    resetPreferences.addActionListener(e -> {
        if (JOptionPane.showConfirmDialog(PreferencesDialog.this,
                Localization.lang("Are you sure you want to reset all settings to default values?"),
                Localization.lang("Reset preferences"),
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            try {
                prefs.clear();
                JOptionPane.showMessageDialog(PreferencesDialog.this,
                        Localization.lang("You must restart JabRef for this to come into effect."),
                        Localization.lang("Reset preferences"), JOptionPane.WARNING_MESSAGE);
            } catch (BackingStoreException ex) {
                LOGGER.warn(ex.getMessage(), ex);
                JOptionPane.showMessageDialog(PreferencesDialog.this, ex.getLocalizedMessage(),
                        Localization.lang("Reset preferences"), JOptionPane.ERROR_MESSAGE);
            }
            updateAfterPreferenceChanges();
        }
    });

    setValues();

    pack();

}

From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java

private void createDataConversionRulesList() {
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(labels.getString("dateConversion.valueRead"));
    columnNames.add(labels.getString("dateConversion.valueConverted"));
    dm = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);
    dm.addRow(new Vector<String>());
    dm.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            if (ruleTable.getEditingRow() != ruleTable.getRowCount() - 1
                    && (StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                            && StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)))) {
                dm.removeRow(ruleTable.getEditingRow());
            }//  w  ww .jav a  2s .  c o m
            if (ruleTable.getEditingRow() == ruleTable.getRowCount() - 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                        && StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    dm.addRow(new Vector<String>());
                }
            }
            if (ruleTable.getEditingColumn() == 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))
                        && !isCorrectDateFormat((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    createOptionPaneForIsoDate(ruleTable.getEditingRow(), 1);
                }
            }
        }
    });

    ruleTable = new JTable(dm);
    oldModel = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);

    JButton saveButton = new JButton(labels.getString("saveBtn"));
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            for (int i = 0; i < data.size() - 1; i++) {
                Vector<String> vector = data.elementAt(i);
                if (vector.elementAt(1) != null && !isCorrectDateFormat((String) vector.elementAt(1))) {
                    createOptionPaneForIsoDate(i, 1);
                }
            }
            xmlFilehandler.saveDataToFile(data, FILENAME);
            saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                    new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
        }
    });

    JButton closeButton = new JButton(labels.getString("quit"));
    closeButton.addActionListener(new ActionListener() {
        // boolean cancel = true;

        public void actionPerformed(ActionEvent e) {
            /*System.out.println(Boolean.toString(oldModel.getRowCount() == (ruleTable.getModel().getRowCount() - 1)) + "<<" + oldModel.getRowCount() + ", " + (ruleTable.getModel().getRowCount() - 1));
            if (oldModel.getRowCount() != ruleTable.getModel().getRowCount() - 1) {
            cancel = showUnsavedChangesDialog();
            } else {
            for (int i = 0; i < (ruleTable.getModel().getRowCount() - 1); i++) {
                for (int j = 0; j <= 1; j++) {
                    System.out.println(oldModel.getValueAt(i, j) == ruleTable.getModel().getValueAt(i, j) + " >> " + oldModel.getValueAt(i, j) + ", " + ruleTable.getModel().getValueAt(i, j));
                    if (oldModel.getValueAt(i, j) != ruleTable.getModel().getValueAt(i, j)) {
                        cancel = showUnsavedChangesDialog();
                    }
                }
            }
            }
            if (cancel) {*/
            dispose();
            //  }
        }
    });

    JButton downloadButton = new JButton(labels.getString("downloadBtn"));
    downloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            File currentLocation = new File(retrieveFromDb.retrieveOpenLocation());
            JFileChooser fileChooser = new JFileChooser(currentLocation);
            fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
            fileChooser.setFileFilter(new FileNameExtensionFilter("XML file", "xml"));
            int returnedVal = fileChooser.showSaveDialog(getParent());

            if (returnedVal == JFileChooser.APPROVE_OPTION) {
                String fileName = fileChooser.getSelectedFile().toString();
                if (!fileName.endsWith(".xml")) {
                    fileName = fileName + ".xml";
                }
                xmlFilehandler.saveDataToFile(data, fileName);
                //additionally save data to standard file
                xmlFilehandler.saveDataToFile(data, FILENAME);
                saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                        new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
            }
        }
    });

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(new JScrollPane(ruleTable));
    saveMessage = new JLabel();
    contentPanel.add(saveMessage, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(saveButton);
    buttonPanel.add(closeButton);
    buttonPanel.add(downloadButton);

    JPanel pane = new JPanel(new BorderLayout());
    pane.add(contentPanel, BorderLayout.PAGE_START);
    pane.add(buttonPanel, BorderLayout.PAGE_END);
    add(pane);
}

From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java

public void install(JComponent parent, Window dialog) {

    final File installDirectory;
    switch (OSInfosDefault.INSTANCE.getOs()) {
    case OSX:/*from   w w w. j  av a2s. c o m*/
        System.setProperty("apple.awt.fileDialogForDirectories", "true");
        FileDialog d = new FileDialog(Frame.getFrames()[0], "Choose directory for installation of " + toolName,
                FileDialog.LOAD);
        d.setVisible(true);
        System.setProperty("apple.awt.fileDialogForDirectories", "false");
        if (d.getFile() != null) {
            installDirectory = new File(d.getDirectory(), d.getFile());
        } else {
            installDirectory = null;
        }
        break;
    default:
        final JFileChooser chooser = new JFileChooser();
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setDialogTitle("Choose directory for installation of " + toolName);
        chooser.setDialogType(JFileChooser.SAVE_DIALOG);
        chooser.setApproveButtonText("Install " + toolName + " here");
        int result = chooser.showDialog(parent, "Install " + toolName + " here");
        if (result == JFileChooser.APPROVE_OPTION) {
            installDirectory = chooser.getSelectedFile();
        } else {
            installDirectory = null;
        }
    }

    if (installDirectory != null) {
        try {
            final File tmp = File.createTempFile("keymaeraDownload", "." + ft.toString().toLowerCase());
            final FileInfo info = new FileInfo(url, tmp.getName(), false);
            final DownloadManager dlm = new DownloadManager();
            ProgressBarWindow pbw = new ProgressBarWindow(parent, installDirectory, tmp, ft, ps, dialog);
            dlm.addListener(pbw);
            Runnable down = new Runnable() {

                @Override
                public void run() {
                    dlm.downloadAll(new FileInfo[] { info }, 2000, tmp.getParentFile().getAbsolutePath(), true);
                }
            };
            Thread thread = new Thread(down);
            thread.start();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}