/*
 * MIT License
 *
 * Copyright (c) 2020 Jannis Weis
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
package com.github.weisj.darklaf.icons;

import java.net.URI;
import java.util.Map;
import java.util.function.Supplier;

import javax.swing.*;

import com.kitfox.svg.SVGUniverse;
import com.kitfox.svg.app.beans.SVGIcon;

public class CustomThemedIcon extends ThemedSVGIcon {

    private final Map<Object, Object> defaults;

    public CustomThemedIcon(final Supplier<URI> uriSupplier, final int displayWidth, final int displayHeight,
                            final Map<Object, Object> colors) {
        super(uriSupplier, displayWidth, displayHeight);
        defaults = colors;
    }

    public CustomThemedIcon(final URI uri, final int displayWidth, final int displayHeight,
                            final Map<Object, Object> colors) {
        super(uri, displayWidth, displayHeight);
        defaults = colors;
    }

    protected CustomThemedIcon(final int width, final int height, final CustomThemedIcon icon) {
        super(width, height, icon);
        this.defaults = icon.defaults;
    }

    @Override
    public CustomThemedIcon derive(final int width, final int height) {
        return new CustomThemedIcon(width, height, this);
    }

    @Override
    protected SVGIcon createSVGIcon() {
        SVGIcon icon = new SVGIcon();
        icon.setSvgUniverse(new SVGUniverse());
        return icon;
    }

    @Override
    protected void patchColors() {
        IconColorMapper.patchColors(getSVGIcon(), defaults);
    }
}

@@ -1192,16 +1192,42 @@
 et.URI;%0A
+import java.util.HashMap;%0A
 import j
@@ -1236,24 +1236,24 @@
 a.util.Map;%0A
-
 import java.
@@ -1281,31 +1281,8 @@
 r;%0A%0A
-import javax.swing.*;%0A%0A
 impo
@@ -1458,16 +1458,197 @@
 aults;%0A%0A
+    public CustomThemedIcon(final Supplier%3CURI%3E uriSupplier, final int displayWidth, final int displayHeight) %7B%0A        this(uriSupplier, displayWidth, displayHeight, null);%0A    %7D%0A%0A
     publ
@@ -1887,32 +1887,67 @@
 efaults = colors
+ != null ? colors : new HashMap%3C%3E()
 ;%0A    %7D%0A%0A    pub
@@ -2311,16 +2311,16 @@
  icon);%0A
-
         
@@ -2349,32 +2349,1185 @@
 efaults;%0A    %7D%0A%0A
+    /**%0A     * Set a property if the underlying property map supports mutation.%0A     *%0A     * @param  key                           the property key.%0A     * @param  value                         the property value.%0A     * @throws UnsupportedOperationException if the underlying property map doesnt support mutation.%0A     */%0A    public void setProperty(final Object key, final Object value) throws UnsupportedOperationException %7B%0A        defaults.put(key, value);%0A    %7D%0A%0A    /**%0A     * Get a property.%0A     *%0A     * @param  key the property key.%0A     * @return     the property value.%0A     */%0A    public Object getProperty(final Object key) %7B%0A        return defaults.get(key);%0A    %7D%0A%0A    /**%0A     * Get a property of a given type.%0A     *%0A     * @param  key  the property key.%0A     * @param  type the type.%0A     * @param  %3CT%3E  the types type parameter.%0A     * @return      the property value if the type matches or null otherwise.%0A     */%0A    public %3CT%3E T getPropertyOfType(final Object key, final Class%3CT%3E type) %7B%0A        Object obj = getProperty(key);%0A        if (type != null && type.isInstance(obj)) return type.cast(obj);%0A        return null;%0A    %7D%0A%0A
     @Override%0A  

Allow custom themed icons to mutate properties.