diff --git a/MekHQ/src/mekhq/gui/ForceRenderer.java b/MekHQ/src/mekhq/gui/ForceRenderer.java
index d6e5a5cfbc1..b19159463d5 100644
--- a/MekHQ/src/mekhq/gui/ForceRenderer.java
+++ b/MekHQ/src/mekhq/gui/ForceRenderer.java
@@ -1,6 +1,5 @@
package mekhq.gui;
-import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.util.UUID;
@@ -24,7 +23,8 @@ public class ForceRenderer extends DefaultTreeCellRenderer {
private static final long serialVersionUID = -553191867660269247L;
- private IconPackage icons;
+ private final IconPackage icons;
+ private final MekHqColors colors = new MekHqColors();
public ForceRenderer(IconPackage i) {
icons = i;
@@ -133,12 +133,12 @@ public Component getTreeCellRendererComponent(
}
setText("" + name + ", " + uname + c3network + transport + "");
if(u.isDeployed() && !sel) {
- setBackground(Color.LIGHT_GRAY);
+ colors.getDeployed().getColor().ifPresent(c -> setBackground(c));
}
}
if(value instanceof Force) {
if(!hasFocus && ((Force)value).isDeployed()) {
- setBackground(Color.LIGHT_GRAY);
+ colors.getDeployed().getColor().ifPresent(c -> setBackground(c));
}
}
setIcon(getIcon(value));
@@ -205,4 +205,4 @@ protected Icon getIconFrom(Force force) {
}
return new ImageIcon(forceImage);
}
-}
\ No newline at end of file
+}
diff --git a/MekHQ/src/mekhq/gui/MekHqColors.java b/MekHQ/src/mekhq/gui/MekHqColors.java
new file mode 100644
index 00000000000..2a5057af2ad
--- /dev/null
+++ b/MekHQ/src/mekhq/gui/MekHqColors.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2020 The MegaMek Team. All rights reserved.
+ *
+ * This file is part of MekHQ.
+ *
+ * MekHQ is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * MekHQ is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MekHQ. If not, see .
+ */
+package mekhq.gui;
+
+import java.awt.Color;
+
+import javax.swing.UIManager;
+
+import mekhq.MekHQ;
+import mekhq.gui.preferences.ColorPreference;
+import mekhq.preferences.PreferencesNode;
+
+public class MekHqColors {
+
+ //
+ // General Colors
+ //
+
+ private static ColorPreference iconButtonColors;
+
+ //
+ // Force Colors
+ //
+
+ private static ColorPreference deployedColors;
+ private static ColorPreference belowContractMinimumColors;
+
+ //
+ // Unit Colors
+ //
+
+ private static ColorPreference inTransitColors;
+ private static ColorPreference refittingColors;
+ private static ColorPreference mothballingColors;
+ private static ColorPreference mothballedColors;
+ private static ColorPreference notRepairableColors;
+ private static ColorPreference nonfunctionalColors;
+ private static ColorPreference needsPartsFixedColors;
+ private static ColorPreference uncrewedColors;
+
+ //
+ // Financial Colors
+ //
+
+ private static ColorPreference loanOverdueColors;
+
+ //
+ // Personnel Colors
+ //
+
+ private static ColorPreference injuredColors;
+ private static ColorPreference healedInjuriesColors;
+ private static ColorPreference paidRetirementColors;
+
+ static {
+ final PreferencesNode preferences = MekHQ.getPreferences().forClass(MekHqColors.class);
+
+ iconButtonColors = new ColorPreference("iconButton", Color.LIGHT_GRAY, Color.BLACK);
+
+ deployedColors = new ColorPreference("deployed", Color.LIGHT_GRAY, Color.BLACK);
+ belowContractMinimumColors = new ColorPreference("belowContractMinimum", UIManager.getColor("Table.background"), Color.RED);
+
+ inTransitColors = new ColorPreference("inTransit", Color.ORANGE, Color.BLACK);
+ refittingColors = new ColorPreference("refitting", Color.CYAN, Color.BLACK);
+ mothballingColors = new ColorPreference("mothballing", new Color(153,153,255), Color.BLACK);
+ mothballedColors = new ColorPreference("mothballed", new Color(204, 204, 255), Color.BLACK);
+ notRepairableColors = new ColorPreference("notRepairable", new Color(190, 150, 55), Color.BLACK);
+ nonfunctionalColors = new ColorPreference("nonfunctional", new Color(205, 92, 92), Color.BLACK);
+ needsPartsFixedColors = new ColorPreference("needsPartsFixed", new Color(238, 238, 0), Color.BLACK);
+ uncrewedColors = new ColorPreference("uncrewed", Color.RED, Color.BLACK);
+
+ loanOverdueColors = new ColorPreference("loanOverdue", Color.RED, Color.BLACK);
+
+ injuredColors = new ColorPreference("injured", Color.RED, Color.BLACK);
+ healedInjuriesColors = new ColorPreference("healed", new Color(0xee9a00), Color.BLACK);
+ paidRetirementColors = new ColorPreference("paidRetirement", Color.LIGHT_GRAY, Color.BLACK);
+
+ preferences.manage(iconButtonColors, deployedColors, belowContractMinimumColors, inTransitColors, refittingColors,
+ mothballingColors, mothballedColors, notRepairableColors, nonfunctionalColors, needsPartsFixedColors,
+ uncrewedColors, loanOverdueColors, injuredColors, healedInjuriesColors, paidRetirementColors);
+ }
+
+ public ColorPreference getIconButton() {
+ return iconButtonColors;
+ }
+
+ public ColorPreference getDeployed() {
+ return deployedColors;
+ }
+
+ public ColorPreference getBelowContractMinimum() {
+ return belowContractMinimumColors;
+ }
+
+ public ColorPreference getInTransit() {
+ return inTransitColors;
+ }
+
+ public ColorPreference getRefitting() {
+ return refittingColors;
+ }
+
+ public ColorPreference getMothballing() {
+ return mothballingColors;
+ }
+
+ public ColorPreference getMothballed() {
+ return mothballedColors;
+ }
+
+ public ColorPreference getNotRepairable() {
+ return notRepairableColors;
+ }
+
+ public ColorPreference getNonFunctional() {
+ return nonfunctionalColors;
+ }
+
+ public ColorPreference getNeedsPartsFixed() {
+ return needsPartsFixedColors;
+ }
+
+ public ColorPreference getUncrewed() {
+ return uncrewedColors;
+ }
+
+ public ColorPreference getLoanOverdue() {
+ return loanOverdueColors;
+ }
+
+ public ColorPreference getInjured() {
+ return injuredColors;
+ }
+
+ public ColorPreference getHealedInjuries() {
+ return healedInjuriesColors;
+ }
+
+ public ColorPreference getPaidRetirement() {
+ return paidRetirementColors;
+ }
+}
diff --git a/MekHQ/src/mekhq/gui/dialog/ObjectiveEditPanel.java b/MekHQ/src/mekhq/gui/dialog/ObjectiveEditPanel.java
index ecaf714bd9a..4bc56088392 100644
--- a/MekHQ/src/mekhq/gui/dialog/ObjectiveEditPanel.java
+++ b/MekHQ/src/mekhq/gui/dialog/ObjectiveEditPanel.java
@@ -36,6 +36,7 @@
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
+import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import megamek.common.OffBoardDirection;
@@ -60,79 +61,79 @@ public class ObjectiveEditPanel extends JDialog {
private JTextField txtPercentage;
private JComboBox cboCountType;
private JComboBox cboForceName;
-
+
private JLabel lblMagnitude;
private JTextField txtAmount;
private JComboBox cboScalingType;
private JComboBox cboEffectType;
private JComboBox cboEffectCondition;
-
+
private JList successEffects;
private JList failureEffects;
private JButton btnRemoveSuccess;
private JButton btnRemoveFailure;
-
+
private JComboBox cboTimeLimitDirection;
private JComboBox cboTimeScaling;
private JTextField txtTimeLimit;
-
+
private JList forceNames;
JButton btnRemove;
-
+
private JList lstDetails;
-
+
private ScenarioTemplate currentScenarioTemplate;
private ScenarioObjective objective;
private ScenarioTemplateEditorDialog parent;
-
+
public ObjectiveEditPanel(ScenarioTemplate template, ScenarioTemplateEditorDialog parent) {
currentScenarioTemplate = template;
objective = new ScenarioObjective();
this.parent = parent;
-
+
initGUI();
updateTimeLimitUI();
validate();
pack();
setLocationRelativeTo(parent);
}
-
+
public ObjectiveEditPanel(ScenarioTemplate template, ScenarioObjective objective, ScenarioTemplateEditorDialog parent) {
currentScenarioTemplate = template;
this.objective = objective;
this.parent = parent;
-
+
initGUI();
updateForceList();
-
+
txtShortDescription.setText(objective.getDescription());
cboObjectiveType.setSelectedItem(objective.getObjectiveCriterion());
cboCountType.setSelectedItem(objective.getAmountType());
txtPercentage.setText(Integer.toString(objective.getAmount()));
setDirectionDropdownVisibility();
-
+
cboDirection.setSelectedIndex(objective.getDestinationEdge().ordinal());
-
+
cboTimeScaling.setSelectedItem(objective.getTimeLimitType());
updateTimeLimitUI();
cboTimeLimitDirection.setSelectedIndex(objective.isTimeLimitAtMost() ? 0 : 1);
if(objective.getTimeLimitType() == TimeLimitType.ScaledToPrimaryUnitCount) {
txtTimeLimit.setText(objective.getTimeLimitScaleFactor().toString());
} else {
- if(objective.getTimeLimit() != null) {
+ if(objective.getTimeLimit() != null) {
txtTimeLimit.setText(objective.getTimeLimit().toString());
}
}
-
+
updateEffectList(successEffects, objective.getSuccessEffects());
updateEffectList(failureEffects, objective.getFailureEffects());
updateDetailList();
-
+
validate();
pack();
setLocationRelativeTo(parent);
}
-
+
private void initGUI() {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = 1;
@@ -140,9 +141,9 @@ private void initGUI() {
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
-
+
getContentPane().setLayout(new GridBagLayout());
-
+
addDescriptionUI(gbc);
gbc.gridx = 0;
gbc.gridy++;
@@ -150,27 +151,27 @@ private void initGUI() {
addObjectiveTypeUI(gbc);
gbc.gridx = 0;
gbc.gridy++;
-
+
addSubjectForce(gbc);
gbc.gridx = 0;
gbc.gridy++;
-
+
addTimeLimitUI(gbc);
gbc.gridx = 0;
gbc.gridy++;
-
+
addEffectUI(gbc);
gbc.gridx = 0;
gbc.gridy++;
-
+
addObjectiveEffectUI(gbc);
-
+
gbc.gridx = 0;
gbc.gridy++;
-
+
addSaveCloseButtons(gbc);
}
-
+
/**
* Handles the save/close buttons row.
*/
@@ -181,24 +182,24 @@ private void addSaveCloseButtons(GridBagConstraints gbc) {
localGbc.gridx = 0;
localGbc.gridy = 0;
localGbc.insets = new Insets(0, 0, 0, 5);
-
+
JButton btnCancel = new JButton("Cancel");
btnCancel.addActionListener(e -> this.setVisible(false));
JButton btnSaveAndClose = new JButton("Save and Close");
btnSaveAndClose.addActionListener(e -> this.saveObjectiveAndClose());
-
+
saveClosePanel.add(btnCancel);
saveClosePanel.add(btnSaveAndClose);
-
+
getContentPane().add(saveClosePanel, gbc);
}
-
+
/**
* Handles the "description" row.
*/
private void addDescriptionUI(GridBagConstraints gbc) {
lblShortDescription = new JLabel("Short Description:");
-
+
JScrollPane txtScroll = new JScrollPane();
txtShortDescription = new JTextArea();
txtShortDescription.setColumns(40);
@@ -206,26 +207,26 @@ private void addDescriptionUI(GridBagConstraints gbc) {
txtShortDescription.setLineWrap(true);
txtShortDescription.setWrapStyleWord(true);
txtScroll.setViewportView(txtShortDescription);
-
+
JTextField txtDetail = new JTextField();
txtDetail.setColumns(40);
JLabel lblDetail = new JLabel("Details (shows up after force/unit list):");
lstDetails = new JList<>();
JButton btnAddDetail = new JButton("Add");
JButton btnRemoveDetail = new JButton("Remove");
-
+
lstDetails.addListSelectionListener(e -> btnRemoveDetail.setEnabled(lstDetails.getSelectedValuesList().size() > 0));
lstDetails.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
btnRemoveDetail.addActionListener(e -> this.removeDetails());
btnAddDetail.addActionListener(e -> this.addDetail(txtDetail));
-
+
JPanel descriptionPanel = new JPanel();
descriptionPanel.setLayout(new GridBagLayout());
GridBagConstraints localGbc = new GridBagConstraints();
localGbc.gridx = 0;
localGbc.gridy = 0;
localGbc.insets = new Insets(5, 0, 5, 5);
-
+
descriptionPanel.add(lblShortDescription, localGbc);
localGbc.gridx++;
descriptionPanel.add(txtScroll, localGbc);
@@ -240,45 +241,45 @@ private void addDescriptionUI(GridBagConstraints gbc) {
descriptionPanel.add(lstDetails, localGbc);
localGbc.gridx++;
descriptionPanel.add(btnRemoveDetail, localGbc);
-
+
getContentPane().add(descriptionPanel, gbc);
}
-
+
/**
* Handles the "objective type" row
*/
private void addObjectiveTypeUI(GridBagConstraints gbc) {
JPanel objectivePanel = new JPanel();
-
- lblObjectiveType = new JLabel("Objective Type:");
+
+ lblObjectiveType = new JLabel("Objective Type:");
cboObjectiveType = new JComboBox<>();
for(ObjectiveCriterion objectiveType : ObjectiveCriterion.values()) {
cboObjectiveType.addItem(objectiveType);
}
cboObjectiveType.addActionListener(e -> this.setDirectionDropdownVisibility());
-
+
txtPercentage = new JTextField();
txtPercentage.setColumns(4);
-
+
cboCountType = new JComboBox<>();
cboCountType.addItem("Percent");
cboCountType.addItem("Fixed Amount");
-
-
+
+
cboDirection = new JComboBox<>();
cboDirection.addItem("Force Destination Edge");
for(int x = 1; x < OffBoardDirection.values().length; x++) {
cboDirection.addItem(OffBoardDirection.values()[x].toString());
}
cboDirection.setVisible(false);
-
+
objectivePanel.setLayout(new GridBagLayout());
GridBagConstraints localGbc = new GridBagConstraints();
localGbc.gridx = 0;
localGbc.gridy = 0;
localGbc.insets = new Insets(0, 0, 0, 5);
-
-
+
+
objectivePanel.add(lblObjectiveType, localGbc);
localGbc.gridx++;
objectivePanel.add(cboObjectiveType, localGbc);
@@ -288,39 +289,39 @@ private void addObjectiveTypeUI(GridBagConstraints gbc) {
objectivePanel.add(txtPercentage, localGbc);
localGbc.gridx++;
objectivePanel.add(cboCountType, localGbc);
-
+
getContentPane().add(objectivePanel, gbc);
}
-
+
/**
* Handles the UI for adding objective effects
*/
private void addObjectiveEffectUI(GridBagConstraints gbc) {
JPanel effectPanel = new JPanel();
-
-
+
+
JLabel lblSuccessEffects = new JLabel("Effects on completion:");
JLabel lblFailureEffects = new JLabel("Effects on failure:");
-
+
successEffects = new JList<>();
successEffects.addListSelectionListener(e -> btnRemoveSuccess.setEnabled(successEffects.getSelectedValuesList().size() > 0));
failureEffects = new JList<>();
failureEffects.addListSelectionListener(e -> btnRemoveFailure.setEnabled(failureEffects.getSelectedValuesList().size() > 0));
-
+
btnRemoveSuccess = new JButton("Remove");
btnRemoveSuccess.addActionListener(e -> this.removeEffect(ObjectiveEffectConditionType.ObjectiveSuccess));
btnRemoveSuccess.setEnabled(false);
-
+
btnRemoveFailure = new JButton("Remove");
btnRemoveFailure.addActionListener(e -> this.removeEffect(ObjectiveEffectConditionType.ObjectiveFailure));
btnRemoveFailure.setEnabled(false);
-
+
GridBagConstraints localGbc = new GridBagConstraints();
effectPanel.setLayout(new GridBagLayout());
localGbc.gridx = 0;
localGbc.gridy = 0;
localGbc.insets = new Insets(0, 0, 0, 5);
-
+
effectPanel.add(lblSuccessEffects, localGbc);
localGbc.gridx++;
effectPanel.add(successEffects, localGbc);
@@ -332,39 +333,39 @@ private void addObjectiveEffectUI(GridBagConstraints gbc) {
effectPanel.add(failureEffects, localGbc);
localGbc.gridx++;
effectPanel.add(btnRemoveFailure, localGbc);
-
+
getContentPane().add(effectPanel, gbc);
}
-
+
/**
* Handles the UI for adding/removing forces relevant to this objective
*/
private void addSubjectForce(GridBagConstraints gbc) {
JPanel forcePanel = new JPanel();
-
+
JLabel forcesLabel = new JLabel("Force Names:");
-
+
cboForceName = new JComboBox();
for(ScenarioForceTemplate forceTemplate : currentScenarioTemplate.getAllScenarioForces()) {
cboForceName.addItem(forceTemplate.getForceName());
}
-
+
forceNames = new JList();
forceNames.setVisibleRowCount(5);
forceNames.addListSelectionListener(e -> btnRemove.setEnabled(forceNames.getSelectedValuesList().size() > 0));
-
+
JButton btnAdd = new JButton("Add");
btnAdd.addActionListener(e -> this.addForce());
-
+
btnRemove = new JButton("Remove");
btnRemove.addActionListener(e -> this.removeForce());
btnRemove.setEnabled(false);
-
+
GridBagConstraints localGbc = new GridBagConstraints();
localGbc.gridx = 0;
localGbc.gridy = 0;
localGbc.insets = new Insets(0, 0, 0, 5);
-
+
forcePanel.add(forcesLabel, localGbc);
localGbc.gridx++;
forcePanel.add(cboForceName, localGbc);
@@ -375,80 +376,80 @@ private void addSubjectForce(GridBagConstraints gbc) {
forcePanel.add(forceNames, localGbc);
localGbc.gridx++;
forcePanel.add(btnRemove, localGbc);
-
-
+
+
getContentPane().add(forcePanel, gbc);
}
-
+
private void addTimeLimitUI(GridBagConstraints gbc) {
JPanel timeLimitPanel = new JPanel();
-
+
JLabel timeLimitLabel = new JLabel("Time Limit:");
-
+
cboTimeLimitDirection = new JComboBox<>();
cboTimeLimitDirection.addItem("at most");
cboTimeLimitDirection.addItem("at least");
-
+
cboTimeScaling = new JComboBox<>();
for(TimeLimitType timeLimitType : TimeLimitType.values()) {
cboTimeScaling.addItem(timeLimitType);
}
cboTimeScaling.addActionListener(e -> this.updateTimeLimitUI());
-
+
txtTimeLimit = new JTextField();
txtTimeLimit.setColumns(5);
-
+
GridBagConstraints localGbc = new GridBagConstraints();
localGbc.gridx = 0;
localGbc.gridy = 0;
localGbc.insets = new Insets(0, 0, 0, 5);
-
+
timeLimitPanel.add(cboTimeLimitDirection, localGbc);
localGbc.gridx++;
timeLimitPanel.add(cboTimeScaling, localGbc);
localGbc.gridx++;
timeLimitPanel.add(txtTimeLimit, localGbc);
-
-
+
+
getContentPane().add(timeLimitPanel, gbc);
}
-
+
/**
* Handles the "add objective effect" row
*/
private void addEffectUI(GridBagConstraints gbc) {
JPanel effectPanel = new JPanel();
-
+
lblMagnitude = new JLabel("Amount:");
txtAmount = new JTextField();
txtAmount.setColumns(5);
-
+
JLabel lblScaling = new JLabel("Effect Scaling:");
cboScalingType = new JComboBox<>();
for(EffectScalingType scalingType : EffectScalingType.values()) {
cboScalingType.addItem(scalingType);
}
-
+
JLabel lblEffectType = new JLabel("Effect Type:");
cboEffectType = new JComboBox<>();
for(ObjectiveEffectType scalingType : ObjectiveEffectType.values()) {
cboEffectType.addItem(scalingType);
}
-
+
JLabel lblEffectCondition = new JLabel("Effect Condition:");
cboEffectCondition = new JComboBox<>();
cboEffectCondition.addItem(ObjectiveEffectConditionType.ObjectiveSuccess);
cboEffectCondition.addItem(ObjectiveEffectConditionType.ObjectiveFailure);
-
+
JButton btnAdd = new JButton("Add");
btnAdd.addActionListener(e -> this.addEffect());
-
+
GridBagConstraints localGbc = new GridBagConstraints();
localGbc.gridx = 0;
localGbc.gridy = 0;
localGbc.insets = new Insets(0, 0, 0, 5);
effectPanel.setLayout(new GridBagLayout());
-
+
effectPanel.add(lblMagnitude, localGbc);
localGbc.gridx++;
effectPanel.add(txtAmount, localGbc);
@@ -466,23 +467,23 @@ private void addEffectUI(GridBagConstraints gbc) {
effectPanel.add(cboEffectCondition, localGbc);
localGbc.gridx++;
effectPanel.add(btnAdd, localGbc);
-
+
getContentPane().add(effectPanel, gbc);
}
-
+
/**
* Event handler for the 'add' button for scenario effects
*/
private void addEffect() {
- int amount = 0;
+ int amount = 0;
try {
amount = Integer.parseInt(txtAmount.getText());
- lblMagnitude.setForeground(Color.black);
+ lblMagnitude.setForeground(UIManager.getColor("text"));
} catch(Exception e) {
lblMagnitude.setForeground(Color.red);
return;
}
-
+
ObjectiveEffect effect = new ObjectiveEffect();
effect.howMuch = amount;
effect.effectScaling = (EffectScalingType) cboScalingType.getSelectedItem();
@@ -490,17 +491,17 @@ private void addEffect() {
if(cboEffectCondition.getSelectedItem() == ObjectiveEffectConditionType.ObjectiveSuccess) {
objective.addSuccessEffect(effect);
-
+
updateEffectList(successEffects, objective.getSuccessEffects());
} else {
objective.addFailureEffect(effect);
-
+
updateEffectList(failureEffects, objective.getFailureEffects());
}
-
+
pack();
}
-
+
/**
* Worker function that updates an objective effects list with the given objective effects
*/
@@ -509,14 +510,14 @@ private void updateEffectList(JList listToUpdate, List listToUpdate;
List objectiveEffects;
-
+
if(conditionType == ObjectiveEffectConditionType.ObjectiveSuccess) {
listToUpdate = successEffects;
objectiveEffects = objective.getSuccessEffects();
@@ -526,84 +527,84 @@ private void removeEffect(ObjectiveEffectConditionType conditionType) {
objectiveEffects = objective.getFailureEffects();
btnRemoveFailure.setEnabled(false);
}
-
+
for(ObjectiveEffect effectToRemove : listToUpdate.getSelectedValuesList()) {
objectiveEffects.remove(effectToRemove);
}
-
+
updateEffectList(listToUpdate, objectiveEffects);
}
-
+
private void addForce() {
objective.addForce(cboForceName.getSelectedItem().toString());
-
- updateForceList();
+
+ updateForceList();
pack();
}
-
+
private void removeForce() {
for(String forceName : forceNames.getSelectedValuesList()) {
objective.removeForce(forceName);
}
-
+
updateForceList();
btnRemove.setEnabled(false);
pack();
}
-
+
private void addDetail(JTextField field) {
objective.addDetail(field.getText());
updateDetailList();
}
-
+
private void removeDetails() {
for(int index : lstDetails.getSelectedIndices()) {
objective.getDetails().remove(index);
}
updateDetailList();
}
-
+
private void updateDetailList() {
DefaultListModel detailModel = new DefaultListModel<>();
for(String detail : objective.getDetails()) {
detailModel.addElement(detail);
}
-
+
lstDetails.setModel(detailModel);
}
-
+
private void updateForceList() {
DefaultListModel forceModel = new DefaultListModel<>();
for(String forceName : objective.getAssociatedForceNames()) {
forceModel.addElement(forceName);
}
-
+
forceNames.setModel(forceModel);
}
-
+
private void setDirectionDropdownVisibility() {
switch((ObjectiveCriterion) cboObjectiveType.getSelectedItem()) {
case PreventReachMapEdge:
case ReachMapEdge:
cboDirection.setVisible(true);
- break;
+ break;
default:
cboDirection.setVisible(false);
break;
}
}
-
+
private void updateTimeLimitUI() {
boolean enable = !cboTimeScaling.getSelectedItem().equals(TimeLimitType.None);
-
+
txtTimeLimit.setEnabled(enable);
cboTimeLimitDirection.setEnabled(enable);
}
-
+
private void saveObjectiveAndClose() {
int number = 0;
int timeLimit = 0;
-
+
try {
number = Integer.parseInt(txtPercentage.getText());
txtPercentage.setBorder(null);
@@ -611,7 +612,7 @@ private void saveObjectiveAndClose() {
txtPercentage.setBorder(new LineBorder(Color.red));
return;
}
-
+
try {
if(txtTimeLimit.isEnabled()) {
timeLimit = Integer.parseInt(txtTimeLimit.getText());
@@ -621,7 +622,7 @@ private void saveObjectiveAndClose() {
txtTimeLimit.setBorder(new LineBorder(Color.red));
return;
}
-
+
objective.setObjectiveCriterion((ObjectiveCriterion) cboObjectiveType.getSelectedItem());
objective.setDescription(txtShortDescription.getText());
if(this.cboCountType.getSelectedIndex() == 0) {
@@ -629,13 +630,13 @@ private void saveObjectiveAndClose() {
} else {
objective.setFixedAmount(number);
}
-
+
if(cboDirection.isVisible() && cboDirection.getSelectedIndex() > 0) {
objective.setDestinationEdge(OffBoardDirection.getDirection(cboDirection.getSelectedIndex() - 1));
} else {
objective.setDestinationEdge(OffBoardDirection.NONE);
}
-
+
objective.setTimeLimitType((TimeLimitType) cboTimeScaling.getSelectedItem());
if(txtTimeLimit.isEnabled()) {
if(objective.getTimeLimitType() == TimeLimitType.ScaledToPrimaryUnitCount) {
@@ -644,15 +645,15 @@ private void saveObjectiveAndClose() {
objective.setTimeLimit(timeLimit);
}
}
-
+
if(cboTimeLimitDirection.isEnabled()) {
objective.setTimeLimitAtMost(cboTimeLimitDirection.getSelectedIndex() == 0);
}
-
+
if(!currentScenarioTemplate.scenarioObjectives.contains(objective)) {
currentScenarioTemplate.scenarioObjectives.add(objective);
}
-
+
parent.updateObjectiveList();
setVisible(false);
}
diff --git a/MekHQ/src/mekhq/gui/model/DocTableModel.java b/MekHQ/src/mekhq/gui/model/DocTableModel.java
index 4777860ce4b..ff27eba2048 100644
--- a/MekHQ/src/mekhq/gui/model/DocTableModel.java
+++ b/MekHQ/src/mekhq/gui/model/DocTableModel.java
@@ -1,6 +1,5 @@
package mekhq.gui.model;
-import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;
@@ -11,6 +10,7 @@
import mekhq.campaign.Campaign;
import mekhq.campaign.personnel.Person;
import mekhq.gui.BasicInfo;
+import mekhq.gui.MekHqColors;
/**
* A table model for displaying doctors
@@ -18,8 +18,9 @@
public class DocTableModel extends DataTableModel {
private static final long serialVersionUID = -6934834363013004894L;
- private Campaign campaign;
-
+ private final Campaign campaign;
+ private final MekHqColors colors = new MekHqColors();
+
public DocTableModel(Campaign c) {
columnNames = new String[] { "Doctors" };
data = new ArrayList();
@@ -33,7 +34,7 @@ public Object getValueAt(int row, int col) {
public Person getDoctorAt(int row) {
return (Person) data.get(row);
}
-
+
public Campaign getCampaign() {
return campaign;
}
@@ -52,19 +53,19 @@ public Renderer(IconPackage icons) {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
- Component c = this;
setOpaque(true);
setPortrait(getDoctorAt(row));
- setText(getValueAt(row, column).toString(), "black");
+ setText(getValueAt(row, column).toString());
//setToolTipText(getCampaign().getTargetFor(getDoctorAt(row), getDoctorAt(row)).getDesc());
if (isSelected) {
highlightBorder();
} else {
unhighlightBorder();
}
- c.setBackground(new Color(220, 220, 220));
- return c;
+ colors.getIconButton().getColor().ifPresent(c -> setBackground(c));
+ colors.getIconButton().getAlternateColor().ifPresent(c -> setForeground(c));
+ return this;
}
}
-}
\ No newline at end of file
+}
diff --git a/MekHQ/src/mekhq/gui/model/LoanTableModel.java b/MekHQ/src/mekhq/gui/model/LoanTableModel.java
index f7ff4b0aadd..49ace089b86 100644
--- a/MekHQ/src/mekhq/gui/model/LoanTableModel.java
+++ b/MekHQ/src/mekhq/gui/model/LoanTableModel.java
@@ -1,6 +1,5 @@
package mekhq.gui.model;
-import java.awt.Color;
import java.awt.Component;
import java.text.DateFormat;
import java.util.ArrayList;
@@ -12,6 +11,7 @@
import mekhq.campaign.finances.Finances;
import mekhq.campaign.finances.Loan;
+import mekhq.gui.MekHqColors;
/**
* A table model for displaying active loans
@@ -30,11 +30,12 @@ public class LoanTableModel extends DataTableModel {
public final static int COL_NEXT_PAY = 8;
public final static int N_COL = 9;
+ private final MekHqColors colors = new MekHqColors();
public LoanTableModel() {
data = new ArrayList();
}
-
+
public int getRowCount() {
return data.size();
}
@@ -70,7 +71,7 @@ public String getColumnName(int column) {
}
public Object getValueAt(int row, int col) {
- Loan loan = getLoan(row);
+ Loan loan = getLoan(row);
if(col == COL_DESC) {
return loan.getDescription();
}
@@ -162,7 +163,8 @@ public Component getTableCellRendererComponent(JTable table,
setForeground(UIManager.getColor("Table.selectionForeground"));
} else {
if(loan.isOverdue()) {
- setBackground(Color.RED);
+ colors.getLoanOverdue().getColor().ifPresent(c -> setBackground(c));
+ colors.getLoanOverdue().getAlternateColor().ifPresent(c -> setForeground(c));
} else {
setBackground(UIManager.getColor("Table.background"));
}
diff --git a/MekHQ/src/mekhq/gui/model/PatientTableModel.java b/MekHQ/src/mekhq/gui/model/PatientTableModel.java
index c1d6e858015..bd3a4ace19e 100644
--- a/MekHQ/src/mekhq/gui/model/PatientTableModel.java
+++ b/MekHQ/src/mekhq/gui/model/PatientTableModel.java
@@ -1,6 +1,5 @@
package mekhq.gui.model;
-import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;
@@ -12,6 +11,7 @@
import mekhq.campaign.Campaign;
import mekhq.campaign.personnel.Person;
import mekhq.gui.BasicInfo;
+import mekhq.gui.MekHqColors;
/**
* A table model for displaying personnel in the infirmary
@@ -19,9 +19,10 @@
public class PatientTableModel extends AbstractListModel {
private static final long serialVersionUID = -1615929049408417297L;
- ArrayList patients;
- Campaign campaign;
-
+ private ArrayList patients;
+ private final Campaign campaign;
+ private final MekHqColors colors = new MekHqColors();
+
public PatientTableModel(Campaign c) {
patients = new ArrayList();
campaign = c;
@@ -46,11 +47,11 @@ public Person getElementAt(int index) {
public int getSize() {
return patients.size();
}
-
+
private Campaign getCampaign() {
return campaign;
}
-
+
public PatientTableModel.Renderer getRenderer(IconPackage icons) {
return new PatientTableModel.Renderer(icons);
}
@@ -68,7 +69,6 @@ public Component getListCellRendererComponent(
int index,
boolean isSelected,
boolean cellHasFocus) {
- Component c = this;
setOpaque(true);
Person p = (Person)getElementAt(index);
if (getCampaign().getCampaignOptions().useAdvancedMedical()) {
@@ -82,8 +82,10 @@ public Component getListCellRendererComponent(
unhighlightBorder();
}
setPortrait(p);
- c.setBackground(new Color(220, 220, 220));
- return c;
+
+ colors.getIconButton().getColor().ifPresent(c -> setBackground(c));
+ colors.getIconButton().getAlternateColor().ifPresent(c -> setForeground(c));
+ return this;
}
}
}
diff --git a/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java b/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java
index 1600460a143..b6ee7c96c01 100644
--- a/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java
+++ b/MekHQ/src/mekhq/gui/model/PersonnelTableModel.java
@@ -18,7 +18,6 @@
*/
package mekhq.gui.model;
-import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;
@@ -46,6 +45,7 @@
import mekhq.campaign.unit.Unit;
import mekhq.campaign.universe.Planet;
import mekhq.gui.BasicInfo;
+import mekhq.gui.MekHqColors;
import mekhq.gui.utilities.MekHqTableCellRenderer;
/**
@@ -61,6 +61,8 @@ public class PersonnelTableModel extends DataTableModel {
private boolean loadAssignmentFromMarket;
private boolean groupByUnit;
+ private final MekHqColors colors = new MekHqColors();
+
public static final int COL_RANK = 0;
public static final int COL_NAME = 1;
public static final int COL_CALL = 2;
@@ -689,11 +691,14 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
setForeground(UIManager.getColor("Table.selectionForeground"));
} else {
if (isDeployed(actualRow)) {
- setBackground(Color.LIGHT_GRAY);
+ colors.getDeployed().getColor().ifPresent(c -> setBackground(c));
+ colors.getDeployed().getAlternateColor().ifPresent(c -> setForeground(c));
} else if ((Integer.parseInt((String) getValueAt(actualRow,COL_HITS)) > 0) || getPerson(actualRow).hasInjuries(true)) {
- setBackground(Color.RED);
+ colors.getInjured().getColor().ifPresent(c -> setBackground(c));
+ colors.getInjured().getAlternateColor().ifPresent(c -> setForeground(c));
} else if (getPerson(actualRow).hasOnlyHealedPermanentInjuries()) {
- setBackground(new Color(0xee9a00));
+ colors.getHealedInjuries().getColor().ifPresent(c -> setBackground(c));
+ colors.getHealedInjuries().getAlternateColor().ifPresent(c -> setForeground(c));
} else {
setBackground(UIManager.getColor("Table.background"));
}
diff --git a/MekHQ/src/mekhq/gui/model/RetirementTableModel.java b/MekHQ/src/mekhq/gui/model/RetirementTableModel.java
index d7617d26942..05091c186fa 100644
--- a/MekHQ/src/mekhq/gui/model/RetirementTableModel.java
+++ b/MekHQ/src/mekhq/gui/model/RetirementTableModel.java
@@ -1,6 +1,5 @@
package mekhq.gui.model;
-import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.util.ArrayList;
@@ -27,6 +26,7 @@
import mekhq.campaign.personnel.RetirementDefectionTracker;
import mekhq.campaign.unit.Unit;
import mekhq.gui.BasicInfo;
+import mekhq.gui.MekHqColors;
import mekhq.gui.dialog.RetirementDefectionDialog;
import mekhq.gui.utilities.MekHqTableCellRenderer;
@@ -55,7 +55,8 @@ public class RetirementTableModel extends AbstractTableModel {
"Payout", "Recruit", "Unit"
};
- private Campaign campaign;
+ private final Campaign campaign;
+ private final MekHqColors colors = new MekHqColors();
private ArrayList data;
private HashMap targets;
private HashMap payBonus;
@@ -401,7 +402,8 @@ public Component getTableCellRendererComponent(JTable table,
if (!isSelected) {
if (null != campaign.getRetirementDefectionTracker().getPayout(p.getId()) &&
campaign.getRetirementDefectionTracker().getPayout(p.getId()).getWeightClass() > 0) {
- setBackground(Color.LIGHT_GRAY);
+ colors.getPaidRetirement().getColor().ifPresent(c -> setBackground(c));
+ colors.getPaidRetirement().getAlternateColor().ifPresent(c -> setForeground(c));
}
}
return this;
@@ -422,7 +424,6 @@ public VisualRenderer(IconPackage icons) {
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);
@@ -479,15 +480,16 @@ public Component getTableCellRendererComponent(JTable table,
}
}
- MekHqTableCellRenderer.setupTableColors(c, table, isSelected, hasFocus, row);
+ MekHqTableCellRenderer.setupTableColors(this, table, isSelected, hasFocus, row);
if (!isSelected) {
if (null != campaign.getRetirementDefectionTracker().getPayout(p.getId()) &&
campaign.getRetirementDefectionTracker().getPayout(p.getId()).getWeightClass() > 0) {
- c.setBackground(Color.LIGHT_GRAY);
+ colors.getPaidRetirement().getColor().ifPresent(c -> setBackground(c));
+ colors.getPaidRetirement().getAlternateColor().ifPresent(c -> setForeground(c));
}
}
-
- return c;
+
+ return this;
}
}
}
diff --git a/MekHQ/src/mekhq/gui/model/UnitTableModel.java b/MekHQ/src/mekhq/gui/model/UnitTableModel.java
index 162f075cb95..dbb378287b0 100644
--- a/MekHQ/src/mekhq/gui/model/UnitTableModel.java
+++ b/MekHQ/src/mekhq/gui/model/UnitTableModel.java
@@ -1,6 +1,5 @@
package mekhq.gui.model;
-import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.util.ArrayList;
@@ -18,15 +17,14 @@
import megamek.common.TechConstants;
import megamek.common.UnitType;
import mekhq.IconPackage;
-import mekhq.MekHQ;
import mekhq.campaign.Campaign;
import mekhq.campaign.force.Force;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.unit.Unit;
import mekhq.gui.BasicInfo;
+import mekhq.gui.MekHqColors;
import mekhq.gui.preferences.ColorPreference;
import mekhq.gui.utilities.MekHqTableCellRenderer;
-import mekhq.preferences.PreferencesNode;
/**
* A table Model for displaying information about units
@@ -59,44 +57,11 @@ public class UnitTableModel extends DataTableModel {
private Campaign campaign;
- public static ColorPreference normalColors;
- public static ColorPreference selectedColors;
- public static ColorPreference deployedColors;
- public static ColorPreference inTransitColors;
- public static ColorPreference refittingColors;
- public static ColorPreference mothballingColors;
- public static ColorPreference mothballedColors;
- public static ColorPreference notRepairableColors;
- public static ColorPreference nonfunctionalColors;
- public static ColorPreference needsPartsFixedColors;
- public static ColorPreference uncrewedColors;
+ private final MekHqColors colors = new MekHqColors();
public UnitTableModel(Campaign c) {
data = new ArrayList();
campaign = c;
- setUserPreferences();
- }
-
- private synchronized void setUserPreferences() {
- if (normalColors == null) {
- PreferencesNode preferences = MekHQ.getPreferences().forClass(UnitTableModel.class);
-
- normalColors = new ColorPreference("normal", UIManager.getColor("Table.background"), UIManager.getColor("Table.foreground"));
- selectedColors = new ColorPreference("selected", UIManager.getColor("Table.selectionBackground"), UIManager.getColor("Table.selectionFackground"));
- deployedColors = new ColorPreference("deployed", Color.LIGHT_GRAY, Color.BLACK);
- inTransitColors = new ColorPreference("inTransit", Color.ORANGE, Color.BLACK);
- refittingColors = new ColorPreference("refitting", Color.CYAN, Color.BLACK);
- mothballingColors = new ColorPreference("mothballing", new Color(153,153,255), Color.BLACK);
- mothballedColors = new ColorPreference("mothballed", new Color(204, 204, 255), Color.BLACK);
- notRepairableColors = new ColorPreference("notRepairable", new Color(190, 150, 55), Color.BLACK);
- nonfunctionalColors = new ColorPreference("nonfunctional", new Color(205, 92, 92), Color.BLACK);
- needsPartsFixedColors = new ColorPreference("needsPartsFixed", new Color(238, 238, 0), Color.BLACK);
- uncrewedColors = new ColorPreference("uncrewed", Color.RED, Color.BLACK);
-
- preferences.manage(normalColors, selectedColors, deployedColors, inTransitColors, refittingColors,
- mothballingColors, mothballedColors, notRepairableColors, nonfunctionalColors, needsPartsFixedColors,
- uncrewedColors);
- }
}
public int getRowCount() {
@@ -347,44 +312,42 @@ public Component getTableCellRendererComponent(JTable table,
Unit u = getUnit(actualRow);
if (isSelected) {
- applyColors(selectedColors, isSelected);
+ setBackground(UIManager.getColor("Table.selectionBackground"));
+ setForeground(UIManager.getColor("Table.selectionForeground"));
} else {
if (u.isDeployed()) {
- applyColors(deployedColors);
+ applyColors(colors.getDeployed());
} else if(!u.isPresent()) {
- applyColors(inTransitColors);
+ applyColors(colors.getInTransit());
} else if(u.isRefitting()) {
- applyColors(refittingColors);
+ applyColors(colors.getRefitting());
} else if (u.isMothballing()) {
- applyColors(mothballingColors);
+ applyColors(colors.getMothballing());
} else if (u.isMothballed()) {
- applyColors(mothballedColors);
+ applyColors(colors.getMothballed());
} else if (!u.isRepairable()) {
- applyColors(notRepairableColors);
+ applyColors(colors.getNotRepairable());
} else if (!u.isFunctional()) {
- applyColors(nonfunctionalColors);
+ applyColors(colors.getNonFunctional());
} else if (u.hasPartsNeedingFixing()) {
- applyColors(needsPartsFixedColors);
+ applyColors(colors.getNeedsPartsFixed());
} else if (u.getEntity() instanceof Infantry
&& u.getActiveCrew().size() < u.getFullCrewSize()) {
- applyColors(uncrewedColors);
+ applyColors(colors.getUncrewed());
} else {
- applyColors(normalColors);
+ setBackground(UIManager.getColor("Table.background"));
+ setForeground(UIManager.getColor("Table.foreground"));
}
}
return this;
}
private void applyColors(ColorPreference c) {
- applyColors(c, false);
- }
-
- private void applyColors(ColorPreference c, boolean isSelected) {
setBackground(c.getColor()
- .orElseGet(() -> UIManager.getColor(isSelected ? "Table.selectionBackground" : "Table.background")));
+ .orElseGet(() -> UIManager.getColor("Table.background")));
setForeground(c.getAlternateColor()
- .orElseGet(() -> UIManager.getColor(isSelected ? "Table.selectionForeground" : "Table.foreground")));
+ .orElseGet(() -> UIManager.getColor("Table.foreground")));
}
}
diff --git a/MekHQ/src/mekhq/gui/view/LanceAssignmentView.java b/MekHQ/src/mekhq/gui/view/LanceAssignmentView.java
index 949908c80b7..de9ff72c110 100644
--- a/MekHQ/src/mekhq/gui/view/LanceAssignmentView.java
+++ b/MekHQ/src/mekhq/gui/view/LanceAssignmentView.java
@@ -21,7 +21,6 @@
package mekhq.gui.view;
-import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.ArrayList;
@@ -40,10 +39,8 @@
import javax.swing.RowSorter;
import javax.swing.SortOrder;
import javax.swing.SwingConstants;
-import javax.swing.UIManager;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
-import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableRowSorter;
@@ -53,9 +50,11 @@
import mekhq.campaign.mission.AtBContract;
import mekhq.campaign.mission.Mission;
import mekhq.campaign.personnel.SkillType;
+import mekhq.gui.MekHqColors;
import mekhq.gui.model.DataTableModel;
import mekhq.gui.model.UnitMarketTableModel;
import mekhq.gui.model.XTableColumnModel;
+import mekhq.gui.utilities.MekHqTableCellRenderer;
/**
* Against the Bot
@@ -79,7 +78,8 @@ public class LanceAssignmentView extends JPanel {
public static final int ROLE_TRAINING = 4;
public static final int ROLE_NUM = 5;
- private Campaign campaign;
+ private final Campaign campaign;
+ private final MekHqColors colors = new MekHqColors();
private JTable tblRequiredLances;
private JTable tblAssignments;
@@ -119,7 +119,7 @@ public Component getListCellRendererComponent(JList> list,
for (int i = 0; i < UnitMarketTableModel.COL_NUM; i++) {
column = ((XTableColumnModel)tblRequiredLances.getColumnModel()).getColumnByModelIndex(i);
column.setPreferredWidth(rlModel.getColumnWidth(i));
- column.setCellRenderer(new DefaultTableCellRenderer() {
+ column.setCellRenderer(new MekHqTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
@@ -129,9 +129,7 @@ public Component getTableCellRendererComponent(JTable table,
getAlignment(table.convertColumnIndexToModel(column)));
if (table.convertColumnIndexToModel(column) > RequiredLancesTableModel.COL_CONTRACT) {
if (((String)value).indexOf('/') >= 0) {
- setForeground(Color.RED);
- } else {
- setForeground(UIManager.getColor(isSelected ? "Table.selectionForeground" : "Table.foreground"));
+ colors.getBelowContractMinimum().getAlternateColor().ifPresent(c -> setForeground(c));
}
}
return this;
@@ -153,7 +151,7 @@ public Component getTableCellRendererComponent(JTable table,
for (int i = 0; i < LanceAssignmentTableModel.COL_NUM; i++) {
column = ((XTableColumnModel)tblAssignments.getColumnModel()).getColumnByModelIndex(i);
column.setPreferredWidth(rlModel.getColumnWidth(i));
- column.setCellRenderer(new DefaultTableCellRenderer() {
+ column.setCellRenderer(new MekHqTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {