## com.bbn.openmap.omGraphics
Class EditableOMPoly

    java.lang.Object
      com.bbn.openmap.event.MapMouseAdapter
          com.bbn.openmap.omGraphics.EditableOMGraphic
              com.bbn.openmap.omGraphics.EditableOMAbstractLine
                  com.bbn.openmap.omGraphics.EditableOMPoly

All Implemented Interfaces:
  MapMouseListener

Direct Known Subclasses:
  EditableLabeledOMPoly, EditableOMDistance, EditableOMSpline

public class EditableOMPoly
extends EditableOMAbstractLine

The EditableOMPoly encompasses an OMPoly, providing methods for modifying or creating it.

Field Summary
`protected OffsetGrabPoint` `gpm`
`protected OffsetGrabPoint` `gpo`
`protected boolean` `manualEnclosed` Whether the poly is a polygon, as opposed to a polyline.
`static int` `OFFSET_POINT_INDEX`
`protected OMPoly` `poly`
`protected java.util.ArrayList` `polyGrabPoints`

Fields inherited from class com.bbn.openmap.omGraphics.EditableOMAbstractLine
`arrowheadMenu, i18n`

Fields inherited from class com.bbn.openmap.omGraphics.EditableOMGraphic
`actionMask, canGrabGraphic, DEBUG, DEBUG_DETAIL, gPoints, holder, lastMouseEvent, listeners, mouseModeServiceList, movingPoint, projection, showGUI, stateMachine`

Constructor Summary
`EditableOMPoly()` Create the EditableOMPoly, setting the state machine to create the poly off of the gestures.
`EditableOMPoly(GraphicAttributes ga)` Create an EditableOMPoly with the polyType and renderType parameters in the GraphicAttributes object.
`EditableOMPoly(OMPoly omp)` Create the EditableOMPoly with an OMPoly already defined, ready for editing.

