Ejemplo n.º 1
0
 /**
  * ------------------------------------------------------ Invalidates the given area of this
  * container that intersects the draw bounds. This intersection is necessary so, for example,
  * changing the text in a textfield does not cause areas outside the textfield to repaint.
  *
  * @param area the area to invalidate
  * @overrides MiPart#invalidateArea
  * @see MiPart#setInvalidAreaNotificationsEnabled
  *     ------------------------------------------------------
  */
 public void invalidateArea(MiBounds area) {
   MiBounds tmpBounds = MiBounds.newBounds();
   getDrawBounds(tmpBounds);
   tmpBounds.intersectionWith(area);
   super.invalidateArea(tmpBounds);
   MiBounds.freeBounds(tmpBounds);
 }
Ejemplo n.º 2
0
 /**
  * ------------------------------------------------------ Constructs a new MiVisibleContainer.
  * ------------------------------------------------------
  */
 public MiVisibleContainer() {
   setInsetMargins(4);
   MiBounds tmpBounds = MiBounds.newBounds();
   tmpBounds.zeroOut();
   tmpBounds.addMargins(getInsetMargins(tmpMargins));
   replaceBounds(tmpBounds);
   setTarget(this);
   setBorderLook(Mi_NONE);
   MiBounds.freeBounds(tmpBounds);
 }
Ejemplo n.º 3
0
  public int processEvent(MiEvent event) {
    if ((event.type == Mi_WINDOW_EXIT_EVENT) || (event.type == Mi_MOUSE_EXIT_EVENT)) {
      setVisible(false);
      visible = false;
    } else if ((event.type != Mi_IDLE_EVENT) && (event.type != Mi_TIMER_TICK_EVENT)) {
      if (!cursorIsAttached) {
        event.editor.appendAttachment(cursor);
        cursorIsAttached = true;
      }

      boolean makeVisible = true;
      if (showOnlyDuringTheseEventStates != null) {
        for (int i = 0; i < showOnlyDuringTheseEventStates.size(); ++i) {
          makeVisible = false;
          MiEvent validEvent = (MiEvent) showOnlyDuringTheseEventStates.get(i);
          if (((validEvent.getModifiers() == event.getModifiers())
                  || (validEvent.getModifiers() == Mi_ANY_MODIFIERS_HELD_DOWN))
              && (validEvent.getMouseButtonState() == event.getMouseButtonState())) {
            makeVisible = true;
            break;
          }
        }
      }
      if (hideDuringTheseEventStates != null) {
        for (int i = 0; i < hideDuringTheseEventStates.size(); ++i) {
          MiEvent validEvent = (MiEvent) hideDuringTheseEventStates.get(i);
          if (((validEvent.getModifiers() == event.getModifiers())
                  || (validEvent.getModifiers() == Mi_ANY_MODIFIERS_HELD_DOWN))
              && (validEvent.getMouseButtonState() == event.getMouseButtonState())) {
            makeVisible = false;
            break;
          }
        }
      }

      if (makeVisible) {
        event.editor.getWorldBounds(editorWorld);
        if ((!event.worldPt.equals(cursorPt)) || (!editorWorld.equals(cursorWorldBounds))) {
          cursorPt.copy(event.worldPt);
          cursorWorldBounds.copy(editorWorld);
          setCursor(cursorPt, cursorWorldBounds);
          if (!visible) {
            setVisible(true);
            visible = true;
          }
        }
      } else {
        setVisible(false);
        visible = false;
      }
    }
    return (Mi_PROPOGATE_EVENT);
  }
