JWaveCanvas2D and JWavePanel2D
The classes JWaveCanvas2D and JWavePanel2D provide the ability to interact with a two-dimensional chart in several ways:
*Pressing and dragging the mouse to zoom in on a chart.
*Selecting a point on a chart.
*Selecting a profile of an image.
Pick Point
The pick feature allows an object to be notified when the user selects a point on a chart with a mouse click. The JWaveCanvas2D and JWavePanel2D parent classes send a notification event to all registered listeners that a PickPointEvent has occurred. When the listener receives the notification event, the data coordinates of the selected point may be retrieved from the getSelectedX and getSelectedY methods. The returned values may be displayed or used as indexes to the data arrays to select actual values.
To use this feature with a chart object, pick point must first be enabled. This can be done either by calling the object’s:
setPickPointEnabled(true)
method or by sending the object an action with the command string “pick-enabled”. Listeners can be added to the object by calling the object’s:
addPickPointListener(PickPointListener listener)
method. The listener must implement the nested interface JWaveCanvas2D. PickPointListener or JWavePanel2D.PickPointListener. The interface requires the implementation of the method:
public void pointPicked(PickPointEvent event)
Example
Assume that we have a chart object that extends JWaveCanvas2D and we want to update a label object with the user-selected coordinates. This could be implemented by adding the following code fragment to the class that sets up the GUI.
final Label label = new Label();
chart.setPickPointEnabled(true);
chart.addPickPointListener(new 
JWaveCanvas2D.PickPointListener() {
public void pointPicked(JWaveCanvas2D.PickPointEvent event) {
	int x = event.getSelectedX();
	int y = event.getSelectedY();
	label.setText("("+x+","+y"+)");
}
	}
}
Zoom
The zoom feature allows the user to zoom into a section of a chart. The JWaveCanvas2D and JWavePanel2D parent classes draw a box indicating the area where the user has pressed and dragged the left mouse button across the chart. When the left mouse has been released all registered listeners will be notified that a zoomEvent has occurred. When the listener receives the notification event, the new X and Y ranges may be retrieved from the getXrange and getYrange methods. The returned values may be used as XRANGE and YRANGE settings for PV-WAVE commands such as PLOT, AXIS, CONTOUR, and SURFACE. For a list of additional PV‑WAVE commands, see PV‑WAVE Reference Guide, Chapter 21, Graphics and Plotting Keywords.
To use this feature with a chart object, zoom must first be enabled. This can be done either by calling the object’s:
setZoomEnabled(true)
method or by sending the object an action with the command string “zoom-enabled”. Listeners can be added to the object by calling the object’s:
addZoomListener(ZoomListener listener)
method. The listener must implement the nested interface JWaveCanvas2D.ZoomListener or JWavePanel2D.ZoomListener. The interface requires the implementation of the method:
public void zoomUpdate(ZoomEvent event)
Example
Assume that we want to add the zoom feature to a chart. This chart is generated by the JWAVE wrapper WImage. The WImage wrapper looks for parameters xrange and yrange, each of which is an array containing two doubles. These parameters specify the area to chart the data in.
The following class fragment shows the zoom feature. The code to initially get the data and generate the chart is omitted for simplicity.
public class ZoomChart extends JWavePanel2D implements
JWavePanel2D.ZoomListener {
private JWaveConnection connection;
private JWaveView imageView;
private Viewable   imageViewable;
private double     xrange[];
private double     yrange[];

public ZoomChart(JWaveConnection connection) {
this.connection = connection;
imageView = new JWaveView(connection, "WImage");
setPreferredSize(new Dimension(500,350));
addZoomListener(this);
}

public void zoomUpdate(JWavePanel2D.ZoomEvent event) {
xrange = event.getXrange();
yrange = event.getYrange();
imageView.setParam("xrange", xrange);
imageView.setParam("yrange", yrange);
// Set size of plot to be produced to match our Panel
imageView.setViewSize(new Dimension(500,350));
try {
        imageView.execute();
        imageViewable = imageView.getViewable();
        imageViewable.setPreferredResizeMode
(Viewable.NOT_RESIZEABLE);
setViewable(imageViewable);
} catch (JWaveException e) {
System.out.println("Problem getting new
Viewable: " + e);
}
}
}
Profile
The profile feature allows the user to select a vertical or horizontal profile of an image by selecting a point on the chart. The JWaveCanvas2D and JWavePanel2D parent classes draw a line representing the row or column of the image selected. The JWaveCanvas2D and JWavePanel2D parent classes will send a notification event to all registered listeners that a ProfileEvent has occurred. When the listener receives the notification event, the data coordinates of the selected point may be retrieved from the getSelectedX and getSelectedY methods. The returned values may be used to extract the values of the image along the line selected. For an example, see ProfileChart.java provided in the jwave_demos/canvas2d directory.
To use this feature with a chart object that displays the image, profile must first be enabled. This can be done either by calling the object’s:
setProfileEnabled(true)
method or by sending the object an action with the command string “profile-enabled”. Listeners can be added to the object by calling the object’s
addProfileListener(ProfileListener listener)
method. The listener must implement the nested interface JWaveCanvas2D.ProfiletListener or JWavePanel2D.ProfileListener. The interface requires the implementation of the method
public void profilePicked(ProfileEvent event)
Example
Assume that we have a chart object that extends JWaveCanvas2D and we want to plot in a separate chart object the profile of an image and allow the user to select the profile to be displayed. This could be implemented by adding the following code fragment to the class which sets up the GUI for the chart object that displays the image:
chart.setProfileEnabled(true);
chart.setProfileType(chart.COLUMN);
The setProfileType can be used to draw the vertical line representing the column or the horizontal line representing the row.
Next add the ProfileListener to the chart object that will display the line plot or profile plot:
chart.addProfileListener(new JWaveCanvas2D.ProfileListener() {
public void profilePicked(JWaveCanvas2D.ProfileEvent event) {
int x = event.getSelectedX();
int y = event.getSelectedY();
Graphics pg = this.getGraphics();
drawProfile(pg);
	}
}
The drawProfile code has been left out for simplicity. The ProfileChart class provided in the jwave_demos/canvas2d directory can easily be used as it is or modified to better meet your needs.