java.awt.FileDialog#setMode ( )源码实例Demo

下面列出了java.awt.FileDialog#setMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: FileChooserBuilder.java
private File showFileDialog( FileDialog fileDialog, int mode ) {
    String oldFileDialogProp = System.getProperty("apple.awt.fileDialogForDirectories"); //NOI18N
    if( dirsOnly ) {
        System.setProperty("apple.awt.fileDialogForDirectories", "true"); //NOI18N
    }
    fileDialog.setMode( mode );
    fileDialog.setVisible(true);
    if( dirsOnly ) {
        if( null != oldFileDialogProp ) {
            System.setProperty("apple.awt.fileDialogForDirectories", oldFileDialogProp); //NOI18N
        } else {
            System.clearProperty("apple.awt.fileDialogForDirectories"); //NOI18N
        }
    }
    if( fileDialog.getDirectory() != null && fileDialog.getFile() != null ) {
        String selFile = fileDialog.getFile();
        File dir = new File( fileDialog.getDirectory() );
        return new File( dir, selFile );
    }
    return null;
}
 
源代码2 项目: triplea   文件: SaveGameFileChooser.java
/**
 * Displays a file chooser dialog for the user to select the file to which the current game should
 * be saved.
 *
 * @param frame The owner of the file chooser dialog; may be {@code null}.
 * @return The file to which the current game should be saved or {@code null} if the user
 *     cancelled the operation.
 */
public static File getSaveGameLocation(final Frame frame, final GameData gameData) {
  final FileDialog fileDialog = new FileDialog(frame);
  fileDialog.setMode(FileDialog.SAVE);
  fileDialog.setDirectory(ClientSetting.saveGamesFolderPath.getValueOrThrow().toString());
  fileDialog.setFilenameFilter((dir, name) -> GameDataFileUtils.isCandidateFileName(name));
  fileDialog.setFile(getSaveGameName(gameData));

  fileDialog.setVisible(true);
  final String fileName = fileDialog.getFile();
  if (fileName == null) {
    return null;
  }

  // If the user selects a filename that already exists,
  // the AWT Dialog will ask the user for confirmation
  return new File(fileDialog.getDirectory(), GameDataFileUtils.addExtensionIfAbsent(fileName));
}
 
源代码3 项目: mpcmaid   文件: MainFrame.java
public void open() {
	final FileDialog openDialog = new FileDialog(this);
	openDialog.setDirectory(Preferences.getInstance().getOpenPath());
	openDialog.setMode(FileDialog.LOAD);
	openDialog.setFilenameFilter(new FilenameFilter() {
		public boolean accept(File dir, String name) {
			String[] supportedFiles = { "PGM", "pgm" };
			for (int i = 0; i < supportedFiles.length; i++) {
				if (name.endsWith(supportedFiles[i])) {
					return true;
				}
			}
			return false;
		}
	});
	openDialog.setVisible(true);
	Preferences.getInstance().setOpenPath(openDialog.getDirectory());
	if (openDialog.getDirectory() != null && openDialog.getFile() != null) {
		String filePath = openDialog.getDirectory() + openDialog.getFile();
		System.out.println(filePath);
		final File pgmFile = new File(filePath);
		final MainFrame newFrame = new MainFrame(pgmFile);
		newFrame.show();
	}
}
 
源代码4 项目: CodenameOne   文件: SamplesRunner.java
@Override
public void exportAsNetbeansProject(Sample sample) {
    FileDialog fileSelector = new FileDialog((JFrame)SwingUtilities.getWindowAncestor(view), "Select Destination");
    fileSelector.setMode(FileDialog.SAVE);
    fileSelector.setVisible(true);
    String selectedFile = fileSelector.getFile();
    if (selectedFile == null) {
        return;
    }
    File f = new File(new File(fileSelector.getDirectory()), selectedFile);
    System.out.println(f);
    new Thread(()->{
        try {
            sample.exportAsNetbeansProject(ctx, f);
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(view, ex.getMessage(), "Export Failed", JOptionPane.ERROR_MESSAGE);

        }
    }).start();
    
    
}
 
源代码5 项目: lizzie   文件: MainFrame.java
public void openFile() {
  JSONObject filesystem = Lizzie.config.persisted.getJSONObject("filesystem");
  FileDialog fileDialog = new FileDialog(this, resourceBundle.getString("LizzieFrame.openFile"));
  fileDialog.setLocationRelativeTo(this);
  fileDialog.setDirectory(filesystem.getString("last-folder"));
  fileDialog.setFile("*.sgf;*.gib;*.SGF;*.GIB");
  fileDialog.setMultipleMode(false);
  fileDialog.setMode(0);
  fileDialog.setVisible(true);
  File[] file = fileDialog.getFiles();
  if (file.length > 0) loadFile(file[0]);
}
 
