@Override
public void translate(LayerEvent e, double dx, double dy) {
AffineTransform af = new AffineTransform();
GrabHandle grabHandle = (GrabHandle) e.getFigureSource();
RectangleManipulator manipulator = (RectangleManipulator) grabHandle.getParent();
RectangleGeometry geometry = manipulator.getGeometry();
RotatableCanvasFigure roi = (RotatableCanvasFigure) manipulator.getChild();
Point2D p = geometry.getRotateCenter();
double cx = p.getX();
double cy = p.getY();
int id = grabHandle.getSite().getID();
if (id == 0) {
double x = e.getLayerX();
double y = e.getLayerY();
double x1 = x - dx - cx;
double x2 = x - cx;
double y1 = y - dy - cy;
double y2 = y - cy;
/////////////////////
// Rotating Handle //
/////////////////////
double angle = Math.atan2(y2, x2) - Math.atan2(y1, x1);
// Transform the child.
af.setToRotation(angle, cx, cy);
roi.transform(af);
} else if (roi.isResizable()) {
///////////////////
// Resize Handle //
///////////////////
RectangularShape r1 = (RectangularShape) geometry.getRect().clone();
// translating the grab handle
grabHandle.translate(dx, dy);
// transform the child roi
RectangularShape r2 = geometry.getRect();
double angle = geometry.getRotateAngle();
af.concatenate(AffineTransform.getRotateInstance(angle, cx, cy));