Example usage for javax.swing JFileChooser addChoosableFileFilter

List of usage examples for javax.swing JFileChooser addChoosableFileFilter

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "Adds a filter to the list of user choosable file filters.")
public void addChoosableFileFilter(FileFilter filter) 

Source Link

Document

Adds a filter to the list of user choosable file filters.

Usage

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
 * /*from  ww  w. j a va 2s.  com*/
 * @throws IOException
 *             if there is an I/O error.
 */
public void doSaveAs() throws IOException {

    JFileChooser fileChooser = new JFileChooser();
    ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"),
            ".png");
    fileChooser.addChoosableFileFilter(filter);

    int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
        String filename = fileChooser.getSelectedFile().getPath();
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight());
    }
}

From source file:base.BasePlayer.AddGenome.java

@Override
public void mousePressed(MouseEvent e) {

    if (e.getSource() == tree) {

        if (selectedNode != null && selectedNode.toString().contains("Add new refe")) {
            try {
                FileDialog fs = new FileDialog(frame, "Select reference fasta-file", FileDialog.LOAD);
                fs.setDirectory(Main.downloadDir);
                fs.setVisible(true);/*from   www.j  av  a 2 s.  co  m*/
                String filename = fs.getFile();
                fs.setFile("*.fasta;*.fa");
                fs.setFilenameFilter(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().contains(".fasta") || name.toLowerCase().contains(".fa");
                    }
                });
                if (filename != null) {
                    File addfile = new File(fs.getDirectory() + "/" + filename);

                    if (addfile.exists()) {

                        genomeFile = addfile;
                        Main.downloadDir = genomeFile.getParent();
                        Main.writeToConfig("DownloadDir=" + genomeFile.getParent());
                        OutputRunner runner = new OutputRunner(genomeFile.getName().replace(".fasta", "")
                                .replace(".fa", "").replace(".gz", ""), genomeFile, null);
                        runner.createGenome = true;
                        runner.execute();
                    } else {
                        Main.showError("File does not exists.", "Error", frame);
                    }

                }
                if (1 == 1) {
                    return;
                }
                JFileChooser chooser = new JFileChooser(Main.downloadDir);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setAcceptAllFileFilterUsed(false);
                MyFilterFasta fastaFilter = new MyFilterFasta();

                chooser.addChoosableFileFilter(fastaFilter);
                chooser.setDialogTitle("Select reference fasta-file");
                if (Main.screenSize != null) {
                    chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                            (int) Main.screenSize.getHeight() / 3));
                }

                int returnVal = chooser.showOpenDialog((Component) this.getParent());

                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    genomeFile = chooser.getSelectedFile();
                    Main.downloadDir = genomeFile.getParent();
                    Main.writeToConfig("DownloadDir=" + genomeFile.getParent());
                    OutputRunner runner = new OutputRunner(
                            genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, null);
                    runner.createGenome = true;
                    runner.execute();

                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (selectedNode != null && selectedNode.isLeaf()
                && selectedNode.toString().contains("Add new anno")) {
            try {
                FileDialog fs = new FileDialog(frame, "Select annotation gff3/gtf-file", FileDialog.LOAD);
                fs.setDirectory(Main.downloadDir);
                fs.setVisible(true);
                String filename = fs.getFile();
                fs.setFile("*.gff3;*.gtf");
                fs.setFilenameFilter(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().contains(".gff3") || name.toLowerCase().contains(".gtf");
                    }
                });

                if (filename != null) {
                    File addfile = new File(fs.getDirectory() + "/" + filename);

                    if (addfile.exists()) {
                        annotationFile = addfile;
                        Main.downloadDir = annotationFile.getParent();
                        Main.writeToConfig("DownloadDir=" + annotationFile.getParent());
                        OutputRunner runner = new OutputRunner(selectedNode.getParent().toString(), null,
                                annotationFile);
                        runner.createGenome = true;
                        runner.execute();
                    } else {
                        Main.showError("File does not exists.", "Error", frame);
                    }

                }
                if (1 == 1) {
                    return;
                }
                JFileChooser chooser = new JFileChooser(Main.downloadDir);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setAcceptAllFileFilterUsed(false);
                MyFilterGFF gffFilter = new MyFilterGFF();

                chooser.addChoosableFileFilter(gffFilter);
                chooser.setDialogTitle("Select annotation gff3-file");
                if (Main.screenSize != null) {
                    chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                            (int) Main.screenSize.getHeight() / 3));
                }
                int returnVal = chooser.showOpenDialog((Component) this.getParent());

                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    annotationFile = chooser.getSelectedFile();
                    Main.downloadDir = annotationFile.getParent();

                    Main.writeToConfig("DownloadDir=" + annotationFile.getParent());
                    OutputRunner runner = new OutputRunner(selectedNode.getParent().toString(), null,
                            annotationFile);
                    runner.createGenome = true;
                    runner.execute();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    if (e.getSource() == genometable) {

        if (new File(".").getFreeSpace()
                / 1048576 < sizeHash.get(genometable.getValueAt(genometable.getSelectedRow(), 0))[0]
                        / 1048576) {
            sizeError.setVisible(true);
            download.setEnabled(false);
            AddGenome.getLinks.setEnabled(false);
        } else {
            sizeError.setVisible(false);
            download.setEnabled(true);
            AddGenome.getLinks.setEnabled(true);
        }
        tree.clearSelection();
        remove.setEnabled(false);
        checkUpdates.setEnabled(false);
    }

}

