Search in sources :

Example 6 with Mech

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

the class MainUI method createNewUnit.

@Override
public void createNewUnit(long entityType, boolean isPrimitive, boolean isIndustrial, Entity oldEntity) {
    int cockpit = Mech.COCKPIT_STANDARD;
    int at = EquipmentType.T_ARMOR_STANDARD;
    int st = EquipmentType.T_STRUCTURE_STANDARD;
    if (isPrimitive && isIndustrial) {
        cockpit = Mech.COCKPIT_PRIMITIVE_INDUSTRIAL;
        at = EquipmentType.T_ARMOR_PRIMITIVE;
        st = EquipmentType.T_STRUCTURE_INDUSTRIAL;
    } else if (isPrimitive) {
        cockpit = Mech.COCKPIT_PRIMITIVE;
        at = EquipmentType.T_ARMOR_PRIMITIVE;
    } else if (isIndustrial) {
        cockpit = Mech.COCKPIT_INDUSTRIAL;
        at = EquipmentType.T_ARMOR_INDUSTRIAL;
        st = EquipmentType.T_STRUCTURE_INDUSTRIAL;
    }
    if (entityType == Entity.ETYPE_TRIPOD_MECH) {
        setEntity(new TripodMech(Mech.GYRO_STANDARD, Mech.COCKPIT_TRIPOD));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    } else if (entityType == Entity.ETYPE_QUAD_MECH) {
        setEntity(new QuadMech(Mech.GYRO_STANDARD, cockpit));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    } else if (entityType == Entity.ETYPE_LAND_AIR_MECH) {
        setEntity(new LandAirMech(Mech.GYRO_STANDARD, Mech.COCKPIT_STANDARD, LandAirMech.LAM_STANDARD));
        getEntity().setTechLevel(TechConstants.T_IS_ADVANCED);
        getEntity().setManualBV(-1);
    } else if (entityType == Entity.ETYPE_QUADVEE) {
        setEntity(new QuadVee(Mech.GYRO_STANDARD, QuadVee.MOTIVE_TRACK));
        getEntity().setTechLevel(TechConstants.T_CLAN_ADVANCED);
        UnitUtil.createSpreadMounts((Mech) getEntity(), EquipmentType.get("Tracks"));
        getEntity().setManualBV(-1);
    } else {
        // type == 0
        setEntity(new BipedMech(Mech.GYRO_STANDARD, cockpit));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    }
    Mech mech = (Mech) getEntity();
    getEntity().setWeight(25);
    if (entityType == Entity.ETYPE_LAND_AIR_MECH) {
        mech.setEngine(new Engine(75, Engine.NORMAL_ENGINE, 0));
        UnitUtil.updateJumpJets(((Mech) getEntity()), 3, Mech.JUMP_STANDARD);
    } else {
        mech.setEngine(new Engine(25, Engine.NORMAL_ENGINE, 0));
    }
    getEntity().setArmorType(at);
    getEntity().setArmorTechLevel(getEntity().getTechLevel());
    getEntity().setStructureType(st);
    mech.addGyro();
    mech.addEngineCrits();
    if (isPrimitive) {
        mech.addPrimitiveCockpit();
    } else if (isIndustrial) {
        mech.addIndustrialCockpit();
    } else if (Entity.ETYPE_QUADVEE == entityType) {
        mech.addQuadVeeCockpit();
    } else {
        mech.addCockpit();
    }
    UnitUtil.updateHeatSinks(mech, 10, "Single");
    getEntity().autoSetInternal();
    for (int loc = 0; loc < getEntity().locations(); loc++) {
        mech.initializeArmor(0, loc);
        mech.initializeRearArmor(0, loc);
    }
    if (null == oldEntity) {
        mech.setChassis("New");
        mech.setModel("Mek");
        mech.setYear(3145);
    } else {
        mech.setChassis(oldEntity.getChassis());
        mech.setModel(oldEntity.getModel());
        mech.setYear(Math.max(oldEntity.getYear(), mech.getConstructionTechAdvancement().getIntroductionDate()));
        mech.setSource(oldEntity.getSource());
        mech.setManualBV(oldEntity.getManualBV());
        SimpleTechLevel lvl = SimpleTechLevel.max(mech.getStaticTechLevel(), SimpleTechLevel.convertCompoundToSimple(oldEntity.getTechLevel()));
        mech.setTechLevel(lvl.getCompoundTechLevel(oldEntity.isClan()));
        mech.setMixedTech(oldEntity.isMixedTech());
    }
}
Also used : TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) SimpleTechLevel(megamek.common.SimpleTechLevel) BipedMech(megamek.common.BipedMech) Mech(megamek.common.Mech) LandAirMech(megamek.common.LandAirMech) TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) QuadVee(megamek.common.QuadVee) BipedMech(megamek.common.BipedMech) Engine(megamek.common.Engine) LandAirMech(megamek.common.LandAirMech)

