use of java.awt.FileDialog in project opennars by opennars.
the class GUI method selectFolder.
/**
* Select a folder from the local file system.
*
* @param prompt the frame text for the chooser
* @return the absolute path name for the selected folder, or null if action
* cancelled.
*/
public static String selectFolder(String prompt) {
String selectedFolder = null;
Frame frame = (applet == null) ? null : applet.frame;
if (PApplet.platform == MACOSX && PApplet.useNativeSelect != false) {
FileDialog fileDialog = new FileDialog(frame, prompt, FileDialog.LOAD);
System.setProperty("apple.awt.fileDialogForDirectories", "true");
fileDialog.setVisible(true);
System.setProperty("apple.awt.fileDialogForDirectories", "false");
String filename = fileDialog.getFile();
if (filename != null) {
try {
selectedFolder = (new File(fileDialog.getDirectory(), fileDialog.getFile())).getCanonicalPath();
} catch (IOException e) {
selectedFolder = null;
}
}
} else {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle(prompt);
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result = fileChooser.showOpenDialog(frame);
if (result == JFileChooser.APPROVE_OPTION) {
try {
selectedFolder = fileChooser.getSelectedFile().getCanonicalPath();
} catch (IOException e) {
selectedFolder = null;
}
}
}
return selectedFolder;
}
use of java.awt.FileDialog in project opennars by opennars.
the class LogPanel method openLogFile.
public boolean openLogFile() {
FileDialog dialog = new FileDialog((Dialog) null, "Inference Log", FileDialog.SAVE);
dialog.setVisible(true);
String directoryName = dialog.getDirectory();
logFilePath = dialog.getFile();
if (logFilePath == null) {
return false;
}
try {
boolean append = true;
boolean autoflush = true;
logFile = new PrintWriter(new FileWriter(directoryName + logFilePath, append), autoflush);
output(LOG.class, "Stream opened: " + logFilePath);
return true;
} catch (IOException ex) {
output(ERR.class, "Log file save: I/O error: " + ex.getMessage());
}
return false;
}
use of java.awt.FileDialog in project competitive-programming by ttvi-cse.
the class Draw method actionPerformed.
/**
* This method cannot be called directly.
*/
@Override
public void actionPerformed(ActionEvent e) {
FileDialog chooser = new FileDialog(frame, "Use a .png or .jpg extension", FileDialog.SAVE);
chooser.setVisible(true);
String filename = chooser.getFile();
if (filename != null) {
save(chooser.getDirectory() + File.separator + chooser.getFile());
}
}
use of java.awt.FileDialog in project fql by CategoricalData.
the class GUI method openActionAlternate.
private static void openActionAlternate() {
// delay();
FileDialog jfc = getOpenDialog();
jfc.setVisible(true);
openAction(jfc.getFiles());
}
use of java.awt.FileDialog in project fql by CategoricalData.
the class GUI method saveAsActionAlternate.
private static void saveAsActionAlternate(CodeEditor<?, ?, ?> e) {
if (e == null) {
return;
}
FileDialog jfc = getSaveDialog(e.lang());
jfc.setVisible(true);
String f = jfc.getFile();
if (f == null) {
return;
}
String d = jfc.getDirectory();
if (d == null) {
throw new RuntimeException("Could not save file");
}
if (!f.endsWith("." + e.lang().fileExtension())) {
f = f + "." + e.lang().fileExtension();
}
File file = new File(d, f);
files.put(e.id, file);
titles.put(e.id, file.getName());
doSave(file, e.getText(), e.id);
}
Aggregations