RE: [OpenMap Users] Fail to repaint correctly in OMGraphicHandlerLayer

From: Stéphane WASSERHARDT <>
Date: Wed, 30 May 2007 09:48:33 +0200


I tried your code and I’m experiencing the same problem…
I checked some things: the prepare method works well (all graphics are
generated). I added some synchronization to guarantee that prepare and
repaint are called after actionPerformed (I don’t know if the Timer calls
actionPerformed from the event dispatch thread…)

Anyway, I could make the problem disappear!


The only way I found thy bypass this problem is to call prepare() in
actionPerformed(), and move the current code of actionPerformed() at the
beginning of prepare(). So the mouseClicked() only does a repaint :


public void actionPerformed(ActionEvent event) {




      public synchronized OMGraphicList prepare() {

            for (int i = 0; i < list.size(); i++) {

                  OMGraphic g = list.getOMGraphicAt(i);


                  if (g instanceof OMCircle) {

                        OMCircle omc = ((OMCircle) g);

                        LatLonPoint point = omc.getLatLon();


                        ((OMCircle) g).setLatLon(point.getLatitude(), point

                                   .getLongitude() + 1);





            return super.prepare();


      public synchronized boolean mouseClicked(MouseEvent e) {


            return false;



This code is less efficient because it generates the whole list each second,
but it works!

I hope this will help narrow the problem :-)






De : [] De la
part de
Envoyé : mardi 29 mai 2007 21:27
À :
Objet : [OpenMap Users] Fail to repaint correctly in OMGraphicHandlerLayer


I am experiencing a sporadic problem in a Layer derived from the
OMGraphHandlerLayer. In my application there is a set of OMGraphics that
independantly move on this layer and occasionally there is a asynchronous
call to prepare and repaint. Occasionally all or part of the set of
OMGraphics disappear until the next repaint. I have tried a myriad of
things to fix the problem and have searched through past correspondence to
see if anyone else has experienced similair problems but to no avail.

I have written a simple application that I believe recreates the problem
that I have been experiencing. The code is included below. It draws a
bunch of stars and circles on a map with no other layers. Every second, the
circles move to the east by one degree. A prepare and repaint occurs with a
click to the map. The behavior that I experience when clicking on the
application the stars are stationary and always draw, the circles usually
redraw in their new location but occasionally will not redraw but disappear
altogether. I have found something that will exacerbate the problem by
adding in a repaint policy that delays slightly before calling repaint. One
is included but is commented out when it would be added to the MapBean.

Could someone try this and let me know if they also see the same problem?

Mark DaBell


The code is as follows.

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import com.bbn.openmap.*;
import com.bbn.openmap.event.*;
import com.bbn.openmap.gui.*;
import com.bbn.openmap.layer.*;
import com.bbn.openmap.omGraphics.*;

class DelayedMapBeanRepaintPolicy extends StandardMapBeanRepaintPolicy {
  long threshold = 100;
  public void repaint(Layer layer) {
    if (map != null) {
      }catch(Exception e){}

class ObjectLayer extends OMGraphicHandlerLayer implements ActionListener,
  OMGraphicList list = new OMGraphicList();
  OMCircle circle = new OMCircle(10,10,5);
  Timer timer = new Timer(1000, this);
  public ObjectLayer(){
    BasicStroke starStroke = new BasicStroke(3f);
    Color starColor = new Color(248,218,7);
    for(int i = -90; i<=90; i+=10){
      for(int j = -180; j<=170;j+=10){
        list.add(new OMCircle((float)i,(float)j,5));
        OMPoly star = new OMPoly((float)i,(float)j,new int[]{0,5,-8,8,-5,0},

            new int[]{-8,7,-2,-2,7,-8}, OMPoly.COORDMODE_ORIGIN);
  public void actionPerformed(ActionEvent event){
    for(int i = 0; i<list.size(); i++){
      OMGraphic g = list.getOMGraphicAt(i);
      if (g instanceof OMCircle){
        OMCircle omc = ((OMCircle)g);
        LatLonPoint point = omc.getLatLon();

  public MapMouseListener getMapMouseListener() {
    return this;
  public String[] getMouseModeServiceList() {

    return new String[] { SelectMouseMode.modeID, NavMouseMode2.modeID};
  public boolean mouseClicked(MouseEvent e) {

    return false;
  public boolean mouseDragged(MouseEvent e) {

    return false;
  public void mouseEntered(MouseEvent e) {}
  public void mouseExited(MouseEvent e) {}
  public void mouseMoved() {}
  public boolean mouseMoved(MouseEvent e) {
    return false;
  public boolean mousePressed(MouseEvent e) {
    return false;
  public boolean mouseReleased(MouseEvent e) {
    return false;


public class TestOM extends JPanel{
  MapBean mapbean = new MapBean();
  MapHandler handler = new MapHandler();
  LayerHandler layerhandler;
  NavigatePanel navpanel;
  JToolBar toolpanel = null;
  DelayedMapBeanRepaintPolicy delayedPolicy = new
  public TestOM(){
    this.setLayout(new BorderLayout());
    //to add the custom DelayRepaintPolicy uncomment this line.
    ObjectLayer ol = new ObjectLayer();
    OMToolSet toolset = new OMToolSet();
    navpanel = toolset.getNavigatePanel();
    handler.add(new MouseModePanel());

    toolpanel = new JToolBar();

    toolpanel.setLayout(new FlowLayout(FlowLayout.LEADING));
    toolpanel.add(new JLabel("Scale:"));
    add(toolpanel, BorderLayout.NORTH);

    layerhandler = new LayerHandler();
  public MouseModeButtonPanel getMouseModeButtonPanel(){
    MouseDelegator md = new MouseDelegator();
    md.addMouseMode(new SelectMouseMode());
    md.addMouseMode(new NavMouseMode2());
    MouseModeButtonPanel mmbp = new MouseModeButtonPanel();
    return mmbp;
  public static void main(String[] args){
    TestOM test = new TestOM();
    JFrame frame = new JFrame();


[To unsubscribe to this list send an email to ""
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed May 30 2007 - 04:12:16 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:08 EDT