Class DrawLayer

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
com.bbn.openmap.Layer
org.ka2ddo.yaac.gui.drawlayer.DrawLayer
All Implemented Interfaces:
com.bbn.openmap.event.MapMouseListener, com.bbn.openmap.event.ProjectionListener, com.bbn.openmap.ProjectionPainter, com.bbn.openmap.PropertyConsumer, ActionListener, ComponentListener, KeyListener, ImageObserver, MenuContainer, BeanContextChild, BeanContextMembershipListener, Serializable, EventListener

public class DrawLayer extends com.bbn.openmap.Layer implements com.bbn.openmap.event.MapMouseListener, KeyListener, ComponentListener
This class implements an overlay on the OpenMap map panel that permits the user to draw arbitrary geometrical lines and objects, suitable for marking and highlighting areas of interest on the map. Note that these overlays are completely independent of the information drawn from the OpenStreetMap data sets and from received APRS stations and objects.
Author:
Andrew Pavlin, KA2DDO
See Also:
  • Field Details

    • DRAW_MOUSE_MODE_NAME

      public static final String DRAW_MOUSE_MODE_NAME
      Mouse mode name for this Layer.
      See Also:
  • Constructor Details

    • DrawLayer

      public DrawLayer(GeographicalMap geoMap, com.bbn.openmap.MouseDelegator mouseDelegator)
      Create a DrawLayer for the specified MouseDelegator.
      Parameters:
      geoMap - GeographicalMap containing this DrawLayer
      mouseDelegator - MouseDelegator indicating which mouse mode the MapBean will sendmouse data to this overlay
  • Method Details

    • registerMouseMode

      public void registerMouseMode(com.bbn.openmap.MouseDelegator mouseDelegator)
      Register the drawing mode of this layer with the MouseDelegator.
      Parameters:
      mouseDelegator - MouseDelegator handling distribution of mouse events to different map layers
    • getMapMouseListener

      public com.bbn.openmap.event.MapMouseListener getMapMouseListener()
      Get the listener to be informed of MapMouseEvents.
      Overrides:
      getMapMouseListener in class com.bbn.openmap.Layer
      Returns:
      MapMouseListener implementaion
    • getMouseModeServiceList

      public String[] getMouseModeServiceList()
      Get the MapBean mouse modes that this DrawLayer services.
      Specified by:
      getMouseModeServiceList in interface com.bbn.openmap.event.MapMouseListener
      Returns:
      an array of the mouse modes serviced
    • getLineColor

      public Color getLineColor()
      Get the current color selected for drawing lines.
      Returns:
      drawing Color
    • setLineColor

      public void setLineColor(Color lineColor)
      Set the RGB Color for drawing the currently edited shape in the DrawLayer.
      Parameters:
      lineColor - Color to drw the current shape with
    • getTransparency

      public int getTransparency()
      Get the current transparency (alpha) value for drawing the current shape.
      Returns:
      the int transparency value from 0 (completely transparent and invisible) to 255 (completely opaque)
    • setTransparency

      public void setTransparency(int transparency)
      Set the current transparency (alpha) value for drawing the current shape.
      Parameters:
      transparency - the int transparency value from 0 (completely transparent and invisible) to 255 (completely opaque)
    • mousePressed

      public boolean mousePressed(MouseEvent mouseEvent)
      Specified by:
      mousePressed in interface com.bbn.openmap.event.MapMouseListener
    • mouseReleased

      public boolean mouseReleased(MouseEvent mouseEvent)
      Specified by:
      mouseReleased in interface com.bbn.openmap.event.MapMouseListener
    • mouseClicked

      public boolean mouseClicked(MouseEvent mouseEvent)
      Specified by:
      mouseClicked in interface com.bbn.openmap.event.MapMouseListener
    • mouseEntered

      public void mouseEntered(MouseEvent mouseEvent)
      Specified by:
      mouseEntered in interface com.bbn.openmap.event.MapMouseListener
    • mouseExited

      public void mouseExited(MouseEvent mouseEvent)
      Specified by:
      mouseExited in interface com.bbn.openmap.event.MapMouseListener
    • mouseDragged

      public boolean mouseDragged(MouseEvent mouseEvent)
      Specified by:
      mouseDragged in interface com.bbn.openmap.event.MapMouseListener
    • mouseMoved

      public boolean mouseMoved(MouseEvent mouseEvent)
      Specified by:
      mouseMoved in interface com.bbn.openmap.event.MapMouseListener
    • mouseMoved

      public void mouseMoved()
      Specified by:
      mouseMoved in interface com.bbn.openmap.event.MapMouseListener
    • keyPressed

      public void keyPressed(KeyEvent e)
      Invoked when a key has been pressed. See the class description for KeyEvent for a definition of a key pressed event.
      Specified by:
      keyPressed in interface KeyListener
    • keyTyped

      public void keyTyped(KeyEvent e)
      Invoked when a key has been typed. See the class description for KeyEvent for a definition of a key typed event.
      Specified by:
      keyTyped in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent e)
      Invoked when a key has been released. See the class description for KeyEvent for a definition of a key released event.
      Specified by:
      keyReleased in interface KeyListener
    • componentHidden

      public void componentHidden(ComponentEvent e)
      Invoked when the component has been made invisible.
      Specified by:
      componentHidden in interface ComponentListener
    • componentResized

      public void componentResized(ComponentEvent e)
      Invoked when the component's size changes.
      Specified by:
      componentResized in interface ComponentListener
    • componentMoved

      public void componentMoved(ComponentEvent e)
      Invoked when the component's position changes.
      Specified by:
      componentMoved in interface ComponentListener
    • componentShown

      public void componentShown(ComponentEvent e)
      Invoked when the component has been made visible.
      Specified by:
      componentShown in interface ComponentListener
    • projectionChanged

      public void projectionChanged(com.bbn.openmap.event.ProjectionEvent projectionEvent)
      Invoked when there has been a fundamental change to the Map.

      Layers are expected to recompute their graphics (if this makes sense), and then repaint() themselves.

      Specified by:
      projectionChanged in interface com.bbn.openmap.event.ProjectionListener
      Parameters:
      projectionEvent - ProjectionEvent
    • paint

      public void paint(Graphics g)
      Render this layer's content into the MapBean. Note that we reproject on every draw to deal with map pans/zooms/resizes.
      Overrides:
      paint in class JComponent
      Parameters:
      g - Graphics object to use for rendering
    • clearSelectedDrawable

      public void clearSelectedDrawable()
      Unselects any drawable in the DrawLayer that was selected by the SELECT mode.
    • getMode

      public DrawMode getMode()
      Get the current drawing mode of the DrawLayer.
      Returns:
      current DrawMode
    • setMode

      public void setMode(DrawMode mode)
      Set the current drawing mode of the DrawLayer.
      Parameters:
      mode - DrawMode to use
    • addDrawable

      public void addDrawable(AbstractDrawable drawable)
      Add another drawable to the draw layer.
      Parameters:
      drawable - AbstractDrawable instance to add
    • setStroke

      public void setStroke(BasicStroke s, String strokeType)
      Set the line stroke type to be used for the currently edited shape.
      Parameters:
      s - BasicStroke of the object
      strokeType - name of the generic stroke type
    • setLineWidth

      public void setLineWidth(float width)
      Set the width (in pixels) for the line drawing the current shape.
      Parameters:
      width - int width in pixels
    • getlineStroke1Pixel

      public BasicStroke getlineStroke1Pixel()
      Get the one-pixel wide style of the line stroke.
      Returns:
      BasicStroke
    • getLineStrokeType

      public String getLineStrokeType()
      Get the descriptive name of the current line stroke type.
      Returns:
      stroke type name String
    • getLineWidth

      public float getLineWidth()
      Get the width (in pixels) for the line drawing the current shape.
      Returns:
      int width in pixels
    • save

      public void save(DataOutput dos) throws IOException
      Write the current set of drawn shapes to a save file in binary format.
      Parameters:
      dos - DataOutput object to write the shapes to
      Throws:
      IOException - if write fails for any reason
    • saveCSV

      public void saveCSV(PrintStream ps, boolean lonBeforeLat)
      Save all the polylines in the DrawLayer in a CSV file of longitude and latitude tuples (altitude is always reported as zero).
      Parameters:
      ps - PrintStream to write the CSV records to
      lonBeforeLat - ignored
    • saveKML

      public void saveKML(PrintStream ps)
      Save all the polylines currently in the DrawLayer as a KML file.
      Parameters:
      ps - PrintStream to write the XML data to
    • load

      public void load(DataInput din) throws IOException
      Read one drawable shape from a binary file.
      Parameters:
      din - DataInput to read the shapes from
      Throws:
      IOException - if read fails for any reason
    • loadCSV

      public void loadCSV(DataInput din, boolean latBeforeLon) throws IOException
      Load a polyline from a CSV file (one vertex per line), using the current stroke and color settings.
      Parameters:
      din - DataInput to read the CSV records from
      latBeforeLon - boolean true if latitude is before longitude in the CSV record, false if longitude before latitude
      Throws:
      IOException - if read fails for any reason other than end-of-file
    • loadGPX

      public void loadGPX(InputStream din) throws IOException
      Load a polyline from a GPX file.
      Parameters:
      din - DataInput of the GPX file
      Throws:
      IOException - if the file could not be read for any reason
    • loadKML

      public void loadKML(InputStream din) throws IOException
      Read polylines from a KML file.
      Parameters:
      din - DataInput of the KML file
      Throws:
      IOException - if file cannot be read for any reason
    • addGraphicList

      public void addGraphicList(com.bbn.openmap.omGraphics.OMGraphicList gl)
      load a list of OMGraphic objects into the DrawLayer.
      Parameters:
      gl - OMGraphicList
    • loadDrawing

      public void loadDrawing()
      Load drawing overlay.
    • saveDrawing

      public void saveDrawing()
      Save drawing overlay.