Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Mouse Wheel

Hello Visaders,

Those with mouse wheel and Java 1.4 or higher may find this piece of code useful, it implements the zoom. Its very simple and better than using the "shift + left button".

But the behavior is a little diferent from the "shift + left button" zoom, the center is the center of the box, not the center of the screen as the user might expect. I think this problem has already been solved in the list but I couldnt find it in the archive. Any other sugestions on funcionality and performance would also be apreciated:

//display is an instance of DisplayImpl that in this case must be declared final,
//but you can workaround this by calling a method outside the listener
display.getComponent().addMouseWheelListener(new java.awt.event.MouseWheelListener() {
   public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
       int rot =  e.getWheelRotation();
       try{
       ProjectionControl pControl = display.getProjectionControl();
       double[] pControlMatrix = pControl.getMatrix();
       // 3D
       if (pControlMatrix.length > 10){
           // Zoom in
           if (rot < 0){
               pControlMatrix[0] = pControlMatrix[0]*1.1f;
               pControlMatrix[5] = pControlMatrix[5]*1.1f;
               pControlMatrix[10] = pControlMatrix[10]*1.1f;
           }
           // Zoom out
           if (rot > 0){
               pControlMatrix[0] = pControlMatrix[0]*0.9f;
               pControlMatrix[5] = pControlMatrix[5]*0.9f;
pControlMatrix[10] = pControlMatrix[10]*0.9f; } // 2D } else {
           // Zoom in
           if (rot < 0){
               pControlMatrix[0] = pControlMatrix[0]*1.1f;
               pControlMatrix[3] = pControlMatrix[3]*1.1f;
           }
           // Zoom out
           if (rot > 0){
               pControlMatrix[0] = pControlMatrix[0]*0.9f;
               pControlMatrix[3] = pControlMatrix[3]*0.9f;
           }
       }
       pControl.setMatrix(pControlMatrix);
       pControl.saveProjection();
       } catch (RemoteException re) {}
       catch (VisADException ve) {}
   }
});

Cicero Zandona


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690