源代码6 项目: netbeans   文件: MiniEdit.java
/** Invoker for the saveas action */
public void saveAs() {
    Doc doc = getSelectedDoc();
    if (doc == null) {
        throw new NullPointerException ("no doc");
    }
    

    FileDialog fd = new FileDialog (MiniEdit.this, "Save as");
    fd.setMode(fd.SAVE);
    fd.show();
    if (fd.getFile() != null) {
        File nue = new File (fd.getDirectory() + fd.getFile());
        try {
            boolean success = nue.createNewFile();
            if (success) {
                FileWriter w = new FileWriter (nue);
                doc.getTextPane().write(w);
                file = nue;
                documentTabs.setTitleAt(documentTabs.getSelectedIndex(), nue.getName());
                documentTabs.setToolTipTextAt(documentTabs.getSelectedIndex(), nue.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
源代码7 项目: JWT4B   文件: JWTInterceptTabController.java
private void radioButtonChanged(boolean cDM, boolean cRK, boolean cOS, boolean cRS, boolean cCS) {
	boolean oldRandomKey = randomKey;

	dontModify = jwtST.getRdbtnDontModify().isSelected();
	randomKey = jwtST.getRdbtnRandomKey().isSelected();
	keepOriginalSignature = jwtST.getRdbtnOriginalSignature().isSelected();
	recalculateSignature = jwtST.getRdbtnRecalculateSignature().isSelected();
	chooseSignature = jwtST.getRdbtnChooseSignature().isSelected();

	jwtST.setKeyFieldState(!keepOriginalSignature && !dontModify && !randomKey && !chooseSignature);

	if (keepOriginalSignature || dontModify) {
		jwtIM.setJWTKey("");
		jwtST.setKeyFieldValue("");
	}
	if (randomKey && !oldRandomKey) {
		generateRandomKey();
	}
	if (cCS) {
		FileDialog dialog = new FileDialog((Frame) null, "Select File to Open");
		dialog.setMode(FileDialog.LOAD);
		dialog.setVisible(true);
		if(dialog.getFile()!=null) {
			String file = dialog.getDirectory() + dialog.getFile();
			Output.output(file + " chosen.");
			String chosen = Strings.filePathToString(file);
			jwtIM.setJWTKey(chosen);
			jwtST.updateSetView(false);	
		}
	}
}
 
源代码8 项目: pumpernickel   文件: FileDialogUtils.java
/**
 * Returns files the user selected or an empty array if the user cancelled
 * the dialog.
 */
public static File[] showOpenDialog(Frame f, String title,
		boolean allowMultipleSelection, FilenameFilter filter) {
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.LOAD);
	if (filter != null)
		fd.setFilenameFilter(filter);
	fd.pack();
	fd.setMultipleMode(allowMultipleSelection);
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	if (fd.getFile() == null)
		return new File[] {};
	return fd.getFiles();
}
 
源代码9 项目: pumpernickel   文件: FileDialogUtils.java
/**
 * Show a save FileDialog.
 * 
 * @param f
 *            the frame that owns the FileDialog.
 * @param title
 *            the dialog title
 * @param filename
 *            the optional default filename shown in the file dialog.
 * @param extension
 *            the file extension ("xml", "png", etc.)
 * @return a File the user chose.
 */
public static File showSaveDialog(Frame f, String title, String filename,
		String extension) {
	if (extension.startsWith("."))
		extension = extension.substring(1);

	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.SAVE);
	if (filename != null)
		fd.setFile(filename);
	fd.setFilenameFilter(new SuffixFilenameFilter(extension));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);

	String s = fd.getFile();
	if (s == null)
		return null;

	if (s.toLowerCase().endsWith("." + extension)) {
		return new File(fd.getDirectory() + s);
	}

	// TODO: show a 'are you sure you want to replace' dialog here, if we
	// change the filename
	// native FileDialogs don't always show the right warning dialog IF the
	// file extension
	// isn't present

	return new File(fd.getDirectory() + fd.getFile() + "." + extension);
}
 
源代码10 项目: binnavi   文件: CFileChooser.java
private static int showNativeFileDialog(final JFileChooser chooser) {
  final FileDialog result = new FileDialog((Frame) chooser.getParent());

  result.setDirectory(chooser.getCurrentDirectory().getPath());

  final File selected = chooser.getSelectedFile();
  result.setFile(selected == null ? "" : selected.getPath());
  result.setFilenameFilter(new FilenameFilter() {
    @Override
    public boolean accept(final File dir, final String name) {
      return chooser.getFileFilter().accept(new File(dir.getPath() + File.pathSeparator + name));
    }
  });

  if (chooser.getDialogType() == SAVE_DIALOG) {
    result.setMode(FileDialog.SAVE);
  } else {
    // The native dialog only support Open and Save
    result.setMode(FileDialog.LOAD);
  }

  if (chooser.getFileSelectionMode() == DIRECTORIES_ONLY) {
    System.setProperty("apple.awt.fileDialogForDirectories", "true");
  }

  // Display dialog
  result.setVisible(true);

  System.setProperty("apple.awt.fileDialogForDirectories", "false");
  if (result.getFile() == null) {
    return CANCEL_OPTION;
  }

  final String selectedDir = result.getDirectory();
  chooser
      .setSelectedFile(new File(FileUtils.ensureTrailingSlash(selectedDir) + result.getFile()));
  return APPROVE_OPTION;
}
 
源代码11 项目: triplea   文件: GameFileSelector.java
/**
 * Opens up a UI pop-up allowing user to select a game file. Returns nothing if user closes the
 * pop-up.
 */
public Optional<File> selectGameFile(final Frame owner) {
  final FileDialog fileDialog = new FileDialog(owner);
  fileDialog.setMode(FileDialog.LOAD);
  fileDialog.setDirectory(ClientSetting.saveGamesFolderPath.getValueOrThrow().toString());
  fileDialog.setFilenameFilter((dir, name) -> GameDataFileUtils.isCandidateFileName(name));
  fileDialog.setVisible(true);

  // FileDialog.getFiles() always returns an array
  // of 1 or 0 items, because FileDialog.multipleMode is false by default
  return Arrays.stream(fileDialog.getFiles()).findAny().map(this::mapFileResult);
}
 
源代码12 项目: mpcmaid   文件: MainFrame.java
public void saveAs() {
	final FileDialog saveDialog = new FileDialog(this);
	saveDialog.setDirectory(Preferences.getInstance().getSavePath());
	saveDialog.setMode(FileDialog.SAVE);
	saveDialog.setFilenameFilter(new FilenameFilter() {
		public boolean accept(File dir, String name) {
			String[] supportedFiles = { "PGM", "pgm" };
			for (int i = 0; i < supportedFiles.length; i++) {
				if (name.endsWith(supportedFiles[i])) {
					return true;
				}
			}
			return false;
		}
	});
	saveDialog.setVisible(true);
	Preferences.getInstance().setSavePath(saveDialog.getDirectory());
	String filename = saveDialog.getFile();
	if (saveDialog.getDirectory() != null && filename != null) {
		if (!filename.toUpperCase().endsWith(".PGM")) {
			filename += ".PGM";
		}
		String filePath = saveDialog.getDirectory() + filename;
		System.out.println(filePath);
		final File file = new File(filePath);
		setPgmFile(file);
		program.save(pgmFile);
	}
}
 
源代码13 项目: BART   文件: Export.java
private File chooseFile() {
    JFrame mainFrame = (JFrame) WindowManager.getDefault().getMainWindow();
    FileDialog fileDialog = new FileDialog(mainFrame, new File(System.getProperty("user.home")).toString());
    fileDialog.setTitle("Export changes in cvs file");
    fileDialog.setFile("expected.csv");
    fileDialog.setMode(FileDialog.SAVE);
    fileDialog.setFilenameFilter(new ExtFileFilter("csv"));
    fileDialog.setVisible(true);
    String filename = fileDialog.getFile();
    if (filename == null){
        return null;
    }
    String dir = fileDialog.getDirectory();
    return new File(dir + File.separator + filename);
}
 
源代码14 项目: netbeans   文件: OpenFileAction.java
/**
 * {@inheritDoc} Displays a file chooser dialog
 * and opens the selected files.
 */
@Override
public void actionPerformed(ActionEvent e) {
    if (running) {
        return;
    }
    try {
        running = true;
        JFileChooser chooser = prepareFileChooser();
        File[] files;
        try {
            if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
                String oldFileDialogProp = System.getProperty("apple.awt.fileDialogForDirectories"); //NOI18N
                System.setProperty("apple.awt.fileDialogForDirectories", "false"); //NOI18N
                FileDialog fileDialog = new FileDialog(WindowManager.getDefault().getMainWindow());
                fileDialog.setMode(FileDialog.LOAD);
                fileDialog.setDirectory(getCurrentDirectory().getAbsolutePath());
                fileDialog.setTitle(chooser.getDialogTitle());
                fileDialog.setVisible(true);
                if( null != oldFileDialogProp ) {
                    System.setProperty("apple.awt.fileDialogForDirectories", oldFileDialogProp); //NOI18N
                } else {
                    System.clearProperty("apple.awt.fileDialogForDirectories"); //NOI18N
                }

                if( fileDialog.getDirectory() != null && fileDialog.getFile() != null ) {
                    String selFile = fileDialog.getFile();
                    File dir = new File( fileDialog.getDirectory() );
                    files = new File[] { new File( dir, selFile ) };
                    currentDirectory = dir;
                } else {
                    throw new UserCancelException();
                }
            } else {
                files = chooseFilesToOpen(chooser);
                currentDirectory = chooser.getCurrentDirectory();
                if (chooser.getFileFilter() != null) { // #227187
                    currentFileFilter =
                            chooser.getFileFilter().getDescription();
                }
            }
        } catch (UserCancelException ex) {
            return;
        }
        for (int i = 0; i < files.length; i++) {
            OpenFile.openFile(files[i], -1);
        }
    } finally {
        running = false;
    }
}