001/*-------------------------------------------------------------------------+ 002| | 003| Copyright 2005-2011 The ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016+-------------------------------------------------------------------------*/ 017package org.conqat.lib.commons.assessment; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.conqat.lib.commons.js_export.ExportToJavaScript; 023 024/** 025 * Enum for traffic light colors. 026 * 027 * Note that the order is relevant: The first Color (RED) is considered the most 028 * dominant color (see {@link Assessment#getDominantColor()}). 029 * 030 * The mapping to actual colors is defined in 031 * {@link AssessmentUtils#getColor(ETrafficLightColor)}, so typically this 032 * method should be adjusted when a new constant is introduced here. 033 */ 034@ExportToJavaScript 035public enum ETrafficLightColor { 036 037 /** Red signals errors or incompleteness. */ 038 RED("#FF3333"), 039 040 /** 041 * Orange is an intermediate state between {@link #RED} and {@link #YELLOW}. 042 */ 043 ORANGE("#FF9966"), 044 045 /** Yellow signals warning or lack of control. */ 046 YELLOW("#FFFF33"), 047 048 /** Green signals the absence of errors or correctness. */ 049 GREEN("#00CC33"), 050 051 /** 052 * Baseline indicates a baseline entry, i.e. there has been no change compared 053 * to a given baseline and thus no color applies. 054 */ 055 BASELINE("#DFEAF4"), 056 057 /** This is used if no information is available. */ 058 UNKNOWN; 059 060 /** Display text of the color (name with normal casing) */ 061 private final String displayText; 062 063 /** Short, one-character display text of the color (e.g., G, Y, R) */ 064 private final String shortDisplayText; 065 066 /** Hex representation of the color */ 067 private final String hexValue; 068 069 /** 070 * This is hex value is used if no color is associated with the 071 * ETrafficLightColor. 072 */ 073 private static final String HEX_VALUE_BLACK = "#000000"; 074 075 /** 076 * Constructor for ETrafficLightColors that do not have an associated color. 077 */ 078 private ETrafficLightColor() { 079 this(HEX_VALUE_BLACK); 080 } 081 082 /** Constructor for ETrafficLightColors that have an associated color. */ 083 private ETrafficLightColor(String hexValue) { 084 this.displayText = this.name().substring(0, 1) + this.name().substring(1).toLowerCase(); 085 this.shortDisplayText = this.name().substring(0, 1); 086 this.hexValue = hexValue; 087 } 088 089 /** @see #displayText */ 090 public String getDisplayText() { 091 return displayText; 092 } 093 094 /** @see #shortDisplayText */ 095 public String getShortDisplayText() { 096 return shortDisplayText; 097 } 098 099 /** @see #hexValue */ 100 public String getHexValue() { 101 return hexValue; 102 } 103 104 /** 105 * Returns the more dominant color, which is the enum literal with smaller index 106 * (as they are sorted by dominance). 107 */ 108 public static ETrafficLightColor getDominantColor(ETrafficLightColor color1, ETrafficLightColor color2) { 109 if (color2.ordinal() < color1.ordinal()) { 110 return color2; 111 } 112 return color1; 113 } 114 115 /** 116 * Returns the traffic light colors red, yellow and green in this particular 117 * order. 118 */ 119 public static List<ETrafficLightColor> getTrafficLightColors() { 120 List<ETrafficLightColor> trafficLights = new ArrayList<>(); 121 trafficLights.add(RED); 122 trafficLights.add(YELLOW); 123 trafficLights.add(GREEN); 124 return trafficLights; 125 } 126}