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: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);/*from  www  . j  a  v a  2s . co  m*/
    dialog.setVisible(true);
    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:sim.util.media.chart.ChartGenerator.java

/** Generates a new ChartGenerator with a blank chart.  Before anything else, buildChart() is called.  */
public ChartGenerator() {
    // create the chart
    buildChart();/* w ww  .ja v a2 s.  c  o  m*/
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(true);

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    split.setBorder(new EmptyBorder(0, 0, 0, 0));
    JScrollPane scroll = new JScrollPane();
    JPanel b = new JPanel();
    b.setLayout(new BorderLayout());
    b.add(seriesAttributes, BorderLayout.NORTH);
    b.add(new JPanel(), BorderLayout.CENTER);
    scroll.getViewport().setView(b);
    scroll.setBackground(getBackground());
    scroll.getViewport().setBackground(getBackground());
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());

    LabelledList list = new LabelledList("Chart Properties");
    DisclosurePanel pan1 = new DisclosurePanel("Chart Properties", list);
    globalAttributes.add(pan1);

    JLabel j = new JLabel("Right-Click or Control-Click");
    j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC));
    list.add(j);
    j = new JLabel("on Chart for More Options");
    j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC));
    list.add(j);

    titleField = new PropertyField() {
        public String newValue(String newValue) {
            setTitle(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    titleField.setValue(chart.getTitle().getText());

    list.add(new JLabel("Title"), titleField);

    buildGlobalAttributes(list);

    final JCheckBox legendCheck = new JCheckBox();
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                LegendTitle title = new LegendTitle(chart.getPlot());
                title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0, 8, 0, 4));
                chart.addLegend(title);
            } else {
                chart.removeLegend();
            }
        }
    };
    legendCheck.addItemListener(il);
    list.add(new JLabel("Legend"), legendCheck);
    legendCheck.setSelected(true);

    /*
      final JCheckBox aliasCheck = new JCheckBox();
      aliasCheck.setSelected(chart.getAntiAlias());
      il = new ItemListener()
      {
      public void itemStateChanged(ItemEvent e)
      {
      chart.setAntiAlias( e.getStateChange() == ItemEvent.SELECTED );
      }
      };
      aliasCheck.addItemListener(il);
      list.add(new JLabel("Antialias"), aliasCheck);
    */

    JPanel pdfButtonPanel = new JPanel();
    pdfButtonPanel.setBorder(new javax.swing.border.TitledBorder("Chart Output"));
    DisclosurePanel pan2 = new DisclosurePanel("Chart Output", pdfButtonPanel);

    pdfButtonPanel.setLayout(new BorderLayout());
    Box pdfbox = new Box(BoxLayout.Y_AXIS);
    pdfButtonPanel.add(pdfbox, BorderLayout.WEST);

    JButton pdfButton = new JButton("Save as PDF");
    pdfbox.add(pdfButton);
    pdfButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileDialog fd = new FileDialog(frame, "Choose PDF file...", FileDialog.SAVE);
            fd.setFile(chart.getTitle().getText() + ".pdf");
            fd.setVisible(true);
            String fileName = fd.getFile();
            if (fileName != null) {
                Dimension dim = chartPanel.getPreferredSize();
                PDFEncoder.generatePDF(chart, dim.width, dim.height,
                        new File(fd.getDirectory(), Utilities.ensureFileEndsWith(fd.getFile(), ".pdf")));
            }
        }
    });
    movieButton = new JButton("Create a Movie");
    pdfbox.add(movieButton);
    pdfbox.add(Box.createGlue());
    movieButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (movieMaker == null)
                startMovie();
            else
                stopMovie();
        }
    });

    globalAttributes.add(pan2);

    // we add into an outer box so we can later on add more global seriesAttributes
    // as the user instructs and still have glue be last
    Box outerAttributes = Box.createVerticalBox();
    outerAttributes.add(globalAttributes);
    outerAttributes.add(Box.createGlue());

    p.add(outerAttributes, BorderLayout.NORTH);
    p.add(scroll, BorderLayout.CENTER);
    p.setMinimumSize(new Dimension(0, 0));
    p.setPreferredSize(new Dimension(200, 0));
    split.setLeftComponent(p);

    // Add scale and proportion fields
    Box header = Box.createHorizontalBox();

    final double MAXIMUM_SCALE = 8;

    fixBox = new JCheckBox("Fill");
    fixBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setFixed(fixBox.isSelected());
        }
    });
    header.add(fixBox);
    fixBox.setSelected(true);

    // add the scale field
    scaleField = new NumberTextField("  Scale: ", 1.0, true) {
        public double newValue(double newValue) {
            if (newValue <= 0.0)
                newValue = currentValue;
            if (newValue > MAXIMUM_SCALE)
                newValue = currentValue;
            scale = newValue;
            resizeChart();
            return newValue;
        }
    };
    scaleField.setToolTipText("Zoom in and out");
    scaleField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    scaleField.setEnabled(false);
    scaleField.setText("");
    header.add(scaleField);

    // add the proportion field
    proportionField = new NumberTextField("  Proportion: ", 1.5, true) {
        public double newValue(double newValue) {
            if (newValue <= 0.0)
                newValue = currentValue;
            proportion = newValue;
            resizeChart();
            return newValue;
        }
    };
    proportionField.setToolTipText("Change the chart proportions (ratio of width to height)");
    proportionField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    header.add(proportionField);

    chartHolder.setMinimumSize(new Dimension(0, 0));
    chartHolder.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    chartHolder.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    chartHolder.getViewport().setBackground(Color.gray);
    JPanel p2 = new JPanel();
    p2.setLayout(new BorderLayout());
    p2.add(chartHolder, BorderLayout.CENTER);
    p2.add(header, BorderLayout.NORTH);
    split.setRightComponent(p2);
    setLayout(new BorderLayout());
    add(split, BorderLayout.CENTER);

    // set the default to be white, which looks good when printed
    chart.setBackgroundPaint(Color.WHITE);

    // JFreeChart has a hillariously broken way of handling font scaling.
    // It allows fonts to scale independently in X and Y.  We hack a workaround here.
    chartPanel.setMinimumDrawHeight((int) DEFAULT_CHART_HEIGHT);
    chartPanel.setMaximumDrawHeight((int) DEFAULT_CHART_HEIGHT);
    chartPanel.setMinimumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion));
    chartPanel.setMaximumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion));
    chartPanel.setPreferredSize(new java.awt.Dimension((int) (DEFAULT_CHART_HEIGHT * DEFAULT_CHART_PROPORTION),
            (int) (DEFAULT_CHART_HEIGHT)));
}

