Ejemplo n.º 1
0
  protected boolean compareProperties(XPropertySet props1, XPropertySet props2) {

    Property[] p1 = props1.getPropertySetInfo().getProperties();
    Property[] p2 = props2.getPropertySetInfo().getProperties();

    if (p1.length != p2.length) {
      log.println("Number of properties differs");
      return false;
    }

    boolean result = true;

    for (int i = 0; i < p1.length; i++) {
      String propName = p1[i].Name;

      log.print("Comparing property '" + propName + "' ...");
      boolean res = false;
      try {
        res =
            ValueComparer.equalValue(
                props1.getPropertyValue(propName), props2.getPropertyValue(propName));
      } catch (com.sun.star.beans.UnknownPropertyException e) {
        log.println("Not found !");
      } catch (com.sun.star.lang.WrappedTargetException e) {
        log.println(e);
      }

      if (res) log.println("OK.");
      else log.println("Different !");

      result &= res;
    }

    return result;
  }
Ejemplo n.º 2
0
  @Override
  public void handle(Object aFormComponent) throws com.sun.star.uno.Exception {
    // check if it's a button
    XPropertySet xProps = UNO.queryPropertySet(aFormComponent);
    XPropertySetInfo xPI = null;
    if (null != xProps) xPI = xProps.getPropertySetInfo();
    if ((null != xPI) && xPI.hasPropertyByName("ClassId")) {
      Short nClassId = (Short) xProps.getPropertyValue("ClassId");
      if (FormComponentType.COMMANDBUTTON == nClassId.shortValue()) {
        // yes, it is
        m_aOperator.revokeButton(xProps);
      }
    }

    // let the super class step down the tree (if possible)
    super.handle(aFormComponent);
  }
Ejemplo n.º 3
0
  /**
   * creates a control in the document
   *
   * <p>Note that <em>control<em> here is an incorrect terminology. What the method really does is
   * it creates a control shape, together with a control model, and inserts them into the document
   * model. This will result in every view to this document creating a control described by the
   * model-shape pair.
   *
   * @param sFormComponentService the service name of the form component to create, e.g. "TextField"
   * @param nXPos the abscissa of the position of the newly inserted shape
   * @param nXPos the ordinate of the position of the newly inserted shape
   * @param nWidth the width of the newly inserted shape
   * @param nHeight the height of the newly inserted shape
   * @param xParentForm the form to use as parent for the newly create form component. May be null,
   *     in this case a default parent is chosen by the implementation
   * @return the property access to the control's model
   */
  protected XPropertySet createControlAndShape(
      String sFormComponentService,
      int nXPos,
      int nYPos,
      int nWidth,
      int nHeight,
      XIndexContainer xParentForm)
      throws java.lang.Exception {
    // let the document create a shape
    XMultiServiceFactory xDocAsFactory =
        UnoRuntime.queryInterface(XMultiServiceFactory.class, m_document.getDocument());
    XControlShape xShape =
        UnoRuntime.queryInterface(
            XControlShape.class, xDocAsFactory.createInstance("com.sun.star.drawing.ControlShape"));

    // position and size of the shape
    xShape.setSize(new Size(nWidth * 100, nHeight * 100));
    xShape.setPosition(new Point(nXPos * 100, nYPos * 100));

    // adjust the anchor so that the control is tied to the page
    XPropertySet xShapeProps = UNO.queryPropertySet(xShape);
    TextContentAnchorType eAnchorType = TextContentAnchorType.AT_PARAGRAPH;
    xShapeProps.setPropertyValue("AnchorType", eAnchorType);

    // create the form component (the model of a form control)
    String sQualifiedComponentName = "com.sun.star.form.component." + sFormComponentService;
    XControlModel xModel =
        UnoRuntime.queryInterface(
            XControlModel.class, m_document.getOrb().createInstance(sQualifiedComponentName));

    // insert the model into the form component hierarchy, if the caller gave us a location
    if (null != xParentForm) {
      xParentForm.insertByIndex(xParentForm.getCount(), xModel);
    }

    // knitt them
    xShape.setControl(xModel);

    // add the shape to the shapes collection of the document
    XDrawPage pageWhereToInsert =
        (m_insertPage != -1) ? m_document.getDrawPage(m_insertPage) : m_document.getMainDrawPage();

    XShapes xDocShapes = UnoRuntime.queryInterface(XShapes.class, pageWhereToInsert);
    xDocShapes.add(xShape);

    // some initializations which are the same for all controls
    XPropertySet xModelProps = UNO.queryPropertySet(xModel);
    try {
      XPropertySetInfo xPSI = xModelProps.getPropertySetInfo();
      if (xPSI.hasPropertyByName("Border")) {
        if (((Short) xModelProps.getPropertyValue("Border")).shortValue()
            == com.sun.star.awt.VisualEffect.LOOK3D)
          xModelProps.setPropertyValue("Border", Short.valueOf(com.sun.star.awt.VisualEffect.FLAT));
      }
      if (xPSI.hasPropertyByName("VisualEffect"))
        xModelProps.setPropertyValue(
            "VisualEffect", Short.valueOf(com.sun.star.awt.VisualEffect.FLAT));
      if (m_document.classify() != DocumentType.CALC)
        if (xPSI.hasPropertyByName("BorderColor"))
          xModelProps.setPropertyValue("BorderColor", Integer.valueOf(0x00C0C0C0));
    } catch (com.sun.star.uno.Exception e) {
      System.err.println(e);
      e.printStackTrace(System.err);
    }
    return xModelProps;
  }