From source file:de.fionera.javamailer.gui.mainView.controllerMain.java

/**
 * Adds the Actionlisteners to the Mainview
 *
 * @param viewMain The Mainview//from w w w  .j av a 2  s  .c o m
 */
private void addActionListener(viewMain viewMain) {
    /**
     * Changes the Amount in the AmountLabel when the slider is moved
     */
    viewMain.getSetMailSettingsPanel().getSliderAmountMails().addChangeListener(e -> {
        Main.amountMails = ((JSlider) e.getSource()).getValue();
        viewMain.getSetMailSettingsPanel().getLabelNumberAmountMails()
                .setText("" + ((JSlider) e.getSource()).getValue());
    });

    /**
     * Changes the Delay in the DelayLabel when the slider is moved
     */
    viewMain.getSetMailSettingsPanel().getSliderDelayMails().addChangeListener(e -> {
        Main.delayMails = ((JSlider) e.getSource()).getValue();
        viewMain.getSetMailSettingsPanel().getLabelNumberDelayMails()
                .setText("" + ((JSlider) e.getSource()).getValue());
    });

    /**
     * Closes the Program, when close is clicked
     */
    viewMain.getCloseItem().addActionListener(e -> System.exit(0));

    /**
     * Opens the Settings when the settingsbutton is clicked
     */
    viewMain.getSettingsItem().addActionListener(e -> new controllerSettings());

    /**
     * Save current Setup
     */
    viewMain.getSaveSettings().addActionListener(e -> {
        JFileChooser jChooser = new JFileChooser();
        JFrame parentFrame = new JFrame();

        FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub");
        jChooser.setFileFilter(filter);

        jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jChooser.setDialogTitle("Select Setup");

        int userSelection = jChooser.showSaveDialog(parentFrame);

        if (userSelection == JFileChooser.APPROVE_OPTION) {
            File fileToSave = new File(jChooser.getSelectedFile() + ".jms");

            saveSetup(viewMain, fileToSave, new ObjectMapper());
        }
    });

    /**
     * Load Setup
     */
    viewMain.getLoadSettings().addActionListener(e -> {
        JFileChooser jChooser = new JFileChooser();

        FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub");
        jChooser.setFileFilter(filter);

        jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jChooser.setDialogTitle("Select Setup");
        jChooser.showOpenDialog(null);

        File file = jChooser.getSelectedFile();

        if (file != null) {
            if (file.getName().endsWith("jms")) {
                try {
                    loadSetup(viewMain, file, new ObjectMapper());
                } catch (Exception error) {
                    error.printStackTrace();
                }
            }
        }
    });

    /**
     * Opens the Open File dialog and start the Parsing of it
     */
    viewMain.getSelectRecipientsPanel().getSelectExcelFileButton().addActionListener(e -> {
        DefaultTableModel model;
        JFileChooser jChooser = new JFileChooser();

        jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel 97 - 2003 (.xls)", "xls"));
        jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel (.xlsx)", "xlsx"));
        jChooser.setDialogTitle("Select only Excel workbooks");
        jChooser.showOpenDialog(null);
        File file = jChooser.getSelectedFile();
        if (file != null) {
            parseFilesForImport parseFilesForImport = new parseFilesForImport();

            if (file.getName().endsWith("xls")) {
                ArrayList returnedData = parseFilesForImport.parseXLSFile(file);

                model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1));

                int tableWidth = model.getColumnCount() * 150;
                int tableHeight = model.getRowCount() * 25;
                viewMain.getSelectRecipientsPanel().getTable()
                        .setPreferredSize(new Dimension(tableWidth, tableHeight));

            } else if (file.getName().endsWith("xlsx")) {
                ArrayList returnedData = parseFilesForImport.parseXLSXFile(file);

                model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1));

                int tableWidth = model.getColumnCount() * 150;
                int tableHeight = model.getRowCount() * 25;
                viewMain.getSelectRecipientsPanel().getTable()
                        .setPreferredSize(new Dimension(tableWidth, tableHeight));

            } else {
                JOptionPane.showMessageDialog(null, "Please select only Excel file.", "Error",
                        JOptionPane.ERROR_MESSAGE);

                model = new DefaultTableModel();
            }
        } else {
            model = new DefaultTableModel();

        }

        viewMain.getSelectRecipientsPanel().getTable().setModel(model);

        int tableWidth = model.getColumnCount() * 150;
        int tableHeight = model.getRowCount() * 25;
        viewMain.getSelectRecipientsPanel().getTable().setPreferredSize(new Dimension(tableWidth, tableHeight));
        viewMain.getCheckAllSettings().getLabelRecipientsAmount().setText("" + model.getRowCount());
        viewMain.getCheckAllSettings().getLabelTimeAmount()
                .setText(""
                        + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()
                                * viewMain.getSelectRecipientsPanel().getTable().getRowCount()
                                / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()
                        + " Seconds");
    });

    /**
     * Starts the sending of th Mails, when the send button is clicked
     */
    viewMain.getCheckAllSettings().getSendMails().addActionListener(e -> {

        String subject = viewMain.getSetMailSettingsPanel().getFieldSubject().getText();
        Sender sender = (Sender) viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem();
        JTable table = viewMain.getSelectRecipientsPanel().getTable();

        if (table != null && sender != null && !subject.equals("")) {
            new sendMails(viewMain);
        }
    });

    /**
     * Clears the Table on buttonclick
     */
    viewMain.getSelectRecipientsPanel().getClearTableButton().addActionListener(e -> {
        viewMain.getSelectRecipientsPanel().getTable().setModel(new DefaultTableModel());
        viewMain.getSelectRecipientsPanel().getTable().setBackground(null);

    });

    /**
     * Removes a single Row on menu click in the editMailPanel
     */
    viewMain.getSelectRecipientsPanel().getDeleteRow().addActionListener(e -> {
        ((DefaultTableModel) viewMain.getSelectRecipientsPanel().getTable().getModel())
                .removeRow(viewMain.getSelectRecipientsPanel().getTable().getSelectedRowCount());
        viewMain.getSelectRecipientsPanel().getTable().setBackground(null);

    });

    /**
     * The Changes the displayed Value when the Time in the Timespinner is getting changed.
     */
    viewMain.getSetMailSettingsPanel().getTimeSpinner().addChangeListener(e -> {
        parseDate.parseDate(viewMain);
        viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, "
                + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining");
        viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString());
        viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate());

    });
    viewMain.getSetMailSettingsPanel().getDatePicker().addActionListener(e -> {
        parseDate.parseDate(viewMain);
        viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, "
                + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining");
        viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString());
        viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate());
    });

    /**
     * Actionevent for the Edit Sender Button
     */
    viewMain.getSetMailSettingsPanel().getButtonEditSender()
            .addActionListener(e -> new controllerEditSender(controllerMain));

    /**
     * Actionevent for the Import Button in the EditMail View
     */
    viewMain.getEditMailPanel().getImportWord().addActionListener(e -> {
        JFileChooser jChooser = new JFileChooser();

        jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Word 97 - 2003 (.doc)", "doc"));
        jChooser.addChoosableFileFilter(new FileNameExtensionFilter("HTML File (.html)", "html"));
        jChooser.setDialogTitle("Select only Word Documents");
        jChooser.showOpenDialog(null);
        File file = jChooser.getSelectedFile();
        if (file != null) {
            parseFilesForImport parseFilesForImport = new parseFilesForImport();

            if (file.getName().endsWith("doc")) {
                String returnedData = parseFilesForImport.parseDOCFile(file);
                viewMain.getEditMailPanel().setEditorText(returnedData);

            } else if (file.getName().endsWith("html")) {
                String content = "";
                try {
                    content = Jsoup.parse(file, "UTF-8").toString();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

                viewMain.getEditMailPanel().setEditorText(content);

            } else {
                JOptionPane.showMessageDialog(null, "Please select a Document file.", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    /**
     * The Tab Changelistener
     * The first if Statement sets the Labels on the Checkallsettings Panel to the right Values
     */
    viewMain.getTabbedPane().addChangeListener(e -> {
        if (viewMain.getTabbedPane().getSelectedComponent() == viewMain.getCheckAllSettings()) {

            viewMain.getCheckAllSettings().getLabelMailBelow()
                    .setText(viewMain.getEditMailPanel().getEditorText()); //Displays the Mail

            viewMain.getCheckAllSettings().getLabelRecipientsAmount()
                    .setText("" + viewMain.getSelectRecipientsPanel().getTable().getModel().getRowCount()); //Displays the Amount of Recipients

            if (viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem() != null) {
                viewMain.getCheckAllSettings().getLabelFromInserted().setText(
                        viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem().toString());
            } else {
                viewMain.getCheckAllSettings().getLabelFromInserted().setText("Select a Sender first");
            }

            viewMain.getCheckAllSettings().getLabelSubjectInserted()
                    .setText(viewMain.getSetMailSettingsPanel().getFieldSubject().getText()); //Displays the Subject

            if (viewMain.getSetMailSettingsPanel().getCheckBoxDelayMails().isSelected()) {
                viewMain.getCheckAllSettings().getLabelDelay().setVisible(true);
                viewMain.getCheckAllSettings().getLabelAmount().setVisible(true);
                viewMain.getCheckAllSettings().getLabelTime().setVisible(true);
                viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(true);
                viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(true);
                viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(true);

                viewMain.getCheckAllSettings().getLabelDelayNumber()
                        .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()); //The Delay Number
                viewMain.getCheckAllSettings().getLabelAmountNumber()
                        .setText("" + viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()); //The Amount of Mail in one package
                viewMain.getCheckAllSettings().getLabelTimeAmount()
                        .setText(""
                                + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()
                                        * viewMain.getSelectRecipientsPanel().getTable().getRowCount()
                                        / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()
                                + " Seconds"); //The Time the Sending needs

            } else {
                viewMain.getCheckAllSettings().getLabelDelay().setVisible(false);
                viewMain.getCheckAllSettings().getLabelAmount().setVisible(false);
                viewMain.getCheckAllSettings().getLabelTime().setVisible(false);
                viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(false);
                viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(false);
                viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(false);
            }

            if (viewMain.getSetMailSettingsPanel().getCheckBoxSendLater().isSelected()) {
                viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(true);
                viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(true);
                viewMain.getCheckAllSettings().getLabelSendingAt()
                        .setText(viewMain.getSetMailSettingsPanel().getDate().toString());

            } else {
                viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(false);
                viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(false);
            }

        }
    });

}

From source file:base.BasePlayer.AddGenome.java

public void actionPerformed(ActionEvent event) {
    if (event.getSource() == download) {
        if (!downloading) {
            downloading = true;/*from w  ww . j  a  v a  2s. c  om*/
            downloadGenome(genometable.getValueAt(genometable.getSelectedRow(), 0).toString());
            downloading = false;
        }
    } else if (event.getSource() == getLinks) {
        URL[] urls = AddGenome.genomeHash
                .get(genometable.getValueAt(genometable.getSelectedRow(), 0).toString());
        JPopupMenu menu = new JPopupMenu();
        JTextArea area = new JTextArea();
        JScrollPane menuscroll = new JScrollPane();
        area.setFont(Main.menuFont);
        menu.add(menuscroll);
        menu.setPreferredSize(new Dimension(
                menu.getFontMetrics(Main.menuFont).stringWidth(urls[0].toString()) + Main.defaultFontSize * 10,
                (int) menu.getFontMetrics(Main.menuFont).getHeight() * 4));
        //area.setMaximumSize(new Dimension(300, 600));
        area.setLineWrap(true);
        area.setWrapStyleWord(true);
        for (int i = 0; i < urls.length; i++) {
            area.append(urls[i].toString() + "\n");
        }

        area.setCaretPosition(0);
        area.revalidate();
        menuscroll.getViewport().add(area);
        menu.pack();
        menu.show(this, 0, 0);

    } else if (event.getSource() == checkEnsembl) {
        if (ensemblfetch) {
            menu.show(AddGenome.treescroll, 0, 0);
        } else {
            EnsemblFetch fetcher = new EnsemblFetch();
            fetcher.execute();
        }
    } else if (event.getSource() == checkUpdates) {
        URL testfile = null;
        try {
            // kattoo onko paivityksia annotaatioon
            String ref = selectedNode.toString();
            if (AddGenome.genomeHash.get(ref) != null) {
                ArrayList<String> testfiles = new ArrayList<String>();
                if (Main.drawCanvas != null) {
                    for (int i = 0; i < Main.genomehash.get(ref).size(); i++) {
                        testfiles.add(Main.genomehash.get(ref).get(i).getName().replace(".bed.gz", ""));
                    }
                }
                testfile = AddGenome.genomeHash.get(ref)[1];
                String result = Main.checkFile(testfile, testfiles);

                if (result.length() == 0) {
                    Main.showError("You have newest annotation file.", "Note");
                } else {
                    int n = JOptionPane.showConfirmDialog(Main.drawCanvas,
                            "New annotation file found: " + result + "\nDownload it now?", "Note",
                            JOptionPane.YES_NO_OPTION);
                    if (n == JOptionPane.YES_OPTION) {
                        URL fileurl = new URL(testfile.getProtocol() + "://" + testfile.getHost()
                                + testfile.getPath().substring(0, testfile.getPath().lastIndexOf("/") + 1)
                                + result);
                        OutputRunner runner = new OutputRunner(fileurl, ref);
                        runner.downloadAnnotation = true;
                        runner.execute();
                    }
                }
            } else {
                Main.showError("This genome is not from Ensembl list, could not check for updates.", "Note",
                        AddGenome.genometable);
            }
        } catch (Exception e) {
            Main.showError("Cannot connect to " + testfile.getHost() + ".\nTry again later.", "Error");
            e.printStackTrace();
        }
    } else if (event.getSource() == remove) {
        if (!selectedNode.isLeaf()) {
            String removeref = selectedNode.toString();
            //   Boolean same = false;
            try {
                if (Main.drawCanvas != null) {
                    if (removeref.equals(Main.refDropdown.getSelectedItem().toString())) {
                        Main.referenceFile.close();
                        //      same = true;
                        if (ChromDraw.exonReader != null) {
                            ChromDraw.exonReader.close();
                        }
                    }
                }
                if (Main.genomehash.containsKey(removeref)) {
                    for (int i = Main.genomehash.get(removeref).size() - 1; i >= 0; i--) {
                        Main.genomehash.get(removeref).remove(i);
                    }
                    Main.genomehash.remove(removeref);

                }
                if (Main.drawCanvas != null) {
                    Main.refModel.removeElement(removeref);
                    Main.refDropdown.removeItem(removeref);
                    Main.refDropdown.revalidate();
                }

                for (int i = 0; i < Main.genome.getItemCount(); i++) {
                    if (Main.genome.getItem(i).getName() != null) {

                        if (Main.genome.getItem(i).getName().equals(removeref)) {
                            Main.genome.remove(Main.genome.getItem(i));
                            break;
                        }
                    }
                }

                FileUtils.deleteDirectory(new File(Main.genomeDir.getCanonicalPath() + "/" + removeref));
                checkGenomes();
                Main.setAnnotationDrop("");

                if (Main.genomehash.size() == 0) {
                    Main.refDropdown.setSelectedIndex(0);
                    Main.setChromDrop("-1");
                }
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    Main.showError("Could not delete genome folder.\nYou can do it manually by deleting folder "
                            + Main.genomeDir.getCanonicalPath() + "/" + removeref, "Note");
                } catch (IOException e1) {

                    e1.printStackTrace();
                }
            }
        } else {
            try {
                if (Main.drawCanvas != null) {
                    if (ChromDraw.exonReader != null) {
                        ChromDraw.exonReader.close();
                    }
                }

                Main.removeAnnotationFile(selectedNode.getParent().toString(), selectedNode.toString());

                FileUtils.deleteDirectory(new File(Main.genomeDir.getCanonicalPath() + "/"
                        + selectedNode.getParent().toString() + "/annotation/" + selectedNode.toString()));

                //   root.remove(selectedNode.getParent().getIndex(selectedNode));
                //   root.remove
                //   checkGenomes();

            } catch (Exception e) {
                e.printStackTrace();
                try {
                    Main.showError("Could not delete genome folder.\nYou can do it manually by deleting folder "
                            + Main.genomeDir.getCanonicalPath() + "/" + selectedNode.getParent().toString()
                            + "/annotation/" + selectedNode.toString(), "Note");
                } catch (IOException e1) {

                    e1.printStackTrace();
                }
            }
            treemodel.removeNodeFromParent(selectedNode);
        }

    } else if (event.getSource() == add) {

        if (genomeFile == null) {
            if (new File(genomeFileText.getText()).exists()) {
                genomeFile = new File(genomeFileText.getText());

            } else {
                genomeFileText.setText("Select reference genome fasta-file.");
                genomeFileText.setForeground(Color.red);
                return;
            }
        }

        /*if(genomeName.getText().contains("Give name") || genomeName.getText().length() == 0) {
           genomeName.setText("Give name of the genome");
           genomeName.setForeground(Color.red);
           genomeName.revalidate();
                   
        }
        else if(!annotation && new File(Main.userDir +"/genomes/"+genomeName.getText().trim().replace("\\s+", "_")).exists()) {
           genomeName.setText("This genome exists already.");
           genomeName.setForeground(Color.red);
           genomeName.revalidate();
        }
        else */

        if ((genomeFileText.getText().length() == 0
                || genomeFileText.getText().startsWith("Select reference"))) {
            genomeFileText.setText("Select reference genome fasta-file.");
            genomeFileText.setForeground(Color.red);
            genomeFileText.revalidate();
        }

        else {

            OutputRunner runner = new OutputRunner(
                    genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, annotationFile);
            runner.execute();
        }

    } else if (event.getSource() == openRef) {
        try {

            JFileChooser chooser = new JFileChooser(Main.downloadDir);
            chooser.setMultiSelectionEnabled(false);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            MyFilterFasta fastaFilter = new MyFilterFasta();

            chooser.addChoosableFileFilter(fastaFilter);
            chooser.setDialogTitle("Select reference fasta-file");
            if (Main.screenSize != null) {
                chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                        (int) Main.screenSize.getHeight() / 3));
            }

            int returnVal = chooser.showOpenDialog((Component) this.getParent());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                genomeFile = chooser.getSelectedFile();
                Main.downloadDir = genomeFile.getParent();
                Main.writeToConfig("DownloadDir=" + genomeFile.getParent());
                genomeFileText.setText(genomeFile.getName());
                genomeFileText.revalidate();
                frame.pack();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (event.getSource() == openAnno) {
        try {

            JFileChooser chooser = new JFileChooser(Main.downloadDir);
            chooser.setMultiSelectionEnabled(false);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            MyFilterGFF gffFilter = new MyFilterGFF();

            chooser.addChoosableFileFilter(gffFilter);
            chooser.setDialogTitle("Select annotation gff3-file");
            if (Main.screenSize != null) {
                chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                        (int) Main.screenSize.getHeight() / 3));
            }
            int returnVal = chooser.showOpenDialog((Component) this.getParent());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                if (genomeFile == null) {
                    genomeFile = Main.fastahash.get(Main.hoverGenome);
                }
                annotationFile = chooser.getSelectedFile();
                Main.downloadDir = annotationFile.getParent();
                Main.writeToConfig("DownloadDir=" + annotationFile.getParent());

                OutputRunner runner = new OutputRunner(
                        genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile,
                        annotationFile);
                runner.execute();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:neg.JRViewerFactura.java

void btnSaveActionPerformed(java.awt.event.ActionEvent evt, String nombre) {
    // Add your handling code here:

    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setLocale(this.getLocale());
    fileChooser.updateUI();// ww w  . ja v a2s.co  m
    String archivo = nombre;
    File f = new File(archivo);
    fileChooser.setSelectedFile(f);

    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);
        fileChooser.setCurrentDirectory(lastFolder);
    }

    int retValue = fileChooser.showSaveDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        javax.swing.filechooser.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"));
        }
    }
}