From source file:edu.gmu.cs.sim.util.media.chart.ChartGenerator.java

/** Generates a new ChartGenerator with a blank chart.  Before anything else, buildChart() is called.  */
public ChartGenerator() {
    // create the chart
    buildChart();/*from  w  w  w. j av a 2  s.  c om*/
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(true);

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    split.setBorder(new EmptyBorder(0, 0, 0, 0));
    JScrollPane scroll = new JScrollPane();
    JPanel b = new JPanel();
    b.setLayout(new BorderLayout());
    b.add(seriesAttributes, BorderLayout.NORTH);
    b.add(new JPanel(), BorderLayout.CENTER);
    scroll.getViewport().setView(b);
    scroll.setBackground(getBackground());
    scroll.getViewport().setBackground(getBackground());
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());

    LabelledList list = new LabelledList("Chart Properties");
    DisclosurePanel pan1 = new DisclosurePanel("Chart Properties", list);
    globalAttributes.add(pan1);

    JLabel j = new JLabel("Right-Click or Control-Click");
    j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC));
    list.add(j);
    j = new JLabel("on Chart for More Options");
    j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC));
    list.add(j);

    titleField = new PropertyField() {
        public String newValue(String newValue) {
            setTitle(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    titleField.setValue(chart.getTitle().getText());

    list.add(new JLabel("Title"), titleField);

    buildGlobalAttributes(list);

    final JCheckBox legendCheck = new JCheckBox();
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                LegendTitle title = new LegendTitle(chart.getPlot());
                title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0, 8, 0, 4));
                chart.addLegend(title);
            } else {
                chart.removeLegend();
            }
        }
    };
    legendCheck.addItemListener(il);
    list.add(new JLabel("Legend"), legendCheck);
    legendCheck.setSelected(true);

    /*
      final JCheckBox aliasCheck = new JCheckBox();
      aliasCheck.setSelected(chart.getAntiAlias());
      il = new ItemListener()
      {
      public void itemStateChanged(ItemEvent e)
      {
      chart.setAntiAlias( e.getStateChange() == ItemEvent.SELECTED );
      }
      };
      aliasCheck.addItemListener(il);
      list.add(new JLabel("Antialias"), aliasCheck);
    */

    JPanel pdfButtonPanel = new JPanel();
    pdfButtonPanel.setBorder(new javax.swing.border.TitledBorder("Chart Output"));
    DisclosurePanel pan2 = new DisclosurePanel("Chart Output", pdfButtonPanel);

    pdfButtonPanel.setLayout(new BorderLayout());
    Box pdfbox = new Box(BoxLayout.Y_AXIS);
    pdfButtonPanel.add(pdfbox, BorderLayout.WEST);

    JButton pdfButton = new JButton("Save as PDF");
    pdfbox.add(pdfButton);
    pdfButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileDialog fd = new FileDialog(frame, "Choose PDF file...", FileDialog.SAVE);
            fd.setFile(chart.getTitle().getText() + ".pdf");
            fd.setVisible(true);
            String fileName = fd.getFile();
            if (fileName != null) {
                Dimension dim = chartPanel.getPreferredSize();
                PDFEncoder.generatePDF(chart, dim.width, dim.height,
                        new File(fd.getDirectory(), Utilities.ensureFileEndsWith(fd.getFile(), ".pdf")));
            }
        }
    });
    movieButton = new JButton("Create a Movie");
    pdfbox.add(movieButton);
    pdfbox.add(Box.createGlue());
    movieButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (movieMaker == null) {
                startMovie();
            } else {
                stopMovie();
            }
        }
    });

    globalAttributes.add(pan2);

    // we add into an outer box so we can later on add more global seriesAttributes
    // as the user instructs and still have glue be last
    Box outerAttributes = Box.createVerticalBox();
    outerAttributes.add(globalAttributes);
    outerAttributes.add(Box.createGlue());

    p.add(outerAttributes, BorderLayout.NORTH);
    p.add(scroll, BorderLayout.CENTER);
    p.setMinimumSize(new Dimension(0, 0));
    p.setPreferredSize(new Dimension(200, 0));
    split.setLeftComponent(p);

    // Add scale and proportion fields
    Box header = Box.createHorizontalBox();

    final double MAXIMUM_SCALE = 8;

    fixBox = new JCheckBox("Fill");
    fixBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setFixed(fixBox.isSelected());
        }
    });
    header.add(fixBox);
    fixBox.setSelected(true);

    // add the scale field
    scaleField = new NumberTextField("  Scale: ", 1.0, true) {
        public double newValue(double newValue) {
            if (newValue <= 0.0) {
                newValue = currentValue;
            }
            if (newValue > MAXIMUM_SCALE) {
                newValue = currentValue;
            }
            scale = newValue;
            resizeChart();
            return newValue;
        }
    };
    scaleField.setToolTipText("Zoom in and out");
    scaleField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    scaleField.setEnabled(false);
    scaleField.setText("");
    header.add(scaleField);

    // add the proportion field
    proportionField = new NumberTextField("  Proportion: ", 1.5, true) {
        public double newValue(double newValue) {
            if (newValue <= 0.0) {
                newValue = currentValue;
            }
            proportion = newValue;
            resizeChart();
            return newValue;
        }
    };
    proportionField.setToolTipText("Change the chart proportions (ratio of width to height)");
    proportionField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    header.add(proportionField);

    chartHolder.setMinimumSize(new Dimension(0, 0));
    chartHolder.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    chartHolder.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    chartHolder.getViewport().setBackground(Color.gray);
    JPanel p2 = new JPanel();
    p2.setLayout(new BorderLayout());
    p2.add(chartHolder, BorderLayout.CENTER);
    p2.add(header, BorderLayout.NORTH);
    split.setRightComponent(p2);
    setLayout(new BorderLayout());
    add(split, BorderLayout.CENTER);

    // set the default to be white, which looks good when printed
    chart.setBackgroundPaint(Color.WHITE);

    // JFreeChart has a hillariously broken way of handling font scaling.
    // It allows fonts to scale independently in X and Y.  We hack a workaround here.
    chartPanel.setMinimumDrawHeight((int) DEFAULT_CHART_HEIGHT);
    chartPanel.setMaximumDrawHeight((int) DEFAULT_CHART_HEIGHT);
    chartPanel.setMinimumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion));
    chartPanel.setMaximumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion));
    chartPanel.setPreferredSize(new java.awt.Dimension((int) (DEFAULT_CHART_HEIGHT * DEFAULT_CHART_PROPORTION),
            (int) (DEFAULT_CHART_HEIGHT)));
}

