java.awt.FileDialog.setMode()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(210)

本文整理了Java中java.awt.FileDialog.setMode()方法的一些代码示例,展示了FileDialog.setMode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileDialog.setMode()方法的具体详情如下:
包路径:java.awt.FileDialog
类名称:FileDialog
方法名:setMode

FileDialog.setMode介绍

暂无

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

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;
}

代码示例来源:origin: sarahtattersall/PIPE

/**
 * @param temporary path to copy to new location
 * @param message   displayed message in save file dialog pop up
 */
private void copyFile(Path temporary, String message) {
  loadDialog.setMode(FileDialog.SAVE);
  loadDialog.setTitle(message);
  loadDialog.setVisible(true);
  File[] files = loadDialog.getFiles();
  if (files.length > 0) {
    File file = files[0];
    Path path = Paths.get(file.toURI());
    try {
      Files.copy(temporary, path, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
      LOGGER.log(Level.SEVERE, e.getMessage());
    }
  }
}

代码示例来源:origin: stackoverflow.com

FileDialog dialog = new FileDialog((Frame)null, "Select File to Open");
 dialog.setMode(FileDialog.LOAD);
 dialog.setVisible(true);
 String file = dialog.getFile();
 System.out.println(file + " chosen.");

代码示例来源:origin: igvteam/igv

private void saveItemActionPerformed(ActionEvent e) {
  java.util.List<ColorPanel.Palette> paletteList = colorPanel.paletteList;
  if (paletteList != null) {
    java.awt.FileDialog fd = new FileDialog(this);
    fd.setMode(FileDialog.SAVE);
    fd.setVisible(true);
    String f = fd.getFile();
    if (f != null) {
      try {
        File file = new File(fd.getDirectory(), f);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
        for (ColorPanel.Palette p : paletteList) {
          pw.println(p.label);
          for (ColorPanel.Swatch s : p.swatches) {
            pw.println(ColorUtilities.colorToString(s.color));
          }
        }
      } catch (Exception e1) {
        e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      }
    }
  }
}

代码示例来源:origin: com.nativelibs4java/javacl-demos-jna

static File chooseFile() {
  if (Platform.isMac()) {
    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;
}
 public static void main(String[] args) {

代码示例来源:origin: nativelibs4java/JavaCL

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;
}
 public static void main(String[] args) {

代码示例来源:origin: com.nativelibs4java/javacl-demos

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;
}
 public static void main(String[] args) {

代码示例来源:origin: sarahtattersall/PIPE

/**
 * Opens the file dialog and saves the selected Petri net into lastLoadedPetriNet
 * for use when calculating the state space exploration
 */
private void loadData() {
  loadDialog.setMode(FileDialog.LOAD);
  loadDialog.setTitle("Select petri net");
  loadDialog.setVisible(true);
  File[] files = loadDialog.getFiles();
  if (files.length > 0) {
    File path = files[0];
    try {
      petriNetNameLabel.setText(path.getName());
      PetriNetReader petriNetIO = new PetriNetIOImpl();
      lastLoadedPetriNet = petriNetIO.read(path.getAbsolutePath());
    } catch (JAXBException | FileNotFoundException e) {
      LOGGER.log(Level.SEVERE, e.getMessage());
    }
  }
}

代码示例来源:origin: nativelibs4java/JavaCL

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;
}

代码示例来源:origin: nativelibs4java/JavaCL

@SuppressWarnings("deprecation")
@Override
public void actionPerformed(ActionEvent ae) {
  boolean paused = demo.paused;
  demo.paused = true;
  FileDialog fc = new FileDialog((Frame)null);
  fc.setMode(FileDialog.LOAD);
  fc.show();
  if (fc.getFile() != null) {
    try {
      BufferedImage im = ImageIO.read(lastFile = new File(new File(fc.getDirectory()), fc.getFile()));
      demo.setImage(im);
    } catch (Exception ex) {
      ParticlesDemo.exception(ex);
      Logger.getLogger(ParticlesDemo.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  demo.paused = paused;
}

代码示例来源:origin: org.scijava/scijava-ui-awt

@Override
public void actionPerformed(final ActionEvent e) {
  File file = new File(path.getText());
  if (!file.isDirectory()) {
    file = file.getParentFile();
  }
  // display file chooser in appropriate mode
  final String style = get().getItem().getWidgetStyle();
  final FileDialog fileDialog = new FileDialog((Frame) null);
  if (FileWidget.SAVE_STYLE.equals(style)) {
    fileDialog.setMode(FileDialog.SAVE);
  }
  else { // default behavior
    fileDialog.setMode(FileDialog.LOAD);
  }
  fileDialog.setDirectory(file.getAbsolutePath());
  fileDialog.setVisible(true);
  final String filename = fileDialog.getFile();
  fileDialog.dispose();
  if (filename == null) return;
  path.setText(filename);
}

代码示例来源:origin: igvteam/igv

private static FileDialog getNativeChooser(String title, File initialDirectory, File initialFile, FilenameFilter filter, int directoryMode, int mode) {
  boolean directories = JFileChooser.DIRECTORIES_ONLY == directoryMode;
  System.setProperty("apple.awt.fileDialogForDirectories", String.valueOf(directories));
  Frame parentFrame = getParentFrame();
  FileDialog fd = new FileDialog(parentFrame, title);
  if (initialDirectory != null) {
    fd.setDirectory(initialDirectory.getAbsolutePath());
  }
  if (initialFile != null) {
    fd.setFile(initialFile.getName());
  }
  if (filter != null) {
    fd.setFilenameFilter(filter);
  }
  fd.setModal(true);
  fd.setMode(mode);
  if (mode == LOAD && !directories) {
    setMultipleMode(fd, true);
  }
  return fd;
}

代码示例来源:origin: elki-project/elki

/**
 * 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();
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki

/**
 * 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();
}

代码示例来源:origin: us.ihmc/DarpaRoboticsChallenge

public static File selectionFileDialog()
{
 
 final FileDialog fileDialog = new FileDialog((Frame) null, "Choose reachability map to load");
 fileDialog.setMode(FileDialog.LOAD);
 fileDialog.setVisible(true);
 String directory = fileDialog.getDirectory();
 String filename = fileDialog.getFile();
 fileDialog.dispose();
 if (directory != null && filename != null)
 {
   return new File(directory, filename);
 }
 else
 {
   return null;
 }
}

代码示例来源:origin: us.ihmc/ihmc-avatar-interfaces

public static File selectionFileDialog()
{
 
 final FileDialog fileDialog = new FileDialog((Frame) null, "Choose reachability map to load");
 fileDialog.setMode(FileDialog.LOAD);
 fileDialog.setVisible(true);
 String directory = fileDialog.getDirectory();
 String filename = fileDialog.getFile();
 fileDialog.dispose();
 if (directory != null && filename != null)
 {
   return new File(directory, filename);
 }
 else
 {
   return null;
 }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils-ui

public int showFileDialog(FileDialog fileDialog, int mode) {
  String oldFileDialogProp = System.getProperty("apple.awt.fileDialogForDirectories"); //NOI18N
  boolean dirsOnly = getFileSelectionMode() == DIRECTORIES_ONLY;
  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) {
    setSelectedFile(new File(fileDialog.getDirectory(), fileDialog.getFile()));
    setSelectedFiles(new File[]{new File(fileDialog.getDirectory(), fileDialog.getFile())});            
    return JFileChooser.APPROVE_OPTION;
  }
  return JFileChooser.CANCEL_OPTION;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils

public int showFileDialog(FileDialog fileDialog, int mode) {
  String oldFileDialogProp = System.getProperty("apple.awt.fileDialogForDirectories"); //NOI18N
  boolean dirsOnly = getFileSelectionMode() == DIRECTORIES_ONLY;
  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) {
    setSelectedFile(new File(fileDialog.getDirectory(), fileDialog.getFile()));
    setSelectedFiles(new File[]{new File(fileDialog.getDirectory(), fileDialog.getFile())});            
    return JFileChooser.APPROVE_OPTION;
  }
  return JFileChooser.CANCEL_OPTION;
}

代码示例来源:origin: triplea-game/triplea

/**
  * Opens up a UI pop-up allowing user to select a game file. Returns nothing if user closes the pop-up.
  */
 public static Optional<File> selectGameFile() {
  // For some strange reason, the only way to get a Mac OS X native-style file dialog
  // is to use an AWT FileDialog instead of a Swing JDialog
  if (SystemProperties.isMac()) {
   final FileDialog fileDialog = GameRunner.newFileDialog();
   fileDialog.setMode(FileDialog.LOAD);
   fileDialog.setDirectory(ClientSetting.saveGamesFolderPath.getValueOrThrow().toString());
   fileDialog.setFilenameFilter((dir, name) -> GameDataFileUtils.isCandidateFileName(name));
   fileDialog.setVisible(true);
   final String fileName = fileDialog.getFile();
   final String dirName = fileDialog.getDirectory();
   return Optional.ofNullable(fileName)
     .map(name -> new File(dirName, fileName));
  }

  return GameRunner.showSaveGameFileChooser();
 }
}

代码示例来源:origin: com.bbossgroups/bboss-htmlparser

/**
 * The action to take when "Open" menu or button pressed.
 */
protected void openAction ()
{
  FileDialog dialog;
  File file;
  dialog = new FileDialog (this);
  dialog.setMode (FileDialog.LOAD);
  dialog.setTitle ("Open");
  dialog.setDirectory (mHomeDir);
  dialog.setVisible (true);
  if (null != dialog.getFile ())
  {
    mHomeDir = dialog.getDirectory ();
    file = new File (mHomeDir + dialog.getFile ());
    open (file.getAbsolutePath ());
    setTitle (TITLE + " - " + file.getAbsolutePath ());
  }
}

相关文章