Example usage for java.awt FileDialog LOAD

List of usage examples for java.awt FileDialog LOAD

Introduction

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

Prototype

int LOAD

To view the source code for java.awt FileDialog LOAD.

Click Source Link

Document

This constant value indicates that the purpose of the file dialog window is to locate a file from which to read.

Usage

From source file:org.mbs3.juniuploader.gui.pnlWoWDirectories.java

private void btnAddDirectoryActionPerformed(ActionEvent evt) {
    if (evt.getSource() == this.btnAddDirectory) {
        boolean failed = false;
        boolean mac = Util.isMac();
        if (mac) {
            java.awt.Frame f = jUniUploader.inst;
            FileDialog fd = new FileDialog(f, "Select a World of Warcraft Directory", FileDialog.LOAD);
            try {
                fd.show();//from w  w  w.  j  a  v a  2 s.  co m

                String fileName = fd.getFile();
                String rootDir = fd.getDirectory();
                String completePath = (rootDir == null ? "" : rootDir) + (fileName == null ? "" : fileName);
                log.debug("Adding OS X style " + completePath);
                if (completePath != null) {
                    File file = new File(completePath);
                    if (file != null && file.exists() && file.isDirectory()) {
                        WDirectory wd = new WDirectory(file);
                        frmMain.wowDirectories.addElement(wd);
                    }

                }

            } catch (Exception ex) {
                failed = true;
                log.warn("Failed trying to display a FileDialog, falling back to JFileChooser", ex);
            }

        }
        if (!mac || failed) {
            JFileChooser fc = new JFileChooser();
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = fc.showOpenDialog(this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                if (file != null && file.exists() && file.isDirectory()) {
                    WDirectory wd = new WDirectory(file);
                    frmMain.wowDirectories.addElement(wd);
                }

            } else {
                log.trace("Open command cancelled by user.");
            }

        }
    }
}

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

public static Path selectFile(String title) {
    // try to open AWT dialog on OSX
    if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
        try {//from w  w  w  .  ja  va 2 s. com
            // open file chooser
            return openFileDialog(title, FileDialog.LOAD, null);
        } catch (Exception e) {
            LOGGER.warn("cannot open AWT filechooser" + e.getMessage());
        } catch (Error e) {
            LOGGER.warn("cannot open AWT filechooser" + e.getMessage());
        }
    }

    // open JFileChooser
    return openJFileChooser(JFileChooser.FILES_ONLY, title, true, null, null);
}

From source file:pipeline.GUI_utils.ListOfPointsView.java

private void reloadUserFormulasFromFile() {
    FileDialog dialog = new FileDialog(new Frame(), "Choose a tab-separated file to load formulas from.",
            FileDialog.LOAD);
    dialog.setVisible(true);/*from w  ww . java 2s  . co  m*/
    String filePath = dialog.getDirectory();
    if (filePath == null)
        return;
    filePath += "/" + dialog.getFile();

    silenceUpdates.incrementAndGet();

    try (BufferedReader r = new BufferedReader(new FileReader(filePath))) {
        List<Integer> userColumns = getUserColumnList();
        int nUserColumns = userColumns.size();
        int row = 0;
        boolean firstLine = true;// the first line contains column names
        while (true) {
            String line = r.readLine();
            if (line == null)
                break;
            StringTokenizer stok = new java.util.StringTokenizer(line);

            int currentColumn = 0;
            while (stok.hasMoreTokens()) {
                String element = stok.nextToken("\t");
                if (firstLine) {
                    // name columns
                    tableModel.setColumnName(userColumns.get(currentColumn), element);
                    modelForColumnDescriptions.setValueAt(element, 0, userColumns.get(currentColumn));
                } else {
                    SpreadsheetCell cell = (SpreadsheetCell) tableModel.getValueAt(row,
                            userColumns.get(currentColumn));
                    if (cell == null) {
                        cell = new SpreadsheetCell("", "", new Object[] { "", element }, true, this, null);
                        tableModel.setValueAt(cell, row, userColumns.get(currentColumn));
                    } else {
                        cell.setFormula(element);
                    }
                }
                currentColumn++;
                if (currentColumn == nUserColumns) {
                    Utils.log("File has more columns than user columns; discarding remaining columns from file",
                            LogLevel.WARNING);
                    break;
                }
            }
            if (!firstLine)
                row++;
            else
                firstLine = false;
        }
    } catch (IOException e) {
        Utils.printStack(e);
    } finally {
        silenceUpdates.decrementAndGet();
    }

    tableModel.fireTableStructureChanged();
    setSpreadsheetColumnEditorAndRenderer();
}

From source file:processing.app.Base.java

/**
 * Prompt for a sketch to open, and open it in a new window.
 *
 * @throws Exception//ww w  .  j ava 2  s.co m
 */
public void handleOpenPrompt() throws Exception {
    // get the frontmost window frame for placing file dialog
    FileDialog fd = new FileDialog(activeEditor, tr("Open an Arduino sketch..."), FileDialog.LOAD);
    File lastFolder = new File(
            PreferencesData.get("last.folder", BaseNoGui.getSketchbookFolder().getAbsolutePath()));
    if (lastFolder.exists() && lastFolder.isFile()) {
        lastFolder = lastFolder.getParentFile();
    }
    fd.setDirectory(lastFolder.getAbsolutePath());

    // Only show .pde files as eligible bachelors
    fd.setFilenameFilter(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".ino") || name.toLowerCase().endsWith(".pde");
        }
    });

    fd.setVisible(true);

    String directory = fd.getDirectory();
    String filename = fd.getFile();

    // User canceled selection
    if (filename == null)
        return;

    File inputFile = new File(directory, filename);

    PreferencesData.set("last.folder", inputFile.getAbsolutePath());
    handleOpen(inputFile);
}