Method Summary
`int` `addMovingPoint(int x, int y)` Add a point to the end of the polyline/polygon and then make it the moving one.
`int` `addPoint(GrabPoint gp)` Add a point at a certain point in the polygon coordinate list.
`int` `addPoint(GrabPoint gp, int position)` Add a point at a certain point in the polygon coordinate list.
`int` `addPoint(int x, int y)` Add a point to the end of the polyline/polygon.
`int` `addPoint(int x, int y, int position)` Add a point at a certain point in the polygon coordinate list.
`protected void` `addPolyGrabPointsToOGP(OffsetGrabPoint ogp)` This method adds all the GrabPoints associated with the polygon nodes and adds them to the offset GrabPoint representing the lat/lon anchor point.
`void` `assertGrabPoints()` Check to make sure the grab points are not null.
`void` `attachToMovingGrabPoint(OffsetGrabPoint gp)` Attach to the Moving OffsetGrabPoint so if it moves, it will move this EditableOMGraphic with it.
`protected GrabPoint` `createGrabPoint(int x, int y, int index, int last)` An internal method that trys to make sure that the grab point for the first node, and for the last, in case of an enclosed polygon, are OffsetGrabPoints.
`void` `createGraphic(GraphicAttributes ga)` Create and set the graphic within the state machine.
`OMGraphic` `createGraphic(int renderType, int lineType)` Extendable method to create specific subclasses of OMPolys.
`void` `deletePoint()` Delete a point off the end of the polyline/polygon.
`void` `deletePoint(int position)` Delete a point at a certain point in the polygon coordinate list.
`void` `detachFromMovingGrabPoint(OffsetGrabPoint gp)` Detach from a Moving OffsetGrabPoint.
`void` `enablePolygonButton(boolean enable)`
`void` `enablePolygonEditButtons(boolean enable)`
`void` `enclose(boolean e)`
`boolean` `evaluateEnclosed()` Method checks if the polygon should be enclosed, and then adds an addition point to the end of the polygon, setting the end point on top of the beginning point.
`boolean` `generate(Projection proj)` Use the current projection to place the graphics on the screen.
`GrabPoint` `getGrabPoint(int index)` Return a particular GrabPoint at a particular point in the array.
`GrabPoint[]` `getGrabPoints()` Get the array of grab points used for the EditableOMGraphic.
`OMGraphic` `getGraphic()` Get the OMGraphic being created/modified by the EditableOMPoly.
`java.awt.Component` `getGUI(GraphicAttributes graphicAttributes)` Adds widgets to modify polygon.
`java.net.URL` `getImageURL(java.lang.String imageName)`
`GrabPoint` `getMovingPoint(java.awt.event.MouseEvent e)` Given a MouseEvent, find a GrabPoint that it is touching, and set the moving point to that GrabPoint.
`javax.swing.JToolBar` `getPolyGUI()`
`javax.swing.JToolBar` `getPolyGUI(boolean includeEnclose, boolean includeAdd, boolean includeDelete)`
`void` `init()` Create and initialize the state machine that interprets the modifying gestures/commands, as well as ititialize the grab points.
`boolean` `isEnclosed()` Returns whether the graphic will be a polygon, instead of a polyline.
`void` `move(java.awt.event.MouseEvent e)` Called to set the OffsetGrabPoint to the current mouse location, and update the OffsetGrabPoint with all the other GrabPoint locations, so everything can shift smoothly.
`void` `regenerate(Projection proj)` Given a new projection, the grab points may need to be repositioned off the current position of the graphic.
`void` `render(java.awt.Graphics graphics)` Draw the EditableOMPoly parts into the java.awt.Graphics object.
`void` `setEnclosed(boolean set)` Set the flag to make the polygon enclosed, which automatically connects the last point with the first point.
`boolean` `setGrabPoint(GrabPoint gb, int index)` Set the GrabPoint at a particule index of the array.
`void` `setGrabPoints()` Take the current location of the GrabPoints, and modify the location parameters of the OMPoly with them.
`boolean` `setGrabPoints(GrabPoint[] points)` Set the grab point objects within the EditableOMGraphic array.
`void` `setGrabPoints(OMGraphic graphic)` Set the grab points for the graphic provided, setting them on the extents of the graphic.
`void` `setGraphic(OMGraphic graphic)` Set the graphic within the state machine.
`void` `setMovingPoint(GrabPoint gp)` Set the GrabPoint that is in the middle of being modified, as a result of a mouseDragged event, or other selection process.
`protected boolean` `syncEnclosed()` Method connects the last point to the first point.
`protected boolean` `unsyncEnclosed()` Method disconnects the last point from the first point.
`int` `whichGrabPoint(GrabPoint gp)` Given a grab point, return its index into the polygon array.

Methods inherited from class com.bbn.openmap.omGraphics.EditableOMAbstractLine
`createArrowIcon, getArrowHeadMenu`

Methods inherited from class com.bbn.openmap.omGraphics.EditableOMGraphic

`_getMovingPoint, addEOMGListener, cleanMap, finalize, fireEvent, fireEvent, fireEvent, fireEvent, getActionMask, getCanGrabGraphic, getGUI, getMouseModeServiceList, getMovingPoint, getProjection, getShowGUI, getStateMachine, handleInitialMouseEvent, modifyOMGraphicForEditRender, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressed, mouseReleased, redraw, redraw, redraw, removeEOMGListener, repaint, repaintRender, reset, resetOMGraphicAfterEditRender, setActionMask, setCanGrabGraphic, setMouseModeServiceList, setProjection, setShowGUI, setStateMachine`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### polyGrabPoints

    protected java.util.ArrayList polyGrabPoints

### gpo

    protected OffsetGrabPoint gpo

### gpm

    protected OffsetGrabPoint gpm

### poly

    protected OMPoly poly

### manualEnclosed

    protected boolean manualEnclosed

  Whether the poly is a polygon, as opposed to a polyline. If the poly color is not clear (OMColor.clear) then it will be a polygon. If it is clear, then it can be set as a polygon - it's otherwise assumed to be a polyline.

### OFFSET_POINT_INDEX

    public static int OFFSET_POINT_INDEX

Constructor Detail

