Java JFrame Parent AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory, final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter)

Here you can find the source of AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory, final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter)

Description

All Platform Save As

License

Apache License

Parameter

Parameter Description
parentFrame a parameter
dialogTitle a parameter
directory a parameter
fileExtension a parameter
fractionFileName a parameter
nonMacFileFilter a parameter

Declaration

public static File AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory,
        final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter) 

Method Source Code


//package com.java2s;
/*/* w ww.  java 2  s  . c o  m*/
 * Copyright 2006-2016 CIRDLES.org.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.Frame;
import java.io.File;
import javax.swing.JFileChooser;

import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;

public class Main {
    /**
     *
     * @param parentFrame
     * @param dialogTitle
     * @param directory
     * @param fileExtension
     * @param fractionFileName
     * @param nonMacFileFilter
     * @return
     */
    public static File AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory,
            final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter) {

        File selectedFile;

        JFileChooser fc = new JFileChooser();
        fc.setSelectedFile(new File(directory + File.separator + fractionFileName));
        fc.setFileFilter(nonMacFileFilter);
        fc.setDialogTitle(dialogTitle);

        // Show save dialog; this method does not return until the dialog is closed
        int result = fc.showSaveDialog(new Frame());
        if (result == JFileChooser.APPROVE_OPTION) {
            selectedFile = fc.getSelectedFile();
            // check for already exists
            int response = 0;
            if (selectedFile.exists()) {
                // Modal dialog with OK/cancel and a text field
                response = JOptionPane.showConfirmDialog(null,
                        new String[] { "The file exists.", "Do you want to replace it?" }, "Ambapo Warning",
                        JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                if (response == JOptionPane.NO_OPTION) {
                    selectedFile = null;
                }
            }
        } else {
            selectedFile = null;
        }

        return selectedFile;
    }
}

Related

  1. AllPlatformGetFile(String dialogTitle, File locationIn, final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect, JLayeredPane parentFrame)
  2. AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory, final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter)
  3. buildParentFrame(Object inp)
  4. centreOverFrame(JInternalFrame win, JInternalFrame parent)
  5. closeFrameWhenEscapePressed(final JRootPane panel, final ActionListener actListener)
  6. createExceptionDialog(Frame parent, String title, Throwable error)