Search in sources :

Example 66 with JFileChooser

use of javax.swing.JFileChooser 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 67 with JFileChooser

use of javax.swing.JFileChooser 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 68 with JFileChooser

use of javax.swing.JFileChooser 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 69 with JFileChooser

use of javax.swing.JFileChooser 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 70 with JFileChooser

use of javax.swing.JFileChooser 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

JFileChooser (javax.swing.JFileChooser)797 File (java.io.File)571 IOException (java.io.IOException)185 FileFilter (javax.swing.filechooser.FileFilter)109 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)96 ActionEvent (java.awt.event.ActionEvent)59 ActionListener (java.awt.event.ActionListener)48 JButton (javax.swing.JButton)44 JPanel (javax.swing.JPanel)40 Component (java.awt.Component)39 FileOutputStream (java.io.FileOutputStream)39 FileNotFoundException (java.io.FileNotFoundException)30 JMenuItem (javax.swing.JMenuItem)29 Point (java.awt.Point)28 ArrayList (java.util.ArrayList)28 FileWriter (java.io.FileWriter)25 Dimension (java.awt.Dimension)24 PrintWriter (java.io.PrintWriter)24 JLabel (javax.swing.JLabel)22 JFrame (javax.swing.JFrame)21