Java Code Examples for java.awt.FileDialog

The following are top voted examples for showing how to use java.awt.FileDialog. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: FileChooserBuilder.java   Source Code and License 9 votes vote down vote up
private File showFileDialog( FileDialog fileDialog, int mode ) {
    String oldFileDialogProp = System.getProperty("apple.awt.fileDialogForDirectories"); //NOI18N
    if( dirsOnly ) {
        System.setProperty("apple.awt.fileDialogForDirectories", "true"); //NOI18N
    }
    fileDialog.setMode( mode );
    fileDialog.setVisible(true);
    if( dirsOnly ) {
        if( null != oldFileDialogProp ) {
            System.setProperty("apple.awt.fileDialogForDirectories", oldFileDialogProp); //NOI18N
        } else {
            System.clearProperty("apple.awt.fileDialogForDirectories"); //NOI18N
        }
    }
    if( fileDialog.getDirectory() != null && fileDialog.getFile() != null ) {
        String selFile = fileDialog.getFile();
        File dir = new File( fileDialog.getDirectory() );
        return new File( dir, selFile );
    }
    return null;
}
 
Example 2
Project: VASSAL-src   File: FileChooser.java   Source Code and License 7 votes vote down vote up
public int showSaveDialog(Component parent) {
  final FileDialog fd = awt_file_dialog_init(parent);
  fd.setMode(FileDialog.SAVE);
  fd.setVisible(true);

  final int value;
  if (fd.getFile() != null) {
    cur = new File(fd.getDirectory(), fd.getFile());
    value = FileChooser.APPROVE_OPTION;
  }
  else {
    value = FileChooser.CANCEL_OPTION;
  }
  updateDirectoryPreference();
  return value;
}
 
Example 3
Project: vexillo   File: ExportMenuItem.java   Source Code and License 7 votes vote down vote up
public ExportMenuItem(final FlagFrame frame) {
	setText("Export...");
	if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_E);
	setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputUtils.META_MASK));
	if (frame == null) {
		setEnabled(false);
	} else {
		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				FileDialog fd = new FileDialog(frame, "Export", FileDialog.SAVE);
				fd.setVisible(true);
				if (fd.getDirectory() == null || fd.getFile() == null) return;
				File file = new File(fd.getDirectory(), fd.getFile());
				new ExportDialog(
					frame, frame.getParentFile(), frame.getFlag(), file,
					frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze()
				).setVisible(true);
			}
		});
	}
}
 
Example 4
Project: vexillo   File: OpenMenuItem.java   Source Code and License 7 votes vote down vote up
public OpenMenuItem() {
	setText("Open...");
	if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_O);
	setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputUtils.META_MASK));
	addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent event) {
			FileDialog fd = new FileDialog(new Frame(), "Open", FileDialog.LOAD);
			fd.setVisible(true);
			if (fd.getDirectory() == null || fd.getFile() == null) return;
			File file = new File(fd.getDirectory(), fd.getFile());
			try {
				FileInputStream in = new FileInputStream(file);
				Flag flag = FlagParser.parse(file.getName(), in);
				in.close();
				String title = file.getName();
				if (flag.getName() != null) title += ": " + flag.getName();
				FlagFrame frame = new FlagFrame(title, file, flag);
				frame.setVisible(true);
			} catch (Exception e) {
				JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), "Open", JOptionPane.ERROR_MESSAGE);
			}
		}
	});
}
 
Example 5
Project: incubator-netbeans   File: FileChooserBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Show an open dialog with a file chooser set up according to the
 * parameters of this builder.
 * @return A file if the user clicks the accept button and a file or
 * folder was selected at the time the user clicked cancel.
 */
public File showOpenDialog() {
    JFileChooser chooser = createFileChooser();
    if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
        FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
        if( null != fileDialog ) {
            return showFileDialog(fileDialog, FileDialog.LOAD );
        }
    }
    chooser.setMultiSelectionEnabled(false);
    int dlgResult = chooser.showOpenDialog(findDialogParent());
    if (JFileChooser.APPROVE_OPTION == dlgResult) {
        File result = chooser.getSelectedFile();
        if (result != null && !result.exists()) {
            result = null;
        }
        return result;
    } else {
        return null;
    }

}
 
