@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);
 }
 public static int getMinimumWidth(IFigure figure) {
   if (figure instanceof FlowPage) {
     FlowPage fp = (FlowPage) figure;
     TextFlow tf = (TextFlow) fp.getChildren().get(0);
     List<?> fragments = tf.getFragments();
     int width = getLongestFragment(fragments) + figure.getBorder().getInsets(figure).getWidth();
     return width;
   } else {
     return figure.getBounds().width;
   }
 }
 public static int getMinimumHeight(IFigure figure) {
   int height = figure.getBounds().height;
   if (figure instanceof FlowPage) {
     FlowPage fp = (FlowPage) figure;
     TextFlow tf = (TextFlow) fp.getChildren().get(0);
     Dimension textExtents = TextUtilities.INSTANCE.getTextExtents(tf.getText(), tf.getFont());
     List<?> fragments = tf.getFragments();
     if (fragments.size() != 0) {
       height = fragments.size() * textExtents.height;
       // include border padding
       height = height + figure.getBorder().getInsets(figure).getHeight();
     }
   }
   return height;
 }