public void mouseReleased(MouseEvent ev) {
    Graphics g = getGraphics();
    Point p1 = ev.getPoint();
    AffineTransform tr = new AffineTransform();
    switch (transformType) {
      case TRANSLATION:
        tr.setToTranslation(p1.x-p.x, p1.y-p.y);
        break;
      case ROTATION:
        double a = Math.atan2(p1.y-y0, p1.x-x0) - Math.atan2(p.y-y0, p.x-x0);
        tr.setToRotation(a);
        break;
      case SCALING:
        double sx = Math.abs((double)(p1.x-x0)/(p.x-x0));
        double sy = Math.abs((double)(p1.y-y0)/(p.y-y0));
        tr.setToScale(sx, sy);
        break;
      case SHEARING:
        double shx = ((double)(p1.x-x0)/(p.x-x0))-1;
        double shy = ((double)(p1.y-y0)/(p.y-y0))-1;
        tr.setToShear(shx, shy);
        break;
      case REFLECTION:
        tr.setTransform(-1,0,0,1,0,0);
        break;
    }
    drawShape = tr.createTransformedShape(drawShape);
    repaint();
  }