]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Changed PieDataset to support Comparable keys.
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 14 Feb 2014 11:52:45 +0000 (11:52 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 14 Feb 2014 11:52:45 +0000 (11:52 +0000)
Fixed ChartVariable compareTo()

refs #4741

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28842 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PieDataset.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartVariable.java

index de176a4c515e0f8b571e26e61d3c19f0d8695b59..c45eb951e500fb10664593f0d0434e09530ab56e 100644 (file)
@@ -19,7 +19,7 @@ import java.util.HashMap;
  * @author Teemu Lempinen\r
  *\r
  */\r
-public interface PieDataset extends IDataset {\r
+public interface PieDataset<T extends Comparable<T>> extends IDataset {\r
 \r
 \r
     /**\r
@@ -27,7 +27,7 @@ public interface PieDataset extends IDataset {
      * indicates the key of the value.\r
      * @return  Map of colors for different slices in a pie chart\r
      */\r
-    public HashMap<String, Color> getColorMap();\r
+    public HashMap<T, Color> getColorMap();\r
 \r
 \r
     /**\r
@@ -35,7 +35,7 @@ public interface PieDataset extends IDataset {
      * indicates the key of the slice.\r
      * @return\r
      */\r
-    public HashMap<String, Boolean> getExplodedMap();\r
+    public HashMap<T, Boolean> getExplodedMap();\r
     \r
    \r
 }\r
index 2c0705007cfaba8dcaed9aa4bf9296ad749e1462..9c4f1193ce00a765a52925a517a46e4860dace9d 100644 (file)
@@ -86,6 +86,7 @@ public class PiePlot extends AbstractPlot {
         properties.otherProperties.put("filterFraction", filterFraction);\r
     }\r
     \r
+    @SuppressWarnings({ "unchecked", "rawtypes" })\r
     @Override\r
     protected void setPlotProperties(PlotProperties properties) {\r
         if(!(plot instanceof MyPiePlot))\r
@@ -129,10 +130,10 @@ public class PiePlot extends AbstractPlot {
             \r
             listener = new DatasetChangeListener() {\r
                 \r
-                @Override\r
+                               @Override\r
                 public void datasetChanged(DatasetChangeEvent event) {\r
-                    HashMap<String, Color> colorMap = ((PieDataset)ds).getColorMap();\r
-                    HashMap<String, Boolean> explodedMap = ((PieDataset)ds).getExplodedMap();\r
+                    HashMap<Comparable<?>, Color> colorMap = ((PieDataset)ds).getColorMap();\r
+                    HashMap<Comparable<?>, Boolean> explodedMap = ((PieDataset)ds).getExplodedMap();\r
                     \r
                     for(Object o : piePlot.getDataset().getKeys()) {\r
                         if(o instanceof Comparable) {\r
@@ -146,14 +147,14 @@ public class PiePlot extends AbstractPlot {
                         }\r
                     }\r
                     \r
-                    for(String name : explodedMap.keySet()) {\r
+                    for(Comparable<?> name : explodedMap.keySet()) {\r
                         Boolean exploded = explodedMap.get(name);\r
                         if(Boolean.TRUE.equals(exploded))\r
                             piePlot.setExplodePercent(name, 0.3);\r
                     } \r
                     piePlot.clearSectionPaints(false);\r
                     piePlot.setDrawingSupplier(new DefaultDrawingSupplier());\r
-                    for(String name : colorMap.keySet())\r
+                    for(Comparable<?> name : colorMap.keySet())\r
                         piePlot.setSectionPaint(name, colorMap.get(name));\r
                 }\r
             };\r
index fb3522775d4803ade162b277eeb3b02b8cf80cc5..20ee63899fff4436e23c37c6670411aa1d4d22f3 100644 (file)
@@ -46,10 +46,15 @@ public class ChartVariable implements Comparable<ChartVariable>{
        \r
        @Override\r
        public int compareTo(ChartVariable o) {\r
+               int rvicomp = rvi.compareTo(o.rvi);\r
+               if (rvicomp == 0)\r
+                       return 0;\r
                if (label != null && o.label != null) {\r
-                       return label.compareTo(o.label);\r
+                       int labelcomp =  label.compareTo(o.label);\r
+                       if (labelcomp != 0)\r
+                               return labelcomp;\r
                }\r
-               return rvi.compareTo(o.rvi);\r
+               return rvicomp;\r
        }\r
 \r
 }\r