### EditableOMPoly

    public EditableOMPoly()

  Create the EditableOMPoly, setting the state machine to create the poly off of the gestures.

### EditableOMPoly

    public EditableOMPoly(GraphicAttributes ga)

  Create an EditableOMPoly with the polyType and renderType parameters in the GraphicAttributes object.

### EditableOMPoly

    public EditableOMPoly(OMPoly omp)

  Create the EditableOMPoly with an OMPoly already defined, ready for editing.

Parameters:
  `omp` - OMPoly that should be edited.

Method Detail

### init

    public void init()

  Create and initialize the state machine that interprets the modifying gestures/commands, as well as ititialize the grab points. Also allocates the grab point array needed by the EditableOMPoly.

### setGraphic

    public void setGraphic(OMGraphic graphic)

  Set the graphic within the state machine. If the graphic is null, then one shall be created, and located off screen until the gestures driving the state machine place it on the map.

  Specified by:
    `setGraphic` in class `EditableOMGraphic`
  Parameters:
    `graphic` - OMGraphic.

### evaluateEnclosed

    public boolean evaluateEnclosed()

  Method checks if the polygon should be enclosed, and then adds an addition point to the end of the polygon, setting the end point on top of the beginning point. The two points are OffsetGrabPoints that are tied to each other's position.

### syncEnclosed

    protected boolean syncEnclosed()

  Method connects the last point to the first point. Make sure they are both OffsetGrabPoints. Return true if the points cover the same pixel and if they were successfully joined.

### unsyncEnclosed

    protected boolean unsyncEnclosed()

  Method disconnects the last point from the first point. Make sure they are both OffsetGrabPoints.

### enclose

    public void enclose(boolean e)

### setEnclosed

    public void setEnclosed(boolean set)

  Set the flag to make the polygon enclosed, which automatically connects the last point with the first point.

### isEnclosed

    public boolean isEnclosed()

  Returns whether the graphic will be a polygon, instead of a polyline.

### createGraphic

    public void createGraphic(GraphicAttributes ga)

  Create and set the graphic within the state machine. The GraphicAttributes describe the type of poly to create.

  Specified by:
    `createGraphic` in class `EditableOMGraphic`
  Parameters:
    `ga` - GraphicAttributes, describing the graphic to be created.

### createGraphic

    public OMGraphic createGraphic(int renderType,
                                   int lineType)

  Extendable method to create specific subclasses of OMPolys.

### getGraphic

    public OMGraphic getGraphic()

  Get the OMGraphic being created/modified by the EditableOMPoly.

  Specified by:
    `getGraphic` in class `EditableOMGraphic`

### attachToMovingGrabPoint

    public void attachToMovingGrabPoint(OffsetGrabPoint gp)

  Attach to the Moving OffsetGrabPoint so if it moves, it will move this EditableOMGraphic with it. EditableOMGraphic version doesn't do anything, each subclass has to decide which of its OffsetGrabPoints should be attached to it.

  Overrides:
    `attachToMovingGrabPoint` in class `EditableOMGraphic`

### detachFromMovingGrabPoint

    public void detachFromMovingGrabPoint(OffsetGrabPoint gp)

  Detach from a Moving OffsetGrabPoint. The EditableOMGraphic version doesn't do anything, each subclass should remove whatever GrabPoint it would have attached to an OffsetGrabPoint.

  Overrides:
    `detachFromMovingGrabPoint` in class `EditableOMGraphic`

### setMovingPoint

    public void setMovingPoint(GrabPoint gp)

  Set the GrabPoint that is in the middle of being modified, as a result of a mouseDragged event, or other selection process.

  Overrides:
    `setMovingPoint` in class `EditableOMGraphic`

### getMovingPoint

    public GrabPoint getMovingPoint(java.awt.event.MouseEvent e)

  Given a MouseEvent, find a GrabPoint that it is touching, and set the moving point to that GrabPoint. Called when a MouseEvent happens, and you want to find out if a GrabPoint should be used to make modifications to the graphic or its position.

  Overrides:
    `getMovingPoint` in class `EditableOMGraphic`
  Parameters:
    `e` - MouseEvent
  Returns:
    GrabPoint that is touched by the MouseEvent, null if none are.

### assertGrabPoints

    public void assertGrabPoints()

  Check to make sure the grab points are not null. If they are, allocate them, and them assign them to the array.

### createGrabPoint

    protected GrabPoint createGrabPoint(int x,
                                        int y,
                                        int index,
                                        int last)

  An internal method that trys to make sure that the grab point for the first node, and for the last, in case of an enclosed polygon, are OffsetGrabPoints. All of the other points will be regular GrabPoints. Usually called when assigning points to a previously defined poly.

  Parameters:
    `x` - the horizontal pixel location of the grab point.
    `y` - the vertical pixel location of the grab point.
    `index` - the index of the grab point.
    `last` - the index of the last point.

### setGrabPoints

    public void setGrabPoints(OMGraphic graphic)

  Set the grab points for the graphic provided, setting them on the extents of the graphic. Called when you want to set the grab points off the points of the graphic.

### setGrabPoints

    public void setGrabPoints()

  Take the current location of the GrabPoints, and modify the location parameters of the OMPoly with them. Called when you want the graphic to change according to the grab points.

  Specified by:
    `setGrabPoints` in class `EditableOMGraphic`

### addMovingPoint

    public int addMovingPoint(int x,
                              int y)

  Add a point to the end of the polyline/polygon and then make it the moving one.

  Returns:
    the index for the point in the polygon, starting with 0.

### addPoint

    public int addPoint(int x,
                        int y)

  Add a point to the end of the polyline/polygon.

  Returns:
    the index for the point in the polygon, starting with 0.

### addPoint

    public int addPoint(int x,
                        int y,
                        int position)

  Add a point at a certain point in the polygon coordinate list. If the position is less than zero, the point will be the starting point. If the position is greater than the list of current points, the point will be added to the end of the poly.

  Returns:
    the index for the point in the polygon, starting with 0.

### addPoint

    public int addPoint(GrabPoint gp)

  Add a point at a certain point in the polygon coordinate list. If the position is less than zero, the point will be the starting point. If the position is greater than the list of current points, the point will be added to the end of the poly. This method is convenient because it lets you define the GrabPoint object to use for the node, in case you need a special type of GrabPoint.

  Parameters:
    `gp` - the GrabPoint set to the screen coordinates of the point to be added.
  Returns:
    the index for the point in the polygon, starting with 0.

### addPoint

    public int addPoint(GrabPoint gp,
                        int position)

  Add a point at a certain point in the polygon coordinate list. If the position is less than zero, the point will be the starting point. If the position is greater than the list of current points, the point will be added to the end of the poly. This method is convenient because it lets you define the GrabPoint object to use for the node, in case you need a special type of GrabPoint.

  Returns:
    the index for the point in the polygon, starting with 0.

### deletePoint

    public void deletePoint()

  Delete a point off the end of the polyline/polygon.

### deletePoint

    public void deletePoint(int position)

  Delete a point at a certain point in the polygon coordinate list. If the position is less than zero, the deleted point will be the starting point. If the position is greater than the list of current points, the point will be deleted from the end of the poly.

### move

    public void move(java.awt.event.MouseEvent e)

  Called to set the OffsetGrabPoint to the current mouse location, and update the OffsetGrabPoint with all the other GrabPoint locations, so everything can shift smoothly. Should also set the OffsetGrabPoint to the movingPoint. Should be called only once at the beginning of the general movement, in order to set the movingPoint. After that, redraw(e) should just be called, and the movingPoint will make the adjustments to the graphic that are needed.

  Specified by:
    `move` in class `EditableOMGraphic`

### addPolyGrabPointsToOGP

    protected void addPolyGrabPointsToOGP(OffsetGrabPoint ogp)

  This method adds all the GrabPoints associated with the polygon nodes and adds them to the offset GrabPoint representing the lat/lon anchor point.

### generate

    public boolean generate(Projection proj)

  Use the current projection to place the graphics on the screen. Has to be called to at least assure the graphics that they are ready for rendering. Called when the graphic position changes.

  Specified by:
    `generate` in class `EditableOMGraphic`
  Parameters:
    `proj` - com.bbn.openmap.proj.Projection
  Returns:
    true

