public static XControlShape createGrid(XComponent oDoc, int height, int width, int x, int y) {
    Size size = new Size();
    Point position = new Point();
    XControlShape oCShape = null;
    XControlModel aControl = null;

    // get MSF
    XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc);

    try {
      Object oInt = oDocMSF.createInstance("com.sun.star.drawing.ControlShape");
      Object aCon = oDocMSF.createInstance("com.sun.star.form.component.GridControl");
      XPropertySet model_props = UnoRuntime.queryInterface(XPropertySet.class, aCon);
      model_props.setPropertyValue(
          "DefaultControl", "com.sun.star.form.control.InteractionGridControl");
      aControl = UnoRuntime.queryInterface(XControlModel.class, aCon);
      oCShape = UnoRuntime.queryInterface(XControlShape.class, oInt);
      size.Height = height;
      size.Width = width;
      position.X = x;
      position.Y = y;
      oCShape.setSize(size);
      oCShape.setPosition(position);
    } catch (com.sun.star.uno.Exception e) {
      // Some exception occurs.FAILED
      System.out.println("Couldn't create Grid" + e);
      throw new StatusException("Couldn't create Grid", e);
    }

    oCShape.setControl(aControl);

    return oCShape;
  } // finish createGrid
  /**
   * Get the closer button on the right top of the current window.
   *
   * @return A point representing the closer button.
   */
  private Point getCloser(Point center) {
    XMultiServiceFactory xMSF = tParam.getMSF();
    Object aToolkit = null;
    try {
      aToolkit = xMSF.createInstance("com.sun.star.awt.Toolkit");
    } catch (com.sun.star.uno.Exception e) {
      throw new StatusException("Could not create 'com.sun.star.awt.Toolkit'.", e);
    }
    XExtendedToolkit xExtendedToolkit = UnoRuntime.queryInterface(XExtendedToolkit.class, aToolkit);
    XTopWindow tw = null;

    XAccessibleComponent xAccessibleComponent = null;
    int k = xExtendedToolkit.getTopWindowCount();
    for (int i = 0; i < k; i++) {
      try {
        XTopWindow tw_temp = xExtendedToolkit.getTopWindow(i);
        XAccessible xacc = UnoRuntime.queryInterface(XAccessible.class, tw_temp);
        if (xacc != null) {
          System.out.println("Name: " + xacc.getAccessibleContext().getAccessibleName());
          if (xacc.getAccessibleContext().getAccessibleName().startsWith("the title")) {
            tw = tw_temp;
            XAccessibleContext xContext = xacc.getAccessibleContext();
            xAccessibleComponent = UnoRuntime.queryInterface(XAccessibleComponent.class, xContext);
            if (xAccessibleComponent == null) System.out.println("!!!! MIST !!!!");
            else System.out.println("########## KLAPPT ########## ");
          }
        } else {
          log.println("\t unknown window");
        }

      } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
      }
    }
    if (tw == null) {
      System.out.println("No TopWindow :-(");
      return null;
    }

    XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, tw);
    Rectangle posSize = xWindow.getPosSize();

    // compare the center point with the dimensions of the current top window
    boolean windowOK = false;
    while (!windowOK) {
      if (posSize.X <= center.X && center.X <= posSize.X + posSize.Width) {
        if (posSize.Y <= center.Y && center.Y <= posSize.Y + posSize.Height) {
          // move window out of the way
          posSize.X = posSize.X + 10;
          posSize.Y = posSize.Y + 10;
          xWindow.setPosSize(posSize.X, posSize.Y, posSize.Width, posSize.Height, PosSize.POS);
        } else {
          windowOK = true;
        }
      } else {
        windowOK = true;
      }
    }

    Point p = xAccessibleComponent.getLocationOnScreen();
    Point closer = new Point();
    closer.X = p.X + posSize.Width - 2;
    closer.Y = p.Y + 5;
    System.out.println("Closer: " + closer.X + "   " + closer.Y);
    return closer;
  }
  /**
   * Determine the current top window center and return this as a point.
   *
   * @return a point representing the sheet center.
   */
  protected Point getSheetCenter() {
    log.println("Trying to get AccessibleSpreadsheet");
    new AccessibilityTools();
    XComponent xSheetDoc = (XComponent) tEnv.getObjRelation("DOCUMENT");

    XModel xModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
    System.out.println("Name: " + xModel.getCurrentController().getFrame().getName());

    XWindow xWindow = AccessibilityTools.getCurrentWindow(xModel);
    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    XAccessibleContext ctx =
        AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);

    XAccessibleComponent AccessibleSpreadsheet =
        UnoRuntime.queryInterface(XAccessibleComponent.class, ctx);

    log.println("Got " + util.utils.getImplName(AccessibleSpreadsheet));

    Object toolkit = null;

    try {
      toolkit = tParam.getMSF().createInstance("com.sun.star.awt.Toolkit");
    } catch (com.sun.star.uno.Exception e) {
      log.println("Couldn't get toolkit");
      e.printStackTrace(log);
      throw new StatusException("Couldn't get toolkit", e);
    }

    XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class, toolkit);

    XTopWindow tw = null;

    int k = tk.getTopWindowCount();
    for (int i = 0; i < k; i++) {
      try {
        XTopWindow tw_temp = tk.getTopWindow(i);
        XAccessible xacc = UnoRuntime.queryInterface(XAccessible.class, tw_temp);
        if (xacc != null) {
          if (xacc.getAccessibleContext().getAccessibleName().indexOf("d2") > 0) {
            tw = tw_temp;
          }
        } else {
          log.println("\t unknown window");
        }

      } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
      }
    }
    if (tw == null) {
      System.out.println("No TopWindow :-(");
      return null;
    }

    Point point = AccessibleSpreadsheet.getLocationOnScreen();
    Rectangle rect = AccessibleSpreadsheet.getBounds();
    Point retPoint = new Point();
    retPoint.X = point.X + (rect.Width / 2);
    retPoint.Y = point.Y + (rect.Height / 2);
    return retPoint;
  }