Example usage for java.awt FileDialog FileDialog

List of usage examples for java.awt FileDialog FileDialog

Introduction

In this page you can find the example usage for java.awt FileDialog FileDialog.

Prototype

public FileDialog(Dialog parent, String title) 

Source Link

Document

Creates a file dialog window with the specified title for loading a file.

Usage

From source file:com.vilt.minium.app.controller.FileController.java

public FileController() throws IOException {
    fileDialog = new FileDialog((Frame) null, "");
    fileDialog.toFront();/*from  www  .j a v  a  2 s.  c om*/
    fileDialog.setAlwaysOnTop(true);
    fileDialog.setFilenameFilter(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".js");
        }
    });
}

From source file:org.tinymediamanager.ui.TmmUIHelper.java

private static Path openDirectoryDialog(String title) throws Exception, Error {
    // set system property to choose directories
    System.setProperty("apple.awt.fileDialogForDirectories", "true");

    FileDialog chooser = new FileDialog(MainWindow.getFrame(), title);
    if (lastDir != null) {
        chooser.setDirectory(lastDir.toFile().getAbsolutePath());
    }//from   ww w  .  j a  v  a  2s.c  o  m
    chooser.setVisible(true);

    // reset system property
    System.setProperty("apple.awt.fileDialogForDirectories", "false");

    if (StringUtils.isNotEmpty(chooser.getFile())) {
        lastDir = Paths.get(chooser.getDirectory());
        return Paths.get(chooser.getDirectory(), chooser.getFile());
    } else {
        return null;
    }
}

From source file:de.mycrobase.jcloudapp.Main.java

public void doUploadFile() {
    FileDialog dlg = new FileDialog((Dialog) null, "Upload File...");
    dlg.setVisible(true);//from ww w .  ja v  a2  s  .c  o  m
    if (dlg.getDirectory() == null || dlg.getFile() == null) {
        return;
    }
    File f = new File(dlg.getDirectory() + File.separator + dlg.getFile());
    if (f.exists()) {
        setImageWorking();
        JSONObject drop = upload(f);
        if (drop != null) {
            String url = getDropUrl(drop);
            System.out.println("Upload complete, URL:\n" + url);
            setClipboard(url);
            icon.displayMessage("Upload finished", String.format("Item: %s", f.getName()),
                    TrayIcon.MessageType.INFO);
        }
        setImageNormal();
    }
}

From source file:org.sbml.bargraph.MainWindow.java

/**
 * Handles the "Open" menu item in the File menu.
 * @param evt//from   w  w w. j av a 2s .  c  o  m
 */
public void openFileHandler(java.awt.event.ActionEvent evt) {
    Log.note("'Open' menu item invoked.");
    FileDialog dialog = new FileDialog(this, "Choose file to graph");
    dialog.setVisible(true);

    if (dialog.getFile() == null) {
        Log.note("User cancelled file selection");
        return;
    }

    VerifiableFile theFile = new VerifiableFile(dialog.getDirectory() + dialog.getFile());
    if (theFile.isVerifiedFile()) {
        Log.note("User selected file '" + theFile.getPath() + "'");
        try {
            updatePanelForSBMLFile(theFile);
        } catch (Exception e) {
            Log.error(e.getMessage());
        }
    } else {
        Log.note("Invalid file selected: '" + theFile.getPath() + "'");
        Dialog.error(this, "Invalid file selected: " + theFile.getName(), "File error");
    }
}

From source file:com.stacksync.desktop.util.FileUtil.java

private static File showBrowseDialogMac(BrowseType type) {
    // AWT looks best on Mac:
    // http://today.java.net/pub/a/today/2004/01/29/swing.html

    String title = "";
    if (type == BrowseType.DIRECTORIES_ONLY) {
        System.setProperty("apple.awt.fileDialogForDirectories", "true");
        title = "Choose Folder";
    } else if (type == BrowseType.FILES_ONLY) {
        System.setProperty("apple.awt.fileDialogForDirectories", "false");
        title = "Choose File";
    }//www.  j ava  2 s. c o  m

    FileDialog dialog = new FileDialog(new Frame(), title);
    dialog.setVisible(true);

    String path = dialog.getDirectory() + dialog.getFile();
    return new File(path);
}

From source file:livecanvas.mesheditor.MeshEditor.java