From source file:processing.app.Sketch.java

/**
 * Prompt the user for a new file to the sketch, then call the
 * other addFile() function to actually add it.
 *//*from   www. ja  v a2  s  . c o  m*/
public void handleAddFile() {
    // make sure the user didn't hide the sketch folder
    ensureExistence();

    // if read-only, give an error
    if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
        // if the files are read-only, need to first do a "save as".
        Base.showMessage(tr("Sketch is Read-Only"), tr("Some files are marked \"read-only\", so you'll\n"
                + "need to re-save the sketch in another location,\n" + "and try again."));
        return;
    }

    // get a dialog, select a file to add to the sketch
    FileDialog fd = new FileDialog(editor, tr("Select an image or other data file to copy to your sketch"),
            FileDialog.LOAD);
    fd.setVisible(true);

    String directory = fd.getDirectory();
    String filename = fd.getFile();
    if (filename == null)
        return;

    // copy the file into the folder. if people would rather
    // it move instead of copy, they can do it by hand
    File sourceFile = new File(directory, filename);

    // now do the work of adding the file
    boolean result = addFile(sourceFile);

    if (result) {
        editor.statusNotice(tr("One file added to the sketch."));
        PreferencesData.set("last.folder", sourceFile.getAbsolutePath());
    }
}

From source file:se.llbit.chunky.renderer.ui.RenderControls.java

private JPanel buildAdvancedPane() {
    rayDepth.update();//from w ww.  j a v  a 2 s.com

    JSeparator sep1 = new JSeparator();
    JSeparator sep2 = new JSeparator();

    numThreads.update();

    cpuLoad.update();

    mergeDumpBtn.setToolTipText("Merge an existing render dump with the current render");
    mergeDumpBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            CenteredFileDialog fileDialog = new CenteredFileDialog(null, "Select Render Dump", FileDialog.LOAD);
            fileDialog.setFilenameFilter(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".dump");
                }
            });
            fileDialog.setDirectory(PersistentSettings.getSceneDirectory().getAbsolutePath());
            fileDialog.setVisible(true);
            File selectedFile = fileDialog.getSelectedFile();
            if (selectedFile != null) {
                sceneMan.mergeRenderDump(selectedFile);
            }
        }
    });

    JPanel panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup().addGroup(numThreads.horizontalGroup(layout))
                    .addGroup(cpuLoad.horizontalGroup(layout)).addComponent(sep1)
                    .addGroup(rayDepth.horizontalGroup(layout)).addComponent(sep2).addComponent(mergeDumpBtn)
                    .addComponent(shutdownWhenDoneCB))
            .addContainerGap());
    layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(numThreads.verticalGroup(layout)).addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(cpuLoad.verticalGroup(layout)).addPreferredGap(ComponentPlacement.UNRELATED)
            .addComponent(sep1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.UNRELATED).addGroup(rayDepth.verticalGroup(layout))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addComponent(sep2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(mergeDumpBtn)
            .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(shutdownWhenDoneCB).addContainerGap());
    return panel;
}

From source file:uk.nhs.cfh.dsp.srth.desktop.actions.querycrud.core.actions.LoadSavedQueryTask.java

/**
 * Do in background.//from  www.j a v  a  2  s .  c  om
 *
 * @return the query statement
 *
 * @throws Exception the exception
 */
@Override
protected Void doInBackground() throws Exception {

    // open file dialog
    FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select file to load",
            FileDialog.LOAD);
    fd.setVisible(true);

    fileSelected = fd.getFile();
    String directorySelected = fd.getDirectory();
    if (fileSelected != null && directorySelected != null) {
        File physicalFile = new File(directorySelected, fileSelected);
        // use file name load file from
        XMLLoader loader = new XMLLoader();
        Document doc = loader.getXMLDoc(physicalFile);

        query = queryExpressionXMLConverter.getQueryStatementFromElement(doc.getRootElement());
        if (query != null) {
            // assign physical location to query
            query.setPhysicalLocation(physicalFile.toURI());

            // register query and set to active query
            queryService.registerQuery(query);
            queryService.queryChanged(query, this);
        }
    }

    return null;
}

From source file:ustc.sse.rjava.RJavaInterface.java

public String rChooseFile(Rengine re, int newFile) {
    FileDialog fd = new FileDialog(new Frame(), (newFile == 0) ? "Select a file" : "Select a new file",
            (newFile == 0) ? FileDialog.LOAD : FileDialog.SAVE);
    fd.setVisible(true);/* w  w w  . jav a2  s.  co  m*/
    String res = null;
    if (fd.getDirectory() != null)
        res = fd.getDirectory();
    if (fd.getFile() != null)
        res = (res == null) ? fd.getFile() : (res + fd.getFile());
    return res;
}

From source file:wsattacker.sso.openid.attacker.gui.MainGui.java

private void loadItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_loadItemActionPerformed
    FileDialog fd = new FileDialog(this, "Choose a file", FileDialog.LOAD);
    fd.setFile("*.xml");
    fd.setVisible(true);//from w  w  w  .  ja  v a  2s  .c o m
    File[] files = fd.getFiles();

    if (files.length > 0) {
        File loadFile = files[0];

        try {
            ToolConfiguration currentToolConfig = new ToolConfiguration();
            currentToolConfig.setAttackerConfig(controller.getAttackerConfig());
            currentToolConfig.setAnalyzerConfig(controller.getAnalyzerConfig());

            XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, currentToolConfig);
        } catch (XmlPersistenceError ex) {
            Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /*int returnVal = loadFileChooser.showOpenDialog(this);
                
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File loadFile = loadFileChooser.getSelectedFile();
    try {
        XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, controller.getConfig());
    } catch (XmlPersistenceError ex) {
        Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex);
    }
    }*/
}