예제 #1
0
  /**
   * Retrieves the start range and sets its context to 'Start' string.
   *
   * <p>Has <b>OK</b> status if the whole range string starts with 'Start' substring.
   *
   * <p>The following method tests are to be completed successfully before :
   *
   * <ul>
   *   <li><code> setString </code>
   * </ul>
   */
  public void _getStart() {

    XText the_text = (XText) tEnv.getObjRelation("XTEXT");

    if (the_text != null) {
      the_text.setString("");
    }

    String exp = "";

    oObj.setString("MiddleEnd");

    oStartRange = oObj.getStart();
    oStartRange.setString("Start");

    if (the_text != null) {
      exp = the_text.getString();
    } else exp = oObj.getText().getString();

    log.println("Start: " + exp);

    tRes.tested("getStart()", oStartRange != null && exp.startsWith("Start"));

    oStartRange.setString("");
  }
예제 #2
0
  public void drawOrganigram() throws java.lang.Exception {
    // get the remote office component context
    xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
    System.out.println("Connected to a running office ...");
    // get the remote service manager
    xRemoteServiceManager = xRemoteContext.getServiceManager();

    Object desktop =
        xRemoteServiceManager.createInstanceWithContext(
            "com.sun.star.frame.Desktop", xRemoteContext);
    XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop);

    PropertyValue[] loadProps = new PropertyValue[0];
    XComponent xDrawComponent =
        xComponentLoader.loadComponentFromURL("private:factory/sdraw", "_blank", 0, loadProps);

    // get draw page by index
    com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier =
        UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent);
    com.sun.star.drawing.XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
    Object drawPage = xDrawPages.getByIndex(0);
    com.sun.star.drawing.XDrawPage xDrawPage =
        UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, drawPage);

    com.sun.star.lang.XMultiServiceFactory xDocumentFactory =
        UnoRuntime.queryInterface(com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent);

    com.sun.star.beans.XPropertySet xPageProps =
        UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xDrawPage);

    int pageWidth = AnyConverter.toInt(xPageProps.getPropertyValue("Width"));
    int pageHeight = AnyConverter.toInt(xPageProps.getPropertyValue("Height"));
    int pageBorderTop = AnyConverter.toInt(xPageProps.getPropertyValue("BorderTop"));
    int pageBorderLeft = AnyConverter.toInt(xPageProps.getPropertyValue("BorderLeft"));
    int pageBorderRight = AnyConverter.toInt(xPageProps.getPropertyValue("BorderRight"));
    int drawWidth = pageWidth - pageBorderLeft - pageBorderRight;
    int horCenter = pageBorderLeft + drawWidth / 2;

    String[][] orgUnits = new String[2][4];
    orgUnits[0][0] = "Management";
    orgUnits[1][0] = "Production";
    orgUnits[1][1] = "Purchasing";
    orgUnits[1][2] = "IT Services";
    orgUnits[1][3] = "Sales";
    int[] levelCount = {1, 4};

    int horSpace = 300;
    int verSpace = 3000;

    int shapeWidth = (drawWidth - (levelCount[1] - 1) * horSpace) / levelCount[1];
    int shapeHeight = pageHeight / 20;
    int shapeX = pageWidth / 2 - shapeWidth / 2;
    int shapeY = pageBorderTop;

    int levelY;
    int levelX;

    com.sun.star.drawing.XShape xStartShape = null;

    for (int level = 0; level <= 1; level++) {
      levelY = pageBorderTop + 2000 + level * (shapeHeight + verSpace);
      for (int i = levelCount[level] - 1; i > -1; i--) {
        shapeX =
            horCenter
                - (levelCount[level] * shapeWidth + (levelCount[level] - 1) * horSpace) / 2
                + i * shapeWidth
                + i * horSpace;
        Object shape = xDocumentFactory.createInstance("com.sun.star.drawing.RectangleShape");
        com.sun.star.drawing.XShape xShape =
            UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, shape);
        xShape.setPosition(new com.sun.star.awt.Point(shapeX, levelY));
        xShape.setSize(new com.sun.star.awt.Size(shapeWidth, shapeHeight));
        xDrawPage.add(xShape);

        com.sun.star.text.XText xText =
            UnoRuntime.queryInterface(com.sun.star.text.XText.class, xShape);

        xText.setString(orgUnits[level][i]);

        // memorize the root shape
        if (level == 0 && i == 0) xStartShape = xShape;

        if (level == 1) {
          Object connector = xDocumentFactory.createInstance("com.sun.star.drawing.ConnectorShape");
          com.sun.star.beans.XPropertySet xConnectorProps =
              UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, connector);
          com.sun.star.drawing.XShape xConnector =
              UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, connector);
          xDrawPage.add(xConnector);
          xConnectorProps.setPropertyValue("StartShape", xStartShape);
          xConnectorProps.setPropertyValue("EndShape", xShape);
          xConnectorProps.setPropertyValue(
              "StartGluePointIndex", new Integer(2)); // 2 = bottom glue point
          xConnectorProps.setPropertyValue(
              "EndGluePointIndex", new Integer(0)); // 0 = top glue point
        }
      }
    }
  }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Retrieves the collection of style
   * families available in the document using the interface <code>XStyleFamiliesSupplier</code>.
   * Obtains default style from the style family <code>'PageStyles'</code>. Retrieves value of the
   * property <code>'RightPageHeaderContent'</code>. Sets some string for the text which is printed
   * in the center part of the header or footer using the interface <code>XHeaderFooterContent
   * </code> and sets new value of the property <code>'RightPageHeaderContent'</code>. Creates text
   * cursor for the text which is printed in the center part of the header or footer. This text
   * cursor is the instance of the service <code>com.sun.star.text.TextCursor</code>.
   * </ul>
   */
  protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {

    XInterface oObj = null;
    XPropertySet PropSet;
    XNameAccess PageStyles = null;
    XStyle StdStyle = null;

    XStyleFamiliesSupplier StyleFam =
        UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xSpreadsheetDoc);

    XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
    try {
      PageStyles =
          (XNameAccess)
              AnyConverter.toObject(
                  new Type(XNameAccess.class), StyleFamNames.getByName("PageStyles"));
      StdStyle =
          (XStyle) AnyConverter.toObject(new Type(XStyle.class), PageStyles.getByName("Default"));
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    } catch (com.sun.star.container.NoSuchElementException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    }

    // get the property-set
    PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);

    XHeaderFooterContent RPHC = null;
    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("creating a test environment");
    try {
      RPHC =
          (XHeaderFooterContent)
              AnyConverter.toObject(
                  new Type(XHeaderFooterContent.class),
                  PropSet.getPropertyValue("RightPageHeaderContent"));
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    }

    XText center = RPHC.getCenterText();
    center.setString("CENTER");

    try {
      PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.beans.PropertyVetoException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    }

    // create testobject here
    oObj = center.createTextCursor();
    TestEnvironment tEnv = new TestEnvironment(oObj);

    // add relation for XTextRange
    tEnv.addObjRelation("XTEXT", UnoRuntime.queryInterface(XText.class, center));

    return tEnv;
  } // finish method getTestEnvironment