Example usage for javax.swing JFileChooser JFileChooser

List of usage examples for javax.swing JFileChooser JFileChooser

Introduction

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

Prototype

public JFileChooser(FileSystemView fsv) 

Source Link

Document

Constructs a JFileChooser using the given FileSystemView.

Usage

From source file:TextFileHandler.java

public File openDirectory(String title) {
    File result = null;/* w ww. j ava 2s  .c o  m*/
    JFileChooser chooser = new JFileChooser(new File("."));
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (title != null)
        chooser.setDialogTitle(title);
    int retVal = chooser.showOpenDialog(null);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        result = chooser.getSelectedFile();
    }
    return result;
}

From source file:net.sf.jabref.openoffice.AutoDetectPaths.java

private boolean autoDetectPaths() {

    if (OS.WINDOWS) {
        List<File> progFiles = findProgramFilesDir();
        File sOffice = null;/*from w w  w. ja  v a2s  .c  om*/
        List<File> sofficeFiles = new ArrayList<>();
        for (File dir : progFiles) {
            if (fileSearchCancelled) {
                return false;
            }
            sOffice = findFileDir(dir, "soffice.exe");
            if (sOffice != null) {
                sofficeFiles.add(sOffice);
            }
        }
        if (sOffice == null) {
            JOptionPane.showMessageDialog(parent, Localization.lang(
                    "Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."),
                    Localization.lang("Could not find OpenOffice/LibreOffice installation"),
                    JOptionPane.INFORMATION_MESSAGE);
            JFileChooser jfc = new JFileChooser(new File("C:\\"));
            jfc.setDialogType(JFileChooser.OPEN_DIALOG);
            jfc.setFileFilter(new javax.swing.filechooser.FileFilter() {

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

                @Override
                public String getDescription() {
                    return Localization.lang("Directories");
                }
            });
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jfc.showOpenDialog(parent);
            if (jfc.getSelectedFile() != null) {
                sOffice = jfc.getSelectedFile();
            }
        }
        if (sOffice == null) {
            return false;
        }

        if (sofficeFiles.size() > 1) {
            // More than one file found
            DefaultListModel<File> mod = new DefaultListModel<>();
            for (File tmpfile : sofficeFiles) {
                mod.addElement(tmpfile);
            }
            JList<File> fileList = new JList<>(mod);
            fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            fileList.setSelectedIndex(0);
            FormBuilder b = FormBuilder.create()
                    .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 4dlu, pref"));
            b.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1);
            b.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3);
            b.add(fileList).xy(1, 5);
            int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                    Localization.lang("Choose OpenOffice/LibreOffice executable"),
                    JOptionPane.OK_CANCEL_OPTION);
            if (answer == JOptionPane.CANCEL_OPTION) {
                return false;
            } else {
                sOffice = fileList.getSelectedValue();
            }

        } else {
            sOffice = sofficeFiles.get(0);
        }
        return setupPreferencesForOO(sOffice.getParentFile(), sOffice, "soffice.exe");
    } else if (OS.OS_X) {
        File rootDir = new File("/Applications");
        File[] files = rootDir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory() && ("OpenOffice.org.app".equals(file.getName())
                        || "LibreOffice.app".equals(file.getName()))) {
                    rootDir = file;
                    break;
                }
            }
        }
        File sOffice = findFileDir(rootDir, SOFFICE_BIN);
        if (fileSearchCancelled) {
            return false;
        }
        if (sOffice == null) {
            return false;
        } else {
            return setupPreferencesForOO(rootDir, sOffice, SOFFICE_BIN);
        }
    } else {
        // Linux:
        String usrRoot = "/usr/lib";
        File inUsr = findFileDir(new File(usrRoot), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if (inUsr == null) {
            inUsr = findFileDir(new File("/usr/lib64"), SOFFICE);
            if (inUsr != null) {
                usrRoot = "/usr/lib64";
            }
        }

        if (fileSearchCancelled) {
            return false;
        }
        File inOpt = findFileDir(new File("/opt"), SOFFICE);
        if (fileSearchCancelled) {
            return false;
        }
        if ((inUsr != null) && (inOpt == null)) {
            return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
        } else if (inOpt != null) {
            if (inUsr == null) {
                return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
            } else { // Found both
                JRadioButton optRB = new JRadioButton(inOpt.getPath(), true);
                JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false);
                ButtonGroup bg = new ButtonGroup();
                bg.add(optRB);
                bg.add(usrRB);
                FormBuilder b = FormBuilder.create()
                        .layout(new FormLayout("left:pref", "pref, 2dlu, pref, 2dlu, pref "));
                b.add(Localization.lang(
                        "Found more than one OpenOffice/LibreOffice executable. Please choose which one to connect to:"))
                        .xy(1, 1);
                b.add(optRB).xy(1, 3);
                b.add(usrRB).xy(1, 5);
                int answer = JOptionPane.showConfirmDialog(null, b.getPanel(),
                        Localization.lang("Choose OpenOffice/LibreOffice executable"),
                        JOptionPane.OK_CANCEL_OPTION);
                if (answer == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (optRB.isSelected()) {
                    return setupPreferencesForOO("/opt", inOpt, SOFFICE_BIN);
                } else {
                    return setupPreferencesForOO(usrRoot, inUsr, SOFFICE_BIN);
                }
            }
        }
    }
    return false;
}

