public class SelectionManager extends Object implements MouseListener, MouseMotionListener, PropertyChangeListener
Modifier and Type | Class and Description |
---|---|
static interface |
SelectionManager.SelectionEnded
This is the interface that an user of SelectionManager has to implement
to get informed when a selection closes.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
aspectRatio
Whether the selection rectangle must obtain the aspect ratio of the
drawComponent.
|
private Polygon |
lasso |
private boolean |
lassoMode |
private Point |
mousePos
Position of the map when the selection rectangle was last drawn.
|
private Point |
mousePosStart
Position of the map when the mouse button was pressed.
|
private NavigatableComponent |
nc
The Component, the selection rectangle is drawn onto.
|
private SelectionManager.SelectionEnded |
selectionEndedListener
The listener that receives the events after left mouse button is released.
|
Constructor and Description |
---|
SelectionManager(SelectionManager.SelectionEnded selectionEndedListener,
boolean aspectRatio,
NavigatableComponent navComp)
Create a new SelectionManager.
|
Modifier and Type | Method and Description |
---|---|
Collection<OsmPrimitive> |
getSelectedObjects(boolean alt)
Return a list of all objects in the selection, respecting the different
modifier.
|
private Rectangle |
getSelectionRectangle()
Calculate and return the current selection rectangle
|
void |
mouseClicked(MouseEvent e) |
void |
mouseDragged(MouseEvent e)
If the correct button is hold, draw the rectangle.
|
void |
mouseEntered(MouseEvent e) |
void |
mouseExited(MouseEvent e) |
void |
mouseMoved(MouseEvent e) |
void |
mousePressed(MouseEvent e)
If the correct button, from the "drawing rectangle" mode
|
void |
mouseReleased(MouseEvent e)
Check the state of the keys and buttons and set the selection accordingly.
|
private void |
paintLasso() |
private void |
paintRect()
Draws a selection rectangle on screen.
|
void |
propertyChange(PropertyChangeEvent evt)
If the action goes inactive, remove the selection rectangle from screen
|
private Polygon |
rectToPolygon(Rectangle r) |
void |
register(NavigatableComponent eventSource,
boolean lassoMode)
Register itself at the given event source.
|
void |
setLassoMode(boolean lassoMode)
Enables or disables the lasso mode.
|
void |
unregister(Component eventSource)
Unregister itself from the given event source.
|
private final SelectionManager.SelectionEnded selectionEndedListener
private Point mousePosStart
null
, a rectangle is drawn on screen.private final NavigatableComponent nc
private boolean aspectRatio
private boolean lassoMode
public SelectionManager(SelectionManager.SelectionEnded selectionEndedListener, boolean aspectRatio, NavigatableComponent navComp)
selectionEndedListener
- The action listener that receives the event when
the left button is released.aspectRatio
- If true, the selection window must obtain the aspect
ratio of the drawComponent.navComp
- The component, the rectangle is drawn onto.public void register(NavigatableComponent eventSource, boolean lassoMode)
eventSource
- The emitter of the mouse events.lassoMode
- true
to enable lasso mode, false
to disable it.public void unregister(Component eventSource)
eventSource
- The emitter of the mouse events.public void mousePressed(MouseEvent e)
mousePressed
in interface MouseListener
public void mouseDragged(MouseEvent e)
mouseDragged
in interface MouseMotionListener
public void mouseReleased(MouseEvent e)
mouseReleased
in interface MouseListener
private void paintRect()
private void paintLasso()
private Rectangle getSelectionRectangle()
public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener
public Collection<OsmPrimitive> getSelectedObjects(boolean alt)
alt
- Whether the alt key was pressed, which means select all
objects that are touched, instead those which are completely covered.private Polygon rectToPolygon(Rectangle r)
public void setLassoMode(boolean lassoMode)
lassoMode
- true
to enable lasso mode, false
to disable it.public void mouseClicked(MouseEvent e)
mouseClicked
in interface MouseListener
public void mouseEntered(MouseEvent e)
mouseEntered
in interface MouseListener
public void mouseExited(MouseEvent e)
mouseExited
in interface MouseListener
public void mouseMoved(MouseEvent e)
mouseMoved
in interface MouseMotionListener