Search in sources :

Example 1 with TextAttribute

use of java.awt.font.TextAttribute in project megameklab by MegaMek.

the class ImageHelper method printMechWeaponsNEquipment.

public static void printMechWeaponsNEquipment(Mech mech, Graphics2D g2d, int leftMargin, int topMargin) {
    int qtyPoint = 26 + leftMargin;
    int typePoint = 38 + leftMargin;
    int locPoint = 105 + leftMargin;
    int heatPoint = 118 + leftMargin;
    int damagePoint = 145 + leftMargin;
    int minPoint = 167 + leftMargin;
    int shtPoint = 183 + leftMargin;
    int medPoint = 199 + leftMargin;
    int longPoint = 215 + leftMargin;
    float linePoint = 202f + topMargin;
    float lineFeed = 6.7f;
    boolean newLineNeeded = false;
    ArrayList<Hashtable<String, EquipmentInfo>> equipmentLocations = new ArrayList<Hashtable<String, EquipmentInfo>>(Mech.LOC_LLEG + 1);
    for (int pos = 0; pos <= Mech.LOC_LLEG; pos++) {
        equipmentLocations.add(pos, new Hashtable<String, EquipmentInfo>());
    }
    for (Mounted eq : mech.getEquipment()) {
        if ((eq.getType() instanceof AmmoType) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(eq.getType(), true)) {
            continue;
        }
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(eq.getLocation());
        String equipmentName = eq.getName();
        if (eq.isRearMounted()) {
            equipmentName += " (R)";
        }
        if (eq.isMechTurretMounted()) {
            equipmentName += " (T)";
        }
        if (eqHash.containsKey(equipmentName)) {
            EquipmentInfo eqi = eqHash.get(equipmentName);
            if (eq.getType().getTechLevel(mech.getTechLevelYear()) != eqi.techLevel) {
                eqi = new EquipmentInfo(mech, eq);
            } else {
                eqi.count++;
            }
            eqHash.put(equipmentName, eqi);
        } else {
            EquipmentInfo eqi = new EquipmentInfo(mech, eq);
            eqHash.put(equipmentName, eqi);
        }
    }
    Font font = UnitUtil.deriveFont(true, 10.0f);
    g2d.setFont(font);
    HashMap<TextAttribute, Object> strikeThroughAttr = new HashMap<TextAttribute, Object>();
    strikeThroughAttr.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    for (int pos = Mech.LOC_HEAD; pos <= Mech.LOC_LLEG; pos++) {
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(pos);
        if (eqHash.size() < 1) {
            continue;
        }
        int count = 0;
        ArrayList<EquipmentInfo> equipmentList = new ArrayList<EquipmentInfo>();
        for (EquipmentInfo eqi : eqHash.values()) {
            equipmentList.add(eqi);
        }
        Collections.sort(equipmentList, StringUtils.equipmentInfoComparator());
        for (EquipmentInfo eqi : equipmentList) {
            newLineNeeded = false;
            if (count >= 12) {
                break;
            }
            font = UnitUtil.deriveFont(7.0f);
            g2d.setFont(font);
            g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
            String name = eqi.name.trim();
            Font nameFont = UnitUtil.getNewFont(g2d, name, false, 60, 7.0f);
            if (eqi.isDestroyed) {
                nameFont = nameFont.deriveFont(strikeThroughAttr);
            }
            g2d.setFont(nameFont);
            if (eqi.c3Level == EquipmentInfo.C3I) {
                ImageHelper.printC3iName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3EM) {
                ImageHelper.printC3EmName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3S) {
                ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3M) {
                ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3SB) {
                ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3MB) {
                ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
                ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else {
                g2d.drawString(name, typePoint, linePoint);
            }
            Font locFont = UnitUtil.getNewFont(g2d, eqi.loc, false, 15, 7.0f);
            g2d.setFont(locFont);
            ImageHelper.printCenterString(g2d, eqi.loc, font, locPoint, linePoint);
            g2d.setFont(UnitUtil.deriveFont(7));
            if (eqi.isWeapon) {
                g2d.drawString(Integer.toString(eqi.heat), heatPoint, linePoint);
                if (eqi.isMML) {
                    ImageHelper.printCenterString(g2d, "[M,C,S]", font, damagePoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("LRM", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "1/Msl", font, damagePoint, linePoint);
                    g2d.drawString("6", minPoint, linePoint);
                    g2d.drawString("7", shtPoint, linePoint);
                    g2d.drawString("14", medPoint, linePoint);
                    g2d.drawString("21", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("SRM", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "2/Msl", font, damagePoint, linePoint);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
                    // + 6, (int) linePoint - 2);
                    g2d.drawString("3", shtPoint, linePoint);
                    g2d.drawString("6", medPoint, linePoint);
                    g2d.drawString("9", longPoint, linePoint);
                } else if (eqi.isATM) {
                    ImageHelper.printCenterString(g2d, "[M,C,S]", font, damagePoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("Standard", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "2/Msl", font, damagePoint, linePoint);
                    g2d.drawString("4", minPoint, linePoint);
                    g2d.drawString("5", shtPoint, linePoint);
                    g2d.drawString("10", medPoint, linePoint);
                    g2d.drawString("15", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("Extended-Range", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "1/Msl", font, damagePoint, linePoint);
                    g2d.drawString("4", minPoint, linePoint);
                    g2d.drawString("9", shtPoint, linePoint);
                    g2d.drawString("18", medPoint, linePoint);
                    g2d.drawString("27", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("High-Explosive", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "3/Msl", font, damagePoint, linePoint);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
                    // + 6, (int) linePoint - 2);
                    g2d.drawString("3", shtPoint, linePoint);
                    g2d.drawString("6", medPoint, linePoint);
                    g2d.drawString("9", longPoint, linePoint);
                } else if (eqi.isAMS) {
                    ImageHelper.printCenterString(g2d, "\u2014 [PD]", font, damagePoint, linePoint);
                    // g2d.drawLine(damagePoint - 9, (int) linePoint - 2,
                    // damagePoint - 3, (int) linePoint - 2);
                    // ImageHelper.printCenterString(g2d, "[PD]", font,
                    // damagePoint+4, linePoint);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    g2d.drawString("\u2014", shtPoint, linePoint);
                    g2d.drawString("\u2014", medPoint, linePoint);
                    g2d.drawString("\u2014", longPoint, linePoint);
                // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
                // + 6, (int) linePoint - 2);
                // g2d.drawLine(shtPoint, (int) linePoint - 2, shtPoint
                // + 6, (int) linePoint - 2);
                // g2d.drawLine(medPoint, (int) linePoint - 2, medPoint
                // + 6, (int) linePoint - 2);
                // g2d.drawLine(longPoint, (int) linePoint - 2,
                // longPoint + 6, (int) linePoint - 2);
                } else if (eqi.isCenturion) {
                    ImageHelper.printCenterString(g2d, "0", font, damagePoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
                    // + 6, (int) linePoint - 2);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    g2d.drawString("6(1)", shtPoint - 1, linePoint);
                    g2d.drawString("12(2)", medPoint - 6, linePoint);
                    g2d.drawString("18(3)", longPoint - 4, linePoint);
                } else {
                    if (ImageHelper.getStringWidth(g2d, eqi.damage.trim(), font) > 22) {
                        font = UnitUtil.deriveFont(6.0f);
                        g2d.setFont(font);
                        ImageHelper.printCenterString(g2d, eqi.damage.substring(0, eqi.damage.indexOf('[')), font, damagePoint, linePoint);
                        font = UnitUtil.deriveFont(7.0f);
                        g2d.setFont(font);
                        ImageHelper.printCenterString(g2d, eqi.damage.substring(eqi.damage.indexOf('[')), font, damagePoint, (linePoint + lineFeed) - 1.0f);
                        newLineNeeded = true;
                    } else {
                        ImageHelper.printCenterString(g2d, eqi.damage, font, damagePoint, linePoint);
                    }
                    if (eqi.minRange > 0) {
                        g2d.drawString(Integer.toString(eqi.minRange), minPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2,
                    // minPoint + 6, (int) linePoint - 2);
                    }
                    if (eqi.shtRange > 0) {
                        g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", shtPoint, linePoint);
                    // g2d.drawLine(shtPoint, (int) linePoint - 2,
                    // shtPoint + 6, (int) linePoint - 2);
                    }
                    if (eqi.medRange > 0) {
                        g2d.drawString(Integer.toString(eqi.medRange), medPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", medPoint, linePoint);
                    // g2d.drawLine(medPoint, (int) linePoint - 2,
                    // medPoint + 6, (int) linePoint - 2);
                    }
                    if (eqi.longRange > 0) {
                        g2d.drawString(Integer.toString(eqi.longRange), longPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", longPoint, linePoint);
                    // g2d.drawLine(longPoint, (int) linePoint - 2,
                    // longPoint + 6, (int) linePoint - 2);
                    }
                }
            } else {
                if (eqi.heat > 0) {
                    g2d.drawString(Integer.toString(eqi.heat), heatPoint, linePoint);
                } else {
                    g2d.drawString("\u2014", heatPoint, linePoint);
                // g2d.drawLine(heatPoint, (int) linePoint - 2,
                // heatPoint + 6, (int) linePoint - 2);
                }
                ImageHelper.printCenterString(g2d, eqi.damage, font, damagePoint - 2, linePoint);
                g2d.drawString("\u2014", minPoint, linePoint);
                g2d.drawString("\u2014", shtPoint, linePoint);
                g2d.drawString("\u2014", medPoint, linePoint);
                // (int) linePoint - 2);
                if (eqi.longRange > 0) {
                    g2d.drawString(Integer.toString(eqi.longRange), longPoint, linePoint);
                } else {
                    g2d.drawString("\u2014", longPoint, linePoint);
                // g2d.drawLine(longPoint, (int) linePoint - 2,
                // longPoint + 6, (int) linePoint - 2);
                }
            }
            if (eqi.hasArtemis) {
                g2d.drawString("w/Artemis IV FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            } else if (eqi.hasArtemisV) {
                g2d.drawString("w/Artemis V FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            } else if (eqi.hasApollo) {
                g2d.drawString("w/Apollo FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            }
            linePoint += lineFeed;
            if (newLineNeeded) {
                linePoint += lineFeed;
            }
            count++;
        }
    }
    if (mech instanceof LandAirMech) {
        ImageHelper.printLAMFuel((LandAirMech) mech, g2d, qtyPoint);
    }
}
Also used : HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) TextAttribute(java.awt.font.TextAttribute) ArrayList(java.util.ArrayList) Font(java.awt.Font) AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) LandAirMech(megamek.common.LandAirMech)

Example 2 with TextAttribute

use of java.awt.font.TextAttribute in project megameklab by MegaMek.

the class ImageHelper method printC3EmName.

public static void printC3EmName(Graphics2D g2d, float lineStart, float linePoint, Font font, boolean isArmored, boolean mixed) {
    Font c3Font = font.deriveFont(font.getStyle(), font.getSize2D());
    HashMap<TextAttribute, Integer> attrMap = new HashMap<TextAttribute, Integer>();
    attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
    int stringWidth;
    if (isArmored) {
        g2d.drawString("O C   Emergency Master" + (mixed ? " (IS)" : ""), lineStart, linePoint);
        stringWidth = ImageHelper.getStringWidth(g2d, "O C", c3Font);
    } else {
        g2d.drawString("C   Emergency Master" + (mixed ? " (IS)" : ""), lineStart, linePoint);
        stringWidth = ImageHelper.getStringWidth(g2d, "C", c3Font);
    }
    // stringWidth = ImageHelper.getStringWidth(g2d, "C", font);
    c3Font = font.deriveFont(attrMap);
    g2d.setFont(c3Font);
    g2d.drawString("3", lineStart + stringWidth, linePoint);
    g2d.setFont(font);
}
Also used : HashMap(java.util.HashMap) TextAttribute(java.awt.font.TextAttribute) Font(java.awt.Font)

Example 3 with TextAttribute

use of java.awt.font.TextAttribute in project megameklab by MegaMek.

the class ImageHelper method printBC3iName.

public static void printBC3iName(Graphics2D g2d, float lineStart, float linePoint, Font font, boolean isArmored, boolean mixed) {
    Font c3Font = font.deriveFont(font.getStyle(), font.getSize2D());
    HashMap<TextAttribute, Integer> attrMap = new HashMap<TextAttribute, Integer>();
    attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
    int stringWidth;
    if (isArmored) {
        g2d.drawString("O Improved BC" + (mixed ? "   (IS)" : ""), lineStart, linePoint);
        stringWidth = ImageHelper.getStringWidth(g2d, "O Improved BC", c3Font);
    } else {
        g2d.drawString("Improved BC" + (mixed ? "   (IS)" : ""), lineStart, linePoint);
        stringWidth = ImageHelper.getStringWidth(g2d, "Improved BC", c3Font);
    }
    c3Font = font.deriveFont(attrMap);
    g2d.setFont(c3Font);
    g2d.drawString("3", lineStart + stringWidth, linePoint);
    g2d.setFont(font);
}
Also used : HashMap(java.util.HashMap) TextAttribute(java.awt.font.TextAttribute) Font(java.awt.Font)

Example 4 with TextAttribute

use of java.awt.font.TextAttribute in project megameklab by MegaMek.

the class ImageHelper method printBC3Name.

public static void printBC3Name(Graphics2D g2d, float lineStart, float linePoint, Font font, boolean isArmored, boolean mixed) {
    Font c3Font = font.deriveFont(font.getStyle(), font.getSize2D());
    HashMap<TextAttribute, Integer> attrMap = new HashMap<TextAttribute, Integer>();
    attrMap.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
    int stringWidth;
    if (isArmored) {
        g2d.drawString("O BC" + (mixed ? "   (IS)" : ""), lineStart, linePoint);
        stringWidth = ImageHelper.getStringWidth(g2d, "O BC", c3Font);
    } else {
        g2d.drawString("BC" + (mixed ? "   (IS)" : ""), lineStart, linePoint);
        stringWidth = ImageHelper.getStringWidth(g2d, "BC", c3Font);
    }
    c3Font = font.deriveFont(attrMap);
    g2d.setFont(c3Font);
    g2d.drawString("3", lineStart + stringWidth, linePoint);
    g2d.setFont(font);
}
Also used : HashMap(java.util.HashMap) TextAttribute(java.awt.font.TextAttribute) Font(java.awt.Font)

Example 5 with TextAttribute

use of java.awt.font.TextAttribute in project gate-core by GateNLP.

the class JFontChooser method updateFont.

// initListeners()
protected void updateFont() {
    Map<TextAttribute, Object> fontAttrs = new HashMap<TextAttribute, Object>();
    fontAttrs.put(TextAttribute.FAMILY, familyCombo.getSelectedItem());
    fontAttrs.put(TextAttribute.SIZE, new Float((String) sizeCombo.getSelectedItem()));
    if (boldChk.isSelected())
        fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
    else
        fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);
    if (italicChk.isSelected())
        fontAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
    else
        fontAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
    Font newFont = new Font(fontAttrs);
    Font oldFont = fontValue;
    fontValue = newFont;
    sampleTextArea.setFont(newFont);
    String text = sampleTextArea.getText();
    sampleTextArea.setText("");
    sampleTextArea.setText(text);
    sampleTextArea.repaint(100);
    firePropertyChange("fontValue", oldFont, newFont);
}
Also used : HashMap(java.util.HashMap) TextAttribute(java.awt.font.TextAttribute) Font(java.awt.Font)

Aggregations

TextAttribute (java.awt.font.TextAttribute)30 Font (java.awt.Font)22 HashMap (java.util.HashMap)21 Configuration (com.haulmont.cuba.core.global.Configuration)2 DesktopConfig (com.haulmont.cuba.desktop.DesktopConfig)2 FontMetrics (java.awt.FontMetrics)2 Paint (java.awt.Paint)2 AffineTransform (java.awt.geom.AffineTransform)2 Hashtable (java.util.Hashtable)2 DesktopResources (com.haulmont.cuba.desktop.DesktopResources)1 CollapsiblePanel (com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel)1 WebColors (com.revolsys.awt.WebColors)1 Geometry (com.revolsys.geometry.model.Geometry)1 SwingUtil (com.revolsys.swing.SwingUtil)1 ClipboardUtil (com.revolsys.swing.dnd.ClipboardUtil)1 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)1 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)1 LayerRecordMenu (com.revolsys.swing.map.layer.record.LayerRecordMenu)1 RecordLayerTableModel (com.revolsys.swing.map.layer.record.table.model.RecordLayerTableModel)1 TablePanel (com.revolsys.swing.table.TablePanel)1