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

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

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

revision 652 by alfonx, Fri Jan 29 08:37:34 2010 UTC revision 653 by alfonx, Mon Feb 1 15:09:18 2010 UTC
# Line 42  import schmitzm.swing.SwingUtil; Line 42  import schmitzm.swing.SwingUtil;
42  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
43    
44  public class XMapPaneAction_Pan implements XMapPaneAction {  public class XMapPaneAction_Pan implements XMapPaneAction {
45            
46            public static enum Direction {
47                    UP, DOWN, RIGHT, LEFT
48            }
49    
50            /**
51             * If this action is triggered by keyboard, defines the amount of panning in
52             * screen pixels
53             **/
54            private static final int KEYBOARD_PAN_LENGTH = 15;
55    
56          /**          /**
57           * This variable can be used to backup the active cursor of the mapPane, if           * This variable can be used to backup the active cursor of the mapPane, if
58           * the actions changes the cursor during dragging           * the actions changes the cursor during dragging
59           */           */
60          public Cursor backupCursor = null;          public Cursor backupCursor = null;
61            
62          /**          /**
63           * Performs a pan action. During panning, the displacement is           * Performs a pan action. During panning, the displacement is stored in
64           * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will           * {@link #imageOrigin} object. Calling {@link #performPan()} will reset the
65           * reset the offset and call {@link #setMapArea(Envelope)}.           * offset and call {@link #setMapArea(Envelope)}.
66           */           */
67          @Override          @Override
68          public void performDragged(XMapPane mapPane, MouseEvent ev,          public void performDragged(XMapPane mapPane, MouseEvent ev,
69                          Point dragStartPos, Point dragLastPos, DirectPosition startCoord,                          Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
70                          DirectPosition endCoord) {                          DirectPosition endCoord) {
71    
72                  final Rectangle winBounds = mapPane.getVisibleRect();                  Point translation = mapPane.getImageOrigin();
73    
74                    doPan(mapPane, translation);
75            }
76    
77                  Point imageOrigin = mapPane.getImageOrigin();          private void doPan(XMapPane mapPane, Point translation) {
78    
79                  winBounds.translate(-imageOrigin.x, -imageOrigin.y);                  final Rectangle winBounds = mapPane.getVisibleRect();
80                    winBounds.translate(-translation.x, -translation.y);
81                  final Envelope newMapArea = mapPane.tranformWindowToGeo(winBounds.x,                  final Envelope newMapArea = mapPane.tranformWindowToGeo(winBounds.x,
82                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y                                  winBounds.y, winBounds.x + winBounds.width, winBounds.y
83                                                  + winBounds.height);                                                  + winBounds.height);
84    
85                  imageOrigin.x = 0;                  translation.x = 0;
86                  imageOrigin.y = 0;                  translation.y = 0;
87    
88                  if (!mapPane.setMapArea(newMapArea)) {                  if (!mapPane.setMapArea(newMapArea)) {
89                          /**                          /**
# Line 99  public class XMapPaneAction_Pan implemen Line 113  public class XMapPaneAction_Pan implemen
113                          mapPane.setCursor(SwingUtil.PANNING_CURSOR);                          mapPane.setCursor(SwingUtil.PANNING_CURSOR);
114                  }                  }
115    
116                    // Variables for the translation in screen pixels
117                  int dX;                  int dX;
118                  int dY;                  int dY;
119    
# Line 119  public class XMapPaneAction_Pan implemen Line 134  public class XMapPaneAction_Pan implemen
134          public void performWheel(XMapPane mapPane, MouseWheelEvent ev,          public void performWheel(XMapPane mapPane, MouseWheelEvent ev,
135                          DirectPosition coord) {                          DirectPosition coord) {
136          }          }
137            
138          @Override          @Override
139          public void performClick(XMapPane mapPane, MouseEvent ev,          public void performClick(XMapPane mapPane, MouseEvent ev,
140                          DirectPosition coord) {                          DirectPosition coord) {
141          }          }
142    
143            @Override
144            public void performKeyboard(XMapPane mapPane, Object param) {
145                    if (param == null)
146                            return;
147    
148                    if (!(param instanceof Direction)) {
149                            throw new IllegalArgumentException("param = " + param
150                                            + " is of expected type XMapPaneAction_Pan.Direction");
151                    }
152    
153                    // Variables for the translation in screen pixels
154                    int dX = 0;
155                    int dY = 0;
156    
157                    switch ((Direction) param) {
158                    case DOWN:
159                            dY = KEYBOARD_PAN_LENGTH;
160                            break;
161                    case UP:
162                            dY = -KEYBOARD_PAN_LENGTH;
163                            break;
164                    case LEFT:
165                            dX = -KEYBOARD_PAN_LENGTH;
166                            break;
167                    case RIGHT:
168                            dX = KEYBOARD_PAN_LENGTH;
169                            break;
170                    }
171    
172                    doPan(mapPane, new Point(dX, dY));
173            }
174    
175  }  }

Legend:
Removed from v.652  
changed lines
  Added in v.653

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26