<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hello,<br>
    <br>
    Like you noticed, the graphic objects are cached, (the
    createGraphics is only called once).<br>
    You must see the rendering engine very much like a 3D scene graph.<br>
    There is a root node which contains other graphics and so on, so the
    createGraphics can return a single Graphic which contain several
    children graphics for each radar.<br>
    The graphic builder takes the MapLayer and the J2DCanvas in
    parameter, this allow the graphic to attach a listener on the
    MapLayer and update his graphic children when needed or recreate
    it's children each time.<br>
    <br>
    The canvas can be repaint at any time using :<br>
    getCanvas().getController().repaint();<br>
    <br>
    You can choose to repaint only on events or use an external thread
    to repaint at regular interval.<br>
    <br>
    johann<br>
    <br>
    <br>
    On 07/26/2011 11:42 AM, Thys Meintjes wrote:
    <blockquote
cite="mid:CAHRf99nE5dmSLrprvw7gn=VHbXRitwAP7eXwc0z0S=momUBJZg@mail.gmail.com"
      type="cite">
      <div class="gmail_quote">
        <div>After adding some logs I noticed the following:</div>
        <div><br>
        </div>
        <div>The TargetGraphicBuilder's &nbsp;createGraphics() is only called
          when loaded or when the state changed. It seems that the
          underlying</div>
        <div>assumption&nbsp;for the builder is that it will only be called
          once or twice to create a set of static graphics.... This does
          not fit with my</div>
        <div>use case where the targetmanager manages a list of
          dynamically changing targets. I assumed&nbsp;createGraphics will be
          called every time&nbsp;</div>
        <div>a repaint is needed - but this is not the case it seems.</div>
        <div><br>
        </div>
        <div>Is there anything I can do about this ? Is there a way of
          adding a graphic directly to a map layer ?&nbsp;</div>
        <div><br>
        </div>
        <div>
          <div>public class TargetGraphicBuilder implements
            GraphicBuilder&lt;GraphicJ2D&gt; {</div>
          <div><br>
          </div>
          <div>&nbsp;&nbsp; &nbsp;private final static Logger logger =
            LoggerFactory.getLogger(TargetGraphicBuilder.class);</div>
          <div>&nbsp;&nbsp; &nbsp;private TargetManager targetManager;</div>
          <div><br>
          </div>
          <div>&nbsp;&nbsp; &nbsp;public TargetGraphicBuilder(TargetManager manager) {</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;targetManager = manager;</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div>
          <div>&nbsp;&nbsp; &nbsp;}</div>
          <div><br>
          </div>
          <div>&nbsp;&nbsp; &nbsp;@Override</div>
          <div>&nbsp;&nbsp; &nbsp;public Collection&lt;GraphicJ2D&gt;
            createGraphics(MapLayer layer, Canvas canvas) {</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;logger.debug("Creating Graphics");</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (canvas instanceof J2DCanvas) {</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;final J2DCanvas j2dcanvas = (J2DCanvas)
            canvas;</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return makeTargets(j2dcanvas);</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;logger.debug("Canvas not a J2DCanvas");</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return Collections.emptyList();</div>
          <div>&nbsp;&nbsp; &nbsp;}</div>
          <div><br>
          </div>
          <div>&nbsp;&nbsp; &nbsp;private Collection makeTargets(J2DCanvas canvas) {</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ArrayList&lt;TargetGraphic&gt; targetGraphics =
            new ArrayList&lt;TargetGraphic&gt;();</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for (Target t : targetManager.getAllTargets()) {</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;targetGraphics.add(new TargetGraphic(canvas,
            t));</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return
            Collections.unmodifiableList(targetGraphics);</div>
          <div>&nbsp;&nbsp; &nbsp;}</div>
          <div><br>
          </div>
          <div>&nbsp;&nbsp; &nbsp;@Override</div>
          <div>&nbsp;&nbsp; &nbsp;public Class&lt;GraphicJ2D&gt; getGraphicType() {</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return GraphicJ2D.class;</div>
          <div>&nbsp;&nbsp; &nbsp;}</div>
          <div><br>
          </div>
          <div>&nbsp;&nbsp; &nbsp;@Override</div>
          <div>
            &nbsp;&nbsp; &nbsp;public Image getLegend(MapLayer layer) throws
            PortrayalException {</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return null;</div>
          <div>&nbsp;&nbsp; &nbsp;}</div>
          <div><br>
          </div>
          <div>&nbsp;&nbsp; &nbsp;public String getName() {</div>
          <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return targetManager.getName();</div>
          <div>&nbsp;&nbsp; &nbsp;}</div>
          <div>}</div>
        </div>
      </div>
      <br>
      -- <br>
      Thys Meintjes<br>
      <br>
      <br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Geotoolkit mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Geotoolkit@lists.osgeo.org">Geotoolkit@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/geotoolkit">http://lists.osgeo.org/mailman/listinfo/geotoolkit</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>