aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHallvard Traetteberg2012-05-10 03:48:19 (EDT)
committerHallvard Traetteberg2012-06-02 09:37:00 (EDT)
commitda69727297197eb10c5b10c0828115ecc2178d16 (patch)
tree6181c5c1e104bede10ca92802ae269fd2a064555
parent9a21bf5bd2698deb6ca46352542c33842443ad35 (diff)
downloadorg.eclipse.nebula-da69727297197eb10c5b10c0828115ecc2178d16.zip
org.eclipse.nebula-da69727297197eb10c5b10c0828115ecc2178d16.tar.gz
org.eclipse.nebula-da69727297197eb10c5b10c0828115ecc2178d16.tar.bz2
Support tool tips.
-rw-r--r--widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/DefaultMouseHandler.java31
-rw-r--r--widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/MouseHandler.java26
2 files changed, 29 insertions, 28 deletions
diff --git a/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/DefaultMouseHandler.java b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/DefaultMouseHandler.java
index 0fc74d5..9ea50aa 100644
--- a/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/DefaultMouseHandler.java
+++ b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/DefaultMouseHandler.java
@@ -10,7 +10,6 @@
******************************************************************************/
package org.eclipse.nebula.jface.geomap;
-import org.eclipse.nebula.widgets.geomap.GeoMap;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintEvent;
@@ -19,8 +18,8 @@ import org.eclipse.swt.graphics.Rectangle;
public class DefaultMouseHandler extends MouseHandler {
- public DefaultMouseHandler(GeoMap geoMap) {
- super(geoMap);
+ public DefaultMouseHandler(GeoMapViewer geoMapViewer) {
+ super(geoMapViewer);
}
private Point downPosition = null;
@@ -28,13 +27,13 @@ public class DefaultMouseHandler extends MouseHandler {
@Override
protected boolean handleDown(MouseEvent e) {
- downPosition = this.geoMap.getMapPosition();
+ downPosition = this.getGeoMap().getMapPosition();
if (isPanning = isPanDownEvent(e)) {
}
if (isZooming = isZoomDownEvent(e)) {
}
if (isCenterDownEvent(e)) {
- this.geoMap.setCenterPosition(this.geoMap.getCursorPosition());
+ getGeoMap().setCenterPosition(this.getGeoMap().getCursorPosition());
return true;
}
return false;
@@ -45,18 +44,18 @@ public class DefaultMouseHandler extends MouseHandler {
@Override
protected boolean handleDrag(MouseEvent e) {
// undo the effect of MapWidget's own panning
- this.geoMap.setMapPosition(downPosition.x, downPosition.y);
+ getGeoMap().setMapPosition(downPosition.x, downPosition.y);
// do our own panning
if (isPanning && downPosition != null) {
int tx = downCoords.x - e.x;
int ty = downCoords.y - e.y;
- this.geoMap.setMapPosition(downPosition.x + tx, downPosition.y + ty);
+ getGeoMap().setMapPosition(downPosition.x + tx, downPosition.y + ty);
return true;
}
if (isZooming && downCoords != null && dragCoords != null) {
int minX = Math.min(downCoords.x, dragCoords.x), minY = Math.min(downCoords.y, dragCoords.y);
int maxX = Math.max(downCoords.x, dragCoords.x), maxY = Math.max(downCoords.y, dragCoords.y);
- Point mapPosition = this.geoMap.getMapPosition();
+ Point mapPosition = getGeoMap().getMapPosition();
zoomRectangle = new Rectangle(mapPosition.x + minX, mapPosition.y + minY, maxX - minX, maxY - minY);
return true;
}
@@ -67,7 +66,7 @@ public class DefaultMouseHandler extends MouseHandler {
public void paintControl(PaintEvent e) {
super.paintControl(e);
if (zoomRectangle != null) {
- Point mapPosition = this.geoMap.getMapPosition();
+ Point mapPosition = getGeoMap().getMapPosition();
e.gc.drawRectangle(zoomRectangle.x - mapPosition.x, zoomRectangle.y - mapPosition.y, zoomRectangle.width, zoomRectangle.height);
}
}
@@ -77,18 +76,8 @@ public class DefaultMouseHandler extends MouseHandler {
if (e.count == 1) {
handleDrag(e);
}
- if (isZooming && downCoords != null) {
- Point mapSize = this.geoMap.getSize();
- int diff = Math.min(mapSize.x / zoomRectangle.width, mapSize.y / zoomRectangle.height);
- while (diff > 1) {
- Point mapPosition = this.geoMap.getMapPosition();
- // pivot on center of zoom rectangle
- Point pivot = new Point(zoomRectangle.x - mapPosition.x + zoomRectangle.width / 2, zoomRectangle.y - mapPosition.y + zoomRectangle.height / 2);
- this.geoMap.zoomIn(pivot);
- // scale zoom rectangle up, to match zoom level
- zoomRectangle = new Rectangle(zoomRectangle.x * 2, zoomRectangle.y * 2, zoomRectangle.width * 2, zoomRectangle.height * 2);
- diff /= 2;
- }
+ if (isZooming && downCoords != null && zoomRectangle.width > 0 && zoomRectangle.height > 0) {
+ this.geoMapViewer.zoomTo(zoomRectangle);
}
downPosition = null;
isPanning = false;
diff --git a/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/MouseHandler.java b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/MouseHandler.java
index f65e540..62579db 100644
--- a/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/MouseHandler.java
+++ b/widgets/geomap/org.eclipse.nebula.jface.geomap/src/org/eclipse/nebula/jface/geomap/MouseHandler.java
@@ -19,6 +19,8 @@ import org.eclipse.swt.events.MouseWheelListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
/**
* Handles mouse interaction, on behalf of a GeoMapViewer. Makes it easier to customize the viewer.
@@ -28,29 +30,38 @@ import org.eclipse.swt.graphics.Point;
*/
class MouseHandler implements MouseListener, MouseMoveListener, MouseTrackListener, MouseWheelListener, PaintListener {
- protected final GeoMap geoMap;
+ protected final GeoMapViewer geoMapViewer;
/**
* @param geoMap
*/
- MouseHandler(GeoMap geoMap) {
- this.geoMap = geoMap;
+ MouseHandler(GeoMapViewer geoMapViewer) {
+ this.geoMapViewer = geoMapViewer;
+ }
+
+ protected GeoMap getGeoMap() {
+ return this.geoMapViewer.getGeoMap();
}
public void mouseEnter(MouseEvent e) {
- this.geoMap.forceFocus();
+ getGeoMap().forceFocus();
}
+
public void mouseExit(MouseEvent e) {
}
protected Point dragCoords;
protected Point downCoords;
+ protected void redraw() {
+ getGeoMap().redraw();
+ }
+
public final void mouseDown(MouseEvent e) {
dragCoords = new Point(e.x, e.y);
downCoords = new Point(e.x, e.y);
if (handleDown(e)) {
- this.geoMap.redraw();
+ redraw();
}
}
@@ -59,14 +70,14 @@ class MouseHandler implements MouseListener, MouseMoveListener, MouseTrackListen
dragCoords.x = e.x;
dragCoords.y = e.y;
if (handleDrag(e)) {
- this.geoMap.redraw();
+ redraw();
}
}
}
public final void mouseUp(MouseEvent e) {
if (handleUp(e)) {
- this.geoMap.redraw();
+ redraw();
}
downCoords = null;
dragCoords = null;
@@ -85,6 +96,7 @@ class MouseHandler implements MouseListener, MouseMoveListener, MouseTrackListen
// stubs
public void mouseHover(MouseEvent e) {
+ geoMapViewer.handleToolTip(e);
}
public void mouseDoubleClick(MouseEvent e) {