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.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

protected JFileChooser initFileChooser() {
    ExtensionFileFilter filter = new ExtensionFileFilter("log,txt", true, true);
    filter.setDescription("?");
    JFileChooser jfc = new JFileChooser();
    FileSystemView fsv = FileSystemView.getFileSystemView();
    //?/* w w  w.j ava  2 s.co  m*/
    jfc.setCurrentDirectory(fsv.getHomeDirectory());
    jfc.setDialogTitle("?");
    jfc.setMultiSelectionEnabled(false);
    jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);//JFileChooser.FILES_AND_DIRECTORIES
    jfc.setFileFilter(filter);
    return jfc;
}

From source file:techtonic.Techtonic.java

private void jmiLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiLoadActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter fnef = new FileNameExtensionFilter("xml file only", ".xml");
    chooser.setFileFilter(fnef);
    int input = chooser.showOpenDialog(this);
    if (input == 0) {

    }//from  w w w. j  a va 2 s.c  o m
}

From source file:AltiConsole.AltiConsoleMainScreen.java

/**
 * Handles all the actions.//from  w w  w .j  a v  a 2  s.com
 * 
 * @param e
 *            the action event.
 */
public void actionPerformed(final ActionEvent e) {
    final Translator trans = Application.getTranslator();

    if (e.getActionCommand().equals("EXIT")) {
        System.out.println("exit and disconnecting\n");
        if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.ClosingWindow"),
                trans.get("AltiConsoleMainScreen.ReallyClosing"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            DisconnectFromAlti();
            System.exit(0);
        }
    } else if (e.getActionCommand().equals("ABOUT")) {
        AboutDialog.showPreferences(AltiConsoleMainScreen.this);
    }
    // ERASE_FLIGHT
    else if (e.getActionCommand().equals("ERASE_FLIGHT")) {

        if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.eraseAllflightData"),
                trans.get("AltiConsoleMainScreen.eraseAllflightDataTitle"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            System.out.println("erasing flight\n");
            ErasingFlight();
        }

    } else if (e.getActionCommand().equals("RETRIEVE_FLIGHT")) {

        System.out.println("retrieving flight\n");
        RetrievingFlight();

    } else
    // SAVE_FLIGHT
    if (e.getActionCommand().equals("SAVE_FLIGHT")) {
        System.out.println("Saving current flight\n");
        SavingFlight();
    } else
    // RETRIEVE_ALTI_CFG
    if (e.getActionCommand().equals("RETRIEVE_ALTI_CFG")) {
        System.out.println("retrieving alti config\n");
        AltiConfigData pAlticonfig = retrieveAltiConfig();
        if (pAlticonfig != null)
            AltiConfigDlg.showPreferences(AltiConsoleMainScreen.this, pAlticonfig, Serial);

    }
    // LICENSE
    else if (e.getActionCommand().equals("LICENSE")) {

        LicenseDialog.showPreferences(AltiConsoleMainScreen.this);
    }
    // comPorts
    else if (e.getActionCommand().equals("comPorts")) {
        DisconnectFromAlti();
        String currentPort;
        //e.
        currentPort = (String) comPorts.getSelectedItem();
        if (Serial != null)
            Serial.searchForPorts();

        System.out.println("We have a new selected value for comport\n");
        comPorts.setSelectedItem(currentPort);
    }
    // UPLOAD_FIRMWARE
    else if (e.getActionCommand().equals("UPLOAD_FIRMWARE")) {
        System.out.println("upload firmware\n");
        //make sure to disconnect first
        DisconnectFromAlti();
        JFileChooser fc = new JFileChooser();
        String hexfile = null;
        File startFile = new File(System.getProperty("user.dir"));
        //FileNameExtensionFilter filter;

        fc.setDialogTitle("Select firmware");
        //fc.set
        fc.setCurrentDirectory(startFile);
        //fc.addChoosableFileFilter(new FileNameExtensionFilter("*.HEX", "hex"));
        fc.setFileFilter(new FileNameExtensionFilter("*.hex", "hex"));
        //fc.fil
        int action = fc.showOpenDialog(SwingUtilities.windowForComponent(this));
        if (action == JFileChooser.APPROVE_OPTION) {
            hexfile = fc.getSelectedFile().getAbsolutePath();
        }
        if (hexfile != null) {

            String exefile = UserPref.getAvrdudePath();

            String conffile = UserPref.getAvrdudeConfigPath();

            String opts = " -v -v -v -v -patmega328p -carduino -P\\\\.\\"
                    + (String) this.comPorts.getSelectedItem() + " -b115200 -D -V ";

            String cmd = exefile + " -C" + conffile + opts + " -Uflash:w:" + hexfile + ":i";
            System.out.println(cmd);

            try {
                Process p = Runtime.getRuntime().exec(cmd);
                AfficheurFlux fluxSortie = new AfficheurFlux(p.getInputStream(), this);
                AfficheurFlux fluxErreur = new AfficheurFlux(p.getErrorStream(), this);

                new Thread(fluxSortie).start();
                new Thread(fluxErreur).start();

                p.waitFor();
            } catch (IOException e1) {
                e1.printStackTrace();
            } catch (InterruptedException e2) {
                e2.printStackTrace();
            }
        }
    }
    // ON_LINE_HELP
    else if (e.getActionCommand().equals("ON_LINE_HELP")) {
        Desktop d = Desktop.getDesktop();
        System.out.println("Online help \n");
        try {
            d.browse(new URI(trans.get("help.url")));
        } catch (URISyntaxException e1) {

            System.out.println("Illegal URL:  " + trans.get("help.url") + " " + e1.getMessage());
        } catch (IOException e1) {
            System.out.println("Unable to launch browser: " + e1.getMessage());
        }

    }
}

From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java

private void loadFilesActionPerformed(ActionEvent evt) throws TrackProfilerException {
    JFileChooser chooser = null;

    if (this.folderWithTracks != null) {
        chooser = new JFileChooser(this.folderWithTracks);
    } else {//from w ww  . ja  va2 s  . c o  m
        chooser = new JFileChooser();
    }

    TrackFileFilter filter = new TrackFileFilter();
    filter.addExtension(PLT_EXTENSION);
    filter.addExtension(WPT_EXTENSION);
    filter.setDescription(new Message(Messages.PLT_AND_WPT_FILES).toString());
    chooser.setFileFilter(filter);
    chooser.setMultiSelectionEnabled(true);

    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File[] selectedFiles = chooser.getSelectedFiles();

        for (int i = 0; i < selectedFiles.length; i++) {
            File selectedFile = selectedFiles[i];
            this.folderWithTracks = selectedFile.getParentFile();

            if (selectedFile.getName().toLowerCase().endsWith("." + PLT_EXTENSION)) { //$NON-NLS-1$
                try {
                    loadTrack(selectedFile);
                } catch (FileNotFoundException e) {
                    throw new TrackProfilerException(
                            new Message(Messages.ERROR_WHEN_LOADING).toString() + selectedFile.getName());
                }
            }
        }

        for (int i = 0; i < selectedFiles.length; i++) {
            File selectedFile = selectedFiles[i];
            this.folderWithTracks = selectedFile.getParentFile();

            if (selectedFile.getName().toLowerCase().endsWith("." + WPT_EXTENSION)) { //$NON-NLS-1$
                try {
                    loadWaypoints(selectedFile);
                } catch (FileNotFoundException e) {
                    throw new TrackProfilerException(
                            new Message(Messages.ERROR_WHEN_LOADING).toString() + selectedFile.getName());
                }
            }
        }

    }
}

From source file:io.github.jeremgamer.editor.panels.components.ButtonPanel.java

