Search in sources :

Example 6 with NotImplementedException

use of sun.reflect.generics.reflectiveObjects.NotImplementedException in project nhglib by VoidZombie.

the class ParameterTweaker method tweak.

/**
     * Register class field for runtime tweaking.
     * This also creates a static reference to passed object, so GC will not be able to free it.
     *
     * @param objInstance object instance that holds the field (usually "this" keyword can be used)
     * @param fieldName   name of class field
     * @param step        by how much should value change on key press
     * @param min         minimum value
     * @param max         maximum value
     * @param decreaseKey ID of key used to decrease value
     * @param increaseKey ID of key used to increase value
     */
public static void tweak(Object objInstance, String fieldName, float step, float min, float max, int decreaseKey, int increaseKey) {
    Field field = null;
    try {
        field = objInstance.getClass().getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
    if (!(field.getType().equals(Float.TYPE) || field.getType().equals(Integer.TYPE)))
        throw new NotImplementedException();
    field.setAccessible(true);
    // add new tweak command to decrease key mapping
    Array<Tweak> keyTweaks = tweakMap.get(decreaseKey, new Array<Tweak>(1));
    keyTweaks.add(new Tweak(objInstance, field, -step, min, max));
    tweakMap.put(decreaseKey, keyTweaks);
    Gdx.app.log("ParameterTweaker", String.format("Key id %d set to change parameter %s by %+f between min=%f and max=%f", decreaseKey, fieldName, -step, min, max));
    // add new tweak command to increase key mapping
    keyTweaks = tweakMap.get(increaseKey, new Array<Tweak>(1));
    keyTweaks.add(new Tweak(objInstance, field, +step, min, max));
    tweakMap.put(increaseKey, keyTweaks);
    Gdx.app.log("ParameterTweaker", String.format("Key id %d set to change parameter %s by %+f between min=%f and max=%f", increaseKey, fieldName, +step, min, max));
    if (instance == null) {
        instance = new ParameterTweaker();
        Gdx.input.setInputProcessor(instance);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) Field(java.lang.reflect.Field) NotImplementedException(sun.reflect.generics.reflectiveObjects.NotImplementedException)

Aggregations

NotImplementedException (sun.reflect.generics.reflectiveObjects.NotImplementedException)6 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)3 URL (java.net.URL)3 IOException (java.io.IOException)2 Array (com.badlogic.gdx.utils.Array)1 TransientObject (io.divide.shared.transitory.TransientObject)1 Field (java.lang.reflect.Field)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Queue (java.util.Queue)1