Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Tools for Java
 QCChart2D for Java
 Overriding Default Behavior of DataCursor
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

png

USA
6 Posts

Posted - 16 Oct 2014 :  17:44:26  Show Profile  Reply with Quote
I'm using both a DataCursor and a ChartZoom object within the same ChartView instance. How would I go about changing the default behavior of the DataCursor object so that it won't clash with the ChartZoom object when a mouse pressed event occurs?

Also, I'm trying to implement code to actively update a label that shows the current X,Y data point as the DataCursor marker is moving along the chart, but haven't able to get it working. Can you provide some sample code that demonstrates how this functionality would be handled?

Thanks!

quinncurtis

1531 Posts

Posted - 16 Oct 2014 :  18:04:02  Show Profile  Reply with Quote
You can't use both at the same time. You must have some sort of toggle (a checkbox or button) that enables one or the other, but not both. You would set the enable property of the cursor or the zoom object depending on the toggle state.

if (zoomEnable)
{
zoomObj.setZoomEnable(true);
cursorObj.setDataCursorEnable(false);
} else
{
zoomObj.setZoomEnable(false);
cursorObj.setDataCursorEnable(true);
}
Go to Top of Page

png

USA
6 Posts

Posted - 17 Oct 2014 :  12:13:46  Show Profile  Reply with Quote
Thanks for your reply. On this same topic, is there a way to set the DataCursor so that the marker appears as the mouse is moving across the chart, rather than having to press and hold down the mouse button as it moves across the chart (its default behavior)?
Go to Top of Page

quinncurtis

1531 Posts

Posted - 17 Oct 2014 :  13:06:49  Show Profile  Reply with Quote
The DataCursor class has no standard mode which tracks the mouseMove event, independent of the button status.

You can play around with a subclass of DataCursor. In this example the first move simulates a mouse pressed event to start the data cursor, and does NOT pass along actual mousePressed and mouseRelease events. Subsequent mouseMoved calls the standard mouse event mouseDragged method, which is what the DataCursor routine tracks. However, you may get remnants, definitely if you use it simultaneously with another MouseListener class which uses the XOR mode, such as the ChartZoom class.



 class CustomDataCursor extends DataCursor {


	   boolean firstpass = true;
	   public CustomDataCursor(ChartView achartview, CartesianCoordinates thetransform,
	                       int nmarkertype,
	                       double rsize)
	  {
	        super(achartview, thetransform, nmarkertype, rsize);
	  }
	   
	   // override mousePressed 
	   public void mousePressed(MouseEvent event)
	    {
		   
	    }
	   
	   // override mouseReleased method 
	   public void mouseReleased(MouseEvent event)
	    {
		   
	    }
	   
	   // create a simulated mousePressed event
	   public void simulatedMousePressed(MouseEvent event)
	    {
		     try {
			   	    super.mousePressed(event);
			     }
			    catch ( Exception  e )
			    {
			    }

		   
	    }
	   
		  // override mouseReleased method in order to add stuff
	   public void mouseMoved (MouseEvent event)
	    {
		   MouseEvent me = new MouseEvent(this.getChartObjComponent(),
	                  event.getID(),
	                  0,
	                  event.getModifiers() | this.getButtonMask(),
	                  event.getX(),
	                  event.getY(),
	                  1,
	                  false);		   
		   if (firstpass){
			   simulatedMousePressed( me);
			   firstpass = false;
		   } else 
		   {
			   super.mouseDragged(me);
		   }
	    }

   
	  }
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Quinn-Curtis Forums © 2000-07 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07