java.awt.FileDialog#setVisible ( )源码实例Demo

下面列出了java.awt.FileDialog#setVisible ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: EchoSim   文件: SuitePanel.java
private void doLoadDisk()
{
    FileDialog fd = new FileDialog(getFrame(), "Load Test Suite", FileDialog.LOAD);
    fd.setDirectory(RuntimeLogic.getProp("suite.file.dir"));
    fd.setFile(RuntimeLogic.getProp("suite.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
    {
        SuiteLogic.load(mRuntime, new File(historyFile));
        RuntimeLogic.setProp("suite.file.dir", fd.getDirectory());
        RuntimeLogic.setProp("suite.file.file", fd.getFile());
    }
    catch (IOException e)
    {
        JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE);
    }
}
 
源代码2 项目: mpcmaid   文件: MainFrame.java
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();
	}
}
 
源代码3 项目: EchoSim   文件: TestingPanel.java
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);
    }
}
 
源代码4 项目: EchoSim   文件: TestingPanel.java
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);
    }
}
 
源代码5 项目: toxiclibs   文件: FileUtils.java
/**
 * 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 formats
 *            an array of allowed file extensions (or null to allow all)
 * @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, final String[] formats, final int mode) {
    String fileID = null;
    FileDialog fd = new FileDialog(frame, title, mode);
    if (path != null) {
        fd.setDirectory(path);
    }
    if (formats != null) {
        fd.setFilenameFilter(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                boolean isAccepted = false;
                for (String ext : formats) {
                    if (name.indexOf(ext) != -1) {
                        isAccepted = true;
                        break;
                    }
                }
                return isAccepted;
            }
        });
    }
    fd.setVisible(true);
    if (fd.getFile() != null) {
        fileID = fd.getFile();
        fileID = fd.getDirectory() + fileID;
    }
    return fileID;
}
 
源代码6 项目: CQL   文件: FileChooser.java
/**
 *
 *
 * @param title
 * @param mode
 * @param filter
 *
 * @return
 */
private static File chooseFileAWT(String title, Mode mode, FileFilter filter) {
	Easik e = Easik.getInstance();
	EasikSettings s = e.getSettings();
	FileDialog dialog = new FileDialog(e.getFrame(), title,
			(mode == Mode.SAVE) ? FileDialog.SAVE : FileDialog.LOAD);

	dialog.setDirectory(s.getDefaultFolder());

	if ((mode == Mode.DIRECTORY) && EasikConstants.RUNNING_ON_MAC) {
		System.setProperty("apple.awt.fileDialogForDirectories", "true");
	} else if (filter != null) {
		dialog.setFilenameFilter(filter);
	}

	// Show the dialog (this blocks until the user is done)
	dialog.setVisible(true);

	if ((mode == Mode.DIRECTORY) && EasikConstants.RUNNING_ON_MAC) {
		System.setProperty("apple.awt.fileDialogForDirectories", "false");
	}

	String filename = dialog.getFile();

	if (filename == null) {
		return null;
	}

	File selected = new File(dialog.getDirectory(), filename);

	if (mode != Mode.DIRECTORY) {
		s.setProperty("folder_last", selected.getParentFile().getAbsolutePath());
	}

	return selected;
}
 
源代码7 项目: binnavi   文件: CFileChooser.java
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;
}
 
源代码8 项目: algs4   文件: StdDraw.java
/**
 * This method cannot be called directly.
 */
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog chooser = new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
    chooser.setVisible(true);
    String filename = chooser.getFile();
    if (filename != null) {
        StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
    }
}
 
源代码9 项目: mpcmaid   文件: MainFrame.java
public void saveAs() {
	final FileDialog saveDialog = new FileDialog(this);
	saveDialog.setDirectory(Preferences.getInstance().getSavePath());
	saveDialog.setMode(FileDialog.SAVE);
	saveDialog.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;
		}
	});
	saveDialog.setVisible(true);
	Preferences.getInstance().setSavePath(saveDialog.getDirectory());
	String filename = saveDialog.getFile();
	if (saveDialog.getDirectory() != null && filename != null) {
		if (!filename.toUpperCase().endsWith(".PGM")) {
			filename += ".PGM";
		}
		String filePath = saveDialog.getDirectory() + filename;
		System.out.println(filePath);
		final File file = new File(filePath);
		setPgmFile(file);
		program.save(pgmFile);
	}
}
 
源代码10 项目: xyTalk-pc   文件: FilesIO.java
public static void saveAsFile(String filePathFull, String fileName) {
	try {
		File f=new File(filePathFull);
		if(f.exists()){
			if (filePathFull == null || filePathFull.trim().length() == 0)
				return;

			FileDialog fd = new FileDialog(new Frame(), "文件另存为",
					FileDialog.SAVE);
			fd.setFile(fileName);
			//fd.setIconImage(SparkManager.getMainWindow().getIconImage());
			fd.toFront();

			fd.setVisible(true);

			if (fd.getFile() != null) {
				copyFile(new File(filePathFull), new File(fd.getDirectory()),fd.getFile());
			} else {
				fd.setAlwaysOnTop(false);
			}
		}else{
			JOptionPane.showMessageDialog(null, Res.FILE_NOT_FOUND, "提示", 1);
		}
	} catch (Exception ex) {
		log.error(ex.getMessage());
	}
}
 
