本文整理匯總了Java中java.awt.FileDialog.setDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java FileDialog.setDirectory方法的具體用法?Java FileDialog.setDirectory怎麽用?Java FileDialog.setDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.FileDialog
的用法示例。
在下文中一共展示了FileDialog.setDirectory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: actionPerformed
import java.awt.FileDialog; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
FileDialog fileDialog = new FileDialog(ImageViewerGui.getMainFrame(), "Choose a file", FileDialog.LOAD);
// does not work on Windows
fileDialog.setFilenameFilter(new AllFilenameFilter());
fileDialog.setMultipleMode(true);
fileDialog.setDirectory(Settings.getSingletonInstance().getProperty("default.local.path"));
fileDialog.setVisible(true);
String directory = fileDialog.getDirectory();
File[] fileNames = fileDialog.getFiles();
if (fileNames.length > 0 && directory != null) {
// remember the current directory for future
Settings.getSingletonInstance().setProperty("default.local.path", directory);
Settings.getSingletonInstance().save("default.local.path");
for (File fileName : fileNames) {
if (fileName.isFile())
Load.image.get(fileName.toURI());
}
}
}
示例5: actionPerformed
import java.awt.FileDialog; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
FileDialog fileDialog = new FileDialog(ImageViewerGui.getMainFrame(), "Choose a file", FileDialog.LOAD);
// does not work on Windows
fileDialog.setFilenameFilter(new JsonFilenameFilter());
fileDialog.setMultipleMode(true);
fileDialog.setDirectory(Settings.getSingletonInstance().getProperty("default.local.path"));
fileDialog.setVisible(true);
String directory = fileDialog.getDirectory();
File[] fileNames = fileDialog.getFiles();
if (fileNames.length > 0 && directory != null) {
// remember the current directory for future
Settings.getSingletonInstance().setProperty("default.local.path", directory);
Settings.getSingletonInstance().save("default.local.path");
for (File fileName : fileNames) {
if (fileName.isFile())
Load.timeline.get(fileName.toURI());
}
}
}
示例6: doIntentLoadFile
import java.awt.FileDialog; //導入方法依賴的package包/類
protected void doIntentLoadFile()
{
FileDialog fd = new FileDialog(getFrame(), "Load Intent File", FileDialog.LOAD);
fd.setDirectory(RuntimeLogic.getProp("intent.file.dir"));
fd.setFile(RuntimeLogic.getProp("intent.file.file"));
fd.setVisible(true);
if (fd.getDirectory() == null)
return;
String intentFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile();
if ((intentFile == null) || (intentFile.length() == 0))
return;
try
{
RuntimeLogic.readIntents(mRuntime, (new File(intentFile)).toURI());
RuntimeLogic.setProp("intent.file.dir", fd.getDirectory());
RuntimeLogic.setProp("intent.file.file", fd.getFile());
}
catch (IOException e)
{
JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+intentFile, JOptionPane.ERROR_MESSAGE);
}
}
示例7: doUtteranceLoadFile
import java.awt.FileDialog; //導入方法依賴的package包/類
protected void doUtteranceLoadFile()
{
FileDialog fd = new FileDialog(getFrame(), "Load Utterance File", FileDialog.LOAD);
fd.setDirectory(RuntimeLogic.getProp("utterance.file.dir"));
fd.setFile(RuntimeLogic.getProp("utterance.file.file"));
fd.setVisible(true);
if (fd.getDirectory() == null)
return;
String intentFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile();
if ((intentFile == null) || (intentFile.length() == 0))
return;
try
{
RuntimeLogic.readUtterances(mRuntime, (new File(intentFile)).toURI());
RuntimeLogic.setProp("utterance.file.dir", fd.getDirectory());
RuntimeLogic.setProp("utterance.file.file", fd.getFile());
}
catch (IOException e)
{
JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+intentFile, JOptionPane.ERROR_MESSAGE);
}
}
示例8: doSave
import java.awt.FileDialog; //導入方法依賴的package包/類
private void doSave()
{
FileDialog fd = new FileDialog(getFrame(), "Save History File", FileDialog.SAVE);
fd.setDirectory(RuntimeLogic.getProp("history.file.dir"));
fd.setFile(RuntimeLogic.getProp("history.file.file"));
fd.setVisible(true);
if (fd.getDirectory() == null)
return;
String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile();
if ((historyFile == null) || (historyFile.length() == 0))
return;
try
{
RuntimeLogic.saveHistory(mRuntime, new File(historyFile));
RuntimeLogic.setProp("history.file.dir", fd.getDirectory());
RuntimeLogic.setProp("history.file.file", fd.getFile());
}
catch (IOException e)
{
JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE);
}
}
示例9: doSaveDisk
import java.awt.FileDialog; //導入方法依賴的package包/類
private void doSaveDisk()
{
FileDialog fd = new FileDialog(getFrame(), "Save Script", FileDialog.SAVE);
fd.setDirectory(RuntimeLogic.getProp("script.file.dir"));
fd.setFile(RuntimeLogic.getProp("script.file.file"));
fd.setVisible(true);
if (fd.getDirectory() == null)
return;
String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile();
if ((historyFile == null) || (historyFile.length() == 0))
return;
try
{
ScriptLogic.saveScript(mRuntime, new File(historyFile));
RuntimeLogic.setProp("script.file.dir", fd.getDirectory());
RuntimeLogic.setProp("script.file.file", fd.getFile());
}
catch (IOException e)
{
JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE);
}
}
示例10: openDirectoryDialog
import java.awt.FileDialog; //導入方法依賴的package包/類
private static Path openDirectoryDialog(String title, String initialPath) throws Exception, Error {
// set system property to choose directories
System.setProperty("apple.awt.fileDialogForDirectories", "true");
FileDialog chooser = new FileDialog(MainWindow.getFrame(), title);
if (StringUtils.isNotBlank(initialPath)) {
Path path = Paths.get(initialPath);
if (Files.exists(path)) {
chooser.setDirectory(path.toFile().getAbsolutePath());
}
}
chooser.setVisible(true);
// reset system property
System.setProperty("apple.awt.fileDialogForDirectories", "false");
if (StringUtils.isNotEmpty(chooser.getFile())) {
return Paths.get(chooser.getDirectory(), chooser.getFile());
}
else {
return null;
}
}
示例11: showFileDialog
import java.awt.FileDialog; //導入方法依賴的package包/類
/**
* Displays a standard AWT file dialog for choosing a file for loading or
* saving.
*
* @param frame
* parent frame
* @param title
* dialog title
* @param path
* base directory (or null)
* @param filter
* a FilenameFilter implementation (or null)
* @param mode
* either FileUtils.LOAD or FileUtils.SAVE
* @return path to chosen file or null, if user has canceled
*/
public static String showFileDialog(final Frame frame, final String title,
String path, FilenameFilter filter, final int mode) {
String fileID = null;
FileDialog fd = new FileDialog(frame, title, mode);
if (path != null) {
fd.setDirectory(path);
}
if (filter != null) {
fd.setFilenameFilter(filter);
}
fd.setVisible(true);
if (fd.getFile() != null) {
fileID = fd.getFile();
fileID = fd.getDirectory() + fileID;
}
return fileID;
}
示例12: openFileDialog
import java.awt.FileDialog; //導入方法依賴的package包/類
private static Path openFileDialog(String title, String initialPath, int mode, String filename) throws Exception, Error {
FileDialog chooser = new FileDialog(MainWindow.getFrame(), title, mode);
if (StringUtils.isNotBlank(initialPath)) {
Path path = Paths.get(initialPath);
if (Files.exists(path)) {
chooser.setDirectory(path.toFile().getAbsolutePath());
}
}
if (mode == FileDialog.SAVE) {
chooser.setFile(filename);
}
chooser.setVisible(true);
if (StringUtils.isNotEmpty(chooser.getFile())) {
return Paths.get(chooser.getDirectory(), chooser.getFile());
}
else {
return null;
}
}
示例13: doLoad
import java.awt.FileDialog; //導入方法依賴的package包/類
private void doLoad()
{
FileDialog fd = new FileDialog(getFrame(), "Load History File", FileDialog.LOAD);
fd.setDirectory(RuntimeLogic.getProp("history.file.dir"));
fd.setFile(RuntimeLogic.getProp("history.file.file"));
fd.setVisible(true);
if (fd.getDirectory() == null)
return;
String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile();
if ((historyFile == null) || (historyFile.length() == 0))
return;
try
{
RuntimeLogic.loadHistory(mRuntime, new File(historyFile));
RuntimeLogic.setProp("history.file.dir", fd.getDirectory());
RuntimeLogic.setProp("history.file.file", fd.getFile());
}
catch (IOException e)
{
JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE);
}
}
示例14: 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();
}
}
示例15: saveConsole
import java.awt.FileDialog; //導入方法依賴的package包/類
private void saveConsole(java.awt.event.ActionEvent evt) {
String text = mainTextArea.getText();
FileDialog fc = new FileDialog(this.getFrame(),
"Save ProtTest console", FileDialog.SAVE);
fc.setDirectory(System.getProperty("user.dir"));
fc.setVisible(true);
String dataFileName = fc.getFile();
try {
File f = new File(dataFileName);
FileWriter fw = new FileWriter(f);
fw.write(text);
fw.close();
} catch (IOException ex) {
Logger.getLogger(XProtTestView.class.getName()).log(Level.SEVERE,
null, ex);
}
}