Example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

Introduction

In this page you can find the example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter.

Prototype

public FileNameExtensionFilter(String description, String... extensions) 

Source Link

Document

Creates a FileNameExtensionFilter with the specified description and file name extensions.

Usage

From source file:au.org.ala.delta.editor.DeltaEditor.java

public File selectFile(boolean open) {
    File selectedFile = null;//  www. java  2s  .co m
    JFileChooser chooser = new JFileChooser();

    if (_lastDirectory != null) {
        chooser.setCurrentDirectory(_lastDirectory);
    }

    chooser.setFileFilter(new FileNameExtensionFilter("Delta Editor files *.dlt", DELTA_FILE_EXTENSION));
    int dialogResult;
    if (open) {
        dialogResult = chooser.showOpenDialog(getMainFrame());
    } else {
        dialogResult = chooser.showSaveDialog(getMainFrame());
    }
    if (dialogResult == JFileChooser.APPROVE_OPTION) {
        selectedFile = chooser.getSelectedFile();
        _lastDirectory = chooser.getCurrentDirectory();
    }
    return selectedFile;
}

From source file:com.josue.tileset.editor.Editor.java

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

    JFileChooser fileDialog = new JFileChooser();
    fileDialog.setFileFilter(new FileNameExtensionFilter("Json file", "json"));
    String outputFileName = inputFile.getAbsolutePath().split("\\.")[0] + ".json";
    fileDialog.setSelectedFile(new File(outputFileName));
    if (fileDialog.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {

        File file = fileDialog.getSelectedFile();
        ObjectMapper mapper = new ObjectMapper();
        mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
        mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
        try {//from w w w. j  av a 2 s .  co  m
            mapper.writeValue(file, loadedTiles);
        } catch (IOException ex) {
            Logger.getLogger(Editor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:generadorqr.jifrNuevoQr.java

void CargarVideo(JLabel label, Integer identificador) {
    int resultado;
    // ventana = new CargarFoto();
    JFileChooser jfchCargarVideo = new JFileChooser();
    FileNameExtensionFilter filtro = new FileNameExtensionFilter("MP4", "mp4");
    jfchCargarVideo.setFileFilter(filtro);
    resultado = jfchCargarVideo.showOpenDialog(null);
    if (JFileChooser.APPROVE_OPTION == resultado) {
        fichero = jfchCargarVideo.getSelectedFile();
        try {//ww  w .  j a v a  2 s.c  om
            tempVideo = fichero.getPath();
            tempNombreMultimedia[identificador] = fichero.getName();
            label.setText(tempNombreMultimedia[identificador]);
            if (label.getText().length() > 10)
                label.setText(tempNombreMultimedia[identificador].substring(0, 10) + "...mp4");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex);
        }
    }
}

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

/**
 * Initialises the interface of the results panel.
 *//*  ww w .j  a  v  a2  s.co m*/
protected void initialize() {
    setLayout(null);

    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);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    JFrame chartFrame = new JFrame();
                    OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                    String title = simulation.toString();
                    DescriptiveStatistics statistics = null;
                    OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    OMRoomType roomType = null;
                    switch (statisticsType) {
                    case RoomArithmeticMeans:
                        title = "R_AM, " + title;
                        statistics = simulation.getRoomAmDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomGeometricMeans:
                        title = "R_GM, " + title;
                        statistics = simulation.getRoomGmDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomMedianQ50:
                        title = "R_MED, " + title;
                        statistics = simulation.getRoomMedDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case RoomMaxima:
                        title = "R_MAX, " + title;
                        statistics = simulation.getRoomMaxDescriptiveStats();
                        roomType = OMRoomType.Room;
                        break;
                    case CellarArithmeticMeans:
                        title = "C_AM, " + title;
                        statistics = simulation.getCellarAmDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarGeometricMeans:
                        title = "C_GM, " + title;
                        statistics = simulation.getCellarGmDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarMedianQ50:
                        title = "C_MED, " + title;
                        statistics = simulation.getCellarMedDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    case CellarMaxima:
                        title = "C_MAX, " + title;
                        statistics = simulation.getCellarMaxDescriptiveStats();
                        roomType = OMRoomType.Cellar;
                        break;
                    default:
                        title = "R_AM, " + title;
                        statistics = simulation.getRoomAmDescriptiveStats();
                        roomType = OMRoomType.Misc;
                        break;
                    }
                    JPanel chartPanel = createDistributionPanel(title, statistics, roomType, false, true, true);
                    chartFrame.getContentPane().add(chartPanel);
                    chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                    chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
                    chartFrame.setTitle("OM Simulation Tool: " + title);
                    chartFrame.setResizable(true);
                    chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    chartFrame.setVisible(true);
                }
            }
        }
    });
    add(btnMaximize);

    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;
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                OMCampaign[] campaigns = simulation.getCampaigns();
                File csvFile = new File(csvPath);
                try {
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    String head = "";
                    switch (statisticsType) {
                    case RoomArithmeticMeans:
                        head = "R_AM";
                        break;
                    case RoomGeometricMeans:
                        head = "R_GM";
                        break;
                    case RoomMedianQ50:
                        head = "R_MED";
                        break;
                    case RoomMaxima:
                        head = "R_MAX";
                        break;
                    case CellarArithmeticMeans:
                        head = "C_AM";
                        break;
                    case CellarGeometricMeans:
                        head = "C_GM";
                        break;
                    case CellarMedianQ50:
                        head = "C_MED";
                        break;
                    case CellarMaxima:
                        head = "C_MAX";
                        break;
                    default:
                        head = "R_AM";
                        break;
                    }
                    csvOutput.write("\"ID\";\"CAMPAIGN\";\"START\";\"" + head + "\"");
                    csvOutput.newLine();
                    int value = 0;
                    for (int i = 0; i < campaigns.length; i++) {
                        switch (statisticsType) {
                        case RoomArithmeticMeans:
                            value = (int) campaigns[i].getRoomAverage();
                            break;
                        case RoomGeometricMeans:
                            value = (int) campaigns[i].getRoomLogAverage();
                            break;
                        case RoomMedianQ50:
                            value = (int) campaigns[i].getRoomMedian();
                            break;
                        case RoomMaxima:
                            value = (int) campaigns[i].getRoomMaximum();
                            break;
                        case CellarArithmeticMeans:
                            value = (int) campaigns[i].getCellarAverage();
                            break;
                        case CellarGeometricMeans:
                            value = (int) campaigns[i].getCellarLogAverage();
                            break;
                        case CellarMedianQ50:
                            value = (int) campaigns[i].getCellarMedian();
                            break;
                        case CellarMaxima:
                            value = (int) campaigns[i].getCellarMaximum();
                            break;
                        default:
                            value = (int) campaigns[i].getRoomAverage();
                            break;
                        }
                        csvOutput.write("\"" + i + "\";\"" + campaigns[i].getVariation() + "\";\""
                                + campaigns[i].getStart() + "\";\"" + value + "\"");
                        csvOutput.newLine();
                    }
                    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;
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                String title = simulation.toString();
                DescriptiveStatistics statistics = null;
                OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                OMRoomType roomType = null;
                switch (statisticsType) {
                case RoomArithmeticMeans:
                    title = "R_AM, " + title;
                    statistics = simulation.getRoomAmDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomGeometricMeans:
                    title = "R_GM, " + title;
                    statistics = simulation.getRoomGmDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomMedianQ50:
                    title = "R_MED, " + title;
                    statistics = simulation.getRoomMedDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case RoomMaxima:
                    title = "R_MAX, " + title;
                    statistics = simulation.getRoomMaxDescriptiveStats();
                    roomType = OMRoomType.Room;
                    break;
                case CellarArithmeticMeans:
                    title = "C_AM, " + title;
                    statistics = simulation.getCellarAmDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarGeometricMeans:
                    title = "C_GM, " + title;
                    statistics = simulation.getCellarGmDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarMedianQ50:
                    title = "C_MED, " + title;
                    statistics = simulation.getCellarMedDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                case CellarMaxima:
                    title = "C_MAX, " + title;
                    statistics = simulation.getCellarMaxDescriptiveStats();
                    roomType = OMRoomType.Cellar;
                    break;
                default:
                    title = "R_AM, " + title;
                    statistics = simulation.getRoomAmDescriptiveStats();
                    roomType = OMRoomType.Misc;
                    break;
                }
                JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, false);
                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();
                }
            } 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);

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

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

    comboBoxSimulations = new JComboBox<OMSimulation>();
    comboBoxSimulations.setFont(new Font("SansSerif", Font.PLAIN, 11));
    comboBoxSimulations.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent arg0) {
            boolean b = false;
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    b = true;
                    comboBoxStatistics.removeAllItems();
                    comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values()));
                } else {
                    b = false;
                    comboBoxStatistics.removeAllItems();
                }
            } else {
                b = false;
                comboBoxStatistics.removeAllItems();
            }
            progressBar.setEnabled(b);
            btnPdf.setVisible(b);
            btnCsv.setVisible(b);
            btnMaximize.setVisible(b);
            lblExportChartTo.setVisible(b);
            comboBoxStatistics.setEnabled(b);
            lblSelectStatistics.setEnabled(b);
        }
    });
    comboBoxSimulations.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            boolean b = false;
            if (comboBoxSimulations.isEnabled()) {
                if (comboBoxSimulations.getSelectedItem() != null) {
                    b = true;
                    comboBoxStatistics.removeAllItems();
                    comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values()));
                    comboBoxStatistics.setSelectedIndex(0);
                } else {
                    b = false;
                    comboBoxStatistics.removeAllItems();
                }
            } else {
                b = false;
                comboBoxStatistics.removeAllItems();
            }
            progressBar.setEnabled(b);
            btnPdf.setVisible(b);
            btnCsv.setVisible(b);
            btnMaximize.setVisible(b);
            lblExportChartTo.setVisible(b);
            comboBoxStatistics.setEnabled(b);
            lblSelectStatistics.setEnabled(b);
        }
    });
    comboBoxSimulations.setBounds(152, 61, 454, 22);
    add(comboBoxSimulations);

    btnRefresh = new JButton("Load");
    btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11));
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmsFile.getText() != null && !txtOmsFile.getText().equals("")
                    && !txtOmsFile.getText().equals(" ")) {
                txtOmsFile.setBackground(Color.WHITE);
                String omsPath = txtOmsFile.getText();
                String oms;
                String[] tmpFileName = omsPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("oms")) {
                    oms = "";
                } else {
                    oms = ".oms";
                }
                txtOmsFile.setText(omsPath + oms);
                setOmsFile(omsPath + oms);
                File omsFile = new File(omsPath + oms);
                if (omsFile.exists()) {
                    txtOmsFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxSimulations.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    progressBar.setStringPainted(true);
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    btnMaximize.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    refreshSimulationsTask = new RefreshSimulations();
                    refreshSimulationsTask.execute();
                } else {
                    txtOmsFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMS-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmsFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMS-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });

    comboBoxStatistics = new JComboBox<OMStatistics>();
    comboBoxStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11));
    comboBoxStatistics.setBounds(152, 90, 454, 22);
    comboBoxStatistics.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            updateDistribution();
        }
    });
    add(comboBoxStatistics);

    btnRefresh.setBounds(616, 61, 124, 23);
    add(btnRefresh);

    panelDistribution = new JPanel();
    panelDistribution.setBounds(10, 118, 730, 347);
    add(panelDistribution);

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

    progressBar.setEnabled(false);
    comboBoxStatistics.setEnabled(false);
    lblSelectStatistics.setEnabled(false);
    btnPdf.setVisible(false);
    btnCsv.setVisible(false);
    btnMaximize.setVisible(false);
    lblExportChartTo.setVisible(false);

    lblHelp = new JLabel("Select an OMS-Simulation file to analyse the simulation results and "
            + "display the distribution chart.");
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11));
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

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

    txtOmsFile = new JTextField();
    txtOmsFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            setOmsFile(txtOmsFile.getText());
        }
    });
    txtOmsFile.setFont(new Font("SansSerif", Font.PLAIN, 11));
    txtOmsFile.setColumns(10);
    txtOmsFile.setBounds(152, 33, 454, 20);
    add(txtOmsFile);

    buttonBrowse = new JButton("Browse");
    buttonBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.oms", "oms"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String oms;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("oms")) {
                    oms = "";
                } else {
                    oms = ".oms";
                }
                txtOmsFile.setText(file.getAbsolutePath() + oms);
                setOmsFile(file.getAbsolutePath() + oms);
            }
        }
    });
    buttonBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11));
    buttonBrowse.setBounds(616, 32, 124, 23);
    add(buttonBrowse);
    progressBar.setVisible(false);
}

