Search in sources :

Example 1 with SVGException

use of com.kitfox.svg.SVGException in project megameklab by MegaMek.

the class PrintInfantry method printImage.

public void printImage(Graphics2D g2d, PageFormat pageFormat) {
    if ((null == g2d) || (null == infantry)) {
        return;
    }
    SVGDiagram diagram;
    int stop = Math.min(4, infantryList.size() - currentPosition);
    if (stop > 3) {
        diagram = ImageHelper.loadSVGImage(new File("data/images/recordsheets/Conventional_Infantry_no_tables.svg"));
    } else {
        diagram = ImageHelper.loadSVGImage(new File("data/images/recordsheets/Conventional_Infantry_tables.svg"));
    }
    try {
        Tspan tspan = (Tspan) diagram.getElement("text_copyright");
        tspan.setText(String.format(tspan.getText(), Calendar.getInstance().get(Calendar.YEAR)));
        ((Text) tspan.getParent()).rebuild();
        diagram.render(g2d);
        for (int pos = 0; pos < stop; pos++) {
            diagram = ImageHelper.loadSVGImage(new File("data/images/recordsheets/Conventional_Infantry_platoon_" + (pos + 1) + ".svg"));
            infantry = infantryList.get(pos + currentPosition);
            tspan = (Tspan) diagram.getElement(ID_PLATOON_NAME);
            String name = infantry.getChassis();
            if (infantry.getModel().length() > 0) {
                name += " " + infantry.getModel();
            }
            if (name.length() > 48) {
                tspan.setText(infantry.getChassis());
            } else {
                tspan.setText(name);
            }
            ((Text) tspan.getParent()).rebuild();
            tspan = (Tspan) diagram.getElement(ID_ARMOR_KIT);
            EquipmentType armor = infantry.getArmorKit();
            if (armor != null) {
                tspan.setText(armor.getName());
                ((Text) tspan.getParent()).rebuild();
            } else if (infantry.hasDEST()) {
                tspan.setText("DEST");
                ((Text) tspan.getParent()).rebuild();
            } else {
                StringJoiner sj = new StringJoiner("/");
                if (infantry.hasSneakCamo()) {
                    sj.add("Camo");
                }
                if (infantry.hasSneakIR()) {
                    sj.add("IR");
                }
                if (infantry.hasSneakECM()) {
                    sj.add("ECM");
                }
                if (sj.length() > 0) {
                    tspan.setText("Sneak(" + sj.toString() + ")");
                    ((Text) tspan.getParent()).rebuild();
                }
            }
            tspan = (Tspan) diagram.getElement(ID_ARMOR_DIVISOR);
            tspan.setText(String.valueOf(infantry.getDamageDivisor() + (infantry.isArmorEncumbering() ? "E" : "")));
            ((Text) tspan.getParent()).rebuild();
            for (int j = 1; j <= 30; j++) {
                if (j > infantry.getShootingStrength()) {
                    diagram.getElement(ID_SOLDIER + j).addAttribute("display", AnimationElement.AT_XML, "none");
                    diagram.getElement(ID_NO_SOLDIER + j).removeAttribute("display", AnimationElement.AT_XML);
                } else {
                    tspan = (Tspan) diagram.getElement(ID_DAMAGE + j);
                    tspan.setText(String.valueOf((int) Math.round(infantry.getDamagePerTrooper() * j)));
                    ((Text) tspan.getParent()).rebuild();
                }
            }
            diagram.updateTime(0);
            InfantryWeapon rangeWeapon = infantry.getPrimaryWeapon();
            if (infantry.getSecondaryWeapon() != null && infantry.getSecondaryN() > 1 && !infantry.getSecondaryWeapon().hasFlag(WeaponType.F_TAG)) {
                rangeWeapon = infantry.getSecondaryWeapon();
            }
            boolean scuba = infantry.getMovementMode() == EntityMovementMode.INF_UMU || infantry.getMovementMode() == EntityMovementMode.SUBMARINE;
            if (scuba) {
                diagram.getElement(ID_UW_LABEL).removeAttribute("display", AnimationElement.AT_XML);
            }
            InfantryWeapon singleSecondary = (infantry.getSecondaryN() == 1) ? infantry.getSecondaryWeapon() : null;
            for (int j = 0; j <= 21; j++) {
                tspan = (Tspan) diagram.getElement(ID_RANGE_MOD + j);
                tspan.setText(rangeMod(j, rangeWeapon, singleSecondary, false));
                if (scuba) {
                    tspan = (Tspan) diagram.getElement(ID_UW_RANGE_MOD + j);
                    tspan.setText(rangeMod(j, rangeWeapon, singleSecondary, true));
                }
                ((Text) tspan.getParent()).rebuild();
            }
            int numGuns = 0;
            int numShots = 0;
            WeaponType gun = null;
            for (Mounted m : infantry.getEquipment()) {
                if (m.getLocation() == Infantry.LOC_FIELD_GUNS) {
                    if (m.getType() instanceof WeaponType) {
                        gun = (WeaponType) m.getType();
                        numGuns++;
                    } else if (m.getType() instanceof AmmoType) {
                        numShots += ((AmmoType) m.getType()).getShots();
                    }
                }
            }
            if (gun == null) {
                diagram.getElement(ID_FIELD_GUN_COLUMNS).addAttribute("display", AnimationElement.AT_XML, "none");
            } else {
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_QTY);
                tspan.setText(Integer.toString(numGuns));
                ((Text) tspan.getParent()).rebuild();
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_TYPE);
                tspan.setText(gun.getName());
                ((Text) tspan.getParent()).rebuild();
                /* We don't use StringUnits.getEquipmentInfo() to format the damage
					 * string because gauss explosion flags do not apply, and switchable
					 * only applies for non-LBX.
					 */
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_DMG);
                if (gun instanceof ArtilleryWeapon) {
                    tspan.setText(gun.getRackSize() + " [AE,S,F]");
                } else {
                    StringBuilder sb = new StringBuilder(Integer.toString(gun.getDamage()));
                    switch(gun.getAmmoType()) {
                        case AmmoType.T_AC_ULTRA:
                        case AmmoType.T_AC_ULTRA_THB:
                            sb.append("/Sht, R2 [DB,R/S/C]");
                            break;
                        case AmmoType.T_AC_ROTARY:
                            sb.append("/Sht, R6 [DB,R/S/C]");
                            break;
                        case AmmoType.T_AC:
                        case AmmoType.T_AC_PRIMITIVE:
                        case AmmoType.T_LAC:
                            sb.append(" [DB,C/S/F]");
                            break;
                        case AmmoType.T_AC_LBX:
                        case AmmoType.T_AC_LBX_THB:
                            sb.append(" [DB,C/F]");
                            break;
                        default:
                            sb.append(" [DB]");
                    }
                    tspan.setText(sb.toString());
                }
                ((Text) tspan.getParent()).rebuild();
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_MIN_RANGE);
                if (gun.getMinimumRange() > 0) {
                    tspan.setText(Integer.toString(gun.getMinimumRange()));
                } else {
                    tspan.setText("—");
                }
                ((Text) tspan.getParent()).rebuild();
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_SHORT);
                tspan.setText(Integer.toString(gun.getShortRange()));
                ((Text) tspan.getParent()).rebuild();
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_MED);
                tspan.setText(Integer.toString(gun.getMediumRange()));
                ((Text) tspan.getParent()).rebuild();
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_LONG);
                tspan.setText(Integer.toString(gun.getLongRange()));
                ((Text) tspan.getParent()).rebuild();
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_AMMO);
                tspan.setText(Integer.toString(numShots));
                ((Text) tspan.getParent()).rebuild();
                tspan = (Tspan) diagram.getElement(ID_FIELD_GUN_CREW);
                tspan.setText(Integer.toString((int) Math.ceil(gun.getTonnage(infantry))));
                ((Text) tspan.getParent()).rebuild();
            }
            if (infantry.hasDEST()) {
                diagram.getElement(ID_DEST_MODS).removeAttribute("display", AnimationElement.AT_XML);
                diagram.getElement(ID_SNEAK_IR_MODS).removeAttribute("display", AnimationElement.AT_XML);
            } else if (infantry.hasSneakCamo()) {
                diagram.getElement(ID_SNEAK_CAMO_MODS).removeAttribute("display", AnimationElement.AT_XML);
            }
            if (infantry.hasSneakIR()) {
                diagram.getElement(ID_SNEAK_IR_MODS).removeAttribute("display", AnimationElement.AT_XML);
            }
            tspan = (Tspan) diagram.getElement(ID_BV);
            tspan.setText(Integer.toString(infantry.calculateBattleValue()));
            ((Text) tspan.getParent()).rebuild();
            tspan = (Tspan) diagram.getElement(ID_TRANSPORT_WT);
            tspan.setText(String.format("%.1f tons", infantry.getWeight()));
            ((Text) tspan.getParent()).rebuild();
            Tspan mp1 = (Tspan) diagram.getElement(ID_MP_1);
            Tspan mode1 = (Tspan) diagram.getElement(ID_MODE_1);
            Tspan mp2 = (Tspan) diagram.getElement(ID_MP_2);
            Tspan mode2 = (Tspan) diagram.getElement(ID_MODE_2);
            switch(infantry.getMovementMode()) {
                case INF_JUMP:
                    mp1.setText(Integer.toString(infantry.getJumpMP(false)));
                    mode1.setText("Jump");
                    mp2.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
                    mode2.setText("Ground");
                    ((Text) mp2.getParent()).rebuild();
                    ((Text) mode2.getParent()).rebuild();
                    break;
                case INF_UMU:
                    mp1.setText(Integer.toString(infantry.getActiveUMUCount()));
                    if (infantry.getOriginalJumpMP() > 1) {
                        mode1.setText("SCUBA (Motorized)");
                    } else {
                        mode1.setText("SCUBA");
                    }
                    mp2.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
                    mode2.setText("Ground");
                    ((Text) mp2.getParent()).rebuild();
                    ((Text) mode2.getParent()).rebuild();
                    break;
                case HOVER:
                    mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
                    mode1.setText("Mechanized Hover");
                    break;
                case TRACKED:
                    mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
                    mode1.setText("Mechanized Tracked");
                    break;
                case WHEELED:
                    mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
                    mode1.setText("Mechanized Wheeled");
                    break;
                case VTOL:
                    mp1.setText(Integer.toString(infantry.getJumpMP(false)));
                    if (infantry.hasMicrolite()) {
                        mode1.setText("VTOL (Microlite)");
                    } else {
                        mode1.setText("VTOL (Micro-copter)");
                    }
                    break;
                case SUBMARINE:
                    mp1.setText(Integer.toString(infantry.getActiveUMUCount()));
                    mode1.setText("Mechanized SCUBA");
                    break;
                case INF_MOTORIZED:
                    mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
                    mode1.setText("Motorized");
                    break;
                case INF_LEG:
                default:
                    mp1.setText(Integer.toString(infantry.getWalkMP(true, true, false)));
                    mode1.setText("Ground");
                    break;
            }
            if (mp1.getText().equals("0")) {
                mp1.setText("0*");
            }
            ((Text) mp1.getParent()).rebuild();
            ((Text) mode1.getParent()).rebuild();
            List<String> notes = new ArrayList<>();
            if (infantry.isMechanized() || infantry.isArmorEncumbering()) {
                notes.add("Cannot make anti-'Mech attacks.");
            }
            if (infantry.hasSpaceSuit()) {
                notes.add("Can operate in vacuum.");
            }
            if (rangeWeapon.hasFlag(WeaponType.F_INF_BURST)) {
                notes.add("+1D6 damage vs. conventional infantry.");
            }
            if (rangeWeapon.hasFlag(WeaponType.F_INF_NONPENETRATING)) {
                notes.add("Can only damage conventional infantry.");
            }
            if (infantry.getPrimaryWeapon().hasFlag(WeaponType.F_INFERNO) || (infantry.getSecondaryWeapon() != null && infantry.getSecondaryWeapon().hasFlag(WeaponType.F_INFERNO))) {
                notes.add("Flame-based weapon.");
            } else {
                for (int i = 0; i < infantry.getPrimaryWeapon().getModesCount(); i++) {
                    if (infantry.getPrimaryWeapon().getMode(i).equals("Heat")) {
                        notes.add("Flame-based weapon.");
                        break;
                    }
                }
                if (infantry.getSecondaryWeapon() != null) {
                    for (int i = 0; i < infantry.getSecondaryWeapon().getModesCount(); i++) {
                        if (infantry.getSecondaryWeapon().getMode(i).equals("Heat")) {
                            notes.add("Flame-based weapon.");
                        }
                    }
                }
            }
            if (infantry.getPrimaryWeapon().hasFlag(WeaponType.F_INF_AA) || (infantry.getSecondaryWeapon() != null && infantry.getSecondaryWeapon().hasFlag(WeaponType.F_INF_AA))) {
                notes.add("Can attack airborn units.");
            }
            if (infantry.hasSpecialization(Infantry.BRIDGE_ENGINEERS)) {
                notes.add("Bridge-building equipment");
            }
            if (infantry.hasSpecialization(Infantry.DEMO_ENGINEERS)) {
                notes.add("Equipped with demolition gear");
            }
            if (infantry.hasSpecialization(Infantry.FIRE_ENGINEERS)) {
                notes.add("Firefighting equipment");
            }
            if (infantry.hasSpecialization(Infantry.MINE_ENGINEERS)) {
                notes.add("Minesweeper equipment");
            }
            if (infantry.hasSpecialization(Infantry.TRENCH_ENGINEERS)) {
                notes.add("Trench/Fieldwork equipment");
            }
            if (infantry.hasSpecialization(Infantry.MARINES)) {
                notes.add("No penalties for vacuum or zero-G");
            }
            if (infantry.hasSpecialization(Infantry.MOUNTAIN_TROOPS)) {
                notes.add("Mountain climbing equipment");
            }
            if (infantry.hasSpecialization(Infantry.PARAMEDICS)) {
                notes.add("Paramedic equipment.");
            }
            if (infantry.hasSpecialization(Infantry.PARATROOPS)) {
                notes.add("Can make atmospheric drops.");
            }
            if (infantry.hasSpecialization(Infantry.SENSOR_ENGINEERS)) {
                notes.add("Surveillance and communication equipment");
            }
            if (infantry.hasSpecialization(Infantry.TAG_TROOPS)) {
                notes.add("Equipped with TAG (Range 3/6/9)");
            }
            if (infantry.hasSneakECM()) {
                notes.add("Invisible to standard/light active probes.");
            }
            for (int i = 0; i < Math.min(8, notes.size()); i++) {
                tspan = (Tspan) diagram.getElement(ID_NOTE_LINE + i);
                tspan.setText(notes.get(i));
            }
            ((Text) diagram.getElement(ID_NOTES)).rebuild();
            diagram.updateTime(0);
            diagram.render(g2d);
        }
    } catch (SVGException ex) {
        ex.printStackTrace();
    }
    g2d.scale(pageFormat.getImageableWidth(), pageFormat.getImageableHeight());
}
Also used : SVGException(com.kitfox.svg.SVGException) ArrayList(java.util.ArrayList) Text(com.kitfox.svg.Text) Tspan(com.kitfox.svg.Tspan) EquipmentType(megamek.common.EquipmentType) AmmoType(megamek.common.AmmoType) SVGDiagram(com.kitfox.svg.SVGDiagram) ArtilleryWeapon(megamek.common.weapons.artillery.ArtilleryWeapon) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) File(java.io.File) StringJoiner(java.util.StringJoiner) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon)

