-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for GamaColor serialization (see #3288 )
- Loading branch information
Showing
3 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...co.gama.serialize/src/ummisco/gama/serializer/gamaType/converters/GamaColorConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |
70 changes: 70 additions & 0 deletions
70
ummisco.gama.serialize/src/ummisco/gama/serializer/gamaType/reduced/GamaColorReducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |