Revision: 5074
          http://sourceforge.net/p/jump-pilot/code/5074
Author:   michaudm
Date:     2016-10-13 07:07:59 +0000 (Thu, 13 Oct 2016)
Log Message:
-----------
Fix problem in Theming Style serialization when using unique values and 
different attribute types.

Modified Paths:
--------------
    plug-ins/ViewManagerPlugin/trunk/build.xml
    
plug-ins/ViewManagerPlugin/trunk/src/org/openjump/ext/viewmanager/ViewManagerExtension.java
    
plug-ins/ViewManagerPlugin/trunk/src/org/openjump/ext/viewmanager/style/PColorThemingStyle.java

Modified: plug-ins/ViewManagerPlugin/trunk/build.xml
===================================================================
--- plug-ins/ViewManagerPlugin/trunk/build.xml  2016-10-12 13:47:28 UTC (rev 
5073)
+++ plug-ins/ViewManagerPlugin/trunk/build.xml  2016-10-13 07:07:59 UTC (rev 
5074)
@@ -19,7 +19,7 @@
     <!-- plugins -->
     <!-- drivers -->
     <property name="view-manager" value="ViewManager" />
-    <property name="view-manager-version" value="0.3.2" />
+    <property name="view-manager-version" value="0.3.3" />
 
 
     <!-- =================================================================== 
-->

Modified: 
plug-ins/ViewManagerPlugin/trunk/src/org/openjump/ext/viewmanager/ViewManagerExtension.java
===================================================================
--- 
plug-ins/ViewManagerPlugin/trunk/src/org/openjump/ext/viewmanager/ViewManagerExtension.java
 2016-10-12 13:47:28 UTC (rev 5073)
+++ 
plug-ins/ViewManagerPlugin/trunk/src/org/openjump/ext/viewmanager/ViewManagerExtension.java
 2016-10-13 07:07:59 UTC (rev 5074)
@@ -14,7 +14,7 @@
     }
 
     public String getVersion() {
-        return "0.3.2 (2016-10-09)";
+        return "0.3.3 (2016-10-12)";
     }
 
     public void configure(PlugInContext context) throws Exception {

Modified: 
plug-ins/ViewManagerPlugin/trunk/src/org/openjump/ext/viewmanager/style/PColorThemingStyle.java
===================================================================
--- 
plug-ins/ViewManagerPlugin/trunk/src/org/openjump/ext/viewmanager/style/PColorThemingStyle.java
     2016-10-12 13:47:28 UTC (rev 5073)
+++ 
plug-ins/ViewManagerPlugin/trunk/src/org/openjump/ext/viewmanager/style/PColorThemingStyle.java
     2016-10-13 07:07:59 UTC (rev 5074)
@@ -8,6 +8,8 @@
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -43,10 +45,34 @@
                         ((Range)entry.getKey()).getMax()),
                         new PBasicStyle((BasicStyle)entry.getValue()),
                         
(String)style.getAttributeValueToLabelMap().get(entry.getKey())));
-            } else {
-                themes.add(new Theme(new ValueKey(entry.getKey()),
+            } else if (entry.getKey() instanceof Integer) {
+                themes.add(new Theme(new IntKey((Integer)entry.getKey()),
                         new PBasicStyle((BasicStyle)entry.getValue()),
                         
(String)style.getAttributeValueToLabelMap().get(entry.getKey())));
+            } else if (entry.getKey() instanceof Long){
+                themes.add(new Theme(new LongKey((Long)entry.getKey()),
+                        new PBasicStyle((BasicStyle)entry.getValue()),
+                        
(String)style.getAttributeValueToLabelMap().get(entry.getKey())));
+            } else if (entry.getKey() instanceof Double){
+                themes.add(new Theme(new DoubleKey((Double)entry.getKey()),
+                        new PBasicStyle((BasicStyle)entry.getValue()),
+                        
(String)style.getAttributeValueToLabelMap().get(entry.getKey())));
+            } else if (entry.getKey() instanceof String){
+                themes.add(new Theme(new StringKey((String)entry.getKey()),
+                        new PBasicStyle((BasicStyle)entry.getValue()),
+                        
(String)style.getAttributeValueToLabelMap().get(entry.getKey())));
+            } else if (entry.getKey() instanceof Timestamp){
+                themes.add(new Theme(new 
TimestampKey((Timestamp)entry.getKey()),
+                        new PBasicStyle((BasicStyle)entry.getValue()),
+                        
(String)style.getAttributeValueToLabelMap().get(entry.getKey())));
+            } else if (entry.getKey() instanceof Date){
+                themes.add(new Theme(new DateKey((Date)entry.getKey()),
+                        new PBasicStyle((BasicStyle)entry.getValue()),
+                        
(String)style.getAttributeValueToLabelMap().get(entry.getKey())));
+            } else if (entry.getKey() instanceof Boolean){
+                themes.add(new Theme(new BooleanKey((Boolean)entry.getKey()),
+                        new PBasicStyle((BasicStyle)entry.getValue()),
+                        
(String)style.getAttributeValueToLabelMap().get(entry.getKey())));
             }
         }
     }
