Search in sources :

Example 1 with SystemColor

use of java.awt.SystemColor in project jdk8u_jdk by JetBrains.

the class BasicLookAndFeel method loadSystemColors.

/**
     * Populates {@code table} with the {@code name-color} pairs in
     * {@code systemColors}. Refer to
     * {@link #initSystemColorDefaults(UIDefaults)} for details on
     * the format of {@code systemColors}.
     * <p>
     * An entry is added to {@code table} for each of the {@code name-color}
     * pairs in {@code systemColors}. The entry key is
     * the {@code name} of the {@code name-color} pair.
     * <p>
     * The value of the entry corresponds to the {@code color} of the
     * {@code name-color} pair.  The value of the entry is calculated
     * in one of two ways. With either approach the value is always a
     * {@code ColorUIResource}.
     * <p>
     * If {@code useNative} is {@code false}, the {@code color} is
     * created by using {@code Color.decode} to convert the {@code
     * String} into a {@code Color}. If {@code decode} can not convert
     * the {@code String} into a {@code Color} ({@code
     * NumberFormatException} is thrown) then a {@code
     * ColorUIResource} of black is used.
     * <p>
     * If {@code useNative} is {@code true}, the {@code color} is the
     * value of the field in {@code SystemColor} with the same name as
     * the {@code name} of the {@code name-color} pair. If the field
     * is not valid, a {@code ColorUIResource} of black is used.
     *
     * @param table the {@code UIDefaults} object the values are added to
     * @param systemColors array of {@code name-color} pairs as described
     *        in {@link #initSystemColorDefaults(UIDefaults)}
     * @param useNative whether the color is obtained from {@code SystemColor}
     *        or {@code Color.decode}
     * @throws NullPointerException if {@code systemColors} is {@code null}; or
     *         {@code systemColors} is not empty, and {@code table} is
     *         {@code null}; or one of the
     *         names of the {@code name-color} pairs is {@code null}; or
     *         {@code useNative} is {@code false} and one of the
     *         {@code colors} of the {@code name-color} pairs is {@code null}
     * @throws ArrayIndexOutOfBoundsException if {@code useNative} is
     *         {@code false} and {@code systemColors.length} is odd
     *
     * @see #initSystemColorDefaults(javax.swing.UIDefaults)
     * @see java.awt.SystemColor
     * @see java.awt.Color#decode(String)
     */
protected void loadSystemColors(UIDefaults table, String[] systemColors, boolean useNative) {
    /* PENDING(hmuller) We don't load the system colors below because
         * they're not reliable.  Hopefully we'll be able to do better in
         * a future version of AWT.
         */
    if (useNative) {
        for (int i = 0; i < systemColors.length; i += 2) {
            Color color = Color.black;
            try {
                String name = systemColors[i];
                color = (Color) (SystemColor.class.getField(name).get(null));
            } catch (Exception e) {
            }
            table.put(systemColors[i], new ColorUIResource(color));
        }
    } else {
        for (int i = 0; i < systemColors.length; i += 2) {
            Color color = Color.black;
            try {
                color = Color.decode(systemColors[i + 1]);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            table.put(systemColors[i], new ColorUIResource(color));
        }
    }
}
Also used : Color(java.awt.Color) SystemColor(java.awt.SystemColor) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException)

Aggregations

Color (java.awt.Color)1 Point (java.awt.Point)1 SystemColor (java.awt.SystemColor)1 PropertyVetoException (java.beans.PropertyVetoException)1