Package java.awt

Examples of java.awt.FileDialog


        optdlg = null;
    }

    public void loadGame() {
        FileDialog fd = new FileDialog(frame, Messages
                .getString("MegaMek.SaveGameDialog.title"), FileDialog.LOAD); //$NON-NLS-1$
        fd.setDirectory("savegames"); //$NON-NLS-1$
        // limit file-list to savedgames only
        fd.setFilenameFilter(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return (null != name && name.endsWith(".sav")); //$NON-NLS-1$
            }
        });
        // Using the FilenameFilter class would be the appropriate way to
        // filter for certain extensions, but it's broken under windoze. See
        // http://developer.java.sun.com/developer/bugParade/bugs/4031440.html
        // for details. The hack below is better than nothing.
        // New note: Since we have a dedicated save dir now, I'm commenting
        // this out.
        // fd.setFile("*.sav"); //$NON-NLS-1$

        fd.setVisible(true);
        if (fd.getFile() == null) {
            return;
        }

        HostDialog hd = new HostDialog(frame);
        hd.setVisible(true);
        if (hd.name == null || hd.serverPass == null || hd.port == 0) {
            return;
        }

        // Players should have to enter a non-blank, non-whitespace name.
        boolean foundValid = false;
        char[] nameChars = hd.name.toCharArray();
        for (int loop = 0; !foundValid && loop < nameChars.length; loop++) {
            if (!Character.isWhitespace(nameChars[loop])) {
                foundValid = true;
            }
        }
        if (!foundValid) {
            new AlertDialog(
                    frame,
                    Messages.getString("MegaMek.PlayerNameAlert1.title"), Messages.getString("MegaMek.PlayerNameAlert1.message")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$
            return;
        }

        // kick off a RNG check
        megamek.common.Compute.d6();
        // start server
        try {
            server = new Server(hd.serverPass, hd.port);
        } catch (IOException ex) {
            System.err.println("could not create server socket on port "
                    + hd.port);
            StringBuffer error = new StringBuffer();
            error.append("Error: could not start server at localhost").append(
                    ":").append(hd.port).append(" (").append(ex.getMessage())
                    .append(").");
            new AlertDialog(
                    frame,
                    Messages.getString("MegaMek.HostGameAllert.title"), error.toString()).setVisible(true); //$NON-NLS-1$
            return;
        }
        if (!server.loadGame(new File(fd.getDirectory(), fd.getFile()))) {
            new AlertDialog(
                    frame,
                    Messages.getString("MegaMek.LoadGameAlert.title"), Messages.getString("MegaMek.LoadGameAlert.message")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$
            server.die();
            server = null;
View Full Code Here


    /**
     * Host a game constructed from a scenario file
     */
    public void scenario() {
        FileDialog fd = new FileDialog(
                frame,
                Messages.getString("MegaMek.SelectScenarioDialog.title"), FileDialog.LOAD); //$NON-NLS-1$
        fd.setDirectory("data" + File.separatorChar + "scenarios"); //$NON-NLS-1$ //$NON-NLS-2$

        // the filter doesn't seem to do anything in windows. oh well
        FilenameFilter ff = new FilenameFilter() {
            public boolean accept(File f, String s) {
                return s.endsWith(".mms"); //$NON-NLS-1$
            }
        };
        fd.setFilenameFilter(ff);
        fd.setFile("*.mms"); // see comment above for load game dialog
                                // //$NON-NLS-1$
        fd.setVisible(true);
        if (fd.getFile() == null) {
            return;
        }
        ScenarioLoader sl = new ScenarioLoader(new File(fd.getDirectory(), fd
                .getFile()));
        IGame g = null;
        try {
            g = sl.createGame();
        } catch (Exception e) {
View Full Code Here

        if (e.getSource().equals(butOK)) {
            if (applyValues()) {
                setVisible(false);
            }
        } else if (e.getSource().equals(butSave)) {
            FileDialog fd = new FileDialog(
                    frame,
                    Messages.getString("RandomMapDialog.FileSaveDialog"), FileDialog.SAVE); //$NON-NLS-1$
            fd.setDirectory("data" + File.separatorChar + "boards");
            fd.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File f, String s) {
                    return s.endsWith(".xml");
                }
            });
            fd.setModal(true);
            fd.setVisible(true);
            String filename = fd.getDirectory() + File.separator + fd.getFile();
            if (filename.indexOf('.') == -1) {
                filename = filename + ".xml";
            }
            File f = new File(filename);
            try {
                mapSettings.save(new FileOutputStream(f));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (e.getSource().equals(butLoad)) {
            FileDialog fd = new FileDialog(
                    frame,
                    Messages.getString("RandomMapDialog.FileLoadDialog"), FileDialog.LOAD); //$NON-NLS-1$
            fd.setDirectory("./data/boards/");
            fd.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File f, String s) {
                    return s.endsWith(".xml");
                }
            });
            fd.setModal(true);
            fd.setVisible(true);
            File f = new File(fd.getDirectory() + File.separator + fd.getFile());
            try {
                mapSettings.load(new FileInputStream(f));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
View Full Code Here

    /**
     * Implement the <code>ActionListener</code> interface.
     */
    public void actionPerformed(ActionEvent event) {
        if (event.getActionCommand().equalsIgnoreCase("fileGameSave")) { //$NON-NLS-1$
            FileDialog fd = new FileDialog(
                    frame,
                    Messages.getString("ClientGUI.FileSaveDialog.title"), FileDialog.SAVE); //$NON-NLS-1$
            fd.setDirectory("."); //$NON-NLS-1$

            fd.setVisible(true);

            if (null != fd.getFile()) {
                String file = fd.getDirectory() + fd.getFile();
                // stupid hack to allow for savegames in folders with spaces in the name
                file = file.replace(" ", "|");
                client.sendChat("/save " + file); //$NON-NLS-1$
            }
        }
View Full Code Here

     */
    protected void loadListFile() {

        // Build the "load unit" dialog, if necessary.
        if (null == dlgLoadList) {
            dlgLoadList = new FileDialog(
                    frame,
                    Messages
                            .getString("ClientGUI.openUnitListFileDialog.title"), FileDialog.LOAD); //$NON-NLS-1$

            // Add a filter for MUL files
View Full Code Here

            return;
        }

        // Build the "save unit" dialog, if necessary.
        if (null == dlgSaveList) {
            dlgSaveList = new FileDialog(
                    frame,
                    Messages
                            .getString("ClientGUI.saveUnitListFileDialog.title"), FileDialog.SAVE); //$NON-NLS-1$

            // Add a filter for MUL files
View Full Code Here

                System.err.println("Error while loading custom BattleArmor!");
                ex.printStackTrace();
                return;
            }
        } else if (ae.getSource() == m_bSave) {
            FileDialog fd = new FileDialog(
                    m_clientgui.frame,
                    Messages
                            .getString("CustomBattleArmorDialog.FileSaveDialog"), FileDialog.SAVE); //$NON-NLS-1$
            fd.setDirectory("data" + File.separatorChar + "mechfiles");
            fd.setFile(m_tfBAName.getText() + ".blk");
            fd.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File f, String s) {
                    return s.endsWith(".blk");
                }
            });
            fd.setModal(true);
            fd.setVisible(true);
            String filename = fd.getDirectory() + File.separator + fd.getFile();
            if (filename.indexOf('.') == -1) {
                filename = filename + ".blk";
            }
            File f = new File(filename);
            try {
View Full Code Here

    /**
     * Selects and loads a file into the BoardEditor. Called when the user
     * selects load file.
     */
    public void boardLoad() {
        final FileDialog fd = new FileDialog(frame, Messages
                .getString("BoardEditor.loadBoard"), FileDialog.LOAD); //$NON-NLS-1$
        fd.setDirectory("data" + File.separator + "boards"); //$NON-NLS-1$ //$NON-NLS-2$
        fd
                .setLocation(frame.getLocation().x + 150,
                        frame.getLocation().y + 100);
        fd.setVisible(true);

        if (fd.getFile() == null) {
            // I want a file, y'know!
            return;
        }
        curpath = fd.getDirectory();
        curfile = fd.getFile();
        // load!
        try {
            final InputStream is = new FileInputStream(new File(curpath,
                    curfile));
            // tell the board to load!
View Full Code Here

    /**
     * Opens a file dialog box to select a file to save as; saves the board to
     * the file.
     */
    public void boardSaveAs() {
        final FileDialog fd = new FileDialog(frame, Messages
                .getString("BoardEditor.saveBoardAs"), FileDialog.SAVE); //$NON-NLS-1$
        fd.setDirectory("data" + File.separator + "boards"); //$NON-NLS-1$ //$NON-NLS-2$
        fd
                .setLocation(frame.getLocation().x + 150,
                        frame.getLocation().y + 100);
        fd.setVisible(true);

        if (fd.getFile() == null) {
            // I want a file, y'know!
            return;
        }
        curpath = fd.getDirectory();
        curfile = fd.getFile();

        // make sure the file ends in board
        if (!curfile.toLowerCase().endsWith(".board")) { //$NON-NLS-1$
            curfile += ".board"; //$NON-NLS-1$
        }
View Full Code Here

    /**
     * Opens a file dialog box to select a file to save as; saves the board to
     * the file as an image. Useful for printing boards.
     */
    public void boardSaveAsImage() {
        final FileDialog fd = new FileDialog(frame, Messages
                .getString("BoardEditor.saveAsImage"), FileDialog.SAVE); //$NON-NLS-1$
        // fd.setDirectory("data" + File.separator + "boards");
        fd
                .setLocation(frame.getLocation().x + 150,
                        frame.getLocation().y + 100);

        // Add a filter for PNG files
        fd.setFilenameFilter(new FilenameFilter() {
            public boolean accept(final File dir, final String name) {
                return (null != name && name.endsWith(".png")); //$NON-NLS-1$
            }
        });

        // use base directory by default
        fd.setDirectory("."); //$NON-NLS-1$

        // Default to the board's name (if it has one).
        String fileName = null;
        if (null != curfile && curfile.length() > 0) {
            fileName = curfile.toUpperCase();
            if (fileName.endsWith(".BOARD")) { //$NON-NLS-1$
                final int length = fileName.length();
                fileName = fileName.substring(0, length - 6);
            }
            fileName = fileName.toLowerCase() + ".png"; //$NON-NLS-1$
            fd.setFile(fileName);
        }

        // Open the dialog and wait for it's return.
        fd.setVisible(true);

        if (fd.getFile() == null) {
            // I want a file, y'know!
            return;
        }
        curpath = fd.getDirectory();
        curfileImage = fd.getFile();

        // make sure the file ends in board
        if (!curfileImage.toLowerCase().endsWith(".png")) { //$NON-NLS-1$
            curfileImage += ".png"; //$NON-NLS-1$
        }
View Full Code Here

TOP

Related Classes of java.awt.FileDialog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.