Example usage for javax.swing JFileChooser setLocale

List of usage examples for javax.swing JFileChooser setLocale

Introduction

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

Prototype

public void setLocale(Locale l) 

Source Link

Document

Sets the locale of this component.

Usage

From source file:modelibra.swing.app.util.FileSelector.java

/**
 * Gets the opened file given a file path.
 * /*from ww w .  jav  a2s .c  o  m*/
 * @param path
 *            path
 * @param lang
 *            language
 * @return file
 */
public File getOpenFile(String path, NatLang lang) {
    File selectedFile = null;
    File currentFile = null;
    if (path != null && !path.equalsIgnoreCase("?")) {
        currentFile = new File(path);
    } else
        currentFile = lastOpenedFile;

    JFileChooser chooser = new JFileChooser();
    chooser.setLocale(lang.getLocale());
    if (currentFile != null) {
        chooser.setCurrentDirectory(currentFile);
    }
    int returnVal = chooser.showOpenDialog(chooser);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        selectedFile = chooser.getSelectedFile();
    }
    lastOpenedFile = selectedFile;

    return selectedFile;
}

From source file:modelibra.swing.app.util.FileSelector.java

/**
 * Gets the saved file given a file path.
 * //w ww  .  ja v  a  2 s  .  c  om
 * @param path
 *            path
 * @param lang
 *            language
 * @return file
 */
public File getSaveFile(String path, NatLang lang) {
    File selectedFile = null;
    File currentFile = null;
    if (path != null && !path.equalsIgnoreCase("?")) {
        currentFile = new File(path);
    } else
        currentFile = lastSavedFile;

    JFileChooser chooser = new JFileChooser();
    chooser.setLocale(lang.getLocale());
    if (currentFile != null) {
        chooser.setCurrentDirectory(currentFile);
    }
    int returnVal = chooser.showSaveDialog(chooser);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        selectedFile = chooser.getSelectedFile(); // a complete path
        if (selectedFile.exists()) {
            if (!replaceFile(null, lang)) {
                selectedFile = null;
            }
        }
    }
    lastSavedFile = selectedFile;

    return selectedFile;
}

From source file:modelibra.swing.app.util.FileSelector.java

/**
 * Selects a file (path)./* w  ww . j av a 2 s  .c o  m*/
 * 
 * @param lang
 *            language
 * @return chosen file path
 */
public String selectFile(NatLang lang) {
    JFileChooser fileChooser = new JFileChooser(lastFilePath);
    fileChooser.setLocale(lang.getLocale());
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setToolTipText(lang.getText("selectFile"));
    fileChooser.setDialogTitle(lang.getText("selectFile"));
    fileChooser.showDialog(null, lang.getText("selectFile"));
    File f = fileChooser.getSelectedFile();
    if (f != null) {
        lastFilePath = f.getPath();
        return lastFilePath;
    } else {
        return null;
    }
}

From source file:modelibra.swing.app.util.FileSelector.java

/**
 * Selects a directory (path)./*  ww  w  .ja  va2 s  .  co m*/
 * 
 * @param lang
 *            language
 * @return chosen directory path
 */
public String selectDirectory(NatLang lang) {
    JFileChooser dirChooser = new JFileChooser(lastDirectoryPath);
    dirChooser.setLocale(lang.getLocale());
    dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    dirChooser.setToolTipText(lang.getText("selectDirectory"));
    dirChooser.setDialogTitle(lang.getText("selectDirectory"));
    dirChooser.showDialog(null, lang.getText("selectDirectory"));
    File f = dirChooser.getSelectedFile();
    if (f != null) {
        lastDirectoryPath = f.getPath();
        return lastDirectoryPath;
    } else {
        return null;
    }
}

