📄 mechselectordialog.java
字号:
/* * MechSelectorDialog.java - Copyright (C) 2002,2004 Josh Yockey * * 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.Client;import megamek.common.Entity;import megamek.common.EntityWeightClass;import megamek.common.EquipmentType;import megamek.common.MechFileParser;import megamek.common.MechSummary;import megamek.common.MechSummaryCache;import megamek.common.MechSummaryComparator;import megamek.common.MiscType;import megamek.common.Mounted;import megamek.common.TechConstants;import megamek.common.UnitType;import megamek.common.WeaponType;import megamek.common.loaders.EntityLoadingException;import javax.swing.DefaultComboBoxModel;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import java.awt.BorderLayout;import java.awt.Cursor;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Font;import java.awt.GridLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import java.util.ArrayList;import java.util.Arrays;import java.util.Enumeration;import java.util.Hashtable;import java.util.Iterator;/* * Allows a user to sort through a list of MechSummaries and select one */public class MechSelectorDialog extends JDialog implements ActionListener, ItemListener, KeyListener, Runnable, WindowListener, ListSelectionListener { // how long after a key is typed does a new search begin private final static int KEY_TIMEOUT = 1000; // these indices should match up with the static values in the MechSummaryComparator private String[] m_saSorts = {Messages.getString("MechSelectorDialog.0"), Messages.getString("MechSelectorDialog.1"), Messages.getString("MechSelectorDialog.2"), Messages.getString("MechSelectorDialog.3"), Messages.getString("MechSelectorDialog.4"), Messages.getString("MechSelectorDialog.5")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ private MechSummary[] m_mechsCurrent = new MechSummary[0]; private Client m_client; private ClientGUI m_clientgui; private UnitLoadingDialog unitLoadingDialog; private StringBuffer m_sbSearch = new StringBuffer(); private long m_nLastSearch = 0; private JLabel m_labelWeightClass = new JLabel(Messages.getString("MechSelectorDialog.m_labelWeightClass"), JLabel.RIGHT); //$NON-NLS-1$ private JComboBox m_chWeightClass = new JComboBox(); private JLabel m_labelType = new JLabel(Messages.getString("MechSelectorDialog.m_labelType"), JLabel.RIGHT); //$NON-NLS-1$ private JComboBox m_chType = new JComboBox(); private JLabel m_labelUnitType = new JLabel(Messages.getString("MechSelectorDialog.m_labelUnitType"), JLabel.RIGHT); //$NON-NLS-1$ private JComboBox m_chUnitType = new JComboBox(); private JLabel m_labelSort = new JLabel(Messages.getString("MechSelectorDialog.m_labelSort"), JLabel.RIGHT); //$NON-NLS-1$ private JComboBox m_chSort = new JComboBox(); private JPanel m_pParams = new JPanel(); private JPanel m_pListOptions = new JPanel(); private JLabel m_labelListOptions = new JLabel(Messages.getString("MechSelectorDialog.m_labelListOptions")); private JCheckBox m_cModel = new JCheckBox(Messages.getString("MechSelectorDialog.m_cModel"), GUIPreferences.getInstance().getMechSelectorIncludeModel()); private JCheckBox m_cName = new JCheckBox(Messages.getString("MechSelectorDialog.m_cName"), GUIPreferences.getInstance().getMechSelectorIncludeName()); private JCheckBox m_cTons = new JCheckBox(Messages.getString("MechSelectorDialog.m_cTons"), GUIPreferences.getInstance().getMechSelectorIncludeTons()); private JCheckBox m_cBV = new JCheckBox(Messages.getString("MechSelectorDialog.m_cBV"), GUIPreferences.getInstance().getMechSelectorIncludeBV()); private JCheckBox m_cYear = new JCheckBox(Messages.getString("MechSelectorDialog.m_cYear"), GUIPreferences.getInstance().getMechSelectorIncludeYear()); private JCheckBox m_cLevel = new JCheckBox(Messages.getString("MechSelectorDialog.m_cLevel"), GUIPreferences.getInstance().getMechSelectorIncludeLevel()); private JCheckBox m_cCost = new JCheckBox(Messages.getString("MechSelectorDialog.m_cCost"), GUIPreferences.getInstance().getMechSelectorIncludeCost()); private JPanel m_pOpenAdvanced = new JPanel(); private JButton m_bToggleAdvanced = new JButton("< Advanced Search >"); private JPanel m_pSouthParams = new JPanel(); JList m_mechList = new JList(new DefaultComboBoxModel()); private JButton m_bPick = new JButton(Messages.getString("MechSelectorDialog.m_bPick")); //$NON-NLS-1$ private JButton m_bPickClose = new JButton(Messages.getString("MechSelectorDialog.m_bPickClose")); //$NON-NLS-1$ private JButton m_bCancel = new JButton(Messages.getString("Close")); //$NON-NLS-1$ private JPanel m_pButtons = new JPanel(); private JTextArea m_mechView = new JTextArea("", 36, 35); private JPanel m_pLeft = new JPanel(); private JComboBox m_cWalk = new JComboBox(); private JTextField m_tWalk = new JTextField(2); private JComboBox m_cJump = new JComboBox(); private JTextField m_tJump = new JTextField(2); private JComboBox m_cArmor = new JComboBox(); private JTextField m_tWeapons1 = new JTextField(2); private JComboBox m_cWeapons1 = new JComboBox(); private JComboBox m_cOrAnd = new JComboBox(); private JTextField m_tWeapons2 = new JTextField(2); private JComboBox m_cWeapons2 = new JComboBox(); private JCheckBox m_chkEquipment = new JCheckBox(); private JComboBox m_cEquipment = new JComboBox(); private JButton m_bSearch = new JButton(Messages.getString("MechSelectorDialog.Search.Search")); private JButton m_bReset = new JButton(Messages.getString("MechSelectorDialog.Search.Reset")); private JLabel m_lCount = new JLabel(); private int m_count; private int m_old_nType; private int m_old_nUnitType; private JPanel m_pUpper = new JPanel(); JLabel m_pPreview = new JLabel(); private JLabel m_labelPlayer = new JLabel(Messages.getString("MechSelectorDialog.m_labelPlayer"), JLabel.RIGHT); //$NON-NLS-1$ private JComboBox m_chPlayer = new JComboBox(); private boolean includeMaxTech; public MechSelectorDialog(ClientGUI cl, UnitLoadingDialog uld) { super(cl.frame, Messages.getString("MechSelectorDialog.title"), true); //$NON-NLS-1$ m_client = cl.getClient(); m_clientgui = cl; unitLoadingDialog = uld; for (int x = 0; x < m_saSorts.length; x++) { m_chSort.addItem(m_saSorts[x]); } updatePlayerChoice(); m_pParams.setLayout(new GridLayout(4, 2)); m_pParams.add(m_labelWeightClass); m_pParams.add(m_chWeightClass); m_pParams.add(m_labelType); m_pParams.add(m_chType); m_pParams.add(m_labelUnitType); m_pParams.add(m_chUnitType); m_pParams.add(m_labelSort); m_pParams.add(m_chSort); m_pListOptions.add(m_labelListOptions); m_cModel.addItemListener(this); m_pListOptions.add(m_cModel); m_cName.addItemListener(this); m_pListOptions.add(m_cName); m_cTons.addItemListener(this); m_pListOptions.add(m_cTons); m_cBV.addItemListener(this); m_pListOptions.add(m_cBV); m_cYear.addItemListener(this); m_pListOptions.add(m_cYear); m_cLevel.addItemListener(this); m_pListOptions.add(m_cLevel); m_cCost.addItemListener(this); m_pListOptions.add(m_cCost); if (GUIPreferences.getInstance().getMechSelectorShowAdvanced()) { buildSouthParams(true); } else { buildSouthParams(false); } m_pButtons.setLayout(new FlowLayout(FlowLayout.CENTER)); m_pButtons.add(m_bPick); m_pButtons.add(m_bPickClose); m_pButtons.add(m_bCancel); m_pButtons.add(m_labelPlayer); m_pButtons.add(m_chPlayer); m_pUpper.setLayout(new BorderLayout()); m_pPreview.setPreferredSize(new Dimension(84, 72)); m_pUpper.add(m_pParams, BorderLayout.WEST); m_pUpper.add(m_pPreview, BorderLayout.CENTER); m_pUpper.add(m_pSouthParams, BorderLayout.SOUTH); m_pLeft.setLayout(new BorderLayout()); m_pLeft.add(m_pUpper, BorderLayout.NORTH); m_mechList.setFont(new Font("Monospaced", Font.PLAIN, 12)); //$NON-NLS-1$ m_mechList.addKeyListener(this); m_pLeft.add(new JScrollPane(m_mechList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); m_pLeft.add(m_pButtons, BorderLayout.SOUTH); getContentPane().setLayout(new BorderLayout()); getContentPane().add(m_pLeft, BorderLayout.CENTER); m_mechView.setFont(new Font("Monospaced", Font.PLAIN, 12)); //$NON-NLS-1$ m_mechView.setEditable(false); m_mechView.setOpaque(false); getContentPane().add(m_mechView, BorderLayout.EAST); //clearMechPreview(); setSize(700, 350); setLocation(computeDesiredLocation()); populateChoices(); m_chWeightClass.addItemListener(this); m_chType.addItemListener(this); m_chUnitType.addItemListener(this); m_chSort.addItemListener(this); m_mechList.addListSelectionListener(this); m_bPick.addActionListener(this); m_bPickClose.addActionListener(this); m_bCancel.addActionListener(this); m_bSearch.addActionListener(this); m_bReset.addActionListener(this); m_bToggleAdvanced.addActionListener(this); addWindowListener(this); updateWidgetEnablements(); } private void buildSouthParams(boolean showAdvanced) { if (showAdvanced) { m_bToggleAdvanced.setText(Messages.getString("MechSelectorDialog.Search.Hide")); m_pOpenAdvanced.add(m_bToggleAdvanced); m_pSouthParams.setLayout(new GridLayout(11, 1)); m_pSouthParams.add(m_pListOptions); m_pSouthParams.add(m_pOpenAdvanced); JPanel row1 = new JPanel(); row1.setLayout(new FlowLayout(FlowLayout.LEFT)); row1.add(new JLabel(Messages.getString("MechSelectorDialog.Search.Walk"))); row1.add(m_cWalk); row1.add(m_tWalk); m_pSouthParams.add(row1); JPanel row2 = new JPanel(); row2.setLayout(new FlowLayout(FlowLayout.LEFT)); row2.add(new JLabel(Messages.getString("MechSelectorDialog.Search.Jump"))); row2.add(m_cJump); row2.add(m_tJump); m_pSouthParams.add(row2); JPanel row3 = new JPanel(); row3.setLayout(new FlowLayout(FlowLayout.LEFT)); row3.add(new JLabel(Messages.getString("MechSelectorDialog.Search.Armor"))); row3.add(m_cArmor); m_pSouthParams.add(row3); JPanel row4 = new JPanel(); row4.setLayout(new FlowLayout(FlowLayout.LEFT)); row4.add(new JLabel(Messages.getString("MechSelectorDialog.Search.Weapons"))); m_pSouthParams.add(row4); JPanel row5 = new JPanel(); row5.setLayout(new FlowLayout(FlowLayout.LEFT)); row5.add(new JLabel(Messages.getString("MechSelectorDialog.Search.WeaponsAtLeast"))); row5.add(m_tWeapons1); row5.add(m_cWeapons1); m_pSouthParams.add(row5); JPanel row6 = new JPanel(); row6.setLayout(new FlowLayout(FlowLayout.LEFT)); row6.add(m_cOrAnd); row6.add(new JLabel(Messages.getString("MechSelectorDialog.Search.WeaponsAtLeast"))); row6.add(m_tWeapons2); row6.add(m_cWeapons2); m_pSouthParams.add(row6); JPanel row7 = new JPanel(); row7.setLayout(new FlowLayout(FlowLayout.LEFT)); row7.add(new JLabel(Messages.getString("MechSelectorDialog.Search.Equipment"))); m_pSouthParams.add(row7); JPanel row8 = new JPanel(); row8.setLayout(new FlowLayout(FlowLayout.LEFT)); row8.add(m_chkEquipment); row8.add(m_cEquipment); m_pSouthParams.add(row8); JPanel row9 = new JPanel(); row9.add(m_bSearch); row9.add(m_bReset); row9.add(m_lCount); m_pSouthParams.add(row9); } else { m_bToggleAdvanced.setText(Messages.getString("MechSelectorDialog.Search.Show")); m_pOpenAdvanced.add(m_bToggleAdvanced); m_pSouthParams.setLayout(new GridLayout(2, 1)); m_pSouthParams.add(m_pListOptions); m_pSouthParams.add(m_pOpenAdvanced); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -