+ static class FileDialogHelper extends FileDialog implements WindowListener, ComponentListener {
+ Semaphore s;
+ public FileDialogHelper(String suggestedFileName, Semaphore s, boolean write) {
+ super(new Frame(), write ? "Save" : "Open", write ? FileDialog.SAVE : FileDialog.LOAD);
+ this.s = s;
+ addWindowListener(this);
+ addComponentListener(this);
+ if (suggestedFileName.indexOf(File.separatorChar) == -1) {
+ setFile(suggestedFileName);
+ } else {
+ setDirectory(suggestedFileName.substring(0, suggestedFileName.lastIndexOf(File.separatorChar)));
+ setFile(suggestedFileName.substring(suggestedFileName.lastIndexOf(File.separatorChar) + 1));
+ }
+ show();
+ }
+ public void windowActivated(WindowEvent e) { }
+ public void windowClosed(WindowEvent e) { s.release(); }
+ public void windowClosing(WindowEvent e) { }
+ public void windowDeactivated(WindowEvent e) { }
+ public void windowDeiconified(WindowEvent e) { }
+ public void windowIconified(WindowEvent e) { }
+ public void windowOpened(WindowEvent e) { }
+ public void componentHidden(ComponentEvent e) { s.release(); }
+ public void componentMoved(ComponentEvent e) { }
+ public void componentResized(ComponentEvent e) { }
+ public void componentShown(ComponentEvent e) { }
+ };
+
+ protected String _fileDialog(String suggestedFileName, boolean write) {
+ final Semaphore s = new Semaphore();
+ FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, write);
+ s.block();
+ return fd.getDirectory() == null ? null : (fd.getDirectory() + File.separatorChar + fd.getFile());
+ }
+
+