From source file:net.rptools.maptool.launcher.MapToolLauncher.java

private JPanel buildBasicPanel() {
    final JPanel p = new JPanel();
    p.setLayout(new BorderLayout());

    // BASIC:  Top panel
    final JPanel logoPanel = new JPanel();
    logoPanel.setLayout(new FlowLayout());
    logoPanel.setBorder(/*w  ww . j  a v  a 2 s.c o m*/
            new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logoPanel.border"))); //$NON-NLS-1$

    jlMTLogo.setIcon(icon);
    logoPanel.add(jlMTLogo);

    // BASIC:  Middle panel
    final JPanel memPanel = new JPanel();
    memPanel.setLayout(new GridLayout(3, 2));
    memPanel.setBorder(new LineBorder(Color.WHITE));

    jtfMaxMem.setHorizontalAlignment(SwingConstants.RIGHT);
    jtfMaxMem.setInfo(CopiedFromOtherJars.getText("msg.info.javaMaxMem", DEFAULT_MAXMEM)); //$NON-NLS-1$ 
    jtfMaxMem.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaMaxMem")); //$NON-NLS-1$
    jtfMaxMem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            jtfMaxMemActionPerformed(evt);
        }
    });
    jtfMaxMem.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent evt) {
            jtfMaxMemFocusLost(evt);
        }

        @Override
        public void focusGained(FocusEvent evt) {
            jtfMaxMemFocusLost(evt);
        }
    });
    jtfMaxMem.addKeyListener(new InputValidator());

    jtfMinMem.setHorizontalAlignment(SwingConstants.RIGHT);
    jtfMinMem.setInfo(CopiedFromOtherJars.getText("msg.info.javaMinMem", DEFAULT_MINMEM)); //$NON-NLS-1$ 
    jtfMinMem.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaMinMem")); //$NON-NLS-1$
    jtfMinMem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            jtfMinMemActionPerformed(evt);
        }
    });
    jtfMinMem.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent evt) {
            jtfMinMemFocusLost(evt);
        }

        @Override
        public void focusGained(FocusEvent evt) {
            jtfMinMemFocusLost(evt);
        }
    });
    jtfMinMem.addKeyListener(new InputValidator());

    jtfStackSize.setHorizontalAlignment(SwingConstants.RIGHT);
    jtfStackSize.setInfo(CopiedFromOtherJars.getText("msg.info.javaStackSize", DEFAULT_STACKSIZE)); //$NON-NLS-1$ 
    jtfStackSize.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaStackSize")); //$NON-NLS-1$
    jtfStackSize.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            jtfStackSizeActionPerformed(evt);
        }
    });
    jtfStackSize.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent evt) {
            jtfStackSizeFocusLost(evt);
        }

        @Override
        public void focusGained(FocusEvent evt) {
            jtfStackSizeFocusLost(evt);
        }
    });
    jtfStackSize.addKeyListener(new InputValidator());

    memPanel.add(jtfMaxMem);
    memPanel.add(jtfMinMem);
    memPanel.add(jtfStackSize);

    // BASIC:  Bottom panel
    final JPanel southPanel = new JPanel();
    southPanel.setLayout(new BorderLayout());

    final JPanel cbPanel = new JPanel();
    cbPanel.setLayout(new GridLayout(2, 1));
    cbPanel.setBorder(new LineBorder(Color.GRAY));

    jcbPromptUser.setSelected(true);
    jcbPromptUser.setText(CopiedFromOtherJars.getText("msg.info.promptAtNextLaunch")); //$NON-NLS-1$
    jcbPromptUser.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.promptAtNextLaunch")); //$NON-NLS-1$
    jcbPromptUser.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            promptUser = jcbPromptUser.isSelected();
        }
    });

    jbMTJar.setText(jbMTJarText);
    jbMTJar.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.registerMapToolJar")); //$NON-NLS-1$
    jbMTJar.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final JFileChooser jfc = new JFileChooser();
            jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            FileFilter filter = new FileNameExtensionFilter(
                    CopiedFromOtherJars.getText("msg.chooser.javaExecutable"), "jar"); //$NON-NLS-1$ //$NON-NLS-2$
            jfc.addChoosableFileFilter(filter);
            jfc.setFileFilter(filter);
            if (IS_MAC) {
                filter = new FileNameExtensionFilter(
                        CopiedFromOtherJars.getText("msg.chooser.appleApplicationBundle"), "app"); //$NON-NLS-1$ //$NON-NLS-2$
                jfc.addChoosableFileFilter(filter);
            }
            jfc.setCurrentDirectory(mapToolJarDir);

            final int returnVal = jfc.showOpenDialog(jbMTJar);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final File f = jfc.getSelectedFile();
                final String fileName = f.getName();
                if (IS_MAC && fileName.endsWith(".app")) { //$NON-NLS-1$
                    File jarDir = new File(f.getParentFile(), fileName);
                    if (jarDir.isDirectory()) {
                        jarDir = new File(jarDir, "Contents/Resources/Java"); //$NON-NLS-1$
                        if (jarDir.isDirectory()) {
                            mapToolJarDir = jarDir;
                            mapToolJarName = fileName.replace(".app", ".jar"); //$NON-NLS-1$ //$NON-NLS-2$
                        } else {
                            logMsg(Level.SEVERE,
                                    "{0} does not contain 'Contents/Resources/Java' like it should!", //$NON-NLS-1$
                                    "msg.chooser.badAppLocation", jarDir); //$NON-NLS-1$
                            return;
                        }
                    } else {
                        logMsg(Level.SEVERE, "{0} is not a directory and it should be!", //$NON-NLS-1$
                                "msg.chooser.badAppLocation", jarDir); //$NON-NLS-1$
                        return;
                    }
                } else {
                    mapToolJarName = fileName;
                    mapToolJarDir = f.getParentFile();
                }
                logMsg(Level.INFO, f.toString(), null);
                jbMTJar.setText(fileName.replace(".jar", EMPTY)); //$NON-NLS-1$
                if (fileName.toLowerCase().startsWith("maptool-")) {
                    // We expect the name matches 'maptool-1.3.b89.jar'
                    mapToolVersion = " " + fileName.substring(8, 11);
                } else {
                    logMsg(Level.SEVERE, "Cannot determine MapTool version number from JAR filename: {0}", //$NON-NLS-1$
                            "msg.info.noMapToolVersion", fileName);
                    mapToolVersion = EMPTY;
                }
                jbLaunch.setEnabled(true);
                updateCommand();
                jbLaunch.requestFocusInWindow();
            }
        }
    });

    cbPanel.add(jcbPromptUser);
    cbPanel.add(jbMTJar);

    southPanel.add(cbPanel, BorderLayout.CENTER);

    p.add(memPanel, BorderLayout.CENTER);
    p.add(logoPanel, BorderLayout.NORTH);
    p.add(southPanel, BorderLayout.SOUTH);
    p.setBorder(new LineBorder(Color.BLACK));
    return p;
}