public ButtonPanel(JFrame frame) {

    this.frame = frame;
    this.setSize(new Dimension(395, frame.getHeight() - 27 - 23));
    this.setLocation(300, 0);
    this.setBorder(BorderFactory.createTitledBorder("Edition du bouton"));
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    JLabel nameLabel = new JLabel("Nom : ");
    name.setPreferredSize(new Dimension(this.getWidth() - 285, 30));
    name.setEditable(false);//from   w  ww  .  jav a  2  s  .  c o  m
    JPanel namePanel = new JPanel();
    namePanel.add(nameLabel);
    namePanel.add(name);
    JPanel textPanel = new JPanel();
    JPanel nameAndTextPanel = new JPanel();
    JLabel textLabel = new JLabel("Texte :");
    CaretListener caretUpdateText = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            bs.set("text", text.getText());
            preview.setText(text.getText());
            preview2.setText(text.getText());
        }
    };
    text.addCaretListener(caretUpdateText);
    text.setPreferredSize(new Dimension(this.getWidth() - 283, 30));
    textPanel.add(textLabel);
    textPanel.add(text);
    nameAndTextPanel.setLayout(new BoxLayout(nameAndTextPanel, BoxLayout.PAGE_AXIS));
    nameAndTextPanel.add(namePanel);
    nameAndTextPanel.add(textPanel);

    JPanel policePanel = new JPanel();
    JLabel policeLabel = new JLabel("Police : ");
    police.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) e.getSource();
            fontStyle = (String) combo.getSelectedItem();
            preview.setFont(new Font(fontStyle, Font.PLAIN, fontSize));
            preview2.setFont(new Font(fontStyle, Font.PLAIN, fontSize));
            bs.set("police", fontStyle);
        }

    });
    police.setPreferredSize(new Dimension(105, 30));
    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = e.getAllFonts();
    for (Font f : fonts) {
        police.addItem(f.getName());
    }
    police.setSelectedItem("Arial");
    policePanel.add(policeLabel);
    policePanel.add(police);

    JPanel sizePanel = new JPanel();
    size.setPreferredSize(new Dimension(60, 25));
    JLabel sizeLabel = new JLabel("Taille : ");
    sizePanel.add(sizeLabel);
    sizePanel.add(size);
    JButton colorButton = new JButton("Couleur");
    colorButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            colorFrame.setModal(false);
            JButton finish = new JButton("Terminer");
            finish.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    colorFrame.dispose();
                }

            });
            colorFrame.setLayout(new BorderLayout());
            colorFrame.add(color, BorderLayout.CENTER);
            colorFrame.add(finish, BorderLayout.SOUTH);
            colorFrame.pack();
            colorFrame.setLocation(SwingUtilities.windowForComponent(imagedButton).getX() + 325,
                    SwingUtilities.windowForComponent(imagedButton).getY() - colorFrame.getHeight() + 40);
            colorFrame.setVisible(true);
        }

    });
    sizePanel.add(colorButton);
    size.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            fontSize = (int) spinner.getValue();
            preview.setFont(new Font(fontStyle, Font.PLAIN, fontSize));
            preview2.setFont(new Font(fontStyle, Font.PLAIN, fontSize));
            bs.set("size", fontSize);
        }
    });

    JPanel policeAndSize = new JPanel();
    policeAndSize.setLayout(new BoxLayout(policeAndSize, BoxLayout.PAGE_AXIS));
    policeAndSize.add(policePanel);
    policeAndSize.add(sizePanel);

    JPanel top = new JPanel();
    top.add(nameAndTextPanel);
    top.add(policeAndSize);
    top.setPreferredSize(new Dimension(395, 20));

    this.add(top);

    JPanel images = new JPanel();
    images.setBorder(BorderFactory.createTitledBorder("Images"));
    images.setLayout(new GridLayout(2, 3));
    images.setPreferredSize(new Dimension(395, this.getHeight() - 320));

    JPanel imaged = new JPanel();
    imaged.setLayout(new BorderLayout());
    imaged.setBorder(BorderFactory.createTitledBorder("Icne interne"));
    imagedButton.setSelected(true);
    imagedButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                bs.set("strings", true);
                preview.setBorderPainted(true);
            } else if (ev.getStateChange() == ItemEvent.DESELECTED) {
                bs.set("strings", false);
                preview.setBorderPainted(false);
            }
        }
    });
    JButton browseInternal = new JButton("Parcourir");
    browseInternal.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "internal.png");
                nameInternal.setText(new File(path).getName());
                nameInternal.setPreferredSize(new Dimension(imgBasic.getWidth() - 10, 30));
                preview.setIcon(new ImageIcon(path));
                preview.repaint();
                bs.set("imageInternal", new File(path).getName());
            }
        }

    });
    JPanel northImaged = new JPanel();
    northImaged.setLayout(new BorderLayout());
    northImaged.add(imagedButton, BorderLayout.NORTH);
    northImaged.add(browseInternal, BorderLayout.SOUTH);
    imaged.add(northImaged, BorderLayout.NORTH);
    imaged.add(nameInternal, BorderLayout.CENTER);
    JButton removeInternal = null;
    try {
        removeInternal = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeInternal.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/internal.png");
            file.delete();
            nameInternal.setText("");
            bs.set("imageInternal", "");
            preview.setIcon(null);
        }

    });
    imaged.add(removeInternal, BorderLayout.SOUTH);
    images.add(imaged);

    imgBasic.setBorder(BorderFactory.createTitledBorder("Base"));
    JButton browseBasic = new JButton("Parcourir");
    browseBasic.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "basic.png");
                nameBasic.setText(new File(path).getName());
                nameBasic.setPreferredSize(new Dimension(imgBasic.getWidth() - 10, 30));
                previewPanel.remove(preview);
                previewPanel.remove(preview2);
                previewPanel.add(preview2);
                color.changePreview(preview2);
                bs.set("imageBasic", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgBasic.setLayout(new BorderLayout());
    imgBasic.add(browseBasic, BorderLayout.NORTH);
    imgBasic.add(nameBasic, BorderLayout.CENTER);
    JButton removeBasic = null;
    try {
        removeBasic = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeBasic.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/basic.png");
            file.delete();
            nameBasic.setText("");
            bs.set("imageBasic", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgBasic.add(removeBasic, BorderLayout.SOUTH);
    images.add(imgBasic);

    imgEntered.setBorder(BorderFactory.createTitledBorder("Survol"));
    JButton browseEntered = new JButton("Parcourir");
    browseEntered.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "entered.png");
                nameEntered.setText(new File(path).getName());
                nameEntered.setPreferredSize(new Dimension(imgEntered.getWidth() - 10, 30));
                bs.set("imageEntered", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgEntered.setLayout(new BorderLayout());
    imgEntered.add(browseEntered, BorderLayout.NORTH);
    imgEntered.add(nameEntered, BorderLayout.CENTER);
    JButton removeEntered = null;
    try {
        removeEntered = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeEntered.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/entered.png");
            file.delete();
            nameEntered.setText("");
            bs.set("imageEntered", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgEntered.add(removeEntered, BorderLayout.SOUTH);
    images.add(imgEntered);

    imgExited.setBorder(BorderFactory.createTitledBorder("Sortie"));
    JButton browseExited = new JButton("Parcourir");
    browseExited.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "exited.png");
                nameExited.setText(new File(path).getName());
                nameExited.setPreferredSize(new Dimension(imgExited.getWidth() - 10, 30));
                bs.set("imageExited", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgExited.setLayout(new BorderLayout());
    imgExited.add(browseExited, BorderLayout.NORTH);
    imgExited.add(nameExited, BorderLayout.CENTER);
    JButton removeExited = null;
    try {
        removeExited = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeExited.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/exited.png");
            file.delete();
            nameExited.setText("");
            bs.set("imageExited", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgExited.add(removeExited, BorderLayout.SOUTH);
    images.add(imgExited);

    imgPressed.setBorder(BorderFactory.createTitledBorder("Clic"));
    JButton browsePressed = new JButton("Parcourir");
    browsePressed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "pressed.png");
                namePressed.setText(new File(path).getName());
                namePressed.setPreferredSize(new Dimension(imgPressed.getWidth() - 10, 30));
                bs.set("imagePressed", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgPressed.setLayout(new BorderLayout());
    imgPressed.add(browsePressed, BorderLayout.NORTH);
    imgPressed.add(namePressed, BorderLayout.CENTER);
    JButton removePressed = null;
    try {
        removePressed = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removePressed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/pressed.png");
            file.delete();
            namePressed.setText("");
            bs.set("imagePressed", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgPressed.add(removePressed, BorderLayout.SOUTH);
    images.add(imgPressed);

    imgReleased.setBorder(BorderFactory.createTitledBorder("Relachement"));
    JButton browseReleased = new JButton("Parcourir");
    browseReleased.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "released.png");
                nameReleased.setText(new File(path).getName());
                nameReleased.setPreferredSize(new Dimension(imgReleased.getWidth() - 10, 30));
                bs.set("imageReleased", new File(path).getName());
                preview2.update();
                previewPanel.repaint();
            }
        }

    });
    imgReleased.setLayout(new BorderLayout());
    imgReleased.add(browseReleased, BorderLayout.NORTH);
    imgReleased.add(nameReleased, BorderLayout.CENTER);
    JButton removeReleased = null;
    try {
        removeReleased = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    removeReleased.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            File file = new File(
                    "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/released.png");
            file.delete();
            nameReleased.setText("");
            bs.set("imageReleased", "");
            preview2.update();
            previewPanel.repaint();
            if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("")
                    && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("")
                    && bs.getString("imageReleased").equals("")) {
                previewPanel.remove(preview2);
                previewPanel.add(preview);
            }
        }

    });
    imgReleased.add(removeReleased, BorderLayout.SOUTH);
    images.add(imgReleased);

    this.add(images);

    JPanel action = new JPanel();
    action.setPreferredSize(new Dimension(395, -20));
    JLabel labelAction = new JLabel("Action : ");
    action.add(labelAction);
    actionList.removeAllItems();
    actionList.addItem("Aucune");
    for (String s : Actions.getActions()) {
        actionList.addItem(s);
    }
    actionList.setPreferredSize(new Dimension(this.getWidth() - 100, 30));
    actionList.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            bs.set("action", combo.getSelectedItem());
        }

    });
    action.add(actionList);
    this.add(action);

    JScrollPane previewScroll = new JScrollPane(previewPanel);
    previewScroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    previewPanel.setBorder(BorderFactory.createTitledBorder("Aperu"));
    previewPanel.add(preview);
    previewScroll.setPreferredSize(new Dimension(395, 40));
    previewScroll.setBorder(null);

    this.add(previewScroll);
}

From source file:com.jug.MotherMachine.java

/**
 * Shows a JFileChooser set up to accept the selection of folders.
 * If 'cancel' is pressed this method terminates the MotherMachine app.
 *
 * @param guiFrame/*from ww w .  j  a  va2  s.c o m*/
 *            parent frame
 * @param path
 *            path to the folder to open initially
 * @return an instance of {@link File} pointing at the selected folder.
 */
private File showFolderChooser(final JFrame guiFrame, final String path) {
    final JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File(path));
    chooser.setDialogTitle("Select folder containing image sequence...");
    chooser.setFileFilter(new FileFilter() {

        @Override
        public final boolean accept(final File file) {
            return file.isDirectory();
        }

        @Override
        public String getDescription() {
            return "We only take directories";
        }
    });
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(guiFrame) == JFileChooser.APPROVE_OPTION) {
        return chooser.getSelectedFile();
    } else {
        System.exit(0);
        return null;
    }
}

From source file:fll.scheduler.SchedulerUI.java

void saveScheduleDescription() {
    if (null == mScheduleDescriptionFile) {
        // prompt the user for a filename to save to

        final String startingDirectory = PREFS.get(DESCRIPTION_STARTING_DIRECTORY_PREF, null);

        final JFileChooser fileChooser = new JFileChooser();
        final FileFilter filter = new BasicFileFilter("FLL Schedule Description (properties)",
                new String[] { "properties" });
        fileChooser.setFileFilter(filter);
        if (null != startingDirectory) {
            fileChooser.setCurrentDirectory(new File(startingDirectory));
        }// www. j a  v a  2s .com

        final int returnVal = fileChooser.showSaveDialog(SchedulerUI.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            final File currentDirectory = fileChooser.getCurrentDirectory();
            PREFS.put(DESCRIPTION_STARTING_DIRECTORY_PREF, currentDirectory.getAbsolutePath());

            mScheduleDescriptionFile = fileChooser.getSelectedFile();
            mDescriptionFilename.setText(mScheduleDescriptionFile.getName());
        } else {
            // user canceled
            return;
        }
    }

    try (final Writer writer = new OutputStreamWriter(new FileOutputStream(mScheduleDescriptionFile),
            Utilities.DEFAULT_CHARSET)) {
        final SolverParams params = mScheduleDescriptionEditor.getParams();
        final List<String> errors = params.isValid();
        if (!errors.isEmpty()) {
            final String formattedErrors = errors.stream().collect(Collectors.joining("\n"));
            JOptionPane.showMessageDialog(SchedulerUI.this,
                    "There are errors that need to be corrected before the description can be saved: "
                            + formattedErrors,
                    "Error saving file", JOptionPane.ERROR_MESSAGE);
        } else {
            final Properties properties = new Properties();
            params.save(properties);
            properties.store(writer, null);
        }
    } catch (final IOException e) {
        final Formatter errorFormatter = new Formatter();
        errorFormatter.format("Error saving file: %s", e.getMessage());
        LOGGER.error(errorFormatter, e);
        JOptionPane.showMessageDialog(SchedulerUI.this, errorFormatter, "Error saving file",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.nbt.TreeFrame.java

protected JFileChooser createFileChooser() {
    JFileChooser fc = new JFileChooser();
    fc.setFileHidingEnabled(false);//from w  w w. ja  v  a2s  .  c o  m
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    String description = "named binary tag";
    FileFilter filter = new FileNameExtensionFilter(description, "mcr", "dat", "dat_old");
    fc.setFileFilter(filter);
    Preferences prefs = getPreferences();
    String exportFile = prefs.get(KEY_FILE, null);
    if (exportFile == null) {
        File cwd = new File(".");
        fc.setCurrentDirectory(cwd);
    } else {
        File selectedFile = new File(exportFile);
        fc.setSelectedFile(selectedFile);
    }
    return fc;
}

From source file:ffx.ui.KeywordPanel.java

/**
 * <p>/*from   w  w  w .j  a  v  a  2  s  .c  o  m*/
 * keySaveAs</p>
 */
public void keySaveAs() {
    if (!fileOpen) {
        return;
    }
    JFileChooser d = MainPanel.resetFileChooser();
    d.setDialogTitle("Save KEY File");
    d.setAcceptAllFileFilterUsed(false);
    if (currentKeyFile != null) {
        d.setCurrentDirectory(currentKeyFile.getParentFile());
        d.setSelectedFile(currentKeyFile);
    }
    d.setFileFilter(new KeyFileFilter());
    int result = d.showSaveDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
        currentKeyFile = d.getSelectedFile();
        keySave(currentKeyFile);
    }
}

From source file:net.lmxm.ute.gui.MainFrame.java

/**
 * Action open file./* ww  w. jav a2 s .c  o  m*/
 */
private void actionOpenFile() {
    final String prefix = "actionOpenFile() :";

    final JFileChooser fcOpen = new JFileChooser(getCurrentDirectory());

    fcOpen.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fcOpen.setFileFilter(getFileFilter());

    final int returnVal = fcOpen.showOpenDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File file = fcOpen.getSelectedFile();

        LOGGER.debug("{} opening file {}", prefix, file.getName());

        try {
            configuration = new ConfigurationReader(file).read();

            loadAndValidatePreferences(file);

            userPreferences.setLastFileEditedPath(file.getAbsolutePath());

            refreshJobsTree();
            updateTitle();
            getJobDetailsEditorScrollPane().setViewportView(null);
        } catch (final Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    } else {
        LOGGER.debug("{} cancelled by user", prefix);
    }
}