[messages] Edit: [Developers] Re: Mouse-Wheel Behavior

bdgza bdegroot at gmail.com
Tue Oct 12 00:30:49 MST 2010


[This message has been edited.]

Since AdjustableSpeedScrollPane is probably re-used in other places than
just Map, this might be better:

Code:
	      viewport.addMouseWheelListener(new MouseWheelListener() {
	    	  public void mouseWheelMoved(MouseWheelEvent e) {
	    		  if (e.getScrollAmount() == 0) return;
	    		  
	    		  Zoomer mapZoomer = null; 
	    			  
	    		  if (parentMap != null)
	    			  mapZoomer =  parentMap.getZoomer();
	    		  
	    		  if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
	    			  if ((mapZoomer != null) && (e.isControlDown())) {
	    				  // zoom
	    				  int notches = e.getWheelRotation();
	    				  int amount = e.getScrollAmount();

	    				  for (int i = 0; i < amount; i++) {
	    					  if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL)
{
	    						  if (notches < 0) {
		    						  //UP
		    						  mapZoomer.zoomIn();
		    					  } else {
		    						  //DOWN
		    						  mapZoomer.zoomOut();
		    					  }
	    					  }
	    				  }

	    			  } else {
	    				  JScrollBar bar = e.isShiftDown() ?
	    						  horizontalScrollBar :
	    							  verticalScrollBar;
	    				  if (bar == null || !bar.isVisible()) return;

	    				  bar.setValue(
	    						  bar.getValue() +
	    						  e.getUnitsToScroll() *
	    						  bar.getUnitIncrement()
	    				  );
	    			  }
	    		  }
	    	  }
	      });



_______________________________________________
Read this topic online here:
http://www.vassalengine.org/forum/viewtopic.php?p=20223#p20223


More information about the messages mailing list