Example 2 with SVGException

use of com.kitfox.svg.SVGException in project megameklab by MegaMek.

the class PrintBattleArmor method printBattleArmorData.

private void printBattleArmorData(Graphics2D g2d, int squadNumber) {
    String battleArmorName = battleArmor.getChassis() + " " + battleArmor.getModel();
    g2d.setFont(UnitUtil.getNewFont(g2d, battleArmorName, true, 85, 8.0f));
    g2d.drawString(battleArmorName, 53, 107.6f + currentMargin);
    Font font = UnitUtil.deriveFont(8.0f);
    g2d.setFont(font);
    if ((battleArmor.getSource() != null) && (battleArmor.getSource().trim().length() > 0)) {
        String sourceFluff = "Era: ";
        font = UnitUtil.deriveFont(true, 8.0f);
        g2d.setFont(font);
        g2d.drawString(sourceFluff, 143, 107.6f + currentMargin);
        font = UnitUtil.deriveFont(8.0f);
        g2d.setFont(font);
        g2d.drawString(battleArmor.getSource(), 158, 107.6f + currentMargin);
    } else {
        String yearFluff = "Year: ";
        font = UnitUtil.deriveFont(true, 8.0f);
        g2d.setFont(font);
        g2d.drawString(yearFluff, 143, 107.6f + currentMargin);
        font = UnitUtil.deriveFont(8.0f);
        g2d.setFont(font);
        g2d.drawString(String.format(" %1$s", battleArmor.getYear()), 161, 107.6f + currentMargin);
    }
    font = UnitUtil.deriveFont(true, 10.0f);
    g2d.setFont(font);
    String techBase = "IS";
    if (battleArmor.isMixedTech()) {
        if (battleArmor.isClan()) {
            techBase = "Mixed Clan";
        } else {
            techBase = "Mixed IS";
        }
    } else if (battleArmor.isClan()) {
        techBase = "Clan";
    }
    if (!isAdvanced && ((battleArmor.getTechLevel() == TechConstants.T_IS_ADVANCED) || (battleArmor.getTechLevel() == TechConstants.T_CLAN_ADVANCED))) {
        techBase += " (Advanced)";
        isAdvanced = true;
    } else if (!isAdvanced && ((battleArmor.getTechLevel() == TechConstants.T_IS_EXPERIMENTAL) || (battleArmor.getTechLevel() == TechConstants.T_CLAN_EXPERIMENTAL))) {
        techBase += " (Experimental)";
        isAdvanced = true;
    }
    if (squadNumber == 0) {
        ImageHelper.printCenterString(g2d, techBase, g2d.getFont(), 520, 64);
    }
    font = UnitUtil.deriveFont(8.0f);
    g2d.setFont(font);
    String groundMP = Integer.toString(battleArmor.getWalkMP(true, true, false, false, false));
    if (battleArmor.hasDWP()) {
        groundMP = groundMP + " [" + Integer.toString(battleArmor.getWalkMP(true, true, false, true, false)) + "]";
    }
    g2d.drawString(groundMP, 78, 131.3f + currentMargin);
    int jumpMP = battleArmor.getJumpMP(true, true, true);
    int umuMP = battleArmor.getActiveUMUCount();
    if ((jumpMP > 0) && (umuMP == 0)) {
        font = UnitUtil.deriveFont(true, 8.0f);
        g2d.setFont(font);
        String movment = String.format("%1$s: ", battleArmor.getMovementModeAsString());
        g2d.drawString(movment, 143, 131.3f + currentMargin);
        float positionX = 143 + ImageHelper.getStringWidth(g2d, movment, font);
        font = UnitUtil.deriveFont(8.0f);
        g2d.setFont(font);
        String printString = Integer.toString(jumpMP);
        if (battleArmor.hasDWP() || battleArmor.isBurdened()) {
            printString = "[" + printString + "]";
        }
        g2d.drawString(printString, positionX, 131.3f + currentMargin);
    } else if ((umuMP > 0) && (jumpMP == 0)) {
        font = UnitUtil.deriveFont(true, 8.0f);
        g2d.setFont(font);
        String movment = String.format("%1$s: ", battleArmor.getMovementModeAsString());
        g2d.drawString(movment, 143, 131.3f + currentMargin);
        float positionX = 143 + ImageHelper.getStringWidth(g2d, movment, font);
        font = UnitUtil.deriveFont(8.0f);
        g2d.setFont(font);
        String printString = Integer.toString(umuMP);
        if (battleArmor.hasDWP() || battleArmor.isBurdened()) {
            printString = "[" + printString + "]";
        }
        g2d.drawString(printString, positionX, 131.3f + currentMargin);
    } else if ((umuMP > 0) && (jumpMP > 0)) {
        font = UnitUtil.deriveFont(true, 8.0f);
        g2d.setFont(font);
        String movment = "Jump: ";
        g2d.drawString(movment, 110, 131.3f + currentMargin);
        float positionX = 110 + ImageHelper.getStringWidth(g2d, movment, font);
        font = UnitUtil.deriveFont(8.0f);
        g2d.setFont(font);
        String printString = Integer.toString(jumpMP);
        if (battleArmor.hasDWP() || battleArmor.isBurdened()) {
            printString = "[" + printString + "]";
        }
        g2d.drawString(printString, positionX, 131.3f + currentMargin);
        movment = String.format("%1$s: ", battleArmor.getMovementModeAsString());
        font = UnitUtil.deriveFont(true, 8.0f);
        g2d.setFont(font);
        g2d.drawString(movment, 160, 131.3f + currentMargin);
        positionX = 160 + ImageHelper.getStringWidth(g2d, movment, font);
        font = UnitUtil.deriveFont(8.0f);
        g2d.setFont(font);
        printString = Integer.toString(umuMP);
        if (battleArmor.hasDWP() || battleArmor.isBurdened()) {
            printString = "[" + printString + "]";
        }
        g2d.drawString(printString, positionX, 131.3f + currentMargin);
    }
    // Cost/BV
    // DecimalFormatSymbols unusualSymbols =
    // new DecimalFormatSymbols();
    // unusualSymbols.setDecimalSeparator('.');
    // unusualSymbols.setGroupingSeparator(',');
    // DecimalFormat myFormatter = new DecimalFormat("#,###",
    // unusualSymbols);
    double bv = battleArmor.calculateBattleValue(true, true);
    if (bv != -1) {
        font = UnitUtil.deriveFont(true, 8);
        g2d.setFont(font);
        g2d.drawString("BV: ", 230, 209.5f + currentMargin);
        font = UnitUtil.deriveFont(false, 8);
        g2d.setFont(font);
        g2d.drawString(String.format("%1$,d", battleArmor.calculateBattleValue(true, true)) + "/" + String.format("%1$,d", battleArmor.calculateBattleValue(true, true, true)), 245, 209.5f + currentMargin);
    }
    if (battleArmor.canDoMechanizedBA()) {
        try {
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/BA/Mechanized" + squadNumber + ".svg")).render(g2d);
        } catch (SVGException e) {
            e.printStackTrace();
        }
    }
    if (UnitUtil.canSwarm(battleArmor)) {
        try {
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/BA/Swarm" + squadNumber + ".svg")).render(g2d);
        } catch (SVGException e) {
            e.printStackTrace();
        }
    }
    if (UnitUtil.canLegAttack(battleArmor)) {
        try {
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/BA/Leg" + squadNumber + ".svg")).render(g2d);
        } catch (SVGException e) {
            e.printStackTrace();
        }
    }
    if (battleArmor.countWorkingMisc(MiscType.F_AP_MOUNT) > 0) {
        try {
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/BA/AP" + squadNumber + ".svg")).render(g2d);
        } catch (SVGException e) {
            e.printStackTrace();
        }
    }
// myFormatter = new DecimalFormat("#,###.##");
// g2d.drawString(myFormatter.format(battleArmor.getCost(true)) +
// " C-bills", 235, 206 + currentMargin);
}
Also used : SVGException(com.kitfox.svg.SVGException) File(java.io.File) Font(java.awt.Font)

