Search in sources :

Example 1 with MechFileParser

use of megamek.common.MechFileParser in project megameklab by MegaMek.

the class MenuBarCreator method jMenuInsertImageFile_actionPerformed.

private void jMenuInsertImageFile_actionPerformed() {
    String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
    File unitFile = new File(filePathName);
    JFileChooser f = new JFileChooser(filePathName);
    f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
    f.setDialogTitle("Load Mech");
    f.setDialogType(JFileChooser.OPEN_DIALOG);
    f.setMultiSelectionEnabled(false);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
    // Add a filter for mul files
    f.setFileFilter(filter);
    int returnVal = f.showOpenDialog(parentFrame);
    if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
        // I want a file, y'know!
        return;
    }
    unitFile = f.getSelectedFile();
    try {
        Entity tempEntity = new MechFileParser(unitFile).getEntity();
        if (UnitUtil.validateUnit(parentFrame.getEntity()).trim().length() > 0) {
            JOptionPane.showMessageDialog(parentFrame, "Warning:Invalid unit, it might load incorrectly!");
        }
        FileDialog fDialog = new FileDialog(parentFrame, "Image Path", FileDialog.LOAD);
        if (parentFrame.getEntity().getFluff().getMMLImagePath().trim().length() > 0) {
            String fullPath = new File(parentFrame.getEntity().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 + "mech" + File.separatorChar);
            fDialog.setFile(parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + ".png");
        }
        fDialog.setLocationRelativeTo(parentFrame);
        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);
            parentFrame.getEntity().getFluff().setMMLImagePath(relativeFilePath);
            BLKFile.encode(unitFile.getAbsolutePath(), tempEntity);
        }
    } catch (Exception ex) {
    }
    return;
}
Also used : Entity(megamek.common.Entity) JFileChooser(javax.swing.JFileChooser) MechFileParser(megamek.common.MechFileParser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) BLKFile(megamek.common.loaders.BLKFile) FileDialog(java.awt.FileDialog)

Example 2 with MechFileParser

use of megamek.common.MechFileParser in project megameklab by MegaMek.

the class MenuBarCreator method jMenuGetUnitWeightBreakdownFromFile_actionPerformed.

private void jMenuGetUnitWeightBreakdownFromFile_actionPerformed() {
    Entity tempEntity = null;
    String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
    File unitFile = new File(filePathName);
    JFileChooser f = new JFileChooser(filePathName);
    f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
    f.setDialogTitle("Choose Unit");
    f.setDialogType(JFileChooser.OPEN_DIALOG);
    f.setMultiSelectionEnabled(false);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
    // Add a filter for mul files
    f.setFileFilter(filter);
    int returnVal = f.showOpenDialog(parentFrame);
    if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
        // I want a file, y'know!
        return;
    }
    unitFile = f.getSelectedFile();
    try {
        tempEntity = new MechFileParser(unitFile).getEntity();
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
    } finally {
        UnitUtil.showUnitWeightBreakDown(tempEntity, parentFrame);
    }
}
Also used : Entity(megamek.common.Entity) JFileChooser(javax.swing.JFileChooser) MechFileParser(megamek.common.MechFileParser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) BLKFile(megamek.common.loaders.BLKFile)

Example 3 with MechFileParser

use of megamek.common.MechFileParser in project megameklab by MegaMek.

the class UnitPrintQueueDialog method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() == bCancel) {
        dispose();
    }
    if (ae.getSource() == bPrint) {
        UnitPrintManager.printAllUnits(units, chSinglePrint.isSelected());
        dispose();
    }
    if (ae.getSource().equals(bSelectCache)) {
        UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(clientgui);
        unitLoadingDialog.setVisible(true);
        UnitSelectorDialog viewer = new UnitSelectorDialog(clientgui, unitLoadingDialog, true);
        viewer.setVisible(false);
        Entity entity = viewer.getChosenEntity();
        if (entity != null) {
            units.add(entity);
            refresh();
        }
    } else if (ae.getSource().equals(bSelectFile)) {
        String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
        JFileChooser f = new JFileChooser(filePathName);
        f.setLocation(clientgui.getLocation().x + 150, clientgui.getLocation().y + 100);
        f.setDialogTitle("Print Unit File");
        f.setMultiSelectionEnabled(true);
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf");
        // Add a filter
        f.setFileFilter(filter);
        int returnVal = f.showOpenDialog(clientgui);
        if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
            // I want a file, y'know!
            return;
        }
        for (File entityFile : f.getSelectedFiles()) {
            try {
                Entity tempEntity = new MechFileParser(entityFile).getEntity();
                units.add(tempEntity);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        refresh();
    } else if (ae.getSource().equals(bRemove)) {
        if (unitList.getSelectedIndices().length > 0) {
            for (int pos = unitList.getSelectedIndices().length - 1; pos >= 0; pos--) {
                units.remove(unitList.getSelectedIndices()[pos]);
            }
            refresh();
        }
    }
}
Also used : Entity(megamek.common.Entity) JFileChooser(javax.swing.JFileChooser) MechFileParser(megamek.common.MechFileParser) UnitLoadingDialog(megamek.client.ui.swing.UnitLoadingDialog) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) UnitSelectorDialog(megamek.client.ui.swing.UnitSelectorDialog)

