Esempio n. 1
0
        /// <summary>
        /// Lays out the container argument using this border layout.
        /// <para>
        /// This method actually reshapes the components in the specified
        /// container in order to satisfy the constraints of this
        /// <code>BorderLayout</code> object. The <code>NORTH</code>
        /// and <code>SOUTH</code> components, if any, are placed at
        /// the top and bottom of the container, respectively. The
        /// <code>WEST</code> and <code>EAST</code> components are
        /// then placed on the left and right, respectively. Finally,
        /// the <code>CENTER</code> object is placed in any remaining
        /// space in the middle.
        /// </para>
        /// <para>
        /// Most applications do not call this method directly. This method
        /// is called when a container calls its <code>doLayout</code> method.
        /// </para>
        /// </summary>
        /// <param name="target">   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 target)
        {
            lock (target.TreeLock)
            {
                Insets insets = target.Insets;
                int    top    = insets.Top;
                int    bottom = target.Height_Renamed - insets.Bottom;
                int    left   = insets.Left;
                int    right  = target.Width_Renamed - insets.Right;

                bool      ltr = target.ComponentOrientation.LeftToRight;
                Component c   = null;

                if ((c = GetChild(NORTH, ltr)) != null)
                {
                    c.SetSize(right - left, c.Height_Renamed);
                    Dimension d = c.PreferredSize;
                    c.SetBounds(left, top, right - left, d.Height_Renamed);
                    top += d.Height_Renamed + Vgap_Renamed;
                }
                if ((c = GetChild(SOUTH, ltr)) != null)
                {
                    c.SetSize(right - left, c.Height_Renamed);
                    Dimension d = c.PreferredSize;
                    c.SetBounds(left, bottom - d.Height_Renamed, right - left, d.Height_Renamed);
                    bottom -= d.Height_Renamed + Vgap_Renamed;
                }
                if ((c = GetChild(EAST, ltr)) != null)
                {
                    c.SetSize(c.Width_Renamed, bottom - top);
                    Dimension d = c.PreferredSize;
                    c.SetBounds(right - d.Width_Renamed, top, d.Width_Renamed, bottom - top);
                    right -= d.Width_Renamed + Hgap_Renamed;
                }
                if ((c = GetChild(WEST, ltr)) != null)
                {
                    c.SetSize(c.Width_Renamed, bottom - top);
                    Dimension d = c.PreferredSize;
                    c.SetBounds(left, top, d.Width_Renamed, bottom - top);
                    left += d.Width_Renamed + Hgap_Renamed;
                }
                if ((c = GetChild(CENTER, ltr)) != null)
                {
                    c.SetBounds(left, top, right - left, bottom - top);
                }
            }
        }
Esempio n. 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);
            }
        }