From source file:org.broad.igv.hic.MainWindow.java

private void loadMenuItemActionPerformed(ActionEvent e) {
    FileDialog dlg = new FileDialog(this);
    dlg.setMode(FileDialog.LOAD);
    dlg.setVisible(true);//from  ww w.  jav  a 2s.  co m
    String file = dlg.getFile();
    if (file != null) {
        try {
            File f = new File(dlg.getDirectory(), dlg.getFile());
            load(f.getAbsolutePath());
        } catch (IOException e1) {
            e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }
}

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 w ww .j  a v a 2s .  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:edu.ku.brc.af.core.db.MySQLBackupService.java

@Override
public void doRestore() {
    AppPreferences remotePrefs = AppPreferences.getLocalPrefs();
    final String mysqlLoc = remotePrefs.get(MYSQL_LOC, getDefaultMySQLLoc());
    final String backupLoc = remotePrefs.get(MYSQLBCK_LOC, getDefaultBackupLoc());

    if (!(new File(mysqlLoc)).exists()) {
        UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_RESTORE", mysqlLoc);
        return;/*from  ww w . java  2s.c o  m*/
    }

    File backupDir = new File(backupLoc);
    if (!backupDir.exists()) {
        if (!backupDir.mkdir()) {
            UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_BK_DIR", backupDir.getAbsoluteFile());
            return;
        }
    }

    FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString("Open"),
            FileDialog.LOAD);
    dlg.setDirectory(backupLoc);
    dlg.setVisible(true);

    String dirStr = dlg.getDirectory();
    String fileName = dlg.getFile();
    if (StringUtils.isEmpty(dirStr) || StringUtils.isEmpty(fileName)) {
        return;
    }

    errorMsg = null;

    final String path = dirStr + fileName;

    final JStatusBar statusBar = UIRegistry.getStatusBar();
    statusBar.setIndeterminate(STATUSBAR_NAME, true);

    String databaseName = DBConnection.getInstance().getDatabaseName();
    SimpleGlassPane glassPane = UIRegistry
            .writeSimpleGlassPaneMsg(getLocalizedMessage("MySQLBackupService.RESTORING", databaseName), 24);

    doCompareBeforeRestore(path, glassPane);
}

