当前位置: 首页>>代码示例>>Java>>正文


Java FileDialog.setMode方法代码示例

本文整理汇总了Java中java.awt.FileDialog.setMode方法的典型用法代码示例。如果您正苦于以下问题:Java FileDialog.setMode方法的具体用法?Java FileDialog.setMode怎么用?Java FileDialog.setMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.FileDialog的用法示例。


在下文中一共展示了FileDialog.setMode方法的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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:FileChooserBuilder.java

示例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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:17,代码来源:FileChooser.java

示例3: 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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:19,代码来源:FileChooser.java

示例4: 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);
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:22,代码来源:FileDialogUtils.java

示例5: showSaveDialog

import java.awt.FileDialog; //导入方法依赖的package包/类
protected File showSaveDialog() {
	FileDialog fd = new FileDialog(frame);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter("mov"));
	fd.setTitle("Save MOV File");
	fd.pack();
	fd.setLocationRelativeTo(frame);
	fd.setVisible(true);
	if(fd.getFile()==null)
		throw new UserCancelledException();
	String filepath = fd.getDirectory() + fd.getFile();
	if(!filepath.toLowerCase().endsWith(".mov")) {
		filepath += ".mov";
	}
	return new File(filepath);
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:17,代码来源:ScreenCaptureDemo.java

示例6: chooseFile

import java.awt.FileDialog; //导入方法依赖的package包/类
public static File chooseFile(File initialFile, boolean load) {
	if (isMac()) {
		FileDialog d = new FileDialog((java.awt.Frame)null);
		d.setMode(load ? FileDialog.LOAD : FileDialog.SAVE);
           if (initialFile != null) {
               d.setDirectory(initialFile.getParent());
               d.setFile(initialFile.getName());
           }
		d.show();
		String f = d.getFile();
		if (f != null)
			return new File(new File(d.getDirectory()), d.getFile());
	} else {
        JFileChooser chooser = new JFileChooser();
           if (initialFile != null)
               chooser.setSelectedFile(initialFile);
        if ((load ? chooser.showOpenDialog(null) : chooser.showSaveDialog(null)) == JFileChooser.APPROVE_OPTION)
        		return chooser.getSelectedFile();
	}
       return null;
}
 
开发者ID:nativelibs4java,项目名称:JavaCL,代码行数:22,代码来源:Utils.java

示例7: open

import java.awt.FileDialog; //导入方法依赖的package包/类
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();
	}
}
 
开发者ID:cyriux,项目名称:mpcmaid,代码行数:26,代码来源:MainFrame.java

示例8: openHandler

import java.awt.FileDialog; //导入方法依赖的package包/类
public void openHandler() {
      if(hasUnsavedChanges()) {
          int confirmed = JOptionPane.showConfirmDialog(null,
                  getFrame().getLang().getWord("ParentEditionPanel.saveOrLooseOnOpen"),
                  "", JOptionPane.YES_NO_CANCEL_OPTION);
          if (confirmed == JOptionPane.YES_OPTION) {
              saveHandler(false);
          } else if (confirmed == JOptionPane.NO_OPTION) {
          } else if (confirmed == JOptionPane.CANCEL_OPTION) {
              return;
          }
      }

FileDialog d = new FileDialog(getFrame());
d.setDirectory(touist.TouIST.getWhereToSave());
  	d.setMode(FileDialog.LOAD);
  	d.setVisible(true);
  	
      editor.setText("");

      if (d.getFile() != null) 
      {
      	String path = d.getDirectory() + d.getFile();
          open(path);
      }
  }
 
开发者ID:touist,项目名称:touist,代码行数:27,代码来源:ParentEditionPanel.java

示例9: actionPerformed

import java.awt.FileDialog; //导入方法依赖的package包/类
/**
 * Button callback to show the file selector
 */
@Override
public void actionPerformed(ActionEvent e) {
  FileDialog fc = new FileDialog(frame);
  fc.setDirectory(defaultpath);
  fc.setMode(mode);
  final String curr = textfield.getText();
  if(curr != null && curr.length() > 0) {
    fc.setFile(curr);
  }
  fc.setVisible(true);
  String filename = fc.getFile();
  if(filename != null) {
    textfield.setText(new File(fc.getDirectory(), filename).getPath());
  }
  fc.setVisible(false);
  fc.dispose();
  textfield.requestFocus();
  fireEditingStopped();
}
 
