@Override
  protected void performAction(Node[] nodes) {

    if (nodes.length == 0) return;
    JasperDesign jd = nodes[0].getLookup().lookup(JasperDesign.class);
    if (jd == null) return;

    List<JRDesignElement> elements = getSelectedElements(nodes);

    boolean aggregate = false;
    for (JRDesignElement element : elements) {
      Rectangle oldBounds = getElementBounds(element);

      // 1. Find the parent...
      Rectangle rect = ModelUtils.getParentBounds(jd, element);
      int oldY = element.getY();
      element.setY((rect.height / 2) - (element.getHeight() / 2));

      aggregate = addTransformationUndo(element, oldBounds, aggregate);
    }
  }
  public void updateBounds() {
    JasperDesign jd = ((AbstractReportObjectScene) this.getScene()).getJasperDesign();

    // Point p =
    // JRBand band = ModelUtils.bandOfElement(element, jd);
    // int bandYLocation = ModelUtils.getBandLocation(band, jd);
    // setPreferredLocation(new Point( jd.getLeftMargin() + element.getX()-5, bandYLocation +
    // element.getY() -5) );
    // setPreferredBounds(new Rectangle(0,0,element.getWidth()+10, element.getHeight()+10));

    Point location = convertModelToLocalLocation(new Point(element.getX(), element.getY()));
    location.x -= getBorder().getInsets().left;
    location.y -= getBorder().getInsets().top;
    setPreferredLocation(location);
    setPreferredBounds(
        new Rectangle(
            0,
            0,
            element.getWidth() + getBorder().getInsets().left + getBorder().getInsets().right,
            element.getHeight() + getBorder().getInsets().top + getBorder().getInsets().bottom));
  }
  protected void paintWidgetImplementation() {

    super.paintWidget();
    Graphics2D gr = getScene().getGraphics();

    // Java2DUtils.setClip(gr,getClientArea());
    // Move the gfx 10 pixel ahead...
    Rectangle r = getPreferredBounds();

    long t = new Date().getTime();
    // if (getElement() instanceof JRDesignImage) return;

    AffineTransform af = gr.getTransform();
    AffineTransform new_af = (AffineTransform) af.clone();
    AffineTransform translate =
        AffineTransform.getTranslateInstance(
            getBorder().getInsets().left + r.x, getBorder().getInsets().top + r.y);
    new_af.concatenate(translate);
    gr.setTransform(new_af);

    JasperDesign jd = ((AbstractReportObjectScene) this.getScene()).getJasperDesign();
    JRDesignElement e = this.getElement();
    DrawVisitor dv = ((AbstractReportObjectScene) this.getScene()).getDrawVisitor();
    if (dv == null) return;

    if (e instanceof JRDesignCrosstab) {
      Composite oldComposite = gr.getComposite();
      gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
      try {
        e.visit(dv);
      } catch (Exception ex) {
      }
      gr.setComposite(oldComposite);
      Shape oldClip = gr.getClip();
      Shape rect = new Rectangle2D.Float(0, 0, element.getWidth(), element.getHeight());

      gr.clip(rect);
      gr.drawImage(crosstabImage.getImage(), 4, 4, null);
      gr.setClip(oldClip);
    }
    //        if (e instanceof JRDesignFrame)
    //        {
    //            Composite oldComposite = gr.getComposite();
    //            gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    //            //try {
    //            //    e.visit( dv );
    //            //} catch (Exception ex){}
    //            gr.setComposite(oldComposite);
    //            Shape oldClip = gr.getClip();
    //            Shape rect = new Rectangle2D.Float(0,0,element.getWidth(), element.getHeight());
    //
    //        }
    else if (e instanceof JRDesignSubreport) {
      Composite oldComposite = gr.getComposite();
      gr.fillRect(0, 0, element.getWidth(), element.getHeight());
      gr.setComposite(oldComposite);
      Shape oldClip = gr.getClip();
      Shape rect = new Rectangle2D.Float(0, 0, element.getWidth(), element.getHeight());
      gr.clip(rect);
      gr.drawImage(subreportImage.getImage(), 4, 4, null);
      gr.setClip(oldClip);
    } else if (e instanceof JRDesignGenericElement) {
      // Composite oldComposite = gr.getComposite();
      Paint oldPaint = gr.getPaint();
      gr.setPaint(new Color(196, 200, 162, 64));
      gr.fillRect(0, 0, element.getWidth(), element.getHeight());
      gr.setPaint(oldPaint);
      // gr.setComposite(oldComposite);
      Shape oldClip = gr.getClip();
      Shape rect = new Rectangle2D.Float(0, 0, element.getWidth(), element.getHeight());
      gr.clip(rect);
      gr.drawImage(genericElementImage.getImage(), 4, 4, null);
      gr.setClip(oldClip);
    } else if (e instanceof JRDesignChart) {

      if (((JRDesignChart) e).getChartType() == JRDesignChart.CHART_TYPE_MULTI_AXIS) {
        Composite oldComposite = gr.getComposite();

        gr.fillRect(0, 0, element.getWidth(), element.getHeight());
        gr.setComposite(oldComposite);
        Shape oldClip = gr.getClip();
        Shape rect = new Rectangle2D.Float(0, 0, element.getWidth(), element.getHeight());
        gr.clip(rect);
        gr.drawImage(multiaxisImage.getImage(), 4, 4, null);
        gr.setClip(oldClip);
      } else {
        ClassLoader oldCL = null;

        dv.setGraphics2D(gr);
        oldCL = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(IReportManager.getJRExtensionsClassLoader());

        try {
          e.visit(dv);
        } catch (Exception ex) {

          System.err.println(
              "iReport - Element rendering exception " + getElement() + " " + ex.getMessage());
          // ex.printStackTrace();
        }

        if (oldCL != null) {
          Thread.currentThread().setContextClassLoader(oldCL);
        }
      }
    } else {
      dv.setGraphics2D(gr);
      try {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(IReportManager.getJRExtensionsClassLoader());
        e.visit(dv);
        Thread.currentThread().setContextClassLoader(cl);
      } catch (Exception ex) {

        System.err.println(
            "iReport - Element rendering exception " + getElement() + " " + ex.getMessage());
        // ex.printStackTrace();
      }
    }

    // show the element and parent coordinates...
    /*
    Point p = getParentElementModelLocation();
    gr.setColor(Color.darkGray);
    gr.setFont(new Font("SansSerif",0,6));
    gr.drawString( getElement().getX() + "," + getElement().getY() + " - " + p.x + "," + p.y, 2, 12);
    */
    //
    gr.setTransform(af);
    // Java2DUtils.resetClip(gr);

    // System.out.println("Painted : " + (t - new Date().getTime()) + "   " + getElement());
  }