Example 6
Project: incubator-netbeans   File: FileChooserBuilder.java   Source Code and License 6 votes vote down vote up
/**
 * Show a save dialog with the file chooser set up according to the
 * parameters of this builder.
 * @return A file if the user clicks the accept button and a file or
 * folder was selected at the time the user clicked cancel.
 */
public File showSaveDialog() {
    JFileChooser chooser = createFileChooser();
    if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
        FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
        if( null != fileDialog ) {
            return showFileDialog( fileDialog, FileDialog.SAVE );
        }
    }
    int result = chooser.showSaveDialog(findDialogParent());
    if (JFileChooser.APPROVE_OPTION == result) {
        return chooser.getSelectedFile();
    } else {
        return null;
    }
}
 
Example 7
Project: incubator-netbeans   File: FileChooserBuilder.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 8
Project: VASSAL-src   File: FileChooser.java   Source Code and License 6 votes vote down vote up
public int showOpenDialog(Component parent) {
  final FileDialog fd = awt_file_dialog_init(parent);
  fd.setMode(FileDialog.LOAD);
  System.setProperty("apple.awt.fileDialogForDirectories",
                     String.valueOf(mode == DIRECTORIES_ONLY));
  fd.setVisible(true);

  final int value;
  if (fd.getFile() != null) {
    cur = new File(fd.getDirectory(), fd.getFile());
    value = FileChooser.APPROVE_OPTION;
  }
  else {
    value = FileChooser.CANCEL_OPTION;
  }
  updateDirectoryPreference();
  return value;
}
 
Example 9
Project: OpenJSharp   File: GtkFileDialogPeer.java   Source Code and License 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 10
Project: jdk8u-jdk   File: GtkFileDialogPeer.java   Source Code and License 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 11
Project: jdk8u-jdk   File: FileDialogForPackages.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 12
Project: jdk8u-jdk   File: FileDialogForDirectories.java   Source Code and License 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example 13
Project: openjdk-jdk10   File: GtkFileDialogPeer.java   Source Code and License 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    if (!quit) {
        run(fd.getTitle(), fd.getMode(), dirname, filename,
                fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
    }
}
 
Example 14
Project: openjdk-jdk10   File: FileDialogForPackages.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 15
Project: openjdk-jdk10   File: FileDialogForDirectories.java   Source Code and License 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example 16
Project: myster   File: DownloaderThread.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 17
Project: openjdk9   File: GtkFileDialogPeer.java   Source Code and License 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    if (!quit) {
        run(fd.getTitle(), fd.getMode(), dirname, filename,
                fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
    }
}
 
Example 18
Project: openjdk9   File: FileDialogForPackages.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 19
Project: openjdk9   File: FileDialogForDirectories.java   Source Code and License 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example 20
Project: MySnakeGame   File: SnakeGameFrame.java   Source Code and License 6 votes vote down vote up
public void actionPerformed(ActionEvent event) {
	FileDialog dialog = new FileDialog(SnakeGameFrame.this, "Open",
			FileDialog.LOAD);
	dialog.setVisible(true);
	String dir = dialog.getDirectory();
	String fileName = dialog.getFile();
	String filePath = dir + fileName;

	if (fileName != null && fileName.trim().length() != 0) {
		File file = new File(filePath);
		panel.loadGameDataFromFile(file);
		startMI.setEnabled(false);
		pauseMI.setEnabled(true);
	} else {
		JOptionPane.showConfirmDialog(SnakeGameFrame.this,
				"�ļ���Ϊ��\nװ����Ϸ����ʧ��", "̰������Ϸ", JOptionPane.DEFAULT_OPTION);
	}

}
 
Example 21
Project: MySnakeGame   File: SnakeGameFrame.java   Source Code and License 6 votes vote down vote up
public void actionPerformed(ActionEvent event) {
	if (panel.getGameState() == GameState.INITIALIZE) {
		JOptionPane.showConfirmDialog(SnakeGameFrame.this,
						"��Ϸû������\n���ܱ�����Ϸ����", "̰������Ϸ",
						JOptionPane.DEFAULT_OPTION);
		return;
	}

	FileDialog dialog = new FileDialog(SnakeGameFrame.this, "Save",FileDialog.SAVE);
	dialog.setVisible(true);
	String dir = dialog.getDirectory();
	String fileName = dialog.getFile();//��ȡ����������������ġ�Ҫ������ļ�����
	String filePath = dir + fileName;
	if (fileName != null && fileName.trim().length() != 0) {
		File file = new File(filePath);
		panel.saveGameDataToFile(file);
	} else {
		JOptionPane.showConfirmDialog(SnakeGameFrame.this,
				"�ļ���Ϊ��\n������Ϸ����ʧ��", "̰������Ϸ", JOptionPane.DEFAULT_OPTION);
	}

}
 
