Skip to content

Commit

Permalink
Merge pull request #2148 from Windchild292/dev_Windchild_1723
Browse files Browse the repository at this point in the history
1723: Fixing Missing Personnel and Hangar Tab Selection Highlights
  • Loading branch information
Windchild292 authored Oct 16, 2020
2 parents 14df0dd + 467736f commit 4e6d5f0
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 277 deletions.
109 changes: 45 additions & 64 deletions MekHQ/src/mekhq/gui/model/PersonnelTableModel.java
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -26,9 +26,7 @@
import java.util.ResourceBundle;
import java.util.UUID;

import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

Expand Down Expand Up @@ -304,12 +302,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("<html>");
for (UUID id : p.getTechUnitIDs()) {
Unit u = getCampaign().getUnit(id);
if (null != u) {
if (u != null) {
toReturn.append(u.getName()).append("<br>");
}
}
Expand All @@ -318,6 +316,7 @@ public String getTooltip(int row, int col) {
} else {
return null;
}
}
default:
return null;
}
Expand All @@ -334,11 +333,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) {
Expand All @@ -363,13 +358,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();
Expand Down Expand Up @@ -399,22 +394,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:
Expand Down Expand Up @@ -592,10 +578,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) {
Expand Down Expand Up @@ -634,22 +620,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:
Expand Down Expand Up @@ -717,31 +699,29 @@ 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);
int actualRow = table.convertRowIndexToModel(row);
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"));
setForeground(UIManager.getColor("Table.foreground"));
}
}
return this;
Expand All @@ -757,30 +737,30 @@ 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);
Person p = getPerson(actualRow);

setText(getValueAt(actualRow, actualCol).toString());

switch(actualCol) {
switch (actualCol) {
case COL_RANK:
setPortrait(p);
setText(p.getFullDesc());
break;
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 = "<b>" + u.getName() + "</b><br>";
desc += u.getEntity().getWeightClassName();
Expand All @@ -802,7 +782,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("<html><b>").append(force.getName())
.append("</b>");
Force parent = force.getParentForce();
Expand All @@ -816,7 +796,7 @@ public Component getTableCellRendererComponent(JTable table,
desc.append("</html>");
setHtmlText(desc.toString());
Image forceImage = getImageFor(force);
if (null != forceImage) {
if (forceImage != null) {
setImage(forceImage);
} else {
clearImage();
Expand All @@ -827,7 +807,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();
Expand All @@ -841,21 +821,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;
}
}

Expand Down
Loading

0 comments on commit 4e6d5f0

Please sign in to comment.