Example usage for java.awt FileDialog getDirectory

List of usage examples for java.awt FileDialog getDirectory

Introduction

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

Prototype

public String getDirectory() 

Source Link

Document

Gets the directory of this file dialog.

Usage

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

public void GraphAnalysis() {
    String fileToLoad, folder;/*from  w  w w.ja  va 2 s  .co  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:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java

/**
 * /*from  w  ww . ja va 2s.  c o  m*/
 */
@SuppressWarnings("unchecked")
protected void exportSchemaLocales() {
    FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString("Save"),
            FileDialog.SAVE);
    dlg.setVisible(true);

    String fileName = dlg.getFile();
    if (fileName != null) {
        final File outFile = new File(dlg.getDirectory() + File.separator + fileName);
        //final File    outFile = new File("xxx.xml");

        final SimpleGlassPane glassPane = new SimpleGlassPane(getResourceString("SL_EXPORT_SCHEMA"), 18);
        glassPane.setBarHeight(12);
        glassPane.setFillColor(new Color(0, 0, 0, 85));

        setGlassPane(glassPane);
        glassPane.setVisible(true);

        SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() {
            @Override
            protected Integer doInBackground() throws Exception {

                DataProviderSessionIFace session = null;
                try {
                    session = DataProviderFactory.getInstance().createSession();

                    int dispId = AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId();
                    String sql = String.format(
                            "FROM SpLocaleContainer WHERE disciplineId = %d AND schemaType = %d", dispId,
                            schemaType);
                    List<SpLocaleContainer> spContainers = (List<SpLocaleContainer>) session.getDataList(sql);
                    try {
                        FileWriter fw = new FileWriter(outFile);

                        //fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<vector>\n");
                        fw.write("<vector>\n");

                        BeanWriter beanWriter = new BeanWriter(fw);
                        XMLIntrospector introspector = beanWriter.getXMLIntrospector();
                        introspector.getConfiguration().setWrapCollectionsInElement(true);
                        beanWriter.getBindingConfiguration().setMapIDs(false);
                        beanWriter.setWriteEmptyElements(false);

                        beanWriter.enablePrettyPrint();

                        double step = 100.0 / (double) spContainers.size();
                        double total = 0.0;
                        for (SpLocaleContainer container : spContainers) {
                            // force Load of lazy collections
                            container.getDescs().size();
                            container.getNames().size();

                            // Leaving this Code as an example of specifying the bewtixt file.
                            /*InputStream inputStream = Specify.class.getResourceAsStream("datamodel/SpLocaleContainer.betwixt");
                            //InputStream inputStream = Specify.class.getResourceAsStream("/edu/ku/brc/specify/tools/schemalocale/SpLocaleContainer.betwixt");
                            InputSource inputSrc    = new InputSource(inputStream); 
                            beanWriter.write(container, inputSrc);
                            inputStream.close(); */

                            beanWriter.write(container);

                            total += step;
                            firePropertyChange("progress", 0, (int) total);
                        }

                        fw.write("</vector>\n");
                        fw.close();

                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }

                } catch (Exception e) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerDlg.class, e);
                    e.printStackTrace();

                } finally {
                    if (session != null) {
                        session.close();
                    }
                }

                return null;
            }

            @Override
            protected void done() {
                super.done();

                glassPane.setVisible(false);
            }
        };

        backupWorker.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(final PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("progress")) {
                    glassPane.setProgress((Integer) evt.getNewValue());
                }
            }
        });
        backupWorker.execute();
    }
}

From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java

@Override
protected void exportButtonActionPerformed(ActionEvent evt) {
    String outputDirectory = null;
    String outputFile = null;/*  w ww . java 2  s  .  c  om*/
    String measurement = (String) measurementLineResultComboBox.getSelectedItem();
    Integer step = Integer.parseInt(stepLineResultTextField.getText());

    FileDialog fileopen = new FileDialog(new Frame(), "Open Results Directory", FileDialog.SAVE);
    fileopen.setModalityType(ModalityType.DOCUMENT_MODAL);
    fileopen.setVisible(true);

    if (fileopen.getFile() != null) {
        outputDirectory = fileopen.getDirectory();
        outputFile = fileopen.getFile();
    }

    if (outputDirectory != null && outputFile != null) {
        new CSVParser().parse(outputDirectory, outputFile, resultFiles, measurement, step);
    }
}

