Revision 23053 trunk/extensions/extTopology/src/org/gvsig/fmap/tools/VectorListenerImpl.java

View differences:

VectorListenerImpl.java
49 49
package org.gvsig.fmap.tools;
50 50

  
51 51
import java.awt.Cursor;
52
import java.awt.event.MouseEvent;
52 53
import java.awt.geom.Point2D;
54
import java.awt.geom.Rectangle2D;
53 55

  
54 56
import org.gvsig.fmap.tools.listeners.VectorListener;
55 57
import org.gvsig.referencing.DisactivableMappedPosition;
......
90 92
	 */
91 93
	MappedPositionContainer linksList;
92 94
	
95
	protected boolean isZooming = false;
93 96
	
97
	
94 98
	public VectorListenerImpl(MapControl mapCtrl, MappedPositionContainer linksList) {
95 99
		super();
96 100
		this.mapCtrl = mapCtrl;
......
98 102
	}
99 103
	
100 104
	public void vector(MoveEvent event) throws BehaviorException {
101
		
102 105
		ViewPort vp = mapCtrl.getMapContext().getViewPort();
103

  
104
		Point2D from = vp.toMapPoint(event.getFrom());
105
		Point2D to = vp.toMapPoint(event.getTo());
106
		int modifiers = event.getEvent().getModifiers();
107
		int modifiersEx = event.getEvent().getModifiersEx();
106 108
		
107
		ReferencingUtil referencing = ReferencingUtil.getInstance();
109
		int ctrlDownMask = modifiersEx & MouseEvent.CTRL_DOWN_MASK;
110
		int button1Mask = modifiers & MouseEvent.BUTTON1_MASK;
111
		int button2Mask = modifiers & MouseEvent.BUTTON3_MASK;
112
	
113
		if(ctrlDownMask == MouseEvent.CTRL_DOWN_MASK && vp.getExtent()!=null){
114
			isZooming = true;
115
			Rectangle2D.Double r = new Rectangle2D.Double();
116
			Rectangle2D rect = vp.getExtent();
117
			double factor = 1;
118
			if(button1Mask == MouseEvent.BUTTON1_MASK){
119
				//zoom +
120
				factor = 1/1.5d;
121
			}else if(button2Mask == MouseEvent.BUTTON3_MASK){
122
				//zoom -
123
				factor = 1*1.5d;
124
			}else{
125
				System.err.println("Tecla ctrl pulsada, pero pulsacion de boton sin boton izquierdo o derecho");
126
				return;
127
			}
128
			
129
			double nuevoX = rect.getMaxX() -
130
				((vp.getExtent().getWidth() * factor) / 2.0);
131
			double nuevoY = rect.getMaxY() -
132
				((vp.getExtent().getHeight() * factor) / 2.0);
133
			r.x = nuevoX;
134
			r.y = nuevoY;
135
			r.width = vp.getExtent().getWidth() * factor;
136
			r.height = vp.getExtent().getHeight() * factor;
137
			vp.setExtent(r);
138
			mapCtrl.getMapContext().clearAllCachingImageDrawnLayers();
139
			
140
		}else{
141
			isZooming = false;
142
//			Point2D from = vp.toMapPoint(event.getFrom());
143
//			Point2D to = vp.toMapPoint(event.getTo());
144
			
145
			Point2D from = event.getFrom();
146
			Point2D to = event.getTo();
147
			
148
			ReferencingUtil referencing = ReferencingUtil.getInstance();
149
			
150
			//TODO Ver como pasar a GeoAPI la proyeccion del mapControl (libJCRS)	
151
			//de momento estamos pasando null
152
			DirectPosition source = 
153
				referencing.create(new double[]{from.getX(), from.getY()}, null);
154
			
155
			DirectPosition destination = 
156
				referencing.create(new double[]{to.getX(), to.getY()}, null);
157
			
158
			DisactivableMappedPosition mappedPosition
159
				= new DisactivableMappedPosition(source, destination);
160
			
161
			this.linksList.addMappedPosition(mappedPosition);
162
		}
108 163
		
109
		//TODO Ver como pasar a GeoAPI la proyeccion del mapControl (libJCRS)	
110
		//de momento estamos pasando null
111
		DirectPosition source = 
112
			referencing.create(new double[]{from.getX(), from.getY()}, null);
113 164
		
114
		DirectPosition destination = 
115
			referencing.create(new double[]{to.getX(), to.getY()}, null);
116
		
117
		
118
//		MappedPosition mappedPosition = 
119
//			new MappedPosition(source, destination);
120
		DisactivableMappedPosition mappedPosition
121
			= new DisactivableMappedPosition(source, destination);
122
		
123
		this.linksList.addMappedPosition(mappedPosition);
124 165

  
125 166
	}
126 167

  

Also available in: Unified diff