Ability to rotate toggle switch

This commit is contained in:
bancika
2012-08-31 13:49:34 +00:00
parent 371fee0614
commit b0164a1ddd
2 changed files with 20 additions and 7 deletions
@@ -13,6 +13,7 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.Orientation; import org.diylc.common.Orientation;
import org.diylc.common.OrientationHV;
import org.diylc.common.PropertyWrapper; import org.diylc.common.PropertyWrapper;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project; import org.diylc.core.Project;
@@ -239,12 +240,14 @@ public class InstantiationManager {
} }
} }
if (template != null) { if (template != null) {
for (Map.Entry<String, Object> pair : template.getValues().entrySet()) { for (Map.Entry<String, Object> pair : template.getValues()
.entrySet()) {
PropertyWrapper property = propertyCache.get(pair.getKey()); PropertyWrapper property = propertyCache.get(pair.getKey());
if (property == null) { if (property == null) {
LOG.warn("Cannot find property " + pair.getKey()); LOG.warn("Cannot find property " + pair.getKey());
} else { } else {
LOG.debug("Filling value from template for " + pair.getKey()); LOG.debug("Filling value from template for "
+ pair.getKey());
property.setValue(pair.getValue()); property.setValue(pair.getValue());
property.writeTo(object); property.writeTo(object);
} }
@@ -262,7 +265,9 @@ public class InstantiationManager {
PropertyWrapper angleProperty = null; PropertyWrapper angleProperty = null;
for (PropertyWrapper propertyWrapper : properties) { for (PropertyWrapper propertyWrapper : properties) {
if (propertyWrapper.getType().getName().equals( if (propertyWrapper.getType().getName().equals(
Orientation.class.getName())) { Orientation.class.getName())
|| propertyWrapper.getType().getName().equals(
OrientationHV.class.getName())) {
angleProperty = propertyWrapper; angleProperty = propertyWrapper;
break; break;
} }
@@ -274,10 +279,18 @@ public class InstantiationManager {
} }
try { try {
angleProperty.readFrom(this.componentSlot); angleProperty.readFrom(this.componentSlot);
Orientation value = (Orientation) angleProperty.getValue(); Object value = angleProperty.getValue();
value.ordinal(); if (value instanceof Orientation) {
angleProperty.setValue(Orientation.values()[(value.ordinal() + 1) angleProperty
% Orientation.values().length]); .setValue(Orientation.values()[(((Orientation) value)
.ordinal() + 1)
% Orientation.values().length]);
} else if (value instanceof OrientationHV) {
angleProperty
.setValue(OrientationHV.values()[(((OrientationHV) value)
.ordinal() + 1)
% OrientationHV.values().length]);
}
angleProperty.writeTo(this.componentSlot); angleProperty.writeTo(this.componentSlot);
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Error trying to rotate the component", e); LOG.warn("Error trying to rotate the component", e);