Пример #1
0
        /// <summary>
        /// Lays out the specified container using this card layout.
        /// <para>
        /// Each component in the <code>parent</code> container is reshaped
        /// to be the size of the container, minus space for surrounding
        /// insets, horizontal gaps, and vertical gaps.
        ///
        /// </para>
        /// </summary>
        /// <param name="parent"> the parent container in which to do the layout </param>
        /// <seealso cref=       java.awt.Container#doLayout </seealso>
        public virtual void LayoutContainer(Container parent)
        {
            lock (parent.TreeLock)
            {
                Insets    insets       = parent.Insets;
                int       ncomponents  = parent.ComponentCount;
                Component comp         = null;
                bool      currentFound = false;

                for (int i = 0; i < ncomponents; i++)
                {
                    comp = parent.GetComponent(i);
                    comp.SetBounds(Hgap_Renamed + insets.Left, Vgap_Renamed + insets.Top, parent.Width_Renamed - (Hgap_Renamed * 2 + insets.Left + insets.Right), parent.Height_Renamed - (Vgap_Renamed * 2 + insets.Top + insets.Bottom));
                    if (comp.Visible)
                    {
                        currentFound = true;
                    }
                }

                if (!currentFound && ncomponents > 0)
                {
                    parent.GetComponent(0).Visible = true;
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Flips to the component that was added to this layout with the
 /// specified <code>name</code>, using <code>addLayoutComponent</code>.
 /// If no such component exists, then nothing happens. </summary>
 /// <param name="parent">   the parent container in which to do the layout </param>
 /// <param name="name">     the component name </param>
 /// <seealso cref=       java.awt.CardLayout#addLayoutComponent(java.awt.Component, java.lang.Object) </seealso>
 public virtual void Show(Container parent, String name)
 {
     lock (parent.TreeLock)
     {
         CheckLayout(parent);
         Component next        = null;
         int       ncomponents = Vector.Count;
         for (int i = 0; i < ncomponents; i++)
         {
             Card card = (Card)Vector[i];
             if (card.Name.Equals(name))
             {
                 next        = card.Comp;
                 CurrentCard = i;
                 break;
             }
         }
         if ((next != null) && !next.Visible)
         {
             ncomponents = parent.ComponentCount;
             for (int i = 0; i < ncomponents; i++)
             {
                 Component comp = parent.GetComponent(i);
                 if (comp.Visible)
                 {
                     comp.Visible = false;
                     break;
                 }
             }
             next.Visible = true;
             parent.Validate();
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Calculates the minimum size for the specified panel. </summary>
        /// <param name="parent"> the parent container in which to do the layout </param>
        /// <returns>    the minimum dimensions required to lay out the
        ///                subcomponents of the specified container </returns>
        /// <seealso cref=       java.awt.Container#doLayout </seealso>
        /// <seealso cref=       java.awt.CardLayout#preferredLayoutSize </seealso>
        public virtual Dimension MinimumLayoutSize(Container parent)
        {
            lock (parent.TreeLock)
            {
                Insets insets      = parent.Insets;
                int    ncomponents = parent.ComponentCount;
                int    w           = 0;
                int    h           = 0;

                for (int i = 0; i < ncomponents; i++)
                {
                    Component comp = parent.GetComponent(i);
                    Dimension d    = comp.MinimumSize;
                    if (d.Width_Renamed > w)
                    {
                        w = d.Width_Renamed;
                    }
                    if (d.Height_Renamed > h)
                    {
                        h = d.Height_Renamed;
                    }
                }
                return(new Dimension(insets.Left + insets.Right + w + Hgap_Renamed * 2, insets.Top + insets.Bottom + h + Vgap_Renamed * 2));
            }
        }
Пример #4
0
        /// <summary>
        /// Determines the minimum size of the container argument using this
        /// grid layout.
        /// <para>
        /// The minimum width of a grid layout is the largest minimum width
        /// of all of the components in the container times the number of columns,
        /// plus the horizontal padding times the number of columns minus one,
        /// plus the left and right insets of the target container.
        /// </para>
        /// <para>
        /// The minimum height of a grid layout is the largest minimum height
        /// of all of the components in the container times the number of rows,
        /// plus the vertical padding times the number of rows minus one, plus
        /// the top and bottom insets of the target container.
        ///
        /// </para>
        /// </summary>
        /// <param name="parent">   the container in which to do the layout </param>
        /// <returns>      the minimum dimensions needed to lay out the
        ///                      subcomponents of the specified container </returns>
        /// <seealso cref=         java.awt.GridLayout#preferredLayoutSize </seealso>
        /// <seealso cref=         java.awt.Container#doLayout </seealso>
        public virtual Dimension MinimumLayoutSize(Container parent)
        {
            lock (parent.TreeLock)
            {
                Insets insets      = parent.Insets;
                int    ncomponents = parent.ComponentCount;
                int    nrows       = Rows_Renamed;
                int    ncols       = Cols;

                if (nrows > 0)
                {
                    ncols = (ncomponents + nrows - 1) / nrows;
                }
                else
                {
                    nrows = (ncomponents + ncols - 1) / ncols;
                }
                int w = 0;
                int h = 0;
                for (int i = 0; i < ncomponents; i++)
                {
                    Component comp = parent.GetComponent(i);
                    Dimension d    = comp.MinimumSize;
                    if (w < d.Width_Renamed)
                    {
                        w = d.Width_Renamed;
                    }
                    if (h < d.Height_Renamed)
                    {
                        h = d.Height_Renamed;
                    }
                }
                return(new Dimension(insets.Left + insets.Right + ncols * w + (ncols - 1) * Hgap_Renamed, insets.Top + insets.Bottom + nrows * h + (nrows - 1) * Vgap_Renamed));
            }
        }
Пример #5
0
 internal virtual void ShowDefaultComponent(Container parent)
 {
     if (parent.ComponentCount > 0)
     {
         CurrentCard = 0;
         parent.GetComponent(0).Visible = true;
         parent.Validate();
     }
 }
Пример #6
0
 /// <summary>
 /// Flips to the previous card of the specified container. If the
 /// currently visible card is the first one, this method flips to the
 /// last card in the layout. </summary>
 /// <param name="parent">   the parent container in which to do the layout </param>
 /// <seealso cref=       java.awt.CardLayout#next </seealso>
 public virtual void Previous(Container parent)
 {
     lock (parent.TreeLock)
     {
         CheckLayout(parent);
         int ncomponents = parent.ComponentCount;
         for (int i = 0; i < ncomponents; i++)
         {
             Component comp = parent.GetComponent(i);
             if (comp.Visible)
             {
                 comp.Visible = false;
                 CurrentCard  = ((i > 0) ? i - 1 : ncomponents - 1);
                 comp         = parent.GetComponent(CurrentCard);
                 comp.Visible = true;
                 parent.Validate();
                 return;
             }
         }
         ShowDefaultComponent(parent);
     }
 }
Пример #7
0
 /// <summary>
 /// Flips to the last card of the container. </summary>
 /// <param name="parent">   the parent container in which to do the layout </param>
 /// <seealso cref=       java.awt.CardLayout#first </seealso>
 public virtual void Last(Container parent)
 {
     lock (parent.TreeLock)
     {
         CheckLayout(parent);
         int ncomponents = parent.ComponentCount;
         for (int i = 0; i < ncomponents; i++)
         {
             Component comp = parent.GetComponent(i);
             if (comp.Visible)
             {
                 comp.Visible = false;
                 break;
             }
         }
         if (ncomponents > 0)
         {
             CurrentCard = ncomponents - 1;
             parent.GetComponent(CurrentCard).Visible = true;
             parent.Validate();
         }
     }
 }
Пример #8
0
        /// <summary>
        /// Returns the minimum dimensions needed to layout the <i>visible</i>
        /// components contained in the specified target container. </summary>
        /// <param name="target"> the container that needs to be laid out </param>
        /// <returns>    the minimum dimensions to lay out the
        ///            subcomponents of the specified container </returns>
        /// <seealso cref= #preferredLayoutSize </seealso>
        /// <seealso cref=       java.awt.Container </seealso>
        /// <seealso cref=       java.awt.Container#doLayout </seealso>
        public virtual Dimension MinimumLayoutSize(Container target)
        {
            lock (target.TreeLock)
            {
                bool      useBaseline           = AlignOnBaseline;
                Dimension dim                   = new Dimension(0, 0);
                int       nmembers              = target.ComponentCount;
                int       maxAscent             = 0;
                int       maxDescent            = 0;
                bool      firstVisibleComponent = true;

                for (int i = 0; i < nmembers; i++)
                {
                    Component m = target.GetComponent(i);
                    if (m.Visible_Renamed)
                    {
                        Dimension d = m.MinimumSize;
                        dim.Height_Renamed = System.Math.Max(dim.Height_Renamed, d.Height_Renamed);
                        if (firstVisibleComponent)
                        {
                            firstVisibleComponent = false;
                        }
                        else
                        {
                            dim.Width_Renamed += Hgap_Renamed;
                        }
                        dim.Width_Renamed += d.Width_Renamed;
                        if (useBaseline)
                        {
                            int baseline = m.GetBaseline(d.Width_Renamed, d.Height_Renamed);
                            if (baseline >= 0)
                            {
                                maxAscent  = System.Math.Max(maxAscent, baseline);
                                maxDescent = System.Math.Max(maxDescent, dim.Height_Renamed - baseline);
                            }
                        }
                    }
                }

                if (useBaseline)
                {
                    dim.Height_Renamed = System.Math.Max(maxAscent + maxDescent, dim.Height_Renamed);
                }

                Insets insets = target.Insets;
                dim.Width_Renamed  += insets.Left + insets.Right + Hgap_Renamed * 2;
                dim.Height_Renamed += insets.Top + insets.Bottom + Vgap_Renamed * 2;
                return(dim);
            }
        }
Пример #9
0
        /// <summary>
        /// Lays out the specified container using this layout.
        /// <para>
        /// This method reshapes the components in the specified target
        /// container in order to satisfy the constraints of the
        /// <code>GridLayout</code> object.
        /// </para>
        /// <para>
        /// The grid layout manager determines the size of individual
        /// components by dividing the free space in the container into
        /// equal-sized portions according to the number of rows and columns
        /// in the layout. The container's free space equals the container's
        /// size minus any insets and any specified horizontal or vertical
        /// gap. All components in a grid layout are given the same size.
        ///
        /// </para>
        /// </summary>
        /// <param name="parent">   the container in which to do the layout </param>
        /// <seealso cref=        java.awt.Container </seealso>
        /// <seealso cref=        java.awt.Container#doLayout </seealso>
        public virtual void LayoutContainer(Container parent)
        {
            lock (parent.TreeLock)
            {
                Insets insets      = parent.Insets;
                int    ncomponents = parent.ComponentCount;
                int    nrows       = Rows_Renamed;
                int    ncols       = Cols;
                bool   ltr         = parent.ComponentOrientation.LeftToRight;

                if (ncomponents == 0)
                {
                    return;
                }
                if (nrows > 0)
                {
                    ncols = (ncomponents + nrows - 1) / nrows;
                }
                else
                {
                    nrows = (ncomponents + ncols - 1) / ncols;
                }
                // 4370316. To position components in the center we should:
                // 1. get an amount of extra space within Container
                // 2. incorporate half of that value to the left/top position
                // Note that we use trancating division for widthOnComponent
                // The reminder goes to extraWidthAvailable
                int totalGapsWidth      = (ncols - 1) * Hgap_Renamed;
                int widthWOInsets       = parent.Width_Renamed - (insets.Left + insets.Right);
                int widthOnComponent    = (widthWOInsets - totalGapsWidth) / ncols;
                int extraWidthAvailable = (widthWOInsets - (widthOnComponent * ncols + totalGapsWidth)) / 2;

                int totalGapsHeight      = (nrows - 1) * Vgap_Renamed;
                int heightWOInsets       = parent.Height_Renamed - (insets.Top + insets.Bottom);
                int heightOnComponent    = (heightWOInsets - totalGapsHeight) / nrows;
                int extraHeightAvailable = (heightWOInsets - (heightOnComponent * nrows + totalGapsHeight)) / 2;
                if (ltr)
                {
                    for (int c = 0, x = insets.Left + extraWidthAvailable; c < ncols; c++, x += widthOnComponent + Hgap_Renamed)
                    {
                        for (int r = 0, y = insets.Top + extraHeightAvailable; r < nrows; r++, y += heightOnComponent + Vgap_Renamed)
                        {
                            int i = r * ncols + c;
                            if (i < ncomponents)
                            {
                                parent.GetComponent(i).SetBounds(x, y, widthOnComponent, heightOnComponent);
                            }
                        }
                    }
                }
                else
                {
                    for (int c = 0, x = (parent.Width_Renamed - insets.Right - widthOnComponent) - extraWidthAvailable; c < ncols; c++, x -= widthOnComponent + Hgap_Renamed)
                    {
                        for (int r = 0, y = insets.Top + extraHeightAvailable; r < nrows; r++, y += heightOnComponent + Vgap_Renamed)
                        {
                            int i = r * ncols + c;
                            if (i < ncomponents)
                            {
                                parent.GetComponent(i).SetBounds(x, y, widthOnComponent, heightOnComponent);
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Lays out the container. This method lets each
        /// <i>visible</i> component take
        /// its preferred size by reshaping the components in the
        /// target container in order to satisfy the alignment of
        /// this <code>FlowLayout</code> object.
        /// </summary>
        /// <param name="target"> the specified component being laid out </param>
        /// <seealso cref= Container </seealso>
        /// <seealso cref=       java.awt.Container#doLayout </seealso>
        public virtual void LayoutContainer(Container target)
        {
            lock (target.TreeLock)
            {
                Insets insets = target.Insets;
                int    maxwidth = target.Width_Renamed - (insets.Left + insets.Right + Hgap_Renamed * 2);
                int    nmembers = target.ComponentCount;
                int    x = 0, y = insets.Top + Vgap_Renamed;
                int    rowh = 0, start = 0;

                bool ltr = target.ComponentOrientation.LeftToRight;

                bool  useBaseline = AlignOnBaseline;
                int[] ascent      = null;
                int[] descent     = null;

                if (useBaseline)
                {
                    ascent  = new int[nmembers];
                    descent = new int[nmembers];
                }

                for (int i = 0; i < nmembers; i++)
                {
                    Component m = target.GetComponent(i);
                    if (m.Visible)
                    {
                        Dimension d = m.PreferredSize;
                        m.SetSize(d.Width_Renamed, d.Height_Renamed);

                        if (useBaseline)
                        {
                            int baseline = m.GetBaseline(d.Width_Renamed, d.Height_Renamed);
                            if (baseline >= 0)
                            {
                                ascent[i]  = baseline;
                                descent[i] = d.Height_Renamed - baseline;
                            }
                            else
                            {
                                ascent[i] = -1;
                            }
                        }
                        if ((x == 0) || ((x + d.Width_Renamed) <= maxwidth))
                        {
                            if (x > 0)
                            {
                                x += Hgap_Renamed;
                            }
                            x   += d.Width_Renamed;
                            rowh = System.Math.Max(rowh, d.Height_Renamed);
                        }
                        else
                        {
                            rowh  = MoveComponents(target, insets.Left + Hgap_Renamed, y, maxwidth - x, rowh, start, i, ltr, useBaseline, ascent, descent);
                            x     = d.Width_Renamed;
                            y    += Vgap_Renamed + rowh;
                            rowh  = d.Height_Renamed;
                            start = i;
                        }
                    }
                }
                MoveComponents(target, insets.Left + Hgap_Renamed, y, maxwidth - x, rowh, start, nmembers, ltr, useBaseline, ascent, descent);
            }
        }
Пример #11
0
        /// <summary>
        /// Centers the elements in the specified row, if there is any slack. </summary>
        /// <param name="target"> the component which needs to be moved </param>
        /// <param name="x"> the x coordinate </param>
        /// <param name="y"> the y coordinate </param>
        /// <param name="width"> the width dimensions </param>
        /// <param name="height"> the height dimensions </param>
        /// <param name="rowStart"> the beginning of the row </param>
        /// <param name="rowEnd"> the the ending of the row </param>
        /// <param name="useBaseline"> Whether or not to align on baseline. </param>
        /// <param name="ascent"> Ascent for the components. This is only valid if
        ///               useBaseline is true. </param>
        /// <param name="descent"> Ascent for the components. This is only valid if
        ///               useBaseline is true. </param>
        /// <returns> actual row height </returns>
        private int MoveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd, bool ltr, bool useBaseline, int[] ascent, int[] descent)
        {
            switch (NewAlign)
            {
            case LEFT:
                x += ltr ? 0 : width;
                break;

            case CENTER:
                x += width / 2;
                break;

            case RIGHT:
                x += ltr ? width : 0;
                break;

            case LEADING:
                break;

            case TRAILING:
                x += width;
                break;
            }
            int maxAscent         = 0;
            int nonbaselineHeight = 0;
            int baselineOffset    = 0;

            if (useBaseline)
            {
                int maxDescent = 0;
                for (int i = rowStart; i < rowEnd; i++)
                {
                    Component m = target.GetComponent(i);
                    if (m.Visible_Renamed)
                    {
                        if (ascent[i] >= 0)
                        {
                            maxAscent  = System.Math.Max(maxAscent, ascent[i]);
                            maxDescent = System.Math.Max(maxDescent, descent[i]);
                        }
                        else
                        {
                            nonbaselineHeight = System.Math.Max(m.Height, nonbaselineHeight);
                        }
                    }
                }
                height         = System.Math.Max(maxAscent + maxDescent, nonbaselineHeight);
                baselineOffset = (height - maxAscent - maxDescent) / 2;
            }
            for (int i = rowStart; i < rowEnd; i++)
            {
                Component m = target.GetComponent(i);
                if (m.Visible)
                {
                    int cy;
                    if (useBaseline && ascent[i] >= 0)
                    {
                        cy = y + baselineOffset + maxAscent - ascent[i];
                    }
                    else
                    {
                        cy = y + (height - m.Height_Renamed) / 2;
                    }
                    if (ltr)
                    {
                        m.SetLocation(x, cy);
                    }
                    else
                    {
                        m.SetLocation(target.Width_Renamed - x - m.Width_Renamed, cy);
                    }
                    x += m.Width_Renamed + Hgap_Renamed;
                }
            }
            return(height);
        }