From source file:neg.JRViewerFactura.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 w w  .  jav  a  2 s .  com
    String archivo = "Pepe.txt";
    File f = new File(archivo);
    fileChooser.setSelectedFile(f);

    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) {
        javax.swing.filechooser.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"));
        }
    }
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void doSaveAs() throws IOException {

    JFileChooser fileChooser = new JFileChooser();
    String currentDirectory = System.getProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL);
    if (currentDirectory != null) {
        File savePath = new File(currentDirectory);
        if (savePath.exists() && savePath.isDirectory()) {
            fileChooser.setCurrentDirectory(savePath);
        }//from   ww w.  j a  v  a2 s  .c o  m
    }
    ExtensionFileFilter ascFilter = new ExtensionFileFilter("Text_Files", ".txt");
    ExtensionFileFilter jpgFilter = new ExtensionFileFilter("JPG_Image_Files", ".jpg");
    ExtensionFileFilter pngFilter = new ExtensionFileFilter("PNG_Image_Files", ".png");
    fileChooser.addChoosableFileFilter(pngFilter);
    fileChooser.addChoosableFileFilter(jpgFilter);
    fileChooser.addChoosableFileFilter(ascFilter);
    fileChooser.setFileFilter(jpgFilter);
    int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
        String filename = fileChooser.getSelectedFile().getPath();
        String selectedDescription = fileChooser.getFileFilter().getDescription();
        String fileExtension = StaticValues.DEFAULT_IMAGE_FILE_EXTENSION;
        if (selectedDescription.toLowerCase().contains("png")) {
            fileExtension = "png";
            if (!filename.toLowerCase().endsWith(".png")) {
                filename = filename + ".png";
            }
        } else if (selectedDescription.toLowerCase().contains("jpg")) {
            fileExtension = "jpg";
            if (!filename.toLowerCase().endsWith(".jpg")) {
                filename = filename + ".jpg";
            }
        } else if (selectedDescription.toLowerCase().contains("text")) {
            fileExtension = "txt";
            if (!filename.toLowerCase().endsWith(".txt")) {
                filename = filename + ".txt";
            }
        }
        File selectedFile = new File(filename);
        int confirm = JOptionPane.YES_OPTION;
        if (selectedFile.exists()) {
            confirm = JOptionPane.showConfirmDialog(this, selectedFile.getName() + " exists, overwrite?",
                    "Confirm Overwriting", JOptionPane.YES_NO_OPTION);
        }
        if (confirm == JOptionPane.YES_OPTION) {
            saveTo(filename, fileExtension);
            System.setProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL, fileChooser.getSelectedFile().getParent());
        }
    }
}

