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

From: <robert.m.dabell_at_L-3com.com>
Date: Wed, 30 May 2007 18:01:41 -0600

Stephane,
It appears that your suggestions works with my larger application. Thank you very much for your time and effort.
 
Mark

-----Original Message-----
From: Stéphane WASSERHARDT [mailto:stephane.wasserhardt_at_magellium.fr]
Sent: Wednesday, May 30, 2007 1:49 AM
To: DaBell, Robert M _at_ CSW-SLC; openmap-users_at_bbn.com
Subject: RE: [OpenMap Users] Fail to repaint correctly in OMGraphicHandlerLayer



Hi,

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) {

            prepare();

}

 

      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) {

            repaint();

            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 :-)

 

Stephane

 

 


  _____


De : owner-openmap-users_at_bbn.com [mailto:owner-openmap-users_at_bbn.com] De la part de robert.m.dabell_at_L-3com.com
Envoyé : mardi 29 mai 2007 21:27
À : openmap-users_at_bbn.com
Objet : [OpenMap Users] Fail to repaint correctly in OMGraphicHandlerLayer

 

All,
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) {
      try{
        Thread.sleep(threshold);
      }catch(Exception e){}
      map.repaint();
       
    }
  }
}

class ObjectLayer extends OMGraphicHandlerLayer implements ActionListener, MapMouseListener{
  OMGraphicList list = new OMGraphicList();
  OMCircle circle = new OMCircle(10,10,5);
  
  Timer timer = new Timer(1000, this);
  public ObjectLayer(){
    this.setList(list);
    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);
        star.setStroke(starStroke);
        
        star.setLinePaint(starColor);
        list.add(star);
      }
    }
    
    timer.start();
  }
  
  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();

        ((OMCircle)g).setLatLon(point.getLatitude(), point.getLongitude()+1);
      }
      
    }
    
  }
  public MapMouseListener getMapMouseListener() {
    return this;
  }
  
  public String[] getMouseModeServiceList() {

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

    prepare();
    repaint();
    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 DelayedMapBeanRepaintPolicy();
  
  public TestOM(){
    this.setLayout(new BorderLayout());
    add(mapbean);
    
    delayedPolicy.setMap(mapbean);
    
    //to add the custom DelayRepaintPolicy uncomment this line.
    //mapbean.setMapBeanRepaintPolicy(delayedPolicy);
    
    handler.add(mapbean);
    ObjectLayer ol = new ObjectLayer();
    
    
    handler.add(ol);
    
    OMToolSet toolset = new OMToolSet();
    
    navpanel = toolset.getNavigatePanel();
    
    handler.add(new MouseModePanel());
    handler.add(toolset);

    toolpanel = new JToolBar();

    toolpanel.setLayout(new FlowLayout(FlowLayout.LEADING));
    
    
    
    toolpanel.add(navpanel);
    toolpanel.add(toolset.getZoomPanel());
    toolpanel.add(new JLabel("Scale:"));
    toolpanel.add(toolset.getScaleField());
    toolpanel.add(getMouseModeButtonPanel());
    
    
    add(toolpanel, BorderLayout.NORTH);

    layerhandler = new LayerHandler();
    layerhandler.addLayer(ol);
    handler.add(layerhandler);
    
    
  }
  
  public MouseModeButtonPanel getMouseModeButtonPanel(){
    MouseDelegator md = new MouseDelegator();
    md.addMouseMode(new SelectMouseMode());
    md.addMouseMode(new NavMouseMode2());
    
    md.setMap(mapbean);
    
    MouseModeButtonPanel mmbp = new MouseModeButtonPanel();
    mmbp.setMouseDelegator(md);
    return mmbp;
    
    
   
  }
  
  public static void main(String[] args){
    TestOM test = new TestOM();
    JFrame frame = new JFrame();
    frame.add(test);
    
    frame.setSize(400,400);
    
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
  }
}

 



--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed May 30 2007 - 20:02:52 EDT

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