Java Code Examples for java.awt.FileDialog#SAVE

The following examples show how to use java.awt.FileDialog#SAVE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GtkFileDialogPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 2
Source File: GtkFileDialogPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 3
Source File: GtkFileDialogPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 4
Source File: GtkFileDialogPeer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    GtkFileDialogPeer.this.run(fd.getTitle(), fd.getMode(), dirname,
                               filename, fd.getFilenameFilter(),
                               fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 5
Source File: GtkFileDialogPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 6
Source File: Picture.java    From java_jail with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Opens a save dialog box when the user selects "Save As" from the menu.
 */
public void actionPerformed(ActionEvent e) {
    FileDialog chooser = new FileDialog(frame,
                         "Use a .png or .jpg extension", FileDialog.SAVE);
    chooser.setVisible(true);
    if (chooser.getFile() != null) {
        save(chooser.getDirectory() + File.separator + chooser.getFile());
    }
}
 
Example 7
Source File: Notate.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dialog to save score as a jMusic serialized jm file.
 */
public void saveJM() {
    FileDialog fd = new FileDialog(this, "Save as a jm file...",FileDialog.SAVE);
            fd.show();
                        
    //write a MIDI file to disk
    if ( fd.getFile() != null) {
        Write.jm(score, fd.getDirectory()+fd.getFile());
    }
}
 
Example 8
Source File: Ted.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void doSaveAs () {
    FileDialog fileDialog = new FileDialog (this, "Save As...", FileDialog.SAVE);
    fileDialog.show ();
    if (fileDialog.getFile () == null)
        return;
    fileName = fileDialog.getDirectory () + File.separator + fileDialog.getFile ();

    doSave (fileName);
}
 
Example 9
Source File: FilesIO.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void saveAsFile(String filePathFull, String fileName) {
	try {
		File f=new File(filePathFull);
		if(f.exists()){
			if (filePathFull == null || filePathFull.trim().length() == 0)
				return;

			FileDialog fd = new FileDialog(new Frame(), "文件另存为",
					FileDialog.SAVE);
			fd.setFile(fileName);
			//fd.setIconImage(SparkManager.getMainWindow().getIconImage());
			fd.toFront();

			fd.setVisible(true);

			if (fd.getFile() != null) {
				copyFile(new File(filePathFull), new File(fd.getDirectory()),fd.getFile());
			} else {
				fd.setAlwaysOnTop(false);
			}
		}else{
			JOptionPane.showMessageDialog(null, Res.FILE_NOT_FOUND, "提示", 1);
		}
	} catch (Exception ex) {
		log.error(ex.getMessage());
	}
}
 
Example 10
Source File: CopyTreesToNexusBlock.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
boolean initFile(){
	MesquiteFileDialog fdlg= new MesquiteFileDialog(containerOfModule(), "Output File for Tree(s)", FileDialog.SAVE);
	fdlg.setBackground(ColorTheme.getInterfaceBackground());
	fdlg.setVisible(true);
	String fileName=fdlg.getFile();
	String directory=fdlg.getDirectory();
	if (StringUtil.blank(fileName) || StringUtil.blank(directory))
		return false;
	saveFile = MesquiteFile.composePath(directory, fileName);
	MesquiteFile.putFileContents(saveFile, "#NEXUS"  + StringUtil.lineEnding(), true);
	MesquiteFile.appendFileContents(saveFile, "BEGIN TREES;"  + StringUtil.lineEnding(), true);
	return true;
}
 
Example 11
Source File: Write.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
* Save the jMusic score as a standard MIDI file
* Prompt user for a filename
* @param Score
*/ 
public static void midi(Score score) {
    FileDialog fd = new FileDialog(new Frame(), 
                                   "Save as a MIDI file ...", 
                                   FileDialog.SAVE);
    fd.setFile("jMusic_composition.mid");
    fd.show();
    if (fd.getFile() != null) {
        Write.midi(score, fd.getDirectory() + fd.getFile());                
    }
    
}
 
Example 12
Source File: RBridge.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String rChooseFile(Rengine re, int newFile) {
    FileDialog fd = new FileDialog(Wandora.getWandora(), (newFile==0)?"Select a file":"Select a new file", (newFile==0)?FileDialog.LOAD:FileDialog.SAVE);
    fd.setVisible(true);
    String res=null;
    if (fd.getDirectory()!=null) res=fd.getDirectory();
    if (fd.getFile()!=null) res=(res==null)?fd.getFile():(res+fd.getFile());
    return res;
}
 
Example 13
Source File: LinuxBrowseListener.java    From BON2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
public LinuxBrowseListener(BON2Gui parent, boolean isOpen, JTextField field) {
  this.parent = parent;
  this.isOpen = isOpen;
  this.field = field;
  
  if (isOpen) {
      this.fd = new FileDialog(this.parent, "Please Select an Input File", FileDialog.LOAD);
  } else {
      this.fd = new FileDialog(this.parent, "Please Select an Output File", FileDialog.SAVE); 
  }
  
  fd.setFilenameFilter( (dir, name) -> name.toLowerCase().endsWith(".jar"));
  
  String key = isOpen ? BON2Gui.PREFS_KEY_OPEN_LOC : BON2Gui.PREFS_KEY_SAVE_LOC;
  String savedDir = parent.prefs.get(key, Paths.get("").toAbsolutePath().toString());
  File currentDir = new File(savedDir);
  
  if (!Paths.get(savedDir).getRoot().toFile().exists()) {
      currentDir = Paths.get("").toAbsolutePath().toFile();
  }
  
  while (!currentDir.isDirectory()) {
      currentDir = currentDir.getParentFile();
  }
  
  fd.setDirectory(currentDir.getPath());
}
 
Example 14
Source File: FileChooser.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 *
 *
 * @param title
 * @param mode
 * @param filter
 *
 * @return
 */
private static File chooseFileAWT(String title, Mode mode, FileFilter filter) {
	Easik e = Easik.getInstance();
	EasikSettings s = e.getSettings();
	FileDialog dialog = new FileDialog(e.getFrame(), title,
			(mode == Mode.SAVE) ? FileDialog.SAVE : FileDialog.LOAD);

	dialog.setDirectory(s.getDefaultFolder());

	if ((mode == Mode.DIRECTORY) && EasikConstants.RUNNING_ON_MAC) {
		System.setProperty("apple.awt.fileDialogForDirectories", "true");
	} else if (filter != null) {
		dialog.setFilenameFilter(filter);
	}

	// Show the dialog (this blocks until the user is done)
	dialog.setVisible(true);

	if ((mode == Mode.DIRECTORY) && EasikConstants.RUNNING_ON_MAC) {
		System.setProperty("apple.awt.fileDialogForDirectories", "false");
	}

	String filename = dialog.getFile();

	if (filename == null) {
		return null;
	}

	File selected = new File(dialog.getDirectory(), filename);

	if (mode != Mode.DIRECTORY) {
		s.setProperty("folder_last", selected.getParentFile().getAbsolutePath());
	}

	return selected;
}
 
Example 15
Source File: SikulixFileChooser.java    From SikuliX1 with MIT License 4 votes vote down vote up
private void processDialog(int selectionMode, String last_dir, String title, int mode, Object[] filters,
                           Object[] result) {
  JFileChooser fchooser = new JFileChooser();
  File fileChoosen = null;
  FileFilter filterChoosen = null;
  if (!last_dir.isEmpty()) {
    fchooser.setCurrentDirectory(new File(last_dir));
  }
  fchooser.setSelectedFile(null);
  fchooser.setDialogTitle(title);
  String btnApprove = "Select";
  if (fromPopFile) {
    fchooser.setFileSelectionMode(DIRSANDFILES);
    fchooser.setAcceptAllFileFilterUsed(true);
  } else {
    fchooser.setFileSelectionMode(selectionMode);
    if (mode == FileDialog.SAVE) {
      fchooser.setDialogType(JFileChooser.SAVE_DIALOG);
      btnApprove = "Save";
    }
    if (filters.length == 0) {
      fchooser.setAcceptAllFileFilterUsed(true);
    } else {
      fchooser.setAcceptAllFileFilterUsed(false);
      for (Object filter : filters) {
        fchooser.setFileFilter((FileFilter) filter);
      }
    }
  }
  if (Settings.isMac()) {
    fchooser.putClientProperty("JFileChooser.packageIsTraversable", "always");
  }
  int dialogResponse = fchooser.showDialog(parentFrame, btnApprove);
  if (dialogResponse != JFileChooser.APPROVE_OPTION) {
    fileChoosen = null;
  } else {
    fileChoosen = fchooser.getSelectedFile();
  }
  result[0] = fileChoosen;
  if (filters.length > 0) {
    result[1] = fchooser.getFileFilter();
  }
}
 
Example 16
Source File: PolicyTool.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * perform SAVE AS
 */
void displaySaveAsDialog(int nextEvent) {

    // pop up a dialog box for the user to enter a filename.
    FileDialog fd = new FileDialog
            (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
    fd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
        }
    });
    fd.setVisible(true);

    // see if the user hit cancel
    if (fd.getFile() == null ||
        fd.getFile().equals(""))
        return;

    // get the entered filename
    File saveAsFile = new File(fd.getDirectory(), fd.getFile());
    String filename = saveAsFile.getPath();
    fd.dispose();

    try {
        // save the policy entries to a file
        tool.savePolicy(filename);

        // display status
        MessageFormat form = new MessageFormat(PolicyTool.getMessage
                ("Policy.successfully.written.to.filename"));
        Object[] source = {filename};
        tw.displayStatusDialog(null, form.format(source));

        // display the new policy filename
        JTextField newFilename = (JTextField)tw.getComponent
                        (ToolWindow.MW_FILENAME_TEXTFIELD);
        newFilename.setText(filename);
        tw.setVisible(true);

        // now continue with the originally requested command
        // (QUIT, NEW, or OPEN)
        userSaveContinue(tool, tw, this, nextEvent);

    } catch (FileNotFoundException fnfe) {
        if (filename == null || filename.equals("")) {
            tw.displayErrorDialog(null, new FileNotFoundException
                        (PolicyTool.getMessage("null.filename")));
        } else {
            tw.displayErrorDialog(null, fnfe);
        }
    } catch (Exception ee) {
        tw.displayErrorDialog(null, ee);
    }
}
 
