本文整理汇总了Java中java.awt.FileDialog类的典型用法代码示例。如果您正苦于以下问题:Java FileDialog类的具体用法?Java FileDialog怎么用?Java FileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileDialog类属于java.awt包,在下文中一共展示了FileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showFileDialog
import java.awt.FileDialog; //导入依赖的package包/类
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: showSaveDialog
import java.awt.FileDialog; //导入依赖的package包/类
public int showSaveDialog(Component parent) {
final FileDialog fd = awt_file_dialog_init(parent);
fd.setMode(FileDialog.SAVE);
fd.setVisible(true);
final int value;
if (fd.getFile() != null) {
cur = new File(fd.getDirectory(), fd.getFile());
value = FileChooser.APPROVE_OPTION;
}
else {
value = FileChooser.CANCEL_OPTION;
}
updateDirectoryPreference();
return value;
}
示例3: showOpenDialog
import java.awt.FileDialog; //导入依赖的package包/类
/**
* Show an open dialog with a file chooser set up according to the
* parameters of this builder.
* @return A file if the user clicks the accept button and a file or
* folder was selected at the time the user clicked cancel.
*/
public File showOpenDialog() {
JFileChooser chooser = createFileChooser();
if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
if( null != fileDialog ) {
return showFileDialog(fileDialog, FileDialog.LOAD );
}
}
chooser.setMultiSelectionEnabled(false);
int dlgResult = chooser.showOpenDialog(findDialogParent());
if (JFileChooser.APPROVE_OPTION == dlgResult) {
File result = chooser.getSelectedFile();
if (result != null && !result.exists()) {
result = null;
}
return result;
} else {
return null;
}
}
示例4: showSaveDialog
import java.awt.FileDialog; //导入依赖的package包/类
/**
* Show a save dialog with the file chooser set up according to the
* parameters of this builder.
* @return A file if the user clicks the accept button and a file or
* folder was selected at the time the user clicked cancel.
*/
public File showSaveDialog() {
JFileChooser chooser = createFileChooser();
if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
if( null != fileDialog ) {
return showFileDialog( fileDialog, FileDialog.SAVE );
}
}
int result = chooser.showSaveDialog(findDialogParent());
if (JFileChooser.APPROVE_OPTION == result) {
return chooser.getSelectedFile();
} else {
return null;
}
}
示例5: createFileDialog
import java.awt.FileDialog; //导入依赖的package包/类
private FileDialog createFileDialog( File currentDirectory ) {
if( badger != null )
return null;
if( !Boolean.getBoolean("nb.native.filechooser") )
return null;
if( dirsOnly && !BaseUtilities.isMac() )
return null;
Component parentComponent = findDialogParent();
Frame parentFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent);
FileDialog fileDialog = new FileDialog(parentFrame);
if (title != null) {
fileDialog.setTitle(title);
}
if( null != currentDirectory )
fileDialog.setDirectory(currentDirectory.getAbsolutePath());
return fileDialog;
}
示例6: showOpenDialog
import java.awt.FileDialog; //导入依赖的package包/类
public int showOpenDialog(Component parent) {
final FileDialog fd = awt_file_dialog_init(parent);
fd.setMode(FileDialog.LOAD);
System.setProperty("apple.awt.fileDialogForDirectories",
String.valueOf(mode == DIRECTORIES_ONLY));
fd.setVisible(true);
final int value;
if (fd.getFile() != null) {
cur = new File(fd.getDirectory(), fd.getFile());
value = FileChooser.APPROVE_OPTION;
}
else {
value = FileChooser.CANCEL_OPTION;
}
updateDirectoryPreference();
return value;
}
示例7: ExportMenuItem
import java.awt.FileDialog; //导入依赖的package包/类
public ExportMenuItem(final FlagFrame frame) {
setText("Export...");
if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_E);
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputUtils.META_MASK));
if (frame == null) {
setEnabled(false);
} else {
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
FileDialog fd = new FileDialog(frame, "Export", FileDialog.SAVE);
fd.setVisible(true);
if (fd.getDirectory() == null || fd.getFile() == null) return;
File file = new File(fd.getDirectory(), fd.getFile());
new ExportDialog(
frame, frame.getParentFile(), frame.getFlag(), file,
frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze()
).setVisible(true);
}
});
}
}
示例8: OpenMenuItem
import java.awt.FileDialog; //导入依赖的package包/类
public OpenMenuItem() {
setText("Open...");
if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_O);
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputUtils.META_MASK));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
FileDialog fd = new FileDialog(new Frame(), "Open", FileDialog.LOAD);
fd.setVisible(true);
if (fd.getDirectory() == null || fd.getFile() == null) return;
File file = new File(fd.getDirectory(), fd.getFile());
try {
FileInputStream in = new FileInputStream(file);
Flag flag = FlagParser.parse(file.getName(), in);
in.close();
String title = file.getName();
if (flag.getName() != null) title += ": " + flag.getName();
FlagFrame frame = new FlagFrame(title, file, flag);
frame.setVisible(true);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), "Open", JOptionPane.ERROR_MESSAGE);
}
}
});
}
示例9: showNativeDialog
import java.awt.FileDialog; //导入依赖的package包/类
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());
}
示例10: init
import java.awt.FileDialog; //导入依赖的package包/类
@Override
public void init() {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
Sysout.createDialogWithInstructions(new String[]{
"Press PASS, this test is for MacOS X only."});
return;
}
System.setProperty("apple.awt.use-file-dialog-packages", "true");
setLayout(new GridLayout(1, 1));
fd = new FileDialog(new Frame(), "Open");
fd.setDirectory(APPLICATIONS_FOLDER);
showBtn = new Button("Show File Dialog");
showBtn.addActionListener(this);
add(showBtn);
String[] instructions = {
"1) Click on 'Show File Dialog' button. A file dialog will come up.",
"2) Navigate to the Applications folder if not already there",
"3) Check that the application bundles can be selected and can not be navigated",
"4) If it's true then the test passed, otherwise it failed."};
Sysout.createDialogWithInstructions(instructions);
}
示例11: init
import java.awt.FileDialog; //导入依赖的package包/类
@Override
public void init() {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
Sysout.createDialogWithInstructions(new String[]{
"Press PASS, this test is for MacOS X only."});
return;
}
System.setProperty("apple.awt.fileDialogForDirectories", "true");
setLayout(new GridLayout(1, 1));
fd = new FileDialog(new Frame(), "Open");
showBtn = new Button("Show File Dialog");
showBtn.addActionListener(this);
add(showBtn);
String[] instructions = {
"1) Click on 'Show File Dialog' button. A file dialog will come up.",
"2) Check that files can't be selected.",
"3) Check that directories can be selected.",
"4) Repeat steps 1 - 3 a few times for different files and directories.",
"5) If it's true then the test passed, otherwise it failed."};
Sysout.createDialogWithInstructions(instructions);
}
示例12: showNativeDialog
import java.awt.FileDialog; //导入依赖的package包/类
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();
}
}
if (!quit) {
run(fd.getTitle(), fd.getMode(), dirname, filename,
fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
}
示例13: askUser
import java.awt.FileDialog; //导入依赖的package包/类
private static String[] askUser(ProgressWindow progress, String dp, String initialFileName, String a) {
String ask = (a == null ? "What do you want to call this file?" : a);
String[] s = new String[2];
FileDialog dialog = new FileDialog(progress, ask, FileDialog.SAVE);
dialog.setSize(400, 300);
dialog.setDirectory(dp);
dialog.setFile(initialFileName);
dialog.show();
String temppath = dialog.getDirectory();
String chosenFileName = dialog.getFile();
if (chosenFileName == null) {
progress.setText("User Cancelled", FileProgressWindow.BAR_1);
return null;
}
s[0] = temppath;
s[1] = chosenFileName;
return s;
}
示例14: actionPerformed
import java.awt.FileDialog; //导入依赖的package包/类
public void actionPerformed(ActionEvent event) {
FileDialog dialog = new FileDialog(SnakeGameFrame.this, "Open",
FileDialog.LOAD);
dialog.setVisible(true);
String dir = dialog.getDirectory();
String fileName = dialog.getFile();
String filePath = dir + fileName;
if (fileName != null && fileName.trim().length() != 0) {
File file = new File(filePath);
panel.loadGameDataFromFile(file);
startMI.setEnabled(false);
pauseMI.setEnabled(true);
} else {
JOptionPane.showConfirmDialog(SnakeGameFrame.this,
"�ļ���Ϊ��\nװ����Ϸ����ʧ��", "̰������Ϸ", JOptionPane.DEFAULT_OPTION);
}
}
示例15: showSaveDialog
import java.awt.FileDialog; //导入依赖的package包/类
public static File showSaveDialog(Frame f,String title,String extension) {
if(extension.startsWith("."))
extension = extension.substring(1);
FileDialog fd = new FileDialog(f, title);
fd.setMode(FileDialog.SAVE);
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);
}
return new File(fd.getDirectory() + fd.getFile()+"."+extension);
}