Ejemplo n.º 4
0
  public boolean getBounds(MiPart obj, MiBounds b) {
    if (!(obj instanceof MiMultiPointShape)) return (false);

    MiDistance startSize = 0;
    MiDistance endSize = 0;
    MiAttributes attributes = obj.getAttributes();
    boolean changed = false;
    boolean styleExtendsBeyondEndOfLine = false;

    int style = attributes.getLineStartStyle();
    if (style != Mi_NONE) {
      startSize = attributes.getLineStartSize();
      if (attributes.getLineEndsSizeFnOfLineWidth()) startSize += attributes.getLineWidth();

      styleExtendsBeyondEndOfLine |= stylesExtendsBeyondEndOfLine[style];
      changed = true;
    }
    style = attributes.getLineEndStyle();
    if (style != Mi_NONE) {
      endSize = attributes.getLineEndSize();
      if (attributes.getLineEndsSizeFnOfLineWidth()) endSize += attributes.getLineWidth();

      styleExtendsBeyondEndOfLine |= stylesExtendsBeyondEndOfLine[style];
      changed = true;
    }
    if (changed) {
      MiMultiPointShape shape = (MiMultiPointShape) obj;
      MiDistance size = (startSize > endSize) ? startSize : endSize;
      // TEST size = size/2;

      if (styleExtendsBeyondEndOfLine) {
        b.addMargins(size);
      } else if (shape.isVertical()) {
        b.setXmin(b.getXmin() - size);
        b.setXmax(b.getXmax() + size);
      } else if (shape.isHorizontal()) {
        b.setYmin(b.getYmin() - size);
        b.setYmax(b.getYmax() + size);
      } else {
        b.addMargins(size);
      }
    }

    return (changed);
  }
Ejemplo n.º 5
0
  public void doLayout() {
    int num = getTarget().getNumberOfParts();
    for (int i = 0; i < num; ++i) {
      MiPart obj = getTarget().getPart(i);
      if (!obj.hasValidLayout()) {
        // 9-1-2002 added this here because settng a invisible part to visible does
        // not update the obj's bounds and if this obj does not have a layout, then the obj will
        // be scaled larger when it should not be. So we update the bounds manually here.
        // Doing it automatically in MiPart setVisible or updateContainersLayout caused (obvious)
        // problems elsewhere (but this is the way it should be done ... and will be someday)
        obj.refreshBounds();

        obj.getPreferredSize(prefSize);
        obj.getBounds(outerBounds);
        if ((prefSize.width != outerBounds.getWidth())
            || (prefSize.height != outerBounds.getHeight())) {
          obj.setSize(prefSize);
        }
      }
    }
  }
Ejemplo n.º 6
0
 /**
  * ------------------------------------------------------ Gets whether the given area intersects
  * the bounds of this MiPart.
  *
  * @param area the area
  * @return true if the given area overlaps the bounds of this MiPart.
  * @overrides MiPart#pick ------------------------------------------------------
  */
 public boolean pick(MiBounds area) {
   MiBounds tmpBounds = MiBounds.newBounds();
   getBounds(tmpBounds);
   if (!tmpBounds.intersects(area)) {
     MiBounds.freeBounds(tmpBounds);
     return (false);
   }
   if (shape instanceof MiRectangle) {
     MiBounds.freeBounds(tmpBounds);
     return (true);
   }
   tmpBounds.subtractMargins(getMargins(tmpMargins));
   shape.setBounds(tmpBounds);
   MiBounds.freeBounds(tmpBounds);
   return (shape.pick(area));
 }
Ejemplo n.º 7
0
  /**
   * ------------------------------------------------------ Render this container (i.e. the
   * background shape then all of it's parts).
   *
   * @param renderer the renderer to use for drawing
   * @overrides MiContainer#render ------------------------------------------------------
   */
  protected void render(MiRenderer renderer) {
    // -------------------------------------------------------
    // Get the outer bounds of this container, subtract margins
    // from it, then assign these bounds to the background shape.
    // -------------------------------------------------------
    MiBounds tmpBounds1 = MiBounds.newBounds();
    MiBounds tmpBounds2 = MiBounds.newBounds();
    getBounds(tmpBounds1);
    tmpBounds1.subtractMargins(getMargins(tmpMargins));
    if (hasFixedWidthOrHeight) {
      shape.setFixedHeight(false);
      shape.setFixedWidth(false);
    }
    if (shape instanceof MiMultiPointShape) shape.setBounds(tmpBounds1);
    else shape.replaceBounds(tmpBounds1);

    // -------------------------------------------------------
    // Assign this container's attributes to the background shape
    // and then draw the background shape.
    // -------------------------------------------------------
    shape.replaceAttributes(getAttributes());
    if (shape instanceof MiMultiPointShape) shape.refreshBounds();
    else shape.replaceDrawBounds(getDrawBounds(tmpBounds1));

    shape.draw(renderer);

    // -------------------------------------------------------
    // Get the clip bounds from the renderer and then intersect
    // these clip bounds with the inner bounds of this container.
    // If there is such an intersection...
    // But use the _drawBounds_ because shadows (and ?) extend
    // outside the innerBounds.
    // -------------------------------------------------------
    if (!okToDrawOutsideInnerBounds) {
      MiBounds clip = renderer.getClipBounds(tmpBounds1);
      if (getInnerBounds(tmpBounds2).intersectionWith(clip)) {
        // -------------------------------------------------------
        // ... set the clip bounds of the renderer to this
        // intersection bounds, draw this containers contents
        // (in super.render()), then restore the clip bounds of
        // the renderer.
        // -------------------------------------------------------
        renderer.setClipBounds(tmpBounds2);
        super.render(renderer);
        renderer.setClipBounds(clip);
      }
    } else {
      super.render(renderer);
    }
    MiBounds.freeBounds(tmpBounds1);
    MiBounds.freeBounds(tmpBounds2);
  }
