Re: [OpenMap Users] Context menus and layer ordering

From: <pch42_at_tpg.com.au>
Date: Fri, 07 Aug 2009 08:44:40 +1000

Carsten,

thanks for that reply. I have created the simplest example I can of the problem. The code is listed
below.

There is an abstract layer with two concrete subclasses. The concrete classes each draw a square -
the two squares partially overlap. The following is extracted from the openmap.properties file.

openmap.layers=mylayer1 mylayer2 shapePolitical
mylayer1.class=om.MyConcreteLayer1
mylayer1.prettyName=Layer 1
mylayer2.class=om.MyConcreteLayer2
mylayer2.prettyName=Layer 2

Initially mylayer1 is on top of mylayer2. Selecting 'Details' from the context menu on the non-
overlapping areas of the squares behaves as expected, but selecting 'Details' from the context
menu when the mouse is over the intersecting area results in the output

This is layer 'Layer 2'

If I then move mylayer2 above mylayer1 selecting 'Details' over the intersecting region produces
the output

This is layer 'Layer 1'.

Paul

**************************
package om;

import java.awt.event.*;
import java.util.*;
import javax.swing.*;

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

public abstract class MyAbstractLayer extends OMGraphicHandlerLayer {

    protected static final String ShowDetails = "Details";

    public MyAbstractLayer() {
        setMouseModeIDsForEvents(new String[]{"Gestures"});
    }

    protected abstract OMGraphicList drawObjects();

    protected abstract String getDetails(OMGraphic omg);

    _at_Override
    public synchronized OMGraphicList prepare() {
        return drawObjects();
    }

    _at_Override
    public java.util.List getItemsForOMGraphicMenu(OMGraphic omg) {
        java.util.List items = new ArrayList();
        items.add(new MyMenuItem(ShowDetails, omg));
        return items;
    }

    class MyMenuItem extends JMenuItem implements ActionListener {

        protected OMGraphic omg;

        public MyMenuItem(String label, OMGraphic omg) {
            super(label);
            this.omg = omg;
            addActionListener(this);
        }

        public MyMenuItem(String label) {
            this(label, null);
        }

        public void actionPerformed(ActionEvent e) {
            String command = e.getActionCommand();
            if (command == ShowDetails) {
                System.out.println(getDetails(omg));
            }
        }
    }
}
******************************
package om;

import java.awt.*;
import com.bbn.openmap.omGraphics.*;

public class MyConcreteLayer1 extends MyAbstractLayer {

    protected OMGraphicList drawObjects() {
        OMGraphicList gl = new OMGraphicList();
        float[] points = {0, 0, 0, 20, 20, 20, 20, 0};
        OMPoly shape = new OMPoly(points, OMGraphic.DECIMAL_DEGREES,
OMGraphic.LINETYPE_STRAIGHT);
        shape.setIsPolygon(true);
        shape.setLinePaint(Color.RED);
        gl.add(shape);
        gl.generate(getProjection());
        return gl;
    }

    protected String getDetails(OMGraphic omg) {
        return "This is layer '" + getName() + "'";
    }
}
*******************************
package om;

import java.awt.*;
import com.bbn.openmap.omGraphics.*;

public class MyConcreteLayer2 extends MyAbstractLayer {

    protected OMGraphicList drawObjects() {
        OMGraphicList gl = new OMGraphicList();
        float[] points = {10, 10, 10, 30, 30, 30, 30, 10};
        OMPoly shape = new OMPoly(points, OMGraphic.DECIMAL_DEGREES,
OMGraphic.LINETYPE_STRAIGHT);
        shape.setIsPolygon(true);
        shape.setLinePaint(Color.BLUE);
        gl.add(shape);
        gl.generate(getProjection());
        return gl;
    }

    protected String getDetails(OMGraphic omg) {
        return "This is layer '" + getName() + "'";
    }
}
**********************************

On Thu, Aug 6th, 2009 at 10:02 PM, "\"Carsten Ø. Madsen\"" <com_at_navicon.dk> wrote:

> Hi
>
> Look at the consumeEvents property of your layers. Maybe events
> bubble
> down or your own event handling lets the event pass down through the
>
> layer stack.
>
> BR
> Carsten
>
> On 08/06/2009 01:15 PM, Paul Chisholm wrote:
> > Hi,
> >
> > I seem to be having some sort of issue with layer ordering. I
> understand
> > that the layers are displayed in the order they appear in the
> layers
> > panel, with layers higher up being displayed over the top of
> layers
> > lower down. I have created a number of subclasses of
> > OMGraphicHandlerLayer to display my own data. Each of these layers
> has a
> > right-click context menu. What I observe when I have two layers (A
> and
> > B) on display with A above B is that a right-click over an area of
> the
> > display brings up the context menu for layer B rather than layer A.
> If
> > If I reorder layers so that A is below B then a right-click
> displays the
> > context menu for A. Any idea what I might be doing to cause this
> > behaviour?
> >
> > Thanks,
> > Paul
> >
> > --
> > [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"]
>
> --
> [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"]
>
>
>



--
[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 Thu Aug 06 2009 - 18:45:33 EDT

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