diff --git a/src/megameklab/com/printing/PrintDropship.java b/src/megameklab/com/printing/PrintDropship.java index e3079193a9e..dddf018801b 100644 --- a/src/megameklab/com/printing/PrintDropship.java +++ b/src/megameklab/com/printing/PrintDropship.java @@ -345,15 +345,8 @@ public String formatFeatures() { int drones = 0; Map eqCount = new HashMap<>(); for (Mounted mount : ship.getMisc()) { - // MASH and DCC use an additional MiscType to expand their capacity. - // Present them as a single piece of equipment and show size. - if (mount.getType().hasFlag(MiscType.F_MASH) || mount.getType().hasFlag(MiscType.F_MASH_EXTRA)) { - mashTheaters++; - } else if (mount.getType().hasFlag(MiscType.F_DRONE_CARRIER_CONTROL) - || mount.getType().hasFlag(MiscType.F_DRONE_EXTRA)){ - drones++; - } else if (UnitUtil.isPrintableEquipment(mount.getType())) { - eqCount.merge(mount.getType().getShortName(), 1, Integer::sum); + if (UnitUtil.isPrintableEquipment(mount.getType())) { + eqCount.merge(mount.getShortName(), 1, Integer::sum); } } if (ship instanceof Jumpship && ((Jumpship) ship).hasLF()) { @@ -366,15 +359,6 @@ public String formatFeatures() { sj.add(eq); } } - if (mashTheaters > 1) { - sj.add("MASH (" + mashTheaters + " theaters)"); - } else if (mashTheaters == 1) { - sj.add("MASH"); - } - if (drones > 0) { - sj.add("Drone Carrier Control System (" + drones - + ((drones > 1) ? " drones)" : " drone)")); - } return sj.toString(); } diff --git a/src/megameklab/com/printing/StandardInventoryEntry.java b/src/megameklab/com/printing/StandardInventoryEntry.java index ec05a5e3459..d778bc126f3 100644 --- a/src/megameklab/com/printing/StandardInventoryEntry.java +++ b/src/megameklab/com/printing/StandardInventoryEntry.java @@ -157,9 +157,9 @@ private String[][] atmAV() { } private String formatName() { - String eqName = mount.getType().getName(); + String eqName = mount.getName(); if (eqName.length() > 20) { - eqName = mount.getType().getShortName(); + eqName = mount.getShortName(); } // Remove trailing IS or Clan tag in brackets or parentheses, including possible leading space StringBuilder name = new StringBuilder(eqName.replaceAll(" ?[\\[(](Clan|IS)[])]", "")); diff --git a/src/megameklab/com/ui/Aero/tabs/EquipmentTab.java b/src/megameklab/com/ui/Aero/tabs/EquipmentTab.java index 1ee1377a19f..0c6b81b0a2c 100644 --- a/src/megameklab/com/ui/Aero/tabs/EquipmentTab.java +++ b/src/megameklab/com/ui/Aero/tabs/EquipmentTab.java @@ -157,15 +157,26 @@ public EquipmentTab(EntitySource eSource) { equipmentTable.setShowGrid(false); equipmentTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); equipmentTable.setDoubleBuffered(true); + equipmentTable.setRowHeight((int) (equipmentTable.getRowHeight() * 1.2)); TableColumn column = null; for (int i = 0; i < equipmentList.getColumnCount(); i++) { column = equipmentTable.getColumnModel().getColumn(i); - if(i == 0) { + if (i == CriticalTableModel.NAME) { column.setPreferredWidth(200); + } else if (i == CriticalTableModel.SIZE) { + column.setCellEditor(equipmentList.new SpinnerCellEditor()); } column.setCellRenderer(equipmentList.getRenderer()); } + equipmentList.addTableModelListener(ev -> { + if (refresh != null) { + refresh.refreshStatus(); + refresh.refreshPreview(); + refresh.refreshBuild(); + refresh.refreshSummary(); + } + }); equipmentScroll.setViewportView(equipmentTable); equipmentScroll.setMinimumSize(new java.awt.Dimension(300, 200)); equipmentScroll.setPreferredSize(new java.awt.Dimension(300, 200)); diff --git a/src/megameklab/com/ui/BattleArmor/tabs/EquipmentTab.java b/src/megameklab/com/ui/BattleArmor/tabs/EquipmentTab.java index 03b065b3162..177b3e7f969 100644 --- a/src/megameklab/com/ui/BattleArmor/tabs/EquipmentTab.java +++ b/src/megameklab/com/ui/BattleArmor/tabs/EquipmentTab.java @@ -151,12 +151,22 @@ public EquipmentTab(EntitySource eSource) { TableColumn column = null; for (int i = 0; i < equipmentList.getColumnCount(); i++) { column = equipmentTable.getColumnModel().getColumn(i); - if(i == 0) { + if (i == CriticalTableModel.NAME) { column.setPreferredWidth(200); + } else if (i == CriticalTableModel.SIZE) { + column.setCellEditor(equipmentList.new SpinnerCellEditor()); } column.setCellRenderer(equipmentList.getRenderer()); } + equipmentList.addTableModelListener(ev -> { + if (refresh != null) { + refresh.refreshStatus(); + refresh.refreshPreview(); + refresh.refreshBuild(); + refresh.refreshSummary(); + } + }); equipmentScroll.setViewportView(equipmentTable); equipmentScroll.setMinimumSize(new java.awt.Dimension(300, 200)); equipmentScroll.setPreferredSize(new java.awt.Dimension(300, 200)); diff --git a/src/megameklab/com/ui/Mek/tabs/EquipmentTab.java b/src/megameklab/com/ui/Mek/tabs/EquipmentTab.java index f33f2a4470c..2ffc6b1a35d 100644 --- a/src/megameklab/com/ui/Mek/tabs/EquipmentTab.java +++ b/src/megameklab/com/ui/Mek/tabs/EquipmentTab.java @@ -153,12 +153,22 @@ public EquipmentTab(EntitySource eSource) { TableColumn column = null; for (int i = 0; i < equipmentList.getColumnCount(); i++) { column = equipmentTable.getColumnModel().getColumn(i); - if(i == 0) { + if (i == CriticalTableModel.NAME) { column.setPreferredWidth(200); + } else if (i == CriticalTableModel.SIZE) { + column.setCellEditor(equipmentList.new SpinnerCellEditor()); } column.setCellRenderer(equipmentList.getRenderer()); } + equipmentList.addTableModelListener(ev -> { + if (refresh != null) { + refresh.refreshStatus(); + refresh.refreshPreview(); + refresh.refreshBuild(); + refresh.refreshSummary(); + } + }); equipmentScroll.setViewportView(equipmentTable); equipmentScroll.setMinimumSize(new java.awt.Dimension(300, 200)); equipmentScroll.setPreferredSize(new java.awt.Dimension(300, 200)); diff --git a/src/megameklab/com/ui/Vehicle/tabs/EquipmentTab.java b/src/megameklab/com/ui/Vehicle/tabs/EquipmentTab.java index 30e78cead92..d4847c26aad 100644 --- a/src/megameklab/com/ui/Vehicle/tabs/EquipmentTab.java +++ b/src/megameklab/com/ui/Vehicle/tabs/EquipmentTab.java @@ -151,12 +151,22 @@ public EquipmentTab(EntitySource eSource) { TableColumn column = null; for (int i = 0; i < equipmentList.getColumnCount(); i++) { column = equipmentTable.getColumnModel().getColumn(i); - if(i == 0) { + if (i == CriticalTableModel.NAME) { column.setPreferredWidth(200); + } else if (i == CriticalTableModel.SIZE) { + column.setCellEditor(equipmentList.new SpinnerCellEditor()); } column.setCellRenderer(equipmentList.getRenderer()); } + equipmentList.addTableModelListener(ev -> { + if (refresh != null) { + refresh.refreshStatus(); + refresh.refreshPreview(); + refresh.refreshBuild(); + refresh.refreshSummary(); + } + }); equipmentScroll.setViewportView(equipmentTable); equipmentScroll.setMinimumSize(new java.awt.Dimension(300, 200)); equipmentScroll.setPreferredSize(new java.awt.Dimension(300, 200)); diff --git a/src/megameklab/com/ui/tabs/EquipmentTab.java b/src/megameklab/com/ui/tabs/EquipmentTab.java index ac41d50559b..8e979b8a077 100644 --- a/src/megameklab/com/ui/tabs/EquipmentTab.java +++ b/src/megameklab/com/ui/tabs/EquipmentTab.java @@ -186,16 +186,26 @@ public EquipmentTab(EntitySource eSource) { equipmentTable.setIntercellSpacing(new Dimension(0, 0)); equipmentTable.setShowGrid(false); equipmentTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - equipmentTable.setDoubleBuffered(true); + equipmentTable.setRowHeight((int) (equipmentTable.getRowHeight() * 1.2)); TableColumn column; for (int i = 0; i < equipmentList.getColumnCount(); i++) { column = equipmentTable.getColumnModel().getColumn(i); - if(i == 0) { + if (i == CriticalTableModel.NAME) { column.setPreferredWidth(200); + } else if (i == CriticalTableModel.SIZE) { + column.setCellEditor(equipmentList.new SpinnerCellEditor()); } column.setCellRenderer(equipmentList.getRenderer()); } + equipmentList.addTableModelListener(ev -> { + if (refresh != null) { + refresh.refreshStatus(); + refresh.refreshPreview(); + refresh.refreshBuild(); + refresh.refreshSummary(); + } + }); JScrollPane equipmentScroll = new JScrollPane(); equipmentScroll.setViewportView(equipmentTable); equipmentScroll.setMinimumSize(new java.awt.Dimension(300, 200)); diff --git a/src/megameklab/com/util/CriticalTableModel.java b/src/megameklab/com/util/CriticalTableModel.java index 0a9824e0f91..44d4f1baeee 100644 --- a/src/megameklab/com/util/CriticalTableModel.java +++ b/src/megameklab/com/util/CriticalTableModel.java @@ -1,5 +1,5 @@ /* - * MegaMekLab - Copyright (C) 2008 + * MegaMekLab - Copyright (C) 2008-2020 The MegaMek Team * * Original author - jtighe (torren@users.sourceforge.net) * @@ -17,25 +17,24 @@ package megameklab.com.util; import java.awt.Component; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; import java.util.Vector; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.SwingConstants; +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellEditor; import javax.swing.table.TableColumn; -import megamek.common.AmmoType; -import megamek.common.BattleArmor; -import megamek.common.Entity; -import megamek.common.Mech; -import megamek.common.MiscType; -import megamek.common.Mounted; -import megamek.common.Tank; -import megamek.common.WeaponType; +import megamek.common.*; +import megamek.common.verifier.BayData; import megamek.common.verifier.TestEntity; import megamek.common.verifier.TestProtomech; +import megameklab.com.ui.tabs.TransportTab; public class CriticalTableModel extends AbstractTableModel { @@ -45,7 +44,7 @@ public class CriticalTableModel extends AbstractTableModel { private static final long serialVersionUID = 7615555055651822051L; private Mounted[] sortedEquipment = {}; - public Vector crits = new Vector(); + public List crits = new ArrayList<>(); public Entity unit; public final static int NAME = 0; @@ -53,14 +52,15 @@ public class CriticalTableModel extends AbstractTableModel { public final static int CRITS = 2; public final static int HEAT = 3; public final static int LOCATION = 4; - public final static int EQUIPMENT = 5; + public final static int SIZE = 5; + public final static int EQUIPMENT = 6; public final static int EQUIPMENTTABLE = 0; public final static int WEAPONTABLE = 1; public final static int BUILDTABLE = 2; - private int tableType = EQUIPMENTTABLE; - private boolean kgStandard = false; + private int tableType; + private boolean kgStandard; private String[] columnNames = { "Name", "Tons", "Crits"}; @@ -77,9 +77,9 @@ public CriticalTableModel(Entity unit, int tableType) { if (tableType == WEAPONTABLE) { longValues = new String[] { "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", - "XXXXXXXXX", "XXX" }; + "XXXXXXXXX", "XXX", "XXXX" }; columnNames = new String[] { "Name", "Tons", "Slots", "Heat", - "Loc" }; + "Loc", "Size" }; } if (kgStandard) { @@ -133,7 +133,8 @@ public String getColumnName(int col) { @Override public boolean isCellEditable(int row, int col) { - return false; + return (col == SIZE) && (row >= 0) && (row < sortedEquipment.length) + && sortedEquipment[row].getType().isVariableTonnage(); } @Override @@ -191,7 +192,7 @@ public Object getValueAt(int row, int col) { return crit; case HEAT: if (crit.getType() instanceof WeaponType) { - return ((WeaponType) crit.getType()).getHeat(); + return crit.getType().getHeat(); } return 0; case LOCATION: @@ -201,10 +202,25 @@ public Object getValueAt(int row, int col) { } else { return unit.getLocationAbbr(crit.getLocation()); } + case SIZE: + if (crit.getType().isVariableTonnage()) { + return NumberFormat.getInstance().format(crit.getSize()); + } else { + return null; + } } return ""; } + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + if ((columnIndex == SIZE) && (rowIndex >= 0) && (rowIndex < getRowCount())) { + Mounted crit = sortedEquipment[rowIndex]; + crit.setSize(Double.parseDouble(aValue.toString())); + fireTableDataChanged(); + } + } + public CriticalTableModel.Renderer getRenderer() { return new Renderer(); } @@ -286,12 +302,50 @@ public Component getTableCellRendererComponent(JTable table, } } + /** + * Cell editor for the size column + */ + public class SpinnerCellEditor extends AbstractCellEditor implements TableCellEditor, ChangeListener { + + private static final long serialVersionUID = 1949617773287631727L; + + private final JSpinner spinner = new JSpinner(); + private int rowIndex = 0; + + public SpinnerCellEditor() { + spinner.addChangeListener(this); + } + + @Override + public Object getCellEditorValue() { + return spinner.getValue(); + } + + @Override + public void stateChanged(ChangeEvent e) { + setValueAt(getCellEditorValue(), rowIndex, SIZE); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, + int column) { + this.rowIndex = row; + Mounted mounted = (Mounted) getValueAt(row, EQUIPMENT); + spinner.removeChangeListener(this); + spinner.setModel(new SpinnerNumberModel(Double.valueOf(mounted.getSize()), + mounted.getType().variableStepSize(), mounted.getType().variableMaxSize(), + mounted.getType().variableStepSize())); + spinner.addChangeListener(this); + return spinner; + } + } + public void addCrit(Mounted mount) { crits.add(mount); } public void removeCrit(int location) { - crits.removeElementAt(location); + crits.remove(location); } /** @@ -302,13 +356,13 @@ public void removeCrit(int location) { public void removeCrits(int[] locs) { Vector mounts = new Vector<>(locs.length); for (Integer l : locs){ - mounts.add(crits.elementAt(l)); + mounts.add(crits.get(l)); } crits.removeAll(mounts); } public void removeAllCrits() { - crits.removeAllElements(); + crits.clear(); } public void removeMounted(int row) { @@ -316,7 +370,7 @@ public void removeMounted(int row) { (Mounted) getValueAt(row, CriticalTableModel.EQUIPMENT)); } - public Vector getCrits() { + public List getCrits() { return crits; } diff --git a/src/megameklab/com/util/ImageHelper.java b/src/megameklab/com/util/ImageHelper.java index 6b74031dd93..6504241ac73 100644 --- a/src/megameklab/com/util/ImageHelper.java +++ b/src/megameklab/com/util/ImageHelper.java @@ -31,17 +31,14 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Vector; +import java.util.*; import javax.swing.ImageIcon; import com.kitfox.svg.SVGDiagram; import com.kitfox.svg.SVGUniverse; +import jdk.nashorn.internal.runtime.options.Option; import megamek.common.Aero; import megamek.common.AmmoType; import megamek.common.BattleArmor; @@ -1163,7 +1160,13 @@ public static void printC3RemoteSensorAmmoName(Graphics2D g2d, public static void printMashCore(Graphics2D g2d, float lineStart, float linePoint, Font font, boolean isArmored, Entity entity) { - int theaters = entity.countWorkingMisc(MiscType.F_MASH_EXTRA) + 1; + int theaters = 1; + Optional mash = entity.getMisc().stream() + .filter(m -> m.getType().hasFlag(MiscType.F_DRONE_CARRIER_CONTROL)) + .findFirst(); + if (mash.isPresent()) { + theaters = (int) mash.get().getSize(); + } String theaterString = theaters > 1 ? " theaters)" : " theater)"; String printString; if (isArmored) { @@ -1179,7 +1182,13 @@ public static void printMashCore(Graphics2D g2d, float lineStart, public static void printDroneControl(Graphics2D g2d, float lineStart, float linePoint, Font font, boolean isArmored, Entity entity) { - int drones = entity.countWorkingMisc(MiscType.F_DRONE_EXTRA); + int drones = 1; + Optional dccs = entity.getMisc().stream() + .filter(m -> m.getType().hasFlag(MiscType.F_DRONE_CARRIER_CONTROL)) + .findFirst(); + if (dccs.isPresent()) { + drones = (int) dccs.get().getSize(); + } String droneString = drones > 1 ? " drones)" : " drone)"; String printString; if (isArmored) { diff --git a/src/megameklab/com/util/RecordSheetEquipmentLine.java b/src/megameklab/com/util/RecordSheetEquipmentLine.java index 0eb914141ec..e655033531a 100644 --- a/src/megameklab/com/util/RecordSheetEquipmentLine.java +++ b/src/megameklab/com/util/RecordSheetEquipmentLine.java @@ -48,7 +48,7 @@ public RecordSheetEquipmentLine(Mounted m) { rear = m.isRearMounted(); turret = m.isMechTurretMounted(); if (eqInfo.name.length() > 20) { - eqInfo.name = eqInfo.name.replace(m.getType().getName(), m.getType().getShortName()); + eqInfo.name = eqInfo.name.replace(m.getName(), m.getShortName()); } } diff --git a/src/megameklab/com/util/UnitUtil.java b/src/megameklab/com/util/UnitUtil.java index 2bc470d1c58..6a9fe6659cf 100644 --- a/src/megameklab/com/util/UnitUtil.java +++ b/src/megameklab/com/util/UnitUtil.java @@ -1131,10 +1131,7 @@ public static boolean isPrintableEquipment(EquipmentType eq, boolean isMech) { || eq.hasFlag(MiscType.F_HARJEL) || eq.hasFlag(MiscType.F_MASS) || eq.hasFlag(MiscType.F_CHASSIS_MODIFICATION) - || eq.hasFlag(MiscType.F_MASH_EXTRA) - || eq.hasFlag(MiscType.F_CHASSIS_MODIFICATION) - || eq.hasFlag(MiscType.F_DRONE_EXTRA) || eq - .hasFlag(MiscType.F_SPONSON_TURRET)) + || eq.hasFlag(MiscType.F_SPONSON_TURRET)) || eq.hasFlag(MiscType.F_EXTERNAL_STORES_HARDPOINT) || eq.hasFlag(MiscType.F_BASIC_FIRECONTROL) || eq.hasFlag(MiscType.F_ADVANCED_FIRECONTROL)) {