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());
}
}
Aggregations