From source file:net.sf.jasperreports.swing.JRViewerToolbar.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();//ww  w  .  j a va2s.c o m
    for (int i = 0; i < saveContributors.size(); i++) {
        fileChooser.addChoosableFileFilter(saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor)) {
        fileChooser.setFileFilter(lastSaveContributor);
    } else if (saveContributors.size() > 0) {
        fileChooser.setFileFilter(saveContributors.get(0));
    }

    if (lastFolder != null) {
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();

        lastFolder = file.getParentFile();

        JRSaveContributor contributor = null;

        if (fileFilter instanceof JRSaveContributor) {
            contributor = (JRSaveContributor) fileFilter;
        } else {
            int i = 0;
            while (contributor == null && i < saveContributors.size()) {
                contributor = saveContributors.get(i++);
                if (!contributor.accept(file)) {
                    contributor = null;
                }
            }

            if (contributor == null) {
                contributor = new JRPrintSaveContributor(viewerContext.getJasperReportsContext(), getLocale(),
                        viewerContext.getResourceBundle());
            }
        }

        lastSaveContributor = contributor;

        try {
            contributor.save(viewerContext.getJasperPrint(), file);
        } catch (JRException e) {
            if (log.isErrorEnabled()) {
                log.error("Save error.", e);
            }
            JOptionPane.showMessageDialog(this, viewerContext.getBundleString("error.saving"));
        }
    }
}

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

/**
 * Das exportverzeichis auswhlen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //from   ww  w  .  ja v  a2s  . co  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:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java

/**
 * Verzeichnis fr die Daten auswhlen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * /*w ww  .j  av a  2  s . 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

/**
 * Suche einen Platz und den Namen frs Logfile Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * /*from w w w .j a va  2 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.openbravo.pos.util.JRViewer411.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();/*  w  ww.j  av a 2s  . c o  m*/
    for (int i = 0; i < saveContributors.size(); i++) {
        fileChooser.addChoosableFileFilter(saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor)) {
        fileChooser.setFileFilter(lastSaveContributor);
    } else if (saveContributors.size() > 0) {
        fileChooser.setFileFilter(saveContributors.get(0));
    }

    if (lastFolder != null) {
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();

        lastFolder = file.getParentFile();

        JRSaveContributor contributor = null;

        if (fileFilter instanceof JRSaveContributor) {
            contributor = (JRSaveContributor) fileFilter;
        } else {
            int i = 0;
            while (contributor == null && i < saveContributors.size()) {
                contributor = saveContributors.get(i++);
                if (!contributor.accept(file)) {
                    contributor = null;
                }
            }

            if (contributor == null) {
                contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle);
            }
        }

        lastSaveContributor = contributor;

        try {
            contributor.save(jasperPrint, file);
        } catch (JRException e) {
            if (log.isErrorEnabled()) {
                log.error("Save error.", e);
            }
            JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
        }
    }
}

From source file:neg.JRViewer.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();/* w ww  .ja  v a 2  s.  co m*/
    for (int i = 0; i < saveContributors.size(); i++) {
        fileChooser.addChoosableFileFilter((JRSaveContributor) saveContributors.get(i));
    }

    if (saveContributors.contains(lastSaveContributor)) {
        fileChooser.setFileFilter(lastSaveContributor);
    } else if (saveContributors.size() > 0) {
        fileChooser.setFileFilter((JRSaveContributor) saveContributors.get(0));
    }

    if (lastFolder != null) {
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        FileFilter fileFilter = fileChooser.getFileFilter();
        File file = fileChooser.getSelectedFile();

        lastFolder = file.getParentFile();

        JRSaveContributor contributor = null;

        if (fileFilter instanceof JRSaveContributor) {
            contributor = (JRSaveContributor) fileFilter;
        } else {
            int i = 0;
            while (contributor == null && i < saveContributors.size()) {
                contributor = (JRSaveContributor) saveContributors.get(i++);
                if (!contributor.accept(file)) {
                    contributor = null;
                }
            }

            if (contributor == null) {
                contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle);
            }
        }

        lastSaveContributor = contributor;

        try {
            contributor.save(jasperPrint, file);
        } catch (JRException e) {
            if (log.isErrorEnabled())
                log.error("Save error.", e);

            JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
        }
    }
}