Search in sources :

Example 6 with MechFileParser

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

the class MenuBarCreator method loadUnitFromFile.

private void loadUnitFromFile(File unitFile) {
    try {
        Entity tempEntity = new MechFileParser(unitFile).getEntity();
        if (null == tempEntity) {
            return;
        }
        if (UnitUtil.validateUnit(tempEntity).trim().length() > 0) {
            JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", UnitUtil.validateUnit(tempEntity)));
        }
        if (tempEntity.getEntityType() != parentFrame.getEntity().getEntityType()) {
            MegaMekLabMainUI newUI = null;
            if (tempEntity.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
                newUI = new megameklab.com.ui.Dropship.MainUI(((Aero) tempEntity).isPrimitive());
            } else if ((tempEntity instanceof Aero) && !((tempEntity instanceof Jumpship) || (tempEntity instanceof FixedWingSupport))) {
                newUI = new megameklab.com.ui.Aero.MainUI(((Aero) tempEntity).isPrimitive());
            } else if (tempEntity instanceof BattleArmor) {
                newUI = new megameklab.com.ui.BattleArmor.MainUI();
            } else if (tempEntity instanceof Infantry) {
                newUI = new megameklab.com.ui.Infantry.MainUI();
            } else if (tempEntity instanceof Mech) {
                newUI = new megameklab.com.ui.Mek.MainUI();
            } else if ((tempEntity instanceof Tank) && !(tempEntity instanceof GunEmplacement)) {
                newUI = new megameklab.com.ui.Vehicle.MainUI();
            }
            if (null == newUI) {
                JOptionPane.showMessageDialog(parentFrame, "Warning: Could not create new UI, aborting unit load!");
                return;
            }
            parentFrame.dispose();
            UnitUtil.updateLoadedUnit(tempEntity);
            newUI.setEntity(tempEntity);
            newUI.reloadTabs();
            newUI.repaint();
            newUI.refreshAll();
            return;
        }
        parentFrame.setEntity(tempEntity);
        UnitUtil.updateLoadedUnit(parentFrame.getEntity());
        CConfig.updateSaveFiles(unitFile.getAbsolutePath());
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
    }
    reload();
    refresh();
    parentFrame.setVisible(true);
}
Also used : MegaMekLabMainUI(megameklab.com.ui.MegaMekLabMainUI) Entity(megamek.common.Entity) FixedWingSupport(megamek.common.FixedWingSupport) Tank(megamek.common.Tank) Infantry(megamek.common.Infantry) MegaMek(megamek.MegaMek) MechFileParser(megamek.common.MechFileParser) MegaMekLabMainUI(megameklab.com.ui.MegaMekLabMainUI) Mech(megamek.common.Mech) Jumpship(megamek.common.Jumpship) GunEmplacement(megamek.common.GunEmplacement) Aero(megamek.common.Aero) BattleArmor(megamek.common.BattleArmor)

Example 7 with MechFileParser

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

the class MenuBarCreator method jMenuGetUnitBreakdownFromFile_actionPerformed.

private void jMenuGetUnitBreakdownFromFile_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.showUnitCostBreakDown(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 8 with MechFileParser

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

the class MenuBarCreator method jMenuGetUnitSpecsFromFile_actionPerformed.

private void jMenuGetUnitSpecsFromFile_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.showUnitSpecs(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 9 with MechFileParser

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

the class UnitPrintManager method printUnitFile.

public static void printUnitFile(JFrame parent, boolean singleUnit) {
    String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
    JFileChooser f = new JFileChooser(filePathName);
    f.setLocation(parent.getLocation().x + 150, parent.getLocation().y + 100);
    f.setDialogTitle("Print Unit File");
    f.setMultiSelectionEnabled(true);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf");
    // Add a filter for mul files
    f.setFileFilter(filter);
    int returnVal = f.showOpenDialog(parent);
    if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
        // I want a file, y'know!
        return;
    }
    try {
        Vector<Entity> unitList = new Vector<Entity>();
        for (File entityFile : f.getSelectedFiles()) {
            Entity tempEntity = new MechFileParser(entityFile).getEntity();
            unitList.add(tempEntity);
        }
        printAllUnits(unitList, singleUnit);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Entity(megamek.common.Entity) JFileChooser(javax.swing.JFileChooser) MechFileParser(megamek.common.MechFileParser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) Vector(java.util.Vector) EntityListFile(megamek.common.EntityListFile) File(java.io.File)

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