@@ -69,13 +95,63 @@
                 mapStyles.put(range, 
(BasicStyle)theme.style.getStyle(layerable));
                 mapLabels.put(range, theme.label);
             }
-        } else {
+        }
+        else if (themes != null && themes.size()>0 && 
themes.iterator().next().key instanceof IntKey) {
             mapStyles = new HashMap<Object, BasicStyle>();
             for (Theme theme : themes) {
-                mapStyles.put(((ValueKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
-                mapLabels.put(((ValueKey)theme.key).value, theme.label);
+                mapStyles.put(((IntKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
+                mapLabels.put(((IntKey)theme.key).value, theme.label);
             }
         }
+        else if (themes != null && themes.size()>0 && 
themes.iterator().next().key instanceof LongKey) {
+            mapStyles = new HashMap<Object, BasicStyle>();
+            for (Theme theme : themes) {
+                mapStyles.put(((LongKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
+                mapLabels.put(((LongKey)theme.key).value, theme.label);
+            }
+        }
+        else if (themes != null && themes.size()>0 && 
themes.iterator().next().key instanceof DoubleKey) {
+            mapStyles = new HashMap<Object, BasicStyle>();
+            for (Theme theme : themes) {
+                mapStyles.put(((DoubleKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
+                mapLabels.put(((DoubleKey)theme.key).value, theme.label);
+            }
+        }
+        else if (themes != null && themes.size()>0 && 
themes.iterator().next().key instanceof StringKey) {
+            mapStyles = new HashMap<Object, BasicStyle>();
+            for (Theme theme : themes) {
+                mapStyles.put(((StringKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
+                mapLabels.put(((StringKey)theme.key).value, theme.label);
+            }
+        }
+        else if (themes != null && themes.size()>0 && 
themes.iterator().next().key instanceof TimestampKey) {
+            mapStyles = new HashMap<Object, BasicStyle>();
+            for (Theme theme : themes) {
+                mapStyles.put(((TimestampKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
+                mapLabels.put(((TimestampKey)theme.key).value, theme.label);
+            }
+        }
+        else if (themes != null && themes.size()>0 && 
themes.iterator().next().key instanceof DateKey) {
+            mapStyles = new HashMap<Object, BasicStyle>();
+            for (Theme theme : themes) {
+                mapStyles.put(((DateKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
+                mapLabels.put(((DateKey)theme.key).value, theme.label);
+            }
+        }
+        else if (themes != null && themes.size()>0 && 
themes.iterator().next().key instanceof BooleanKey) {
+            mapStyles = new HashMap<Object, BasicStyle>();
+            for (Theme theme : themes) {
+                mapStyles.put(((BooleanKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
+                mapLabels.put(((BooleanKey)theme.key).value, theme.label);
+            }
+        }
+        //else {
+        //    mapStyles = new HashMap<Object, BasicStyle>();
+        //    for (Theme theme : themes) {
+        //        mapStyles.put(((ValueKey)theme.key).value, 
(BasicStyle)theme.style.getStyle(layerable));
+        //        mapLabels.put(((ValueKey)theme.key).value, theme.label);
+        //    }
+        //}
         colorThemingStyle.setAttributeValueToBasicStyleMap(mapStyles);
         colorThemingStyle.setAttributeValueToLabelMap(mapLabels);
         return colorThemingStyle;
@@ -87,7 +163,13 @@
 
         //@XmlElement
         @XmlElements(value = {
-            @XmlElement(name="value", type=ValueKey.class),
+            @XmlElement(name="int-value", type=IntKey.class),
+            @XmlElement(name="long-value", type=LongKey.class),
+            @XmlElement(name="double-value", type=DoubleKey.class),
+            @XmlElement(name="date-value", type=DateKey.class),
+            @XmlElement(name="timestamp-value", type=TimestampKey.class),
+            @XmlElement(name="boolean-value", type=BooleanKey.class),
+            @XmlElement(name="string-value", type=StringKey.class),
             @XmlElement(name="range", type=RangeKey.class),
         })
         Key key;
@@ -111,26 +193,177 @@
         }
     }
 
-    @XmlRootElement(name="value")
-    public static class ValueKey implements Key {
 
+    // Interface that all types of keys must implement
+    public interface Key extends Comparable<Key> {}
+
+
+    @XmlRootElement(name="int-value")
+    public static class IntKey implements Key {
+
         @XmlElement
+        Integer value;
+
+        IntKey() {}
+
+        IntKey(Integer object) {
+            this.value = object;
+        }
+
+        public int compareTo(Key key) {
+            if (value == null) return -1;
+            else if (key == null) return 1;
+            if (key instanceof IntKey) {
+                return value.compareTo(((IntKey) key).value);
+            }
+            return getClass().getName().compareTo(key.getClass().getName());
+        }
+
+    }
+
+
+    @XmlRootElement(name="long-value")
+    public static class LongKey implements Key {
+
+        @XmlElement
+        Long value;
+
+        LongKey() {}
+
+        LongKey(Long object) {
+            this.value = object;
+        }
+
+        public int compareTo(Key key) {
+            if (value == null) return -1;
+            else if (key == null) return 1;
+            if (key instanceof LongKey) {
+                return value.compareTo(((LongKey) key).value);
+            }
+            return getClass().getName().compareTo(key.getClass().getName());
+        }
+
+    }
+
+
+    @XmlRootElement(name="double-value")
+    public static class DoubleKey implements Key {
+
+        @XmlElement
+        Double value;
+
+        DoubleKey() {}
+
+        DoubleKey(Double object) {
+            this.value = object;
+        }
+
+        public int compareTo(Key key) {
+            if (value == null) return -1;
+            else if (key == null) return 1;
+            if (key instanceof DoubleKey) {
+                return value.compareTo(((DoubleKey) key).value);
+            }
+            return getClass().getName().compareTo(key.getClass().getName());
+        }
+
+    }
+
+
+    @XmlRootElement(name="string-value")
+    public static class StringKey implements Key {
+
+        @XmlElement
         String value;
 
-        ValueKey() {}
+        StringKey() {}
 
-        ValueKey(Object object) {
-            this.value = object.toString();
+        StringKey(String object) {
+            this.value = object;
         }
 
         public int compareTo(Key key) {
-            if (key instanceof ValueKey)
-                return this.value.compareTo(((ValueKey)key).value);
+            if (value == null) return -1;
+            else if (key == null) return 1;
+            if (key instanceof StringKey) {
+                return value.compareTo(((StringKey) key).value);
+            }
             return getClass().getName().compareTo(key.getClass().getName());
         }
 
     }
 
+
+    @XmlRootElement(name="boolean-value")
+    public static class BooleanKey implements Key {
+
+        @XmlElement
+        Boolean value;
+
+        BooleanKey() {}
+
+        BooleanKey(Boolean object) {
+            this.value = object;
+        }
+
+        public int compareTo(Key key) {
+            if (value == null) return -1;
+            else if (key == null) return 1;
+            if (key instanceof BooleanKey) {
+                return value.compareTo(((BooleanKey) key).value);
+            }
+            return getClass().getName().compareTo(key.getClass().getName());
+        }
+
+    }
+
+
+    @XmlRootElement(name="date-value")
+    public static class DateKey implements Key {
+
+        @XmlElement
+        @XmlJavaTypeAdapter(DateAdapter.class)
+        Date value;
+
+        DateKey() {}
+
+        DateKey(Date object) {
+            this.value = object;
+        }
+
+        public int compareTo(Key key) {
+            if (key instanceof DateKey) {
+                return value.compareTo(((DateKey) key).value);
+            }
+            return getClass().getName().compareTo(key.getClass().getName());
+        }
+
+    }
+
+
+    @XmlRootElement(name="timestamp-value")
+    public static class TimestampKey implements Key {
+
+        @XmlElement
+        @XmlJavaTypeAdapter(TimestampAdapter.class)
+        Timestamp value;
+
+        TimestampKey() {}
+
+        TimestampKey(Timestamp object) {
+            this.value = object;
+        }
+
+        public int compareTo(Key key) {
+            if (key instanceof TimestampKey) {
+                return value.compareTo(((TimestampKey) key).value);
+            }
+            return getClass().getName().compareTo(key.getClass().getName());
+        }
+
+    }
+
+
     @XmlRootElement(name="range")
     @XmlAccessorType(XmlAccessType.FIELD)
     public static class RangeKey extends com.vividsolutions.jump.util.Range 
implements Key {
@@ -149,7 +382,41 @@
 
     }
 
-    public interface Key extends Comparable<Key> {}
 
 
+    private static class DateAdapter extends XmlAdapter<String, Date> {
+
+        private final SimpleDateFormat dateFormat = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+
+        @Override
+        public String marshal(Date v) throws Exception {
+            synchronized (dateFormat) {
+                return dateFormat.format(v);
+            }
+        }
+
+        @Override
+        public Date unmarshal(String v) throws Exception {
+            synchronized (dateFormat) {
+                return dateFormat.parse(v);
+            }
+        }
+
+    }
+
+    private static class TimestampAdapter extends XmlAdapter<String, 
Timestamp> {
+
+        @Override
+        public String marshal(Timestamp v) throws Exception {
+            return v.toString();
+        }
+
+        @Override
+        public Timestamp unmarshal(String v) throws Exception {
+            return Timestamp.valueOf(v);
+        }
+
+    }
+
+
 }


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to