Example 17
Source File: PolicyTool.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * perform SAVE AS
 */
void displaySaveAsDialog(int nextEvent) {

    // pop up a dialog box for the user to enter a filename.
    FileDialog fd = new FileDialog
            (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
    fd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
        }
    });
    fd.setVisible(true);

    // see if the user hit cancel
    if (fd.getFile() == null ||
        fd.getFile().equals(""))
        return;

    // get the entered filename
    File saveAsFile = new File(fd.getDirectory(), fd.getFile());
    String filename = saveAsFile.getPath();
    fd.dispose();

    try {
        // save the policy entries to a file
        tool.savePolicy(filename);

        // display status
        MessageFormat form = new MessageFormat(PolicyTool.getMessage
                ("Policy.successfully.written.to.filename"));
        Object[] source = {filename};
        tw.displayStatusDialog(null, form.format(source));

        // display the new policy filename
        JTextField newFilename = (JTextField)tw.getComponent
                        (ToolWindow.MW_FILENAME_TEXTFIELD);
        newFilename.setText(filename);
        tw.setVisible(true);

        // now continue with the originally requested command
        // (QUIT, NEW, or OPEN)
        userSaveContinue(tool, tw, this, nextEvent);

    } catch (FileNotFoundException fnfe) {
        if (filename == null || filename.equals("")) {
            tw.displayErrorDialog(null, new FileNotFoundException
                        (PolicyTool.getMessage("null.filename")));
        } else {
            tw.displayErrorDialog(null, fnfe);
        }
    } catch (Exception ee) {
        tw.displayErrorDialog(null, ee);
    }
}
 
