org.kordamp.ikonli.javafx.StackedFontIcon Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ikonli-javafx Show documentation
Show all versions of ikonli-javafx Show documentation
Icon packs for Java applications
/*
* Copyright 2015-2016 Andres Almiray.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kordamp.ikonli.javafx;
import com.sun.javafx.css.converters.PaintConverter;
import com.sun.javafx.css.converters.SizeConverter;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
import javafx.collections.MapChangeListener;
import javafx.css.CssMetaData;
import javafx.css.Styleable;
import javafx.css.StyleableIntegerProperty;
import javafx.css.StyleableObjectProperty;
import javafx.css.StyleableProperty;
import javafx.scene.Node;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import org.kordamp.ikonli.Ikon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;
/**
* @author Andres Almiray
*/
public class StackedFontIcon extends StackPane implements Icon {
private static final String KEY_STACKED_FONT_ICON_SIZE = StackedFontIcon.class.getName() + ".iconSize";
private StyleableIntegerProperty iconSize;
private StyleableObjectProperty iconColor;
private double[] iconSizes = new double[0];
private ChangeListener iconSizeChangeListener = (v, o, n) -> setIconSizeOnChildren(n.intValue());
private ChangeListener iconColorChangeListener = (v, o, n) -> setIconColorOnChildren(n);
public static void setIconSize(Node icon, double size) {
if (icon != null && size >= 0d && size <= 1.0d) {
icon.getProperties().put(KEY_STACKED_FONT_ICON_SIZE, size);
}
}
public static double getIconSize(Node icon) {
if (icon != null) {
Object value = icon.getProperties().get(KEY_STACKED_FONT_ICON_SIZE);
if (value instanceof Number) {
return ((Number) value).doubleValue();
}
}
return 1.0d;
}
private class NodeSizeListener implements MapChangeListener
© 2015 - 2025 Weber Informatics LLC | Privacy Policy