Example usage for javax.swing JFileChooser OPEN_DIALOG

List of usage examples for javax.swing JFileChooser OPEN_DIALOG

Introduction

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

Prototype

int OPEN_DIALOG

To view the source code for javax.swing JFileChooser OPEN_DIALOG.

Click Source Link

Document

Type value indicating that the JFileChooser supports an "Open" file operation.

Usage

From source file:net.sf.firemox.tools.MToolKit.java

/**
 * Return the deck file chosen with an "open" dialog.
 * //from   w  w  w . j a va  2 s  .co m
 * @return the file chosen, or the previous one if canceled.
 */
public static String getDeckFile() {
    return getDeckFile(JFileChooser.OPEN_DIALOG);
}

From source file:net.sf.firemox.tools.MToolKit.java

/**
 * Open a DialogFile dialog and return the chosen MDB file.
 * /*w  ww.  j a v a2  s  .c o m*/
 * @param oldFile
 *          the old MDB file, will be returned if user cancel operation
 * @param parent
 *          is parent of this dialog
 * @return the file chosen, or oldFile if canceled
 */
public static String getMdbFile(String oldFile, JFrame parent) {
    try {
        return showDialogFile("choose your mdb file", 'o', oldFile == null ? null : MToolKit.getFile(oldFile),
                mdbFilter, parent, JFileChooser.OPEN_DIALOG).getCanonicalPath();
    } catch (java.io.IOException e) {
        javax.swing.JOptionPane.showMessageDialog(parent, "Error occurred reading the specified file",
                "File problem", JOptionPane.ERROR_MESSAGE);
        return oldFile;
    } catch (Exception e) {
        // cancel of user;
        return null;
    }
}

From source file:com.g2inc.scap.editor.gui.windows.EditorMainWindow.java