From source file:org.jax.maanova.plot.SaveChartAction.java

/**
 * {@inheritDoc}/*from  w w  w  .  j a v a  2s.c o  m*/
 */
public void actionPerformed(ActionEvent e) {
    JFreeChart myChart = this.chart;
    Dimension mySize = this.size;

    if (myChart == null || mySize == null) {
        LOG.severe("Failed to save graph image because of a null value");
        MessageDialogUtilities.errorLater(Maanova.getInstance().getApplicationFrame(),
                "Internal error: Failed to save graph image.", "Image Save Failed");
    } else {
        // use the remembered starting dir
        MaanovaApplicationConfigurationManager configurationManager = MaanovaApplicationConfigurationManager
                .getInstance();
        JMaanovaApplicationState applicationState = configurationManager.getApplicationState();
        FileType rememberedJaxbImageDir = applicationState.getRecentImageExportDirectory();
        File rememberedImageDir = null;
        if (rememberedJaxbImageDir != null && rememberedJaxbImageDir.getFileName() != null) {
            rememberedImageDir = new File(rememberedJaxbImageDir.getFileName());
        }

        // select the image file to save
        JFileChooser fileChooser = new JFileChooser(rememberedImageDir);
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setApproveButtonText("Save Graph");
        fileChooser.setDialogTitle("Save Graph as Image");
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.addChoosableFileFilter(PngFileFilter.getInstance());
        fileChooser.setFileFilter(PngFileFilter.getInstance());
        int response = fileChooser.showSaveDialog(Maanova.getInstance().getApplicationFrame());
        if (response == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();

            // tack on the extension if there isn't one
            // already
            if (!PngFileFilter.getInstance().accept(selectedFile)) {
                String newFileName = selectedFile.getName() + "." + PngFileFilter.PNG_EXTENSION;
                selectedFile = new File(selectedFile.getParentFile(), newFileName);
            }

            if (selectedFile.exists()) {
                // ask the user if they're sure they want to overwrite
                String message = "Exporting the graph image to " + selectedFile.getAbsolutePath()
                        + " will overwrite an " + " existing file. Would you like to continue anyway?";
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine(message);
                }

                boolean overwriteOk = MessageDialogUtilities
                        .confirmOverwrite(Maanova.getInstance().getApplicationFrame(), selectedFile);
                if (!overwriteOk) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("overwrite canceled");
                    }
                    return;
                }
            }

            try {
                ChartUtilities.saveChartAsPNG(selectedFile, myChart, mySize.width, mySize.height);

                File parentDir = selectedFile.getParentFile();
                if (parentDir != null) {
                    // update the "recent image directory"
                    ObjectFactory objectFactory = new ObjectFactory();
                    FileType latestJaxbImageDir = objectFactory.createFileType();
                    latestJaxbImageDir.setFileName(parentDir.getAbsolutePath());
                    applicationState.setRecentImageExportDirectory(latestJaxbImageDir);
                }
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, "failed to save graph image", ex);
            }
        }
    }
}

From source file:com.adito.upgrade.GUIUpgrader.java

public GUIUpgrader() {
    super(new BorderLayout());
    JPanel info = new JPanel(new BorderLayout(2, 2));

    //        info.setBackground(Color.white);
    //        info.setForeground(Color.black);
    //        info.setOpaque(true);
    info.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    JLabel l = new JLabel("<html><p>This utility upgrades configuration from "
            + "one version 0.1.16 installation to another "
            + "0.2.5+ installation. You may choose which resources you "
            + "wish to be copied. If resources with the same name already " + "exist they will be left as is.");
    l.setIcon(new ImageIcon(GUIUpgrader.class.getResource("upgrader-48x48.png")));
    info.add(l, BorderLayout.CENTER);
    info.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);
    mainPanel = new JPanel(new BorderLayout());
    add(info, BorderLayout.NORTH);
    add(mainPanel, BorderLayout.CENTER);

    // Installations panel
    JPanel installations = new JPanel(new GridBagLayout());
    installations.setBorder(BorderFactory.createTitledBorder("Installations"));
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbc.weightx = 2.0;/*from  w w w  . j a  v a 2 s. c  o  m*/
    UIUtil.jGridBagAdd(installations, new JLabel("Source"), gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 1.0;
    source = new JTextField();
    source.getDocument().addDocumentListener(this);
    UIUtil.jGridBagAdd(installations, source, gbc, GridBagConstraints.RELATIVE);
    browseSource = new JButton("Browse");
    browseSource.setMnemonic('b');
    browseSource.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(source.getText());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogTitle("Select source installation directory (0.16.1)");
            if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) {
                source.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    gbc.weightx = 0.0;
    UIUtil.jGridBagAdd(installations, browseSource, gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 2.0;
    UIUtil.jGridBagAdd(installations, new JLabel("Target"), gbc, GridBagConstraints.REMAINDER);
    gbc.weightx = 1.0;
    target = new JTextField(System.getProperty("user.dir"));
    target.getDocument().addDocumentListener(this);
    UIUtil.jGridBagAdd(installations, target, gbc, GridBagConstraints.RELATIVE);
    browseTarget = new JButton("Browse");
    browseTarget.setMnemonic('r');
    browseTarget.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser(target.getText());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogTitle("Select target installation directory (0.2.5+)");
            if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) {
                target.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    gbc.weightx = 0.0;
    UIUtil.jGridBagAdd(installations, browseTarget, gbc, GridBagConstraints.REMAINDER);
    mainPanel.add(installations, BorderLayout.NORTH);

    // Upgrade selection
    upgradeSelectionPanel = new JPanel();
    upgradeSelectionPanel.setBorder(BorderFactory.createTitledBorder("Upgrades"));
    upgradeSelectionPanel.setLayout(new BoxLayout(upgradeSelectionPanel, BoxLayout.Y_AXIS));
    mainPanel.add(upgradeSelectionPanel, BorderLayout.CENTER);

}

From source file:kihira.tails.client.gui.GuiExport.java

@Override
protected void actionPerformed(GuiButton button) {
    //Export to file
    if (button.id == 0 || button.id == 1 || button.id == 2) {
        AbstractClientPlayer player = this.mc.thePlayer;
        File file;//  w  w  w  .  ja  v a2s  .  c  o m

        this.exportMessage = "";
        this.exportLoc = null;
        if (button.id == 0)
            file = new File(System.getProperty("user.home"));
        else if (button.id == 1)
            file = new File(System.getProperty("user.dir"));
        else {
            JFileChooser fileChooser = new JFileChooser(new File(System.getProperty("user.dir")));
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            if (fileChooser.showSaveDialog(Display.getParent()) == JFileChooser.APPROVE_OPTION) {
                file = fileChooser.getSelectedFile();
            } else
                return;
        }

        if (file.exists() && file.canWrite()) {
            this.exportLoc = file.toURI();
            file = new File(file, File.separatorChar + player.getCommandSenderName() + ".png");

            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    setExportMessage(
                            EnumChatFormatting.DARK_RED + String.format("Failed to create skin file! %s", e));
                    e.printStackTrace();
                }
            }

            BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, player);
            if (image != null) {
                try {
                    ImageIO.write(image, "png", file);
                } catch (IOException e) {
                    setExportMessage(
                            EnumChatFormatting.DARK_RED + String.format("Failed to save skin file! %s", e));
                    e.printStackTrace();
                }
            } else {
                setExportMessage(
                        EnumChatFormatting.DARK_RED + String.format("Failed to export skin, image was null!"));
                file.delete();
            }
        }

        if (Strings.isNullOrEmpty(this.exportMessage)) {
            savePartsData();
            this.openFolderButton.visible = true;
            setExportMessage(EnumChatFormatting.GREEN + I18n.format("tails.export.success", file));
        }
    }
    if (button.id == 3 && this.exportLoc != null) {
        try {
            Desktop.getDesktop().browse(this.exportLoc);
        } catch (IOException e) {
            setExportMessage(
                    EnumChatFormatting.DARK_RED + String.format("Failed to open export location: %s", e));
            e.printStackTrace();
        }
    }

    //Upload
    if (button.id == 10) {
        final BufferedImage image = TextureHelper.writePartsDataToSkin(this.partsData, this.mc.thePlayer);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                exportMessage = I18n.format("tails.uploading");
                new ImgurUpload().uploadImage(image);
            }
        };
        runnable.run();
    }
}

