[Schmitzm-commits] r2236 - in trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree: . chart
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Feb 21 16:20:17 CET 2013
Author: mojays
Date: 2013-02-21 16:20:16 +0100 (Thu, 21 Feb 2013)
New Revision: 2236
Modified:
trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/JFreeChartUtil.java
trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/SelectableChartPanel.java
Log:
JFreeChartUtil.getSelectionRenderer(.): BugFix to handle storage of SelectionRenderes correctly in Map for CompinedPlots
SelectableChartPanel: BugFix to avoid selection destroy in situation of multiple synchronized plots
Modified: trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/JFreeChartUtil.java 2013-02-16 13:08:13 UTC (rev 2235)
+++ trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/JFreeChartUtil.java 2013-02-21 15:20:16 UTC (rev 2236)
@@ -958,38 +958,55 @@
return null;
}
+ /**
+ * Returns all {@link SelectionRenderer} for a {@link Plot}.
+ *
+ * @param plot
+ * the plot to check for renderer
+ * @return never {@code null}
+ */
+ public static Map<Integer, SelectionRenderer<?>> getSelectionRenderer(Plot plot) {
+ return getSelectionRenderer(plot, 0);
+ }
+
/**
* Returns all {@link SelectionRenderer} for a {@link Plot}.
*
* @param plot
* the plot to check for renderer
+ * @param mapKeyOffset
+ * offset which is added to the plot/renderer index when used as key in returned map (necessary
+ * when determining {@link SelectionRenderer} from CombinedPlot, because for all sub-plots
+ * the indices would be the same and so replace elements in map!). NOTE: When offset is used,
+ * the map keys CAN NOT anymore be used directly as reference e.g. to dataset index!!
* @return never {@code null}
*/
- public static Map<Integer, SelectionRenderer<?>> getSelectionRenderer(
- Plot plot) {
+ private static Map<Integer, SelectionRenderer<?>> getSelectionRenderer(Plot plot, int mapKeyOffset) {
Map<Integer, SelectionRenderer<?>> selRenderer = new HashMap<Integer, SelectionRenderer<?>>();
if ( plot instanceof CombinedRangeXYPlot ) {
for (Object p : ((CombinedRangeXYPlot)plot).getSubplots())
- selRenderer.putAll( getSelectionRenderer((Plot)p) );
+ // renderers of first sub-plot get index 10, 11, ...
+ // renderers of second sub-plot get index 20, 21, ...
+ selRenderer.putAll( getSelectionRenderer((Plot)p, ++mapKeyOffset*10) );
return selRenderer;
}
if ( plot instanceof CombinedRangeCategoryPlot ) {
for (Object p : ((CombinedRangeCategoryPlot)plot).getSubplots())
- selRenderer.putAll( getSelectionRenderer((Plot)p) );
+ selRenderer.putAll( getSelectionRenderer((Plot)p, ++mapKeyOffset*10) );
return selRenderer;
}
if ( plot instanceof CombinedDomainXYPlot ) {
for (Object p : ((CombinedDomainXYPlot)plot).getSubplots())
- selRenderer.putAll( getSelectionRenderer((Plot)p) );
+ selRenderer.putAll( getSelectionRenderer((Plot)p, ++mapKeyOffset*10) );
return selRenderer;
}
if ( plot instanceof CombinedDomainCategoryPlot ) {
for (Object p : ((CombinedDomainCategoryPlot)plot).getSubplots())
- selRenderer.putAll( getSelectionRenderer((Plot)p) );
+ selRenderer.putAll( getSelectionRenderer((Plot)p, ++mapKeyOffset*10) );
return selRenderer;
}
@@ -998,7 +1015,7 @@
for (int i = 0; i < xyPlot.getRendererCount(); i++) {
XYItemRenderer r = xyPlot.getRenderer(i);
if (r instanceof SelectionRenderer<?>)
- selRenderer.put(i, (SelectionRenderer<?>) r);
+ selRenderer.put(i+mapKeyOffset, (SelectionRenderer<?>) r);
}
}
@@ -1007,7 +1024,7 @@
for (int i = 0; i < catPlot.getRendererCount(); i++) {
CategoryItemRenderer r = catPlot.getRenderer(i);
if (r instanceof SelectionRenderer<?>)
- selRenderer.put(i, (SelectionRenderer<?>) r);
+ selRenderer.put(i+mapKeyOffset, (SelectionRenderer<?>) r);
}
}
Modified: trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/SelectableChartPanel.java
===================================================================
--- trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/SelectableChartPanel.java 2013-02-16 13:08:13 UTC (rev 2235)
+++ trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/SelectableChartPanel.java 2013-02-21 15:20:16 UTC (rev 2236)
@@ -209,7 +209,18 @@
selModel.clearSelection();
}
}
-
+
+ // IMPORTANT: In the case, that selection is cleared from multiple plots (which are connected
+ // by synchronizer e.g. via a table), but renewed only for one of the plots (where
+ // the new selection was made), the setValueIsAdjusting(false) at the end, immediately
+ // destroys the new selection (because of propagation), if it is called first for
+ // one of the plots which were only cleared.
+ // We solve this problem, by separating the propagation (setValueIsAdjusting(false))
+ // of the clearance and the new selection!
+ for (DatasetSelectionModel<?,?,?> selModel : changedModels)
+ selModel.setValueIsAdjusting(false);
+ changedModels.clear();
+
for (Iterator<ChartEntity> i = selectedEntities.iterator(); i.hasNext();) {
ChartEntity e = i.next();
Dataset dataset = null;
@@ -259,6 +270,7 @@
LOGGER.error("Selection not yet implemented for selection model: "+LangUtil.getSimpleClassName(selModel));
}
}
+
// refresh the visualization
refresh();
// reset the "valueAdjusting" property to inform listeners
More information about the Schmitzm-commits
mailing list