diff --git a/ummisco.gama.serialize/src/ummisco/gama/serializer/factory/Converters.java b/ummisco.gama.serialize/src/ummisco/gama/serializer/factory/Converters.java index ced9aac802..6893cb91a0 100644 --- a/ummisco.gama.serialize/src/ummisco/gama/serializer/factory/Converters.java +++ b/ummisco.gama.serialize/src/ummisco/gama/serializer/factory/Converters.java @@ -17,6 +17,7 @@ import ummisco.gama.serializer.gamaType.converters.GamaAgentConverterNetwork; import ummisco.gama.serializer.gamaType.converters.GamaBDIPlanConverter; import ummisco.gama.serializer.gamaType.converters.GamaBasicTypeConverter; +import ummisco.gama.serializer.gamaType.converters.GamaColorConverter; import ummisco.gama.serializer.gamaType.converters.GamaFileConverter; import ummisco.gama.serializer.gamaType.converters.GamaGraphConverter; import ummisco.gama.serializer.gamaType.converters.GamaListConverter; @@ -44,7 +45,7 @@ public abstract class Converters { */ private static Converter[] loadConverter(ConverterScope cs) { - Converter[] converters= new Converter[15]; + Converter[] converters= new Converter[16]; converters[0]= new GamaBasicTypeConverter(cs); converters[1]=new GamaAgentConverter(cs); converters[2]=new GamaListConverter(cs); @@ -53,16 +54,17 @@ private static Converter[] loadConverter(ConverterScope cs) converters[5]=new GamaMatrixConverter(cs); converters[6]=new GamaGraphConverter(cs); converters[7]=new GamaFileConverter(cs); + converters[8]=new GamaColorConverter(); - converters[8]=new LogConverter(); - converters[9]=new SavedAgentConverter(cs); + converters[9]=new LogConverter(); + converters[10]=new SavedAgentConverter(cs); - converters[10]= new GamaPopulationConverter(cs); - converters[11]= new GamaSpeciesConverter(cs); - converters[12]= new ReferenceAgentConverter(cs); - converters[13]= new GamaPathConverter(cs); + converters[11]= new GamaPopulationConverter(cs); + converters[12]= new GamaSpeciesConverter(cs); + converters[13]= new ReferenceAgentConverter(cs); + converters[14]= new GamaPathConverter(cs); - converters[14]= new GamaBDIPlanConverter(cs); + converters[15]= new GamaBDIPlanConverter(cs); //converters[12]= new ComplexMessageConverter(cs); @@ -92,7 +94,7 @@ public static Converter[] converterFactory(ConverterScope cs) // TODO Remove when possible private static Converter[] loadConverterNetwork(ConverterScope cs) { - Converter[] converters= new Converter[14]; + Converter[] converters= new Converter[15]; converters[0]= new GamaBasicTypeConverter(cs); converters[1]=new GamaAgentConverterNetwork(cs); converters[2]=new GamaListConverterNetwork(cs); @@ -101,15 +103,16 @@ private static Converter[] loadConverterNetwork(ConverterScope cs) converters[5]=new GamaMatrixConverter(cs); converters[6]=new GamaGraphConverter(cs); converters[7]=new GamaFileConverter(cs); + converters[8]=new GamaColorConverter(); - converters[8]=new LogConverter(); - converters[9]=new SavedAgentConverter(cs); + converters[9]=new LogConverter(); + converters[10]=new SavedAgentConverter(cs); - converters[10]= new GamaPopulationConverter(cs); - converters[11]= new GamaSpeciesConverter(cs); - converters[12]= new GamaPathConverter(cs); + converters[11]= new GamaPopulationConverter(cs); + converters[12]= new GamaSpeciesConverter(cs); + converters[13]= new GamaPathConverter(cs); - converters[13]= new GamaBDIPlanConverter(cs); + converters[14]= new GamaBDIPlanConverter(cs); //converters[12]= new ComplexMessageConverter(cs); diff --git a/ummisco.gama.serialize/src/ummisco/gama/serializer/gamaType/converters/GamaColorConverter.java b/ummisco.gama.serialize/src/ummisco/gama/serializer/gamaType/converters/GamaColorConverter.java new file mode 100644 index 0000000000..cfec354306 --- /dev/null +++ b/ummisco.gama.serialize/src/ummisco/gama/serializer/gamaType/converters/GamaColorConverter.java @@ -0,0 +1,58 @@ +package ummisco.gama.serializer.gamaType.converters; + +import com.thoughtworks.xstream.converters.Converter; +import com.thoughtworks.xstream.converters.MarshallingContext; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; + +import msi.gama.util.GamaColor; +import ummisco.gama.dev.utils.DEBUG; +import ummisco.gama.serializer.gamaType.reduced.GamaColorReducer; + +@SuppressWarnings("rawtypes") +public class GamaColorConverter implements Converter { + + @Override + public boolean canConvert(final Class arg0) { + + if (GamaColor.class.equals(arg0)) { + return true; + } + + final Class[] allInterface = arg0.getInterfaces(); + for (final Class c : allInterface) { + if (c.equals(GamaColor.class)) + return true; + } + + final Class superClass = arg0.getSuperclass(); + if (superClass != null) { + return canConvert(superClass); + } + + return false; + } + + @Override + public void marshal(Object arg0, HierarchicalStreamWriter arg1, MarshallingContext arg2) { + final GamaColor mc = (GamaColor) arg0; + DEBUG.OUT("ConvertAnother : GamaColor " + mc.getClass()); + arg2.convertAnother(new GamaColorReducer(mc)); + DEBUG.OUT("END -- ConvertAnother : GamaColor " + mc.getClass()); + + } + + @Override + public Object unmarshal(HierarchicalStreamReader arg0, UnmarshallingContext arg1) { + final GamaColorReducer gcr = (GamaColorReducer) arg1.convertAnother(null, GamaColorReducer.class); + return gcr.constructObject(); + } + + + + + + + +} diff --git a/ummisco.gama.serialize/src/ummisco/gama/serializer/gamaType/reduced/GamaColorReducer.java b/ummisco.gama.serialize/src/ummisco/gama/serializer/gamaType/reduced/GamaColorReducer.java new file mode 100644 index 0000000000..699a08fb77 --- /dev/null +++ b/ummisco.gama.serialize/src/ummisco/gama/serializer/gamaType/reduced/GamaColorReducer.java @@ -0,0 +1,70 @@ +package ummisco.gama.serializer.gamaType.reduced; + +import msi.gama.util.GamaColor; + +public class GamaColorReducer { + + + public float getR() { + return r; + } + + + public void setR(float r) { + this.r = r; + } + + + public float getG() { + return g; + } + + + public void setG(float g) { + this.g = g; + } + + + public float getB() { + return b; + } + + + public void setB(float b) { + this.b = b; + } + + + public float getA() { + return a; + } + + + public void setA(float a) { + this.a = a; + } + + + private float r; + private float g; + private float b; + private float a; + + + public GamaColorReducer(GamaColor c) { + r = c.red(); + g = c.green(); + b = c.blue(); + a = c.alpha(); + } + + + public Object constructObject() { + return new GamaColor(r/255.0,g/255.0,b/255.0,a/255.0); + } + + + + + +}