Search in sources :

Example 26 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.

the class ImportOfxAction method importOfx.

private static void importOfx() {
    final ResourceBundle rb = ResourceUtils.getBundle();
    final Preferences pref = Preferences.userNodeForPackage(ImportOfxAction.class);
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    if (engine == null || engine.getRootAccount().getChildCount() == 0) {
        StaticUIMethods.displayError(rb.getString("Message.Error.CreateBasicAccounts"));
        return;
    }
    final JFileChooser chooser = new JFileChooser(pref.get(OFX_DIR, null));
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new FileNameExtensionFilter("Ofx Files (*.ofx,*.qfx)", "ofx", "qfx"));
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        pref.put(OFX_DIR, chooser.getCurrentDirectory().getAbsolutePath());
        File file = chooser.getSelectedFile();
        if (file.exists()) {
            new Import(file).execute();
        }
    }
}
Also used : OfxImport(jgnash.convert.imports.ofx.OfxImport) JFileChooser(javax.swing.JFileChooser) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) Engine(jgnash.engine.Engine)

Example 27 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.

the class AttachmentPanel method attachmentAction.

private void attachmentAction() {
    final Preferences pref = Preferences.userNodeForPackage(AbstractBankTransactionPanel.class);
    final String baseFile = EngineFactory.getActiveDatabase();
    final String[] fileSuffixes = ImageIO.getReaderFileSuffixes();
    StringBuilder description = new StringBuilder(rb.getString("Title.ImageFiles")).append(" (");
    for (int i = 0; i < fileSuffixes.length; i++) {
        description.append("*.");
        description.append(fileSuffixes[i]);
        if (i < fileSuffixes.length - 1) {
            description.append(", ");
        }
    }
    description.append(")");
    FileFilter fileFilter = new FileNameExtensionFilter(description.toString(), fileSuffixes);
    final JFileChooser chooser = new JFileChooser(pref.get(LAST_DIR, null));
    chooser.addChoosableFileFilter(fileFilter);
    chooser.setFileFilter(fileFilter);
    chooser.setMultiSelectionEnabled(false);
    chooser.setAcceptAllFileFilterUsed(false);
    if (attachment != null) {
        chooser.setSelectedFile(attachment.toFile());
    }
    if (chooser.showOpenDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
        pref.put(LAST_DIR, chooser.getCurrentDirectory().getAbsolutePath());
        File selectedFile = chooser.getSelectedFile();
        if (selectedFile != null) {
            boolean result = true;
            final Path attachmentDirectory = AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile));
            if (baseFile.startsWith(EngineFactory.REMOTE_PREFIX)) {
                // working remotely
                moveAttachment = true;
            } else if (attachmentDirectory != null && !attachmentDirectory.toString().equals(selectedFile.getParent())) {
                String message = ResourceUtils.getString("Message.Warn.MoveFile", selectedFile.toString(), attachmentDirectory.toString());
                result = YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new JLabel(message), rb.getString("Title.MoveFile"));
                if (result) {
                    moveAttachment = true;
                    Path newPath = Paths.get(AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile)) + FileUtils.separator + selectedFile.getName());
                    if (newPath.toFile().exists()) {
                        message = ResourceUtils.getString("Message.Warn.SameFile", selectedFile.toString(), attachmentDirectory.toString());
                        StaticUIMethods.displayWarning(message);
                        moveAttachment = false;
                        result = false;
                    }
                }
            }
            if (result) {
                attachment = selectedFile.toPath();
            }
        }
    }
}
Also used : Path(java.nio.file.Path) JFileChooser(javax.swing.JFileChooser) JLabel(javax.swing.JLabel) Preferences(java.util.prefs.Preferences) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 28 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.

the class MonthBalanceCSV method getFileName.

private String getFileName() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new FileNameExtensionFilter(rb.getString("Message.CSVFile"), "csv"));
    if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
        String fileName = chooser.getSelectedFile().getAbsolutePath();
        if (!fileName.endsWith(".csv")) {
            fileName = fileName + ".csv";
        }
        return fileName;
    }
    return null;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter)

Example 29 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.

the class ProfitLossTXT method getFileName.

private String getFileName() {
    final JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new FileNameExtensionFilter(rb.getString("Message.TXTFile"), "txt"));
    if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
        String fileName = chooser.getSelectedFile().getAbsolutePath();
        if (!fileName.endsWith(".txt")) {
            fileName = fileName + ".txt";
        }
        return fileName;
    }
    return null;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter)

Example 30 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project jgnash by ccavanaugh.

the class PrintCheckDialog method createFileChooser.

/**
     * Creates a {@code JFileChooser}
     * directory can be null, The JFileChooser will sort it out
     * @param dir directory to start in
     * @return the JFileChooser
     */
private JFileChooser createFileChooser(final String dir) {
    JFileChooser chooser = new JFileChooser(dir);
    chooser.addChoosableFileFilter(new FileNameExtensionFilter(rb.getString("Label.jGnashFiles") + " (*.xml)", "xml"));
    return chooser;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter)

Aggregations

FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)51 File (java.io.File)31 JFileChooser (javax.swing.JFileChooser)29 FileFilter (javax.swing.filechooser.FileFilter)15 IOException (java.io.IOException)11 Preferences (java.util.prefs.Preferences)7 FileNotFoundException (java.io.FileNotFoundException)6 PCGFile (pcgen.io.PCGFile)6 ResourceBundle (java.util.ResourceBundle)5 SwingWorker (javax.swing.SwingWorker)5 FileOutputStream (java.io.FileOutputStream)3 PCGenSettings (pcgen.system.PCGenSettings)3 ImportException (dr.evolution.io.Importer.ImportException)2 MissingBlockException (dr.evolution.io.NexusImporter.MissingBlockException)2 java.awt (java.awt)2 BorderLayout (java.awt.BorderLayout)2 Cursor (java.awt.Cursor)2 Dimension (java.awt.Dimension)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2