Search in sources :

Example 1 with TestEntity

use of megamek.common.verifier.TestEntity in project megameklab by MegaMek.

the class UnitUtil method showUnitWeightBreakDown.

public static void showUnitWeightBreakDown(Entity unit, JFrame frame) {
    TestEntity testEntity = getEntityVerifier(unit);
    JTextPane textPane = new JTextPane();
    JScrollPane scroll = new JScrollPane();
    textPane.setText(testEntity.printEntity().toString());
    textPane.setEditable(false);
    textPane.setCaret(new DefaultCaret());
    scroll.setViewportView(textPane);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    scroll.setVisible(true);
    JDialog jdialog = new JDialog();
    jdialog.add(scroll);
    Dimension size = new Dimension(CConfig.getIntParam("WINDOWWIDTH") / 2, CConfig.getIntParam("WINDOWHEIGHT"));
    jdialog.setPreferredSize(size);
    jdialog.setMinimumSize(size);
    scroll.setPreferredSize(size);
    scroll.setMinimumSize(size);
    jdialog.setLocationRelativeTo(frame);
    jdialog.setVisible(true);
    try {
        textPane.setSelectionStart(0);
        textPane.setSelectionEnd(0);
    } catch (Exception ex) {
    }
}
Also used : TestEntity(megamek.common.verifier.TestEntity) JScrollPane(javax.swing.JScrollPane) JTextPane(javax.swing.JTextPane) DefaultCaret(javax.swing.text.DefaultCaret) Dimension(java.awt.Dimension) JDialog(javax.swing.JDialog) LocationFullException(megamek.common.LocationFullException)

Example 2 with TestEntity

use of megamek.common.verifier.TestEntity in project megameklab by MegaMek.

the class UnitUtil method getEntityVerifier.

/**
 * Returns a TestEntity instance for the supplied Entity.
 *
 * @param unit
 * @return
 */
public static TestEntity getEntityVerifier(Entity unit) {
    EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
    TestEntity testEntity = null;
    if (unit.hasETypeFlag(Entity.ETYPE_MECH)) {
        testEntity = new TestMech((Mech) unit, entityVerifier.mechOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_SUPPORT_TANK)) {
        testEntity = new TestSupportVehicle((Tank) unit, entityVerifier.tankOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_TANK)) {
        testEntity = new TestTank((Tank) unit, entityVerifier.tankOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
        testEntity = new TestSmallCraft((SmallCraft) unit, entityVerifier.aeroOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_AERO)) {
        testEntity = new TestAero((Aero) unit, entityVerifier.aeroOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_BATTLEARMOR)) {
        testEntity = new TestBattleArmor((BattleArmor) unit, entityVerifier.baOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_INFANTRY)) {
        testEntity = new TestInfantry((Infantry) unit, entityVerifier.infOption, null);
    }
    return testEntity;
}
Also used : TestEntity(megamek.common.verifier.TestEntity) EntityVerifier(megamek.common.verifier.EntityVerifier) TestTank(megamek.common.verifier.TestTank) TestAero(megamek.common.verifier.TestAero) TestBattleArmor(megamek.common.verifier.TestBattleArmor) TestTank(megamek.common.verifier.TestTank) Tank(megamek.common.Tank) Infantry(megamek.common.Infantry) TestInfantry(megamek.common.verifier.TestInfantry) TestMech(megamek.common.verifier.TestMech) TestSupportVehicle(megamek.common.verifier.TestSupportVehicle) TestSmallCraft(megamek.common.verifier.TestSmallCraft) Mech(megamek.common.Mech) TestMech(megamek.common.verifier.TestMech) TripodMech(megamek.common.TripodMech) BipedMech(megamek.common.BipedMech) LandAirMech(megamek.common.LandAirMech) QuadMech(megamek.common.QuadMech) File(java.io.File) Aero(megamek.common.Aero) TestAero(megamek.common.verifier.TestAero) TestInfantry(megamek.common.verifier.TestInfantry)

Example 3 with TestEntity

use of megamek.common.verifier.TestEntity in project megameklab by MegaMek.

the class UnitUtil method validateUnit.

/**
 * check that the unit is vaild
 *
 * @param unit
 * @return
 */
public static String validateUnit(Entity unit) {
    StringBuffer sb = new StringBuffer();
    TestEntity testEntity = getEntityVerifier(unit);
    if (testEntity != null) {
        testEntity.correctEntity(sb, unit.getTechLevel());
    }
    return sb.toString();
}
Also used : TestEntity(megamek.common.verifier.TestEntity)

Aggregations

TestEntity (megamek.common.verifier.TestEntity)3 Dimension (java.awt.Dimension)1 File (java.io.File)1 JDialog (javax.swing.JDialog)1 JScrollPane (javax.swing.JScrollPane)1 JTextPane (javax.swing.JTextPane)1 DefaultCaret (javax.swing.text.DefaultCaret)1 Aero (megamek.common.Aero)1 BipedMech (megamek.common.BipedMech)1 Infantry (megamek.common.Infantry)1 LandAirMech (megamek.common.LandAirMech)1 LocationFullException (megamek.common.LocationFullException)1 Mech (megamek.common.Mech)1 QuadMech (megamek.common.QuadMech)1 Tank (megamek.common.Tank)1 TripodMech (megamek.common.TripodMech)1 EntityVerifier (megamek.common.verifier.EntityVerifier)1 TestAero (megamek.common.verifier.TestAero)1 TestBattleArmor (megamek.common.verifier.TestBattleArmor)1 TestInfantry (megamek.common.verifier.TestInfantry)1