⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generalinfomapset.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * MegaMek - Copyright (C) 2003,2004 Ben Mazur (bmazur@sev.org) *  *  This program is free software; you can redistribute it and/or modify it  *  under the terms of the GNU General Public License as published by the Free  *  Software Foundation; either version 2 of the License, or (at your option)  *  any later version. *  *  This program is distributed in the hope that it will be useful, but  *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License  *  for more details. */package megamek.client.ui.swing.widget;import megamek.client.ui.swing.GUIPreferences;import megamek.client.ui.swing.Messages;import megamek.common.Building;import megamek.common.Entity;import megamek.common.GunEmplacement;import megamek.common.IEntityMovementType;import megamek.common.Mech;import megamek.common.Tank;import megamek.common.options.IOption;import javax.swing.JComponent;import java.awt.Color;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Image;import java.util.Enumeration;import java.util.Vector;/** * Set of elements to reperesent general unit information in MechDisplay */public class GeneralInfoMapSet implements DisplayMapSet {    private static final String IMAGE_DIR = "data/images/widgets";    private static String STAR3 = "***";  //$NON-NLS-1$    private JComponent comp;    private PMAreasGroup content = new PMAreasGroup();    private PMSimpleLabel mechTypeL0, mechTypeL1, statusL, playerL, teamL,    weightL, bvL, pilotL, mpL0, mpL1, mpL2, mpL3, curMoveL, heatL,    movementTypeL, ejectL, elevationL, buildingTypeL, buildingHeightL;    private PMSimpleLabel statusR, playerR, teamR, weightR, bvR, pilotR,    mpR0, mpR1, mpR2, mpR3, curMoveR, heatR, movementTypeR, ejectR,    elevationR, buildingTypeR, buildingHeightR;    private PMSimpleLabel[] advantagesR;    private Vector bgDrawers = new Vector();    private static final Font FONT_VALUE = new Font("SansSerif", Font.PLAIN, GUIPreferences.getInstance().getInt("AdvancedMechDisplayLargeFontSize")); //$NON-NLS-1$    private static final Font FONT_TITLE = new Font("SansSerif", Font.ITALIC, GUIPreferences.getInstance().getInt("AdvancedMechDisplayLargeFontSize")); //$NON-NLS-1$    private int yCoord = 1;    /**     * This constructor have to be called anly from addNotify() method     */    public GeneralInfoMapSet(JComponent c) {        comp = c;        setAreas();        setBackGround();    }    //These two methods are used to vertically position new labels on the    // display.    private int getYCoord() {        return yCoord * 15 - 5;    }    private int getNewYCoord() {        yCoord++;        return getYCoord();    }    private void setAreas() {        FontMetrics fm = comp.getFontMetrics(FONT_TITLE);        mechTypeL0 = createLabel(Messages.getString("GeneralInfoMapSet.LocOstLCT"), fm, 0, getYCoord()); //$NON-NLS-1$        mechTypeL0.setColor(Color.yellow);        content.addArea(mechTypeL0);        mechTypeL1 = createLabel(STAR3, fm, 0, getNewYCoord());        mechTypeL1.setColor(Color.yellow);        content.addArea(mechTypeL1);        fm = comp.getFontMetrics(FONT_VALUE);        playerL = createLabel(Messages.getString("GeneralInfoMapSet.playerL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(playerL);        playerR = createLabel(Messages.getString("GeneralInfoMapSet.playerR"), fm, playerL.getSize().width + 10, getYCoord()); //$NON-NLS-1$        content.addArea(playerR);        teamL = createLabel(Messages.getString("GeneralInfoMapSet.teamL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(teamL);        teamR = createLabel(Messages.getString("GeneralInfoMapSet.teamR"), fm, teamL.getSize().width + 10, getYCoord()); //$NON-NLS-1$        content.addArea(teamR);        statusL = createLabel(Messages.getString("GeneralInfoMapSet.statusL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(statusL);        statusR = createLabel(STAR3, fm, statusL.getSize().width + 10, getYCoord());        content.addArea(statusR);        weightL = createLabel(Messages.getString("GeneralInfoMapSet.weightL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(weightL);        weightR = createLabel(STAR3, fm, weightL.getSize().width + 10, getYCoord());        content.addArea(weightR);        bvL = createLabel(Messages.getString("GeneralInfoMapSet.bvL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(bvL);        bvR = createLabel(STAR3, fm, bvL.getSize().width + 10, getYCoord());        content.addArea(bvR);        mpL0 = createLabel(Messages.getString("GeneralInfoMapSet.mpL0"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(mpL0);        mpR0 = createLabel("", fm, mpL0.getSize().width + 10, getYCoord()); //$NON-NLS-1$        content.addArea(mpR0);        mpL1 = createLabel(Messages.getString("GeneralInfoMapSet.mpL1"), fm, 0, getNewYCoord()); //$NON-NLS-1$        mpL1.moveTo(mpL0.getSize().width - mpL1.getSize().width, getYCoord());        content.addArea(mpL1);        mpR1 = createLabel(STAR3, fm, mpL0.getSize().width + 10, getYCoord());        content.addArea(mpR1);        mpL2 = createLabel(Messages.getString("GeneralInfoMapSet.mpL2"), fm, 0, getNewYCoord()); //$NON-NLS-1$        mpL2.moveTo(mpL0.getSize().width - mpL2.getSize().width, getYCoord());        content.addArea(mpL2);        mpR2 = createLabel(STAR3, fm, mpL0.getSize().width + 10, getYCoord());        content.addArea(mpR2);        mpL3 = createLabel(Messages.getString("GeneralInfoMapSet.mpL3"), fm, 0, getNewYCoord()); //$NON-NLS-1$        mpL3.moveTo(mpL0.getSize().width - mpL3.getSize().width, getYCoord());        content.addArea(mpL3);        mpR3 = createLabel(STAR3, fm, mpL0.getSize().width + 10, getYCoord());        content.addArea(mpR3);        curMoveL = createLabel(Messages.getString("GeneralInfoMapSet.curMoveL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(curMoveL);        curMoveR = createLabel(STAR3, fm, curMoveL.getSize().width + 10, getYCoord());        content.addArea(curMoveR);        heatL = createLabel(Messages.getString("GeneralInfoMapSet.heatL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(heatL);        heatR = createLabel(STAR3, fm, heatL.getSize().width + 10, getYCoord());        content.addArea(heatR);        movementTypeL = createLabel(Messages.getString("GeneralInfoMapSet.movementTypeL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(movementTypeL);        movementTypeR = createLabel(STAR3, fm, movementTypeL.getSize().width + 10, getYCoord());        content.addArea(movementTypeR);        pilotL = createLabel(Messages.getString("GeneralInfoMapSet.pilotL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(pilotL);        pilotR = createLabel(STAR3, fm, pilotL.getSize().width + 10, getYCoord());        content.addArea(pilotR);        ejectL = createLabel(Messages.getString("GeneralInfoMapSet.ejectL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(ejectL);        ejectR = createLabel(STAR3, fm, ejectL.getSize().width + 10, getYCoord());        content.addArea(ejectR);        elevationL = createLabel(Messages.getString("GeneralInfoMapSet.elevationL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(elevationL);        elevationR = createLabel(STAR3, fm, ejectL.getSize().width + 10, getYCoord());        content.addArea(elevationR);        buildingTypeL = createLabel(Messages.getString("GeneralInfoMapSet.buildingTypeL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(buildingTypeL);        buildingTypeR = createLabel(STAR3, fm, buildingTypeL.getSize().width + 10, getYCoord());        content.addArea(buildingTypeR);        buildingHeightL = createLabel(Messages.getString("GeneralInfoMapSet.buildingHeightL"), fm, 0, getNewYCoord()); //$NON-NLS-1$        content.addArea(buildingHeightL);        buildingHeightR = createLabel(STAR3, fm, buildingHeightL.getSize().width + 10, getYCoord());        content.addArea(buildingHeightR);        advantagesR = new PMSimpleLabel[24];        for (int i = 0; i < advantagesR.length; i++) {            advantagesR[i] = createLabel(Integer.toString(i), fm, pilotL.getSize().width + 10, getNewYCoord());            content.addArea(advantagesR[i]);        }        //DO NOT PLACE ANY MORE LABELS BELOW HERE.  They will get        //pushed off the bottom of the screen by the pilot advantage        //labels.  Why not just allocate the number of pilot advantage        //labels required instead of a hard 24?  Because we don't have        //an entity at this point.  Bleh.    }    /**     * updates fields for the unit     */    public void setEntity(Entity en) {        String s = en.getShortName();        mechTypeL1.setVisible(false);        if (s.length() > GUIPreferences.getInstance().getInt("AdvancedMechDisplayWrapLength")) {            mechTypeL1.setColor(Color.yellow);            int i = s.lastIndexOf(" ", GUIPreferences.getInstance().getInt("AdvancedMechDisplayWrapLength")); //$NON-NLS-1$            mechTypeL0.setString(s.substring(0, i));            mechTypeL1.setString(s.substring(i).trim());            mechTypeL1.setVisible(true);        } else {            mechTypeL0.setString(s);            mechTypeL1.setString(""); //$NON-NLS-1$        }        if (!en.isDesignValid()) {            //If this is the case, we will just overwrite the name-overflow            // area, since this info is more important.            mechTypeL1.setColor(Color.red);            mechTypeL1.setString(Messages.getString("GeneralInfoMapSet.invalidDesign"));            mechTypeL1.setVisible(true);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -