Example usage for javax.swing JFileChooser setFileFilter

List of usage examples for javax.swing JFileChooser setFileFilter

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "Sets the File Filter used to filter out files of type.")
public void setFileFilter(FileFilter filter) 

Source Link

Document

Sets the current file filter.

Usage

From source file:net.panthema.BispanningGame.GamePanel.java

public void writePdf() throws FileNotFoundException, DocumentException {

    // Query user for filename
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Specify PDF file to save");
    chooser.setCurrentDirectory(new File("."));
    FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Documents", "pdf");
    chooser.setFileFilter(filter);

    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
        return;/*from w  ww  .j  a  v  a 2 s  .co  m*/

    File outfile = chooser.getSelectedFile();
    if (!outfile.getAbsolutePath().endsWith(".pdf")) {
        outfile = new File(outfile.getAbsolutePath() + ".pdf");
    }

    // Calculate page size rectangle
    Dimension size = mVV.getSize();
    Rectangle rsize = new Rectangle(size.width, size.height);

    // Open the PDF file for writing - and create a Graphics2D object
    Document document = new Document(rsize);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outfile));
    document.open();

    PdfContentByte contentByte = writer.getDirectContent();
    PdfGraphics2D graphics2d = new PdfGraphics2D(contentByte, size.width, size.height, new DefaultFontMapper());

    // Create a container to hold the visualization
    Container container = new Container();
    container.addNotify();
    container.add(mVV);
    container.setVisible(true);
    container.paintComponents(graphics2d);

    // Dispose of the graphics and close the document
    graphics2d.dispose();
    document.close();

    // Put mVV back onto visible plane
    setLayout(new BorderLayout());
    add(mVV, BorderLayout.CENTER);
}

From source file:net.panthema.BispanningGame.GamePanel.java

public void writeGraphML() throws IOException {

    // Query user for filename
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Specify GraphML file to save");
    chooser.setCurrentDirectory(new File("."));
    FileNameExtensionFilter filter = new FileNameExtensionFilter("GraphML File", "graphml");
    chooser.setFileFilter(filter);

    if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
        return;/*  ww w .j  av a  2  s . com*/

    File outfile = chooser.getSelectedFile();
    if (!outfile.getAbsolutePath().endsWith(".graphml")) {
        outfile = new File(outfile.getAbsolutePath() + ".graphml");
    }

    // construct graphml writer
    GraphMLWriter<Integer, MyEdge> graphWriter = new GraphMLWriter<Integer, MyEdge>();

    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outfile)));

    graphWriter.addVertexData("x", null, "0", new Transformer<Integer, String>() {
        public String transform(Integer v) {
            return Double.toString(mLayout.getX(v));
        }
    });

    graphWriter.addVertexData("y", null, "0", new Transformer<Integer, String>() {
        public String transform(Integer v) {
            return Double.toString(mLayout.getY(v));
        }
    });

    graphWriter.addEdgeData("color", null, "0", new Transformer<MyEdge, String>() {
        public String transform(MyEdge e) {
            return Integer.toString(e.color);
        }
    });

    graphWriter.save(mGraph, out);
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelTesting.java

/**
 * Initialises the interface of the results panel.
 *///  www .  ja  v  a2  s .com
