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   View source code 8 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   View source code 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: incubator-netbeans   File: FileChooserBuilder.java   View source code 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 4
Project: incubator-netbeans   File: FileChooserBuilder.java   View source code 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 5
Project: incubator-netbeans   File: FileChooserBuilder.java   View source code 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 6
Project: VASSAL-src   File: FileChooser.java   View source code 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 7
Project: vexillo   File: ExportMenuItem.java   View source code 6 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 8
Project: vexillo   File: OpenMenuItem.java   View source code 6 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 9
Project: OpenJSharp   File: GtkFileDialogPeer.java   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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   View source code 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);
    }
}