private void initFilemenu() {
    final EditorMainWindow parentWinRef = this;

    exitMenuItem.addActionListener(new ActionListener() {
        @Override//from  w  w  w .ja  v  a2 s .c o  m
        public void actionPerformed(ActionEvent e) {
            parentWinRef.dispose();
        }
    });

    openOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            final JFileChooser fc = new JFileChooser();
            fc.setDialogType(JFileChooser.OPEN_DIALOG);

            File lastOpenedFrom = guiProps.getLastOpenedFromFile();

            // Set current directory
            fc.setCurrentDirectory(lastOpenedFrom);

            FileFilter ff = new OcilOrOvalFilesFilter("OVAL");
            fc.setFileFilter(ff);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

            int ret = fc.showOpenDialog(EditorMainWindow.getInstance());

            if (ret == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                File parent = f.getAbsoluteFile().getParentFile();
                guiProps.setLastOpenedFrom(parent.getAbsolutePath());
                guiProps.save();

                openFile(f, SCAPDocumentClassEnum.OVAL);
            }
        }
    });

    saveMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            // get the currently open window
            JInternalFrame selectedWin = desktopPane.getSelectedFrame();

            if (selectedWin != null) {
                SCAPDocument scapDoc = null;

                Document dom = null;
                String filename = null;

                if (selectedWin instanceof OvalEditorForm) {
                    OvalEditorForm oef = (OvalEditorForm) selectedWin;
                    scapDoc = oef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else if (selectedWin instanceof CPEDictionaryEditorForm) {
                    CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin;
                    scapDoc = cef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                }

                if (dom != null) {
                    // since this is a save operation, not save as, we won't
                    // prompt the user for where to store the file

                    try {
                        scapDoc.save();
                        ((EditorForm) selectedWin).setDirty(false);
                    } catch (Exception e) {
                        String message = "An error occured trying to save to file " + filename + ": "
                                + e.getMessage();
                        EditorUtil.showMessageDialog(parentWinRef, message,
                                EditorMessages.SAVE_ERROR_DIALOG_TITLE, JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        }
    });

    saveAsMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            // get the currently open window
            JInternalFrame selectedWin = desktopPane.getSelectedFrame();

            if (selectedWin != null) {
                SCAPDocument scapDoc = null;
                Document dom = null;
                String filename = null;
                String windowTitle = null;

                if (selectedWin instanceof OvalEditorForm) {
                    windowTitle = OvalEditorForm.WINDOW_TITLE_BASE;
                    OvalEditorForm oef = (OvalEditorForm) selectedWin;
                    scapDoc = oef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else if (selectedWin instanceof CPEDictionaryEditorForm) {
                    windowTitle = CPEDictionaryEditorForm.WINDOW_TITLE_BASE;
                    CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin;
                    scapDoc = cef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else {
                    return;
                }

                if (dom != null) {
                    String newFilename = null;
                    SCAPDocumentTypeEnum docType = scapDoc.getDocumentType();

                    FileSaveAsWizard saveAsWiz = new FileSaveAsWizard(EditorMainWindow.getInstance(), true,
                            docType);

                    //saveAsWiz.pack();
                    saveAsWiz.setLocationRelativeTo(EditorMainWindow.getInstance());
                    saveAsWiz.setVisible(true);

                    if (saveAsWiz.wasCancelled()) {
                        return;
                    }

                    newFilename = saveAsWiz.getFilename();

                    try {
                        scapDoc.setFilename(newFilename);
                        scapDoc.saveAs(newFilename);

                        EditorUtil.markActiveWindowDirty(EditorMainWindow.getInstance(), false);
                        ((EditorForm) selectedWin).refreshRootNode();

                    } catch (Exception e) {
                        LOG.error(e.getMessage(), e);

                        EditorUtil.showMessageDialog(parentWinRef, "An error occured trying to save to file "
                                + newFilename + ": " + e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                    SCAPContentManager scm = SCAPContentManager.getInstance();

                    if (scm != null) {
                        scm.removeDocument(filename);
                        scm.addDocument(newFilename, scapDoc);
                        selectedWin.setTitle(windowTitle + (new File(newFilename)).getAbsolutePath());
                    } else {
                        LOG.error("SCM instance is null here!");
                    }
                }
            }
        }
    });

    newXCCDFFromOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            //generateXccdfFromOvalOrOcil("OVAL");
            final JFileChooser fc = new JFileChooser();
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
            File lastOpenedFrom = guiProps.getLastOpenedFromFile();

            // Set current directory
            fc.setCurrentDirectory(lastOpenedFrom);
            FileFilter ff = new OcilOrOvalFilesFilter("OVAL");
            fc.setFileFilter(ff);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int ret = fc.showOpenDialog(EditorMainWindow.getInstance());
            if (ret == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                File parent = f.getAbsoluteFile().getParentFile();
                guiProps.setLastOpenedFrom(parent.getAbsolutePath());
                guiProps.save();
                try {
                    InputStream is = this.getClass().getClassLoader().getResourceAsStream("oval-to-xccdf.xsl");
                    File xsltfile = new File("oval-to-xccdf.xsl");
                    OutputStream outputStream = new FileOutputStream(xsltfile);
                    IOUtils.copy(is, outputStream);
                    outputStream.close();
                    OvalToXCCDF1.ovalToXccdf(f, xsltfile);
                    xsltfile.delete();
                    String reverseDNS = JOptionPane.showInputDialog("reverse_DNS:");
                    if (reverseDNS == null || reverseDNS.length() == 0) {
                        JOptionPane.showMessageDialog(null, "Enter the reverse_DNS", "alert",
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        JFileChooser fc1 = new JFileChooser();
                        fc1.setCurrentDirectory(f);
                        int ret1 = fc1.showSaveDialog(EditorMainWindow.getInstance());
                        if (ret1 == JFileChooser.APPROVE_OPTION) {
                            File savefile = fc1.getSelectedFile();
                            is = this.getClass().getClassLoader().getResourceAsStream("xccdf_1.1_to_1.2.xsl");
                            xsltfile = new File("oval-to-xccdf.xsl");
                            outputStream = new FileOutputStream(xsltfile);
                            IOUtils.copy(is, outputStream);
                            outputStream.close();
                            File temp = new File("temp.xml");
                            XCCDF1to2.xccdf12(savefile, reverseDNS, xsltfile, temp);
                            JOptionPane.showMessageDialog(null,
                                    "XCCDF File Created: " + savefile.getAbsolutePath(), "XCCDF Created",
                                    JOptionPane.PLAIN_MESSAGE);
                            xsltfile.delete();
                            temp.delete();
                            temp = null;
                        }

                    }

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (TransformerException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //  openFile(f, SCAPDocumentClassEnum.OVAL);
            }

        }

    });

    newOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            CreateOvalWizard wiz = new CreateOvalWizard(true);
            wiz.setName("create_oval_wizard");
            wiz.pack();
            wiz.setVisible(true);

            if (!wiz.wasCancelled()) {
                // User has been through the wizard to select
                // 1. an Oval schema version (eg, OVAL55)
                // 2. one or more platforms (eg, "windows", "solaris", etc)
                // 3. a file name for the new Oval file
                // Now we are ready to actually create the file
                String createdFilename = createNewOvalDocument(wiz);

                if (createdFilename == null) {
                    LOG.error("newOvalMenuItem.actionlistener: Created filename was null!");
                    return;
                }

                File f = new File(createdFilename);

                guiProps.setLastOpenedFromFile(f.getParentFile());
                guiProps.save();

                SCAPContentManager scm = SCAPContentManager.getInstance();

                if (scm != null) {
                    OvalDefinitionsDocument dd = (OvalDefinitionsDocument) scm.getDocument(f.getAbsolutePath());

                    openFile(dd);
                }
            }
            wiz.setVisible(false);
            wiz.dispose();
        }
    });

    /* wizModeMenuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        WizardModeWindow wizModeWin = new WizardModeWindow();
            
        EditorMainWindow emw = EditorMainWindow.getInstance();
        JDesktopPane emwDesktopPane = emw.getDesktopPane();
            
        wizModeWin.setTitle("Wizard Mode");
        wizModeWin.pack();
            
        wizModeWin.addInternalFrameListener(new WeakInternalFrameListener(EditorMainWindow.getInstance()));
            
        Dimension dpDim = emwDesktopPane.getSize();
        int x = (dpDim.width - wizModeWin.getWidth()) / 2;
        int y = (dpDim.height - wizModeWin.getHeight()) / 2;
            
        wizModeWin.setLocation(x, y);
        emwDesktopPane.add(wizModeWin);
        wizModeWin.setVisible(true);
            
        setWizMode(true);
    }
     });*/

    ugMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                InputStream resource = this.getClass().getResourceAsStream("/User_Guide.pdf");
                try {
                    File userGuideFile = File.createTempFile("UserGuide", ".pdf");
                    userGuideFile.deleteOnExit();
                    OutputStream out = new FileOutputStream(userGuideFile);
                    try {
                        // copy contents from resource to out
                        IOUtils.copy(resource, out);
                    } catch (IOException ex) {
                        JOptionPane.showMessageDialog(null, "Couldn't copy between streams.");
                    } finally {
                        out.close();
                    }
                    desktop.open(userGuideFile);
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(null, "Could not call Open on desktop object.");
                } finally {
                    try {
                        if (resource != null) {
                            resource.close();
                        }
                    } catch (IOException ex) {
                        LOG.error("Error displaying user guide", ex);
                        JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide.");
                    }
                }
            } else {
                JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide.");
            }
        }
    });

}

