Search in sources :

Example 26 with FileDialog

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;
}
Also used : Frame(java.awt.Frame) JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) FileDialog(java.awt.FileDialog) File(java.io.File)

Example 27 with FileDialog

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;
}
Also used : ERR(nars.io.events.OutputHandler.ERR) FileWriter(java.io.FileWriter) IOException(java.io.IOException) FileDialog(java.awt.FileDialog) PrintWriter(java.io.PrintWriter)

Example 28 with FileDialog

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());
    }
}
Also used : FileDialog(java.awt.FileDialog)

Example 29 with FileDialog

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());
}
Also used : FileDialog(java.awt.FileDialog)

Example 30 with FileDialog

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);
}
Also used : FileDialog(java.awt.FileDialog) File(java.io.File)

Aggregations

FileDialog (java.awt.FileDialog)78 File (java.io.File)43 JFileChooser (javax.swing.JFileChooser)18 Frame (java.awt.Frame)16 IOException (java.io.IOException)16 FilenameFilter (java.io.FilenameFilter)10 Dialog (java.awt.Dialog)8 FileFilter (javax.swing.filechooser.FileFilter)7 FileOutputStream (java.io.FileOutputStream)5 PrintStream (java.io.PrintStream)4 Button (java.awt.Button)3 Dimension (java.awt.Dimension)3 MenuItem (java.awt.MenuItem)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 MalformedURLException (java.net.MalformedURLException)3 SQLException (java.sql.SQLException)3 JLabel (javax.swing.JLabel)3 Component (java.awt.Component)2 GridLayout (java.awt.GridLayout)2