001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.validation;
003
004import static org.openstreetmap.josm.tools.I18n.marktr;
005import static org.openstreetmap.josm.tools.I18n.tr;
006
007import java.awt.Color;
008
009import org.openstreetmap.josm.data.preferences.NamedColorProperty;
010import org.openstreetmap.josm.tools.Logging;
011
012/** The error severity */
013public enum Severity {
014    // CHECKSTYLE.OFF: SingleSpaceSeparator
015    /** Error messages */
016    ERROR(1, tr("Errors"), /* ICON(data/) */"error",       new NamedColorProperty(marktr("validation error"), Color.RED).get()),
017    /** Warning messages */
018    WARNING(2, tr("Warnings"), /* ICON(data/) */"warning", new NamedColorProperty(marktr("validation warning"), Color.YELLOW).get()),
019    /** Other messages */
020    OTHER(3, tr("Other"), /* ICON(data/) */"other",        new NamedColorProperty(marktr("validation other"), Color.CYAN).get());
021    // CHECKSTYLE.ON: SingleSpaceSeparator
022
023    /** Numeric ordering of the severities, 1 being major, 3 being minor */
024    private final int level;
025
026    /** Description of the severity code */
027    private final String message;
028
029    /** Associated icon */
030    private final String icon;
031
032    /** Associated color */
033    @SuppressWarnings("ImmutableEnumChecker") // see https://github.com/google/error-prone/pull/1682
034    private final Color color;
035
036    /**
037     * Constructor
038     *
039     * @param level Numeric ordering, 1 being major, 3 being minor
040     * @param message Description
041     * @param icon Associated icon
042     * @param color The color of this severity
043     */
044    Severity(int level, String message, String icon, Color color) {
045        this.level = level;
046        this.message = message;
047        this.icon = icon;
048        this.color = color;
049    }
050
051    /**
052     * Retrieves all colors once from the preferences to register them
053     */
054    public static void getColors() {
055        for (Severity c : values()) {
056            Logging.debug("{0}", c);
057        }
058    }
059
060    @Override
061    public String toString() {
062        return message;
063    }
064
065    /**
066     * Gets the associated icon
067     * @return the associated icon
068     */
069    public String getIcon() {
070        return icon;
071    }
072
073    /**
074     * Gets the associated color
075     * @return The associated color
076     */
077    public Color getColor() {
078        return color;
079    }
080
081    /**
082     * Gets the severity level, 1 being major, 3 being minor
083     * @return The severity level
084     * @since 12667
085     */
086    public int getLevel() {
087        return level;
088    }
089}