/[schmitzm]/branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java
ViewVC logotype

Diff of /branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_ZoomIn.java revision 639 by alfonx, Thu Jan 28 16:07:22 2010 UTC branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java revision 648 by alfonx, Thu Jan 28 16:51:55 2010 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  package skrueger.geotools;
2    
 import java.awt.Color;  
 import java.awt.Graphics;  
3  import java.awt.Point;  import java.awt.Point;
4    import java.awt.Rectangle;
5  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
6  import java.awt.event.MouseWheelEvent;  import java.awt.event.MouseWheelEvent;
 import java.awt.geom.Point2D;  
7    
8  import org.opengis.geometry.DirectPosition;  import org.opengis.geometry.DirectPosition;
9    
10  public class XMapPaneAction_ZoomIn implements XMapPaneAction {  import com.vividsolutions.jts.geom.Coordinate;
11            import com.vividsolutions.jts.geom.Envelope;
         /**  
          * Stores last position of a drag event in window coordinates  
          */  
         protected Point lastPos;  
           
         @Override  
         public void performClick(XMapPane mapPane, MouseEvent ev,  
                         DirectPosition coord) {  
                   
                 mapPane.zoomTo(ev.getPoint(), 1 / 2.);  
         }  
12    
13          @Override  public abstract class XMapPaneAction_Zoom implements XMapPaneAction {
         public void performDragging(XMapPane mapPane, MouseEvent ev,  
                         Point dragStartPos, DirectPosition startCoord,  
                         DirectPosition endCoord) {  
                   
                 mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev.getPoint());  
         }  
14    
15          @Override          public static class In extends XMapPaneAction_Zoom {
16          public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,  
17                          DirectPosition coord) {                  @Override
18                    public void performClick(XMapPane mapPane, MouseEvent ev,
19                  final int units = wheelEvt.getUnitsToScroll();                                  DirectPosition coord) {
20                  if (units > 0)  
21                          mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);                          mapPane.zoomTo(ev.getPoint(), 1 / 2.);
22                  else                  }
23                          mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);  
24          }                  @Override
25                    public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
26                                    DirectPosition coord) {
27    
28                            final int units = wheelEvt.getUnitsToScroll();
29                            if (units > 0)
30                                    mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);
31                            else
32                                    mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);
33                    }
34    
35                    @Override
36                    public void performDragging(XMapPane mapPane, MouseEvent ev,
37                                    Point dragStartPos, Point dragLastPos,
38                                    DirectPosition startCoord, DirectPosition endCoord) {
39    
40                            if (dragLastPos != null)
41                                    mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
42                                                    dragLastPos);
43    
44                            mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
45                                            .getPoint());
46                    }
47    
48                    @Override
49                    public void performDragged(XMapPane mapPane, MouseEvent ev,
50                                    Point dragStartPos, Point dragLastPos,
51                                    DirectPosition startCoord, DirectPosition endCoord) {
52    
53                            if (dragLastPos != null)
54                                    mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
55                                                    dragLastPos);
56    
57                            // If this is similar to a click, let mouseClicked handle it!
58                            if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
59                                            .getPoint().y
60                                            - dragStartPos.y)) < 160) {
61                                    // performClick(mapPane, ev, coord)
62                                    return;
63                            }
64    
65                            final Rectangle bounds = mapPane.getBounds();
66    
67                            Envelope mapArea = mapPane.getMapArea();
68    
69                            // Replace with transform and translate
70                            final double mapWidth = mapArea.getWidth();
71                            final double mapHeight = mapArea.getHeight();
72    
73                            final double startX = ((dragStartPos.x * mapWidth) / (double) bounds.width)
74                                            + mapArea.getMinX();
75                            final double startY = (((bounds.getHeight() - dragStartPos.y) * mapHeight) / (double) bounds.height)
76                                            + mapArea.getMinY();
77                            final double endX = ((ev.getPoint().x * mapWidth) / (double) bounds.width)
78                                            + mapArea.getMinX();
79                            final double endY = (((bounds.getHeight() - ev.getPoint().y) * mapHeight) / (double) bounds.height)
80                                            + mapArea.getMinY();
81    
82                            final double left = Math.min(startX, endX);
83                            final double right = Math.max(startX, endX);
84                            final double bottom = Math.min(startY, endY);
85                            final double top = Math.max(startY, endY);
86                            final Coordinate ll = new Coordinate(left, bottom);
87                            final Coordinate ur = new Coordinate(right, top);
88    
89          @Override                          mapPane.setMapArea(new Envelope(ll, ur));
         public void performDragged(XMapPane mapPane, MouseEvent ev,  
                         Point dragStartPos, DirectPosition startCoord,  
                         DirectPosition endCoord) {  
                 // TODO Auto-generated method stub  
90    
91                    }
92          }          }
93    
94  }          public static class Out extends XMapPaneAction_Zoom {
95    
96                    @Override
97                    public void performClick(XMapPane mapPane, MouseEvent ev,
98                                    DirectPosition coord) {
99    
100                            mapPane.zoomTo(ev.getPoint(), 2.);
101                    }
102    
103                    @Override
104                    public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
105                                    DirectPosition coord) {
106    
107                            final int units = wheelEvt.getUnitsToScroll();
108                            if (units <= 0)
109                                    mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);
110                            else
111                                    mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);
112                    }
113    
114                    @Override
115                    public void performDragging(XMapPane mapPane, MouseEvent ev,
116                                    Point dragStartPos, Point dragLastPos,
117                                    DirectPosition startCoord, DirectPosition endCoord) {
118    
119                            if (dragLastPos != null)
120                                    mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
121                                                    dragLastPos);
122    
123                            mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
124                                            .getPoint());
125                    }
126    
127                    @Override
128                    public void performDragged(XMapPane mapPane, MouseEvent ev,
129                                    Point dragStartPos, Point dragLastPos,
130                                    DirectPosition startCoord, DirectPosition endCoord) {
131    
132                            if (dragLastPos != null)
133                                    mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
134                                                    dragLastPos);
135    
136                            // If this is similar to a click, let mouseClicked handle it!
137                            if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
138                                            .getPoint().y
139                                            - dragStartPos.y)) < 160) {
140                                    // performClick(mapPane, ev, coord)
141                                    return;
142                            }
143    
144                            final Rectangle bounds = mapPane.getBounds();
145    
146                            Envelope mapArea = mapPane.getMapArea();
147    
148                            // Replace with transform and translate
149                            final double mapWidth = mapArea.getWidth();
150                            final double mapHeight = mapArea.getHeight();
151    
152                            final double startX = ((dragStartPos.x * mapWidth) / (double) bounds.width)
153                                            + mapArea.getMinX();
154                            final double startY = (((bounds.getHeight() - dragStartPos.y) * mapHeight) / (double) bounds.height)
155                                            + mapArea.getMinY();
156                            final double endX = ((ev.getPoint().x * mapWidth) / (double) bounds.width)
157                                            + mapArea.getMinX();
158                            final double endY = (((bounds.getHeight() - ev.getPoint().y) * mapHeight) / (double) bounds.height)
159                                            + mapArea.getMinY();
160    
161                            // make the dragged rectangle in screen coords the new map size?
162                            final double left = Math.min(startX, endX);
163                            final double right = Math.max(startX, endX);
164                            final double bottom = Math.min(startY, endY);
165                            final double top = Math.max(startY, endY);
166                            final double nWidth = (mapWidth * mapWidth) / (right - left);
167                            final double nHeight = (mapHeight * mapHeight) / (top - bottom);
168                            final double deltaX1 = left - mapArea.getMinX();
169                            final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
170                            final double deltaY1 = bottom - mapArea.getMinY();
171                            final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
172                            final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
173                                            mapArea.getMinY() - nDeltaY1);
174                            final double deltaX2 = mapArea.getMaxX() - right;
175                            final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
176                            final double deltaY2 = mapArea.getMaxY() - top;
177                            final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
178                            final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
179                                            mapArea.getMaxY() + nDeltaY2);
180    
181                            mapPane.setMapArea(new Envelope(ll, ur));
182    
183                    }
184            }
185    }

Legend:
Removed from v.639  
changed lines
  Added in v.648

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26