Search in sources :

Example 11 with FileDialog

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

the class MenuBarCreator method jMenuSaveAsEntity_actionPerformed.

public void jMenuSaveAsEntity_actionPerformed(ActionEvent event) {
    if (UnitUtil.validateUnit(parentFrame.getEntity()).length() > 0) {
        JOptionPane.showMessageDialog(parentFrame, "Warning: Saving an invalid unit, it might load incorrectly!");
    }
    UnitUtil.compactCriticals(parentFrame.getEntity());
    FileDialog fDialog = new FileDialog(parentFrame, "Save As", FileDialog.SAVE);
    String filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_LOC);
    fDialog.setDirectory(filePathName);
    fDialog.setFile(parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + (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 12 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);
    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);
        getSmallCraft().getFluff().setMMLImagePath(relativeFilePath);
    }
    refresh.refreshPreview();
    return;
}
Also used : FileDialog(java.awt.FileDialog) File(java.io.File)

Example 13 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);
        getInfantry().getFluff().setMMLImagePath(relativeFilePath);
    }
    refresh.refreshPreview();
    return;
}
Also used : FileDialog(java.awt.FileDialog) File(java.io.File)

Example 14 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);
    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);
        getAero().getFluff().setMMLImagePath(relativeFilePath);
    }
    refresh.refreshPreview();
    return;
}
Also used : FileDialog(java.awt.FileDialog) File(java.io.File)

Example 15 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);
    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);
        getAero().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