Ejemplo n.º 8
0
  /**
   * ------------------------------------------------------ Realculates the outer bounds of this
   * container.
   *
   * @param bounds the (returned) outer bounds
   *     ------------------------------------------------------
   */
  protected void reCalcBounds(MiBounds bounds) {
    getBounds(bounds);

    if (!autoLayoutEnabled) {
      return;
    }

    MiBounds contents = MiBounds.newBounds();
    MiMargins insetMargins = getInsetMargins();
    MiMargins cellMargins = getCellMargins();

    super.reCalcBounds(contents);
    if (contents.isReversed()) {
      contents.copy(bounds);
      if (contents.isReversed()) {
        contents.setBounds(0, 0, 0, 0);
        contents.addMargins(insetMargins);
        contents.addMargins(cellMargins);
        contents.addMargins(getMargins(tmpMargins));
      } else if ((contents.getWidth()
              < insetMargins.getWidth()
                  + getMargins(tmpMargins).getWidth()
                  + cellMargins.getWidth())
          || (contents.getHeight()
              < insetMargins.getHeight()
                  + getMargins(tmpMargins).getHeight()
                  + cellMargins.getHeight())) {
        contents.setWidth(
            insetMargins.getWidth() + getMargins(tmpMargins).getWidth() + cellMargins.getWidth());
        contents.setHeight(
            insetMargins.getHeight()
                + getMargins(tmpMargins).getHeight()
                + cellMargins.getHeight());
      }
      bounds.copy(contents);
    } else {
      // SUPER CLASS DOES THIS contents.addMargins(insetMargins);
      contents.addMargins(cellMargins);
      // SUPER CLASS DOES THIS contents.addMargins(getMargins(tmpMargins));
    }

    if ((autoLayoutRule == MAKE_CONTAINER_SAME_SIZE_AS_CONTENTS)) {
      bounds.copy(contents);
    } else if ((autoLayoutRule == MAKE_CONTAINER_SAME_SIZE_OR_BIGGER_THAN_CONTENTS)) {
      if (!contents.isContainedIn(bounds)) bounds.copy(contents);
    } else if ((autoLayoutRule
        == MAKE_CONTAINER_SAME_SIZE_AS_CONTENTS_OR_OVERRIDDEN_PREFERRED_SIZE)) {
      bounds.copy(contents);
      if (hasOverriddenPreferredSize()) {
        bounds.setSize(getPreferredSize(new MiSize()));
      }
    }

    if (hasFixedWidthOrHeight) {
      getBounds(contents);

      if (hasFixedWidth()) {
        bounds.xmin = contents.xmin;
        bounds.xmax = contents.xmax;
      }
      if (hasFixedHeight()) {
        bounds.ymin = contents.ymin;
        bounds.ymax = contents.ymax;
      }
    }
    MiBounds.freeBounds(contents);
  }
