當前位置: 首頁>>代碼示例>>Java>>正文


Java FileDialog.setDirectory方法代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:FileChooserBuilder.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:FileDialogForPackages.java

示例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;
}
 
開發者ID:addertheblack,項目名稱:myster,代碼行數:22,代碼來源:DownloaderThread.java

示例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());
        }
    }
}
 
開發者ID:Helioviewer-Project,項目名稱:JHelioviewer-SWHV,代碼行數:22,代碼來源:OpenLocalFileAction.java

示例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());
        }
    }
}
 
開發者ID:Helioviewer-Project,項目名稱:JHelioviewer-SWHV,代碼行數:22,代碼來源:OpenLocalFileAction.java

示例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);
    }
}
 
開發者ID:jjaquinta,項目名稱:EchoSim,代碼行數:23,代碼來源:ApplicationPanel.java

示例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);
    }
}
 
開發者ID:jjaquinta,項目名稱:EchoSim,代碼行數:23,代碼來源:ApplicationPanel.java

示例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);
    }
}
 
開發者ID:jjaquinta,項目名稱:EchoSim,代碼行數:23,代碼來源:TestingPanel.java

示例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);
    }
}
 
開發者ID:jjaquinta,項目名稱:EchoSim,代碼行數:23,代碼來源:ScriptPanel.java

示例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;
  }
}
 
開發者ID:tinyMediaManager,項目名稱:tinyMediaManager,代碼行數:24,代碼來源:TmmUIHelper.java

示例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;
}
 
開發者ID:postspectacular,項目名稱:toxiclibs,代碼行數:34,代碼來源:FileUtils.java

示例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;
  }
}
 
開發者ID:tinyMediaManager,項目名稱:tinyMediaManager,代碼行數:21,代碼來源:TmmUIHelper.java

示例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);
    }
}
 
開發者ID:jjaquinta,項目名稱:EchoSim,代碼行數:23,代碼來源:TestingPanel.java

示例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();
	}
}
 
開發者ID:cyriux,項目名稱:mpcmaid,代碼行數:26,代碼來源:MainFrame.java

示例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);
	}
}
 
開發者ID:ddarriba,項目名稱:prottest3,代碼行數:20,代碼來源:XProtTestView.java


注:本文中的java.awt.FileDialog.setDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。