protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
   container.validate();
   List<IFigure> children = container.getChildren();
   Rectangle result = new Rectangle().setLocation(container.getClientArea().getLocation());
   for (IFigure c : children) result.union(c.getBounds());
   Insets ins = container.getInsets();
   result.resize(ins.getWidth(), ins.getHeight());
   return result.getSize();
 }
 @Override
 public void relocate(IFigure target) {
   Rectangle bounds = target.getBounds().getCopy();
   Point location = null;
   if (parent instanceof ConnectorEditPart) {
     ConnectorEditPart connectorPart = (ConnectorEditPart) parent;
     PointList points = getPoints(connectorPart.getConnectionFigure());
     location = getPointForEnd(points);
   } else {
     // if the parent is any other edit part
     // use the bounds center
     location = parent.getFigure().getBounds().getCenter();
   }
   if (lastLocation == null) {
     lastLocation = location;
   }
   Dimension delta = location.getDifference(lastLocation);
   bounds.translate(delta.width, delta.height);
   lastLocation = location.getCopy();
   // if the current width is 0 then the
   // user has never set the width, calculate it
   // here using a maximum number of 400
   boolean cropWidth = false;
   if (bounds.width == 0) {
     Dimension preferred = target.getPreferredSize();
     bounds.width = preferred.width;
     bounds.width = Math.min(400, bounds.width);
     cropWidth = true;
   }
   if (bounds.width < target.getBorder().getInsets(target).getWidth()) {
     // do not allow resizing to zero
     bounds.width = target.getBorder().getInsets(target).getWidth();
   }
   // we must set the bounds to allow recalculation
   // of text height (wrapping)
   target.setBounds(bounds);
   target.validate();
   // adjust height to account for word wrapping
   bounds.height = getMinimumHeight(target);
   if (cropWidth) {
     // crop the width here, as this is not a user set
     // width and otherwise if near 400 may leave extra
     // slack
     bounds.width = getMinimumWidth(target);
   }
   target.setBounds(bounds);
 }