Search in sources :

Example 51 with FileDialog

use of java.awt.FileDialog in project jdk8u_jdk by JetBrains.

the class FileDialogForPackages method init.

@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[] { "Press PASS, this test is for MacOS X only." });
        return;
    }
    System.setProperty("apple.awt.use-file-dialog-packages", "true");
    setLayout(new GridLayout(1, 1));
    fd = new FileDialog(new Frame(), "Open");
    fd.setDirectory(APPLICATIONS_FOLDER);
    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Navigate to the Applications folder if not already there", "3) Check that the application bundles can be selected and can not be navigated", "4) If it's true then the test passed, otherwise it failed." };
    Sysout.createDialogWithInstructions(instructions);
}
Also used : GridLayout(java.awt.GridLayout) Frame(java.awt.Frame) Button(java.awt.Button) FileDialog(java.awt.FileDialog)

Example 52 with FileDialog

use of java.awt.FileDialog in project jdk8u_jdk by JetBrains.

the class SubjDelegPerm method userSaveContinue.

/**
     * when the user sees the 'YES', 'NO', 'CANCEL' buttons on the
     * displayUserSave dialog, and the click on one of them,
     * we need to continue the originally requested action
     * (either QUITting, opening NEW policy file, or OPENing an existing
     * policy file.  do that now.
     */