Example 7 with Mech

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

the class CriticalTransferHandler method importData.

/**
 */
@Override
public boolean importData(TransferSupport info) {
    if (!info.isDrop() || !((getUnit() instanceof Mech) || (getUnit() instanceof Aero) || (getUnit() instanceof BattleArmor))) {
        return false;
    }
    int trooper = 0;
    if (info.getComponent() instanceof DropTargetCriticalList) {
        DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) info.getComponent();
        if (getUnit() instanceof BattleArmor) {
            String[] split = list.getName().split(":");
            if (split.length != 2) {
                return false;
            }
            location = Integer.parseInt(split[0]);
            trooper = Integer.parseInt(split[1]);
        } else {
            location = Integer.parseInt(list.getName());
        }
        Transferable t = info.getTransferable();
        int slotNumber = list.getDropLocation().getIndex();
        try {
            Mounted eq = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
            if (getUnit() instanceof BattleArmor) {
                if ((location == eq.getBaMountLoc()) && (trooper == eq.getLocation())) {
                    return false;
                }
            } else {
                // the criticals its mounted in
                if (eq.getLocation() != Entity.LOC_NONE || eq.getSecondLocation() != Entity.LOC_NONE) {
                    UnitUtil.removeCriticals(getUnit(), eq);
                    changeMountStatus(eq, Entity.LOC_NONE, false);
                } else {
                    eq.setOmniPodMounted(UnitUtil.canPodMount(getUnit(), eq));
                }
            }
            if (!UnitUtil.isValidLocation(getUnit(), eq.getType(), location)) {
                JOptionPane.showMessageDialog(null, eq.getName() + " can't be placed in " + getUnit().getLocationName(location) + "!", "Invalid Location", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }
            if (getUnit() instanceof Aero) {
                return addEquipmentAero((Aero) getUnit(), eq);
            } else if (getUnit() instanceof Mech) {
                // superheavies can put 2 ammobins or heatsinks in one crit
                if ((getUnit() instanceof Mech) && ((Mech) getUnit()).isSuperHeavy()) {
                    CriticalSlot cs = getUnit().getCritical(location, slotNumber);
                    if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) && (cs.getMount2() == null)) {
                        EquipmentType etype = cs.getMount().getType();
                        EquipmentType etype2 = eq.getType();
                        boolean canDouble = false;
                        if ((etype instanceof AmmoType) && (etype2 instanceof AmmoType)) {
                            canDouble = (((AmmoType) etype).getAmmoType() == ((AmmoType) etype2).getAmmoType()) && (((AmmoType) etype).getRackSize() == ((AmmoType) etype2).getRackSize());
                        } else if (etype.equals(etype2) && UnitUtil.isHeatSink(etype)) {
                            canDouble = etype.getCriticals(getUnit()) == 1;
                        }
                        if (canDouble) {
                            cs.setMount2(eq);
                            changeMountStatus(eq, location, false);
                            return true;
                        }
                    }
                }
                return addEquipmentMech((Mech) getUnit(), eq, slotNumber);
            } else if (getUnit() instanceof BattleArmor) {
                return addEquipmentBA((BattleArmor) getUnit(), eq, trooper);
            }
        } catch (LocationFullException lfe) {
            JOptionPane.showMessageDialog(null, lfe.getMessage(), "Location Full", JOptionPane.INFORMATION_MESSAGE);
            return false;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return true;
    }
    return false;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Transferable(java.awt.datatransfer.Transferable) EquipmentType(megamek.common.EquipmentType) EntityLoadingException(megamek.common.loaders.EntityLoadingException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) LocationFullException(megamek.common.LocationFullException) IOException(java.io.IOException) AmmoType(megamek.common.AmmoType) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) Mech(megamek.common.Mech) LandAirMech(megamek.common.LandAirMech) Aero(megamek.common.Aero) TestAero(megamek.common.verifier.TestAero) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Example 8 with Mech

use of megamek.common.Mech 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 9 with Mech

use of megamek.common.Mech 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 10 with Mech

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

the class MenuBarCreator method loadFileMenuOptions.

