org.nuiton.jaxx.runtime.resources.UIResourcesProvider Maven / Gradle / Ivy
package org.nuiton.jaxx.runtime.resources;
/*-
* #%L
* JAXX :: Runtime Spi
* %%
* Copyright (C) 2008 - 2024 Code Lutin, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import javax.swing.ImageIcon;
import javax.swing.UIManager;
import java.awt.Color;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
/**
* Created by tchemit on 13/12/2017.
*
* @author Tony Chemit - [email protected]
*/
public class UIResourcesProvider {
private static final Logger log = LogManager.getLogger(UIResourcesProvider.class);
private static final String ICON_PREFIX = "icon.";
private static final String COLOR_PREFIX = "color.";
private final String name;
private final String resourcePath;
private int nbIcons;
private int nbColors;
public UIResourcesProvider(String name, String resourcePath) {
this.name = name;
this.resourcePath = resourcePath;
}
public void load() throws IOException {
log.info(String.format("%s Loading ui resources", name));
try (InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
Objects.requireNonNull(resourceAsStream,"Could not find ui resources file: "+resourcePath);
Properties p = new Properties();
p.load(resourceAsStream);
load(p);
}
log.info(String.format("%s Loaded %d icon(s).", name, nbIcons));
log.info(String.format("%s Loaded %d color(s).", name, nbColors));
}
public int getNbIcons() {
return nbIcons;
}
public int getNbColors() {
return nbColors;
}
public void load(Properties incoming) throws IOException {
nbIcons = nbColors = 0;
for (Map.Entry