private void open(File file) {
    if (file == null) {
        FileDialog fd = new FileDialog(JOptionPane.getFrameForComponent(MeshEditor.this), "Load");
        fd.setVisible(true);/*from   w w  w . j a  v a2 s .c o m*/
        String file_str = fd.getFile();
        if (file_str == null) {
            return;
        }
        file = new File(fd.getDirectory() + "/" + file_str);
    }
    try {
        StringWriter out = new StringWriter();
        InputStreamReader in = new InputStreamReader(new FileInputStream(file));
        Utils.copy(in, out);
        in.close();
        out.close();
        clear();
        JSONObject doc = new JSONObject(out.toString());
        Layer rootLayer = Layer.fromJSON(doc.getJSONObject("rootLayer"));
        layersView.setRootLayer(rootLayer);
        rootLayer.setCanvas(canvas);
        for (Layer layer : rootLayer.getSubLayersRecursively()) {
            layer.setCanvas(canvas);
        }
        JSONObject canvasJSON = doc.optJSONObject("canvas");
        if (canvasJSON != null) {
            canvas.fromJSON(canvasJSON);
        }
        canvas.setCurrLayer(rootLayer);
    } catch (Exception e1) {
        e1.printStackTrace();
        String msg = "An error occurred while trying to load.";
        JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(MeshEditor.this), msg, "Error",
                JOptionPane.ERROR_MESSAGE);
    }
    repaint();
}

From source file:livecanvas.mesheditor.MeshEditor.java

private void save(File file) {
    if (!canSave()) {
        return;//  ww w .  ja  va 2 s. com
    }
    if (file == null) {
        FileDialog fd = new FileDialog(JOptionPane.getFrameForComponent(MeshEditor.this), "Save");
        fd.setVisible(true);
        String file_str = fd.getFile();
        if (file_str == null) {
            return;
        }
        file = new File(fd.getDirectory() + "/" + file_str);
    }
    try {
        Layer rootLayer = layersView.getRootLayer();
        for (Layer l : rootLayer.getSubLayersRecursively()) {
            Path path = l.getPath();
            if (path.isFinalized()) {
                Mesh mesh = path.getMesh();
                if (mesh.getControlPointsCount() < 2) {
                    String msg = "At least one mesh has less than 2 control points.\n"
                            + "You may not be able to use it for animation. Do you\n"
                            + "still want to continue?";
                    if (JOptionPane.showConfirmDialog(this, msg, "Warning", JOptionPane.YES_NO_OPTION,
                            JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
                        return;
                    } else {
                        break;
                    }
                }
            }
        }
        PrintWriter out = new PrintWriter(new FileOutputStream(file));
        JSONObject doc = new JSONObject();
        doc.put("rootLayer", rootLayer.toJSON());
        doc.put("canvas", canvas.toJSON());
        doc.write(out);
        out.close();
    } catch (Exception e1) {
        e1.printStackTrace();
        String msg = "An error occurred while trying to load.";
        JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(MeshEditor.this), msg, "Error",
                JOptionPane.ERROR_MESSAGE);
    }
    repaint();
}

From source file:org.apache.pdfbox.debugger.PDFDebugger.java

private void openMenuItemActionPerformed(ActionEvent evt) {
    try {//  ww w  .  j  av a  2  s . c  o m
        if (IS_MAC_OS) {
            FileDialog openDialog = new FileDialog(this, "Open");
            openDialog.setFilenameFilter(new FilenameFilter() {
                @Override
                public boolean accept(File file, String s) {
                    return file.getName().toLowerCase().endsWith(".pdf");
                }
            });
            openDialog.setVisible(true);
            if (openDialog.getFile() != null) {
                readPDFFile(openDialog.getFile(), "");
            }
        } else {
            String[] extensions = new String[] { "pdf", "PDF" };
            FileFilter pdfFilter = new ExtensionFileFilter(extensions, "PDF Files (*.pdf)");
            FileOpenSaveDialog openDialog = new FileOpenSaveDialog(this, pdfFilter);

            File file = openDialog.openFile();
            if (file != null) {
                readPDFFile(file, "");
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.declarativa.interprolog.gui.Ini.java

public void GraphAnalysis() {
    String fileToLoad, folder;/*from www.j  av a2s  .  c o  m*/
    File filetoreconsult = null;
    FileDialog d = new FileDialog(this, "Consult file...");
    d.setVisible(true);
    fileToLoad = d.getFile();
    folder = d.getDirectory();
    if (fileToLoad != null) {
        ArgBuildManager manag = new ArgBuildManager();
        manag.GraphFileRules(folder, fileToLoad);//Call to the ArgBuildManager!
        /*
         filetoreconsult = new File(folder, fileToLoad);
         if (engine.consultAbsolute(filetoreconsult)) {
         addToReloaders(filetoreconsult, "consult");
         }
         */
        //System.out.println("file:"+filetoreconsult.);

    }
}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

void reconsultFile() {
    String nome, directorio;//from   w w w . j a  v  a2  s  .co  m
    File filetoreconsult = null;
    FileDialog d = new FileDialog(this, "Consult file...");
    d.setVisible(true);
    nome = d.getFile();
    directorio = d.getDirectory();
    if (nome != null) {
        filetoreconsult = new File(directorio, nome);
        if (engine.consultAbsolute(filetoreconsult)) {
            addToReloaders(filetoreconsult, "consult");
        }
    }
}