From source file:net.sf.firemox.tools.MToolKit.java

/**
 * return the picture file chosen/* ww w.  j  ava  2  s. com*/
 * 
 * @param oldFile
 *          the old picture, will be returned if user cancel operation
 * @param parent
 *          is parent of this dialog
 * @return the picture file chosen, or oldFile if canceled
 */
public static String getPictureFile(String oldFile, JFrame parent) {
    try {
        return showDialogFile("choose your a picture", 'o', null, pictureFilter, parent,
                JFileChooser.OPEN_DIALOG).getCanonicalPath();
    } catch (java.io.IOException e) {
        throw new InternalError("choosing picture file");
    } catch (Exception e) {
        // cancel of user;
        return null;
    }
}

From source file:cl.uai.webcursos.emarking.desktop.OptionsDialog.java

/**
 * Create the dialog.//from www  .j  av a 2s.com
 */
public OptionsDialog(Moodle _moodle) {
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            cancelled = true;
        }
    });
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    setIconImage(Toolkit.getDefaultToolkit().getImage(OptionsDialog.class
            .getResource("/cl/uai/webcursos/emarking/desktop/resources/glyphicons_439_wrench.png")));
    setTitle(EmarkingDesktop.lang.getString("emarkingoptions"));
    setModal(true);
    setBounds(100, 100, 707, 444);
    this.moodle = _moodle;
    this.moodle.loadProperties();
    getContentPane().setLayout(new BorderLayout());
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            okButton = new JButton(EmarkingDesktop.lang.getString("ok"));
            okButton.setEnabled(false);
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
                        if (!validator.isValid(moodleurl.getText())) {
                            throw new Exception(EmarkingDesktop.lang.getString("invalidmoodleurl") + " "
                                    + moodleurl.getText());
                        }
                        File f = new File(filename.getText());
                        if (!f.exists() || f.isDirectory()
                                || (!f.getPath().endsWith(".pdf") && !f.getPath().endsWith(".zip"))) {
                            throw new Exception(EmarkingDesktop.lang.getString("invalidpdffile") + " "
                                    + filename.getText());
                        }
                        if (omrtemplate.getText().trim().length() > 0) {
                            File omrf = new File(omrtemplate.getText());
                            if (!omrf.exists() || omrf.isDirectory() || (!omrf.getPath().endsWith(".xtmpl"))) {
                                throw new Exception(EmarkingDesktop.lang.getString("invalidomrfile") + " "
                                        + omrtemplate.getText());
                            }
                        }
                        moodle.setLastfile(filename.getText());
                        moodle.getQrExtractor().setDoubleside(chckbxDoubleSide.isSelected());
                        moodle.setMaxthreads(Integer.parseInt(getMaxThreads().getSelectedItem().toString()));
                        moodle.setResolution(Integer.parseInt(getResolution().getSelectedItem().toString()));
                        moodle.setMaxzipsize(getMaxZipSize().getSelectedItem().toString());
                        moodle.setOMRTemplate(omrtemplate.getText());
                        moodle.setThreshold(Integer.parseInt(spinnerOMRthreshold.getValue().toString()));
                        moodle.setDensity(Integer.parseInt(spinnerOMRdensity.getValue().toString()));
                        moodle.setShapeSize(Integer.parseInt(spinnerOMRshapeSize.getValue().toString()));
                        moodle.setAnonymousPercentage(
                                Integer.parseInt(spinnerAnonymousPercentage.getValue().toString()));
                        moodle.setAnonymousPercentageCustomPage(
                                Integer.parseInt(spinnerAnonymousPercentageCustomPage.getValue().toString()));
                        moodle.setFakeStudents(chckbxMarkersTraining.isSelected());
                        moodle.saveProperties();
                        cancelled = false;
                        setVisible(false);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(panel,
                                EmarkingDesktop.lang.getString("invaliddatainform"));
                    }
                }
            });
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton(EmarkingDesktop.lang.getString("cancel"));
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    cancelled = true;
                    setVisible(false);
                }
            });
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    getContentPane().add(tabbedPane, BorderLayout.CENTER);

    panel = new JPanel();
    tabbedPane.addTab(EmarkingDesktop.lang.getString("general"), null, panel, null);
    panel.setLayout(null);

    JPanel panel_2 = new JPanel();
    panel_2.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_2.setBounds(10, 11, 665, 131);
    panel.add(panel_2);
    panel_2.setLayout(null);

    JLabel lblPassword = new JLabel(EmarkingDesktop.lang.getString("password"));
    lblPassword.setBounds(10, 99, 109, 14);
    panel_2.add(lblPassword);
    lblPassword.setHorizontalAlignment(SwingConstants.RIGHT);

    password = new JPasswordField();
    password.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            testConnection();
        }
    });
    password.setBounds(129, 96, 329, 20);
    panel_2.add(password);
    this.password.setText(this.moodle.getPassword());

    btnTestConnection = new JButton(EmarkingDesktop.lang.getString("connect"));
    btnTestConnection.setEnabled(false);
    btnTestConnection.setBounds(468, 93, 172, 27);
    panel_2.add(btnTestConnection);

    username = new JTextField();
    username.setBounds(129, 65, 329, 20);
    panel_2.add(username);
    username.setColumns(10);
    this.username.setText(this.moodle.getUsername());

    moodleurl = new JTextField();
    moodleurl.setBounds(129, 34, 329, 20);
    panel_2.add(moodleurl);
    moodleurl.setColumns(10);
    moodleurl.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            warn();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            warn();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            warn();
        }

        private void warn() {
            UrlValidator validator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
            if (!validator.isValid(moodleurl.getText()) || !moodleurl.getText().endsWith("/")) {
                moodleurl.setForeground(Color.RED);
                btnTestConnection.setEnabled(false);
            } else {
                moodleurl.setForeground(Color.BLACK);
                btnTestConnection.setEnabled(true);
            }
        }
    });

    // Initializing values from moodle configuration
    this.moodleurl.setText(this.moodle.getUrl());

    JLabel lblMoodleUrl = new JLabel(EmarkingDesktop.lang.getString("moodleurl"));
    lblMoodleUrl.setBounds(10, 37, 109, 14);
    panel_2.add(lblMoodleUrl);
    lblMoodleUrl.setHorizontalAlignment(SwingConstants.RIGHT);

    JLabel lblUsername = new JLabel(EmarkingDesktop.lang.getString("username"));
    lblUsername.setBounds(10, 68, 109, 14);
    panel_2.add(lblUsername);
    lblUsername.setHorizontalAlignment(SwingConstants.RIGHT);

    JLabel lblMoodleSettings = new JLabel(EmarkingDesktop.lang.getString("moodlesettings"));
    lblMoodleSettings.setBounds(10, 11, 230, 14);
    panel_2.add(lblMoodleSettings);
    btnTestConnection.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            testConnection();
        }
    });

    JPanel panel_3 = new JPanel();
    panel_3.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_3.setBounds(10, 159, 666, 174);
    panel.add(panel_3);
    panel_3.setLayout(null);

    JLabel lblPdfFile = new JLabel(EmarkingDesktop.lang.getString("pdffile"));
    lblPdfFile.setBounds(0, 39, 119, 14);
    panel_3.add(lblPdfFile);
    lblPdfFile.setHorizontalAlignment(SwingConstants.RIGHT);

    JLabel lblScanned = new JLabel(EmarkingDesktop.lang.getString("scanned"));
    lblScanned.setBounds(0, 64, 119, 14);
    panel_3.add(lblScanned);
    lblScanned.setHorizontalAlignment(SwingConstants.RIGHT);

    chckbxDoubleSide = new JCheckBox(EmarkingDesktop.lang.getString("doubleside"));
    chckbxDoubleSide.setEnabled(false);
    chckbxDoubleSide.setBounds(125, 60, 333, 23);
    panel_3.add(chckbxDoubleSide);
    chckbxDoubleSide.setToolTipText(EmarkingDesktop.lang.getString("doublesidetooltip"));
    this.chckbxDoubleSide.setSelected(this.moodle.getQrExtractor().isDoubleside());

    filename = new JTextField();
    filename.setEnabled(false);
    filename.setBounds(129, 36, 329, 20);
    panel_3.add(filename);
    filename.setColumns(10);
    filename.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            warn();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            warn();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            warn();
        }

        private void warn() {
            validateFileForProcessing(!btnTestConnection.isEnabled());
        }
    });
    this.filename.setText(this.moodle.getLastfile());

    btnOpenPdfFile = new JButton(EmarkingDesktop.lang.getString("openfile"));
    btnOpenPdfFile.setEnabled(false);
    btnOpenPdfFile.setBounds(468, 33, 172, 27);
    panel_3.add(btnOpenPdfFile);

    JLabel lblPdfFileSettings = new JLabel(EmarkingDesktop.lang.getString("filesettings"));
    lblPdfFileSettings.setBounds(10, 11, 230, 14);
    panel_3.add(lblPdfFileSettings);

    JLabel lblOMRtemplate = new JLabel(EmarkingDesktop.lang.getString("omrfile"));
    lblOMRtemplate.setHorizontalAlignment(SwingConstants.RIGHT);
    lblOMRtemplate.setBounds(0, 142, 119, 14);
    panel_3.add(lblOMRtemplate);

    omrtemplate = new JTextField();
    omrtemplate.setEnabled(false);
    omrtemplate.setText((String) null);
    omrtemplate.setColumns(10);
    omrtemplate.setBounds(129, 139, 329, 20);
    panel_3.add(omrtemplate);
    omrtemplate.setText(this.moodle.getOMRTemplate());

    btnOpenOMRTemplate = new JButton(EmarkingDesktop.lang.getString("openomrfile"));
    btnOpenOMRTemplate.setEnabled(false);
    btnOpenOMRTemplate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setDialogTitle(EmarkingDesktop.lang.getString("openfiletitle"));
            chooser.setDialogType(JFileChooser.OPEN_DIALOG);
            chooser.setFileFilter(new FileFilter() {
                @Override
                public String getDescription() {
                    return "*.xtmpl";
                }

                @Override
                public boolean accept(File arg0) {
                    if (arg0.getName().endsWith(".xtmpl") || arg0.isDirectory())
                        return true;
                    return false;
                }
            });
            int retval = chooser.showOpenDialog(panel);
            if (retval == JFileChooser.APPROVE_OPTION) {
                omrtemplate.setText(chooser.getSelectedFile().getAbsolutePath());
            } else {
                return;
            }
        }
    });
    btnOpenOMRTemplate.setBounds(468, 136, 172, 27);
    panel_3.add(btnOpenOMRTemplate);

    lblMarkersTraining = new JLabel((String) EmarkingDesktop.lang.getString("markerstraining"));
    lblMarkersTraining.setHorizontalAlignment(SwingConstants.RIGHT);
    lblMarkersTraining.setBounds(0, 89, 119, 14);
    panel_3.add(lblMarkersTraining);

    chckbxMarkersTraining = new JCheckBox(EmarkingDesktop.lang.getString("markerstrainingfakestudents"));
    chckbxMarkersTraining.setBounds(125, 87, 333, 23);
    panel_3.add(chckbxMarkersTraining);
    btnOpenPdfFile.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            okButton.setEnabled(false);
            JFileChooser chooser = new JFileChooser();
            chooser.setDialogTitle(EmarkingDesktop.lang.getString("openfiletitle"));
            chooser.setDialogType(JFileChooser.OPEN_DIALOG);
            chooser.setFileFilter(new FileFilter() {
                @Override
                public String getDescription() {
                    return "*.pdf, *.zip";
                }

                @Override
                public boolean accept(File arg0) {
                    if (arg0.getName().endsWith(".zip") || arg0.getName().endsWith(".pdf")
                            || arg0.isDirectory())
                        return true;
                    return false;
                }
            });
            int retval = chooser.showOpenDialog(panel);
            if (retval == JFileChooser.APPROVE_OPTION) {
                filename.setText(chooser.getSelectedFile().getAbsolutePath());
                okButton.setEnabled(true);
            } else {
                return;
            }
        }
    });

    JPanel panel_1 = new JPanel();
    tabbedPane.addTab(EmarkingDesktop.lang.getString("advanced"), null, panel_1, null);
    panel_1.setLayout(null);

    JPanel panel_4 = new JPanel();
    panel_4.setLayout(null);
    panel_4.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_4.setBounds(10, 11, 665, 131);
    panel_1.add(panel_4);

    JLabel lblAdvancedOptions = new JLabel(EmarkingDesktop.lang.getString("advancedoptions"));
    lblAdvancedOptions.setBounds(10, 11, 233, 14);
    panel_4.add(lblAdvancedOptions);

    JLabel lblThreads = new JLabel(EmarkingDesktop.lang.getString("maxthreads"));
    lblThreads.setBounds(10, 38, 130, 14);
    panel_4.add(lblThreads);
    lblThreads.setHorizontalAlignment(SwingConstants.RIGHT);

    JLabel lblSomething = new JLabel(EmarkingDesktop.lang.getString("separatezipfiles"));
    lblSomething.setBounds(10, 73, 130, 14);
    panel_4.add(lblSomething);
    lblSomething.setHorizontalAlignment(SwingConstants.RIGHT);

    JLabel label = new JLabel(EmarkingDesktop.lang.getString("resolution"));
    label.setBounds(10, 105, 130, 14);
    panel_4.add(label);
    label.setHorizontalAlignment(SwingConstants.RIGHT);

    resolution = new JComboBox<Integer>();
    resolution.setBounds(150, 99, 169, 27);
    panel_4.add(resolution);
    resolution.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 75, 100, 150, 300, 400, 500, 600 }));
    resolution.setSelectedIndex(2);
    this.resolution.setSelectedItem(this.moodle.getQrExtractor().getResolution());

    maxZipSize = new JComboBox<String>();
    maxZipSize.setBounds(150, 67, 169, 27);
    panel_4.add(maxZipSize);
    maxZipSize.setModel(new DefaultComboBoxModel<String>(new String[] { "<dynamic>", "2Mb", "4Mb", "8Mb",
            "16Mb", "32Mb", "64Mb", "128Mb", "256Mb", "512Mb", "1024Mb" }));
    maxZipSize.setSelectedIndex(6);
    this.maxZipSize.setSelectedItem(this.moodle.getMaxZipSizeString());

    maxThreads = new JComboBox<Integer>();
    maxThreads.setBounds(150, 32, 169, 27);
    panel_4.add(maxThreads);
    maxThreads.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 2, 4, 8, 16 }));
    maxThreads.setSelectedIndex(1);
    this.maxThreads.setSelectedItem(this.moodle.getQrExtractor().getMaxThreads());

    JPanel panel_5 = new JPanel();
    panel_5.setLayout(null);
    panel_5.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_5.setBounds(10, 153, 665, 131);
    panel_1.add(panel_5);

    JLabel lblOMRoptions = new JLabel(EmarkingDesktop.lang.getString("omroptions"));
    lblOMRoptions.setBounds(10, 11, 233, 14);
    panel_5.add(lblOMRoptions);

    JLabel lblOMRthreshold = new JLabel(EmarkingDesktop.lang.getString("omrthreshold"));
    lblOMRthreshold.setHorizontalAlignment(SwingConstants.RIGHT);
    lblOMRthreshold.setBounds(10, 32, 130, 14);
    panel_5.add(lblOMRthreshold);

    JLabel lblShapeSize = new JLabel(EmarkingDesktop.lang.getString("omrshapesize"));
    lblShapeSize.setHorizontalAlignment(SwingConstants.RIGHT);
    lblShapeSize.setBounds(10, 99, 130, 14);
    panel_5.add(lblShapeSize);

    JLabel lblDensity = new JLabel(EmarkingDesktop.lang.getString("omrdensity"));
    lblDensity.setHorizontalAlignment(SwingConstants.RIGHT);
    lblDensity.setBounds(10, 70, 130, 14);
    panel_5.add(lblDensity);

    spinnerOMRthreshold = new JSpinner();
    spinnerOMRthreshold.setBounds(150, 32, 169, 20);
    panel_5.add(spinnerOMRthreshold);
    spinnerOMRthreshold.setValue(this.moodle.getOMRthreshold());

    spinnerOMRdensity = new JSpinner();
    spinnerOMRdensity.setBounds(150, 67, 169, 20);
    panel_5.add(spinnerOMRdensity);
    spinnerOMRdensity.setValue(this.moodle.getOMRdensity());

    spinnerOMRshapeSize = new JSpinner();
    spinnerOMRshapeSize.setBounds(150, 99, 169, 20);
    panel_5.add(spinnerOMRshapeSize);
    spinnerOMRshapeSize.setValue(this.moodle.getOMRshapeSize());

    JLabel lblAnonymousPercentage = new JLabel(
            "<html>" + EmarkingDesktop.lang.getString("anonymouspercentage") + "</html>");
    lblAnonymousPercentage.setHorizontalAlignment(SwingConstants.RIGHT);
    lblAnonymousPercentage.setBounds(329, 32, 130, 27);
    panel_5.add(lblAnonymousPercentage);

    spinnerAnonymousPercentage = new JSpinner();
    spinnerAnonymousPercentage.setBounds(469, 32, 169, 20);
    panel_5.add(spinnerAnonymousPercentage);
    spinnerAnonymousPercentage.setValue(this.moodle.getAnonymousPercentage());

    JLabel lblAnonymousPercentageCustomPage = new JLabel(
            "<html>" + EmarkingDesktop.lang.getString("anonymouspercentagecustompage") + "</html>");
    lblAnonymousPercentageCustomPage.setHorizontalAlignment(SwingConstants.RIGHT);
    lblAnonymousPercentageCustomPage.setBounds(329, 70, 130, 27);
    panel_5.add(lblAnonymousPercentageCustomPage);

    spinnerAnonymousPercentageCustomPage = new JSpinner();
    spinnerAnonymousPercentageCustomPage.setBounds(469, 70, 169, 20);
    panel_5.add(spinnerAnonymousPercentageCustomPage);
    spinnerAnonymousPercentageCustomPage.setValue(this.moodle.getAnonymousPercentageCustomPage());

    JLabel lblCustomPage = new JLabel(
            "<html>" + EmarkingDesktop.lang.getString("anonymouscustompage") + "</html>");
    lblCustomPage.setHorizontalAlignment(SwingConstants.RIGHT);
    lblCustomPage.setBounds(329, 99, 130, 27);
    panel_5.add(lblCustomPage);

    spinnerCustomPage = new JSpinner();
    spinnerCustomPage.setBounds(469, 99, 169, 20);
    panel_5.add(spinnerCustomPage);
    spinnerCustomPage.setValue(this.moodle.getAnonymousCustomPage());
}

