本文整理匯總了Java中com.github.czyzby.kiwi.util.gdx.reflection.Reflection.setFieldValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Reflection.setFieldValue方法的具體用法?Java Reflection.setFieldValue怎麽用?Java Reflection.setFieldValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.czyzby.kiwi.util.gdx.reflection.Reflection
的用法示例。
在下文中一共展示了Reflection.setFieldValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: injectFields
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
/** Invoked when all skins are loaded. Injects skin assets.
*
* @param interfaceService used to retrieve skins.
* @return {@link OnMessage#REMOVE}. */
@SuppressWarnings("unchecked")
@OnMessage(AutumnMessage.SKINS_LOADED)
public boolean injectFields(final InterfaceService interfaceService) {
for (final Entry<Pair<String, String>, Array<Pair<Field, Object>>> entry : fieldsToInject) {
final Skin skin = interfaceService.getParser().getData().getSkin(entry.key.getSecond());
final String assetId = entry.key.getFirst();
if (skin == null) {
throw new ContextInitiationException(
"Unable to inject asset: " + assetId + ". Unknown skin ID: " + entry.key.getSecond());
}
for (final Pair<Field, Object> injection : entry.value) {
try {
Reflection.setFieldValue(injection.getFirst(), injection.getSecond(),
skin.get(assetId, injection.getFirst().getType()));
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject skin asset: " + assetId + " from skin: " + skin
+ " to field: " + injection.getFirst() + " of component: " + injection.getSecond(),
exception);
}
}
}
fieldsToInject.clear();
return OnMessage.REMOVE;
}
示例2: handleRegularAssetInjection
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
private void handleRegularAssetInjection(final Object component, final Field field, final Asset assetData) {
if (assetData.value().length != 1) {
throw new GdxRuntimeException(
"Regular fields can store only 1 asset. If the field is a collection, its type is not currently supported: only LibGDX Array, ObjectSet and ObjectMap are permitted. Regular arrays will not be supported. Found multiple assets in field: "
+ field + " of component: " + component);
}
final String assetPath = assetData.value()[0];
if (assetData.loadOnDemand()) {
// Loaded immediately.
@SuppressWarnings("unchecked") final Object asset = finishLoading(assetPath, field.getType());
try {
Reflection.setFieldValue(field, component, asset);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject asset loaded on demand.", exception);
}
} else {
load(assetPath, field.getType());
// Scheduled to be loaded, delayed injection.
assetInjections.add(new StandardAssetInjection(field, assetPath, component));
}
}
示例3: injectAssets
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private void injectAssets(final AssetService assetService) {
try {
ObjectMap map = (ObjectMap) Reflection.getFieldValue(field, component);
if (map == null) {
map = GdxMaps.newObjectMap();
}
for (int assetIndex = 0; assetIndex < assetPaths.length; assetIndex++) {
map.put(assetKeys[assetIndex], assetService.get(assetPaths[assetIndex], assetType));
}
Reflection.setFieldValue(field, component, map);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject map of assets into component: " + component + ".",
exception);
}
}
示例4: injectAssets
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private void injectAssets(final AssetService assetService) {
try {
Array array = (Array) Reflection.getFieldValue(field, component);
if (array == null) {
array = GdxArrays.newArray();
}
for (final String assetPath : assetPaths) {
array.add(assetService.get(assetPath, assetType));
}
Reflection.setFieldValue(field, component, array);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject array of assets into component: " + component + ".",
exception);
}
}
示例5: handleLazyAssetInjection
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
private void handleLazyAssetInjection(final Object component, final Field field, final Asset assetData) {
if (Annotations.isNotVoid(assetData.lazyCollection())) {
handleLazyAssetCollectionInjection(component, field, assetData);
return;
} else if (assetData.value().length != 1) {
throw new GdxRuntimeException(
"Lazy wrapper can contain only one asset if lazy collection type is not provided. Found multiple assets in field: "
+ field + " of component: " + component);
}
final String assetPath = assetData.value()[0];
if (!assetData.loadOnDemand()) {
load(assetPath, assetData.type());
}
try {
Reflection.setFieldValue(field, component,
Lazy.providedBy(new AssetProvider(this, assetPath, assetData.type(), assetData.loadOnDemand())));
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject lazy asset.", exception);
}
}
示例6: handleMapInjection
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private void handleMapInjection(final Object component, final Field field, final Asset assetData) {
if (assetData.loadOnDemand()) {
final String[] assetPaths = assetData.value();
final String[] assetKeys = assetData.keys().length == 0 ? assetData.value() : assetData.keys();
try {
ObjectMap assets = (ObjectMap) Reflection.getFieldValue(field, component);
if (assets == null) {
assets = GdxMaps.newObjectMap();
}
for (int assetIndex = 0; assetIndex < assetPaths.length; assetIndex++) {
assets.put(assetKeys[assetIndex], finishLoading(assetPaths[assetIndex], assetData.type()));
}
Reflection.setFieldValue(field, component, assets);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject array of assets into: " + component, exception);
}
} else {
for (final String assetPath : assetData.value()) {
load(assetPath, assetData.type());
}
// Scheduled to be loaded, delayed injection.
assetInjections.add(new ObjectMapAssetInjection(assetData.value(), assetData.keys(), assetData.type(),
field, component));
}
}
示例7: injectAssets
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private void injectAssets(final AssetService assetService) {
try {
ObjectSet set = (ObjectSet) Reflection.getFieldValue(field, component);
if (set == null) {
set = GdxSets.newSet();
}
for (final String assetPath : assetPaths) {
set.add(assetService.get(assetPath, assetType));
}
Reflection.setFieldValue(field, component, set);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject set of assets into component: " + component + ".",
exception);
}
}
示例8: setDefaultTooltipManager
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
/** Since main tooltip manager instance cannot be changed globally with a regular setter, this method modifies it
* using reflection.
*
* @param tooltipManager will be returned on {@link TooltipManager#getInstance()} calls. */
public static void setDefaultTooltipManager(final TooltipManager tooltipManager) {
try {
// We have to set the app field, as it is validated by the static getter.
Reflection.setFieldValue(ClassReflection.getDeclaredField(TooltipManager.class, "app"), null, Gdx.app);
Reflection.setFieldValue(ClassReflection.getDeclaredField(TooltipManager.class, "instance"), null,
tooltipManager);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to set default tooltip manager.", exception);
}
}
示例9: setFieldValue
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
/** @param field will be set.
* @param component contains the field.
* @param value will become field's value. */
protected void setFieldValue(final Field field, final Object component, final Object value) {
try {
Reflection.setFieldValue(field, component, value);
} catch (final ReflectionException exception) {
throw new ContextInitiationException(
"Unable to inject value of field: " + field + " into component: " + component, exception);
}
}
示例10: injectStage
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
/** @param stage will be injected into {@link com.github.czyzby.autumn.mvc.stereotype.ViewStage}-annotated field, if
* present. */
protected void injectStage(final Stage stage) {
if (stageField != null) {
try {
Reflection.setFieldValue(stageField, wrappedObject, stage);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject stage into controller: " + wrappedObject + ".",
exception);
}
}
}
示例11: set
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
public void set(final Object preference) {
try {
Reflection.setFieldValue(field, owner, preference);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to set field value in component: " + owner, exception);
}
}
示例12: handleLazyAssetCollectionInjection
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
private void handleLazyAssetCollectionInjection(final Object component, final Field field, final Asset assetData) {
final String[] assetPaths = assetData.value();
final Class<?> assetType = assetData.type();
if (!assetData.loadOnDemand()) {
for (final String assetPath : assetPaths) {
load(assetPath, assetType);
}
}
try {
ObjectProvider<?> provider;
final Class<?> collectionClass = assetData.lazyCollection();
if (collectionClass.equals(Array.class)) {
provider = new ArrayAssetProvider(this, assetPaths, assetType, assetData.loadOnDemand());
} else if (collectionClass.equals(ObjectSet.class)) {
provider = new ObjectSetAssetProvider(this, assetPaths, assetType, assetData.loadOnDemand());
} else if (collectionClass.equals(ObjectMap.class)) {
provider = new ObjectMapAssetProvider(this, assetPaths, assetData.keys(), assetType,
assetData.loadOnDemand());
} else {
throw new GdxRuntimeException("Unsupported collection type in annotated class of component: "
+ component + ". Expected Array, ObjectSet or ObjectMap, received: " + collectionClass + ".");
}
Reflection.setFieldValue(field, component, Lazy.providedBy(provider));
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject lazy asset collection.", exception);
}
}
示例13: setDefaultTooltipManager
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
/** Since main tooltip manager instance cannot be changed globally with a regular setter, this method modifies it
* using reflection.
*
* @param tooltipManager will be returned on {@link TooltipManager#getInstance()} calls.
* @throws GdxRuntimeException if unable to change manager. */
public static void setDefaultTooltipManager(final TooltipManager tooltipManager) {
try {
TooltipManager.getInstance();
Reflection.setFieldValue(ClassReflection.getDeclaredField(TooltipManager.class, "instance"), null,
tooltipManager);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to set default tooltip manager.", exception);
}
}
示例14: changed
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void changed(final ChangeEvent event, final Actor actor) {
try {
Reflection.setFieldValue(field, owner, processor.extractValueFromActor((Widget) actor));
} catch (final ReflectionException exception) {
throw new GdxRuntimeException(
"Unable to update OnChange-annotated field: " + field + " of object: " + owner, exception);
}
}
示例15: read
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
public void read(final String name, final Preferences preferences) throws Exception {
Reflection.setFieldValue(field, owner, type.convert(preferences.getString(name)));
}