Example 22
Project: pumpernickel   File: FileDialogUtils.java   Source Code and License 6 votes vote down vote up
public static File showSaveDialog(Frame f,String title,String extension) {
	if(extension.startsWith("."))
		extension = extension.substring(1);
	
	FileDialog fd = new FileDialog(f, title);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter(extension));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);

	String s = fd.getFile();
	if(s==null)
		return null;
	
	if(s.toLowerCase().endsWith("."+extension)) {
		return new File(fd.getDirectory() + s);
	}
	
	return new File(fd.getDirectory() + fd.getFile()+"."+extension);
}
 
Example 23
Project: pumpernickel   File: AudioPlayerUI.java   Source Code and License 6 votes vote down vote up
protected void doBrowseForFile(AudioPlayerComponent apc) {
	Window w = SwingUtilities.getWindowAncestor(apc);
	if(!(w instanceof Frame))
		throw new RuntimeException("cannot invoke a FileDialog if the player is not in a java.awt.Frame");
	//the button shouldn't be enabled if w isn't a Frame...
	Frame f = (Frame)w;
	FileDialog fd = new FileDialog(f);
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	
	if(fd.getFile()==null) throw new UserCancelledException();
	File file = new File(fd.getDirectory()+fd.getFile());
	try {
		apc.setSource( file.toURI().toURL() );
	} catch (MalformedURLException e) {
		e.printStackTrace();
		apc.setSource(null);
	}
}
 
Example 24
Project: pumpernickel   File: ScreenCaptureDemo.java   Source Code and License 6 votes vote down vote up
protected File showSaveDialog() {
	FileDialog fd = new FileDialog(frame);
	fd.setMode(FileDialog.SAVE);
	fd.setFilenameFilter(new SuffixFilenameFilter("mov"));
	fd.setTitle("Save MOV File");
	fd.pack();
	fd.setLocationRelativeTo(frame);
	fd.setVisible(true);
	if(fd.getFile()==null)
		throw new UserCancelledException();
	String filepath = fd.getDirectory() + fd.getFile();
	if(!filepath.toLowerCase().endsWith(".mov")) {
		filepath += ".mov";
	}
	return new File(filepath);
}
 
Example 25
Project: pumpernickel   File: ImageQuantizationDemo.java   Source Code and License 6 votes vote down vote up
/** If invoked from within a Frame: this pulls up a FileDialog to
 * browse for a file. If this is invoked from a secure applet: then
 * this will throw an exception.
 * 
 * @param ext an optional list of extensions
 * @return a File, or null if the user declined to select anything.
 */
public File browseForFile(String... ext) {
	Window w = SwingUtilities.getWindowAncestor(this);
	if(!(w instanceof Frame))
		throw new IllegalStateException();
	Frame frame = (Frame)w;
	FileDialog fd = new FileDialog(frame);
	if(ext!=null && ext.length>0 && (!(ext.length==1 && ext[0]==null)))
		fd.setFilenameFilter(new SuffixFilenameFilter(ext));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	String d = fd.getFile();
	if(d==null) return null;
	return new File(fd.getDirectory()+fd.getFile());
}
 
Example 26
Project: pumpernickel   File: FileIcon.java   Source Code and License 6 votes vote down vote up
/** This captures a File's icon and saves it as a PNG.
 * This is tested on Mac; I'm not sure how it will perform
 * on Windows. You may need to modify the icon size. As of this
 * writing on Mac: you can pass most any Dimension object and
 * the icon will scale upwards safely.
 */
public static void main(String[] args) throws IOException {
	FileDialog fd = new FileDialog(new Frame());
	fd.pack();
	fd.setVisible(true);
	File f = new File(fd.getDirectory()+fd.getFile());
	Icon icon = getIcon(f);
	icon = new ScaledIcon(icon, 24, 24);
	BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = bi.createGraphics();
	icon.paintIcon(null, g, 0, 0);
	g.dispose();
	File f2 = new File(f.getParentFile(), f.getName()+".png");
	if(f2.exists())
		System.exit(1);
	ImageIO.write(bi, "png", f2);
	System.exit(0);;
}
 
