📄 mechdisplay.java
字号:
/** * MegaMek - Copyright (C) 2000,2001,2002,2003,2004,2006 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;import megamek.client.event.MechDisplayEvent;import megamek.client.event.MechDisplayListener;import megamek.client.ui.AWT.Messages;import megamek.client.ui.swing.widget.ArmlessMechMapSet;import megamek.client.ui.swing.widget.BackGroundDrawer;import megamek.client.ui.swing.widget.BattleArmorMapSet;import megamek.client.ui.swing.widget.BufferedPanel;import megamek.client.ui.swing.widget.DisplayMapSet;import megamek.client.ui.swing.widget.GeneralInfoMapSet;import megamek.client.ui.swing.widget.GunEmplacementMapSet;import megamek.client.ui.swing.widget.InfantryMapSet;import megamek.client.ui.swing.widget.MechMapSet;import megamek.client.ui.swing.widget.MechPanelTabStrip;import megamek.client.ui.swing.widget.PMUtil;import megamek.client.ui.swing.widget.PicMap;import megamek.client.ui.swing.widget.ProtomechMapSet;import megamek.client.ui.swing.widget.QuadMapSet;import megamek.client.ui.swing.widget.TankMapSet;import megamek.client.ui.swing.widget.VTOLMapSet;import megamek.common.*;import javax.swing.DefaultListModel;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import java.awt.CardLayout;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Image;import java.awt.Insets;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.util.ArrayList;import java.util.Enumeration;import java.util.Vector;/** * Displays the info for a mech. This is also a sort * of interface for special movement and firing actions. */public class MechDisplay extends JPanel { // buttons & gizmos for top level private MechPanelTabStrip tabStrip; private JPanel displayP; private MovementPanel mPan; private ArmorPanel aPan; public WeaponPanel wPan; private SystemPanel sPan; private ExtraPanel ePan; private ClientGUI clientgui; private Entity currentlyDisplaying; private ArrayList<MechDisplayListener> eventListeners = new ArrayList<MechDisplayListener>(); /** * Creates and lays out a new mech display. */ public MechDisplay(ClientGUI clientgui) { super(new GridBagLayout()); this.clientgui = clientgui; tabStrip = new MechPanelTabStrip(this); displayP = new JPanel(new CardLayout()); mPan = new MovementPanel(); displayP.add("movement", mPan); //$NON-NLS-1$ aPan = new ArmorPanel(); displayP.add("armor", aPan); //$NON-NLS-1$ wPan = new WeaponPanel(); displayP.add("weapons", wPan); //$NON-NLS-1$ sPan = new SystemPanel(); displayP.add("systems", sPan); //$NON-NLS-1$ ePan = new ExtraPanel(); displayP.add("extras", ePan); //$NON-NLS-1$ // layout main panel GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(4, 1, 0, 1); c.weightx = 1.0; c.weighty = 0.0; c.gridwidth = GridBagConstraints.REMAINDER; addBag(tabStrip, c); c.insets = new Insets(0, 1, 1, 1); c.weighty = 1.0; addBag(displayP, c); ((CardLayout) displayP.getLayout()).show(displayP, "movement"); //$NON-NLS-1$ //tabStrip.setTab(0); } private void addBag(JComponent comp, GridBagConstraints c) { ((GridBagLayout) getLayout()).setConstraints(comp, c); add(comp); } /** * Displays the specified entity in the panel. */ public void displayEntity(Entity en) { clientgui.mechW.setTitle(en.getShortName()); currentlyDisplaying = en; mPan.displayMech(en); aPan.displayMech(en); wPan.displayMech(en); sPan.displayMech(en); ePan.displayMech(en); } /** * Returns the entity we'return currently displaying */ public Entity getCurrentEntity() { return currentlyDisplaying; } /** * Changes to the specified panel. */ public void showPanel(String s) { ((CardLayout) displayP.getLayout()).show(displayP, s); if ("movement".equals(s)) { //$NON-NLS-1$ tabStrip.setTab(0); } else if ("armor".equals(s)) { //$NON-NLS-1$ tabStrip.setTab(1); } else if ("weapons".equals(s)) { //$NON-NLS-1$ tabStrip.setTab(3); } else if ("systems".equals(s)) { //$NON-NLS-1$ tabStrip.setTab(2); } else if ("extras".equals(s)) { //$NON-NLS-1$ tabStrip.setTab(4); } } /** * Adds the specified mech display listener to receive * events from this view. * * @param listener the listener. */ public void addMechDisplayListener(MechDisplayListener listener) { eventListeners.add(listener); } /** * Notifies attached listeners of the event. * * @param event the mech display event. */ private void processMechDisplayEvent(MechDisplayEvent event) { for (int i = 0; i < eventListeners.size(); i++) { MechDisplayListener lis = eventListeners.get(i); switch (event.getType()) { case MechDisplayEvent.WEAPON_SELECTED: lis.WeaponSelected(event); break; default: System.err.println("unknown event " + event.getType() + " in processMechDisplayEvent"); break; } } } /** * The movement panel contains all the buttons, readouts * and gizmos relating to moving around on the * battlefield. */ private class MovementPanel extends PicMap { private GeneralInfoMapSet gi; private int minTopMargin = 8; private int minLeftMargin = 8; MovementPanel() { gi = new GeneralInfoMapSet(this); addElement(gi.getContentGroup()); Vector v = gi.getBackgroundDrawers(); Enumeration iter = v.elements(); while (iter.hasMoreElements()) { addBgDrawer((BackGroundDrawer) iter.nextElement()); } onResize(); } public void addNotify() { super.addNotify(); update(); } public void onResize() { int w = getSize().width; Rectangle r = getContentBounds(); int dx = Math.round(((w - r.width) / 2)); if (dx < minLeftMargin) dx = minLeftMargin; int dy = minTopMargin; if (r != null) setContentMargins(dx, dy, dx, dy); } /** * updates fields for the specified mech */ public void displayMech(Entity en) { gi.setEntity(en); onResize(); update(); } } /** * This panel contains the armor readout display. */ private class ArmorPanel extends PicMap { private TankMapSet tank; private MechMapSet mech; private InfantryMapSet infantry; private BattleArmorMapSet battleArmor; private ProtomechMapSet proto; private VTOLMapSet vtol; private QuadMapSet quad; private GunEmplacementMapSet gunEmplacement; private ArmlessMechMapSet armless; private int minTopMargin; private int minLeftMargin; private int minBottomMargin; private int minRightMargin; private static final int minTankTopMargin = 8; private static final int minTankLeftMargin = 8; private static final int minVTOLTopMargin = 8; private static final int minVTOLLeftMargin = 8; private static final int minMechTopMargin = 18; private static final int minMechLeftMargin = 7; private static final int minMechBottomMargin = 0; private static final int minMechRightMargin = 0; private static final int minInfTopMargin = 8; private static final int minInfLeftMargin = 8; public void addNotify() { super.addNotify(); tank = new TankMapSet(this); mech = new MechMapSet(this); infantry = new InfantryMapSet(this); battleArmor = new BattleArmorMapSet(this); proto = new ProtomechMapSet(this); vtol = new VTOLMapSet(this); quad = new QuadMapSet(this); gunEmplacement = new GunEmplacementMapSet(this); armless = new ArmlessMechMapSet(this); } public void onResize() { Rectangle r = getContentBounds(); if (r == null) return; int w = Math.round(((getSize().width - r.width) / 2)); int h = Math.round(((getSize().height - r.height) / 2)); int dx = w < minLeftMargin ? minLeftMargin : w; int dy = h < minTopMargin ? minTopMargin : h; setContentMargins(dx, dy, minRightMargin, minBottomMargin); } /** * updates fields for the specified mech */ public void displayMech(Entity en) { // Look out for a race condition. if (en == null) { return; } DisplayMapSet ams = mech; removeAll(); if (en instanceof QuadMech) { ams = quad; minLeftMargin = minMechLeftMargin; minTopMargin = minMechTopMargin; minBottomMargin = minMechBottomMargin; minRightMargin = minMechRightMargin; } else if (en instanceof ArmlessMech) { ams = armless; minLeftMargin = minMechLeftMargin; minTopMargin = minMechTopMargin; minBottomMargin = minMechBottomMargin; minRightMargin = minMechRightMargin; } else if (en instanceof Mech) { ams = mech; minLeftMargin = minMechLeftMargin; minTopMargin = minMechTopMargin;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -