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

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

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

FileDialog.setDirectory介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

private File showFileDialog (String title, int mode ) {
  FileDialog dialog = new FileDialog(this, title, mode);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) 
    return null;
  lastDir = dir;
  return new File(dir, file);
}

代码示例来源:origin: libgdx/libgdx

private File showFileDialog (String title, int mode ) {
  FileDialog dialog = new FileDialog(this, title, mode);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) 
    return null;
  lastDir = dir;
  return new File(dir, file);
}

代码示例来源:origin: libgdx/libgdx

protected void save () {
  FileDialog dialog = new FileDialog(this, "Save Image", FileDialog.SAVE);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    generatePremultiplyAlpha(new File(dir, file));
    JOptionPane.showMessageDialog(this, "Conversion complete!");
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this, "Error saving image.");
    return;
  }
}

代码示例来源:origin: libgdx/libgdx

protected void save () {
  FileDialog dialog = new FileDialog(this, "Save Image", FileDialog.SAVE);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    generatePremultiplyAlpha(new File(dir, file));
    JOptionPane.showMessageDialog(this, "Conversion complete!");
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this, "Error saving image.");
    return;
  }
}

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.ttf");
    dialog.setDirectory(prefs.get("dir.font", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.font", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.ttf");
    dialog.setDirectory(prefs.get("dir.font", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.font", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent event) {
  FileDialog dialog = new FileDialog(editor, "Select Image", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    final FileHandle absolute = Gdx.files.absolute(dir + file);
    final BufferedImage read = ImageIO.read(absolute.read());
    final Image scaledInstance = read.getScaledInstance(100, -1, Image.SCALE_SMOOTH);
    final ImageIcon image = new ImageIcon(scaledInstance);
    JLabel previewImage = new JLabel(image);
    previewImage.setOpaque(true);
    previewImage.setBackground(Color.MAGENTA);
    buildImagePanel(previewImage, absolute.file());
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent event) {
  FileDialog dialog = new FileDialog(editor, "Select Image", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    final FileHandle absolute = Gdx.files.absolute(dir + file);
    final BufferedImage read = ImageIO.read(absolute.read());
    final Image scaledInstance = read.getScaledInstance(100, -1, Image.SCALE_SMOOTH);
    final ImageIcon image = new ImageIcon(scaledInstance);
    JLabel previewImage = new JLabel(image);
    previewImage.setOpaque(true);
    previewImage.setBackground(Color.MAGENTA);
    buildImagePanel(previewImage, absolute.file());
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: libgdx/libgdx

protected void open () {
  FileDialog dialog = new FileDialog(this, "Open Image", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    image = ImageIO.read(new File(dir, file));
    imagePanel.setImage(image);
    imagePanel.revalidate();
    imagePanel.repaint();
    pack();
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this, "Error opening image.");
    return;
  }
}

代码示例来源:origin: libgdx/libgdx

protected void open () {
  FileDialog dialog = new FileDialog(this, "Open Image", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    image = ImageIO.read(new File(dir, file));
    imagePanel.setImage(image);
    imagePanel.revalidate();
    imagePanel.repaint();
    pack();
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this, "Error opening image.");
    return;
  }
}

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save Hiero settings file", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.save", ""));
    if (lastSaveFilename.length() > 0) {
      dialog.setFile(lastSaveFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename);
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.save", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    if (!fileName.endsWith(".hiero")) fileName += ".hiero";
    lastSaveFilename = fileName;
    File file = new File(dialog.getDirectory(), fileName);
    try {
      save(file);
    } catch (IOException ex) {
      throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
    }
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save Hiero settings file", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.save", ""));
    if (lastSaveFilename.length() > 0) {
      dialog.setFile(lastSaveFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename);
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.save", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    if (!fileName.endsWith(".hiero")) fileName += ".hiero";
    lastSaveFilename = fileName;
    File file = new File(dialog.getDirectory(), fileName);
    try {
      save(file);
    } catch (IOException ex) {
      throw new RuntimeException("Error saving Hiero settings file: " + file.getAbsolutePath(), ex);
    }
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.fnt");
    dialog.setDirectory(prefs.get("dir.savebm", ""));
    if (lastSaveBMFilename.length() > 0) {
      dialog.setFile(lastSaveBMFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.savebm", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastSaveBMFilename = fileName;
    saveBm(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.fnt");
    dialog.setDirectory(prefs.get("dir.savebm", ""));
    if (lastSaveBMFilename.length() > 0) {
      dialog.setFile(lastSaveBMFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.savebm", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastSaveBMFilename = fileName;
    saveBm(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent event) {
    FileDialog dialog = new FileDialog(editor, "Open Image", FileDialog.LOAD);
    if (lastDir != null) dialog.setDirectory(lastDir);
    dialog.setVisible(true);
    final String file = dialog.getFile();
    final String dir = dialog.getDirectory();
    if (dir == null || file == null || file.trim().length() == 0) return;
    lastDir = dir;
    final ParticleEmitter emitter = editor.getEmitter();
    emitter.getImagePaths().add(new File(dir, file).getAbsolutePath());
    emitter.getSprites().clear();
    updateImageList(emitter.getImagePaths());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent event) {
    FileDialog dialog = new FileDialog(editor, "Open Image", FileDialog.LOAD);
    if (lastDir != null) dialog.setDirectory(lastDir);
    dialog.setVisible(true);
    final String file = dialog.getFile();
    final String dir = dialog.getDirectory();
    if (dir == null || file == null || file.trim().length() == 0) return;
    lastDir = dir;
    final ParticleEmitter emitter = editor.getEmitter();
    emitter.getImagePaths().add(new File(dir, file).getAbsolutePath());
    emitter.getSprites().clear();
    updateImageList(emitter.getImagePaths());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.open", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.open", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastOpenFilename = fileName;
    open(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.open", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.open", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastOpenFilename = fileName;
    open(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

void openEffect (boolean mergeIntoCurrent) {
  FileDialog dialog = new FileDialog(editor, "Open Effect", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();

代码示例来源:origin: libgdx/libgdx

void openEffect (boolean mergeIntoCurrent) {
  FileDialog dialog = new FileDialog(editor, "Open Effect", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();

相关文章