package com.qualityeclipse.genealogy.listener; import org.eclipse.draw2d.*; import org.eclipse.draw2d.geometry.*; public abstract class FigureMover implements MouseListener, MouseMotionListener { private final IFigure figure; public FigureMover(IFigure figure) { this.figure = figure; figure.addMouseListener(this); figure.addMouseMotionListener(this); } private Point location; public void mousePressed(MouseEvent event) { location = event.getLocation(); event.consume(); } public void mouseDragged(MouseEvent event) { if(location == null) return; Point newLocation = event.getLocation(); if (newLocation == null) return; Dimension offset = newLocation.getDifference(location); if (offset.width == 0 && offset.height == 0) return; location = newLocation; UpdateManager updateMgr = figure.getUpdateManager(); LayoutManager layoutMgr = figure.getParent().getLayoutManager(); Rectangle bounds = figure.getBounds(); updateMgr.addDirtyRegion(figure.getParent(), bounds); bounds = bounds.getCopy().translate(offset.width, offset.height); layoutMgr.setConstraint(figure, bounds); figure.translate(offset.width, offset.height); updateMgr.addDirtyRegion(figure.getParent(), bounds); event.consume(); } public void mouseReleased(MouseEvent event) { if(location == null) return; location = null; event.consume(); } }