From 44950f70f5cbf975605a32b74a17b1e9d09bc8f0 Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Fri, 16 Oct 2020 13:27:45 -0400 Subject: [PATCH 1/6] Cleaning up code in UnitTableModel --- MekHQ/src/mekhq/gui/model/UnitTableModel.java | 365 ++++++++---------- 1 file changed, 162 insertions(+), 203 deletions(-) diff --git a/MekHQ/src/mekhq/gui/model/UnitTableModel.java b/MekHQ/src/mekhq/gui/model/UnitTableModel.java index 425af378b6..377864681b 100644 --- a/MekHQ/src/mekhq/gui/model/UnitTableModel.java +++ b/MekHQ/src/mekhq/gui/model/UnitTableModel.java @@ -81,6 +81,7 @@ public UnitTableModel(Campaign c) { campaign = c; } + @Override public int getRowCount() { return data.size(); } @@ -92,102 +93,99 @@ public int getColumnCount() { @Override public String getColumnName(int column) { - switch(column) { - case COL_NAME: - return "Name"; - case COL_TYPE: - return "Type"; - case COL_WEIGHT: - return "Weight"; - case COL_WCLASS: - return "Class"; - case COL_COST: - return "Value"; - case COL_TECH: - return "Tech"; - case COL_QUALITY: - return "Quality"; - case COL_STATUS: - return "Status"; - case COL_PILOT: - return "Assigned to"; - case COL_FORCE: - return "Force"; - case COL_TECH_CRW: - return "Tech Crew"; - case COL_CREW: - return "Crew"; - case COL_BV: - return "BV"; - case COL_REPAIR: - return "# Repairs"; - case COL_PARTS: - return "# Parts"; - case COL_QUIRKS: - return "Quirks"; - case COL_MAINTAIN: - return "Maintenance Costs"; - case COL_SITE: - return "Site"; - case COL_RSTATUS: - return "Repair Status"; - default: - return "?"; + switch (column) { + case COL_NAME: + return "Name"; + case COL_TYPE: + return "Type"; + case COL_WEIGHT: + return "Weight"; + case COL_WCLASS: + return "Class"; + case COL_COST: + return "Value"; + case COL_TECH: + return "Tech"; + case COL_QUALITY: + return "Quality"; + case COL_STATUS: + return "Status"; + case COL_PILOT: + return "Assigned to"; + case COL_FORCE: + return "Force"; + case COL_TECH_CRW: + return "Tech Crew"; + case COL_CREW: + return "Crew"; + case COL_BV: + return "BV"; + case COL_REPAIR: + return "# Repairs"; + case COL_PARTS: + return "# Parts"; + case COL_QUIRKS: + return "Quirks"; + case COL_MAINTAIN: + return "Maintenance Costs"; + case COL_SITE: + return "Site"; + case COL_RSTATUS: + return "Repair Status"; + default: + return "?"; } } public int getColumnWidth(int c) { - switch(c) { - case COL_WCLASS: - case COL_TYPE: - case COL_SITE: - return 50; - case COL_COST: - case COL_STATUS: - case COL_RSTATUS: - return 80; - case COL_PILOT: - case COL_FORCE: - case COL_TECH: - case COL_NAME: - case COL_TECH_CRW: - return 150; - default: - return 20; + switch (c) { + case COL_WCLASS: + case COL_TYPE: + case COL_SITE: + return 50; + case COL_COST: + case COL_STATUS: + case COL_RSTATUS: + return 80; + case COL_PILOT: + case COL_FORCE: + case COL_TECH: + case COL_NAME: + case COL_TECH_CRW: + return 150; + default: + return 20; } } public int getAlignment(int col) { - switch(col) { - case COL_QUALITY: - case COL_QUIRKS: - case COL_CREW: - case COL_RSTATUS: - return SwingConstants.CENTER; - case COL_WEIGHT: - case COL_COST: - case COL_MAINTAIN: - case COL_REPAIR: - case COL_PARTS: - case COL_BV: - return SwingConstants.RIGHT; - default: - return SwingConstants.LEFT; + switch (col) { + case COL_QUALITY: + case COL_QUIRKS: + case COL_CREW: + case COL_RSTATUS: + return SwingConstants.CENTER; + case COL_WEIGHT: + case COL_COST: + case COL_MAINTAIN: + case COL_REPAIR: + case COL_PARTS: + case COL_BV: + return SwingConstants.RIGHT; + default: + return SwingConstants.LEFT; } } public String getTooltip(int row, int col) { Unit u = getUnit(row); - switch(col) { - case COL_STATUS: - if(u.isRefitting()) { - return u.getRefit().getDesc(); - } - return null; - case COL_QUIRKS: - return u.getQuirksList(); - default: - return null; + switch (col) { + case COL_STATUS: + return u.isRefitting() ? u.getRefit().getDesc() : null; + case COL_QUIRKS: + return u.getQuirksList(); + default: + return null; } } @@ -202,99 +200,65 @@ public boolean isCellEditable(int row, int col) { } public Unit getUnit(int i) { - if(i >= data.size()) { - return null; - } - return (Unit)data.get(i); + return (i < data.size()) ? (Unit) data.get(i) : null; } + @Override public Object getValueAt(int row, int col) { Unit u; - if(data.isEmpty() || (row < 0) || row >= data.size()) { + if (data.isEmpty() || (row < 0) || (row >= data.size())) { return ""; } else { u = getUnit(row); } Entity e = u.getEntity(); - //PilotPerson pp = u.getPilot(); - if(null == e) { + if (e == null) { return "?"; } - if(col == COL_NAME) { - return u.getName(); - } - if(col == COL_TYPE) { - return UnitType.getTypeDisplayableName(e.getUnitType()); - } - if(col == COL_WEIGHT) { - return e.getWeight(); - } - if(col == COL_WCLASS) { - return e.getWeightClassName(); - } - if(col == COL_COST) { - return u.getSellValue().toAmountAndSymbolString(); - } - if(col == COL_MAINTAIN) { - return u.getMaintenanceCost(); - } - if(col == COL_TECH) { - return TechConstants.getLevelDisplayableName(e.getTechLevel()); - } - if(col == COL_QUALITY) { - return u.getQualityName(); - } - if(col == COL_STATUS) { - return u.getStatus(); - } - if(col == COL_TECH_CRW) { - if(null != u.getTech()) { - return u.getTech().getFullTitle(); - } else { - return "-"; - } - } - if(col == COL_PILOT) { - if(null == u.getCommander()) { - return "-"; - } else { - return u.getCommander().getFullTitle(); - } - } - if(col == COL_FORCE) { - Force force = u.getCampaign().getForce(u.getForceId()); - if(null == force) { - return "-"; - } else { - return force.getFullName(); - } - } - if(col == COL_BV) { - if(null == u.getEntity().getCrew()) { - return e.calculateBattleValue(true, true); - } else { - return e.calculateBattleValue(true, false); - } - } - if(col == COL_REPAIR) { - return u.getPartsNeedingFixing().size(); - } - if(col == COL_PARTS) { - return u.getPartsNeeded().size(); - } - if(col == COL_QUIRKS) { - return e.countQuirks(); - } - if(col == COL_CREW) { - return u.getActiveCrew().size() + "/" + u.getFullCrewSize(); - } - if(col == COL_SITE) { - return Unit.getSiteName(u.getSite()); - } - if (col == COL_RSTATUS) { - return u.isSalvage() ? "Salvage" : "Repair"; + + switch (col) { + case COL_NAME: + return u.getName(); + case COL_TYPE: + return UnitType.getTypeDisplayableName(e.getUnitType()); + case COL_WCLASS: + return e.getWeightClassName(); + case COL_TECH: + return TechConstants.getLevelDisplayableName(e.getTechLevel()); + case COL_WEIGHT: + return e.getWeight(); + case COL_COST: + return u.getSellValue().toAmountAndSymbolString(); + case COL_STATUS: + return u.getStatus(); + case COL_QUALITY: + return u.getQualityName(); + case COL_PILOT: + return (u.getCommander() != null) ? u.getCommander().getFullTitle() : "-"; + case COL_FORCE: + Force force = u.getCampaign().getForce(u.getForceId()); + return (force != null) ? force.getFullName() : "-"; + case COL_CREW: + return u.getActiveCrew().size() + "/" + u.getFullCrewSize(); + case COL_TECH_CRW: + return (u.getTech() != null) ? u.getTech().getFullTitle() : "-"; + case COL_MAINTAIN: + return u.getMaintenanceCost(); + case COL_BV: + return e.calculateBattleValue(true, u.getEntity().getCrew() == null); + case COL_REPAIR: + return u.getPartsNeedingFixing().size(); + case COL_PARTS: + return u.getPartsNeeded().size(); + case COL_SITE: + return Unit.getSiteName(u.getSite()); + case COL_QUIRKS: + return e.countQuirks(); + case COL_RSTATUS: + return u.isSalvage() ? "Salvage" : "Repair"; + default: + return "?"; } - return "?"; } public Campaign getCampaign() { @@ -306,14 +270,10 @@ public void refreshData() { } public TableCellRenderer getRenderer(boolean graphic) { - if (graphic) { - return new UnitTableModel.VisualRenderer(); - } - return new UnitTableModel.Renderer(); + return (graphic) ? new UnitTableModel.VisualRenderer() : new UnitTableModel.Renderer(); } public class Renderer extends DefaultTableCellRenderer { - private static final long serialVersionUID = 9054581142945717303L; @Override @@ -360,11 +320,8 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole } private void applyColors(ColorPreference c) { - setBackground(c.getColor() - .orElseGet(() -> UIManager.getColor("Table.background"))); - - setForeground(c.getAlternateColor() - .orElseGet(() -> UIManager.getColor("Table.foreground"))); + setBackground(c.getColor().orElseGet(() -> UIManager.getColor("Table.background"))); + setForeground(c.getAlternateColor().orElseGet(() -> UIManager.getColor("Table.foreground"))); } } @@ -385,37 +342,39 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole setText(getValueAt(actualRow, actualCol).toString()); Unit u = getUnit(actualRow); - if (actualCol == COL_PILOT) { - Person p = u.getCommander(); - if(null != p) { - setPortrait(p); - setText(p.getFullDesc()); - } else { - clearImage(); + switch (actualCol) { + case COL_WCLASS: { + String desc = "" + u.getName() + "
"; + desc += u.getEntity().getWeightClassName(); + if (!((u.getEntity() instanceof SmallCraft) || (u.getEntity() instanceof Jumpship))) { + desc += " " + UnitType.getTypeDisplayableName(u.getEntity().getUnitType()); + } + desc += "
" + u.getStatus() + ""; + setHtmlText(desc); + Image mekImage = getImageFor(u); + if (mekImage != null) { + setImage(mekImage); + } else { + clearImage(); + } } - } - if (actualCol == COL_TECH_CRW) { - Person p = u.getTech(); - if(null != p) { - setPortrait(p); - setText(p.getFullDesc()); - } else { - clearImage(); + case COL_PILOT: { + Person p = u.getCommander(); + if (p != null) { + setPortrait(p); + setText(p.getFullDesc()); + } else { + clearImage(); + } } - } - if(actualCol == COL_WCLASS) { - String desc = "" + u.getName() + "
"; - desc += u.getEntity().getWeightClassName(); - if(!(u.getEntity() instanceof SmallCraft || u.getEntity() instanceof Jumpship)) { - desc += " " + UnitType.getTypeDisplayableName(u.getEntity().getUnitType()); - } - desc += "
" + u.getStatus() + ""; - setHtmlText(desc); - Image mekImage = getImageFor(u); - if(null != mekImage) { - setImage(mekImage); - } else { - clearImage(); + case COL_TECH_CRW: { + Person p = u.getTech(); + if (p != null) { + setPortrait(p); + setText(p.getFullDesc()); + } else { + clearImage(); + } } } From 033b2cd899cddffabd6e1b0c45c44f12795523ad Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Fri, 16 Oct 2020 13:28:17 -0400 Subject: [PATCH 2/6] Cleaning up code in PersonnelTableModel --- .../mekhq/gui/model/PersonnelTableModel.java | 63 +++++++++---------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java b/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java index 37c81c98ef..f7653f0ef8 100644 --- a/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java +++ b/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 - The MegaMek Team. All rights reserved. + * Copyright (c) 2020 - The MegaMek Team. All Rights Reserved. * * This file is part of MekHQ. * @@ -28,7 +28,6 @@ import javax.swing.JTable; import javax.swing.SwingConstants; -import javax.swing.UIManager; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; @@ -717,8 +716,8 @@ public class Renderer extends DefaultTableCellRenderer { private static final long serialVersionUID = 9054581142945717303L; @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, - int row, int column) { + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, + boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setOpaque(true); int actualCol = table.convertColumnIndexToModel(column); @@ -726,22 +725,17 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole setHorizontalAlignment(getAlignment(actualCol)); setToolTipText(getTooltip(actualRow, actualCol)); - setForeground(UIManager.getColor("Table.foreground")); - if (isSelected) { - setBackground(UIManager.getColor("Table.selectionBackground")); - setForeground(UIManager.getColor("Table.selectionForeground")); - } else { + if (!isSelected) { if (isDeployed(actualRow)) { colors.getDeployed().getColor().ifPresent(this::setBackground); colors.getDeployed().getAlternateColor().ifPresent(this::setForeground); - } else if ((Integer.parseInt((String) getValueAt(actualRow,COL_HITS)) > 0) || getPerson(actualRow).hasInjuries(true)) { + } else if ((Integer.parseInt((String) getValueAt(actualRow,COL_HITS)) > 0) + || getPerson(actualRow).hasInjuries(true)) { colors.getInjured().getColor().ifPresent(this::setBackground); colors.getInjured().getAlternateColor().ifPresent(this::setForeground); } else if (getPerson(actualRow).hasOnlyHealedPermanentInjuries()) { colors.getHealedInjuries().getColor().ifPresent(this::setBackground); colors.getHealedInjuries().getAlternateColor().ifPresent(this::setForeground); - } else { - setBackground(UIManager.getColor("Table.background")); } } return this; @@ -757,9 +751,8 @@ public VisualRenderer() { } @Override - public Component getTableCellRendererComponent(JTable table, - Object value, boolean isSelected, boolean hasFocus, - int row, int column) { + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, + boolean hasFocus, int row, int column) { Component c = this; int actualCol = table.convertColumnIndexToModel(column); int actualRow = table.convertRowIndexToModel(row); @@ -767,7 +760,7 @@ public Component getTableCellRendererComponent(JTable table, setText(getValueAt(actualRow, actualCol).toString()); - switch(actualCol) { + switch (actualCol) { case COL_RANK: setPortrait(p); setText(p.getFullDesc()); @@ -775,12 +768,13 @@ public Component getTableCellRendererComponent(JTable table, case COL_ASSIGN: if (loadAssignmentFromMarket) { Entity en = personnelMarket.getAttachedEntity(p); - setText(en != null ? en.getDisplayName() : "-"); + setText((en != null) ? en.getDisplayName() : "-"); } else { Unit u = getCampaign().getUnit(p.getUnitId()); if ((u == null) && !p.getTechUnitIDs().isEmpty()) { u = getCampaign().getUnit(p.getTechUnitIDs().get(0)); } + if (u != null) { String desc = "" + u.getName() + "
"; desc += u.getEntity().getWeightClassName(); @@ -802,7 +796,7 @@ public Component getTableCellRendererComponent(JTable table, break; case COL_FORCE: Force force = getCampaign().getForceFor(p); - if (null != force) { + if (force != null) { StringBuilder desc = new StringBuilder("").append(force.getName()) .append(""); Force parent = force.getParentForce(); @@ -816,7 +810,7 @@ public Component getTableCellRendererComponent(JTable table, desc.append(""); setHtmlText(desc.toString()); Image forceImage = getImageFor(force); - if (null != forceImage) { + if (forceImage != null) { setImage(forceImage); } else { clearImage(); @@ -827,7 +821,7 @@ public Component getTableCellRendererComponent(JTable table, break; case COL_HITS: Image hitImage = getHitsImage(p.getHits()); - if (null != hitImage) { + if (hitImage != null) { setImage(hitImage); } else { clearImage(); @@ -841,21 +835,22 @@ public Component getTableCellRendererComponent(JTable table, } private Image getHitsImage(int hits) { - switch(hits) { - case 1: - return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/onehit.png"); - case 2: - return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/twohits.png"); - case 3: - return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/threehits.png"); - case 4: - return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/fourhits.png"); - case 5: - return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/fivehits.png"); - case 6: - return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/sixhits.png"); + switch (hits) { + case 1: + return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/onehit.png"); + case 2: + return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/twohits.png"); + case 3: + return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/threehits.png"); + case 4: + return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/fourhits.png"); + case 5: + return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/fivehits.png"); + case 6: + return Toolkit.getDefaultToolkit().getImage("data/images/misc/hits/sixhits.png"); + default: + return null; } - return null; } } From 08bcb4718b3ae6b2c514bdb0c63c5c483eff1043 Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Fri, 16 Oct 2020 13:30:33 -0400 Subject: [PATCH 3/6] Adding missing breaks for a switch --- MekHQ/src/mekhq/gui/model/UnitTableModel.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/MekHQ/src/mekhq/gui/model/UnitTableModel.java b/MekHQ/src/mekhq/gui/model/UnitTableModel.java index 377864681b..7d85ca844d 100644 --- a/MekHQ/src/mekhq/gui/model/UnitTableModel.java +++ b/MekHQ/src/mekhq/gui/model/UnitTableModel.java @@ -287,10 +287,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole setToolTipText(getTooltip(actualRow, actualCol)); Unit u = getUnit(actualRow); - if (isSelected) { - setBackground(UIManager.getColor("Table.selectionBackground")); - setForeground(UIManager.getColor("Table.selectionForeground")); - } else { + if (!isSelected) { if (u.isDeployed()) { applyColors(colors.getDeployed()); } else if(!u.isPresent()) { @@ -311,9 +308,6 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole applyColors(colors.getUnmaintained()); } else if (u.getActiveCrew().size() < u.getFullCrewSize()) { applyColors(colors.getUncrewed()); - } else { - setBackground(UIManager.getColor("Table.background")); - setForeground(UIManager.getColor("Table.foreground")); } } return this; @@ -357,6 +351,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole } else { clearImage(); } + break; } case COL_PILOT: { Person p = u.getCommander(); @@ -366,6 +361,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole } else { clearImage(); } + break; } case COL_TECH_CRW: { Person p = u.getTech(); @@ -375,6 +371,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole } else { clearImage(); } + break; } } From 01373e20380db42371dcfec51d34e2db74c2b5cd Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Fri, 16 Oct 2020 13:36:35 -0400 Subject: [PATCH 4/6] Further cleanup --- .../mekhq/gui/model/PersonnelTableModel.java | 44 ++++++------------- MekHQ/src/mekhq/gui/model/UnitTableModel.java | 8 +--- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java b/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java index f7653f0ef8..e51e86b569 100644 --- a/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java +++ b/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java @@ -303,12 +303,12 @@ public String getTooltip(int row, int col) { return p.getAbilityListAsString(PilotOptions.LVL3_ADVANTAGES); case COL_NIMP: return p.getAbilityListAsString(PilotOptions.MD_ADVANTAGES); - case COL_ASSIGN: + case COL_ASSIGN: { if ((p.getTechUnitIDs().size() > 1) && !loadAssignmentFromMarket) { StringBuilder toReturn = new StringBuilder(""); for (UUID id : p.getTechUnitIDs()) { Unit u = getCampaign().getUnit(id); - if (null != u) { + if (u != null) { toReturn.append(u.getName()).append("
"); } } @@ -317,6 +317,7 @@ public String getTooltip(int row, int col) { } else { return null; } + } default: return null; } @@ -333,11 +334,7 @@ public boolean isCellEditable(int row, int col) { } public Person getPerson(int i) { - if (i >= data.size()) { - return null; - } else { - return (Person) data.get(i); - } + return (i < data.size()) ? (Person) data.get(i) : null; } public boolean isDeployed(int row) { @@ -362,13 +359,13 @@ public Object getValueAt(int row, int col) { return p.getGivenName(); case COL_LAST_NAME: return p.getLastName(); - case COL_SURNAME: + case COL_SURNAME: { toReturn = p.getSurname(); if (StringUtil.isNullOrEmpty(toReturn)) { return ""; } else if (!getGroupByUnit()) { return toReturn; - } else { + } else { // If we're grouping by unit, determine the number of persons under // their command. UUID unitId = p.getUnitId(); @@ -398,22 +395,13 @@ public Object getValueAt(int row, int col) { ? resources.getString("surname_soldiers.text") : resources.getString("surname_crew.text")); } + } case COL_HONORIFIC: - toReturn = p.getHonorific(); - if (!StringUtil.isNullOrEmpty(toReturn)) { - return toReturn; - } else { - return ""; - } + return p.getHonorific(); case COL_CALL: return p.getCallsign(); case COL_BLOODNAME: - toReturn = p.getBloodname(); - if (!StringUtil.isNullOrEmpty(toReturn)) { - return toReturn; - } else { - return ""; - } + return p.getBloodname(); case COL_GENDER: return GenderDescriptors.MALE_FEMALE.getDescriptorCapitalized(p.getGender()); case COL_AGE: @@ -591,10 +579,10 @@ public Object getValueAt(int row, int col) { return Integer.toString(p.getHits()); case COL_SKILL: return p.getSkillSummary(); - case COL_ASSIGN: + case COL_ASSIGN: { if (loadAssignmentFromMarket) { Entity en = personnelMarket.getAttachedEntity(p); - return ((en != null) ? en.getDisplayName() : "-"); + return ((en != null) ? en.getDisplayName() : "-"); } else { Unit u = getCampaign().getUnit(p.getUnitId()); if (u != null) { @@ -633,22 +621,18 @@ public Object getValueAt(int row, int col) { } } break; + } case COL_XP: return Integer.toString(p.getXP()); case COL_DEPLOY: Unit u = getCampaign().getUnit(p.getUnitId()); - if ((null != u) && u.isDeployed()) { + if ((u != null) && u.isDeployed()) { return getCampaign().getScenario(u.getScenarioId()).getName(); } - break; case COL_FORCE: Force force = getCampaign().getForceFor(p); - if (null != force) { - return force.getName(); - } else { - return resources.getString("force_none.text"); - } + return (force != null) ? force.getName() : resources.getString("force_none.text"); case COL_SALARY: return p.getSalary().toAmountAndSymbolString(); case COL_KILLS: diff --git a/MekHQ/src/mekhq/gui/model/UnitTableModel.java b/MekHQ/src/mekhq/gui/model/UnitTableModel.java index 7d85ca844d..245ae47718 100644 --- a/MekHQ/src/mekhq/gui/model/UnitTableModel.java +++ b/MekHQ/src/mekhq/gui/model/UnitTableModel.java @@ -265,10 +265,6 @@ public Campaign getCampaign() { return campaign; } - public void refreshData() { - setData(new ArrayList<>(getCampaign().getHangar().getUnits())); - } - public TableCellRenderer getRenderer(boolean graphic) { return (graphic) ? new UnitTableModel.VisualRenderer() : new UnitTableModel.Renderer(); } @@ -290,9 +286,9 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole if (!isSelected) { if (u.isDeployed()) { applyColors(colors.getDeployed()); - } else if(!u.isPresent()) { + } else if (!u.isPresent()) { applyColors(colors.getInTransit()); - } else if(u.isRefitting()) { + } else if (u.isRefitting()) { applyColors(colors.getRefitting()); } else if (u.isMothballing()) { applyColors(colors.getMothballing()); From 4870ddcba90639c8009a908d7ab2c6f3fce992db Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Fri, 16 Oct 2020 13:55:55 -0400 Subject: [PATCH 5/6] Adding Force graphic to UnitTableModel graphical display --- MekHQ/src/mekhq/gui/model/UnitTableModel.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/MekHQ/src/mekhq/gui/model/UnitTableModel.java b/MekHQ/src/mekhq/gui/model/UnitTableModel.java index 245ae47718..d2ec61890f 100644 --- a/MekHQ/src/mekhq/gui/model/UnitTableModel.java +++ b/MekHQ/src/mekhq/gui/model/UnitTableModel.java @@ -359,6 +359,32 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole } break; } + case COL_FORCE: { + Force force = getCampaign().getForceFor(u); + if (force != null) { + StringBuilder desc = new StringBuilder("").append(force.getName()) + .append(""); + Force parent = force.getParentForce(); + //cut off after three lines and don't include the top level + int lines = 1; + while ((parent != null) && (parent.getParentForce() != null) && (lines < 4)) { + desc.append("
").append(parent.getName()); + lines++; + parent = parent.getParentForce(); + } + desc.append(""); + setHtmlText(desc.toString()); + Image forceImage = getImageFor(force); + if (forceImage != null) { + setImage(forceImage); + } else { + clearImage(); + } + } else { + clearImage(); + } + break; + } case COL_TECH_CRW: { Person p = u.getTech(); if (p != null) { From 467736f024e8345ba710fb20ba4cb220061fee52 Mon Sep 17 00:00:00 2001 From: Windchild292 Date: Fri, 16 Oct 2020 14:02:28 -0400 Subject: [PATCH 6/6] 1723: Fixing missing selected line on Hangar and Personnel Tabs --- MekHQ/src/mekhq/gui/model/PersonnelTableModel.java | 8 +++++--- MekHQ/src/mekhq/gui/model/UnitTableModel.java | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java b/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java index e51e86b569..95bf2c6765 100644 --- a/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java +++ b/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java @@ -26,8 +26,7 @@ import java.util.ResourceBundle; import java.util.UUID; -import javax.swing.JTable; -import javax.swing.SwingConstants; +import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; @@ -713,13 +712,16 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole if (isDeployed(actualRow)) { colors.getDeployed().getColor().ifPresent(this::setBackground); colors.getDeployed().getAlternateColor().ifPresent(this::setForeground); - } else if ((Integer.parseInt((String) getValueAt(actualRow,COL_HITS)) > 0) + } else if ((Integer.parseInt((String) getValueAt(actualRow, COL_HITS)) > 0) || getPerson(actualRow).hasInjuries(true)) { colors.getInjured().getColor().ifPresent(this::setBackground); colors.getInjured().getAlternateColor().ifPresent(this::setForeground); } else if (getPerson(actualRow).hasOnlyHealedPermanentInjuries()) { colors.getHealedInjuries().getColor().ifPresent(this::setBackground); colors.getHealedInjuries().getAlternateColor().ifPresent(this::setForeground); + } else { + setBackground(UIManager.getColor("Table.background")); + setForeground(UIManager.getColor("Table.foreground")); } } return this; diff --git a/MekHQ/src/mekhq/gui/model/UnitTableModel.java b/MekHQ/src/mekhq/gui/model/UnitTableModel.java index d2ec61890f..c7863e6736 100644 --- a/MekHQ/src/mekhq/gui/model/UnitTableModel.java +++ b/MekHQ/src/mekhq/gui/model/UnitTableModel.java @@ -304,6 +304,9 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole applyColors(colors.getUnmaintained()); } else if (u.getActiveCrew().size() < u.getFullCrewSize()) { applyColors(colors.getUncrewed()); + } else { + setForeground(UIManager.getColor("Table.foreground")); + setBackground(UIManager.getColor("Table.background")); } } return this;