use of java.awt.FileDialog in project skeleton-sp18 by Berkeley-CS61B.
the class StdDraw method actionPerformed.
/**
* This method cannot be called directly.
*/
@Override
public void actionPerformed(ActionEvent e) {
FileDialog chooser = new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
chooser.setVisible(true);
String filename = chooser.getFile();
if (filename != null) {
StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
}
}
use of java.awt.FileDialog in project propane by ruby-processing.
the class ShimAWT method selectFolderImpl.
/*
static public void selectFolder(final String prompt,
final String callbackMethod,
final File defaultSelection,
final Object callbackObject,
final Frame parentFrame) {
selectFolderEvent(prompt, callbackMethod, defaultSelection, callbackObject, parentFrame, null);
}
// Will remove the 'sketch' parameter once we get an upstream JOGL fix
// https://github.com/processing/processing/issues/3831
static public void selectFolderEvent(final String prompt,
final String callbackMethod,
final File defaultSelection,
final Object callbackObject,
final Frame parentFrame,
final PApplet sketch) {
EventQueue.invokeLater(() -> {
selectFolderImpl(prompt, callbackMethod, defaultSelection,
callbackObject, parentFrame, sketch);
});
}
*/
public static void selectFolderImpl(final String prompt, final String callbackMethod, final File defaultSelection, final Object callbackObject, final Frame parentFrame) {
File selectedFile = null;
if (PApplet.platform == PConstants.MACOS && PApplet.useNativeSelect) {
FileDialog fileDialog = new FileDialog(parentFrame, prompt, FileDialog.LOAD);
if (defaultSelection != null) {
fileDialog.setDirectory(defaultSelection.getAbsolutePath());
}
System.setProperty("apple.awt.fileDialogForDirectories", "true");
fileDialog.setVisible(true);
System.setProperty("apple.awt.fileDialogForDirectories", "false");
String filename = fileDialog.getFile();
if (filename != null) {
selectedFile = new File(fileDialog.getDirectory(), fileDialog.getFile());
}
} else {
checkLookAndFeel();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle(prompt);
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (defaultSelection != null) {
fileChooser.setCurrentDirectory(defaultSelection);
}
int result = fileChooser.showOpenDialog(parentFrame);
if (result == JFileChooser.APPROVE_OPTION) {
selectedFile = fileChooser.getSelectedFile();
}
}
PApplet.selectCallback(selectedFile, callbackMethod, callbackObject);
}
use of java.awt.FileDialog in project libgdx by libgdx.
the class PreAlpha method open.
protected void open() {
FileDialog dialog = new FileDialog(this, "Open Image", FileDialog.LOAD);
if (lastDir != null)
dialog.setDirectory(lastDir);
dialog.setVisible(true);
final String file = dialog.getFile();
final String dir = dialog.getDirectory();
if (dir == null || file == null || file.trim().length() == 0)
return;
lastDir = dir;
try {
image = ImageIO.read(new File(dir, file));
imagePanel.setImage(image);
imagePanel.revalidate();
imagePanel.repaint();
pack();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Error opening image.");
return;
}
}
use of java.awt.FileDialog in project libgdx by libgdx.
the class FlameMain method showFileDialog.
private File showFileDialog(String title, int mode) {
FileDialog dialog = new FileDialog(this, title, mode);
if (lastDir != null)
dialog.setDirectory(lastDir);
dialog.setVisible(true);
final String file = dialog.getFile();
final String dir = dialog.getDirectory();
if (dir == null || file == null || file.trim().length() == 0)
return null;
lastDir = dir;
return new File(dir, file);
}
use of java.awt.FileDialog in project screenbird by adamhub.
the class AtomFactory method main.
/** This opens a file and parses the atoms.
* This is made private so the BlogUpdater doesn't pick it up and make
* a jar.
*/
private static void main(String[] args) {
Frame frame = new Frame();
FileDialog fd = new FileDialog(frame);
fd.setVisible(true);
if (fd.getFile() == null)
throw new NullPointerException();
File file = new File(fd.getDirectory() + fd.getFile());
try {
Atom[] atom = AtomFactory.readAll(file);
//can we write the same movie back verbatim?
File tmp = File.createTempFile("copy", ".mov");
FileOutputStream out = new FileOutputStream(tmp);
try {
for (int a = 0; a < atom.length; a++) {
atom[a].write(out);
}
out.close();
log("tmp: " + tmp.getAbsolutePath() + ", tmp.length() = " + tmp.length() + ", fil.length() = " + file.length());
boolean equals = IOUtils.equals(file, tmp);
log("write() accuracy: " + (equals ? "passed" : "failed"));
if (equals)
tmp.delete();
} catch (Exception e) {
log("write() accuracy: failed");
log(e);
} finally {
out.close();
}
} catch (IOException e) {
log(e);
}
log("finished");
}
Aggregations