org.openjump.core.ui.plugin.tools
Class AdvancedMeasureTool

java.lang.Object
  extended by com.vividsolutions.jump.workbench.ui.cursortool.AbstractCursorTool
      extended by com.vividsolutions.jump.workbench.ui.cursortool.MultiClickTool
          extended by com.vividsolutions.jump.workbench.ui.cursortool.PolygonTool
              extended by org.openjump.core.ui.plugin.tools.AdvancedMeasureTool
All Implemented Interfaces:
CursorTool, java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener

public class AdvancedMeasureTool
extends PolygonTool
implements java.awt.event.ActionListener

A tool for measurment of distance or area.

Version:
0.1
Author:
Matthias Scholz

Nested Class Summary
 
Nested classes/interfaces inherited from class com.vividsolutions.jump.workbench.ui.cursortool.AbstractCursorTool
AbstractCursorTool.Listener
 
Field Summary
static int MEASURE_MODE_AREA
          Measure mode area.
static int MEASURE_MODE_DISTANCE
          Measure mode distance.
 
Fields inherited from class com.vividsolutions.jump.workbench.ui.cursortool.AbstractCursorTool
isLinuxOS
 
Constructor Summary
AdvancedMeasureTool(WorkbenchContext context)
          Build a new AdvancedMeasureTool instance.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          ActionListener for the JMenuItems.
protected  void gestureFinished()
          Gesture is finished, now do the work, paint the measurement.
 java.awt.Cursor getCursor()
          Returns the Cursor depending on the measureMode.
 javax.swing.Icon getIcon()
          Returns the Icon depending on the measureMode.
 javax.swing.JPopupMenu getPopupMenu()
          Returns the popup menu for this tool.
 javax.swing.JToggleButton getToolbarButton()
          Returns the toolbar button for this tool.
protected  boolean isFinishingRelease(java.awt.event.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).
 void mouseClicked(java.awt.event.MouseEvent e)
          Clickhandler for the measuretool.
 void mouseLocationChanged(java.awt.event.MouseEvent e)
          Handle mouse location changes.
 
Methods inherited from class com.vividsolutions.jump.workbench.ui.cursortool.PolygonTool
checkPolygon, getPolygon
 
Methods inherited from class com.vividsolutions.jump.workbench.ui.cursortool.MultiClickTool
activate, add, cancelGesture, deactivate, finishGesture, getCoordinates, getMetrics, getShape, mouseDragged, mouseMoved, mousePressed, mouseReleased, setCloseRing, setMetricsDisplay, toArray
 
Methods inherited from class com.vividsolutions.jump.workbench.ui.cursortool.AbstractCursorTool
add, allowSnapping, check, cleanup, clearShape, createCursor, createCursor, createStandardSnappingPolicies, drawShapeXOR, drawShapeXOR, execute, fireGestureFinished, getColor, getName, getPanel, getSnapManager, getTaskFrame, getWorkbench, isGestureInProgress, isRightMouseButtonUsed, isRollingBackInvalidEdits, isShapeOnScreen, mouseEntered, mouseExited, name, redrawShape, reportNothingToUndoYet, setColor, setFilling, setStroke, setStrokeWidth, setup, snap, snap, toString, wasControlPressed, wasShiftPressed, workbench, workbenchFrame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MEASURE_MODE_DISTANCE

public static final int MEASURE_MODE_DISTANCE
Measure mode distance.

See Also:
Constant Field Values

MEASURE_MODE_AREA

public static final int MEASURE_MODE_AREA
Measure mode area.

See Also:
Constant Field Values
Constructor Detail

AdvancedMeasureTool

public AdvancedMeasureTool(WorkbenchContext context)
Build a new AdvancedMeasureTool instance.

Parameters:
context -
Method Detail

getIcon

public javax.swing.Icon getIcon()
Returns the Icon depending on the measureMode.

Specified by:
getIcon in interface CursorTool
Returns:
null to use a default icon

getCursor

public java.awt.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(java.awt.event.MouseEvent e)
Handle mouse location changes.

Overrides:
mouseLocationChanged in class MultiClickTool
Parameters:
e -

mouseClicked

public void mouseClicked(java.awt.event.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 java.awt.event.MouseListener
Overrides:
mouseClicked in class AbstractCursorTool
Parameters:
e -

isFinishingRelease

protected boolean isFinishingRelease(java.awt.event.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 -
Returns:
true if double clicked and more the one click

gestureFinished

protected void gestureFinished()
                        throws java.awt.geom.NoninvertibleTransformException
Gesture is finished, now do the work, paint the measurement.

Specified by:
gestureFinished in class AbstractCursorTool
Throws:
java.awt.geom.NoninvertibleTransformException

getPopupMenu

public javax.swing.JPopupMenu getPopupMenu()
Returns the popup menu for this tool.

Returns:
the popup menu

getToolbarButton

public javax.swing.JToggleButton getToolbarButton()
Returns the toolbar button for this tool.

Returns:
the toolbarButton

actionPerformed

public void actionPerformed(java.awt.event.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 java.awt.event.ActionListener
Parameters:
e -