Search in sources :

Example 31 with FileNameExtensionFilter

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

the class ImportQifAction method importQif.

private static void importQif() {
    final ResourceBundle rb = ResourceUtils.getBundle();
    final Preferences pref = Preferences.userNodeForPackage(ImportQifAction.class);
    final Logger logger = Logger.getLogger("qifimport");
    if (debug) {
        try {
            Handler fh = new FileHandler("%h/jgnash%g.log");
            fh.setFormatter(new SimpleFormatter());
            logger.addHandler(fh);
            logger.setLevel(Level.FINEST);
        } catch (IOException ioe) {
            logger.log(Level.SEVERE, "Could not install file handler", ioe);
        }
    }
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    if (engine.getRootAccount() == null) {
        StaticUIMethods.displayError(rb.getString("Message.Error.CreateBasicAccounts"));
        return;
    }
    final JFileChooser chooser = new JFileChooser(pref.get(QIFDIR, null));
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(new FileNameExtensionFilter("Qif Files (*.qif)", "qif"));
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        pref.put(QIFDIR, chooser.getCurrentDirectory().getAbsolutePath());
        boolean fullFile = QifUtils.isFullFile(chooser.getSelectedFile());
        if (fullFile) {
            // prompt for date format
            final DateFormat dateFormat = getQIFDateFormat();
            class ImportFile extends SwingWorker<Void, Void> {

                @Override
                protected Void doInBackground() throws Exception {
                    UIApplication.getFrame().displayWaitMessage(rb.getString("Message.ImportWait"));
                    QifImport imp = new QifImport();
                    try {
                        imp.doFullParse(chooser.getSelectedFile(), dateFormat);
                    } catch (NoAccountException e) {
                        logger.log(Level.SEVERE, "Mistook partial qif file as a full qif file", e);
                    }
                    imp.dumpStats();
                    imp.doFullImport();
                    if (imp.getDuplicateCount() > 0) {
                        String message = imp.getDuplicateCount() + " duplicate transactions were found";
                        logger.info(message);
                    }
                    return null;
                }

                @Override
                protected void done() {
                    UIApplication.getFrame().stopWaitMessage();
                }
            }
            new ImportFile().execute();
        } else {
            final QifImport imp = new QifImport();
            if (!imp.doPartialParse(chooser.getSelectedFile())) {
                StaticUIMethods.displayError(rb.getString("Message.Error.ParseTransactions"));
                return;
            }
            imp.dumpStats();
            if (imp.getParser().accountList.isEmpty()) {
                StaticUIMethods.displayError(rb.getString("Message.Error.ParseTransactions"));
                return;
            }
            PartialDialog dlg = new PartialDialog(imp.getParser());
            DialogUtils.addBoundsListener(dlg);
            dlg.setVisible(true);
            if (dlg.isWizardValid()) {
                imp.doPartialImport(dlg.getAccount());
                if (imp.getDuplicateCount() > 0) {
                    if (YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new MultiLineLabel(TextResource.getString("DupeTransImport.txt")), rb.getString("Title.DuplicateTransactionsFound"), YesNoDialog.WARNING_MESSAGE)) {
                        Transaction[] t = imp.getDuplicates();
                        for (Transaction element : t) {
                            engine.addTransaction(element);
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) FileHandler(java.util.logging.FileHandler) Handler(java.util.logging.Handler) PartialDialog(jgnash.ui.wizards.imports.qif.PartialDialog) IOException(java.io.IOException) Logger(java.util.logging.Logger) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) FileHandler(java.util.logging.FileHandler) NoAccountException(jgnash.convert.imports.qif.NoAccountException) JFileChooser(javax.swing.JFileChooser) Transaction(jgnash.engine.Transaction) DateFormat(jgnash.convert.imports.DateFormat) QifImport(jgnash.convert.imports.qif.QifImport) SwingWorker(javax.swing.SwingWorker) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) Engine(jgnash.engine.Engine) MultiLineLabel(jgnash.ui.components.MultiLineLabel)

Example 32 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project MatematicaDiscreta by Leoginski.

the class main method jbArquivoActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void jbArquivoActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_jbArquivoActionPerformed
    // TODO add your handling code here:
    StorageSession.resetStorage();
    jcbConjunto1.removeAllItems();
    jcbConjunto2.removeAllItems();
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileNameExtensionFilter("Filtro .txt", "txt"));
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.showOpenDialog(this);
    File txtFileLer = new File(fileChooser.getSelectedFile().getAbsolutePath());
    jtfArquivo.setText(txtFileLer.getName());
    // Leitura do arquivo
    try {
        FileReader arq = new FileReader(txtFileLer);
        BufferedReader lerArq = new BufferedReader(arq);
        // Pegando linhas do arquivo
        String linha = lerArq.readLine();
        //Expressoes regulares
        Pattern acharConjunto = Pattern.compile("[A-Z]");
        Pattern acharElemento = Pattern.compile("([a-z])");
        Pattern numero = Pattern.compile("\\d+");
        // Varrendo as linhas
        while (linha != null) {
            // Aplicando regex
            Matcher acharConjuntoMatcher = acharConjunto.matcher(linha);
            Matcher acharElementoMatcher = acharElemento.matcher(linha);
            Matcher numeroMatcher = numero.matcher(linha);
            // Econtrando conjuntos
            if (acharConjuntoMatcher.find()) {
                // Nome do conjunto
                String nome = acharConjuntoMatcher.group();
                // Instancia objeto e adiciona ao ArrayList
                if (!StorageSession.existeNomeIgualConjunto(nome)) {
                    Conjunto target = new Conjunto(nome);
                    while (numeroMatcher.find()) {
                        // Obtém valor
                        int value = Integer.parseInt(numeroMatcher.group());
                        Elemento elemento = new Elemento(Integer.toString(value), value);
                        target.addElemento(elemento);
                    }
                    // adiciona conjunto
                    StorageSession.setConjuntos(target);
                } else {
                    JOptionPane.showMessageDialog(null, "Conjunto " + nome + " já existe!");
                }
            }
            // Encontrando elementos
            if (acharElementoMatcher.find()) {
                // Nome do elemento
                String nome = acharElementoMatcher.group();
                int value = 0;
                if (!StorageSession.existeNomeIgualElemento(nome)) {
                    // O loop pegará o elemento com 1 ou mais digitos.
                    while (numeroMatcher.find()) {
                        value = Integer.parseInt(numeroMatcher.group());
                    }
                    Elemento shot = new Elemento(nome, value);
                    // adiciona elemento
                    StorageSession.setElementos(shot);
                } else {
                    JOptionPane.showMessageDialog(null, "Elemento " + nome + " já existe!");
                }
            }
            // lê da segunda até a última linha
            linha = lerArq.readLine();
        }
        arq.close();
    } catch (IOException e) {
        System.err.printf("Erro na abertura do arquivo: %s.\n", e.getMessage());
    }
    // PREENCHER O COMBOBOX
    for (String obj : StorageSession.getComboItens()) {
        jcbConjunto1.addItem(obj);
        jcbConjunto2.addItem(obj);
    }
}
Also used : Pattern(java.util.regex.Pattern) JFileChooser(javax.swing.JFileChooser) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) Conjunto(model.Conjunto) Elemento(model.Elemento) FileReader(java.io.FileReader) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 33 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project DistributedFractalNetwork by Budder21.

