Class View

All Implemented Interfaces:
JMapEventDispatcher, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
OverView, ViewMagnifier

public class View extends JComponent implements JMapEventDispatcher
See Also:
  • Field Details

  • Constructor Details

    • View

      public View(LayerManager layerMgr, ViewSettings settings)
      Constructs a new View object associated with the specified LayerManager. The specified view settings are applied to the view.
      Parameters:
      layerMgr - the associated LayerManager
      settings - the settings to be applied to the view
      See Also:
  • Method Details

    • initEventDispatcher

      protected ViewEventDispatcher initEventDispatcher()
    • close

      public void close()
      Frees resources used by the view. Should be called when the view is no longer needed.
    • createOffImage

      protected boolean createOffImage()
    • paint

      public void paint(Graphics g)
      Paint on the graphic
      Overrides:
      paint in class JComponent
      Parameters:
      g - the corresponding Graphic instance
    • addPopupMenuItem

      public void addPopupMenuItem(JMenuItem menuItem)
      Adds a menu item to the view contextual menu.
      Parameters:
      menuItem - the JMenuItem to add
    • addPopupMenuSeparator

      public void addPopupMenuSeparator()
      Adds separator to the view contextual menu.
    • getCurrentTool

      public Tool getCurrentTool()
      Returns the current active tool of the view. Can be null if no tool is active.
      Returns:
      the current active tool
    • addPopupMenuAction

      public JMenuItem addPopupMenuAction(Action menuItemAction)
      Adds an action to the view contextual menu. A JMenuItem is created with the action. This menu item is returned.
      Parameters:
      menuItemAction - the action to add
      Returns:
      the menu item created with the action
    • removePopupMenuItem

      public void removePopupMenuItem(JMenuItem menuItem)
      Removes a menu item from the view contextual menu.
      Parameters:
      menuItem - the menu item to remove
    • removePopupMenuAction

      public void removePopupMenuAction(Action menuItemAction)
      Removes an action from the view contextual menu.
      Parameters:
      menuItemAction - the action to remove
    • getMouseOverManager

      public MouseOverManager getMouseOverManager()
      Return the MouseOverManager for this view.
      Returns:
      the mouseOverManager
    • setBounds

      public void setBounds(int x, int y, int width, int height)
      Sets the view bounds.
      Overrides:
      setBounds in class Component
      Parameters:
      x - the new x-coordinate of this view.
      y - the new y-coordinate of this view.
      width - the new width of this view.
      height - the new height of this view.
      See Also:
    • getViewOverlay

      public ViewOverlay getViewOverlay()
      Returns the ViewOverlay associated with this view
      Returns:
      ViewOverlay
    • draw

      protected void draw(K2DTransform t, OrientedRectangle wcRegion, int drawOptions)
    • draw

      protected void draw(K2DTransform t, OrientedRectangle wcRegion, Rectangle dcRegion, int drawOptions, boolean updateViewGraphics)
    • drawVolatileElement

      @Deprecated public void drawVolatileElement(K2DElement element, VectorLayer vectorLayer, Graphics g)
      Deprecated.
      use viewOverlay.drawVolatileElement(element, layer);
      This method draws a volatile element while erasing the previous volatile element drawn by this method. Passing null as argument restores the screen with the offImage (clears volatile drawings). resetVolatileImageLastBounds() resets the last element's bound (useful if the user calls redraw and there is no portion of the screen to restore)
      Parameters:
      element - element that need to be drawn on the screen
      g - graphics instance. Not used anymore.
      layer - the layer that contains the element.
    • drawVolatileElements

      @Deprecated public void drawVolatileElements(K2DElement[] elements, VectorLayer vectorLayer, Rectangle userBoundingBoxDc, Graphics g)
      Deprecated.
      use viewOverlay.drawVolatileElement(element, layer);
      this method draws the specified elements in a volatile fashion on the screen while restoring the specified region from the offimage.
      Parameters:
      elements - array of K2DElements elements that need to be drawn on the screen
      vectorLayer - the layer that contains the array of elements.
      userBoundingBoxDc - Additional region in DC which needs to be restored. Not used anymore.
      g - graphics instance. Not used anymore.
    • resetVolatileImageLastBounds

      @Deprecated public void resetVolatileImageLastBounds()
      Deprecated.
      Is of no use anymore.
      Resets the last drawn bounds for the method
    • drawVolatileElements

      @Deprecated public void drawVolatileElements(K2DElement[] elements, VectorLayer vectorLayer, Graphics g)
      Deprecated.
      use viewOverlay.drawVolatileElement(element, layer);
      This method draws a volatile elements while each call of this method erases the previous volatile elements drawn by this method. At the end, either drawVolatileElement(null) should be called to restore the view or resetVolatileImageLastBounds() should be called if the user has manually restored it (called redraw, refresh, etc..)
      Parameters:
      elements - array of K2DStyledElements elements that need to be drawn on the screen
      vectorLayer - the layer that contains the array of elements.
      g - the graphics instance. Not used anymore.
    • setCurrentTool

      public void setCurrentTool(Tool tool)
      Sets the active Tool object for this view.
      Parameters:
      tool - the new current active tool of the view
    • dispatchEvent

      public void dispatchEvent(JMapEvent event)
      The dispatchEvent method is used to dispatch synchronously JMap events to all registered listeners. The main use of the JMapEventDispatcher interface is to dispatch events that were previously added to the JMap event queue.
      Note: only ViewEvent will be accepted by this method. Any other JMap event types will cause the view to throw an exception.
      Specified by:
      dispatchEvent in interface JMapEventDispatcher
      Parameters:
      event - the event to be dispatched.
      Throws:
      IllegalArgumentException - will be thrown if the JMapEvent instance is no an instance of the ViewEvent class.
      See Also:
    • fireToolChangedEvent

      protected void fireToolChangedEvent(Tool oldTool, Tool newTool)
    • firePopupMenuShowingEvent

      protected void firePopupMenuShowingEvent(MouseEvent mouseEvent)
    • this_mousePressed

      protected void this_mousePressed(MouseEvent e)
      Event handler for mouse down events.
      Parameters:
      e - the mouse event.
    • this_mouseReleased

      protected void this_mouseReleased(MouseEvent e)
      Event handler for mouse up events.
      Parameters:
      e - the mouse event.
    • this_mouseMoved

      protected void this_mouseMoved(MouseEvent e)
      Event handler for mouse move events.
      Parameters:
      e - the mouse event.
    • this_mouseClicked

      protected void this_mouseClicked(MouseEvent e)
      Event handler for mouse click events.
      Parameters:
      e - the mouse event.
    • this_mouseDragged

      protected void this_mouseDragged(MouseEvent e)
      Event handler for mouse drag events.
      Parameters:
      e - the mouse event.
    • isBusy

      public boolean isBusy()
      Indicates if the View is currently busy repainting.
      Returns:
      true if the drawing thread is repainting
    • this_mouseEntered

      protected void this_mouseEntered(MouseEvent e)
    • this_mouseExited

      protected void this_mouseExited(MouseEvent e)
    • isMouseInside

      public boolean isMouseInside()
      Determines if the mouse cursor is inside the view.
      Returns:
      true if mouse cursor is inside the view
    • panSmooth

      public void panSmooth(int xDC, int yDC)
      This method will pan the view and dynamically update the view to reflect the translation.
      Parameters:
      xDC - the translation in x expressed in DC coordinates
      yDC - the translation in y expressed in DC coordinates
      See Also:
    • panSmooth

      public void panSmooth(int xDC, int yDC, boolean redrawLabels)
      This method will pan the view and dynamically update the view to reflect the translation. When this method is used, fireViewChanged() should be called manually.
      Parameters:
      xDC - the translation in x expressed in DC coordinates
      yDC - the translation in y expressed in DC coordinates
      redrawLabels - if this should also redraw the labels
      See Also:
    • redraw

      public void redraw(OrientedRectangle wcRegion)
      Redraws the current view using all layers.
      Parameters:
      wcRegion - the region to redraw.
    • redraw

      public void redraw(OrientedRectangle WCRegion, int drawOptions)
      Redraws the current view using the specified draw options.
      Parameters:
      WCRegion - the region to redraw.
      drawOptions - a bit field value that specifies what to draw.
      See Also:
    • redraw

      public void redraw(OrientedRectangle WCRegion, int drawOptions, boolean stopDrawing)
      Redraws the current view using the specified draw options.
      Parameters:
      WCRegion - the region to redraw.
      drawOptions - a bit field value that specifies what to draw.
      stopDrawing - defines whether the drawing thread should be stopped drawing before redrawing the view. However, this flag has not effect on a synchronized redraw.
      See Also:
    • redraw

      public void redraw(OrientedRectangle wcRegion, int drawOptions, boolean stopDrawing, boolean updateViewGraphics)
      Redraws the current view using the specified draw options.
      Parameters:
      wcRegion - the region to redraw.
      drawOptions - a bit field value that specifies what to draw.
      stopDrawing - defines whether the drawing thread should be stopped drawing before redrawing the view. However, this flag has not effect on a synchronized redraw.
      updateViewGraphics - defines whether the redraw should update the view graphics (false will only affect the offImage)
    • refresh

      public void refresh()
      Redraws the complete view.
    • setLayerManager

      public void setLayerManager(LayerManager layerMgr)
      Sets the layer manager
      Parameters:
      layerMgr -
    • setViewName

      public void setViewName(String viewName)
      Sets the view name. IllegalArgumentException if viewName is null. A PropertyChangeEvent event is fired (propertyName : PROPERTY_VIEW_NAME).
      Parameters:
      viewName - the new name for this view
      See Also:
    • getViewName

      public String getViewName()
      Gets the view name.
      Returns:
      the name for this view
    • setRefreshable

      public void setRefreshable(boolean refreshable)
      Sets whether the view is refreshable.
      Parameters:
      refreshable - a boolean value that specifies whether the view is refreshable.
    • this_layerRefreshRequestEvent

      protected void this_layerRefreshRequestEvent()
      Handles layerRefreshrequestEvent Refreshes the layer
    • this_layerAddedEventOccurred

      protected void this_layerAddedEventOccurred(LayerAddedEvent e)
    • this_layerRemovedEventOccurred

      protected void this_layerRemovedEventOccurred(LayerRemovedEvent e)
    • this_layerStyleChangedEventOccurred

      protected void this_layerStyleChangedEventOccurred(LayerStyleChangedEvent e)
      Handles layer style change events.
      Parameters:
      e - the corresponding LayerStyleChangedEvent
    • this_layerPosChangedEventOccurred

      protected void this_layerPosChangedEventOccurred(LayerPosChangedEvent e)
      Handles layer position change events.
      Parameters:
      e -
    • this_layerReceivedDataEventOccurred

      protected void this_layerReceivedDataEventOccurred(LayerReceivedDataEvent e)
      Handles new data events.
      Parameters:
      e - the corresponding new data event
    • this_layerPropertyChangedEvent

      protected void this_layerPropertyChangedEvent(LayerPropertyChangedEvent e)
      Handler for LayerPropertyChangedEvent events.
      Parameters:
      e - the received event.
    • getViewGraphicsRef

      public GraphicsRef getViewGraphicsRef()
      Returns the GraphicsRef instance of the view.
      Returns:
      the GraphicsRef instance of the view.
    • getRenderer

      public ViewRenderer getRenderer()
      Returns the ViewRenderer instance which is used to render the map on the view.
      Returns:
      the ViewRenderer instance of the view.
    • fireViewRedrawOccurredEvent

      protected void fireViewRedrawOccurredEvent(ViewState viewState)
      Fires a ViewRedrawEvent.
      Parameters:
      viewState - parameters used to redraw the view.
    • fireViewRepaintOccurredEvent

      protected void fireViewRepaintOccurredEvent(Graphics g)
      Fires a ViewRedrawEvent.
      Parameters:
      g - the graphics instance used to paint the view.
    • addStaticElement

      public void addStaticElement(ViewStaticElement staticElem)
      Adds the specified static element to the list of elements that will be drawn in this view on top of geographic data. Static elements are displayed in the order they are added to a view.
      Parameters:
      staticElem - the static element to be added
      See Also:
    • addStaticImage

      @Deprecated public void addStaticImage(Image im, Point pt, int relativeTo)
      Deprecated.
      Use addStaticElement instead
      Adds the specified static image to the list of images that will be drawn in this view on top of geographic data. These images are positioned using the specified point and relatively to the corner of the view area specified by the relativeTo constant.
      Parameters:
      im - the image
      pt - the position of the image relative to the specified corner
      relativeTo - a constant from KStaticImage class used to specify the corner near which the image will be drawn
      See Also:
    • addViewEventListener

      public void addViewEventListener(ViewEventListener listener)
      Adds a listener to the list of view event listeners.
      Parameters:
      listener - the event listener to add
    • removeViewEventListener

      public void removeViewEventListener(ViewEventListener listener)
      Removes a listener from the list of view event listeners.
      Parameters:
      listener - the event listener to remove
    • applySettings

      public void applySettings(ViewSettings settings)
      Sets the settings for the view
      Parameters:
      settings - the ViewSettings instance containing the settings
      See Also:
    • drawStaticElements

      public void drawStaticElements(GraphicsRef gr, K2DTransform t, Rectangle viewBounds)
      Draws view static elements.
      Parameters:
      gr - the graphics instance wrapper to use.
      t - the view transformation matrix.
      viewBounds - the view bounds to draw.
    • fireViewChanged

      public void fireViewChanged()
    • getCenterOfView

      public Point getCenterOfView()
      Returns the coordinate of the center of the view in DC coordinates.
      Returns:
      the center of the view in DC coordinates
    • getDCViewBounds

      public Rectangle getDCViewBounds()
      Returns the coordinate of the center of the view in DC coordinates.
      Returns:
      the center of the view in DC coordinates
    • getDisplayUnit

      public JMapUnit getDisplayUnit()
      This method returns the Display unit. Note that depending on the scale the alternative Display unit might be used, so the use of the getCurrentDisplayUnit() method should be considered
      Returns:
      the main display unit for this view
    • getDistanceUnit

      public JMapUnit getDistanceUnit()
      Returns:
      the current distance unit for this view
    • getGraphicsManager

      public GraphicsManager getGraphicsManager()
      Returns the graphics manager of the current view. Useful for drawing synchronization.
      Returns:
      Returns the graphicsManager.
    • getInitialViewBounds

      public OrientedRectangle getInitialViewBounds()
      Gets the intial view bounds
      Returns:
      initialViewBounds
    • getLayerManager

      public LayerManager getLayerManager()
      Returns the LayerManager object associated with this view. active.
      Returns:
      the layer manager of the view
    • getMapProjection

      public Projection getMapProjection()
      Returns the current map data projection.
      Returns:
      the map data projection.
    • getMeasurementProjection

      public Projection getMeasurementProjection()
    • getMapUnit

      public JMapUnit getMapUnit()
      Returns the current map data unit.
      Returns:
      the current map data unit.
    • getMaxViewBounds

      public OrientedRectangle getMaxViewBounds()
      Returns the maximum bounds of this view
      Returns:
      maximum bounds of this view
    • getRotation

      public double getRotation()
      Returns the view rotation angle in degrees.
      Returns:
      the rotation angle
    • getScaleFactor

      public double getScaleFactor()
      Computes the view current scale factor denominator. The scale expresses the ratio between the size of the elements displayed on the screen and the real sizes in world coordinates.
      Returns:
      the view scale factor denominator as in (1 : denominator)
    • getScaleFactor

      public double getScaleFactor(double dcScale)
      Computes a scale factor denominator. The scale expresses the ratio between the size of the elements displayed on the screen and the real sizes in world coordinates.
      Parameters:
      dcScale - the ratio between DC and WC coordinates.
      Returns:
      the scale factor denominator as in (1 : denominator)
    • getStaticElements

      public ViewStaticElement[] getStaticElements()
      Returns view static elements added to this view.
      Returns:
      an array view static elements.
    • getTransform

      public K2DTransform getTransform()
      Returns the K2DTransform object associated with this view.
      Returns:
      the transformation of the view
    • getVerbose

      public boolean getVerbose()
      Returns the verbose mode for this view.
      Returns:
      the verbose mode.
    • getViewSettings

      public ViewSettings getViewSettings()
      Returns the current view settings.
      Returns:
      a ViewSettings instance with the current settings
    • getViewState

      public ViewState getViewState()
      Returns the current state of the view, including all parameters needed to restore the current state.
      Returns:
      the current state of the view.
    • getWCViewBounds

      public OrientedRectangle getWCViewBounds()
      Returns a Rectangle object representing the area of the view in WC.
      Returns:
      the area of the view in WC coordinates
    • getZoomLevel

      public double getZoomLevel()
      Gets the zoom level expressed in the current map units
      Returns:
      the zoom level
    • isRefreshable

      public boolean isRefreshable()
      Returns whether the view is refreshable.
      Returns:
      a boolean value that specifies whether the view is refreshable.
    • moveTo

      public void moveTo(Point coord)
      Makes the specified WC coordinate the new center of the view
      Parameters:
      coord - the new center WC coordinate of the view
    • moveTo

      public void moveTo(double x, double y)
      Makes the specified WC coordinate the new center of the view.
      Parameters:
      x - the new x value
      y - the new y value
    • pan

      public void pan(int xdc, int ydc)
      Adjusts the view in order to display a region that corresponds to the current region translated by xDC in x and yDC in y (in DC).
      Parameters:
      xdc - the translation in x expressed in DC coordinates
      ydc - the translation in y expressed in DC coordinates
    • removeStaticElement

      public void removeStaticElement(ViewStaticElement staticElem)
      Removes the specified static element from the list.
      Parameters:
      staticElem - the static element to be removed
      See Also:
    • setDisplayUnit

      public void setDisplayUnit(JMapUnit unit)
      Sets the unit to use when displaying coordinates. A PropertyChangeEvent event is fired (propertyName : PROPERTY_DISPLAY_UNIT).
      Parameters:
      unit - the main display unit to use on this view
      See Also:
    • setDistanceUnit

      public void setDistanceUnit(JMapUnit unit)
      Sets the unit to use when displaying distances. A PropertyChangeEvent event is fired (propertyName : PROPERTY_DISTANCE_UNIT).
      Parameters:
      unit - the distance unit to use on this view
      See Also:
    • setInitialViewBounds

      public void setInitialViewBounds(OrientedRectangle initialViewBounds)
      Sets the initial view bounds
      Parameters:
      initialViewBounds - The initial view bounds.
    • setMapUnit

      public void setMapUnit(JMapUnit unit)
      Sets the unit for this map. A PropertyChangeEvent event is fired (propertyName : PROPERTY_MAP_UNIT).
      Parameters:
      unit - the corresponding JMapUnit instance.
      See Also:
    • setMaxViewBounds

      public void setMaxViewBounds(OrientedRectangle maxBounds)
      Sets the maximum view bounds where the user will be able to zoom/pan
      Parameters:
      maxBounds -
    • setMaximumScale

      public void setMaximumScale(double scale)
      Sets the View object maximum scale. This value is automatically respected when zoom operations are executed on the view.
      Parameters:
      scale - the maximum scale
    • setRotation

      public void setRotation(double angle)
      Rotates the map to the specified angle in degrees. A PropertyChangeEvent event is fired (propertyName : PROPERTY_MAP_ROTATION).
      Parameters:
      angle - the absolute angle in degrees (0 means north is straight up)
      See Also:
    • setVerbose

      public void setVerbose(boolean verbose)
      Sets the verbose mode for this view.
      Parameters:
      verbose - The verbose mode
    • zoom

      public void zoom(double factor, Point WCPt)
      Zooms by the specified factor and around specified point. A zoom factor between 0 and 1 will result in a "zoom out" operation and a factor greater than 1 will result in a "zoom in" operation.
      Parameters:
      factor - the zooming factor
      WCPt - the center of the zoom operation in WC
    • zoom

      public void zoom(double factor)
      Zooms by the specified factor and around the center of the view. A zoom factor between 0 and 1 will result in a "zoom out" operation and a factor greater than 1 will result in a "zoom in" operation.
      Parameters:
      factor - the zooming factor
    • zoom

      public void zoom(Rectangle rect)
      Zooms to the specified WC region (rect). This method ensures that all the region specified by rect will be visible.
      Parameters:
      rect - the WC region to zoom to.
    • zoom

      public void zoom(OrientedRectangle rect)
      Zooms to the specified WC region (rect). This method ensures that all the region specified by rect will be visible.
      Parameters:
      rect - the WC region to zoom to.
    • zoomExtent

      public void zoomExtent()
      Adjusts the view in order to display every element of every visible layer managed by the associated LayerManager object.
    • setScale

      public void setScale(double scaleFactor)
      Sets the new scale of the view.
      Parameters:
      scaleFactor - the scale denominator (pass 1000 for a scale of 1 : 1000)
    • moveBackward

      public boolean moveBackward()
      Adjust the view in order to display the region that was displayed prior to the previous change in the view (similar to undo). Previous regions are maintained in a Stack object automatically.
      Returns:
      true if a previous region is available
    • moveForward

      public boolean moveForward()
      If moveBackward() was called, adjust the view in order to display the region that was displayed before the call to moveBackward() (similar to redo). Previous regions are maintained in a Stack object automatically.
      Returns:
      true if a following region is available
    • zoomToRect

      @Deprecated public void zoomToRect(OrientedRectangle rect)
      Deprecated.
      use zoom(OrientedRectangle) instead
      Zooms to the specified WC region (rect). This method ensures that all the region specified by rect will be visible.
      Parameters:
      rect - the region to zoom to.
    • addMarker

      public long addMarker(Point coord, String text, Style markerStyle)
      Adds a new marker to the view.
      Parameters:
      coord - The coordinate of the marker
      text - (Optional) the text of this marker, null if none
      markerStyle - (Optional) the style of this marker, null if none
      Returns:
      id of the marker added to the view
    • removeMarker

      public void removeMarker(long markerId)
      Removes the specified marker from this view
      Parameters:
      markerId - the id of the marker to remove
    • clearMarkers

      public void clearMarkers()
      Removes all the markers from this view
    • setScaleValidator

      public void setScaleValidator(ScaleValidator scaleValidator)
    • getScaleValidator

      public ScaleValidator getScaleValidator()
    • setLayerRefreshManagerView

      public void setLayerRefreshManagerView(LayerViewRefreshManager dynamicLayerManager)