Ejemplo n.º 9
0
  /**
   * ------------------------------------------------------ Lays out the container's parts and it's
   * background shape.
   *
   * @overrides MiLayout.doLayout ------------------------------------------------------
   */
  protected void doLayout() {
    if (!autoLayoutEnabled) return;

    MiBounds contents = MiBounds.newBounds();
    MiBounds oldContents = MiBounds.newBounds();
    MiBounds containerBounds = MiBounds.newBounds();
    MiBounds tmp = MiBounds.newBounds();
    MiSize size = MiSize.newSize();
    // -------------------------------------------------------
    // Iterate through all parts of this container... set their
    // size to their preferredSize if this container does not
    // have a layout which has already done so. Also collect
    // the union of their bounds into 'contents'.
    // -------------------------------------------------------
    for (int i = 0; i < getNumberOfParts(); ++i) {
      if (getPart(i).isVisible()) {
        // -------------------------------------------------------
        // If contents have not already been laid out...
        // -------------------------------------------------------
        if ((getLayout() == null) || (!getLayout().determinesPreferredAndMinimumSizes())) {
          getPart(i).getPreferredSize(size);
          getPart(i).setSize(size);
        }
        getPart(i).getBounds(tmp);
        contents.union(tmp);
      }
    }

    // -------------------------------------------------------
    // Set 'oldContents' to this current bounds of all of this
    // container's parts. This will be used later to see it
    // we have changed the size of this container. 'contents'
    // will be modified by this layout routine as per the layout
    // constraints applied to this container.
    // -------------------------------------------------------
    oldContents.copy(contents);

    // -------------------------------------------------------
    // Get the inner bounds of this container into 'container'.
    // -------------------------------------------------------
    MiBounds container = getInnerBounds(containerBounds);
    if (container.isReversed()) {
      getPreferredSize(size);
      replaceBounds(new MiBounds(size));
      container = getInnerBounds(containerBounds);
    }

    // -------------------------------------------------------
    // Set the bounds to the center of the inner bounds.
    // -------------------------------------------------------
    contents.setCenterX(container.getCenterX());
    contents.setCenterY(container.getCenterY());

    // -------------------------------------------------------
    // Expand the bounds to the size of the inner bounds, if
    // so specified by the elementSizing contraints.
    // -------------------------------------------------------
    if (getElementHSizing() == Mi_EXPAND_TO_FILL) contents.setWidth(container.getWidth());
    else if (getElementVSizing() == Mi_EXPAND_TO_FILL) contents.setHeight(container.getHeight());

    // -------------------------------------------------------
    // Translate the bounds in a horizontal direction if so
    // specified by the elementHJustification contraint.
    // -------------------------------------------------------
    int elementHJustification = getElementHJustification();
    if (elementHJustification == Mi_LEFT_JUSTIFIED) contents.translateXminTo(container.getXmin());
    else if (elementHJustification == Mi_RIGHT_JUSTIFIED)
      contents.translateXmaxTo(container.getXmax());
    else if (elementHJustification == Mi_CENTER_JUSTIFIED)
      contents.setCenterX(container.getCenterX());
    else if (elementHJustification == Mi_JUSTIFIED) contents.setCenterX(container.getCenterX());

    // -------------------------------------------------------
    // Modify the bounds to stay within the inner bounds as
    // held in the 'container' variable.
    // -------------------------------------------------------
    if (contents.getXmin() < container.getXmin()) contents.translateXminTo(container.getXmin());
    if (contents.getXmax() > container.getXmax()) contents.translateXmaxTo(container.getXmax());
    if (contents.getXmin() < container.getXmin()) contents.setXmin(container.getXmin());

    // -------------------------------------------------------
    // Translate the bounds in a vertical direction if so
    // specified by the elementVJustification contraint.
    // -------------------------------------------------------
    int elementVJustification = getElementVJustification();
    if (elementVJustification == Mi_BOTTOM_JUSTIFIED) contents.translateYminTo(container.getYmin());
    else if (elementVJustification == Mi_TOP_JUSTIFIED)
      contents.translateYmaxTo(container.getYmax());
    else if (elementVJustification == Mi_CENTER_JUSTIFIED)
      contents.setCenterY(container.getCenterY());
    else if (elementVJustification == Mi_JUSTIFIED) contents.setCenterY(container.getCenterY());

    // -------------------------------------------------------
    // Modify the bounds to stay within the inner bounds as
    // held in the 'container' variable.
    // -------------------------------------------------------
    if (container.getYmin() > contents.getYmin()) contents.translateYminTo(container.getYmin());
    if (container.getYmax() < contents.getYmax()) contents.translateYmaxTo(container.getYmax());
    if (container.getYmin() > contents.getYmin()) contents.setYmin(container.getYmin());

    // -------------------------------------------------------
    // If we have changed the bounds in some way...
    // -------------------------------------------------------
    if (!oldContents.equals(contents)) {
      // -------------------------------------------------------
      // Calculate how much we have to translate the parts...
      // -------------------------------------------------------
      MiDistance tx = contents.getCenterX() - oldContents.getCenterX();
      MiDistance ty = contents.getCenterY() - oldContents.getCenterY();
      // -------------------------------------------------------
      // If there are no expand-to-fill contraints...
      // -------------------------------------------------------
      if ((getElementHSizing() != Mi_EXPAND_TO_FILL)
          && (getElementVSizing() != Mi_EXPAND_TO_FILL)) {
        // -------------------------------------------------------
        // Just translate all of the parts and we are done...
        // -------------------------------------------------------
        for (int i = 0; i < getNumberOfParts(); ++i) {
          getPart(i).translate(tx, ty);
        }
      } else {
        // -------------------------------------------------------
        // There is an expand-to-fill contraint, we need to scale
        // the parts... calculate the scale factor for each dimension.
        // -------------------------------------------------------
        MiPoint center = contents.getCenter();
        MiScale scale =
            new MiScale(
                contents.getWidth() / oldContents.getWidth(),
                contents.getHeight() / oldContents.getHeight());
        if (getElementHSizing() != Mi_EXPAND_TO_FILL) scale.x = 1;
        if (getElementVSizing() != Mi_EXPAND_TO_FILL) scale.y = 1;
        // -------------------------------------------------------
        // Iterate through the parts, translating and scaling
        // -------------------------------------------------------
        for (int i = 0; i < getNumberOfParts(); ++i) {
          getPart(i).translate(tx, ty);
          getPart(i).scale(center, scale);
        }
      }
    }
    // -------------------------------------------------------
    // Release all the bounds we allocated above
    // -------------------------------------------------------
    MiBounds.freeBounds(contents);
    MiBounds.freeBounds(oldContents);
    MiBounds.freeBounds(containerBounds);
    MiBounds.freeBounds(tmp);
    MiSize.freeSize(size);
  }