the class FractalChooserMenu method chooseFractal.

/**
	 * Allows a user to choose a saved fractal and set zoom speed and resolution
	 * parameters
	 * @return a RenderManger for the network to use. Will return null if no fractal if the window is closed
	 */
public static RenderManager chooseFractal() {
    waiting = true;
    manager = null;
    JFrame f = new JFrame();
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    JLabel message = new JLabel(" Fractal:");
    message.setFont(Constants.mediumFont);
    p.add(message, BorderLayout.WEST);
    RoundedButton chooseFile = new RoundedButton();
    chooseFile.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e1) {
                e1.printStackTrace();
            }
            JFileChooser fileChooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Fractal", "prop");
            fileChooser.setFileFilter(filter);
            manager = new RenderManager(fileChooser.getSelectedFile());
        }
    });
    p.add(chooseFile, BorderLayout.CENTER);
    f.setContentPane(p);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setResizable(false);
    f.addWindowListener(new WindowListener() {

        public void windowOpened(WindowEvent e) {
        }

        public void windowClosed(WindowEvent e) {
        }

        public void windowIconified(WindowEvent e) {
        }

        public void windowDeiconified(WindowEvent e) {
        }

        public void windowActivated(WindowEvent e) {
        }

        public void windowDeactivated(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
            waiting = false;
        }
    });
    f.setVisible(true);
    while (manager == null || waiting) {
    }
    return manager;
}
Also used : JPanel(javax.swing.JPanel) WindowListener(java.awt.event.WindowListener) RoundedButton(menus.RoundedButton) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

Example 34 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project javatari by ppeccin.

the class FileROMChooser method chooseFileToLoad.

public static File chooseFileToLoad() throws AccessControlException {
    if (chooser != null && chooser.isShowing())
        return null;
    if (lastLoadFileChosen == null)
        lastLoadFileChosen = new File(Parameters.LAST_ROM_LOAD_FILE_CHOSEN);
    if (chooser == null)
        createChooser();
    chooser.setFileFilter(new FileNameExtensionFilter(ROMLoader.VALID_LOAD_FILES_DESC, ROMLoader.VALID_LOAD_FILE_EXTENSIONS));
    chooser.setSelectedFile(lastLoadFileChosen);
    int res = chooser.showOpenDialog(null);
    if (res != 0)
        return null;
    lastLoadFileChosen = chooser.getSelectedFile();
    Parameters.LAST_ROM_LOAD_FILE_CHOSEN = lastLoadFileChosen.toString();
    Parameters.savePreferences();
    return lastLoadFileChosen;
}
Also used : FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 35 with FileNameExtensionFilter

use of javax.swing.filechooser.FileNameExtensionFilter in project pcgen by PCGen.

the class PCGenFrame method showOpenPartyChooser.

void showOpenPartyChooser() {
    PCGenSettings context = PCGenSettings.getInstance();
    chooser.setCurrentDirectory(new File(context.getProperty(PCGenSettings.PCP_SAVE_PATH)));
    chooser.resetChoosableFileFilters();
    chooser.setFileFilter(new FileNameExtensionFilter("Pcp files only", "pcp"));
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        loadPartyFromFile(file);
    }
}
Also used : PCGenSettings(pcgen.system.PCGenSettings) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Aggregations

FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)52 File (java.io.File)32 JFileChooser (javax.swing.JFileChooser)30 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