From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java

@SuppressWarnings({ "unchecked" })
private void openXML() {
    FileDialog fileDlg = new FileDialog((Frame) UIRegistry.getTopWindow(), "", FileDialog.LOAD);

    fileDlg.setFilenameFilter(new FilenameFilter() {
        @Override/*from www .j  a  va2  s  .  co  m*/
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".xml");
        }
    });
    fileDlg.setVisible(true);

    String fileName = fileDlg.getFile();
    if (fileName != null) {
        File iFile = new File(fileDlg.getDirectory() + File.separator + fileName);

        XStream xstream = new XStream();
        FormInfo.configXStream(xstream);
        FormFieldInfo.configXStream(xstream);

        try {
            forms = (Vector<FormInfo>) xstream.fromXML(FileUtils.openInputStream(iFile));
            formsTable.setModel(new FormCellModel(forms));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java

/**
 * //from w  ww .  j  a v a  2s  .  c o  m
 */
protected void exportResource() {

    int index = levelCBX.getSelectedIndex();
    if (index > -1) {
        String exportedName = null;

        String data = null;
        String fileName = null;
        AppResourceIFace appRes = null;
        if (tabbedPane.getSelectedComponent() == viewsPanel) {
            if (viewSetsList.getSelectedIndex() > -1) {
                SpViewSetObj vso = (SpViewSetObj) viewSetsList.getSelectedValue();
                exportedName = vso.getName();
                fileName = FilenameUtils.getName(vso.getFileName());
                data = vso.getDataAsString(true);
            }
        } else {
            JList theList = tabbedPane.getSelectedComponent() == repPanel ? repList : resList;
            if (theList.getSelectedIndex() > 0) {
                appRes = (AppResourceIFace) theList.getSelectedValue();
                exportedName = appRes.getName();
                fileName = FilenameUtils.getName(exportedName);
                data = appRes.getDataAsString();

            }
        }

        if (StringUtils.isNotEmpty(data)) {
            final String EXP_DIR_PREF = "RES_LAST_EXPORT_DIR";
            String initalExportDir = AppPreferences.getLocalPrefs().get(EXP_DIR_PREF, getUserHomeDir());

            FileDialog fileDlg = new FileDialog(this, getResourceString("RIE_ExportResource"), FileDialog.SAVE);

            File expDir = new File(initalExportDir);
            if (StringUtils.isNotEmpty(initalExportDir) && expDir.exists()) {
                fileDlg.setDirectory(initalExportDir);
            }

            fileDlg.setFile(fileName);

            UIHelper.centerAndShow(fileDlg);

            String dirStr = fileDlg.getDirectory();
            fileName = fileDlg.getFile();

            if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) {
                AppPreferences.getLocalPrefs().put(EXP_DIR_PREF, dirStr);

                File expFile = new File(dirStr + File.separator + fileName);
                try {
                    if (isReportResource((SpAppResource) appRes)
                            && isSpReportResource((SpAppResource) appRes)) {
                        writeSpReportResToZipFile(expFile, data, appRes);
                    } else {
                        FileUtils.writeStringToFile(expFile, data);
                    }

                } catch (FileNotFoundException ex) {
                    showLocalizedMsg("RIE_NOFILEPERM");

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

        if (exportedName != null) {
            getStatusBar().setText(getLocalizedMessage("RIE_RES_EXPORTED", exportedName));
        }
    }
}

From source file:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java

/**
 * /*from w  w  w  .j  a v a 2  s  .  c o  m*/
 */
public void startUp() {
    //AskForDirectory afd = new AskForDirectory(frame);
    //currentPath = afd.getDirectory();
    FileDialog dlg = new FileDialog(frame, "Select a Directory", FileDialog.LOAD);
    UIHelper.centerAndShow(dlg);
    String currentPath = dlg.getDirectory();

    if (StringUtils.isNotEmpty(currentPath)) {
        if (doSrcParsing) {
            File rootDir = new File("/Users/rods/Documents/SVN/SpecifyInsightL10N");
            srcIndexer = new L10NSrcIndexer(rootDir);
            doScanSources();
        }

        boolean isDirOK = true;
        rootDir = new File(currentPath);
        if (!rootDir.exists()) {
            String dirPath = getFullPath(currentPath);
            rootDir = new File(dirPath);
            isDirOK = rootDir.exists();
        }

        if (isDirOK) {
            createUI();

            register(MAINPANE, mainPane);
            frame.setGlassPane(glassPane = GhostGlassPane.getInstance());
            frame.setLocationRelativeTo(null);
            Toolkit.getDefaultToolkit().setDynamicLayout(true);
            register(GLASSPANE, glassPane);

            if (setupSrcFiles(rootDir) > 0) {
                frame.pack();
                UIHelper.centerAndShow(frame);

                destLanguage = doChooseLangLocale(Locale.ENGLISH);
                if (destLanguage != null) {
                    destLbl.setText(destLanguage.getDisplayName() + ":");
                    return;
                }
            } else {
                UIRegistry.showError("The are no localizable files in the directory you selected.");
                System.exit(0);
            }
        }
    }

    UIRegistry.showError("StrLocalizer will exit.");
    System.exit(0);
}

From source file:processing.app.Sketch.java

/**
 * Handles 'Save As' for a sketch.//from ww  w  .j ava 2  s  . c o  m
 * <P>
 * This basically just duplicates the current sketch folder to
 * a new location, and then calls 'Save'. (needs to take the current
 * state of the open files and save them to the new folder..
 * but not save over the old versions for the old sketch..)
 * <P>
 * Also removes the previously-generated .class and .jar files,
 * because they can cause trouble.
 */
protected boolean saveAs() throws IOException {
    // get new name for folder
    FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
    if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())
            || isUntitled()) {
        // default to the sketchbook folder
        fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
    } else {
        // default to the parent folder of where this was
        // on macs a .getParentFile() method is required

        fd.setDirectory(data.getFolder().getParentFile().getAbsolutePath());
    }
    String oldName = data.getName();
    fd.setFile(oldName);

    fd.setVisible(true);
    String newParentDir = fd.getDirectory();
    String newName = fd.getFile();

    // user canceled selection
    if (newName == null)
        return false;
    newName = Sketch.checkName(newName);

    File newFolder = new File(newParentDir, newName);

    // make sure there doesn't exist a .cpp file with that name already
    // but ignore this situation for the first tab, since it's probably being
    // resaved (with the same name) to another location/folder.
    for (int i = 1; i < data.getCodeCount(); i++) {
        SketchCode code = data.getCode(i);
        if (newName.equalsIgnoreCase(code.getPrettyName())) {
            Base.showMessage(tr("Error"), I18n.format(tr("You can't save the sketch as \"{0}\"\n"
                    + "because the sketch already has a file with that name."), newName));
            return false;
        }
    }

    // check if the paths are identical
    if (newFolder.equals(data.getFolder())) {
        // just use "save" here instead, because the user will have received a
        // message (from the operating system) about "do you want to replace?"
        return save();
    }

    // check to see if the user is trying to save this sketch inside itself
    try {
        String newPath = newFolder.getCanonicalPath() + File.separator;
        String oldPath = data.getFolder().getCanonicalPath() + File.separator;

        if (newPath.indexOf(oldPath) == 0) {
            Base.showWarning(tr("How very Borges of you"), tr(
                    "You cannot save the sketch into a folder\n" + "inside itself. This would go on forever."),
                    null);
            return false;
        }
    } catch (IOException e) {
        //ignore
    }

    // if the new folder already exists, then need to remove
    // its contents before copying everything over
    // (user will have already been warned)
    if (newFolder.exists()) {
        Base.removeDir(newFolder);
    }
    // in fact, you can't do this on windows because the file dialog
    // will instead put you inside the folder, but it happens on osx a lot.

    // now make a fresh copy of the folder
    newFolder.mkdirs();

    // grab the contents of the current tab before saving
    // first get the contents of the editor text area
    if (current.getCode().isModified()) {
        current.getCode().setProgram(editor.getText());
    }

    // save the other tabs to their new location
    for (SketchCode code : data.getCodes()) {
        if (data.indexOfCode(code) == 0)
            continue;
        File newFile = new File(newFolder, code.getFileName());
        code.saveAs(newFile);
    }

    // re-copy the data folder (this may take a while.. add progress bar?)
    if (data.getDataFolder().exists()) {
        File newDataFolder = new File(newFolder, "data");
        Base.copyDir(data.getDataFolder(), newDataFolder);
    }

    // re-copy the code folder
    if (data.getCodeFolder().exists()) {
        File newCodeFolder = new File(newFolder, "code");
        Base.copyDir(data.getCodeFolder(), newCodeFolder);
    }

    // copy custom applet.html file if one exists
    // http://dev.processing.org/bugs/show_bug.cgi?id=485
    File customHtml = new File(data.getFolder(), "applet.html");
    if (customHtml.exists()) {
        File newHtml = new File(newFolder, "applet.html");
        Base.copyFile(customHtml, newHtml);
    }

    // save the main tab with its new name
    File newFile = new File(newFolder, newName + ".ino");
    data.getCode(0).saveAs(newFile);

    editor.handleOpenUnchecked(newFile, currentIndex, editor.getSelectionStart(), editor.getSelectionStop(),
            editor.getScrollPosition());

    // Name changed, rebuild the sketch menus
    //editor.sketchbook.rebuildMenusAsync();
    editor.base.rebuildSketchbookMenus();

    // Make sure that it's not an untitled sketch
    setUntitled(false);

    // let Editor know that the save was successful
    return true;
}