From ce3c6e07068c4f803ddc172beb1100d090b8a76c Mon Sep 17 00:00:00 2001 From: luukkainen Date: Fri, 14 Feb 2014 11:52:45 +0000 Subject: [PATCH] Changed PieDataset to support Comparable keys. 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/chart/PieDataset.java | 6 +++--- .../src/org/simantics/jfreechart/chart/PiePlot.java | 11 ++++++----- .../jfreechart/chart/properties/ChartVariable.java | 9 +++++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PieDataset.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PieDataset.java index de176a4c..c45eb951 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PieDataset.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PieDataset.java @@ -19,7 +19,7 @@ import java.util.HashMap; * @author Teemu Lempinen * */ -public interface PieDataset extends IDataset { +public interface PieDataset> extends IDataset { /** @@ -27,7 +27,7 @@ public interface PieDataset extends IDataset { * indicates the key of the value. * @return Map of colors for different slices in a pie chart */ - public HashMap getColorMap(); + public HashMap getColorMap(); /** @@ -35,7 +35,7 @@ public interface PieDataset extends IDataset { * indicates the key of the slice. * @return */ - public HashMap getExplodedMap(); + public HashMap getExplodedMap(); } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java index 2c070500..9c4f1193 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/PiePlot.java @@ -86,6 +86,7 @@ public class PiePlot extends AbstractPlot { properties.otherProperties.put("filterFraction", filterFraction); } + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void setPlotProperties(PlotProperties properties) { if(!(plot instanceof MyPiePlot)) @@ -129,10 +130,10 @@ public class PiePlot extends AbstractPlot { listener = new DatasetChangeListener() { - @Override + @Override public void datasetChanged(DatasetChangeEvent event) { - HashMap colorMap = ((PieDataset)ds).getColorMap(); - HashMap explodedMap = ((PieDataset)ds).getExplodedMap(); + HashMap, Color> colorMap = ((PieDataset)ds).getColorMap(); + HashMap, Boolean> explodedMap = ((PieDataset)ds).getExplodedMap(); for(Object o : piePlot.getDataset().getKeys()) { if(o instanceof Comparable) { @@ -146,14 +147,14 @@ public class PiePlot extends AbstractPlot { } } - for(String name : explodedMap.keySet()) { + for(Comparable name : explodedMap.keySet()) { Boolean exploded = explodedMap.get(name); if(Boolean.TRUE.equals(exploded)) piePlot.setExplodePercent(name, 0.3); } piePlot.clearSectionPaints(false); piePlot.setDrawingSupplier(new DefaultDrawingSupplier()); - for(String name : colorMap.keySet()) + for(Comparable name : colorMap.keySet()) piePlot.setSectionPaint(name, colorMap.get(name)); } }; diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartVariable.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartVariable.java index fb352277..20ee6389 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartVariable.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/ChartVariable.java @@ -46,10 +46,15 @@ public class ChartVariable implements Comparable{ @Override public int compareTo(ChartVariable o) { + int rvicomp = rvi.compareTo(o.rvi); + if (rvicomp == 0) + return 0; if (label != null && o.label != null) { - return label.compareTo(o.label); + int labelcomp = label.compareTo(o.label); + if (labelcomp != 0) + return labelcomp; } - return rvi.compareTo(o.rvi); + return rvicomp; } } -- 2.47.1