Class AdvancedMeasureTool

All Implemented Interfaces:
CursorTool, ActionListener, MouseListener, MouseMotionListener, EventListener

public class AdvancedMeasureTool extends PolygonTool implements ActionListener
A tool for measurment of distance or area.
Version:
0.1
Author:
Matthias Scholz <ms@jammerhund.de>
  • Field Details

    • MEASURE_MODE_DISTANCE

      public static final int MEASURE_MODE_DISTANCE
      Measure mode distance.
      See Also:
    • MEASURE_MODE_AREA

      public static final int MEASURE_MODE_AREA
      Measure mode area.
      See Also:
  • Constructor Details

    • AdvancedMeasureTool

      public AdvancedMeasureTool(WorkbenchContext context)
      Build a new AdvancedMeasureTool instance.
      Parameters:
      context - the workbench context
  • Method Details

    • getIcon

      public Icon getIcon()
      Returns the Icon depending on the measureMode.
      Specified by:
      getIcon in interface CursorTool
      Returns:
      null to use a default icon
    • getCursor

      public Cursor getCursor()
      Returns the Cursor depending on the measureMode.
      Specified by:
      getCursor in interface CursorTool
      Overrides:
      getCursor in class AbstractCursorTool
      Returns:
      the Cursor
    • mouseLocationChanged

      public void mouseLocationChanged(MouseEvent e)
      Handle mouse location changes.
      Overrides:
      mouseLocationChanged in class MultiClickTool
      Parameters:
      e - a MouseEvent
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Clickhandler for the measuretool. If the user starts a new measure with a sinle click, then all old mesurements (features on the mesure layer) will be deleted. But if the user starts with a double click, then this measuremt will be added! Because of the event behaviour during a double click, this code is a little bit tricky. During a double click you get first a single click (getClickCount()=1) and after them the double click (getClickCount()=2). So we must check after the first click if later comes the double click. This is done by a Timer. The maximum time to detect a double click we can get through the desktop property "awt.multiClickInterval". Second is the overridden method MultiClickTool.isFinishingRelease() important.
      Specified by:
      mouseClicked in interface MouseListener
      Overrides:
      mouseClicked in class AbstractCursorTool
      Parameters:
      e - a MouseEvent
    • isFinishingRelease

      protected boolean isFinishingRelease(MouseEvent e)
      For the possibility to start a gesture (measurement) with a double click, only finish, if we have more then one click previously done (coordinates > 1). See mouseClicked() method.
      Overrides:
      isFinishingRelease in class MultiClickTool
      Parameters:
      e - a MouseEvent
      Returns:
      true if double clicked and more the one click
    • gestureFinished

      protected void gestureFinished() throws NoninvertibleTransformException
      Gesture is finished, now do the work, paint the measurement.
      Specified by:
      gestureFinished in class AbstractCursorTool
      Throws:
      NoninvertibleTransformException
    • getPopupMenu

      public JPopupMenu getPopupMenu()
      Returns the popup menu for this tool.
      Returns:
      the popup menu
    • getToolbarButton

      public JToggleButton getToolbarButton()
      Returns the toolbar button for this tool.
      Returns:
      the toolbarButton
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      ActionListener for the JMenuItems. We must set the Icon, the TooltipText, Cursor and the CloseRing Mode. Second the tool will be activated through a JMenuItem ActionEvent. So you do not need a second click ;-)
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      e - an ActionEvent