private void loadFileMenuOptions() {
    file.removeAll();
    file.setMnemonic(KeyEvent.VK_F);
    JMenuItem item = new JMenuItem();
    item = new JMenuItem("Reset Current Unit");
    item.setMnemonic(KeyEvent.VK_R);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuResetEntity_actionPerformed(e);
        }
    });
    file.add(item);
    JMenu unitMenu = new JMenu("Switch Unit Type");
    unitMenu.setMnemonic(KeyEvent.VK_S);
    Entity en = parentFrame.getEntity();
    if (!(en instanceof Mech) || ((Mech) en).isPrimitive()) {
        item = new JMenuItem();
        item.setText("Mech");
        item.setMnemonic(KeyEvent.VK_M);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.addActionListener(e -> jMenuLoadMech());
        unitMenu.add(item);
    }
    if (!(en.isFighter() || (en.isFighter() && ((Aero) en).isPrimitive()))) {
        item = new JMenuItem();
        item.setText("Aero/Conv Fighter");
        item.setMnemonic(KeyEvent.VK_A);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jMenuLoadAero();
            }
        });
        unitMenu.add(item);
    }
    if (!(en instanceof SmallCraft) || ((Aero) en).isPrimitive()) {
        item = new JMenuItem();
        item.setText("Dropship/Small Craft");
        item.setMnemonic(KeyEvent.VK_D);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.addActionListener(e -> jMenuLoadDropship());
        unitMenu.add(item);
    }
    if (!(parentFrame.getEntity() instanceof Tank)) {
        item = new JMenuItem();
        item.setText("Combat Vehicle");
        item.setMnemonic(KeyEvent.VK_T);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jMenuLoadVehicle();
            }
        });
        unitMenu.add(item);
    }
    if (!(parentFrame.getEntity() instanceof BattleArmor)) {
        item = new JMenuItem();
        item.setText("BattleArmor");
        item.setMnemonic(KeyEvent.VK_B);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jMenuLoadBattleArmor();
            }
        });
        unitMenu.add(item);
    }
    if (!(parentFrame.getEntity() instanceof Infantry) || (parentFrame.getEntity() instanceof BattleArmor)) {
        item = new JMenuItem();
        item.setText("Infantry");
        item.setMnemonic(KeyEvent.VK_I);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jMenuLoadInfantry();
            }
        });
        unitMenu.add(item);
    }
    JMenu pMenu = new JMenu("Primitive/Retro");
    if (!(en instanceof Mech) || !((Mech) en).isPrimitive()) {
        item = new JMenuItem();
        item.setText("Mech");
        item.addActionListener(e -> jMenuLoadPrimitiveMech());
        pMenu.add(item);
    }
    if (!(en.isFighter()) || !((Aero) en).isPrimitive()) {
        item = new JMenuItem();
        item.setText("Aero");
        item.addActionListener(e -> jMenuLoadPrimitiveAero());
        pMenu.add(item);
    }
    if (!(en.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) || !((Aero) en).isPrimitive()) {
        item = new JMenuItem();
        item.setText("Dropship/Small Craft");
        item.addActionListener(e -> jMenuLoadPrimitiveDropship());
        pMenu.add(item);
    }
    unitMenu.add(pMenu);
    file.add(unitMenu);
    JMenu loadMenu = new JMenu("Load");
    loadMenu.setMnemonic(KeyEvent.VK_L);
    item = new JMenuItem();
    item.setText("From Cache");
    item.setMnemonic(KeyEvent.VK_C);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuLoadEntity_actionPerformed(e);
        }
    });
    loadMenu.add(item);
    item = new JMenuItem();
    item.setText("From File");
    item.setMnemonic(KeyEvent.VK_F);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuLoadEntityFromFile_actionPerformed(e);
        }
    });
    loadMenu.add(item);
    file.add(loadMenu);
    item = new JMenuItem(String.format("Current Unit"));
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.setMnemonic(KeyEvent.VK_C);
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuPrintCurrentUnit();
        }
    });
    file.add(UnitPrintManager.printMenu(parentFrame, item));
    item = new JMenuItem();
    item.setText("Save");
    item.setMnemonic(KeyEvent.VK_S);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuSaveEntity_actionPerformed(e);
        }
    });
    file.add(item);
    item = new JMenuItem();
    item.setText("Save As");
    item.setMnemonic(KeyEvent.VK_A);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuSaveAsEntity_actionPerformed(e);
        }
    });
    file.add(item);
    JMenu exportMenu = new JMenu("Export");
    item = new JMenuItem("to HTML");
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuExportEntityHTML_actionPerformed(e);
        }
    });
    exportMenu.add(item);
    item = new JMenuItem("to Text");
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuExportEntityText_actionPerformed(e);
        }
    });
    exportMenu.add(item);
    item = new JMenuItem("to Clipboard (text)");
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuExportEntityClipboard_actionPerformed(e);
        }
    });
    exportMenu.add(item);
    file.add(exportMenu);
    item = new JMenuItem("Configuration");
    item.setMnemonic(KeyEvent.VK_C);
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuConfiguration_actionPerformed(e);
        }
    });
    file.add(item);
    int fileNumber = 1;
    if (CConfig.getParam(CConfig.CONFIG_SAVE_FILE_1).length() > 1) {
        file.addSeparator();
        item = new JMenuItem();
        String newFile = CConfig.getParam(CConfig.CONFIG_SAVE_FILE_1);
        if (newFile.length() > 35) {
            item.setText(fileNumber + ". .." + newFile.substring(newFile.length() - 36));
        } else {
            item.setText(fileNumber + ". " + newFile);
        }
        item.setMnemonic(fileNumber);
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jMenuLoadEntityFromFile_actionPerformed(1);
            }
        });
        file.add(item);
        fileNumber++;
    }
    if (CConfig.getParam(CConfig.CONFIG_SAVE_FILE_2).length() > 1) {
        item = new JMenuItem();
        String newFile = CConfig.getParam(CConfig.CONFIG_SAVE_FILE_2);
        if (newFile.length() > 35) {
            item.setText(fileNumber + ". .." + newFile.substring(newFile.length() - 36));
        } else {
            item.setText(fileNumber + ". " + newFile);
        }
        item.setMnemonic(fileNumber);
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jMenuLoadEntityFromFile_actionPerformed(2);
            }
        });
        file.add(item);
        fileNumber++;
    }
    if (CConfig.getParam(CConfig.CONFIG_SAVE_FILE_3).length() > 1) {
        item = new JMenuItem();
        String newFile = CConfig.getParam(CConfig.CONFIG_SAVE_FILE_3);
        if (newFile.length() > 35) {
            item.setText(fileNumber + ". .." + newFile.substring(newFile.length() - 36));
        } else {
            item.setText(fileNumber + ". " + newFile);
        }
        item.setMnemonic(fileNumber);
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jMenuLoadEntityFromFile_actionPerformed(3);
            }
        });
        file.add(item);
        fileNumber++;
    }
    if (CConfig.getParam(CConfig.CONFIG_SAVE_FILE_4).length() > 1) {
        item = new JMenuItem();
        String newFile = CConfig.getParam(CConfig.CONFIG_SAVE_FILE_4);
        if (newFile.length() > 35) {
            item.setText(fileNumber + ". .." + newFile.substring(newFile.length() - 36));
        } else {
            item.setText(fileNumber + ". " + newFile);
        }
        item.setMnemonic(fileNumber);
        item.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jMenuLoadEntityFromFile_actionPerformed(4);
            }
        });
        file.add(item);
        fileNumber++;
    }
    file.addSeparator();
    item = new JMenuItem();
    item.setText("Exit");
    item.setMnemonic(KeyEvent.VK_X);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jMenuExit_actionPerformed(e);
        }
    });
    file.add(item);
}
Also used : Entity(megamek.common.Entity) ActionEvent(java.awt.event.ActionEvent) Tank(megamek.common.Tank) SmallCraft(megamek.common.SmallCraft) Infantry(megamek.common.Infantry) ActionListener(java.awt.event.ActionListener) Mech(megamek.common.Mech) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) Aero(megamek.common.Aero) BattleArmor(megamek.common.BattleArmor)

Aggregations

Mech (megamek.common.Mech)14 BattleArmor (megamek.common.BattleArmor)7 Aero (megamek.common.Aero)6 Entity (megamek.common.Entity)6 Tank (megamek.common.Tank)6 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 BipedMech (megamek.common.BipedMech)4 EquipmentType (megamek.common.EquipmentType)4 Infantry (megamek.common.Infantry)4 TripodMech (megamek.common.TripodMech)4 TestBattleArmor (megamek.common.verifier.TestBattleArmor)4 JMenuItem (javax.swing.JMenuItem)3 LandAirMech (megamek.common.LandAirMech)3 FileDialog (java.awt.FileDialog)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintStream (java.io.PrintStream)2 List (java.util.List)2 Vector (java.util.Vector)2