Example 3 with SVGException

use of com.kitfox.svg.SVGException in project megameklab by MegaMek.

the class PrintLargeSupportVehicle method printImage.

public void printImage(Graphics2D g2d, PageFormat pageFormat) {
    if (g2d == null) {
        return;
    }
    System.gc();
    try {
        if (largesupporttank instanceof SuperHeavyTank) {
            try {
                ImageHelper.loadSVGImage(new File("data/images/recordsheets/SuperHeavyTankCritTable.svg")).render(g2d);
            } catch (SVGException e) {
                e.printStackTrace();
            }
        } else {
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/LargeSupportTankCritTable.svg")).render(g2d);
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/LargeSupportTankHitTable.svg")).render(g2d);
        }
        ImageHelper.loadSVGImage(new File("data/images/recordsheets/TankMotiveDmgTable.svg")).render(g2d);
        ImageHelper.loadSVGImage(new File("data/images/recordsheets/TankSheetCopyrightInfo.svg")).render(g2d);
        ImageHelper.loadSVGImage(new File("data/images/recordsheets/SuperHeavyBaseTemplate.svg")).render(g2d);
        if (largesupporttank.hasNoTurret()) {
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/SuperHeavyNoTurretTemplate.svg")).render(g2d);
        } else if (largesupporttank.hasNoDualTurret()) {
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/SuperHeavySingleTurretTemplate.svg")).render(g2d);
        } else {
            ImageHelper.loadSVGImage(new File("data/images/recordsheets/SuperHeavyDualTurretTemplate.svg")).render(g2d);
        }
    } catch (SVGException e) {
        e.printStackTrace();
    }
    printLargeSupportTankData(g2d);
    printArmor(g2d);
    printWeaponsNEquipment(g2d);
    // Armor Pips
    printFrontArmor(g2d, largesupporttank.getOArmor(Tank.LOC_FRONT), false);
    printFrontLeftArmor(g2d, largesupporttank.getOArmor(LargeSupportTank.LOC_FRONTLEFT), false);
    printFrontRightArmor(g2d, largesupporttank.getOArmor(LargeSupportTank.LOC_FRONTRIGHT), false);
    printRearLeftArmor(g2d, largesupporttank.getOArmor(LargeSupportTank.LOC_REARLEFT), false);
    printRearRightArmor(g2d, largesupporttank.getOArmor(LargeSupportTank.LOC_REARRIGHT), false);
    printRearArmor(g2d, largesupporttank.getOArmor(LargeSupportTank.LOC_REAR), false);
    if (!largesupporttank.hasNoTurret()) {
        printTurretArmor(g2d, largesupporttank.getOArmor(LargeSupportTank.LOC_TURRET), false);
    }
    if (!largesupporttank.hasNoDualTurret()) {
        printFrontTurretArmor(g2d, largesupporttank.getOArmor(LargeSupportTank.LOC_TURRET_2));
    }
    // Internal Pips
    printFrontStruct(g2d, largesupporttank.getOInternal(Tank.LOC_FRONT), false);
    printLeftFrontStruct(g2d, largesupporttank.getOInternal(LargeSupportTank.LOC_FRONTLEFT), false);
    printRightFrontStruct(g2d, largesupporttank.getOInternal(LargeSupportTank.LOC_REARRIGHT), false);
    printLeftRearStruct(g2d, largesupporttank.getOInternal(LargeSupportTank.LOC_REARLEFT), false);
    printRightRearStruct(g2d, largesupporttank.getOInternal(LargeSupportTank.LOC_REARRIGHT), false);
    printRearStruct(g2d, largesupporttank.getOInternal(LargeSupportTank.LOC_REAR), false);
    if (!largesupporttank.hasNoTurret()) {
        printTurretStruct(g2d, largesupporttank.getOInternal(LargeSupportTank.LOC_TURRET), false);
    }
    if (!largesupporttank.hasNoDualTurret()) {
        printFrontTurretStruct(g2d, largesupporttank.getOInternal(LargeSupportTank.LOC_TURRET_2));
    }
    printLargeSupportTankImage(g2d);
    g2d.scale(pageFormat.getImageableWidth(), pageFormat.getImageableHeight());
}
Also used : SuperHeavyTank(megamek.common.SuperHeavyTank) SVGException(com.kitfox.svg.SVGException) File(java.io.File)

