Ejemplo n.º 1
0
    /**
     * This method clicks into the middle of a document. It uses Accessibility to get the document
     * and query for its position and its range to calculate the middle. This values was used for
     * <CODE>Robot</CODE> Class. This Robot class is able to move the mouse and to click a mouse
     * button
     *
     * @see java.awt.Robot
     */
    private void clickIntoDoc() {
      try {
        // get the position and the range of a scroll bar

        XWindow xWindow = AccessibilityTools.getCurrentWindow(xModel);

        XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

        XAccessibleContext xPanel =
            AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
        XAccessibleComponent xPanelCont =
            UnoRuntime.queryInterface(XAccessibleComponent.class, xPanel);

        // the position of the panel
        Point point = xPanelCont.getLocationOnScreen();

        // the range of the panel
        Rectangle rect = xPanelCont.getBounds();

        try {
          Robot rob = new Robot();
          int x = point.X + (rect.Width / 2);
          int y = point.Y + (rect.Height / 2);
          System.out.println("try to click into the middle of the document");
          rob.mouseMove(x, y);
          rob.mousePress(InputEvent.BUTTON1_MASK);
          rob.mouseRelease(InputEvent.BUTTON1_MASK);
        } catch (java.awt.AWTException e) {
          System.out.println("couldn't press mouse button");
        }
      } catch (java.lang.Exception e) {
        System.out.println("could not click into the scroll bar: " + e.toString());
      }
    }
  /**
   * Called to create an instance of <code>TestEnvironment</code> with an object to test and related
   * objects. Creates a frame and inserts it into document. Obtains accessible object for the
   * inserted text frame.
   *
   * @param Param test parameters
   * @param log writer to log information while testing
   * @see TestEnvironment
   * @see #getTestEnvironment
   */
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {

    XInterface oObj = null;
    XTextFrame oFrame1 = null;
    XPropertySet oPropSet = null;
    XText oText = null;
    XTextCursor oCursor = null;

    // get a soffice factory object
    SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) Param.getMSF());
    // creating Frames
    log.println("creating Frames");
    try {
      oFrame1 = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
      oPropSet = UnoRuntime.queryInterface(XPropertySet.class, oFrame1);
      oPropSet.setPropertyValue("AnchorType", TextContentAnchorType.AS_CHARACTER);
      oText = xTextDoc.getText();
      oCursor = oText.createTextCursor();

      log.println("inserting Frame1");
      XTextContent the_content = UnoRuntime.queryInterface(XTextContent.class, oFrame1);
      oText.insertTextContent(oCursor, the_content, true);
    } catch (Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't insert TextFrame", e);
    }

    XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);

    AccessibilityTools at = new AccessibilityTools();

    XWindow xWindow =
        AccessibilityTools.getCurrentWindow((XMultiServiceFactory) Param.getMSF(), aModel);
    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);

    log.println("ImplementationName " + utils.getImplName(oObj));
    AccessibilityTools.printAccessibleTree(
        log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

    TestEnvironment tEnv = new TestEnvironment(oObj);

    XController xController = xTextDoc.getCurrentController();
    XViewSettingsSupplier xViewSetSup =
        UnoRuntime.queryInterface(XViewSettingsSupplier.class, xController);

    final XPropertySet PropSet = xViewSetSup.getViewSettings();

    tEnv.addObjRelation(
        "EventProducer",
        new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
          public void fireEvent() {
            try {
              // change zoom value to 15%
              PropSet.setPropertyValue("ZoomValue", new Short("15"));
              // and back to 100%
              PropSet.setPropertyValue("ZoomValue", new Short("100"));
            } catch (com.sun.star.lang.WrappedTargetException e) {

            } catch (com.sun.star.lang.IllegalArgumentException e) {

            } catch (com.sun.star.beans.PropertyVetoException e) {

            } catch (com.sun.star.beans.UnknownPropertyException e) {

            }
          }
        });

    return tEnv;
  }
Ejemplo n.º 3
0
  /**
   * 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;
  }