@SuppressWarnings("fallthrough")
void userSaveContinue(PolicyTool tool, ToolWindow tw, ToolDialog us, int select) {
    // now either QUIT, open a NEW policy file, or OPEN an existing policy
    switch(select) {
        case ToolDialog.QUIT:
            tw.setVisible(false);
            tw.dispose();
            System.exit(0);
        case ToolDialog.NEW:
            try {
                tool.openPolicy(null);
            } catch (Exception ee) {
                tool.modified = false;
                tw.displayErrorDialog(null, ee);
            }
            // display the policy entries via the policy list textarea
            JList list = new JList(new DefaultListModel());
            list.setVisibleRowCount(15);
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            list.addMouseListener(new PolicyListListener(tool, tw));
            tw.replacePolicyList(list);
            // display null policy filename and keystore
            JTextField newFilename = (JTextField) tw.getComponent(ToolWindow.MW_FILENAME_TEXTFIELD);
            newFilename.setText("");
            tw.setVisible(true);
            break;
        case ToolDialog.OPEN:
            // pop up a dialog box for the user to enter a filename.
            FileDialog fd = new FileDialog(tw, PolicyTool.getMessage("Open"), FileDialog.LOAD);
            fd.addWindowListener(new WindowAdapter() {

                public void windowClosing(WindowEvent e) {
                    e.getWindow().setVisible(false);
                }
            });
            fd.setVisible(true);
            // see if the user hit 'cancel'
            if (fd.getFile() == null || fd.getFile().equals(""))
                return;
            // get the entered filename
            String policyFile = new File(fd.getDirectory(), fd.getFile()).getPath();
            try {
                // open the policy file
                tool.openPolicy(policyFile);
                // display the policy entries via the policy list textarea
                DefaultListModel listModel = new DefaultListModel();
                list = new JList(listModel);
                list.setVisibleRowCount(15);
                list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                list.addMouseListener(new PolicyListListener(tool, tw));
                PolicyEntry[] entries = tool.getEntry();
                if (entries != null) {
                    for (int i = 0; i < entries.length; i++) {
                        listModel.addElement(entries[i].headerToString());
                    }
                }
                tw.replacePolicyList(list);
                tool.modified = false;
                // display the new policy filename
                newFilename = (JTextField) tw.getComponent(ToolWindow.MW_FILENAME_TEXTFIELD);
                newFilename.setText(policyFile);
                tw.setVisible(true);
                // inform user of warnings
                if (tool.newWarning == true) {
                    tw.displayStatusDialog(null, PolicyTool.getMessage("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
                }
            } catch (Exception e) {
                // add blank policy listing
                list = new JList(new DefaultListModel());
                list.setVisibleRowCount(15);
                list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                list.addMouseListener(new PolicyListListener(tool, tw));
                tw.replacePolicyList(list);
                tool.setPolicyFileName(null);
                tool.modified = false;
                // display a null policy filename
                newFilename = (JTextField) tw.getComponent(ToolWindow.MW_FILENAME_TEXTFIELD);
                newFilename.setText("");
                tw.setVisible(true);
                // display the error
                MessageFormat form = new MessageFormat(PolicyTool.getMessage("Could.not.open.policy.file.policyFile.e.toString."));
                Object[] source = { policyFile, e.toString() };
                tw.displayErrorDialog(null, form.format(source));
            }
            break;
    }
}
Also used : MessageFormat(java.text.MessageFormat) MalformedURLException(java.net.MalformedURLException) ExpandException(sun.security.util.PropertyExpander.ExpandException) CertificateException(java.security.cert.CertificateException) Point(java.awt.Point) FileDialog(java.awt.FileDialog)

Example 53 with FileDialog

use of java.awt.FileDialog in project megameklab by MegaMek.

the class MenuBarCreator method jMenuSaveEntity_actionPerformed.

public void jMenuSaveEntity_actionPerformed(ActionEvent event) {
    if (UnitUtil.validateUnit(parentFrame.getEntity()).length() > 0) {
        JOptionPane.showMessageDialog(parentFrame, "Warning: Saving an invalid unit, it might load incorrectly!");
    }
    String unitName = parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel();
    UnitUtil.compactCriticals(parentFrame.getEntity());
    String filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_FILE_1);
    if ((filePathName.trim().length() < 1) || !filePathName.contains(unitName)) {
        FileDialog fDialog = new FileDialog(parentFrame, "Save As", FileDialog.SAVE);
        filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_LOC);
        fDialog.setDirectory(filePathName);
        fDialog.setFile(unitName + (parentFrame.getEntity() instanceof Mech ? ".mtf" : ".blk"));
        fDialog.setLocationRelativeTo(parentFrame);
        fDialog.setVisible(true);
        if (fDialog.getFile() != null) {
            filePathName = fDialog.getDirectory() + fDialog.getFile();
            CConfig.setParam(CConfig.CONFIG_SAVE_LOC, fDialog.getDirectory());
        } else {
            return;
        }
    }
    try {
        if (parentFrame.getEntity() instanceof Mech) {
            FileOutputStream out = new FileOutputStream(filePathName);
            PrintStream p = new PrintStream(out);
            p.println(((Mech) parentFrame.getEntity()).getMtf());
            p.close();
            out.close();
        } else {
            BLKFile.encode(filePathName, parentFrame.getEntity());
        }
        CConfig.updateSaveFiles(filePathName);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    JOptionPane.showMessageDialog(parentFrame, parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + " saved to " + filePathName);
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) Mech(megamek.common.Mech) FileDialog(java.awt.FileDialog)

Example 54 with FileDialog

use of java.awt.FileDialog in project megameklab by MegaMek.

the class MenuBarCreator method jMenuExportEntityHTML_actionPerformed.

public void jMenuExportEntityHTML_actionPerformed(ActionEvent event) {
    if (UnitUtil.validateUnit(parentFrame.getEntity()).length() > 0) {
        JOptionPane.showMessageDialog(parentFrame, "Warning: exporting an invalid unit!");
    }
    String unitName = parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel();
    MechView mview = new MechView(parentFrame.getEntity(), false);
    FileDialog fDialog = new FileDialog(parentFrame, "Save As", FileDialog.SAVE);
    String filePathName = new File(System.getProperty("user.dir").toString()).getAbsolutePath();
    fDialog.setDirectory(filePathName);
    fDialog.setFile(unitName + ".html");
    fDialog.setLocationRelativeTo(parentFrame);
    fDialog.setVisible(true);
    if (fDialog.getFile() != null) {
        filePathName = fDialog.getDirectory() + fDialog.getFile();
    } else {
        return;
    }
    try {
        FileOutputStream out = new FileOutputStream(filePathName);
        PrintStream p = new PrintStream(out);
        p.println(mview.getMechReadout());
        p.close();
        out.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : PrintStream(java.io.PrintStream) MechView(megamek.common.MechView) FileOutputStream(java.io.FileOutputStream) FileDialog(java.awt.FileDialog) File(java.io.File) BLKFile(megamek.common.loaders.BLKFile)

Example 55 with FileDialog

use of java.awt.FileDialog in project megameklab by MegaMek.

the class StatusBar method getFluffImage.

private void getFluffImage() {
    // copied from structureTab
    FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD);
    fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
    /*
         //This does not seem to be working
        if (getMech().getFluff().getMMLImagePath().trim().length() > 0) {
            String fullPath = new File(getMech().getFluff().getMMLImagePath()).getAbsolutePath();
            String imageName = fullPath.substring(fullPath.lastIndexOf(File.separatorChar) + 1);
            fullPath = fullPath.substring(0, fullPath.lastIndexOf(File.separatorChar) + 1);
            fDialog.setDirectory(fullPath);
            fDialog.setFile(imageName);
        } else {
            fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
            fDialog.setFile(getMech().getChassis() + " " + getMech().getModel() + ".png");
        }
        */
    fDialog.setLocationRelativeTo(this);
    fDialog.setVisible(true);
    if (fDialog.getFile() != null) {
        String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
        relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
        getMech().getFluff().setMMLImagePath(relativeFilePath);
    }
    refresh.refreshPreview();
    return;
}
Also used : FileDialog(java.awt.FileDialog) File(java.io.File)

Aggregations

FileDialog (java.awt.FileDialog)78 File (java.io.File)43 JFileChooser (javax.swing.JFileChooser)18 Frame (java.awt.Frame)16 IOException (java.io.IOException)16 FilenameFilter (java.io.FilenameFilter)10 Dialog (java.awt.Dialog)8 FileFilter (javax.swing.filechooser.FileFilter)7 FileOutputStream (java.io.FileOutputStream)5 PrintStream (java.io.PrintStream)4 Button (java.awt.Button)3 Dimension (java.awt.Dimension)3 MenuItem (java.awt.MenuItem)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 MalformedURLException (java.net.MalformedURLException)3 SQLException (java.sql.SQLException)3 JLabel (javax.swing.JLabel)3 Component (java.awt.Component)2 GridLayout (java.awt.GridLayout)2