Example 18
Source File: PolicyTool.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * perform SAVE AS
 */
void displaySaveAsDialog(int nextEvent) {

    // pop up a dialog box for the user to enter a filename.
    FileDialog fd = new FileDialog
            (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
    fd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
        }
    });
    fd.setVisible(true);

    // see if the user hit cancel
    if (fd.getFile() == null ||
        fd.getFile().equals(""))
        return;

    // get the entered filename
    File saveAsFile = new File(fd.getDirectory(), fd.getFile());
    String filename = saveAsFile.getPath();
    fd.dispose();

    try {
        // save the policy entries to a file
        tool.savePolicy(filename);

        // display status
        MessageFormat form = new MessageFormat(PolicyTool.getMessage
                ("Policy.successfully.written.to.filename"));
        Object[] source = {filename};
        tw.displayStatusDialog(null, form.format(source));

        // display the new policy filename
        JTextField newFilename = (JTextField)tw.getComponent
                        (ToolWindow.MW_FILENAME_TEXTFIELD);
        newFilename.setText(filename);
        tw.setVisible(true);

        // now continue with the originally requested command
        // (QUIT, NEW, or OPEN)
        userSaveContinue(tool, tw, this, nextEvent);

    } catch (FileNotFoundException fnfe) {
        if (filename == null || filename.equals("")) {
            tw.displayErrorDialog(null, new FileNotFoundException
                        (PolicyTool.getMessage("null.filename")));
        } else {
            tw.displayErrorDialog(null, fnfe);
        }
    } catch (Exception ee) {
        tw.displayErrorDialog(null, ee);
    }
}
 