Example 4 with SVGException

use of com.kitfox.svg.SVGException in project pivot by apache.

the class Pivot964Pivot method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    // force dimensions for host frame
    display.getHostWindow().setSize(1028, 600);
    window = new Window();
    prepareSVG();
    final ImageView image = new ImageView(new Drawing(diagram));
    BoxPane bp = new BoxPane();
    TablePane tp = new TablePane();
    setStyles(tp, "{padding: 4}");
    TablePane.Column c1 = new TablePane.Column(-1);
    TablePane.Column c2 = new TablePane.Column(-1);
    tp.getColumns().add(c1);
    tp.getColumns().add(c2);
    TablePane.Row r1 = new TablePane.Row(-1);
    TablePane.Row r2 = new TablePane.Row(-1);
    TablePane.Row r3 = new TablePane.Row(-1);
    PushButton pb1 = new PushButton("Visible");
    PushButton pb2 = new PushButton("Invisible (bug)");
    r1.add(pb1);
    r1.add(pb2);
    final Spinner sp1 = new Spinner(new ListAdapter<>(spinnerData));
    sp1.setPreferredWidth(80);
    sp1.setSelectedIndex(0);
    final Spinner sp2 = new Spinner(new ListAdapter<>(spinnerData));
    sp2.setPreferredWidth(80);
    sp2.setSelectedIndex(0);
    BoxPane bp1 = new BoxPane();
    setStyles(bp1, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp1.add(new Label("X:"));
    bp1.add(sp1);
    r2.add(bp1);
    BoxPane bp2 = new BoxPane();
    setStyles(bp2, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp2.add(new Label("Y:"));
    bp2.add(sp2);
    r2.add(bp2);
    tp.getRows().add(r1);
    tp.getRows().add(r2);
    r3.add(new Label("   Max X=507"));
    r3.add(new Label("   Max Y=269"));
    tp.getRows().add(r3);
    bp.add(image);
    bp.add(tp);
    pb1.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    pb2.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                String xOffset = (String) sp1.getSelectedItem();
                String yOffset = (String) sp2.getSelectedItem();
                String viewBox = String.format("%1$s %2$s 2368 1652", xOffset, yOffset);
                root.setAttribute("viewBox", AnimationElement.AT_XML, viewBox);
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    window.setContent(bp);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Drawing(org.apache.pivot.wtk.media.Drawing) Spinner(org.apache.pivot.wtk.Spinner) SVGException(com.kitfox.svg.SVGException) Label(org.apache.pivot.wtk.Label) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ImageView(org.apache.pivot.wtk.ImageView) SVGElementException(com.kitfox.svg.SVGElementException) PushButton(org.apache.pivot.wtk.PushButton) TablePane(org.apache.pivot.wtk.TablePane)

Example 5 with SVGException

use of com.kitfox.svg.SVGException in project pivot by apache.

the class Drawing method setSize.

public void setSize(int width, int height) {
    int previousWidth = getWidth();
    int previousHeight = getHeight();
    SVGRoot root = diagram.getRoot();
    try {
        root.setAttribute("width", AnimationElement.AT_XML, Integer.toString(width));
        root.setAttribute("height", AnimationElement.AT_XML, Integer.toString(height));
    } catch (SVGElementException exception) {
        throw new RuntimeException(exception);
    }
    try {
        diagram.updateTime(0.0);
    } catch (SVGException exception) {
        throw new RuntimeException(exception);
    }
    imageListeners.sizeChanged(this, previousWidth, previousHeight);
}
Also used : SVGRoot(com.kitfox.svg.SVGRoot) SVGException(com.kitfox.svg.SVGException) SVGElementException(com.kitfox.svg.SVGElementException)

Aggregations

SVGException (com.kitfox.svg.SVGException)8 File (java.io.File)5 SVGElementException (com.kitfox.svg.SVGElementException)3 Font (java.awt.Font)3 SVGDiagram (com.kitfox.svg.SVGDiagram)1 SVGElement (com.kitfox.svg.SVGElement)1 SVGRoot (com.kitfox.svg.SVGRoot)1 Text (com.kitfox.svg.Text)1 Tspan (com.kitfox.svg.Tspan)1 BorderLayout (java.awt.BorderLayout)1 ArrayList (java.util.ArrayList)1 StringJoiner (java.util.StringJoiner)1 JPanel (javax.swing.JPanel)1 AmmoType (megamek.common.AmmoType)1 EquipmentType (megamek.common.EquipmentType)1 Mounted (megamek.common.Mounted)1 SuperHeavyTank (megamek.common.SuperHeavyTank)1 WeaponType (megamek.common.WeaponType)1 ArtilleryWeapon (megamek.common.weapons.artillery.ArtilleryWeapon)1 InfantryWeapon (megamek.common.weapons.infantry.InfantryWeapon)1