From source file:InterfaceModule.JRobert.java

private File loadFile() {
    JFileChooser chooser = new JFileChooser(System.getProperty("user.dir") + "/saves/");
    FileNameExtensionFilter filter = new FileNameExtensionFilter("TXT file", "txt");
    chooser.setFileFilter(filter);/*from ww w  .  j a v  a 2s .c  o m*/
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFile();
    } else
        return null;
}

From source file:generadorqr.jifrNuevoQr.java

void CargarAudio(JLabel label, Integer identificador) {
    int resultado;
    // ventana = new CargarFoto();
    JFileChooser jfchCargarVideo = new JFileChooser();
    FileNameExtensionFilter filtro = new FileNameExtensionFilter("MP3", "mp3");
    jfchCargarVideo.setFileFilter(filtro);
    resultado = jfchCargarVideo.showOpenDialog(null);
    if (JFileChooser.APPROVE_OPTION == resultado) {
        fichero = jfchCargarVideo.getSelectedFile();
        try {// w  w w .  j av  a2s .com
            tempAudio = fichero.getPath();
            tempNombreMultimedia[identificador] = fichero.getName();
            label.setText(tempNombreMultimedia[identificador]);
            if (label.getText().length() > 10)
                label.setText(tempNombreMultimedia[identificador].substring(0, 10) + "...mp3");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex);
        }
    }
}

