Example usage for javax.swing JFileChooser setSelectedFile

List of usage examples for javax.swing JFileChooser setSelectedFile

Introduction

In this page you can find the example usage for javax.swing JFileChooser setSelectedFile.

Prototype

@BeanProperty(preferred = true)
public void setSelectedFile(File file) 

Source Link

Document

Sets the selected file.

Usage

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java

/**
 *
 * @throws IOException//from   w  w  w . j a v a  2 s  .c o  m
 */
private void createPdf(JFreeChart chart) throws IOException {
    // choose directory to save pdf file
    JFileChooser chooseDirectory = new JFileChooser();
    chooseDirectory.setDialogTitle("Choose a directory to save the report");
    chooseDirectory.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooseDirectory.setSelectedFile(new File("chart rose plot" + ".pdf"));
    // in response to the button click, show open dialog
    int returnVal = chooseDirectory.showSaveDialog(angleDirectPanel);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File directory = chooseDirectory.getCurrentDirectory();
        PdfSwingWorker pdfSwingWorker = new PdfSwingWorker(directory,
                chooseDirectory.getSelectedFile().getName(), chart);
        pdfSwingWorker.execute();
    } else {
        singleCellPreProcessingController.showMessage("Open command cancelled by user", "",
                JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:org.nekorp.workflow.desktop.view.ServicioView.java

private void ordenServicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ordenServicioActionPerformed
    try {//from w  ww.j av a 2s .c o  m
        if (servicioMetaData.isEditado()) {
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
            this.aplication.guardaServicio();
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
        }
        ParametrosReporteOS param = new ParametrosReporteOS();
        Object[] options = { "Evaluacin", "Presupuesto" };
        int n = javax.swing.JOptionPane.showOptionDialog(mainFrame, "Qu tipo de reporte desea generar?",
                "Tipo de reporte", javax.swing.JOptionPane.YES_NO_OPTION,
                javax.swing.JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
        if (n == javax.swing.JOptionPane.CLOSED_OPTION) {
            return;
        }
        param.setConCosto(!(n == javax.swing.JOptionPane.YES_OPTION));
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf");
        chooser.setFileFilter(filter);
        String homePath = System.getProperty("user.home");
        String prefijo;
        if (param.isConCosto()) {
            prefijo = "/Orden-Servicio-presupuesto-";
        } else {
            prefijo = "/Orden-Servicio-evaluacion-";
        }
        File f = new File(
                new File(homePath + prefijo + this.viewServicioModel.getId() + ".pdf").getCanonicalPath());
        chooser.setSelectedFile(f);
        int returnVal = chooser.showSaveDialog(this.mainFrame);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
            param.setDestination(chooser.getSelectedFile());
            this.aplication.generaOrdenServicio(param);
        }
    } catch (IllegalArgumentException e) {
        //no lo guardo por que tenia horribles errores... tambien especializar la excepcion
    } catch (IOException ex) {
        ServicioView.LOGGER.error("error al exportar orden de servicio", ex);
    } finally {
        this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
}

From source file:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java

/**
 * Suche einen Platz und den Namen frs Logfile Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //from w  w  w.  j  a  v  a2 s .  co m
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 03.08.2012
 */
private void chooseLogFile() {
    JFileChooser fileChooser;
    int retVal;
    //
    // Einen Dateiauswahldialog Creieren
    //
    fileChooser = new JFileChooser();
    fileChooser.setLocale(Locale.getDefault());
    fileChooser.setDialogTitle(fileChooserLogTitle);
    fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    fileChooser.setApproveButtonToolTipText(approveLogButtonTooltip);
    // das existierende Logfile voreinstellen
    fileChooser.setSelectedFile(SpxPcloggerProgramConfig.logFile);
    retVal = fileChooser.showDialog(this, approveLogButtonText);
    // Mal sehen, was der User gewollt hat
    if (retVal == JFileChooser.APPROVE_OPTION) {
        // Ja, ich wollte das so
        // nach dem nchsten Programmstart dieses File anlegen/nutzen
        logfileNameTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
        wasChangedParameter = true;
        lg.debug("select <" + fileChooser.getSelectedFile().getName() + "> as new logfile after restart.");
    }
}

From source file:com.att.aro.ui.view.menu.tools.RegexWizard.java

private void saveConfig() {
    if (this.videoConfig != null) {
        doEnter();//from w w  w  . j  a va 2s  .  c  o  m
        VideoDataTags[] xref = resultsTable.getVideoDataTags();
        if (xref.length > 0) {
            this.videoConfig.setXref(xref);
        }
    }
    // update object from fields
    updateConfigAndTags();

    if (this.videoConfig != null && voConfigHelper.validateConfig(videoConfig)) {
        try {
            JFileChooser fileChooser = new JFileChooser(voConfigHelper.getFolderPath());
            if (videoConfig.getDesc() != null) {
                fileChooser.setSelectedFile(new File(videoConfig.getDesc()));
            }
            // fileChooser.setCurrentDirectory(new File(voConfigHelper.getFolderPath()));
            if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                voConfigHelper.saveConfigFile(videoConfig.getVideoType(),
                        fileChooser.getSelectedFile().getName().replaceAll("\\.json", ""),
                        videoConfig.getType(), videoConfig.getRegex(), videoConfig.getHeaderRegex(),
                        videoConfig.getResponseRegex(), videoConfig.getXref());
            }
        } catch (JsonGenerationException e1) {
            log.error("VideoAnalysisConfig failed Jason generation :" + e1.getMessage());
        } catch (JsonMappingException e1) {
            log.error("VideoAnalysisConfig failed to de-serialize :" + e1.getMessage());
        } catch (IOException e1) {
            log.error("VideoAnalysisConfig failed to save :" + e1.getMessage());
        } catch (Exception e1) {
            log.error("VideoAnalysisConfig failed to load :" + e1.getMessage());
        }

    } else {
        log.error("VideoAnalysisConfig is invalid: capture groups not equal to cross references");
        JOptionPane.showMessageDialog(this,
                String.format("%s config is invalid: capture groups not equal to cross references",
                        videoConfig != null ? videoConfig.getDesc() : "unknown"),
                "Failure", JOptionPane.ERROR_MESSAGE);
    }

}

From source file:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java

/**
 * Verzeichnis fr die Daten auswhlen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * /*from   ww w . j a  v  a  2s. c om*/
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 03.08.2012
 */
private void chooseDataDir() {
    JFileChooser fileChooser;
    int retVal;
    //
    // Einen Dateiauswahldialog Creieren
    //
    fileChooser = new JFileChooser();
    fileChooser.setLocale(Locale.getDefault());
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setDialogTitle(fileChooserDirTitle);
    fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    fileChooser.setApproveButtonToolTipText(approveDirButtonTooltip);
    // das existierende Logfile voreinstellen
    fileChooser.setSelectedFile(SpxPcloggerProgramConfig.databaseDir);
    retVal = fileChooser.showDialog(this, approveDirButtonText);
    // Mal sehen, was der User gewollt hat
    if (retVal == JFileChooser.APPROVE_OPTION) {
        // Ja, ich wollte das so
        databaseDirTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
        wasChangedParameter = true;
    }
}

From source file:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java

/**
 * Das exportverzeichis auswhlen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * /*from w w w .j a  va2s  .c o m*/
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 28.08.2012
 */
private void chooseExportDir() {
    JFileChooser fileChooser;
    int retVal;
    //
    // Einen Dateiauswahldialog Creieren
    //
    fileChooser = new JFileChooser();
    fileChooser.setLocale(Locale.getDefault());
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setDialogTitle(fileChooserExportDirTitle);
    fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    fileChooser.setApproveButtonToolTipText(approveDirButtonTooltip);
    // das existierende Verzeichnis voreinstellen
    fileChooser.setSelectedFile(SpxPcloggerProgramConfig.exportDir);
    retVal = fileChooser.showDialog(this, approveDirButtonText);
    // Mal sehen, was der User gewollt hat
    if (retVal == JFileChooser.APPROVE_OPTION) {
        // Ja, ich wollte das so
        exportDirTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
        wasChangedParameter = true;
    }
}

From source file:captureplugin.CapturePlugin.java

/**
 * Check the programs after data update.
 *//*  w  ww .  j a v  a  2s . c  o m*/
public void handleTvDataUpdateFinished() {
    mNeedsUpdate = true;

    if (mAllowedToShowDialog) {
        mNeedsUpdate = false;

        DeviceIf[] devices = mConfig.getDeviceArray();

        final DefaultTableModel model = new DefaultTableModel() {
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        model.setColumnCount(5);
        model.setColumnIdentifiers(new String[] { mLocalizer.msg("device", "Device"),
                Localizer.getLocalization(Localizer.I18N_CHANNEL), mLocalizer.msg("date", "Date"),
                ProgramFieldType.START_TIME_TYPE.getLocalizedName(),
                ProgramFieldType.TITLE_TYPE.getLocalizedName() });

        JTable table = new JTable(model);
        table.getTableHeader().setReorderingAllowed(false);
        table.getTableHeader().setResizingAllowed(false);
        table.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
            public Component getTableCellRendererComponent(JTable renderTable, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
                Component c = super.getTableCellRendererComponent(renderTable, value, isSelected, hasFocus, row,
                        column);

                if (value instanceof DeviceIf) {
                    if (((DeviceIf) value).getDeleteRemovedProgramsAutomatically() && !isSelected) {
                        c.setForeground(Color.red);
                    }
                }

                return c;
            }
        });

        int[] columnWidth = new int[5];

        for (int i = 0; i < columnWidth.length; i++) {
            columnWidth[i] = UiUtilities.getStringWidth(table.getFont(), model.getColumnName(i)) + 10;
        }

        for (DeviceIf device : devices) {
            Program[] deleted = device.checkProgramsAfterDataUpdateAndGetDeleted();

            if (deleted != null && deleted.length > 0) {
                for (Program p : deleted) {
                    if (device.getDeleteRemovedProgramsAutomatically() && !p.isExpired() && !p.isOnAir()) {
                        device.remove(UiUtilities.getLastModalChildOf(getParentFrame()), p);
                    } else {
                        device.removeProgramWithoutExecution(p);
                    }

                    if (!p.isExpired()) {
                        Object[] o = new Object[] { device, p.getChannel().getName(), p.getDateString(),
                                p.getTimeString(), p.getTitle() };

                        for (int i = 0; i < columnWidth.length; i++) {
                            columnWidth[i] = Math.max(columnWidth[i],
                                    UiUtilities.getStringWidth(table.getFont(), o[i].toString()) + 10);
                        }

                        model.addRow(o);
                    }
                }
            }

            device.getProgramList();
        }

        if (model.getRowCount() > 0) {
            int sum = 0;

            for (int i = 0; i < columnWidth.length; i++) {
                table.getColumnModel().getColumn(i).setPreferredWidth(columnWidth[i]);

                if (i < columnWidth.length - 1) {
                    table.getColumnModel().getColumn(i).setMaxWidth(columnWidth[i]);
                }

                sum += columnWidth[i];
            }

            JScrollPane scrollPane = new JScrollPane(table);
            scrollPane.setPreferredSize(new Dimension(450, 250));

            if (sum > 500) {
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                scrollPane.getViewport().setPreferredSize(
                        new Dimension(sum, scrollPane.getViewport().getPreferredSize().height));
            }

            JButton export = new JButton(mLocalizer.msg("exportList", "Export list"));
            export.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JFileChooser chooser = new JFileChooser();
                    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
                    chooser.setFileFilter(new FileFilter() {
                        public boolean accept(File f) {
                            return f.isDirectory() || f.toString().toLowerCase().endsWith(".txt");
                        }

                        public String getDescription() {
                            return "*.txt";
                        }
                    });

                    chooser.setSelectedFile(new File("RemovedPrograms.txt"));
                    if (chooser.showSaveDialog(
                            UiUtilities.getLastModalChildOf(getParentFrame())) == JFileChooser.APPROVE_OPTION) {
                        if (chooser.getSelectedFile() != null) {
                            String file = chooser.getSelectedFile().getAbsolutePath();

                            if (!file.toLowerCase().endsWith(".txt") && file.indexOf('.') == -1) {
                                file = file + ".txt";
                            }

                            if (file.indexOf('.') != -1) {
                                try {
                                    RandomAccessFile write = new RandomAccessFile(file, "rw");
                                    write.setLength(0);

                                    String eolStyle = File.separator.equals("/") ? "\n" : "\r\n";

                                    for (int i = 0; i < model.getRowCount(); i++) {
                                        StringBuilder line = new StringBuilder();

                                        for (int j = 0; j < model.getColumnCount(); j++) {
                                            line.append(model.getValueAt(i, j)).append(' ');
                                        }

                                        line.append(eolStyle);

                                        write.writeBytes(line.toString());
                                    }

                                    write.close();
                                } catch (Exception ee) {
                                }
                            }
                        }
                    }
                }
            });

            Object[] message = {
                    mLocalizer.msg("deletedText",
                            "The data was changed and the following programs were deleted:"),
                    scrollPane, export };

            JOptionPane pane = new JOptionPane();
            pane.setMessage(message);
            pane.setMessageType(JOptionPane.PLAIN_MESSAGE);

            final JDialog d = pane.createDialog(UiUtilities.getLastModalChildOf(getParentFrame()),
                    mLocalizer.msg("CapturePlugin", "CapturePlugin") + " - "
                            + mLocalizer.msg("deletedTitle", "Deleted programs"));
            d.setResizable(true);
            d.setModal(false);

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    d.setVisible(true);
                }
            });
        }
    }
}

From source file:cs.cirg.cida.CIDAView.java

@Action
public void exportSynopsisTable() {
    JFileChooser chooser = new JFileChooser(experimentController.getDataDirectory());
    //model.getActiveExperiment().getName() + ".csv"
    chooser.setSelectedFile(new File(CIDAConstants.DEFAULT_TABLE_NAME));
    int returnVal = chooser.showOpenDialog(this.getComponent());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        experimentController.exportSynopsisTable(chooser.getSelectedFile());
    }//w w  w .  j  a v a 2  s.c  o  m
}

From source file:ffx.ui.KeywordPanel.java

/**
 * <p>//www.j a  va 2 s.  co m
 * keySaveAs</p>
 */
public void keySaveAs() {
    if (!fileOpen) {
        return;
    }
    JFileChooser d = MainPanel.resetFileChooser();
    d.setDialogTitle("Save KEY File");
    d.setAcceptAllFileFilterUsed(false);
    if (currentKeyFile != null) {
        d.setCurrentDirectory(currentKeyFile.getParentFile());
        d.setSelectedFile(currentKeyFile);
    }
    d.setFileFilter(new KeyFileFilter());
    int result = d.showSaveDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        currentKeyFile = d.getSelectedFile();
        keySave(currentKeyFile);
    }
}

From source file:jboost.visualization.HistogramFrame.java

private File selectPDFFile() {

    File fFile = new File("default.pdf");
    JFileChooser fc = new JFileChooser();

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(new FileFilter() {

        public boolean accept(File f) {
            String path = f.getAbsolutePath();
            if (f.isDirectory() || path.endsWith(".pdf"))
                return true;
            else// w ww  .  j a va  2s .  com
                return false;
        }

        public String getDescription() {
            return "PDF Files";
        }
    });

    // Set to a default name for save.
    fc.setSelectedFile(fFile);

    // Open chooser dialog
    int result = fc.showSaveDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
        return null;
    } else if (result == JFileChooser.APPROVE_OPTION) {
        fFile = fc.getSelectedFile();
        if (fFile.exists()) {
            int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.CANCEL_OPTION)
                return null;
        }
        return fFile;
    } else {
        return null;
    }
}