Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customization for colors used throughout MekHQ #1480 #1491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion MekHQ/src/mekhq/gui/BriefingTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package mekhq.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
Expand Down
12 changes: 7 additions & 5 deletions MekHQ/src/mekhq/gui/ForceRenderer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mekhq.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.util.UUID;
Expand All @@ -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;
Expand Down Expand Up @@ -133,12 +133,14 @@ public Component getTreeCellRendererComponent(
}
setText("<html>" + name + ", " + uname + c3network + transport + "</html>");
if(u.isDeployed() && !sel) {
setBackground(Color.LIGHT_GRAY);
colors.getDeployed().getColor().ifPresent(c -> setBackground(c));
colors.getDeployed().getAlternateColor().ifPresent(c -> setForeground(c));
}
}
if(value instanceof Force) {
if(!hasFocus && ((Force)value).isDeployed()) {
setBackground(Color.LIGHT_GRAY);
colors.getDeployed().getColor().ifPresent(c -> setBackground(c));
colors.getDeployed().getAlternateColor().ifPresent(c -> setForeground(c));
}
}
setIcon(getIcon(value));
Expand Down Expand Up @@ -205,4 +207,4 @@ protected Icon getIconFrom(Force force) {
}
return new ImageIcon(forceImage);
}
}
}
28 changes: 13 additions & 15 deletions MekHQ/src/mekhq/gui/HangarTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package mekhq.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
Expand Down Expand Up @@ -76,7 +75,6 @@
import mekhq.gui.model.XTableColumnModel;
import mekhq.gui.preferences.JComboBoxPreference;
import mekhq.gui.preferences.JTablePreference;
import mekhq.gui.preferences.JToggleButtonPreference;
import mekhq.gui.sorter.FormattedNumberSorter;
import mekhq.gui.sorter.TargetSorter;
import mekhq.gui.sorter.UnitStatusSorter;
Expand Down Expand Up @@ -126,7 +124,7 @@ public GuiTabType tabType() {

/*
* (non-Javadoc)
*
*
* @see mekhq.gui.CampaignGuiTab#initTab()
*/
@Override
Expand Down Expand Up @@ -217,7 +215,7 @@ public void mouseClicked(MouseEvent e) {
splitUnit.setDividerLocation(1.0);
}
}
}
}
});
unitTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
TableColumn column = null;
Expand Down Expand Up @@ -346,7 +344,7 @@ public JTable getUnitTable() {

/*
* (non-Javadoc)
*
*
* @see mekhq.gui.CampaignGuiTab#refreshAll()
*/
@Override
Expand Down Expand Up @@ -558,7 +556,7 @@ public void refreshUnitList() {
}
getCampaignGui().refreshLab();
}

private void refreshAcquisitionList() {
acquireUnitsModel.setData(getCampaign().getShoppingList().getUnitList());
}
Expand All @@ -571,12 +569,12 @@ private void refreshAcquisitionList() {
public void handle(DeploymentChangedEvent ev) {
filterUnitScheduler.schedule();;
}

@Subscribe
public void handle(PersonChangedEvent ev) {
filterUnitScheduler.schedule();;
}

@Subscribe
public void handle(ScenarioResolvedEvent ev) {
unitListScheduler.schedule();
Expand All @@ -586,17 +584,17 @@ public void handle(ScenarioResolvedEvent ev) {
public void handle(UnitChangedEvent ev) {
filterUnitScheduler.schedule();;
}

@Subscribe
public void handle(UnitNewEvent ev) {
unitListScheduler.schedule();
}

@Subscribe
public void handle(UnitRemovedEvent ev) {
unitListScheduler.schedule();
}

@Subscribe
public void handle(RepairStatusChangedEvent ev) {
filterUnitScheduler.schedule();
Expand All @@ -609,28 +607,28 @@ public void handle(AcquisitionEvent ev) {
acquisitionListScheduler.schedule();
}
}

@Subscribe
public void handle(ProcurementEvent ev) {
if (ev.getAcquisition() instanceof UnitOrder) {
acquisitionListScheduler.schedule();
}
}

@Subscribe
public void handle(PartEvent ev) {
if (ev.getPart().getUnit() != null) {
filterUnitScheduler.schedule();
}
}

@Subscribe
public void handle(PartWorkEvent ev) {
if (ev.getPartWork().getUnit() != null) {
filterUnitScheduler.schedule();
}
}

@Subscribe
public void handle(OvertimeModeEvent ev) {
filterUnitScheduler.schedule();
Expand Down
1 change: 0 additions & 1 deletion MekHQ/src/mekhq/gui/MapTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package mekhq.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
Expand Down
158 changes: 158 additions & 0 deletions MekHQ/src/mekhq/gui/MekHqColors.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
1 change: 0 additions & 1 deletion MekHQ/src/mekhq/gui/PersonnelTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package mekhq.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
Expand Down
Loading