From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java

/**
 *
 * @param columnsFormulasToPrint/*  w  w w. j  a v  a  2s  .  c o m*/
 *            If null, print all columns
 * @param stripNewLinesInCells
 * @param filePath
 *            Full path to save file to; if null, user will be prompted.
 */
public void saveFilteredRowsToFile(List<Integer> columnsFormulasToPrint, boolean stripNewLinesInCells,
        String filePath) {
    String saveTo;
    if (filePath == null) {
        FileDialog dialog = new FileDialog(new Frame(), "Save filtered rows to", FileDialog.SAVE);
        dialog.setVisible(true);
        saveTo = dialog.getDirectory();
        if (saveTo == null)
            return;

        saveTo += "/" + dialog.getFile();
    } else {
        saveTo = filePath;
    }

    PrintWriter out = null;
    try {
        out = new PrintWriter(saveTo);

        StringBuffer b = new StringBuffer();
        if (columnsFormulasToPrint == null) {
            for (int i = 0; i < this.getColumnCount(); i++) {
                b.append(getColumnName(i));
                if (i < getColumnCount() - 1)
                    b.append("\t");
            }
        } else {
            int index = 0;
            for (int i : columnsFormulasToPrint) {
                b.append(getColumnName(i));
                if (index + 1 < columnsFormulasToPrint.size())
                    b.append("\t");
                index++;
            }
        }
        out.println(b);

        for (int i = 0; i < model.getRowCount(); i++) {
            int rowIndex = convertRowIndexToView(i);
            if (rowIndex > -1) {
                if (columnsFormulasToPrint == null)
                    if (stripNewLinesInCells)
                        out.println(getRowAsString(rowIndex).replaceAll("\n", " "));
                    else
                        out.println(getRowAsString(rowIndex));
                else {
                    boolean first = true;
                    for (int column : columnsFormulasToPrint) {
                        if (!first) {
                            out.print("\t");
                        }
                        first = false;
                        SpreadsheetCell cell = (SpreadsheetCell) getValueAt(rowIndex, column);
                        if (cell != null) {
                            String formula = cell.getFormula();
                            if (formula != null) {
                                if (stripNewLinesInCells)
                                    out.print(formula.replaceAll("\n", " "));
                                else
                                    out.print(formula);
                            }
                        }
                    }
                    out.println("");
                }
            }
        }

        out.close();
    } catch (FileNotFoundException e) {
        Utils.printStack(e);
        Utils.displayMessage("Could not save table", true, LogLevel.ERROR);
    }
}

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  .ja v  a 2 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;//from   ww  w . ja va2 s .  c o  m
    }
    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:jpad.MainEditor.java

public void saveAs_OSX_Nix() {
    String fileToSaveTo = null;//  www  .  j av a 2 s . c  o  m
    FilenameFilter awtFilter = new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            String lowercaseName = name.toLowerCase();
            if (lowercaseName.endsWith(".txt")) {
                return true;
            } else {
                return false;
            }
        }
    };
    FileDialog fd = new FileDialog(this, "Save Text File", FileDialog.SAVE);
    fd.setDirectory(System.getProperty("java.home"));
    if (curFile == null)
        fd.setFile("Untitled.txt");
    else
        fd.setFile(curFile);
    fd.setFilenameFilter(awtFilter);
    fd.setVisible(true);
    if (fd.getFile() != null)
        fileToSaveTo = fd.getDirectory() + fd.getFile();
    else {
        fileToSaveTo = fd.getFile();
        return;
    }

    curFile = fileToSaveTo;
    JRootPane root = this.getRootPane();
    root.putClientProperty("Window.documentFile", new File(curFile));
    hasChanges = false;
    hasSavedToFile = true;
}

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java

/**
 * //from  w w  w  .  j  a  v a2  s  .  c o m
 */