开发者ID:elki-project,项目名称:elki,代码行数:23,代码来源:ParameterTable.java

示例10: saveAs

import java.awt.FileDialog; //导入方法依赖的package包/类
/** 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();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:MiniEdit.java

示例11: actionPerformed

import java.awt.FileDialog; //导入方法依赖的package包/类
public void actionPerformed( ActionEvent e ) {
    Object source = e.getSource();
    if ( source == quitMI ) {
        quit();
    }
    else if ( source == optionsMI ) {
        preferences();
    }
    else if ( source == aboutMI ) {
        about();
    }
    else if ( source == openMI ) {
        // File:Open action shows a FileDialog for loading displayable images
        FileDialog openDialog = new FileDialog( this );
        openDialog.setMode( FileDialog.LOAD );
        openDialog.setFilenameFilter( new FilenameFilter() {
            public boolean accept( File dir, String name ) {
                String[] supportedFiles = ImageIO.getReaderFormatNames();
                for ( int i = 0; i < supportedFiles.length; i++ ) {
                    if ( name.endsWith( supportedFiles[i] ) ) {
                        return true;
                    }
                }
                return false;
            }
        } );
        openDialog.setVisible( true );
        String filePath = openDialog.getDirectory() + openDialog.getFile();
        if ( filePath != null ) {
            loadImageFile( filePath );
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:34,代码来源:MyApp.java

示例12: showOpenDialog

import java.awt.FileDialog; //导入方法依赖的package包/类
public static File showOpenDialog(Frame f,String title,String... extensions) {
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.LOAD);
	if(extensions!=null && extensions.length>0)
		fd.setFilenameFilter(new SuffixFilenameFilter(extensions));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	if(fd.getFile()==null)
		return null;
	return new File(fd.getDirectory() + fd.getFile());
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:13,代码来源:FileDialogUtils.java

示例13: promptFile

import java.awt.FileDialog; //导入方法依赖的package包/类
public File promptFile(String name,String suffix) {
	if(suffix.startsWith(".")==false)
		suffix = '.'+suffix;
	FileDialog fd = new FileDialog(JarWriterApp.this);
	fd.setFile(name);
	fd.setMode(FileDialog.SAVE);
	fd.setVisible(true);
	String s = fd.getFile();
	if(s==null)
		return null;
	File returnValue = new File(fd.getDirectory()+s);
	if(s.toLowerCase().endsWith(suffix.toLowerCase())==false) {
		s = s+suffix;
		returnValue = new File(fd.getDirectory()+s);
		if(returnValue.exists()) {
			String dialogTitle = "File Error";
			int type = QDialog.ERROR_MESSAGE;
			String boldMessage = "The file \""+s+"\" already exists.";
			String plainMessage = "Please export again using a unique name.";
			QDialog.showDialog(JarWriterApp.this, dialogTitle, type, boldMessage, plainMessage, 
					null, //innerComponent, 
					null, //lowerLeftComponent, 
					DialogFooter.OK_OPTION,
					DialogFooter.OK_OPTION,
					null, //dontShowKey, 
					null, //alwaysApplyKey, 
					DialogFooter.EscapeKeyBehavior.TRIGGERS_DEFAULT); // escapeKeyBehavior)
			throw new RuntimeException(boldMessage+" "+plainMessage);
		}
	}
	return returnValue;
}
 
开发者ID:mickleness,项目名称:pumpernickel,代码行数:33,代码来源:JarWriterApp.java

示例14: chooseFile

import java.awt.FileDialog; //导入方法依赖的package包/类
static File chooseFile() {
	if (Platform.isMacOSX()) {
		FileDialog d = new FileDialog((java.awt.Frame)null);
		d.setMode(FileDialog.LOAD);
		d.show();
		String f = d.getFile();
		if (f != null)
			return new File(new File(d.getDirectory()), d.getFile());
	} else {
        JFileChooser chooser = new JFileChooser();
        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
        	return chooser.getSelectedFile();
	}
       return null;
}
 
开发者ID:nativelibs4java,项目名称:JavaCL,代码行数:16,代码来源:SobelFilterDemo.java

示例15: showNativeFileDialog

import java.awt.FileDialog; //导入方法依赖的package包/类
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;
}
 
开发者ID:google,项目名称:binnavi,代码行数:39,代码来源:CFileChooser.java


注:本文中的java.awt.FileDialog.setMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。