org.fhcrc.cpl.toolbox.gui.chart
Class ChartMouseAndMotionListener

java.lang.Object
  extended by java.awt.event.MouseAdapter
      extended by org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener
Direct Known Subclasses:
LogRatioHistMouseListener

public abstract class ChartMouseAndMotionListener
extends java.awt.event.MouseAdapter

Superclass for MouseListener/MouseMotionListener combos to hang on charts, with some utility methods. This was built initially in order to display selection boxes on top of a histogram, in a subclass, but I've tried to put stuff at this level that might be useful in other contexts NOTE: should only be used with charts that use XYPlots


Field Summary
protected  org.jfree.chart.ChartPanel _chartPanel
           
protected static org.apache.log4j.Logger _log
           
protected  org.jfree.chart.axis.NumberAxis domainAxis
           
protected  org.jfree.chart.axis.NumberAxis rangeAxis
           
 
Constructor Summary
ChartMouseAndMotionListener()
           
ChartMouseAndMotionListener(PanelWithChart panelWithChart)
           
 
Method Summary
protected  void drawAllButSelectedRegionHoriz(java.awt.geom.Rectangle2D selectedRegion, java.awt.Stroke stroke, java.awt.Color color, boolean xorMode, java.awt.Graphics2D g2)
          Draw a box to the left of the selected region, and one to the right, that together encompass everything but the selection
protected  void drawSelectedRegion(java.awt.geom.Rectangle2D selectedRegion, java.awt.Stroke stroke, java.awt.Color fillColor, boolean xorMode, java.awt.Graphics2D g2)
          Draws zoom rectangle (if present).
 org.jfree.chart.ChartPanel getChartPanel()
           
protected  java.awt.Graphics2D getChartPanelGraphics()
          Utility method for getting graphics
protected  java.awt.Point getPointInRectangle(int x, int y, java.awt.geom.Rectangle2D area)
          Returns a point based on (x, y) but constrained to be within the bounds of the given rectangle.
 void setChartPanel(org.jfree.chart.ChartPanel _cp)
           
protected  double transformMouseXValue(double rawValue)
          Transform a mouse X value into a value in the units of the X axis of the chart.
protected  double transformXValueToMouse(double xValue)
          Transform a value in the units of the X axis of the chart into a mouse x value Note: if there were multiple subplots, this would need to take a MouseEvent to determine which one
 
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

protected static org.apache.log4j.Logger _log

_chartPanel

protected org.jfree.chart.ChartPanel _chartPanel

domainAxis

protected org.jfree.chart.axis.NumberAxis domainAxis

rangeAxis

protected org.jfree.chart.axis.NumberAxis rangeAxis
Constructor Detail

ChartMouseAndMotionListener

public ChartMouseAndMotionListener()

ChartMouseAndMotionListener

public ChartMouseAndMotionListener(PanelWithChart panelWithChart)
Method Detail

getPointInRectangle

protected java.awt.Point getPointInRectangle(int x,
                                             int y,
                                             java.awt.geom.Rectangle2D area)
Returns a point based on (x, y) but constrained to be within the bounds of the given rectangle. This method could be moved to JCommon.

Parameters:
x - the x-coordinate.
y - the y-coordinate.
area - the rectangle (null not permitted).
Returns:
A point within the rectangle.

getChartPanelGraphics

protected java.awt.Graphics2D getChartPanelGraphics()
Utility method for getting graphics

Returns:

transformMouseXValue

protected double transformMouseXValue(double rawValue)
Transform a mouse X value into a value in the units of the X axis of the chart. Note: if there were multiple subplots, this would need to take a MouseEvent to determine which one Note: bounds the raw value by the boundaries of the chart. No using values off the ends, even if you're zoomed

Parameters:
rawValue -
Returns:

transformXValueToMouse

protected double transformXValueToMouse(double xValue)
Transform a value in the units of the X axis of the chart into a mouse x value Note: if there were multiple subplots, this would need to take a MouseEvent to determine which one

Parameters:
xValue -
Returns:

drawSelectedRegion

protected void drawSelectedRegion(java.awt.geom.Rectangle2D selectedRegion,
                                  java.awt.Stroke stroke,
                                  java.awt.Color fillColor,
                                  boolean xorMode,
                                  java.awt.Graphics2D g2)
Draws zoom rectangle (if present). The drawing is performed in XOR mode, therefore when this method is called twice in a row, the second call will completely restore the state of the canvas.

Parameters:
selectedRegion -
stroke -
fillColor -

drawAllButSelectedRegionHoriz

protected void drawAllButSelectedRegionHoriz(java.awt.geom.Rectangle2D selectedRegion,
                                             java.awt.Stroke stroke,
                                             java.awt.Color color,
                                             boolean xorMode,
                                             java.awt.Graphics2D g2)
Draw a box to the left of the selected region, and one to the right, that together encompass everything but the selection

Parameters:
selectedRegion -
stroke -
color -

getChartPanel

public org.jfree.chart.ChartPanel getChartPanel()

setChartPanel

public void setChartPanel(org.jfree.chart.ChartPanel _cp)


Fred Hutchinson Cancer Research Center