Example usage for com.badlogic.gdx.utils.reflect Field isFinal

List of usage examples for com.badlogic.gdx.utils.reflect Field isFinal

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils.reflect Field isFinal.

Prototype

public boolean isFinal() 

Source Link

Document

Return true if the field includes the final modifier.

Usage

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

License:Apache License

/** ?? */
public static <T> boolean isResInUse(Skin skin, T target) {
    if (skin == null || target == null) {
        throw new IllegalArgumentException("skin and target can not null");
    }/*from  w  w w. j  a v a 2s  .  co  m*/
    try {
        Class<?> clazzTarget = target.getClass();
        for (String widget : SkinEditorGame.widgets) {
            Class<?> resType = Class
                    .forName("com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style");
            // ?
            if (resType == clazzTarget) {
                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() == clazzTarget) {
                        @SuppressWarnings("unchecked")
                        T f = (T) field.get(objStyle);
                        if (target.equals(f)) {
                            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");
    }//from w  w  w. j a v a  2  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;
}

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

License:Apache License

/** ?? */
public static <T> boolean isResInUse(Skin skin, T target) {
    if (skin == null || target == null) {
        throw new IllegalArgumentException("skin and target can not null");
    }/*  www . jav a  2  s . co  m*/
    try {
        Class<?> clazzTarget = target.getClass();
        for (String widget : widgets) {
            Class<?> resType = Class
                    .forName("com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style");
            // ?
            if (resType == clazzTarget) {
                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() == clazzTarget) {
                        @SuppressWarnings("unchecked")
                        T f = (T) field.get(objStyle);
                        if (target.equals(f)) {
                            return true;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

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  .j av a 2 s .c om
    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:com.libgdx.skin.editor.utils.scene2d.CustomSkin.java

License:Apache License

void write1Style(Json json, Class<? extends Object> resType, ObjectMap<String, ? extends Object> typeResources,
        String styleName) {/*from  w  w w.  ja  va  2  s .c  om*/
    //  name  style
    Object objStyle = typeResources.get(styleName);
    Field[] fields = ClassReflection.getFields(resType);

    // ? BitmapFont? fields? fields  0
    if (objStyle instanceof com.badlogic.gdx.graphics.g2d.BitmapFont) {
        BitmapFont font = (BitmapFont) objStyle;
        json.writeValue("file", font.getData().fontFile.name());
        return;
    }

    // Handle fields
    for (Field field : fields) {
        //  field
        if (field.isFinal() || field.isStatic() || field.isTransient()) {
            continue;
        }
        try {
            write1Filed(json, objStyle, field);
        } catch (Exception e) {
            String tag = getClass().getSimpleName();
            String message = String.format("resTypes:%s  field:%s  json ", resType, field);
            Gdx.app.debug(tag, message, e);
        }
    }
}