源代码11 项目: marathonv5   文件: FileDialogElement.java
@Override
public void sendKeys(CharSequence... keysToSend) {
    FileDialog fileDialog = (FileDialog) dialog.getWindow();
    String filePath = (String) keysToSend[0];
    String setPath = "";
    if (filePath != null && !"".equals(filePath)) {
        setPath = ChooserHelper.decodeFile(filePath).getPath();
    }
    fileDialog.setFile(setPath);
    fileDialog.setVisible(false);
}
 
源代码12 项目: swingsane   文件: CustomSettingsDialog.java
private File getLoadFile(String filename, String extension) {
  FileDialog fd = new FileDialog((JDialog) getRootPane().getTopLevelAncestor(),
      Localizer.localize("LoadScannerOptionsFromFileTitle"), FileDialog.LOAD);
  fd.setDirectory(".");
  FilenameExtensionFilter filter = new FilenameExtensionFilter();
  filter.addExtension("xml");
  fd.setFilenameFilter(filter);
  fd.setModal(true);
  fd.setVisible(true);
  if (fd.getFile() == null) {
    return null;
  }
  return new File(fd.getDirectory() + File.separator + fd.getFile());
}
 
源代码13 项目: BART   文件: Export.java
private File chooseFile() {
    JFrame mainFrame = (JFrame) WindowManager.getDefault().getMainWindow();
    FileDialog fileDialog = new FileDialog(mainFrame, new File(System.getProperty("user.home")).toString());
    fileDialog.setTitle("Export changes in cvs file");
    fileDialog.setFile("expected.csv");
    fileDialog.setMode(FileDialog.SAVE);
    fileDialog.setFilenameFilter(new ExtFileFilter("csv"));
    fileDialog.setVisible(true);
    String filename = fileDialog.getFile();
    if (filename == null){
        return null;
    }
    String dir = fileDialog.getDirectory();
    return new File(dir + File.separator + filename);
}
 
源代码14 项目: Spark   文件: ChatRoomTransferDecorator.java
private void showFilePicker() {
     SwingWorker worker = new SwingWorker() {
         @Override
public Object construct() {
             try {
                 Thread.sleep(10);
             }
             catch (InterruptedException e1) {
                 Log.error(e1);
             }
             return true;
         }

         @Override
public void finished() {
             FileDialog fileChooser = SparkManager.getTransferManager().getFileChooser(SparkManager.getChatManager().getChatContainer().getChatFrame(), Res.getString("title.select.file.to.send"));
             if (SparkManager.getTransferManager().getDefaultDirectory() != null)
             {
                 fileChooser.setDirectory(SparkManager.getTransferManager().getDefaultDirectory().getAbsolutePath());
             }
             fileChooser.setVisible(true);

             final File[] files = fileChooser.getFiles();
             if ( files.length == 0) {
                 // no selection
                 return;
             }

             File file = files[0]; // Single-file selection is used. Using the first array item is safe.

             if (file.exists()) {
                 SparkManager.getTransferManager().setDefaultDirectory(file.getParentFile());
                 SparkManager.getTransferManager().sendFile(file, ((ChatRoomImpl)chatRoom).getParticipantJID());
             }

         }
     };
     worker.start();
 }
 
源代码15 项目: JWT4B   文件: JWTInterceptTabController.java
private void radioButtonChanged(boolean cDM, boolean cRK, boolean cOS, boolean cRS, boolean cCS) {
	boolean oldRandomKey = randomKey;

	dontModify = jwtST.getRdbtnDontModify().isSelected();
	randomKey = jwtST.getRdbtnRandomKey().isSelected();
	keepOriginalSignature = jwtST.getRdbtnOriginalSignature().isSelected();
	recalculateSignature = jwtST.getRdbtnRecalculateSignature().isSelected();
	chooseSignature = jwtST.getRdbtnChooseSignature().isSelected();

	jwtST.setKeyFieldState(!keepOriginalSignature && !dontModify && !randomKey && !chooseSignature);

	if (keepOriginalSignature || dontModify) {
		jwtIM.setJWTKey("");
		jwtST.setKeyFieldValue("");
	}
	if (randomKey && !oldRandomKey) {
		generateRandomKey();
	}
	if (cCS) {
		FileDialog dialog = new FileDialog((Frame) null, "Select File to Open");
		dialog.setMode(FileDialog.LOAD);
		dialog.setVisible(true);
		if(dialog.getFile()!=null) {
			String file = dialog.getDirectory() + dialog.getFile();
			Output.output(file + " chosen.");
			String chosen = Strings.filePathToString(file);
			jwtIM.setJWTKey(chosen);
			jwtST.updateSetView(false);	
		}
	}
}
 