From source file:my.swingconnect.SwingConnectUI.java

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

    //To BROWSE A FILE FROM THE DIRECTORY
    JFileChooser chooser = new JFileChooser();
    //To enable showing hidden file
    chooser.setFileHidingEnabled(false);
    //To Enable selecting directory or files
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    //To enable multiple file selections
    chooser.setMultiSelectionEnabled(true);
    //Choice of user to save or open a file
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setDialogTitle("Choose a file...");

    //To user to select a file
    if (chooser.showOpenDialog(SwingConnectUI.this) == JFileChooser.APPROVE_OPTION) {
        targetFile = chooser.getSelectedFile();
        String directory = targetFile.getPath();
        jTextField4.setText(targetFile.toString());

        //                       files = new File("/Users/pradil90/Desktop/207dropbox").listFiles();

        files = new File(directory).listFiles();
        for (File file : files) {
            if (file.isFile()) {
                results.add(file.getAbsolutePath());

                //                           results.add(file.getName());

                System.out.println(file);

                count++;/*from   ww  w . j a  va 2s .  co m*/

                System.out.println(count);

            }

        }

        results.remove(0);
        jButton3.setEnabled(true);

    }
}

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  a  v a2s .  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:net.sf.firemox.DeckBuilder.java

/**
 * Invoked when an action occurs.// w  w  w. jav  a 2 s  .c  o m
 * 
 * @param e
 *          attached event
 */
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if ("menu_help_about".equals(command)) {
        new About(form).setVisible(true);
    } else if ("menu_db_exit".equals(command)) {
        exitForm();
    } else if ("menu_db_new".equals(command)) {
        if (!verifyModification()) {
            return;
        }
        setTitle("DeckBuilder");
        deckNameTxt.setText("");
        rightListModel.getCards().clear();
        datasets.removeAll();
        modifiedSinceSave = false;
        updateChecker();
        setAsNew();
    } else if ("menu_convert_DCK_MP".equals(command)) {
        /*
         * Convert an entire directory from a format to MP one
         */
        try {
            Converter
                    .convertDCK(MToolKit
                            .showDialogFile("Choose a directory of DCK to convert", 'o', null, FILTER_DECK,
                                    this, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY)
                            .getCanonicalPath());
        } catch (IOException e1) {
            JOptionPane.showMessageDialog(this, "Error occurred reading the specified directory",
                    "File problem", JOptionPane.ERROR_MESSAGE);
        } catch (Exception e1) {
            // cancel of user;
        }
    } else if ("menu_db_constraints".equals(command)) {
        // Show the deck constraints applied on the current TBS
        new DeckRules(this).setVisible(true);
    } else if ("menu_help_help".equals(command)) {
        /*
         * This method is invoked when user has chosen to see the help file. <br>
         * TODO documentation is not yet done for this form
         */
        JOptionPane.showMessageDialog(form, "Sorry, no documentation available for deck builder",
                "Negative yet implemented", JOptionPane.INFORMATION_MESSAGE);
    } else if ("menu_db_load".equals(command)) {
        if (verifyModification()) {
            String deckFile = MToolKit.getDeckFile(this, JFileChooser.OPEN_DIALOG);
            if (deckFile != null) {
                loadDeck(deckFile, rightListModel.getCards());
            }
        }
    } else if ("menu_db_saveas".equals(command)) {
        String deckFile = MToolKit.getDeckFile(this, JFileChooser.SAVE_DIALOG);
        if (deckFile != null) {
            MSaveDeck.saveDeck(deckFile, rightListModel.getCards(), form);
            setAsSaved();
        }
    } else if ("menu_db_save".equals(command)) {
        saveCurrentDeck();
        setAsSaved();
    } else {
        // several implemented filters
        final MListModel<MCardCompare> model = (MListModel<MCardCompare>) leftList.getModel();

        final FileInputStream dbStream = MdbLoader.resetMdb();

        final List<MCardCompare> toRemove = new ArrayList<MCardCompare>();

        if ("clear".equals(command)) {
            // Reset the color filters
            for (Component component : toolBar.getComponents()) {
                if (component instanceof JToggleButton) {
                    ((JToggleButton) component).setSelected(true);
                }
            }
        }
        model.addAll(model.removedDelegate);

        final int cardType = CardFactory.getIdCard((String) idCardComboBox.getSelectedItem());
        if (cardType != -1) {
            // "All" is not selected in card type filter
            // we remove the cards that don't have the selected card id
            for (MCardCompare cardCompare : model.delegate) {
                try {
                    final CardModel cardModel = cardCompare.getModel(dbStream);
                    if (!MCard.hasIdCard(cardModel.getIdCard(), cardType)) {
                        toRemove.add(cardCompare);
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            model.removeAll(toRemove);
            toRemove.clear();
        }

        // property filter
        // we search for the property value, if it isn't found it's because "All"
        // is selected in the comboBox
        int property = CardFactory.getProperty((String) propertiesComboBox.getSelectedItem());

        if (property != -1) {
            // "All" is not selected in property filter
            // we remove the cards that don't have the selected property
            for (MCardCompare cardCompare : model.delegate) {
                try {
                    final CardModel cardModel = cardCompare.getModel(dbStream);
                    if (!MCard.hasProperty(cardModel.getProperties(), property)) {
                        toRemove.add(cardCompare);
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            model.removeAll(toRemove);
            toRemove.clear();
        }

        // color filters
        for (int i = 1; i < IdCardColors.CARD_COLOR_VALUES.length + 1; i++) {
            final JToggleButton colorButton = (JToggleButton) toolBar.getComponent(i);
            if (!colorButton.isSelected()) {
                for (MCardCompare cardCompare : model.delegate) {
                    try {
                        final CardModel cardModel = cardCompare.getModel(dbStream);
                        if (i == 1) {
                            if (cardModel.getIdColor() == 0) {
                                toRemove.add(cardCompare);
                            }
                        } else if ((cardModel.getIdColor()
                                & IdCardColors.CARD_COLOR_VALUES[i - 1]) == IdCardColors.CARD_COLOR_VALUES[i
                                        - 1]) {
                            toRemove.add(cardCompare);
                        }
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
                model.removeAll(toRemove);
                toRemove.clear();
            }
        }
        leftList.repaint();
        if (!model.isEmpty())
            leftList.setSelectedIndex(0);
    }
}

From source file:net.sf.jsignpdf.VisibleSignatureDialog.java

private void btnBgImgPathBrowseActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnBgImgPathBrowseActionPerformed
    fc.showFileChooser(tfBgImgPath, null, JFileChooser.OPEN_DIALOG);
}

From source file:net.sf.jsignpdf.VisibleSignatureDialog.java

private void btnImgPathBrowseActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnImgPathBrowseActionPerformed
    fc.showFileChooser(tfImgPath, null, JFileChooser.OPEN_DIALOG);
}