From source file:ffx.ui.MainPanel.java

/**
 * Trys to convert a file picked from a JFileChooser
 *//* w w w.  j a va  2s.c o  m*/
private Thread open() {
    if (openThread != null && openThread.isAlive()) {
        return null;
    }
    JFileChooser fc = resetFileChooser();
    fc.setDialogTitle("Choose FFX, PDB, XYZ or ARC");
    fc.addChoosableFileFilter(xyzFileFilter);
    fc.addChoosableFileFilter(pdbFileFilter);
    fc.addChoosableFileFilter(intFileFilter);
    fc.addChoosableFileFilter(arcFileFilter);
    fc.addChoosableFileFilter(ffxFileFilter);
    fc.setAcceptAllFileFilterUsed(true);
    int result = fc.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        return open(file, null);
    }
    return null;
}

From source file:client.welcome2.java

private void SupplierUploadContractButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SupplierUploadContractButton1ActionPerformed
    try {/*w ww.  ja v  a2s .c o  m*/

        JFileChooser supplier_chooser = new JFileChooser();
        supplier_chooser.setDialogTitle("Open a File");
        FileNameExtensionFilter docFilter = new FileNameExtensionFilter("Word Files", "docx");
        FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter("PDF Documents", "pdf");
        supplier_chooser.addChoosableFileFilter(docFilter);
        supplier_chooser.addChoosableFileFilter(pdfFilter);
        int result = supplier_chooser.showOpenDialog(null);
        if (result == 0) {
            File f = supplier_chooser.getSelectedFile();
            supplier_filename_update = f.getAbsolutePath();
            SupplierUploadText1.setText(supplier_filename_update);
            f.getAbsoluteFile();

        }

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);

    }
}

From source file:client.welcome2.java

private void SupplierUploadContractButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SupplierUploadContractButtonActionPerformed

    try {//from  w  w  w .  j a  va  2 s  .  c  om

        JFileChooser supplier_chooser = new JFileChooser();
        supplier_chooser.setDialogTitle("Open a File");
        FileNameExtensionFilter docFilter = new FileNameExtensionFilter("Word Files", "docx");
        FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter("PDF Documents", "pdf");
        supplier_chooser.addChoosableFileFilter(docFilter);
        supplier_chooser.addChoosableFileFilter(pdfFilter);
        int result = supplier_chooser.showOpenDialog(null);
        if (result == 0) {
            File f = supplier_chooser.getSelectedFile();
            filename_supplier = f.getAbsolutePath();
            SupplierUploadText.setText(filename_supplier);
            f.getAbsoluteFile();

        }

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);

    }
}