CN1 Charts: How to zoomToShapeInChartCoords() and then show a Dialog afterwards

20 views
Skip to first unread message

cubiq1

unread,
May 29, 2015, 7:38:46 AM5/29/15
to codenameone...@googlegroups.com
Hi,

I'm using CN1 Charts to plot a pie chart, as given in the Charts Demo. When I tap a segment I'd like the chart to zoom into the segment and then display a Dialog providing details of the segment.

I've managed to get it working, however, the Dialog is shown before the segment is zoomed in. How can I get the zoom operation to first complete before showing the Dialog? callSeriallyAndWait throws a runtime exception.

Many thanks

@Override
protected void seriesReleased(final SeriesSelection sel) {

   
for (SimpleSeriesRenderer r : renderer.getSeriesRenderers()){
        r
.setHighlighted(false);
   
}

   
SimpleSeriesRenderer r = renderer.getSeriesRendererAt(sel.getPointIndex());
    r
.setHighlighted(true);

   
Shape seg = chart.getSegmentShape(sel.getPointIndex());
   
Rectangle bounds = seg.getBounds();
    bounds
= new Rectangle(
    bounds
.getX()-40,
    bounds
.getY()-40,
    bounds
.getWidth()+80,
    bounds
.getHeight()+80);

    zoomToShapeInChartCoords
(bounds, 500);

   
// I'd like this to show AFTER the zoom has completed
   
Dialog.show("Info", "Segment info goes here.", "OK", null);
}

Shai Almog

unread,
May 29, 2015, 11:57:13 AM5/29/15
to codenameone...@googlegroups.com, cub...@gmail.com
Hi,
use callSerially NOT callSeriallyAndWait!
Wait would cause the EDT to stall.

However, I'm guessing you can just use a UITimer with 500ms which will give the animation time to complete.

cubiq1

unread,
May 29, 2015, 1:18:16 PM5/29/15
to codenameone...@googlegroups.com, cub...@gmail.com
A 500ms UITimer worked like a charm. Thanks.
Reply all
Reply to author
Forward
0 new messages