From source file:net.pandoragames.far.ui.swing.menu.FileMenu.java

private void init(final Localizer localizer, final ComponentRepository componentRepository) {
    //   Import/*from  www  .j a  va 2 s .  c om*/
    JMenuItem importMenu = new JMenuItem(localizer.localize("label.import"));
    importMenu.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser(config.getFileListExportDirectory());
            fileChooser.setDialogTitle(localizer.localize("label.select-import-file"));
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int returnVal = fileChooser.showOpenDialog(FileMenu.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                Runnable fileImporter = new ImportAction(fileChooser.getSelectedFile(), localizer,
                        componentRepository.getOperationCallBackListener(), config.isWindows());
                Thread thread = new Thread(fileImporter);
                thread.setDaemon(true);
                thread.start();
            }
        }
    });
    this.add(importMenu);
    //   Export
    export = new JMenuItem(localizer.localize("label.export"));
    export.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ExportFileListDialog dialog = new ExportFileListDialog(mainFrame, tableModel, config);
            dialog.pack();
            dialog.setVisible(true);
        }
    });
    this.add(export);
    // seperator 
    this.addSeparator();
    //   Edit
    edit = new JMenuItem(localizer.localize("label.edit"));
    edit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileEditor editor = new FileEditor(mainFrame, tableModel.getSelectedRows().get(0), config);
            editor.pack();
            editor.setVisible(true);
        }
    });
    this.add(edit);
    //   View
    JMenuItem view = new JMenuItem(viewAction);
    this.add(view);
    //   Preview
    JMenuItem preview = new JMenuItem(previewAction);
    this.add(preview);
    //   Info
    info = new JMenuItem(localizer.localize("label.info"));
    info.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            InfoView infoView = new InfoView(mainFrame, tableModel.getSelectedRows().get(0), config,
                    repository);
            infoView.pack();
            infoView.setVisible(true);
        }
    });
    this.add(info);
    // seperator 
    this.addSeparator();
    // copy
    copy = new JMenuItem(localizer.localize("menu.copy"));
    copy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileOperationDialog.copyDialog(tableModel, findForm, errorSink, config, mainFrame);
        }
    });
    this.add(copy);
    // tree copy
    treeCopy = new JMenuItem(localizer.localize("menu.treeCopy"));
    treeCopy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileOperationDialog.treeCopyDialog(tableModel, findForm, errorSink, config, mainFrame);
        }
    });
    this.add(treeCopy);
    // move
    move = new JMenuItem(localizer.localize("menu.move"));
    move.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileOperationDialog.moveDialog(tableModel, findForm, errorSink, config, mainFrame);
        }
    });
    this.add(move);
    // delete
    delete = new JMenuItem(localizer.localize("menu.delete"));
    delete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileOperationDialog.deleteDialog(tableModel, findForm.getBaseDirectory(), errorSink, config,
                    mainFrame);
        }
    });
    this.add(delete);
    // rename
    rename = new JMenuItem(localizer.localize("menu.rename-dialog"));
    rename.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int rowIndex = tableModel.getRowIndex(tableModel.getSelectedRows().get(0));
            FileOperationDialog.renameDialog(rowIndex, tableModel, findForm, errorSink, config, mainFrame);
        }
    });
    this.add(rename);
}

