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    private final Color color;
034
035    /**
036     * Constructor
037     *
038     * @param level Numeric ordering, 1 being major, 3 being minor
039     * @param message Description
040     * @param icon Associated icon
041     * @param color The color of this severity
042     */
043    Severity(int level, String message, String icon, Color color) {
044        this.level = level;
045        this.message = message;
046        this.icon = icon;
047        this.color = color;
048    }
049
050    /**
051     * Retrieves all colors once from the preferences to register them
052     */
053    public static void getColors() {
054        for (Severity c : values()) {
055            Logging.debug("{0}", c);
056        }
057    }
058
059    @Override
060    public String toString() {
061        return message;
062    }
063
064    /**
065     * Gets the associated icon
066     * @return the associated icon
067     */
068    public String getIcon() {
069        return icon;
070    }
071
072    /**
073     * Gets the associated color
074     * @return The associated color
075     */
076    public Color getColor() {
077        return color;
078    }
079
080    /**
081     * Gets the severity level, 1 being major, 3 being minor
082     * @return The severity level
083     * @since 12667
084     */
085    public int getLevel() {
086        return level;
087    }
088}