Пример #1
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);
            }
        }
Пример #2
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);
            }
        }