From source file:coreferenceresolver.gui.MarkupGUI.java

public MarkupGUI() throws IOException {
    highlightPainters = new ArrayList<>();

    for (int i = 0; i < COLORS.length; ++i) {
        DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(
                COLORS[i]);//from w  ww .jav a 2s.c  o  m
        highlightPainters.add(highlightPainter);
    }

    defaulPath = FileUtils.readFileToString(new File(".\\src\\coreferenceresolver\\gui\\defaultpath"));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new BorderLayout());
    this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());

    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    //create menu items
    JMenuItem importMenuItem = new JMenuItem("Import");

    JMenuItem exportMenuItem = new JMenuItem("Export");

    fileMenu.add(importMenuItem);
    fileMenu.add(exportMenuItem);

    menuBar.add(fileMenu);

    this.setJMenuBar(menuBar);

    ScrollablePanel mainPanel = new ScrollablePanel();
    mainPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.NONE);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    //IMPORT BUTTON
    importMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //                MarkupGUI.reviewElements.clear();
            //                MarkupGUI.markupReviews.clear();                
            JFileChooser markupFileChooser = new JFileChooser(defaulPath);
            markupFileChooser.setDialogTitle("Choose your markup file");
            markupFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

            if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                final JDialog d = new JDialog();
                JPanel p1 = new JPanel(new GridBagLayout());
                p1.add(new JLabel("Please Wait..."), new GridBagConstraints());
                d.getContentPane().add(p1);
                d.setSize(100, 100);
                d.setLocationRelativeTo(null);
                d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                d.setModal(true);

                SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() {
                    protected Void doInBackground() throws IOException, BadLocationException {
                        readMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath());
                        for (int i = 0; i < markupReviews.size(); ++i) {
                            mainPanel.add(newReviewPanel(markupReviews.get(i), i));
                        }
                        return null;
                    }

                    protected void done() {
                        MarkupGUI.this.revalidate();
                        d.dispose();
                    }
                };
                worker.execute();
                d.setVisible(true);
            } else {
                return;
            }
        }
    });

    //EXPORT BUTTON: GET NEW VALUE (REF, TYPE) OF NPs      
    exportMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser markupFileChooser = new JFileChooser(defaulPath);
            markupFileChooser.setDialogTitle("Choose where your markup file saved");
            markupFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                final JDialog d = new JDialog();
                JPanel p1 = new JPanel(new GridBagLayout());
                p1.add(new JLabel("Please Wait..."), new GridBagConstraints());
                d.getContentPane().add(p1);
                d.setSize(100, 100);
                d.setLocationRelativeTo(null);
                d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                d.setModal(true);

                SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() {
                    protected Void doInBackground() throws IOException {
                        for (Review review : markupReviews) {
                            generateNPsRef(review);
                        }
                        int i = 0;
                        for (ReviewElement reviewElement : reviewElements) {
                            int j = 0;
                            for (Element element : reviewElement.elements) {
                                String newType = element.typeSpinner.getValue().toString();
                                if (newType.equals("Object")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(0);
                                } else if (newType.equals("Attribute")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(3);
                                } else if (newType.equals("Other")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(1);
                                } else if (newType.equals("Candidate")) {
                                    markupReviews.get(i).getNounPhrases().get(j).setType(2);
                                }
                                ++j;
                            }
                            ++i;
                        }
                        initMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath() + File.separator
                                + "markup.out.txt");
                        return null;
                    }

                    protected void done() {
                        d.dispose();
                        try {
                            Desktop.getDesktop()
                                    .open(new File(markupFileChooser.getSelectedFile().getAbsolutePath()));
                        } catch (IOException ex) {
                            Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                };
                worker.execute();
                d.setVisible(true);
            } else {
                return;
            }
        }
    });

    JScrollPane scrollMainPane = new JScrollPane(mainPanel);
    scrollMainPane.getVerticalScrollBar().setUnitIncrement(16);
    scrollMainPane.setPreferredSize(new Dimension(this.getWidth(), this.getHeight()));
    scrollMainPane.setSize(this.getWidth(), this.getHeight());
    this.setResizable(false);
    this.add(scrollMainPane, BorderLayout.CENTER);
    this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    this.pack();
}

