Changeset 6655 in josm for trunk/src/org


Ignore:
Timestamp:
2014-01-08T21:45:22+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9535 - handling of alpha values in HTML color codes (used in preferences)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ColorHelper.java

    r6380 r6655  
    1313    }
    1414   
     15    /**
     16     * Returns the {@code Color} for the given HTML code.
     17     * @param html the color code
     18     * @return the color
     19     */
    1520    public static Color html2color(String html) {
    1621        if (html.length() > 0 && html.charAt(0) == '#')
     
    3439    }
    3540
     41    /**
     42     * Returns the HTML color code (6 or 8 digit).
     43     * @param col The color to convert
     44     * @return the HTML color code (6 or 8 digit)
     45     */
    3646    public static String color2html(Color col) {
     47        return color2html(col, true);
     48    }
     49
     50    /**
     51     * Returns the HTML color code (6 or 8 digit).
     52     * @param col The color to convert
     53     * @param withAlpha if {@code true} and alpha value < 255, return 8-digit color code, else always 6-digit
     54     * @return the HTML color code (6 or 8 digit)
     55     * @since 6655
     56     */
     57    public static String color2html(Color col, boolean withAlpha) {
    3758        if (col == null)
    3859            return null;
    39         return "#"+int2hex(col.getRed())+int2hex(col.getGreen())+int2hex(col.getBlue());
     60        String code = "#"+int2hex(col.getRed())+int2hex(col.getGreen())+int2hex(col.getBlue());
     61        if (withAlpha) {
     62            int alpha = col.getAlpha();
     63            if (alpha < 255) {
     64                code += int2hex(alpha);
     65            }
     66        }
     67        return code;
    4068    }
    4169}
Note: See TracChangeset for help on using the changeset viewer.