public abstract class Tool
extends java.lang.Object
public void onToolReleased(MouseEvent e)
{
Layer layer;
K2DElement elem = null;
// Obtain an array of layers to cycle through them in reverse order (from top to bottom)
Layer layers[] = view.getLayerManager().getProjectLayers();
// Transform the event DC coordinate to a WC coordinate
int xDC = e.getX();
int yDC = e.getY();
K2DCoord WCCoord = view.getTransform().transformInv(new Point.Float(xDC, yDC));
// Cycle through every layer looking for an element under the WC coordinate
for (int i=layers.length-1; i>=0; i--)
{
layer = layers[i];
// Layer should be visible and displayed at the current scale
if (!layer.getVisible() || !layer.isDrawable(view.getZoomLevel()))
continue;
elem = layer.getElementAtPoint(WCCoord, mainView, true);
if (elem != null)
{
// do something useful with the element
break;
}
}
}
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
autoPan |
protected java.awt.Cursor |
cursor |
protected View |
view |
| Constructor and Description |
|---|
Tool() |
| Modifier and Type | Method and Description |
|---|---|
java.awt.Cursor |
getCursor()
Gets the cursor to be used on the view when this tool is active.
|
View |
getView()
This method gets the View instance associated with the tool
|
void |
init(View view)
This method is called by the view when this tool becomes the current active
tool of the view.
|
boolean |
isAutoPan() |
void |
onToolClicked(java.awt.event.MouseEvent e)
This method is called by the view (View instance) after mouse clicked events generated by the user.
|
void |
onToolDragged(java.awt.event.MouseEvent e)
This method is called by the view (View instance) after mouse dragged events generated by the user.
|
void |
onToolMoved(java.awt.event.MouseEvent e)
This method is called by the view (View instance) after mouse moved events generated by the user.
|
void |
onToolPressed(java.awt.event.MouseEvent e)
This method is called by the view (View instance) after mouse pressed events generated by the user.
|
void |
onToolReleased(java.awt.event.MouseEvent e)
This method is called by the view (View instance) after mouse released events generated by the user.
|
void |
setAutoPan(boolean autoPan)
Determines if the tool supports auto pan (automatic panning when mouse cursor is close to view sides)
|
void |
terminate()
This method is called by the view when this tool is replaced as the current
active tool of the view.
|
protected Point |
toWCPoint(java.awt.event.MouseEvent e)
Utility method that returns a point in WC from the specifies mouse event.
|
protected java.awt.Cursor cursor
protected View view
protected boolean autoPan
public void init(View view)
view - view instance associated with the toolpublic void terminate()
public java.awt.Cursor getCursor()
Cursorpublic void onToolReleased(java.awt.event.MouseEvent e)
e - the corresponding mouse event.public void onToolDragged(java.awt.event.MouseEvent e)
e - the corresponding mouse event.public void onToolPressed(java.awt.event.MouseEvent e)
e - the corresponding mouse event.public void onToolMoved(java.awt.event.MouseEvent e)
e - the corresponding mouse event.public void onToolClicked(java.awt.event.MouseEvent e)
e - the corresponding mouse event.public View getView()
public boolean isAutoPan()
public void setAutoPan(boolean autoPan)
autoPan - the automatic pan status to useprotected Point toWCPoint(java.awt.event.MouseEvent e)
e - the mouse event