protected void initialize() {

    setLayout(null);
    isSimulated = false;

    lblExportChartTo = new JLabel("Export chart to ...");
    lblExportChartTo.setBounds(436, 479, 144, 14);
    lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblExportChartTo.setVisible(false);
    add(lblExportChartTo);

    btnCsv = new JButton("CSV");
    btnCsv.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String csv;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("csv")) {
                    csv = "";
                } else {
                    csv = ".csv";
                }
                String csvPath = file.getAbsolutePath() + csv;
                double[] selectedValues;
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                final int day = 24;
                File csvFile = new File(csvPath);
                try {
                    OMCampaign campaign;
                    if (isResult) {
                        campaign = getResultCampaign();
                    } else {
                        campaign = new OMCampaign(start, rooms, 0);
                    }
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    csvOutput.write("\"ID\";\"Room\";\"Radon\"");
                    csvOutput.newLine();
                    selectedValues = campaign.getValueChain();
                    int x = 0;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[0].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[1].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[2].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[3].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[4].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[5].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    start = start + day;
                    for (int i = start; i < start + day; i++) {
                        csvOutput.write("\"" + i + "\";\"" + rooms[6].getId() + "\";\""
                                + (int) selectedValues[x] + "\"");
                        csvOutput.newLine();
                        x++;
                    }
                    JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                    csvOutput.close();
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnCsv.setBounds(590, 475, 70, 23);
    btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnCsv.setVisible(false);
    add(btnCsv);

    btnPdf = new JButton("PDF");
    btnPdf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String pdf;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("pdf")) {
                    pdf = "";
                } else {
                    pdf = ".pdf";
                }
                String pdfPath = file.getAbsolutePath() + pdf;
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                OMCampaign campaign;
                try {
                    if (isResult) {
                        campaign = getResultCampaign();
                    } else {
                        campaign = new OMCampaign(start, rooms, 0);
                    }
                    JFreeChart chart = OMCharts.createCampaignChart(campaign, false);
                    String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId()
                            + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId()
                            + ", Start: " + start;
                    int height = (int) PageSize.A4.getWidth();
                    int width = (int) PageSize.A4.getHeight();
                    try {
                        OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title);
                        JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success",
                                JOptionPane.INFORMATION_MESSAGE);
                    } catch (IOException ioe) {
                        JOptionPane.showMessageDialog(null,
                                "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed",
                                JOptionPane.ERROR_MESSAGE);
                        ioe.printStackTrace();
                    }
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null, "Failed to create chart!\n" + ioe.getMessage(),
                            "Failed", JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnPdf.setBounds(670, 475, 70, 23);
    btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnPdf.setVisible(false);
    add(btnPdf);

    lblSelectProject = new JLabel("Select Project");
    lblSelectProject.setBounds(10, 65, 132, 14);
    lblSelectProject.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblSelectProject);

    lblSelectRooms = new JLabel("Select Rooms");
    lblSelectRooms.setBounds(10, 94, 132, 14);
    lblSelectRooms.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblSelectRooms);

    lblStartTime = new JLabel("Start Time");
    lblStartTime.setBounds(10, 123, 132, 14);
    lblStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(lblStartTime);

    lblWarning = new JLabel("Select 6 rooms and 1 cellar!");
    lblWarning.setForeground(Color.RED);
    lblWarning.setBounds(565, 123, 175, 14);
    lblWarning.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblWarning.setVisible(false);
    add(lblWarning);

    sliderStartTime = new JSlider();
    sliderStartTime.setMaximum(0);
    sliderStartTime.setBounds(152, 119, 285, 24);
    sliderStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(sliderStartTime);

    spnrStartTime = new JSpinner();
    spnrStartTime.setModel(new SpinnerNumberModel(0, 0, 0, 1));
    spnrStartTime.setBounds(447, 120, 108, 22);
    spnrStartTime.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(spnrStartTime);

    btnRefresh = new JButton("Load");
    btnRefresh.setBounds(616, 61, 124, 23);
    btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(btnRefresh);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(btnMaximize);

    panelCampaign = new JPanel();
    panelCampaign.setBounds(10, 150, 730, 315);
    panelCampaign.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(panelCampaign);

    progressBar = new JProgressBar();
    progressBar.setBounds(10, 475, 730, 23);
    progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11));
    progressBar.setVisible(false);
    add(progressBar);

    lblOpenOmbfile = new JLabel("Open OMB-File");
    lblOpenOmbfile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblOpenOmbfile.setBounds(10, 36, 132, 14);
    add(lblOpenOmbfile);

    lblHelp = new JLabel("Select an OMB-Object file to manually simulate virtual campaigns.");
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

    txtOmbFile = new JTextField();
    txtOmbFile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    txtOmbFile.setColumns(10);
    txtOmbFile.setBounds(152, 33, 454, 20);
    add(txtOmbFile);

    btnBrowse = new JButton("Browse");
    btnBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnBrowse.setBounds(616, 32, 124, 23);
    add(btnBrowse);

    comboBoxRoom1 = new JComboBox<OMRoom>();
    comboBoxRoom1.setBounds(152, 90, 75, 22);
    comboBoxRoom1.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom1);

    comboBoxRoom2 = new JComboBox<OMRoom>();
    comboBoxRoom2.setBounds(237, 90, 75, 22);
    comboBoxRoom2.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom2);

    comboBoxRoom3 = new JComboBox<OMRoom>();
    comboBoxRoom3.setBounds(323, 90, 75, 22);
    comboBoxRoom3.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom3);

    comboBoxRoom4 = new JComboBox<OMRoom>();
    comboBoxRoom4.setBounds(408, 90, 75, 22);
    comboBoxRoom4.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom4);

    comboBoxRoom5 = new JComboBox<OMRoom>();
    comboBoxRoom5.setBounds(494, 90, 75, 22);
    comboBoxRoom5.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom5);

    comboBoxRoom6 = new JComboBox<OMRoom>();
    comboBoxRoom6.setBounds(579, 90, 75, 22);
    comboBoxRoom6.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom6);

    comboBoxRoom7 = new JComboBox<OMRoom>();
    comboBoxRoom7.setBounds(665, 90, 75, 22);
    comboBoxRoom7.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxRoom7);

    comboBoxProjects = new JComboBox<OMBuilding>();
    comboBoxProjects.setBounds(152, 61, 454, 22);
    comboBoxProjects.setFont(new Font("SansSerif", Font.PLAIN, 11));
    add(comboBoxProjects);

    comboBoxRoom1.addActionListener(this);
    comboBoxRoom1.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom2.addActionListener(this);
    comboBoxRoom2.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom3.addActionListener(this);
    comboBoxRoom3.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom4.addActionListener(this);
    comboBoxRoom4.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom5.addActionListener(this);
    comboBoxRoom5.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom6.addActionListener(this);
    comboBoxRoom6.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });
    comboBoxRoom7.addActionListener(this);
    comboBoxRoom7.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            validateCampaign();
        }
    });

    sliderStartTime.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    spnrStartTime.setValue((int) sliderStartTime.getValue());
                    updateChart();
                }
            }
        }
    });
    spnrStartTime.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    sliderStartTime.setValue((Integer) spnrStartTime.getValue());
                    updateChart();
                }
            }
        }
    });
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("")
                    && !txtOmbFile.getText().equals(" ")) {
                txtOmbFile.setBackground(Color.WHITE);
                String ombPath = txtOmbFile.getText();
                String omb;
                String[] tmpFileName = ombPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(ombPath + omb);
                setOmbFile(ombPath + omb);
                File ombFile = new File(ombPath + omb);
                if (ombFile.exists()) {
                    txtOmbFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxProjects.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    progressBar.setVisible(true);
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    btnMaximize.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    progressBar.setIndeterminate(true);
                    progressBar.setStringPainted(true);
                    refreshTask = new Refresh();
                    refreshTask.execute();
                } else {
                    txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                OMRoom[] rooms = new OMRoom[7];
                rooms[0] = (OMRoom) comboBoxRoom1.getSelectedItem();
                rooms[1] = (OMRoom) comboBoxRoom2.getSelectedItem();
                rooms[2] = (OMRoom) comboBoxRoom3.getSelectedItem();
                rooms[3] = (OMRoom) comboBoxRoom4.getSelectedItem();
                rooms[4] = (OMRoom) comboBoxRoom5.getSelectedItem();
                rooms[5] = (OMRoom) comboBoxRoom6.getSelectedItem();
                rooms[6] = (OMRoom) comboBoxRoom7.getSelectedItem();
                int start = sliderStartTime.getValue();
                String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId()
                        + rooms[3].getId() + rooms[4].getId() + rooms[5].getId() + rooms[6].getId()
                        + ", Start: " + start;
                OMCampaign campaign;
                if (isResult) {
                    campaign = getResultCampaign();
                } else {
                    campaign = new OMCampaign(start, rooms, 0);
                }
                JPanel campaignChart = createCampaignPanel(campaign, false, true);
                JFrame chartFrame = new JFrame();
                chartFrame.getContentPane().add(campaignChart);
                chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
                chartFrame.setTitle(title);
                chartFrame.setResizable(true);
                chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                chartFrame.setVisible(true);
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    });
    txtOmbFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            setOmbFile(txtOmbFile.getText());
        }
    });
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String omb;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(file.getAbsolutePath() + omb);
                setOmbFile(file.getAbsolutePath() + omb);
            }
        }
    });
}