源代码16 项目: java_jail   文件: Picture.java
/**
 * Opens a save dialog box when the user selects "Save As" from the menu.
 */
public void actionPerformed(ActionEvent e) {
    FileDialog chooser = new FileDialog(frame,
                         "Use a .png or .jpg extension", FileDialog.SAVE);
    chooser.setVisible(true);
    if (chooser.getFile() != null) {
        save(chooser.getDirectory() + File.separator + chooser.getFile());
    }
}
 
源代码17 项目: wandora   文件: RBridge.java
@Override
public String rChooseFile(Rengine re, int newFile) {
    FileDialog fd = new FileDialog(Wandora.getWandora(), (newFile==0)?"Select a file":"Select a new file", (newFile==0)?FileDialog.LOAD:FileDialog.SAVE);
    fd.setVisible(true);
    String res=null;
    if (fd.getDirectory()!=null) res=fd.getDirectory();
    if (fd.getFile()!=null) res=(res==null)?fd.getFile():(res+fd.getFile());
    return res;
}
 
源代码18 项目: jdk8u_jdk   文件: PolicyTool.java
/**
 * perform SAVE AS
 */
void displaySaveAsDialog(int nextEvent) {

    // pop up a dialog box for the user to enter a filename.
    FileDialog fd = new FileDialog
            (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
    fd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
        }
    });
    fd.setVisible(true);

    // see if the user hit cancel
    if (fd.getFile() == null ||
        fd.getFile().equals(""))
        return;

    // get the entered filename
    File saveAsFile = new File(fd.getDirectory(), fd.getFile());
    String filename = saveAsFile.getPath();
    fd.dispose();

    try {
        // save the policy entries to a file
        tool.savePolicy(filename);

        // display status
        MessageFormat form = new MessageFormat(PolicyTool.getMessage
                ("Policy.successfully.written.to.filename"));
        Object[] source = {filename};
        tw.displayStatusDialog(null, form.format(source));

        // display the new policy filename
        JTextField newFilename = (JTextField)tw.getComponent
                        (ToolWindow.MW_FILENAME_TEXTFIELD);
        newFilename.setText(filename);
        tw.setVisible(true);

        // now continue with the originally requested command
        // (QUIT, NEW, or OPEN)
        userSaveContinue(tool, tw, this, nextEvent);

    } catch (FileNotFoundException fnfe) {
        if (filename == null || filename.equals("")) {
            tw.displayErrorDialog(null, new FileNotFoundException
                        (PolicyTool.getMessage("null.filename")));
        } else {
            tw.displayErrorDialog(null, fnfe);
        }
    } catch (Exception ee) {
        tw.displayErrorDialog(null, ee);
    }
}
 
源代码19 项目: openjdk-jdk9   文件: DragEventSource.java
public void actionPerformed (ActionEvent ae) {
    FileDialog fd = new FileDialog (frame, "Image Selector", FileDialog.LOAD);
    fd.setVisible(true);
}
 
源代码20 项目: openjdk-8   文件: PolicyTool.java
/**
 * perform SAVE AS
 */
void displaySaveAsDialog(int nextEvent) {

    // pop up a dialog box for the user to enter a filename.
    FileDialog fd = new FileDialog
            (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
    fd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
        }
    });
    fd.setVisible(true);

    // see if the user hit cancel
    if (fd.getFile() == null ||
        fd.getFile().equals(""))
        return;

    // get the entered filename
    File saveAsFile = new File(fd.getDirectory(), fd.getFile());
    String filename = saveAsFile.getPath();
    fd.dispose();

    try {
        // save the policy entries to a file
        tool.savePolicy(filename);

        // display status
        MessageFormat form = new MessageFormat(PolicyTool.getMessage
                ("Policy.successfully.written.to.filename"));
        Object[] source = {filename};
        tw.displayStatusDialog(null, form.format(source));

        // display the new policy filename
        JTextField newFilename = (JTextField)tw.getComponent
                        (ToolWindow.MW_FILENAME_TEXTFIELD);
        newFilename.setText(filename);
        tw.setVisible(true);

        // now continue with the originally requested command
        // (QUIT, NEW, or OPEN)
        userSaveContinue(tool, tw, this, nextEvent);

    } catch (FileNotFoundException fnfe) {
        if (filename == null || filename.equals("")) {
            tw.displayErrorDialog(null, new FileNotFoundException
                        (PolicyTool.getMessage("null.filename")));
        } else {
            tw.displayErrorDialog(null, fnfe);
        }
    } catch (Exception ee) {
        tw.displayErrorDialog(null, ee);
    }
}