Example 19
Source File: PolicyTool.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * perform SAVE AS
 */
void displaySaveAsDialog(int nextEvent) {

    // pop up a dialog box for the user to enter a filename.
    FileDialog fd = new FileDialog
            (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
    fd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
        }
    });
    fd.setVisible(true);

    // see if the user hit cancel
    if (fd.getFile() == null ||
        fd.getFile().equals(""))
        return;

    // get the entered filename
    File saveAsFile = new File(fd.getDirectory(), fd.getFile());
    String filename = saveAsFile.getPath();
    fd.dispose();

    try {
        // save the policy entries to a file
        tool.savePolicy(filename);

        // display status
        MessageFormat form = new MessageFormat(PolicyTool.getMessage
                ("Policy.successfully.written.to.filename"));
        Object[] source = {filename};
        tw.displayStatusDialog(null, form.format(source));

        // display the new policy filename
        JTextField newFilename = (JTextField)tw.getComponent
                        (ToolWindow.MW_FILENAME_TEXTFIELD);
        newFilename.setText(filename);
        tw.setVisible(true);

        // now continue with the originally requested command
        // (QUIT, NEW, or OPEN)
        userSaveContinue(tool, tw, this, nextEvent);

    } catch (FileNotFoundException fnfe) {
        if (filename == null || filename.equals("")) {
            tw.displayErrorDialog(null, new FileNotFoundException
                        (PolicyTool.getMessage("null.filename")));
        } else {
            tw.displayErrorDialog(null, fnfe);
        }
    } catch (Exception ee) {
        tw.displayErrorDialog(null, ee);
    }
}
 
Example 20
Source File: PolicyTool.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * perform SAVE AS
 */
void displaySaveAsDialog(int nextEvent) {

    // pop up a dialog box for the user to enter a filename.
    FileDialog fd = new FileDialog
            (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
    fd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
        }
    });
    fd.setVisible(true);

    // see if the user hit cancel
    if (fd.getFile() == null ||
        fd.getFile().equals(""))
        return;

    // get the entered filename
    File saveAsFile = new File(fd.getDirectory(), fd.getFile());
    String filename = saveAsFile.getPath();
    fd.dispose();

    try {
        // save the policy entries to a file
        tool.savePolicy(filename);

        // display status
        MessageFormat form = new MessageFormat(PolicyTool.getMessage
                ("Policy.successfully.written.to.filename"));
        Object[] source = {filename};
        tw.displayStatusDialog(null, form.format(source));

        // display the new policy filename
        JTextField newFilename = (JTextField)tw.getComponent
                        (ToolWindow.MW_FILENAME_TEXTFIELD);
        newFilename.setText(filename);
        tw.setVisible(true);

        // now continue with the originally requested command
        // (QUIT, NEW, or OPEN)
        userSaveContinue(tool, tw, this, nextEvent);

    } catch (FileNotFoundException fnfe) {
        if (filename == null || filename.equals("")) {
            tw.displayErrorDialog(null, new FileNotFoundException
                        (PolicyTool.getMessage("null.filename")));
        } else {
            tw.displayErrorDialog(null, fnfe);
        }
    } catch (Exception ee) {
        tw.displayErrorDialog(null, ee);
    }
}