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

📄 chatlounge.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * MegaMek -  *  Copyright (C) 2000,2001,2002,2003,20042005,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.AWT;import java.awt.*;import java.awt.event.*;import java.util.Enumeration;import java.util.Vector;import java.util.Iterator;import java.util.LinkedList;import java.util.Comparator;import java.util.Collections;import gov.nist.gui.TabPanel;import megamek.client.Client;import megamek.client.bot.BotClient;import megamek.client.bot.ui.AWT.BotGUI;import megamek.client.bot.TestBot;import megamek.client.event.BoardViewListener;import megamek.client.ui.AWT.util.PlayerColors;import megamek.client.ui.AWT.widget.BufferedPanel;import megamek.client.ui.AWT.widget.ImageButton;import megamek.common.*;import megamek.common.event.GameEntityNewEvent;import megamek.common.event.GameEntityRemoveEvent;import megamek.common.event.GameListener;import megamek.common.event.GamePhaseChangeEvent;import megamek.common.event.GamePlayerChangeEvent;import megamek.common.event.GameSettingsChangeEvent;import megamek.common.util.Distractable;import megamek.common.util.DistractableAdapter;public class ChatLounge    extends AbstractPhaseDisplay    implements ActionListener, ItemListener, BoardViewListener, GameListener, DoneButtoned, Distractable {    // Distraction implementation.    private DistractableAdapter distracted = new DistractableAdapter();    // parent Client    private Client client;    private ClientGUI clientgui;    // The camo selection dialog.    private CamoChoiceDialog camoDialog;    // buttons & such    private Panel panPlayerInfo;    private Label labPlayerInfo;    private List lisPlayerInfo;    private Label labTeam;    private Choice choTeam;    private Label labCamo;    private ImageButton butCamo;    private Panel panMinefield;    private Label labMinefield;    private List lisMinefield;    private Label labConventional;    private Label labCommandDetonated;    private Label labVibrabomb;    private TextField fldConventional;    private TextField fldCommandDetonated;    private TextField fldVibrabomb;    private Button butMinefield;    private Button butOptions;    private Label labBoardSize;    private Label labMapSize;    private List lisBoardsSelected;    private Button butChangeBoard;    private Panel panBoardSettings;    private Button butLoadList;    //      private Label  lblPlaceholder;    private Button butSaveList;    private Button butDeleteAll;    private Button butLoad;    private Button butLoadCustomBA;    private Button butDelete;    private Button butCustom;    private Button butMechReadout;    private Button butViewGroup;    private List lisEntities;    private int[] entityCorrespondance;    private Panel panEntities;    private Label labStarts;    private List lisStarts;    private Panel panStarts;    private Button butChangeStart;    private Label labBVs;    private List lisBVs;    private CheckboxGroup bvCbg;    private Checkbox chkBV;    private Checkbox chkTons;    private Checkbox chkCost;        private Panel panBVs;    private TabPanel panTabs;    private Panel panMain;    private Panel panUnits;    private Panel panTop;    private Label labStatus;    private Button butDone;        private Button butAddBot;    private Button butRemoveBot;    MechSummaryCache.Listener mechSummaryCacheListener = new MechSummaryCache.Listener() {        public void doneLoading() {            butLoad.setEnabled(true);            butLoadCustomBA.setEnabled(true);        }    };        /**     * Creates a new chat lounge for the client.     */    public ChatLounge(ClientGUI clientgui) {        super();        this.client = clientgui.getClient();        this.clientgui = clientgui;        // Create a tabbed panel to hold our components.        panTabs = new TabPanel();        Font tabPanelFont = new Font ("Dialog",Font.BOLD, //$NON-NLS-1$          GUIPreferences.getInstance().getInt("AdvancedChatLoungeTabFontSize"));        panTabs.setTabFont (tabPanelFont);                // Create a new camo selection dialog.        camoDialog = new CamoChoiceDialog(clientgui.getFrame());        client.game.addGameListener(this);        clientgui.getBoardView().addBoardViewListener(this);        butOptions = new Button(Messages.getString("ChatLounge.butOptions")); //$NON-NLS-1$        butOptions.addActionListener(this);        butDone = new Button(Messages.getString("ChatLounge.butDone")); //$NON-NLS-1$        Font font = null;        try {            font = new Font("sanserif", Font.BOLD, 12); //$NON-NLS-1$        }        catch (Exception exp) {            exp.printStackTrace();        }        if (null == font) {            System.err.println("Couldn't find the new font for the 'Done' button."); //$NON-NLS-1$        } else {            butDone.setFont(font);        }        butDone.setActionCommand("ready"); //$NON-NLS-1$        butDone.addActionListener(this);        setupPlayerInfo();        setupMinefield();        setupBoardSettings();        refreshGameSettings();        setupEntities();        refreshEntities();        setupBVs();        refreshBVs();        setupStarts();        refreshStarts();        setupMainPanel();        labStatus = new Label("", Label.CENTER); //$NON-NLS-1$        // layout main thing        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        setLayout(gridbag);        c.fill = GridBagConstraints.BOTH;        c.weightx = 1.0;        c.weighty = 1.0;        c.insets = new Insets(1, 1, 1, 1);        c.gridwidth = GridBagConstraints.REMAINDER;        if (GUIPreferences.getInstance().getChatLoungeTabs()) {            addBag (panTabs, gridbag, c);        } else {            addBag(panMain, gridbag, c);        }        //         c.weightx = 1.0;    c.weighty = 0.0;        //         addBag(labStatus, gridbag, c);        //          c.gridwidth = 1;        //          c.weightx = 1.0;    c.weighty = 0.0;        //          addBag(client.cb.getComponent(), gridbag, c);        //          c.gridwidth = 1;        //          c.anchor = GridBagConstraints.EAST;        //          c.weightx = 0.0;    c.weighty = 0.0;        //          c.ipady = 10;        //          addBag(butDone, gridbag, c);        validate();    }    private void addBag(Component comp, GridBagLayout gridbag, GridBagConstraints c) {        gridbag.setConstraints(comp, c);        add(comp);    }    /**     * Sets up the player info (team, camo) panel     */    private void setupPlayerInfo() {        Player player = client.getLocalPlayer();        panPlayerInfo = new Panel();        labPlayerInfo = new Label(Messages.getString("ChatLounge.labPlayerInfo")); //$NON-NLS-1$        lisPlayerInfo = new List(5);        lisPlayerInfo.addItemListener(new ItemListener() {            public void itemStateChanged(ItemEvent e) {                butRemoveBot.setEnabled(false);                Client c = getPlayerListSelected(lisPlayerInfo);                if (c == null) {                    lisPlayerInfo.select(-1);                    return;                }                if (c instanceof BotClient) {                    butRemoveBot.setEnabled(true);                }                 choTeam.select(c.getLocalPlayer().getTeam());            }        });                butAddBot = new Button(Messages.getString("ChatLounge.butAddBot")); //$NON-NLS-1$        butAddBot.setActionCommand("add_bot"); //$NON-NLS-1$        butAddBot.addActionListener(this);                butRemoveBot = new Button(Messages.getString("ChatLounge.butRemoveBot")); //$NON-NLS-1$        butRemoveBot.setEnabled(false);        butRemoveBot.setActionCommand("remove_bot"); //$NON-NLS-1$        butRemoveBot.addActionListener(this);                labTeam = new Label(Messages.getString("ChatLounge.labTeam"), Label.RIGHT); //$NON-NLS-1$        labCamo = new Label(Messages.getString("ChatLounge.labCamo"), Label.RIGHT); //$NON-NLS-1$        choTeam = new Choice();        choTeam.addItemListener(this);        setupTeams();        butCamo = new ImageButton();        butCamo.setLabel(Messages.getString("ChatLounge.noCamo")); //$NON-NLS-1$        butCamo.setPreferredSize(84, 72);        butCamo.setActionCommand("camo"); //$NON-NLS-1$        butCamo.addActionListener(this);        camoDialog.addItemListener(            new CamoChoiceListener(camoDialog, butCamo, butOptions.getBackground(), player.getId(), client));        refreshCamos();        // If we have a camo pattern, use it.  Otherwise set a background.        Image[] images = (Image[]) camoDialog.getSelectedObjects();        if (null != images) {            butCamo.setImage(images[0]);        } else {            butCamo.setBackground(PlayerColors.getColor(player.getColorIndex()));        }        // layout        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        panPlayerInfo.setLayout(gridbag);        c.fill = GridBagConstraints.VERTICAL;        c.insets = new Insets(1, 1, 1, 1);        c.weightx = 1.0;        c.weighty = 0.0;        c.gridwidth = GridBagConstraints.REMAINDER;        gridbag.setConstraints(labPlayerInfo, c);        panPlayerInfo.add(labPlayerInfo);        c.fill = GridBagConstraints.BOTH;        c.weightx = 1.0;        c.weighty = 1.0;        gridbag.setConstraints(lisPlayerInfo, c);        panPlayerInfo.add(lisPlayerInfo);        c.gridwidth = 1;        c.weightx = 0.0;        c.weighty = 0.0;        gridbag.setConstraints(labTeam, c);        panPlayerInfo.add(labTeam);        c.gridwidth = GridBagConstraints.REMAINDER;        c.weightx = 1.0;        c.weighty = 0.0;        gridbag.setConstraints(choTeam, c);        panPlayerInfo.add(choTeam);        c.gridwidth = 1;        c.weightx = 0.0;        c.weighty = 0.0;        gridbag.setConstraints(labCamo, c);        panPlayerInfo.add(labCamo);        c.gridwidth = GridBagConstraints.REMAINDER;        c.weightx = 1.0;        c.weighty = 0.0;        gridbag.setConstraints(butCamo, c);        panPlayerInfo.add(butCamo);                c.gridwidth = 1;        c.weightx = 0.0;        c.weighty = 0.0;        gridbag.setConstraints(butAddBot, c);        panPlayerInfo.add(butAddBot);        c.gridwidth = GridBagConstraints.REMAINDER;        c.weightx = 1.0;        c.weighty = 0.0;        gridbag.setConstraints(butRemoveBot, c);        panPlayerInfo.add(butRemoveBot);        refreshPlayerInfo();    }    /**     * Sets up the minefield panel     */    private void setupMinefield() {        panMinefield = new Panel();        labMinefield = new Label(Messages.getString("ChatLounge.labMinefield")); //$NON-NLS-1$        lisMinefield = new List(2);        labConventional = new Label(Messages.getString("ChatLounge.labConventional"), Label.RIGHT); //$NON-NLS-1$        labCommandDetonated = new Label(Messages.getString("ChatLounge.labCommandDetonated"), Label.RIGHT); //$NON-NLS-1$        labVibrabomb = new Label(Messages.getString("ChatLounge.labVibrabomb"), Label.RIGHT); //$NON-NLS-1$        fldConventional = new TextField(1);        fldCommandDetonated = new TextField(1);        fldVibrabomb = new TextField(1);        butMinefield = new Button(Messages.getString("ChatLounge.butMinefield")); //$NON-NLS-1$        butMinefield.addActionListener(this);        enableMinefields(client.game.getOptions().booleanOption("minefields")); //$NON-NLS-1$        // layout        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        panMinefield.setLayout(gridbag);        c.fill = GridBagConstraints.VERTICAL;        c.insets = new Insets(1, 1, 1, 1);        c.weightx = 1.0;        c.weighty = 0.0;        c.gridwidth = GridBagConstraints.REMAINDER;        gridbag.setConstraints(labMinefield, c);        panMinefield.add(labMinefield);        c.fill = GridBagConstraints.BOTH;        c.weightx = 1.0;        c.weighty = 1.0;        gridbag.setConstraints(lisMinefield, c);        panMinefield.add(lisMinefield);        c.gridwidth = 1;        c.weightx = 0.0;        c.weighty = 0.0;        gridbag.setConstraints(labConventional, c);        panMinefield.add(labConventional);        c.gridwidth = GridBagConstraints.REMAINDER;

⌨️ 快捷键说明

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