Example usage for com.badlogic.gdx.scenes.scene2d.ui Skin find

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Skin find

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Skin find.

Prototype

public String find(Object resource) 

Source Link

Document

Returns the name of the specified style object, or null if it is not in the skin.

Usage

From source file:com.libgdx.skin.editor.utils.scene2d.CustomSkin.java

License:Apache License

/** ?? */
public static <T> boolean isStyleInUse(Skin skin, String targetStyleName, Class<T> targetStyleClazz) {
    if (skin == null || targetStyleName == null || targetStyleName.trim().length() == 0
            || targetStyleClazz == null) {
        throw new IllegalArgumentException("skin?targetStyleName and targetStyleClazz can not null");
    }//  w w w  . ja v a  2s.  c o  m
    try {
        for (String widget : widgets) {
            Class<?> resType = Class
                    .forName("com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style");
            // ?
            if (resType == targetStyleClazz) {
                continue;
            }
            ObjectMap<String, ?> typeResources = skin.getAll(resType);
            if (emptyMap(typeResources)) {
                continue;
            }
            //  styleName ?.???
            Array<String> styleNames = typeResources.keys().toArray();
            // ??? resType ? ?
            for (String styleName : styleNames) {
                Object objStyle = typeResources.get(styleName);
                Field[] fields = ClassReflection.getFields(objStyle.getClass());
                for (Field field : fields) {
                    //  field
                    if (field.isFinal() || field.isStatic() || field.isTransient()) {
                        continue;
                    }
                    if (field.getType() == targetStyleClazz) {
                        @SuppressWarnings("unchecked")
                        T fieldObj = (T) field.get(objStyle);
                        String fieldObjStyleName = skin.find(fieldObj);
                        if (targetStyleName.equals(fieldObjStyleName)) {
                            return true;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:org.shadebob.skineditor.utils.scenes.scene2d.ui.CustomSkin.java

License:Apache License

/** ?? */
public static <T> boolean isStyleInUse(Skin skin, String targetStyleName, Class<T> targetStyleClazz) {
    if (skin == null || targetStyleName == null || targetStyleName.trim().length() == 0
            || targetStyleClazz == null) {
        throw new IllegalArgumentException("skin?targetStyleName and targetStyleClazz can not null");
    }// ww  w  .j a v a2  s  .c  o m
    try {
        for (String widget : SkinEditorGame.widgets) {
            Class<?> resType = Class
                    .forName("com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style");
            // ?
            if (resType == targetStyleClazz) {
                continue;
            }
            ObjectMap<String, ?> typeResources = skin.getAll(resType);
            if (emptyMap(typeResources)) {
                continue;
            }
            //  styleName ?.???
            Array<String> styleNames = typeResources.keys().toArray();
            // ??? resType ? ?
            for (String styleName : styleNames) {
                Object objStyle = typeResources.get(styleName);
                Field[] fields = ClassReflection.getFields(objStyle.getClass());
                for (Field field : fields) {
                    //  field
                    if (field.isFinal() || field.isStatic() || field.isTransient()) {
                        continue;
                    }
                    if (field.getType() == targetStyleClazz) {
                        @SuppressWarnings("unchecked")
                        T fieldObj = (T) field.get(objStyle);
                        String fieldObjStyleName = skin.find(fieldObj);
                        if (targetStyleName.equals(fieldObjStyleName)) {
                            return true;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}