Search in sources :

Example 1 with DropTargetCriticalList

use of megameklab.com.util.DropTargetCriticalList in project megameklab by MegaMek.

the class CriticalView method refresh.

public void refresh() {
    leftPanel.removeAll();
    rightPanel.removeAll();
    bodyPanel.removeAll();
    frontPanel.removeAll();
    rearPanel.removeAll();
    turretPanel.removeAll();
    dualTurretPanel.removeAll();
    fullTurretPanel.removeAll();
    rearLeftPanel.removeAll();
    rearRightPanel.removeAll();
    this.remove(fullTurretPanel);
    if (getTank() instanceof VTOL) {
        if (getTank().hasNoTurret()) {
            turretPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Rotor", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
            fullTurretPanel.add(turretPanel);
            this.add(fullTurretPanel);
        } else {
            dualTurretPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Turret", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
            fullTurretPanel.add(dualTurretPanel);
            turretPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Rotor", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
            fullTurretPanel.add(turretPanel);
            this.add(fullTurretPanel);
        }
    } else if (!getTank().hasNoDualTurret()) {
        dualTurretPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Front Turret", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
        fullTurretPanel.add(dualTurretPanel);
        turretPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Rear Turret", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
        fullTurretPanel.add(turretPanel);
        this.add(fullTurretPanel);
    } else if (!getTank().hasNoTurret()) {
        turretPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Turret", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
        fullTurretPanel.add(turretPanel);
        this.add(fullTurretPanel);
    }
    synchronized (getTank()) {
        for (int location = 0; location < getTank().locations(); location++) {
            // JPanel locationPanel = new JPanel();
            Vector<String> critNames = new Vector<String>(1, 1);
            for (int slot = 0; slot < getTank().getNumberOfCriticals(location); slot++) {
                CriticalSlot cs = getTank().getCritical(location, slot);
                if (cs == null) {
                    continue;
                } else if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
                    critNames.add(getMech().getSystemName(cs.getIndex()));
                } else if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
                    try {
                        Mounted m = cs.getMount();
                        // Critical didn't get removed. Remove it now.
                        if (m == null) {
                            m = cs.getMount();
                            if (m == null) {
                                getTank().setCritical(location, slot, null);
                                continue;
                            }
                            cs.setMount(m);
                        }
                        StringBuffer critName = new StringBuffer(m.getName());
                        if (critName.length() > 25) {
                            critName.setLength(25);
                            critName.append("...");
                        }
                        if (m.isRearMounted()) {
                            critName.append(" (R)");
                        }
                        if (m.isSponsonTurretMounted()) {
                            critName.append(" (ST)");
                        }
                        if (m.isPintleTurretMounted()) {
                            critName.append(" (PT)");
                        }
                        critNames.add(critName.toString());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            if (critNames.size() == 0) {
                critNames.add(MtfFile.EMPTY);
            }
            DropTargetCriticalList<String> criticalSlotList = null;
            DropTargetCriticalList<String> dropTargetCriticalList = new DropTargetCriticalList<String>(critNames, eSource, refresh, showEmpty);
            criticalSlotList = dropTargetCriticalList;
            criticalSlotList.setVisibleRowCount(critNames.size());
            criticalSlotList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            criticalSlotList.setFont(new Font("Arial", Font.PLAIN, 10));
            criticalSlotList.setName(Integer.toString(location));
            criticalSlotList.setBorder(BorderFactory.createEtchedBorder(Color.WHITE.brighter(), Color.BLACK.darker()));
            if (!(getTank()).isSuperHeavy()) {
                switch(location) {
                    case Tank.LOC_FRONT:
                        frontPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_LEFT:
                        leftPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_RIGHT:
                        rightPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_BODY:
                        bodyPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_REAR:
                        rearPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_TURRET:
                        turretPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_TURRET_2:
                        dualTurretPanel.add(criticalSlotList);
                        break;
                }
            } else if (getTank() instanceof VTOL) {
                switch(location) {
                    case Tank.LOC_FRONT:
                        frontPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_LEFT:
                        leftPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_RIGHT:
                        rightPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_BODY:
                        bodyPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_REAR:
                        rearPanel.add(criticalSlotList);
                        break;
                    case VTOL.LOC_ROTOR:
                        turretPanel.add(criticalSlotList);
                        break;
                }
            } else {
                switch(location) {
                    case Tank.LOC_FRONT:
                        frontPanel.add(criticalSlotList);
                        break;
                    case SuperHeavyTank.LOC_FRONTLEFT:
                        leftPanel.add(criticalSlotList);
                        break;
                    case SuperHeavyTank.LOC_FRONTRIGHT:
                        rightPanel.add(criticalSlotList);
                        break;
                    case SuperHeavyTank.LOC_REARLEFT:
                        rearLeftPanel.add(criticalSlotList);
                        break;
                    case SuperHeavyTank.LOC_REARRIGHT:
                        rearRightPanel.add(criticalSlotList);
                        break;
                    case Tank.LOC_BODY:
                        bodyPanel.add(criticalSlotList);
                        break;
                    case SuperHeavyTank.LOC_REAR:
                        rearPanel.add(criticalSlotList);
                        break;
                    case SuperHeavyTank.LOC_TURRET:
                        turretPanel.add(criticalSlotList);
                        break;
                    case SuperHeavyTank.LOC_TURRET_2:
                        dualTurretPanel.add(criticalSlotList);
                        break;
                }
            }
        }
        middlePanel2.setVisible(getTank().isSuperHeavy() && !(getTank() instanceof VTOL));
        frontPanel.repaint();
        bodyPanel.repaint();
        leftPanel.repaint();
        rightPanel.repaint();
        rearLeftPanel.repaint();
        rearRightPanel.repaint();
        rearPanel.repaint();
        turretPanel.repaint();
        dualTurretPanel.repaint();
    }
}
Also used : VTOL(megamek.common.VTOL) DropTargetCriticalList(megameklab.com.util.DropTargetCriticalList) CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) Vector(java.util.Vector) Font(java.awt.Font)

Aggregations

Font (java.awt.Font)1 Vector (java.util.Vector)1 CriticalSlot (megamek.common.CriticalSlot)1 Mounted (megamek.common.Mounted)1 VTOL (megamek.common.VTOL)1 DropTargetCriticalList (megameklab.com.util.DropTargetCriticalList)1