From source file:net.sf.clichart.main.ChartFrame.java

private void saveChart() {
    JFileChooser chooser = new JFileChooser(".");
    chooser.addChoosableFileFilter(new ExtensionFileFilter(".jpg", "JPEG files"));
    chooser.addChoosableFileFilter(new ExtensionFileFilter(".png", "PNG files"));

    if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File outputFile = chooser.getSelectedFile();

        if (outputFile.exists()) {
            int result = JOptionPane.showConfirmDialog(this, "File exists - overwrite?", "File exists",
                    JOptionPane.OK_CANCEL_OPTION);
            if (result != JOptionPane.OK_OPTION) {
                return;
            }/*from   w  w w .  ja  va2s .com*/
        }

        System.err.println("Saving chart to " + outputFile.getPath());
        try {
            new ChartSaver(m_chart, m_initialWidth, m_initialHeight).saveChart(outputFile);
        } catch (ChartSaverException e) {
            JOptionPane.showMessageDialog(this, "Failed to save chart: " + e.getMessage());
        }
    }
}

From source file:com.naval.gui.Gui.java

private void creerPartie() {
    final JFileChooser fc = new JFileChooser(Config.getRepTravail());

    fc.addChoosableFileFilter(new GameFileFilter("gm", "Description de partie"));
    fc.setAcceptAllFileFilterUsed(false);

    int returnVal = fc.showOpenDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        // TODO : load only if game is !=

        try {// w  ww.j  av a  2  s  .c  o m
            FileReader fr = new FileReader(file);
            partie = Partie.creer(fr);
            partie.save();
            hintBar.setText("Partie " + partie.nom + " cre avec succes");
        } catch (FileNotFoundException e) {
            hintBar.setText(e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            hintBar.setText(e.getMessage());
            e.printStackTrace();
        }
    }
}

From source file:com.original.widget.OPicture.java

/**
 * very simple method to select an image file.
 * Please be advised that we will create our own file chooser in the
 * near future. Since in our system, people will be not encouraged to
 * access the physical file./*from  ww  w.jav  a 2 s  .c  o m*/
 *
 * Of course, we need to discuss how to handle this issue.
 * @return
 */

private File chooseImgFile() {
    JFileChooser chooser = new JFileChooser(".");
    FileFilter imgType = new OriExtFileFilter("Image files", new String[] { ".jpg", ".gif", ".jpeg", ".png" });
    chooser.addChoosableFileFilter(imgType);
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(imgType);
    int status = chooser.showOpenDialog(null);
    if (status == JFileChooser.APPROVE_OPTION) {
        File f = chooser.getSelectedFile();
        return f;
    }
    return null;
}