From source file:FileChooserDemo.java

private FileFilter createFileFilter(String description, boolean showExtensionInDescription,
        String... extensions) {/*  w ww .ja  v a 2 s  .  c o m*/
    if (showExtensionInDescription) {
        description = createFileNameFilterDescriptionFromExtensions(description, extensions);
    }
    return new FileNameExtensionFilter(description, extensions);
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public void fileSaveHex(SpinCADBank bank) {
    // Create a file chooser
    String savedPath = prefs.get("MRUHexFolder", "");

    final JFileChooser fc = new JFileChooser(savedPath);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Hex Files", "hex");
    fc.setFileFilter(filter);/*from ww  w .ja v a2s  . c  om*/
    fc.showSaveDialog(new JFrame());
    File fileToBeSaved = fc.getSelectedFile();

    if (!fc.getSelectedFile().getAbsolutePath().endsWith(".hex")) {
        fileToBeSaved = new File(fc.getSelectedFile() + ".hex");
    }
    int n = JOptionPane.YES_OPTION;
    if (fileToBeSaved.exists()) {
        JFrame frame1 = new JFrame();
        n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!",
                JOptionPane.YES_NO_OPTION);
    }
    if (n == JOptionPane.YES_OPTION) {
        String filePath;
        try {
            filePath = fileToBeSaved.getPath();
            fileToBeSaved.delete();
        } finally {
        }
        for (int i = 0; i < 8; i++) {
            try {
                if (bank.patch[i].isHexFile) {
                    fileSaveHex(i, bank.patch[i].hexFile, filePath);
                } else {
                    fileSaveHex(i, bank.patch[i].patchModel.getRenderBlock().generateHex(), filePath);
                }
            } catch (IOException e) {
                JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);

                e.printStackTrace();
            }
        }
        saveMRUHexFolder(filePath);
    }
}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public void fileSaveSpj(SpinCADBank bank) {
    // Create a file chooser
    String savedPath = prefs.get("MRUSpjFolder", "");
    String[] spnFileNames = new String[8];

    final JFileChooser fc = new JFileChooser(savedPath);
    // In response to a button click:
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin Project Files", "spj");
    fc.setFileFilter(filter);//  w  ww.  ja va2 s.c o m
    // XXX debug
    fc.showSaveDialog(new JFrame());
    File fileToBeSaved = fc.getSelectedFile();

    if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spj")) {
        fileToBeSaved = new File(fc.getSelectedFile() + ".spj");
    }
    int n = JOptionPane.YES_OPTION;
    if (fileToBeSaved.exists()) {
        JFrame frame1 = new JFrame();
        n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!",
                JOptionPane.YES_NO_OPTION);
    }
    if (n == JOptionPane.YES_OPTION) {
        // filePath points at the desired Spj file
        String filePath = fileToBeSaved.getPath();
        String folder = fileToBeSaved.getParent().toString();

        // export the individual SPN files
        for (int i = 0; i < 8; i++) {
            try {
                String asmFileNameRoot = FilenameUtils.removeExtension(bank.patch[i].patchFileName);
                String asmFileName = folder + "\\" + asmFileNameRoot + ".spn";
                if (bank.patch[i].patchFileName != "Untitled") {
                    fileSaveAsm(bank.patch[i], asmFileName);
                    spnFileNames[i] = asmFileName;
                }
            } catch (IOException e) {
                JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);

                e.printStackTrace();
            } finally {
            }
        }

        // now create the Spin Project file
        fileToBeSaved.delete();
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(fileToBeSaved, true));
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        try {
            writer.write("NUMDOCS:8");
            writer.newLine();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        for (int i = 0; i < 8; i++) {
            try {
                if (bank.patch[i].patchFileName != "Untitled") {
                    writer.write(spnFileNames[i] + ",1");
                } else {
                    writer.write(",0");
                }
                writer.newLine();
            } catch (IOException e) {
                JOptionPane.showOptionDialog(null, "File save error!\n" + filePath, "Error",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);

                e.printStackTrace();
            }
        }
        // write the build flags
        try {
            writer.write(",1,1,1");
            writer.newLine();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        try {
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        saveMRUSpjFolder(filePath);
    }
}