Search in sources :

Example 1 with BayWeaponCriticalTree

use of megameklab.com.ui.util.BayWeaponCriticalTree in project megameklab by MegaMek.

the class AerospaceBuildView method mousePressed.

public void mousePressed(MouseEvent e) {
    // locations, but only if those locations are make sense
    if (e.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem item = null;
        if (equipmentTable.getSelectedRowCount() > 1) {
            List<Mounted> list = new ArrayList<>();
            for (int row : equipmentTable.getSelectedRows()) {
                list.add((Mounted) equipmentTable.getModel().getValueAt(row, CriticalTableModel.EQUIPMENT));
            }
            for (BayWeaponCriticalTree l : arcViews) {
                // Aerodyne small craft and dropships skip the aft side arcs
                if (getAero().hasETypeFlag(Entity.ETYPE_SMALL_CRAFT) && !getAero().isSpheroid() && !l.validForAerodyne()) {
                    continue;
                }
                if (list.stream().anyMatch(eq -> l.canAdd(eq))) {
                    item = new JMenuItem(l.getLocationName());
                    item.addActionListener(ev -> l.addToLocation(list));
                    popup.add(item);
                }
            }
        } else {
            final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
            Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
            for (BayWeaponCriticalTree l : arcViews) {
                // Aerodyne small craft and dropships skip the aft side arcs
                if (getAero().hasETypeFlag(Entity.ETYPE_SMALL_CRAFT) && !getAero().isSpheroid() && !l.validForAerodyne()) {
                    continue;
                }
                if (getAero().usesWeaponBays()) {
                    JMenu menu = new JMenu(l.getLocationName());
                    for (Mounted bay : l.baysFor(eq)) {
                        if (eq.getType() instanceof AmmoType) {
                            final int shotCount = ((AmmoType) eq.getType()).getShots();
                            JMenu locMenu = new JMenu(bay.getName());
                            for (int shots = shotCount; shots <= eq.getUsableShotsLeft(); shots += shotCount) {
                                item = new JMenuItem("Add " + shots + ((shots > 1) ? " shots" : " shot"));
                                final int addShots = shots;
                                item.addActionListener(ev -> l.addAmmoToBay(bay, eq, addShots));
                                locMenu.add(item);
                            }
                            menu.add(locMenu);
                        } else {
                            item = new JMenuItem(bay.getName());
                            item.addActionListener(ev -> l.addToBay(bay, eq));
                            menu.add(item);
                        }
                    }
                    if (eq.getType() instanceof WeaponType) {
                        final EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
                        item = new JMenuItem("New " + bayType.getName());
                        item.addActionListener(ev -> l.addToNewBay(bayType, eq));
                        menu.add(item);
                    }
                    if (menu.getItemCount() > 0) {
                        popup.add(menu);
                    } else if ((eq.getType() instanceof MiscType) && l.canAdd(eq)) {
                        item = new JMenuItem(l.getLocationName());
                        item.addActionListener(ev -> l.addToLocation(eq));
                        popup.add(item);
                    }
                } else {
                    item = new JMenuItem(l.getLocationName());
                    item.addActionListener(ev -> l.addToLocation(eq));
                    popup.add(item);
                }
            }
        }
        popup.show(this, e.getX(), e.getY());
    }
}
Also used : ListSelectionModel(javax.swing.ListSelectionModel) Weapon(megamek.common.weapons.Weapon) ArrayList(java.util.ArrayList) EquipmentType(megamek.common.EquipmentType) EntitySource(megameklab.com.ui.EntitySource) Vector(java.util.Vector) JMenuItem(javax.swing.JMenuItem) TitledBorder(javax.swing.border.TitledBorder) Mounted(megamek.common.Mounted) StringUtils(megameklab.com.util.StringUtils) BorderLayout(java.awt.BorderLayout) MouseListener(java.awt.event.MouseListener) AmmoType(megamek.common.AmmoType) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) AeroBayTransferHandler(megameklab.com.ui.util.AeroBayTransferHandler) JMenu(javax.swing.JMenu) IView(megameklab.com.util.IView) BorderFactory(javax.swing.BorderFactory) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) Dimension(java.awt.Dimension) List(java.util.List) WeaponType(megamek.common.WeaponType) CriticalTableModel(megameklab.com.util.CriticalTableModel) MiscType(megamek.common.MiscType) JTable(javax.swing.JTable) Collections(java.util.Collections) Entity(megamek.common.Entity) BayWeaponCriticalTree(megameklab.com.ui.util.BayWeaponCriticalTree) RefreshListener(megameklab.com.util.RefreshListener) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MiscType(megamek.common.MiscType) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BayWeaponCriticalTree(megameklab.com.ui.util.BayWeaponCriticalTree) EquipmentType(megamek.common.EquipmentType) JPopupMenu(javax.swing.JPopupMenu) AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Aggregations

BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Vector (java.util.Vector)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 BorderFactory (javax.swing.BorderFactory)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 ListSelectionModel (javax.swing.ListSelectionModel)1 TitledBorder (javax.swing.border.TitledBorder)1 TableColumn (javax.swing.table.TableColumn)1 AmmoType (megamek.common.AmmoType)1