From source file:de.tor.tribes.ui.views.DSWorkbenchSelectionFrame.java

private void exportAsHTML() {
    List<Village> selection = getSelectedElements();
    if (selection.isEmpty()) {
        showInfo("Keine Drfer ausgewhlt");
        return;/*from   w  w  w .j a  va 2  s. c  o  m*/
    }
    //do HTML export
    String dir = GlobalOptions.getProperty("screen.dir");

    JFileChooser chooser = null;
    try {
        //handle vista problem
        chooser = new JFileChooser(dir);
    } catch (Exception e) {
        JOptionPaneHelper.showErrorBox(this,
                "Konnte Dateiauswahldialog nicht ffnen.\nMglicherweise verwendest du Windows Vista. Ist dies der Fall, beende DS Workbench, klicke mit der rechten Maustaste auf DSWorkbench.exe,\n"
                        + "whle 'Eigenschaften' und deaktiviere dort unter 'Kompatibilitt' den Windows XP Kompatibilittsmodus.",
                "Fehler");
        return;
    }

    chooser.setDialogTitle("Datei auswhlen");
    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f != null) && (f.isDirectory() || f.getName().endsWith(".html"));
        }

        @Override
        public String getDescription() {
            return "*.html";
        }
    });
    //open dialog
    chooser.setSelectedFile(new File(dir + "/Dorfliste.html"));
    int ret = chooser.showSaveDialog(this);
    if (ret == JFileChooser.APPROVE_OPTION) {
        try {
            //check extension
            File f = chooser.getSelectedFile();
            String file = f.getCanonicalPath();
            if (!file.endsWith(".html")) {
                file += ".html";
            }

            //check overwrite
            File target = new File(file);
            if (target.exists()) {
                if (JOptionPaneHelper.showQuestionConfirmBox(this, "Bestehende Datei berschreiben?",
                        "berschreiben", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                    //do not overwrite
                    return;
                }
            }
            //do export
            SelectionHTMLExporter.doExport(target, selection);
            GlobalOptions.addProperty("screen.dir", target.getParent());
            showSuccess("Auswahl erfolgreich gespeichert");
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Willst du die erstellte Datei jetzt im Browser betrachten?", "Information", "Nein",
                    "Ja") == JOptionPane.YES_OPTION) {
                BrowserInterface.openPage(target.toURI().toURL().toString());
            }
        } catch (Exception inner) {
            logger.error("Failed to write selection to HTML", inner);
            showError("Fehler beim Speichern");
        }
    }
}

From source file:com.cybercom.svp.machine.gui.MachineForm.java

private void buttomLoadFirmwareSettingFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttomLoadFirmwareSettingFileActionPerformed
    JFileChooser fileDialog = new JFileChooser();
    fileDialog.setDialogTitle("Select firmware file");

    FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml");
    fileDialog.setFileFilter(filter);
    fileDialog.setDialogType(JFileChooser.OPEN_DIALOG);
    int result = fileDialog.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {

        try {/*from w w  w  .  j av a 2 s  .com*/
            String xml = FileUtils.readFileToString(fileDialog.getSelectedFile());
            firmwareUpdateRequestSetting = xmlToObj(FirmwareUpdateRequest.class, xml);
            updateFirmwareSettings();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

private void menuItemFileOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemFileOpenActionPerformed
    final JFileChooser dlg = new JFileChooser(this.destinationFile);
    dlg.setFileFilter(Utils.JHX_FILE_FILTER);
    if (dlg.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        final File file = dlg.getSelectedFile();
        loadFromFile(file);/*from w w w.  ja v a2 s . co  m*/
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

private void menuFileSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFileSaveAsActionPerformed
    final JFileChooser fileDlg = new JFileChooser(this.destinationFile);
    fileDlg.setFileFilter(Utils.JHX_FILE_FILTER);

    if (fileDlg.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fileDlg.getSelectedFile();
        if (!file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jhx")) {
            file = new File(file.getParentFile(), file.getName() + ".jhx");
        }//  w  ww  . java 2 s .  c o m
        if (saveStateToFile(file)) {
            updateTheSourceFile(file);
        }
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

private void menuFileExportAsXMLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFileExportAsXMLActionPerformed
    SelectLayersExportData toExport = prepareExportData();

    final DialogSelectLayersForExport dlg = new DialogSelectLayersForExport(this, true, true, false, toExport);
    dlg.setTitle("Select data for XML export");
    dlg.setVisible(true);//  w w w .  j  a  va  2  s. c  o m
    toExport = dlg.getResult();
    if (toExport != null) {
        final JFileChooser fileChooser = new JFileChooser(this.lastExportedFile);
        fileChooser.setFileFilter(Utils.XML_FILE_FILTER);
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            this.lastExportedFile = ensureFileExtenstion(fileChooser.getSelectedFile(), "xml");
            processExporterAsLongTask(this, "Export to XML file",
                    new XmlExporter(getDocumentOptions(), toExport, this.cellComments), this.lastExportedFile);
        }
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

private void menuFileExportAsImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFileExportAsImageActionPerformed
    SelectLayersExportData toExport = prepareExportData();

    final DialogSelectLayersForExport dlg = new DialogSelectLayersForExport(this, true, true, true, toExport);
    dlg.setTitle("Select data for export as PNG Image");
    dlg.setVisible(true);/* w  w  w .  j  a  va 2 s  .  c om*/
    toExport = dlg.getResult();
    if (toExport != null) {
        final JFileChooser fileChooser = new JFileChooser(this.lastExportedFile);
        fileChooser.setFileFilter(Utils.PNG_FILE_FILTER);
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            this.lastExportedFile = ensureFileExtenstion(fileChooser.getSelectedFile(), "png");
            processExporterAsLongTask(this, "Export to PNG image",
                    new PNGImageExporter(getDocumentOptions(), toExport, this.cellComments),
                    this.lastExportedFile);
        }
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

private void menuFileExportAsSVGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFileExportAsSVGActionPerformed
    SelectLayersExportData toExport = prepareExportData();

    final DialogSelectLayersForExport dlg = new DialogSelectLayersForExport(this, true, true, true, toExport);
    dlg.setTitle("Select data for export as SVG Image");
    dlg.setVisible(true);/* w ww .  java 2s . c om*/
    toExport = dlg.getResult();
    if (toExport != null) {
        final JFileChooser fileChooser = new JFileChooser(this.lastExportedFile);
        fileChooser.setFileFilter(Utils.SVG_FILE_FILTER);
        if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            this.lastExportedFile = ensureFileExtenstion(fileChooser.getSelectedFile(), "svg");
            processExporterAsLongTask(this, "Export to SVG image",
                    new SVGImageExporter(getDocumentOptions(), toExport, this.cellComments),
                    this.lastExportedFile);
        }
    }
}