private void importSchema(final boolean doLocalization) {
    FileDialog fileDlg = new FileDialog((Dialog) null);
    fileDlg.setTitle(getResourceString(doLocalization ? SL_CHS_LOC : SL_CHS_IMP));
    UIHelper.centerAndShow(fileDlg);

    String fileName = fileDlg.getFile();
    if (StringUtils.isNotEmpty(fileName)) {
        String title = getResourceString(doLocalization ? "SL_L10N_SCHEMA" : "SL_IMPORT_SCHEMA");

        final File file = new File(fileDlg.getDirectory() + File.separator + fileName);
        final SimpleGlassPane glassPane = new SimpleGlassPane(title, 18);
        glassPane.setBarHeight(12);
        glassPane.setFillColor(new Color(0, 0, 0, 85));

        setGlassPane(glassPane);
        glassPane.setVisible(true);

        SwingWorker<Integer, Integer> importWorker = new SwingWorker<Integer, Integer>() {
            private boolean isOK = false;

            @Override
            protected Integer doInBackground() throws Exception {
                DataProviderSessionIFace localSession = null;
                try {
                    localSession = DataProviderFactory.getInstance().createSession();

                    localSession.beginTransaction();

                    BuildSampleDatabase bsd = new BuildSampleDatabase();

                    Discipline discipline = localSession.get(Discipline.class,
                            AppContextMgr.getInstance().getClassObject(Discipline.class).getId());

                    isOK = bsd.loadSchemaLocalization(discipline, schemaType, DBTableIdMgr.getInstance(), null, //catFmtName,
                            null, //accFmtName,
                            doLocalization ? UpdateType.eLocalize : UpdateType.eImport, // isDoingUpdate
                            file, // external file
                            glassPane, localSession);
                    if (isOK) {
                        localSession.commit();
                    } else {
                        localSession.rollback();
                    }

                } catch (Exception ex) {
                    ex.printStackTrace();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BuildSampleDatabase.class, ex);

                } finally {
                    if (localSession != null) {
                        localSession.close();
                    }
                }

                return null;
            }

            @Override
            protected void done() {
                super.done();

                glassPane.setVisible(false);

                if (isOK) {
                    UIRegistry.showLocalizedMsg("Specify.ABT_EXIT");
                    CommandDispatcher.dispatch(new CommandAction("App", "AppReqExit"));
                }
            }
        };
        importWorker.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(final PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("progress")) {
                    glassPane.setProgress((Integer) evt.getNewValue());
                }
            }
        });
        importWorker.execute();
    }
}

From source file:Forms.CreateGearForm.java

private GearSpec loadGearSpec() {
    //Get top level frame
    JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel);

    //Create dialog for choosing gearspec file
    FileDialog fd = new FileDialog(topFrame, "Choose a .gearspec file", FileDialog.LOAD);
    fd.setDirectory(System.getProperty("user.home"));
    fd.setFile("*.gearspec");
    fd.setVisible(true);// w  w w  . j  a v a  2 s .com
    //Get file
    String filename = fd.getFile();
    if (filename == null)
        System.out.println("You cancelled the choice");
    else {
        System.out.println("You chose " + filename);

        //Get spec file
        File specFile = new File(fd.getDirectory() + Utils.pathSeparator() + filename);

        //If it exists, set it as the selected file path
        if (specFile.exists()) {
            //Generate spec
            return Utils.specForFile(specFile);
        }
    }

    return null;
}

From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java

private void openTestScenario() {
    FileDialog fileopen = new FileDialog(this, "Open Test Scenario", FileDialog.LOAD);
    fileopen.setFilenameFilter(new FilenameFilter() {
        @Override//from   w  w  w  .j  a va2  s  .  c  om
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith("xml");
        }
    });

    fileopen.setVisible(true);

    if (fileopen.getFile() != null) {
        filePath = fileopen.getDirectory();
        fileName = fileopen.getFile();

        algorithm = AlgorithmXMLParser.read(filePath, fileName);
        configureTree();
        updateToolBarButtonsState();
        ((CardLayout) panelTestScenario.getLayout()).last(panelTestScenario);
    }
}