[OpenMap Users] Edit many OMGraphics simultaneously

From: fede jeanne <fedejeanne_at_gmail.com>
Date: Thu, 5 Aug 2010 11:44:41 -0300

Hi all:
I'm using OpenMap 4.6.4 and i'm trying to edit several EsriPolygons
simultaneously. So far I've extended the AbstractToolLoader class to provide
my own EditableGGGraphicList (I've tried using the existing
EditableOMGraphicList but i think this class wasn't intended for what i'm
trying to do). This "EditableGGGraphicList" class has an internal graphic
list to hold the original graphics and pass events to them (it is kind of a
"wrapper")... but the edition does not work: i'm able to select several
polygons together and move them, but i can't edit them (i mean: i can't grab
ONE point and move it in order to change the "shape" of the polygon).

I attach some code in case it can be useful:

//OMGraphicListLoader.java
--------------------------------------------------------------------------------------------------------------------------
package openmap.tools.drawing;

import openmap.omGraphics.EditableGGGraphicList;

import com.bbn.openmap.omGraphics.EditableOMGraphic;
import com.bbn.openmap.omGraphics.GraphicAttributes;
import com.bbn.openmap.omGraphics.OMGraphic;
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.tools.drawing.AbstractToolLoader;
import com.bbn.openmap.tools.drawing.EditClassWrapper;

public class OMGraphicListLoader extends AbstractToolLoader {
    protected String graphicClassName =
"com.bbn.openmap.omGraphics.OMGraphicList";

    public OMGraphicListLoader() {
        super();
        init();
    }

    public EditableOMGraphic getEditableGraphic(OMGraphic graphic) {
        if (graphic instanceof OMGraphicList) {
            return new EditableGGGraphicList((OMGraphicList) graphic);
        }
        return null;
    }

    public EditableOMGraphic getEditableGraphic(String classname,
            GraphicAttributes ga) {
        if (classname.intern() == graphicClassName) {
            return new EditableGGGraphicList(ga);
        }
        return null;
    }

    public void init() {
        EditClassWrapper ecw = new EditClassWrapper(graphicClassName,
                "com.bbn.openmap.omGraphics.EditableOMGraphicList",
                "editablepoint.gif", "OMGraphicList");

        addEditClassWrapper(ecw);
    }

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//EditableGGGraphicList.java
------------------------------------------------------------------------------------------------------------------------
package openmap.omGraphics;

import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

import openmap.omGraphics.factory.EditableOMGraphicFactory;

import com.bbn.openmap.omGraphics.EditableOMGraphic;
import com.bbn.openmap.omGraphics.GraphicAttributes;
import com.bbn.openmap.omGraphics.OMGraphic;
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.omGraphics.editable.GGListStateMachine;
import com.bbn.openmap.proj.Projection;
import com.bbn.openmap.util.Debug;

public class EditableGGGraphicList extends EditableOMGraphic {

    private OMGraphicList list;
    private List<EditableOMGraphic> editableList;

    public EditableGGGraphicList(OMGraphicList graphic) {
        setGraphic(graphic);
    }

    public EditableGGGraphicList(GraphicAttributes ga) {
        createGraphic(ga);
    }

    public void createGraphic(GraphicAttributes ga) {
        System.out.println("EditableGGGraphicList.createGraphic()");
        list = new OMGraphicList();
        editableList = new ArrayList<EditableOMGraphic>();
    }

    public boolean generate(Projection proj) {
        boolean ret = true;
        for (int i = 0; i < editableList.size(); ++i) {
            ret &= editableList.get(i).generate(proj);
        }
        return ret;
    }

    public OMGraphic getGraphic() {
        // FIXME this could be the method inside which the edition fails.
Maybe
        // what's happening is that, being the edited polygons inside the
        // "editableList" and not inside the "list", the editor is receiving
old
        // (not modified) polygons.
        return list;
    }

    public void regenerate(Projection proj) {
        System.out.println("EditableGGGraphicList.regenerate()");
        if (list != null) {
            for (int i = 0; i < editableList.size(); ++i) {
                editableList.get(i).regenerate(proj);
            }
        }

        setGrabPoints();
        generate(proj);
    }

    public void render(Graphics g) {
        System.out.println("EditableGGGraphicList.render()");
        if (list != null) {
            for (int i = 0; i < editableList.size(); ++i) {
                editableList.get(i).render(g);
            }
        }
    }

    public void setGrabPoints() {
        System.out.println("EditableGGGraphicList.setGrabPoints()");
        if (list != null) {
            for (int i = 0; i < editableList.size(); ++i) {
                editableList.get(i).setGrabPoints();
            }
        }

    }

    public void setGraphic(OMGraphic graphic) {

        System.out.println("EditableGGGraphicList.setGraphic()");
        init();
        if (graphic instanceof OMGraphicList) {
            list = (OMGraphicList) graphic;
            for (int i = 0; i < list.size(); ++i) {
                OMGraphic gr = list.getOMGraphicAt(i);

                // next line is used to get an instance of en EditableOMPoly
                // from an OMPoly (remember that EsriPolygon extends OMPoly)
                EditableOMGraphic egr = EditableOMGraphicFactory
                        .createEditableOMGraphic(gr);
                editableList.add(egr);
            }
            stateMachine.setSelected();
            setGrabPoints();
        } else {
            createGraphic(null);
        }
    }

    /**
     * Create and initialize the state machine that interprets the modifying
     * gestures/commands, as well as initialize the grab points. Also
allocates
     * the grab point array needed by the EditableOMPoint.
     */
    public void init() {
        Debug.message("eomg", "EditableOMPoint.init()");
        setCanGrabGraphic(false);
        setStateMachine(new GGListStateMachine(this));
        editableList = new ArrayList<EditableOMGraphic>();
    }

    public void move(MouseEvent e) {
        if (list != null) {
            for (int i = 0; i < editableList.size(); ++i) {
                editableList.get(i).move(e);
            }
        }
    }
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Any help or hint on this will be much appreciated!
thanks in advance

-- 
Fede
--
[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 05 2010 - 10:45:42 EDT

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