Example 27
Project: pumpernickel   File: JarWriterApp.java   Source Code and License 6 votes vote down vote up
public void loadJar() throws IOException {
	FileDialog fd = new FileDialog(new Frame());
	fd.setFilenameFilter(new SuffixFilenameFilter("jar"));
	fd.pack();
	fd.setVisible(true);
	if(fd.getFile()==null) return;
	File jarFile = new File(fd.getDirectory()+fd.getFile());
	try(ZipFile zf = new ZipFile(jarFile)) {
		try(InputStream in = zf.getInputStream(new ZipEntry(KEY_SETUP_ENTRY))) {
			if(in==null) throw new IOException("This jar does not appear to be built with a recent version of JarWriterApp.");
			ContainerProperties p = new ContainerProperties();
			p.load(in);
			p.install(getContentPane(), null);
		}
		zf.close();
	}
}
 
Example 28
Project: pumpernickel   File: KeyStoreEditor.java   Source Code and License 6 votes vote down vote up
public static KeyStoreEditor create(Frame parentWindow) {
	KeyStoreEditor editor = new KeyStoreEditor();
	String dialogTitle = "Create Keystore";
	Icon icon = QDialog.getIcon(QDialog.PLAIN_MESSAGE);
	QDialog.showDialog(parentWindow, dialogTitle, icon, editor, editor.footer, true, null, null);
	JComponent button = editor.footer.getLastSelectedComponent();
	if( button==editor.footer.getButton(DialogFooter.OK_OPTION) ) {
		FileDialog fd = new FileDialog(parentWindow, "Create Keystore", FileDialog.SAVE);
		fd.setFilenameFilter(new SuffixFilenameFilter("jks"));
		fd.setFile("keystore.jks");
		fd.pack();
		fd.setLocationRelativeTo(null);
		fd.setVisible(true);
		if(fd.getFile()==null)
			return null;
		editor.jksFile = new File(fd.getDirectory()+fd.getFile());
		editor.create(false);
		return editor;
	} else {
		return null;
	}
}
 
Example 29
Project: pumpernickel   File: WavCopier.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("unused")
private static void main(String[] s) {
	try {
		JFrame frame = new JFrame();
		FileDialog fd = new FileDialog(frame);
		fd.setFilenameFilter(new SuffixFilenameFilter("wav", "wave"));
		fd.pack();
		fd.setVisible(true);
		if(fd.getFile()==null) return;
		File wavFile = new File(fd.getDirectory()+fd.getFile());
		FileInputStream in = null;
		try {
			in = new FileInputStream(wavFile);
			System.err.println("length: " + wavFile.length());
			WavCopier r = new WavCopier(in);
		} finally {
			in.close();
		}
		System.exit(0);
	} catch(IOException e) {
		e.printStackTrace();
		System.exit(1);
	}
}
 
Example 30
Project: jdk8u_jdk   File: GtkFileDialogPeer.java   Source Code and License 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 31
Project: jdk8u_jdk   File: FileDialogForPackages.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 32
Project: jdk8u_jdk   File: FileDialogForDirectories.java   Source Code and License 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example 33
Project: JHelioviewer-SWHV   File: OpenLocalFileAction.java   Source Code and License 6 votes vote down vote up
@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());
        }
    }
}
 
Example 34
Project: JHelioviewer-SWHV   File: OpenLocalFileAction.java   Source Code and License 6 votes vote down vote up
@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());
        }
    }
}
 
Example 35
Project: lookaside_java-1.8.0-openjdk   File: GtkFileDialogPeer.java   Source Code and License 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 36
Project: lookaside_java-1.8.0-openjdk   File: FileDialogForPackages.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 37
Project: lookaside_java-1.8.0-openjdk   File: FileDialogForDirectories.java   Source Code and License 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example 38
Project: JavaCL   File: Utils.java   Source Code and License 6 votes vote down vote up
public static File chooseFile(File initialFile, boolean load) {
	if (isMac()) {
		FileDialog d = new FileDialog((java.awt.Frame)null);
		d.setMode(load ? FileDialog.LOAD : FileDialog.SAVE);
           if (initialFile != null) {
               d.setDirectory(initialFile.getParent());
               d.setFile(initialFile.getName());
           }
		d.show();
		String f = d.getFile();
		if (f != null)
			return new File(new File(d.getDirectory()), d.getFile());
	} else {
        JFileChooser chooser = new JFileChooser();
           if (initialFile != null)
               chooser.setSelectedFile(initialFile);
        if ((load ? chooser.showOpenDialog(null) : chooser.showSaveDialog(null)) == JFileChooser.APPROVE_OPTION)
        		return chooser.getSelectedFile();
	}
       return null;
}
 
