org.omegahat.Graphics.Plots.Examples.Events
Class SelectionTracker

java.lang.Object
  |
  +--org.omegahat.Graphics.Plots.Examples.Events.SelectionTracker
All Implemented Interfaces:
java.util.EventListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

public class SelectionTracker
extends java.lang.Object
implements java.awt.event.MouseMotionListener, java.awt.event.MouseListener

Example of how we listen to graphics device events and identify the graphical components identified by those events, supporting either clicking on a point or brushing a region. The simple click identifies the component at the pointer for the click javax.swing.event. The brushing provides a rubber-band rectangle while the dragging is occurring. Terminiating the drag calls the getSelected() method which currently returns an array containing


Field Summary
protected  java.awt.Graphics gc
          Graphics context used in the drawing of the rubber band.
protected  boolean justClicks
          Indicates whether we are interested in click or brushing/dragging event.
protected  javax.swing.ListSelectionModel selectionModel
           
protected  int x0
          The starting location in pixels (RDC) of the latest rubber-banding.
protected  int x1
          The other location of the rubber-banding rectangle.
protected  int y0
          The starting location in pixels (RDC) of the latest rubber-banding.
protected  int y1
          The other location of the rubber-banding rectangle.
 
Constructor Summary
SelectionTracker(java.awt.Component comp)
           
SelectionTracker(java.awt.Component comp, boolean justClicks)
           
 
Method Summary
 int[] getSelected(int x0, int y0, int x1, int y1, GraphicalContainerInt top, java.awt.Rectangle bounds)
          Current method for identifying the graphical components in the graphical container that are in the rectangle identified by the device coordinates x0, y0, x1, y1.
 javax.swing.ListSelectionModel getSelectionModel()
          Accessor for selectionModel field
 GraphicalComponentInt identify(java.awt.event.MouseEvent ev)
          Identify the graphical component in the data region of the plot in the AWT component reporting the mouse event.
 void mouseClicked(java.awt.event.MouseEvent e)
          If we are just interested in clicks, this is called when there is a simple mouse click (not drag and release) and then we determine which graphical component data region of interest has been selected by this point.
 void mouseDragged(java.awt.event.MouseEvent e)
          Triggered when the mouse is dragged in the device of interest, causing us to move the rubber banding rectangle and update its position.
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
          Need to implement this, but not interested in simple motion - only drags.
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent ev)
           
 javax.swing.ListSelectionModel setSelectionModel(javax.swing.ListSelectionModel value)
          Accessor for setting selectionModel field
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

justClicks

protected boolean justClicks
Indicates whether we are interested in click or brushing/dragging event.

gc

protected java.awt.Graphics gc
Graphics context used in the drawing of the rubber band.

x0

protected int x0
The starting location in pixels (RDC) of the latest rubber-banding.

y0

protected int y0
The starting location in pixels (RDC) of the latest rubber-banding.

x1

protected int x1
The other location of the rubber-banding rectangle.

y1

protected int y1
The other location of the rubber-banding rectangle.

selectionModel

protected javax.swing.ListSelectionModel selectionModel
Constructor Detail

SelectionTracker

public SelectionTracker(java.awt.Component comp)

SelectionTracker

public SelectionTracker(java.awt.Component comp,
                        boolean justClicks)
Method Detail

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
If we are just interested in clicks, this is called when there is a simple mouse click (not drag and release) and then we determine which graphical component data region of interest has been selected by this point.
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent ev)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Triggered when the mouse is dragged in the device of interest, causing us to move the rubber banding rectangle and update its position.
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Need to implement this, but not interested in simple motion - only drags.
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

identify

public GraphicalComponentInt identify(java.awt.event.MouseEvent ev)
Identify the graphical component in the data region of the plot in the AWT component reporting the mouse event.

getSelected

public int[] getSelected(int x0,
                         int y0,
                         int x1,
                         int y1,
                         GraphicalContainerInt top,
                         java.awt.Rectangle bounds)
Current method for identifying the graphical components in the graphical container that are in the rectangle identified by the device coordinates x0, y0, x1, y1.

getSelectionModel

public javax.swing.ListSelectionModel getSelectionModel()
Accessor for selectionModel field

setSelectionModel

public javax.swing.ListSelectionModel setSelectionModel(javax.swing.ListSelectionModel value)
Accessor for setting selectionModel field