Ejemplo n.º 10
0
  protected void layoutParts(int h_sizing, int v_sizing, int h_justification, int v_justification) {
    if (graphics != null) graphics.getPreferredSize(tmpSize);
    else if (strValue != null) attributes.getFont().getSize(strValue, tmpSize);
    else tmpSize.zeroOut();

    MiBounds cellBounds = MiBounds.newBounds();
    cellBounds.setSize(tmpSize);
    MiBounds theInnerBounds = tmpBounds;
    theInnerBounds.copy(innerBounds);
    if (margins != null) theInnerBounds.subtractMargins(margins);
    cellBounds.setCenterX(theInnerBounds.getCenterX());
    cellBounds.setCenterY(theInnerBounds.getCenterY());
    switch (h_sizing) {
      case Mi_EXPAND_TO_FILL:
        cellBounds.setWidth(theInnerBounds.getWidth());
        break;
      case Mi_SAME_SIZE:
        cellBounds.setWidth(theInnerBounds.getWidth());
        break;
      case Mi_NONE:
      default:
        break;
    }

    switch (v_sizing) {
      case Mi_EXPAND_TO_FILL:
        cellBounds.setHeight(theInnerBounds.getHeight());
        break;
      case Mi_SAME_SIZE:
        cellBounds.setHeight(theInnerBounds.getHeight());
        break;
      case Mi_NONE:
      default:
        break;
    }
    switch (h_justification) {
      case Mi_JUSTIFIED:
      case Mi_CENTER_JUSTIFIED:
      case Mi_NONE:
        cellBounds.setCenterX(theInnerBounds.getCenterX());
        break;
      case Mi_LEFT_JUSTIFIED:
        cellBounds.translateXminTo(theInnerBounds.getXmin());
        break;
      case Mi_RIGHT_JUSTIFIED:
        cellBounds.translateXmaxTo(theInnerBounds.getXmax());
        break;
    }

    switch (v_justification) {
      case Mi_JUSTIFIED:
      case Mi_CENTER_JUSTIFIED:
      case Mi_NONE:
        cellBounds.setCenterY(theInnerBounds.getCenterY());
        break;
      case Mi_BOTTOM_JUSTIFIED:
        cellBounds.translateYminTo(theInnerBounds.getYmin());
        break;
      case Mi_TOP_JUSTIFIED:
        cellBounds.translateYmaxTo(theInnerBounds.getYmax());
        break;
    }

    if (graphics != null) {
      graphics.setBounds(cellBounds);
      if (!graphics.hasValidLayout()) {
        graphics.validateLayout();
      }
    } else {
      innerBounds.copy(cellBounds);
    }
    MiBounds.freeBounds(cellBounds);
  }
Ejemplo n.º 11
0
 public MiBounds getNodeBounds(MiBounds b) {
   b.copy(bounds);
   return (b);
 }