Example 4 with MechFileParser

use of megamek.common.MechFileParser in project megameklab by MegaMek.

the class MenuBarCreator method jMenuGetUnitValidationFromFile_actionPerformed.

private void jMenuGetUnitValidationFromFile_actionPerformed() {
    Entity tempEntity = null;
    String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
    File unitFile = new File(filePathName);
    JFileChooser f = new JFileChooser(filePathName);
    f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
    f.setDialogTitle("Choose Unit");
    f.setDialogType(JFileChooser.OPEN_DIALOG);
    f.setMultiSelectionEnabled(false);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
    // Add a filter for mul files
    f.setFileFilter(filter);
    int returnVal = f.showOpenDialog(parentFrame);
    if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
        // I want a file, y'know!
        return;
    }
    unitFile = f.getSelectedFile();
    try {
        tempEntity = new MechFileParser(unitFile).getEntity();
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
    } finally {
        UnitUtil.showValidation(tempEntity, parentFrame);
    }
}
Also used : Entity(megamek.common.Entity) JFileChooser(javax.swing.JFileChooser) MechFileParser(megamek.common.MechFileParser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) BLKFile(megamek.common.loaders.BLKFile)

Example 5 with MechFileParser

use of megamek.common.MechFileParser in project megameklab by MegaMek.

the class MenuBarCreator method jMenuGetUnitBVFromFile_actionPerformed.

private void jMenuGetUnitBVFromFile_actionPerformed() {
    Entity tempEntity = null;
    String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
    File unitFile = new File(filePathName);
    JFileChooser f = new JFileChooser(filePathName);
    f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
    f.setDialogTitle("Choose Unit");
    f.setDialogType(JFileChooser.OPEN_DIALOG);
    f.setMultiSelectionEnabled(false);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
    // Add a filter for mul files
    f.setFileFilter(filter);
    int returnVal = f.showOpenDialog(parentFrame);
    if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
        // I want a file, y'know!
        return;
    }
    unitFile = f.getSelectedFile();
    try {
        tempEntity = new MechFileParser(unitFile).getEntity();
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
    } finally {
        tempEntity.calculateBattleValue(true, true);
        UnitUtil.showBVCalculations(tempEntity.getBVText(), parentFrame);
    }
}
Also used : Entity(megamek.common.Entity) JFileChooser(javax.swing.JFileChooser) MechFileParser(megamek.common.MechFileParser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) BLKFile(megamek.common.loaders.BLKFile)

Aggregations

Entity (megamek.common.Entity)9 MechFileParser (megamek.common.MechFileParser)9 File (java.io.File)8 JFileChooser (javax.swing.JFileChooser)8 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)8 BLKFile (megamek.common.loaders.BLKFile)6 FileDialog (java.awt.FileDialog)1 Vector (java.util.Vector)1 MegaMek (megamek.MegaMek)1 UnitLoadingDialog (megamek.client.ui.swing.UnitLoadingDialog)1 UnitSelectorDialog (megamek.client.ui.swing.UnitSelectorDialog)1 Aero (megamek.common.Aero)1 BattleArmor (megamek.common.BattleArmor)1 EntityListFile (megamek.common.EntityListFile)1 FixedWingSupport (megamek.common.FixedWingSupport)1 GunEmplacement (megamek.common.GunEmplacement)1 Infantry (megamek.common.Infantry)1 Jumpship (megamek.common.Jumpship)1 Mech (megamek.common.Mech)1 Tank (megamek.common.Tank)1