Search in sources :

Example 31 with JFileChooser

use of javax.swing.JFileChooser in project yyl_example by Relucent.

the class CertContent2 method registerListener.

/** 注册监听 */
private void registerListener() {
    btnKeystore.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int returnVal = chooser.showOpenDialog(btnKeystore);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtKeystore.setText(chooser.getSelectedFile().getAbsolutePath());
            }
            txtCerFile.setText(txtKeystore.getText() + ".cer");
            fillJComboBox();
        }
    });
    cboAlias.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            Object oItem = cboAlias.getSelectedItem();
            String sAlias = oItem == null ? "" : String.valueOf(oItem);
            txtCerFile.setText(txtKeystore.getText() + "_" + sAlias + ".cer");
        }
    });
    btnDisplay.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            sCommand = getCommand();
            txtDebug.setText("");
            txtDebug.append(sCommand);
        }
    });
    btnExecute.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            txtDebug.setText("");
            new ExecuteCommand(txtDebug).execute(sCommand, null);
            btnExecute.setEnabled(false);
            fillJComboBox();
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ActionEvent(java.awt.event.ActionEvent)

Example 32 with JFileChooser

use of javax.swing.JFileChooser in project yyl_example by Relucent.

the class CertContent3 method registerListener.

/** 注册监听 */
private void registerListener() {
    btnKeystore.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int returnVal = chooser.showOpenDialog(btnKeystore);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtKeystore.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    btnDisplay.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            sCommand = getCommand();
            txtDebug.setText("");
            txtDebug.append(sCommand);
        }
    });
    btnExecute.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            txtDebug.setText("");
            new ExecuteCommand(txtDebug).execute(sCommand, null);
            btnExecute.setEnabled(false);
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ActionEvent(java.awt.event.ActionEvent)

Example 33 with JFileChooser

use of javax.swing.JFileChooser in project yyl_example by Relucent.

the class CertContent4 method registerListener.

/** 注册监听 */
private void registerListener() {
    btnKeystore.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int returnVal = chooser.showOpenDialog(btnKeystore);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtKeystore.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    btnCerFile.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {

                public boolean accept(File f) {
                    return (f.isFile() && f.getPath().endsWith(".cer"));
                }

                public String getDescription() {
                    return ".cer";
                }
            });
            int returnVal = chooser.showOpenDialog(btnCerFile);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtCerFile.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    btnDisplay.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            sCommand = getCommand();
            txtDebug.setText("");
            txtDebug.append(sCommand);
        }
    });
    btnExecute.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            txtDebug.setText("");
            new ExecuteCommand(txtDebug).execute(sCommand, new String[] { "y" });
            btnExecute.setEnabled(false);
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ActionEvent(java.awt.event.ActionEvent) File(java.io.File)

Example 34 with JFileChooser

use of javax.swing.JFileChooser in project pcgen by PCGen.

the class Initiative method saveToFile.

//** End Preferences Functions **
//** IO Functions **
/**  Calls up a file save dialog, and if a file is selected/created, will then save the combatants out to disk. */
public void saveToFile() {
    JFileChooser fLoad = new JFileChooser();
    File defaultFile = new File(PCGenSettings.getPcgDir());
    if (defaultFile.exists()) {
        fLoad.setCurrentDirectory(defaultFile);
    }
    String[] fileExt = { "gmi", "init" };
    FileFilter sff = new FileNameExtensionFilter("GMGen Initiative/Encounter Export", fileExt);
    fLoad.addChoosableFileFilter(sff);
    fLoad.setFileFilter(sff);
    final int returnVal = fLoad.showSaveDialog(this);
    try {
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            String fileName = fLoad.getSelectedFile().getName();
            String ext = "";
            if (!fileName.endsWith(".gmi")) {
                ext = ".gmi";
            }
            File xml = new File(fLoad.getSelectedFile().getParent() + File.separator + fileName + ext);
            if (xml.exists()) {
                int choice = JOptionPane.showConfirmDialog(this, "File Exists, Overwrite?", "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (choice == JOptionPane.YES_OPTION) {
                    SettingsHandler.ensurePathExists(xml.getParentFile());
                    saveToDocument(xml);
                }
            } else {
                SettingsHandler.ensurePathExists(xml.getParentFile());
                saveToDocument(xml);
            }
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "Error Writing File");
        Logging.errorPrint("Error Writing File");
        Logging.errorPrint(e.getMessage(), e);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) IOException(java.io.IOException)

Example 35 with JFileChooser

use of javax.swing.JFileChooser in project pcgen by PCGen.

the class DiceBagPluginController method fileOpen.

/**
	 * <p>
	 * Displays a file-open dialog box and processes the selected values.
	 * </p>
	 *
	 * @return {@code boolean} indicating success/failure of operation.
	 */
public boolean fileOpen() {
    boolean returnValue = false;
    String sFile = SettingsHandler.getGMGenOption(DiceBagPlugin.LOG_NAME + ".LastFile", System.getProperty("user.dir"));
    JFileChooser open = new JFileChooser();
    if (sFile != null) {
        File defaultFile = new File(sFile);
        if (defaultFile.exists()) {
            open.setCurrentDirectory(defaultFile);
        }
    }
    String fileExt = "dbg";
    FileFilter ff = new FileNameExtensionFilter("GMGen Dice Bag", fileExt);
    open.addChoosableFileFilter(ff);
    open.setFileFilter(ff);
    if (open.showOpenDialog(GMGenSystem.inst) == JFileChooser.APPROVE_OPTION) {
        openFile(open.getSelectedFile());
        returnValue = true;
    }
    return returnValue;
}
Also used : JFileChooser(javax.swing.JFileChooser) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Aggregations

JFileChooser (javax.swing.JFileChooser)297 File (java.io.File)178 IOException (java.io.IOException)63 FileFilter (javax.swing.filechooser.FileFilter)40 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)30 ActionEvent (java.awt.event.ActionEvent)27 ActionListener (java.awt.event.ActionListener)22 FileOutputStream (java.io.FileOutputStream)19 JButton (javax.swing.JButton)19 JPanel (javax.swing.JPanel)16 Point (java.awt.Point)14 Preferences (java.util.prefs.Preferences)12 JMenuItem (javax.swing.JMenuItem)12 Component (java.awt.Component)11 FileNotFoundException (java.io.FileNotFoundException)11 JFrame (javax.swing.JFrame)10 JLabel (javax.swing.JLabel)10 ResourceBundle (java.util.ResourceBundle)8 BorderLayout (java.awt.BorderLayout)7 FileDialog (java.awt.FileDialog)7