### regenerate

    public void regenerate(Projection proj)

  Given a new projection, the grab points may need to be repositioned off the current position of the graphic. Called when the projection changes.

  Specified by:
    `regenerate` in class `EditableOMGraphic`

### render

    public void render(java.awt.Graphics graphics)

  Draw the EditableOMPoly parts into the java.awt.Graphics object. The grab points are only rendered if the poly machine state is PolySelectedState.POLY_SELECTED.

  Specified by:
    `render` in class `EditableOMGraphic`
  Parameters:
    `graphics` - java.awt.Graphics.

### setGrabPoints

    public boolean setGrabPoints(GrabPoint[] points)

  Set the grab point objects within the EditableOMGraphic array. For the EditableOMPoly, with its variable number of GrabPoints, this just sets up a new list of all the grab points to look at. It's different than the polyGrabPoints, which are the grab points just on the polygon. This list includes the offset grab point. This method should be called when a new point gets added to the polygon, and should take an array of all the GrabPoints created. It will add the offsetGrabPoint to the end of the array.

  Overrides:
    `setGrabPoints` in class `EditableOMGraphic`
  Parameters:
    `points` - a GrabPoint[] for the points on the polygon.
  Returns:
    true if the grab point array was exactly what the EditableOMGraphic was expecting, in terms of length of the GrabPoint array length. The method copies the array values that fit into the resident array.

### getGrabPoints

    public GrabPoint[] getGrabPoints()

  Get the array of grab points used for the EditableOMGraphic. Creates the array by copying all the grab points out of the ArrayList, and tacking the offset grab point to the end.

  Overrides:
    `getGrabPoints` in class `EditableOMGraphic`

### setGrabPoint

    public boolean setGrabPoint(GrabPoint gb,
                                int index)

  Set the GrabPoint at a particule index of the array. This can be used to tie two different grab points together. This used to work with the gPoints array declared in EditableOMGraphic - no longer. If the index is -1, the offset grab point is set, and any other index refers to the concurrent polygon point.

  Overrides:
    `setGrabPoint` in class `EditableOMGraphic`
  Parameters:
    `gb` - GrabPoint to assign within array.
    `index` - the index of the array to put the GrabPoint. This index should be -1 for the offset grab point, or the index of the corner of the poly, in order starting from 0.
  Returns:
    If the grab point or array is null, or if the index is outside the range of the array, false is returned. If everything goes OK, then true is returned.

### whichGrabPoint

    public int whichGrabPoint(GrabPoint gp)

  Given a grab point, return its index into the polygon array. If its not in the array, the next available index is returned.

### getGrabPoint

    public GrabPoint getGrabPoint(int index)

  Return a particular GrabPoint at a particular point in the array. The EditableOMGraphic should describe which indexes refer to which grab points in the EOMG GrabPoint array. If the index is OFFSET_POINT_INDEX, the offset point is returned. If the index is otherwise outside the range of the array, null is returned.

  Overrides:
    `getGrabPoint` in class `EditableOMGraphic`

### getGUI

    public java.awt.Component getGUI(GraphicAttributes graphicAttributes)

  Adds widgets to modify polygon.

  Overrides:
    `getGUI` in class `EditableOMAbstractLine`
  Parameters:
    `graphicAttributes` - the GraphicAttributes to use to get the GUI widget from to control those parameters for this EOMG.
  Returns:
    Component to use to control parameters for this EOMG.

### enablePolygonButton

    public void enablePolygonButton(boolean enable)

### enablePolygonEditButtons

    public void enablePolygonEditButtons(boolean enable)

### getPolyGUI

    public javax.swing.JToolBar getPolyGUI()

### getPolyGUI

    public javax.swing.JToolBar getPolyGUI(boolean includeEnclose,
                                           boolean includeAdd,
                                           boolean includeDelete)

### getImageURL

    public java.net.URL getImageURL(java.lang.String imageName)

Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details