Example 39
Project: stickes   File: Files.java   Source Code and License 6 votes vote down vote up
void loadDialog() {
    FileDialog fd = new FileDialog(visual.frame, "Choose a file", FileDialog.LOAD);
    fd.setFilenameFilter(sf.getLoadFilenameFilter());
    fd.setFile("*");
    fd.setVisible(true);
    if (fd.getFiles().length == 0) {
        return;
    }
    File f = fd.getFiles()[0];
    try {
        if (f.exists()) {
            importFile(f);
            visual.init(2);
        } else {
            JOptionPane.showMessageDialog(visual.frame, f.getName() + " does not exist");
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(visual.frame, "error loading " + f.getName() + ": " + ex);
    }
}
 
Example 40
Project: stickes   File: Files.java   Source Code and License 6 votes vote down vote up
void saveDialog(String text) {
    try {
        FileDialog fd = new FileDialog(visual.frame, text, FileDialog.SAVE);
        fd.setFilenameFilter(sf.getSaveFilenameFilter());
        fd.setVisible(true);
        if (fd.getFiles().length == 0) {
            return;
        }
        sf.save(fd.getFiles()[0], visual.getStichData());

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(visual.frame, "error during save: " + ex.getMessage());
        Logger
                .getLogger(Visual.class
                        .getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 41
Project: toxiclibs   File: FileUtils.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 42
Project: vzome-desktop   File: ZomicEditorPanel.java   Source Code and License 6 votes vote down vote up
private void writeToFile( String script )
    {
//        int returnVal = mFileChooser.showSaveDialog( ZomicEditorPanel.this );
//        if (returnVal == JFileChooser.APPROVE_OPTION) {
//            File file = mFileChooser.getSelectedFile();
		mFileChooser .setTitle( SAVE );
		mFileChooser .setMode( FileDialog .SAVE );
		mFileChooser .setVisible( true );
		String fileName = mFileChooser .getFile();
		if ( fileName != null ) {
			File file = new File( mFileChooser .getDirectory(), fileName );
            // A try-with-resources block closes the resource even if an exception occurs
            try (Writer out = new FileWriter( file )) {
                out .write( script );
            }
            catch (Exception exc) {
                JOptionPane .showMessageDialog( ZomicEditorPanel.this,
                    "An exception prevented successful writing of the file.",
                   "File save error", JOptionPane.ERROR_MESSAGE );
                exc.printStackTrace();
            }
        }
    }
 
Example 43
Project: vzome-desktop   File: FileAction.java   Source Code and License 6 votes vote down vote up
@Override
  public void actionPerformed( ActionEvent arg0 )
  {
  	String title = ( mTitle != null )? mTitle : ( mOpening? "Choose a file" : "Save a file" );
mFileChooser .setTitle( title );
mFileChooser .setMode( mOpening? FileDialog .LOAD : FileDialog .SAVE );
mFileChooser .setVisible( true );
mFileChooser .setFilenameFilter( null );
String fileName = mFileChooser .getFile();
if ( fileName == null )
{
    logger .info( "file action cancelled" );
    return;
}
      if ( ! mOpening && ! fileName .endsWith( "." + mExtension ) )
          fileName = fileName + "." + mExtension;
File file = new File( mFileChooser .getDirectory(), fileName );
      if ( ! actOrError( file ) )
          return;
  }
 
Example 44
Project: touist   File: ParentEditionPanel.java   Source Code and License 6 votes vote down vote up
public void openHandler() {
      if(hasUnsavedChanges()) {
          int confirmed = JOptionPane.showConfirmDialog(null,
                  getFrame().getLang().getWord("ParentEditionPanel.saveOrLooseOnOpen"),
                  "", JOptionPane.YES_NO_CANCEL_OPTION);
          if (confirmed == JOptionPane.YES_OPTION) {
              saveHandler(false);
          } else if (confirmed == JOptionPane.NO_OPTION) {
          } else if (confirmed == JOptionPane.CANCEL_OPTION) {
              return;
          }
      }

FileDialog d = new FileDialog(getFrame());
d.setDirectory(touist.TouIST.getWhereToSave());
  	d.setMode(FileDialog.LOAD);
  	d.setVisible(true);
  	
      editor.setText("");

      if (d.getFile() != null) 
      {
      	String path = d.getDirectory() + d.getFile();
          open(path);
      }
  }
 
Example 45
Project: CIMMYT   File: FileSave.java   Source Code and License 6 votes vote down vote up
public static final File saveFileMac(String title, File startDirectory, final String fileDesc, String defaultFileName) {
        File path = null;
        
        System.setProperty("apple.awt.fileDialogForDirectories", "true");
        FileDialog d = new FileDialog((Dialog)null, title, FileDialog.SAVE);
        
        if(defaultFileName != null) {
                d.setFile(defaultFileName);  
        }
        
        d.setFilenameFilter(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                        return dir.isDirectory() || dir.isFile();
                }
        });
        
        d.setVisible(true);
        String tmp = d.getFile();
        
        if(tmp != null) {
                path = new File(tmp);
        }
        
        return path;
}
 
Example 46
Project: EchoSim   File: SuitePanel.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 47
Project: EchoSim   File: SuitePanel.java   Source Code and License 6 votes vote down vote up
private void doSaveDisk()
{
    FileDialog fd = new FileDialog(getFrame(), "Save Suite", FileDialog.SAVE);
    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.save(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);
    }
}
 
Example 48
Project: EchoSim   File: ScriptPanel.java   Source Code and License 6 votes vote down vote up
private void doLoadDisk()
{
    FileDialog fd = new FileDialog(getFrame(), "Load Script", FileDialog.LOAD);
    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.load(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);
    }
}
 
