package ar.com.geotekne.openmap.omGraphics; import java.awt.event.MouseEvent; import java.util.Iterator; import ar.com.geotekne.openmap.omGraphics.factory.EditableOMGraphicFactory; import com.bbn.openmap.omGraphics.EditableOMGraphic; import com.bbn.openmap.omGraphics.EditableOMGraphicList; import com.bbn.openmap.omGraphics.GrabPoint; import com.bbn.openmap.omGraphics.OMGraphic; import com.bbn.openmap.omGraphics.OMGraphicList; /** * This class changes the way the edition occurs for the {@code * EditableOMGraphicList}s. It adds support to -separately- change the * shape (i.e. their borders) of the figures inside the list as well as * move them together around the map * * @author fjeanne * */ public class GGEditableOMGraphicList extends EditableOMGraphicList { /** * The graphic being edited at any time (the one with the mouse over it) */ private EditableOMGraphic currSelectedGraphic; public GGEditableOMGraphicList() { super(); } public GGEditableOMGraphicList(OMGraphicList oml) { super(oml); // the "editables" list is managed diferently than it was before: here // we load ALL the editable graphics from the graphics in the original // list (the "omgl" list) initEditables(oml); } @Override public void init() { super.init(); // with this holder I can get a more sophisticated treatment in the // "DrawingAttributes held" matter. I can succesfully hold and restore // DrawingAttributes for each and every OMGraphic inside an // OMGraphicList (as well as for a simple OMGraphic without any list // involved) holder = new GGDrawingAttributesList(); } private void initEditables(OMGraphicList oml) { for (int i = 0; i < oml.size(); ++i) { OMGraphic gr = oml.getOMGraphicAt(i); if (gr instanceof OMGraphicList) { initEditables((OMGraphicList) gr); } else { // this is a "factory" class added just for testing. It does the // same job the "getEditableGraphic(OMGraphic g)" method in the // "OMDrawingTool" class does: returns an EditableOMGraphic from // an OMGraphic // TODO replace this with the "OMDrawingTool" mechanism editables.add(EditableOMGraphicFactory .createEditableOMGraphic(gr)); } } } @Override public GrabPoint getMovingPoint(MouseEvent me) { // this method is called whenever the mouse is moved above the layer, so // it's a good place to figure out which figure the user is trying to // edit Iterator it = editables.iterator(); GrabPoint gp = super.getMovingPoint(me); GrabPoint auxGp = null; currSelectedGraphic = null; while (it.hasNext() && auxGp == null) { EditableOMGraphic eomg = (EditableOMGraphic) it.next(); auxGp = eomg.getMovingPoint(me); if (auxGp != null) { // if an EditableOMGraphic returns a moving point then it must // have the mouse above. Look no more, this is the graphic being // edited and we must return its grab point in order to change // the shape of the figure gp = auxGp; currSelectedGraphic = eomg; } } return gp; } @Override public GrabPoint getMovingPoint() { // if there is a selected graphic at this time then it must return the // moving point, otherwise the "gpm" will be returned and the whole list // of figures can be moved together if (currSelectedGraphic != null) { return currSelectedGraphic.getMovingPoint(); } return gpm; } }