Package hec.map

Class MapCanvas

All Implemented Interfaces:
ComponentListener, ImageObserver, MenuContainer, Serializable, Runnable, EventListener, Accessible

public class MapCanvas extends JPanel implements ImageObserver, ComponentListener, Runnable
Geo-referenced drawing area for the MapPanel.

See Also:
  • Field Details

    • MAP_SCALE_FORMAT

      protected MessageFormat MAP_SCALE_FORMAT
      Description
    • m_mapScaleInformation

      protected String m_mapScaleInformation
      Description
    • _backgroundColor

      protected Color _backgroundColor
      the background color of the MapCanvas
    • _drawGrids

      protected boolean _drawGrids
      flag indicating whether grids are drawn or not.
    • USE_RENDER

      public static String USE_RENDER
    • useRenderer

      protected boolean useRenderer
  • Constructor Details

    • MapCanvas

      public MapCanvas(MapPanel parent)
      Create a new MapCanvas object

      Parameters:
      parent - Description
  • Method Details

    • setMouseAdapter

      public MapMouseAdapter setMouseAdapter(MapMouseAdapter adapter)
      Set the active mouse adapter for the canvas.

      Parameters:
      adapter - The new MouseAdapter value

      Returns:
      Description of the Returned Value

    • setCursor

      public void setCursor(Cursor cursor)
      Overrides:
      setCursor in class Component
    • getMouseAdapter

      public MapMouseAdapter getMouseAdapter()
      get the current MapMouseAdapter

      Returns:
      the current MapMouseAdapter or null if there isn't a selected MouseAdapter
    • getImageBuffer

      public Image getImageBuffer()
    • getBufferedGraphics

      public Graphics getBufferedGraphics()
      Returns the graphics context for the image buffer

      Returns:
      The BufferedGraphics value
    • getMapMouseAdapter

      public MapMouseAdapter getMapMouseAdapter()
      Gets the MapMouseAdapter attribute of the MapCanvas object

      Returns:
      The MapMouseAdapter value
    • getToolTipText

      public String getToolTipText(MouseEvent e)
      Gets the ToolTipText attribute of the MapCanvas object

      Overrides:
      getToolTipText in class JComponent
      Parameters:
      e - Description

      Returns:
      The ToolTipText value
    • addMapLegendItem

      public void addMapLegendItem(LegendItem item)
    • removeMapLegendItem

      public boolean removeMapLegendItem(LegendItem item)
    • addMapTextObject

      public void addMapTextObject(MapTextObject textobj)
      Adds a feature to the MapTextObject attribute of the MapCanvas object

      Parameters:
      textobj - The feature to be added to the MapTextObject attribute
    • addMapLabelItem

      public void addMapLabelItem(MapLabelItem newlabel)
      adds a label to the labelitem set

      Parameters:
      newlabel - The feature to be added to the MapLabelItem attribute
    • run

      public void run()
      Paints map from within a thread. This method implements run as required by the Runnable interface. When the paint is complete, the map panel is notified that it can forget about this thread.
      Specified by:
      run in interface Runnable
    • redrawMaps

      public void redrawMaps()
      Method Description
    • validateImage

      protected void validateImage()
      check to make sure we have a valid image. If we don't recreate the image.

      from VolatileImage JavaDoc's:
      The drawing surface of an image (the memory where the image contents actually reside) can be lost or invalidated, causing the contents of that memory to go away. The drawing surface thus needs to be restored or recreated and the contents of that surface need to be re-rendered.

    • paintComponent

      public void paintComponent(Graphics g)
      Overrides the default paint to call the paintMap function. This indirection is here to allow drawing to be skipped under some circumstances.

      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - Description of Parameter

      See Also:
    • paintComponentDefault

      public void paintComponentDefault(Graphics g)
    • drawLegendItems

      public void drawLegendItems(Graphics g, MapScale scale)
    • paintComponentThreaded

      public void paintComponentThreaded(Graphics g)
    • computeMapScale

      public double computeMapScale()
      Method Description

      Returns:
      Description
    • computeMapScale

      public static double computeMapScale(int localWidth, double worldViewWidth)
    • imageUpdate

      public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
      Method Description

      Specified by:
      imageUpdate in interface ImageObserver
      Overrides:
      imageUpdate in class Component
      Parameters:
      img - Description
      infoflags - Description
      x - Description
      y - Description
      width - Description
      height - Description

      Returns:
      Description
    • componentHidden

      public void componentHidden(ComponentEvent e)
      Method Description

      Specified by:
      componentHidden in interface ComponentListener
      Parameters:
      e - Description
    • componentMoved

      public void componentMoved(ComponentEvent e)
      Method Description

      Specified by:
      componentMoved in interface ComponentListener
      Parameters:
      e - Description
    • componentResized

      public void componentResized(ComponentEvent e)
      Method Description

      Specified by:
      componentResized in interface ComponentListener
      Parameters:
      e - Description
    • createImageBuffer

      public Image createImageBuffer()
      Creates a new Image Buffer that will be the "double" buffere for this canvas. If the size of this component is (0,0) then the Image Buffer will be NULL
    • componentShown

      public void componentShown(ComponentEvent e)
      Method Description

      Specified by:
      componentShown in interface ComponentListener
      Parameters:
      e - Description
    • paintCoordinateGrid

      public void paintCoordinateGrid(Graphics bg, MapScale scale)
      Method Description

      Parameters:
      bg - Description
      scale - Description
    • stop

      public void stop()
      Method Description
    • paintMap

      protected void paintMap(Graphics g)
      Draws the map to the specified graphics context.

      Parameters:
      g - Description of Parameter
    • repaint

      public void repaint()
      Overrides:
      repaint in class Component
    • paintMapDefault

      protected void paintMapDefault(Graphics g)
    • paintGlyphs

      public void paintGlyphs(Graphics g, Image imageBuffer)
    • paintGlyph

      public void paintGlyph(MapGlyph glyph, int i, int mapScale, Graphics bg, MapScale scale)
    • paintMapBorders

      public void paintMapBorders(MapGlyph glyph, MapScale scale, Graphics bg)
    • drawMapLabels

      public void drawMapLabels(Graphics bg)
    • setBackgroundColor

      public void setBackgroundColor(Color color)
      setBackgroundColor Set the color to be used as the background for the canvas. By default, this is white

      Parameters:
      color - The new background color
    • getBackgroundColor

      public Color getBackgroundColor()
      getBackgroundColor Get the color to be used as the background for the canvas.

      Returns:
      The background color
    • setDrawGrids

      public void setDrawGrids(boolean drawGrids)
      setDrawGrids Sets whether grids should be drawn on the canvas

      Parameters:
      drawGrids - True to draw grids, false to omit grids.
    • getDrawGrids

      public boolean getDrawGrids()
      getDrawGrids Gets whether grids should be drawn on the canvas

      Returns:
      True if grids are to be drawn, false otherwise.