Example 49
Project: EchoSim   File: ScriptPanel.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 50
Project: EchoSim   File: ApplicationPanel.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 51
Project: EchoSim   File: ApplicationPanel.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 52
Project: EchoSim   File: TestingPanel.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 53
Project: EchoSim   File: TestingPanel.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 54
Project: elki   File: ParameterTable.java   Source Code and License 6 votes vote down vote up
/**
 * Button callback to show the file selector
 */
@Override
public void actionPerformed(ActionEvent e) {
  FileDialog fc = new FileDialog(frame);
  fc.setDirectory(defaultpath);
  fc.setMode(mode);
  final String curr = textfield.getText();
  if(curr != null && curr.length() > 0) {
    fc.setFile(curr);
  }
  fc.setVisible(true);
  String filename = fc.getFile();
  if(filename != null) {
    textfield.setText(new File(fc.getDirectory(), filename).getPath());
  }
  fc.setVisible(false);
  fc.dispose();
  textfield.requestFocus();
  fireEditingStopped();
}
 
Example 55
Project: elki   File: ParameterTable.java   Source Code and License 6 votes vote down vote up
/**
 * Apply the Editor for a selected option.
 */
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  if(row < parameters.size()) {
    Parameter<?> option = parameters.getNode(row).param;
    if(option instanceof FileParameter) {
      FileParameter fp = (FileParameter) option;
      File f = null;
      mode = FileParameter.FileType.INPUT_FILE.equals(fp.getFileType()) ? FileDialog.LOAD : FileDialog.SAVE;
      if(fp.isDefined()) {
        f = fp.getValue();
      }
      textfield.setText(f != null ? f.getPath() : "");
    }
  }
  textfield.requestFocus();
  return panel;
}
 
Example 56
Project: HTML5_WebSite   File: Jpan_btn.java   Source Code and License 6 votes vote down vote up
private FitxerDades getFitxerDades(final String sPath) {
	final FileDialog fd = new FileDialog(fDialog, Language.getLabel(9),
			FileDialog.LOAD);
	FitxerDades fitx;

	fitx = new FitxerDades();
	fd.setDirectory(sPath);
	fd.setVisible(true);
	if (fd.getFile() == null) {
		fitx = null;
	} else {
		fitx.setNom(fd.getFile());
		fitx.setPath(fd.getDirectory());
	}
	return fitx;
}
 
Example 57
Project: prottest3   File: XProtTestView.java   Source Code and License 6 votes vote down vote up
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);
	}
}
 
Example 58
Project: infobip-open-jdk-8   File: GtkFileDialogPeer.java   Source Code and License 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example 59
Project: infobip-open-jdk-8   File: FileDialogForPackages.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 60
Project: infobip-open-jdk-8   File: FileDialogForDirectories.java   Source Code and License 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}