/**
  * Helper function to get the minor axis
  *
  * @param toOrientation the orintation of the axis
  * @param toDimension the dimension to get the value from
  * @return the minor axis value
  */
 private float getMinorAxis(Orientation toOrientation, Dimension toDimension) {
   return toOrientation.equals(Orientation.HORIZONTAL())
       ? toDimension.getHeight()
       : toDimension.getWidth();
 }
  @Override
  protected void layoutChildren(IContainer toContainer) {
    Dimension loContainerSize = toContainer.getContentSize();
    float lnMajorAxis = getMajorAxis(m_oOrientation, loContainerSize);
    float lnCumulatedMajor = 0;
    float lnCumulatedMinor = 0;
    float lnMaxMinor = 0;
    float lnMaxMajor = 0;
    int lnControlCount = 0;
    float lnMaxWidth = loContainerSize.getWidth();

    // if the Major Axis is zero, then we can change it here, if it is not zero then it can not be
    // changed
    if (lnMajorAxis <= 0) {
      lnMajorAxis = Float.MAX_VALUE;
    }

    // Get the list of contained controls
    List<IControl> loControls = toContainer.getChildren();

    // Loop through all the controls, if alignment is left, then front to back, otherwise back to
    // front
    for (int i = (m_oAlignment == Alignment.LEFT() ? 0 : loControls.size() - 1),
            lnLength = (m_oAlignment == Alignment.LEFT() ? loControls.size() : 0);
        (m_oAlignment == Alignment.LEFT() ? i < lnLength : i >= lnLength);
        i = i + (m_oAlignment == Alignment.LEFT() ? 1 : -1)) {
      IControl loControl = loControls.get(i);

      // If the control does not participate in the layout, don't include it here
      if (!loControl.participatesInLayout()) {
        // TODO: At the time I comment this, all control does not participates in layout
        //                continue;
      }

      // Get the size of this control
      Dimension loSize = getContainedControlDimensions(loControl);
      setContainedControlSize(toContainer, loControl, loSize);

      float lnControlMajor = getMajorAxis(m_oOrientation, loSize);
      float lnControlMinor = getMinorAxis(m_oOrientation, loSize);

      lnMaxMinor = Math.max(lnMaxMinor, lnControlMinor);

      // Check if the control can be placed here or if it needs to be moved
      if (lnCumulatedMajor + lnControlMajor > lnMajorAxis) {
        // The control is too big, if it is not the only control move it to the next position.
        if (lnControlCount == 0) {
          // This is the only control on this axis, so it has to be placed here
          setContainedControlLocation(
              toContainer,
              loControl,
              getAlignedLeft(
                  m_oOrientation.equals(Orientation.HORIZONTAL())
                      ? lnCumulatedMajor
                      : lnCumulatedMinor,
                  lnMaxWidth,
                  loSize.getWidth()),
              m_oOrientation.equals(Orientation.HORIZONTAL())
                  ? lnCumulatedMinor
                  : lnCumulatedMajor);
          lnCumulatedMajor += lnControlMajor;
          lnMajorAxis = lnCumulatedMajor;
          lnMaxMajor = Math.max(lnMaxMajor, lnCumulatedMajor);
          lnControlCount++;
        } else {
          // This needs to be moved to the next position
          lnCumulatedMinor += lnMaxMinor;
          lnCumulatedMajor = 0;

          setContainedControlLocation(
              toContainer,
              loControl,
              getAlignedLeft(
                  m_oOrientation.equals(Orientation.HORIZONTAL())
                      ? lnCumulatedMajor
                      : lnCumulatedMinor,
                  lnMaxWidth,
                  loSize.getWidth()),
              m_oOrientation.equals(Orientation.HORIZONTAL())
                  ? lnCumulatedMinor
                  : lnCumulatedMajor);

          lnCumulatedMajor += lnControlMajor;
          lnMaxMinor = lnControlMinor;
          lnControlCount = 0;
        }
      } else {
        // this control fits
        setContainedControlLocation(
            toContainer,
            loControl,
            getAlignedLeft(
                m_oOrientation.equals(Orientation.HORIZONTAL())
                    ? lnCumulatedMajor
                    : lnCumulatedMinor,
                lnMaxWidth,
                loSize.getWidth()),
            m_oOrientation.equals(Orientation.HORIZONTAL()) ? lnCumulatedMinor : lnCumulatedMajor);

        lnCumulatedMajor += lnControlMajor;
        lnMaxMajor = Math.max(lnMaxMajor, lnCumulatedMajor);
        lnControlCount++;
      }
    }
    lnCumulatedMinor += lnMaxMinor;
  }