Search in sources :

Example 36 with FileDialog

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

Example 37 with FileDialog

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

Example 38 with FileDialog

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

Example 39 with FileDialog

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

Example 40 with FileDialog

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

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