Beispiel #1
0
  @Override
  protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
    SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF());

    log.println("creating a textdocument");
    xTextDoc = SOF.createTextDoc(null);

    log.println("maximize the window size");
    XModel xModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
    XFrame xFrame = xModel.getCurrentController().getFrame();
    XWindow xWin = xFrame.getContainerWindow();

    Toolkit.getDefaultToolkit();
    Dimension dim = new Dimension(800, 600);

    Rectangle newPosSize = xWin.getPosSize();
    newPosSize.Width = new Double(dim.getWidth()).intValue();
    newPosSize.Height = new Double(dim.getHeight()).intValue();
    newPosSize.X = 0;
    newPosSize.Y = 0;

    xWin.setPosSize(
        newPosSize.X,
        newPosSize.Y,
        newPosSize.Width,
        newPosSize.Height,
        com.sun.star.awt.PosSize.POSSIZE);
  }
  /**
   * 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;
  }