Guest User

Better ZoomChart zooming

a guest
Jan 8th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. public void mouseDragged(final MouseEvent e) {
  2.         if (this.m_lastPressedButton != MouseEvent.BUTTON1) {
  3.             return;
  4.         }
  5.  
  6.         double x;   // Rectangle start x without chart bounds
  7.         double y;   // Rectangle start y without chart bounds
  8.         double x2;  // Rectangle end x without chart bounds
  9.         double y2;  // Rectangle end y without chart bounds
  10.         double startX;
  11.         double endX;
  12.         double dimX;
  13.         double dimY;
  14.         double startY;
  15.         double endY;
  16.         double chartStartX = this.getXChartStart();
  17.         double chartEndX = this.getXChartEnd();
  18.         // Switched these around because I think the window's top as y starting coordinates
  19.         double chartStartY = this.getYChartEnd();      
  20.         double chartEndY = this.getYChartStart();
  21.  
  22.         // Checking which coordinates will be rectangles starting and ending points
  23.         x = Math.min(this.m_startPoint.getX(), e.getX());
  24.         x2 = Math.max(this.m_startPoint.getX(), e.getX());
  25.         y = Math.min(this.m_startPoint.getY(), e.getY());
  26.         y2 = Math.max(this.m_startPoint.getY(), e.getY());
  27.        
  28.        
  29.         // Bounding rectangle to chart area only
  30.         // x-coordinate
  31.         startX = Math.min(chartEndX, x);
  32.         startX = Math.max(chartStartX, startX);
  33.         endX = Math.min(chartEndX, x2);
  34.         endX = Math.max(chartStartX, endX);
  35.        
  36.         // y-coordinate
  37.         startY = Math.min(chartEndY, y);
  38.         startY = Math.max(chartStartY, startY);
  39.         endY = Math.min(chartEndY, y2);
  40.         endY = Math.max(chartStartY, endY);
  41.    
  42.  
  43.         dimX = endX - startX;
  44.         dimY = endY - startY;
  45.  
  46.         this.m_zoomArea = new Rectangle2D.Double(startX, startY, dimX, dimY);
  47.  
  48.         this.setRequestedRepaint(true);
  49.   }
Advertisement
Add Comment
Please, Sign In to add comment