Fix the layout when stretchComponenets==false
and the number of components is not evenly divisible
by the number of cols or rows.
198766
@Override
	public void layoutContainer(Container parent) {
		synchronized (parent.getTreeLock()) {
			Insets insets=parent.getInsets();
			int ncomponents=parent.getComponentCount();
			if(ncomponents==0) return;

			int nrows=rows;
			int ncols=columns;
			if(nrows>0) {
				ncols=((ncomponents/2)+nrows-1)/nrows;
			} else {
				nrows=((ncomponents/2)+ncols-1)/ncols;
			}

			// Determine the desired widths for the labels
			int[] labelWidths=new int[ncols];
			int pos=0;
		Loop1:
			for(int y=0;y<nrows;y++) {
				for(int x=0;x<ncols;x++) {
					if(pos>=ncomponents) break Loop1;
					Component component=parent.getComponent(pos);
					pos+=2;
					Dimension d=component.getPreferredSize();
					if(d.width>labelWidths[x]) labelWidths[x]=d.width;
				}
			}
			Dimension parentSize=parent.getSize();
			int width=parentSize.width-(insets.left+insets.right);
			int height=parentSize.height-(insets.top+insets.bottom);
			int lasty=0;
			pos=0;
		Loop:
			for(int y=0;y<nrows;y++) {
				int yend=0;
				int cellHeight=0;
				if (stretchComponents) {
					yend=((y+1)*(height+vgap))/nrows-vgap;
					cellHeight=yend-lasty;
				}
				int lastx=0;
				for(int x=0;x<ncols;x++) {
					if(pos>=ncomponents) break Loop;
					int xend=((x+1)*(width+hgap))/ncols-hgap;
					int cellWidth=xend-lastx;
					// Split this width into two areas, left for label and right for component
					int availableWidth=labelWidths[x];
					if(availableWidth>cellWidth) availableWidth=cellWidth;
					// Reshape the label to fit
					Component label=parent.getComponent(pos++);
					Dimension labelD=label.getPreferredSize();
					Component component=parent.getComponent(pos++);
					Dimension componentD=component.getPreferredSize();
					if (!stretchComponents) {
						cellHeight = Math.max(labelD.height, componentD.height);
						if((lasty+cellHeight)>yend) yend=lasty+cellHeight;
						// yend = lasty+cellHeight;
					}

					//int actualWidth=labelD.width;
					//if(actualWidth>availableWidth) actualWidth=availableWidth;
					label.setBounds(
						lastx+insets.left,
						lasty+insets.top,
						availableWidth,
						cellHeight
					);
					// Split out the right area
					if(pos>ncomponents) break Loop;
					availableWidth=cellWidth-cgap-labelWidths[x];
					if(availableWidth<0) availableWidth=0;
					// Reshape the component
					int actualWidth=componentD.width;
					if(actualWidth>availableWidth) actualWidth=availableWidth;
					component.setBounds(
						lastx+labelWidths[x]+cgap+insets.left,
						lasty+insets.top,
						actualWidth,
						cellHeight /*Klay--8/22/01*/
					);
					// Get ready for next iteration
					lastx=xend+hgap;
				}
				lasty=yend+vgap;
			}
		}
	}
370659
function(w, h) {
    grids[0].set( space.size.$multiply( 0.1 ) ).to( space.size.$multiply( 0.9, 0.3 ) ).init( 50, 50, "fix", "fix" );
    grids[1].set( space.size.$multiply( 0.1, 0.4 ) ).to( space.size.$multiply( 0.9, 0.6 ) ).init( 50, 50, "flex", "flex" );
    grids[2].set( space.size.$multiply( 0.1, 0.7 ) ).to( space.size.$multiply( 0.9, 0.9 ) ).init( 5, 8, "stretch", "stretch" );
  }
772929
function setLayout(d, layout, lastDisplay) {
        if (layout === 'vertical' || layout === 'multimode_vertical' ||
            layout === 'all_vertical') {

            d.displayDiv.style.float = 'none';
            d.titleDiv.style.float = 'none';
            d.titleDiv.style['margin-right'] = '0px';
            d.contentDiv.style.float = 'none';
            return true;
        }
        if (layout === 'horizontal') {
            d.displayDiv.style.float = 'none';
            d.titleDiv.style.float = 'left';
            d.titleDiv.style['margin-right'] = '6px';
            d.contentDiv.style.float = 'right';
            return true;
        }
        if (layout === 'multimode_horizontal') {
            d.displayDiv.style.float = 'left';
            d.titleDiv.style.float = 'none';
            d.titleDiv.style['margin-right'] = '0px';
            d.contentDiv.style.float = 'none';
            if (!lastDisplay) {
                d.displayDiv.style['margin-right'] = '10px';
            }
            return true;
        }
        if (layout === 'all_horizontal') {
            d.displayDiv.style.float = 'left';
            d.titleDiv.style.float = 'left';
            d.titleDiv.style['margin-right'] = '6px';
            d.contentDiv.style.float = 'right';
            if (!lastDisplay) {
                d.displayDiv.style['margin-right'] = '10px';
            }
            return true;
        }
        return false;
    }
138651
function fixVerticalPositionIE() {
  var container = getContainer();
  var popup = getPopup();
  container.style.removeProperty('align-items');

  if (popup.offsetTop < 0) {
    container.style.alignItems = 'flex-start';
  }
}
857137
public void fixDialogDimens() {
    Logr.d("Fixing dimensions to h = %d / w = %d", getMeasuredHeight(), getMeasuredWidth());
    // Fix the layout height/width after the dialog has been shown.
    getLayoutParams().height = getMeasuredHeight();
    getLayoutParams().width = getMeasuredWidth();
    // Post this runnable so it runs _after_ the dimen changes have been applied/re-measured.
    post(new Runnable() {
      @Override public void run() {
        Logr.d("Dimens are fixed: now scroll to the selected date");
        scrollToSelectedDates();
      }
    });
  }
969725
protected void configureNavi (FlexTable controls, int row, int col,
                                  int start, int limit, int total)
    {
        HorizontalPanel panel = new HorizontalPanel();
        panel.add(new Label("Page:")); // TODO: i18n

        // determine which pages we want to show
        int page = 1+start/_resultsPerPage;

        int pages;
        if (total < 0) {
            pages = page + 1;
        } else {
            pages = total/_resultsPerPage + (total%_resultsPerPage == 0 ? 0 : 1);
        }

        List<Integer> shown = new ArrayList<Integer>();
        shown.add(1);
        for (int ii = Math.max(2, Math.min(page-2, pages-5));
             ii <= Math.min(pages-1, Math.max(page+2, 6)); ii++) {
            shown.add(ii);
        }
        if (pages != 1) {
            shown.add(pages);
        }

        // now display those as "Page: _1_ ... _3_ _4_ 5 _6_ _7_ ... _10_"
        int ppage = 0;
        for (Integer cpage : shown) {
            if (cpage - ppage > 1) {
                panel.add(createPageLabel("...", null));
            }
            if (cpage == page) {
                panel.add(createPageLabel(""+page, "Current"));
            } else {
                panel.add(createPageLinkLabel(cpage));
            }
            ppage = cpage;
        }
        if (total < 0) {
            panel.add(createPageLabel("...", null));
        }
        controls.setWidget(row, col, panel);
        controls.getFlexCellFormatter().setHorizontalAlignment(row, col, HasAlignment.ALIGN_CENTER);
    }
1306404
protected void buildComponent() {
        addComponent(titleLayout);
        setComponentAlignment(titleLayout, Alignment.TOP_LEFT);
        setWidth(100, Unit.PERCENTAGE);
        setImmediate(true);
        addStyleName("action-history-header");
        addStyleName("bordered-layout");
        addStyleName("no-border-bottom");
    }
1171313
protected void adjustContentSize() {

        if (m_isFrame && m_isShowing) {
            if (m_buttonPanel != null) {
                m_contentPanel.getElement().getStyle().setBottom(m_buttonPanel.getOffsetHeight() + 6, Unit.PX);
            } else {
                m_contentPanel.getElement().getStyle().clearBottom();
            }
        }
    }
695654
private static void tryLayout(
            final Graphics2D graphics2D, final DistanceUnit scaleUnit, final double scaleDenominator,
            final double intervalLengthInWorldUnits, final ScaleBarRenderSettings settings,
            final int tryNumber) {
        if (tryNumber > MAX_NUMBER_LAYOUTING_TRIES) {
            // if no good layout can be found, stop. an empty scalebar graphic will be shown.
            LOGGER.error("layouting the scalebar failed (unit: {}, scale: {})", scaleUnit, scaleDenominator);
            return;
        }

        final ScalebarAttributeValues scalebarParams = settings.getParams();
        final DistanceUnit intervalUnit =
                bestUnit(scaleUnit, intervalLengthInWorldUnits, scalebarParams.lockUnits);
        final float intervalLengthInPixels = (float) scaleUnit.convertTo(
                intervalLengthInWorldUnits / scaleDenominator, DistanceUnit.PX);

        //compute the label positions
        final List<Label> labels = new ArrayList<>(scalebarParams.intervals + 1);
        final float leftLabelMargin;
        final float rightLabelMargin;
        final float topLabelMargin;
        final float bottomLabelMargin;

        final Font font = new Font(scalebarParams.font, Font.PLAIN, getFontSize(settings));
        final FontRenderContext frc = new FontRenderContext(null, true, true);

        if (scalebarParams.intervals > 1 || scalebarParams.subIntervals) {
            //the label will be centered under each tick mark
            for (int i = 0; i <= scalebarParams.intervals; i++) {
                String labelText = createLabelText(scaleUnit, intervalLengthInWorldUnits * i, intervalUnit);
                if (i == scalebarParams.intervals) {
                    // only show unit for the last label
                    labelText += intervalUnit;
                }
                TextLayout labelLayout = new TextLayout(labelText, font, frc);
                labels.add(new Label(intervalLengthInPixels * i, labelLayout, graphics2D));
            }
            leftLabelMargin = labels.get(0).getRotatedWidth(scalebarParams.getLabelRotation()) / 2.0f;
            rightLabelMargin =
                    labels.get(labels.size() - 1).getRotatedWidth(scalebarParams.getLabelRotation()) / 2.0f;
            topLabelMargin = labels.get(0).getRotatedHeight(scalebarParams.getLabelRotation()) / 2.0f;
            bottomLabelMargin =
                    labels.get(labels.size() - 1).getRotatedHeight(scalebarParams.getLabelRotation()) / 2.0f;
        } else {
            //if there is only one interval, place the label centered between the two tick marks
            String labelText =
                    createLabelText(scaleUnit, intervalLengthInWorldUnits, intervalUnit) + intervalUnit;
            TextLayout labelLayout = new TextLayout(labelText, font, frc);
            final Label label = new Label(intervalLengthInPixels / 2.0f, labelLayout, graphics2D);
            labels.add(label);
            rightLabelMargin = 0;
            leftLabelMargin = 0;
            topLabelMargin = 0;
            bottomLabelMargin = 0;
        }

        if (fitsAvailableSpace(scalebarParams, intervalLengthInPixels,
                               leftLabelMargin, rightLabelMargin, topLabelMargin, bottomLabelMargin,
                               settings)) {
            //the layout fits the maxSize
            settings.setLabels(labels);
            settings.setScaleUnit(scaleUnit);
            settings.setIntervalLengthInPixels(intervalLengthInPixels);
            settings.setIntervalLengthInWorldUnits(intervalLengthInWorldUnits);
            settings.setIntervalUnit(intervalUnit);
            settings.setLeftLabelMargin(leftLabelMargin);
            settings.setRightLabelMargin(rightLabelMargin);
            settings.setTopLabelMargin(topLabelMargin);
            settings.setBottomLabelMargin(bottomLabelMargin);

            doLayout(graphics2D, scalebarParams, settings);
        } else {
            //not enough room because of the labels, try a smaller bar
            double nextIntervalDistance = getNearestNiceValue(
                    intervalLengthInWorldUnits * 0.9, scaleUnit, scalebarParams.lockUnits);
            tryLayout(graphics2D, scaleUnit, scaleDenominator, nextIntervalDistance, settings,
                      tryNumber + 1);
        }
    }
621590
def layout(self, value):
        ''

        if self._adjust_id:
            self._fix_component_id(value)
        return Dash.layout.fset(self, value)
956212
public void setComponentConstraints(JComponent component)
    {
        GridBagConstraints c = this.getGBConstraints();
        GridBagLayout gridbag = (GridBagLayout)this.getScreenLayout();
        gridbag.setConstraints(component, c);
        
        Application application = BaseApplet.getSharedInstance().getApplication();
        MuffinManager muffinManager = application.getMuffinManager();
        if (component instanceof JTextComponent)
            if (muffinManager != null)
        {
            muffinManager.replaceClipboardAction(component, "cut");
            muffinManager.replaceClipboardAction(component, "copy");
            muffinManager.replaceClipboardAction(component, "paste");
        }        
    }
1334900
private void updateCustomComponentBounds()
    {
        if (customComponents == null)
        {
            return;
        }
        if (table == null)
        {
            return;
        }
        for (int i = 0; i < customComponents.size(); i++)
        {
            JComponent component = customComponents.get(i);
            Rectangle rect = getHeaderRect(i);
            rect.height = customComponentHeight;
            component.setBounds(rect);
        }
        revalidate();
    }
797434
public void configure( int width , int height , int gridRows , int gridCols ) {

		// need to maintain the same ratio of pixels in the grid as in the regular image for similarity and rigid
		// to work correctly
		int s = Math.max(width,height);
		scaleX = s/(float)(gridCols-1);
		scaleY = s/(float)(gridRows-1);
		if( gridRows > gridCols ) {
			scaleY /= (gridCols-1)/ (float) (gridRows-1);
		} else {
			scaleX /= (gridRows-1)/ (float) (gridCols-1);
		}

		this.gridRows = gridRows;
		this.gridCols = gridCols;

		grid.resize(gridCols*gridRows);
		reset();
	}
1358619
function changeLayout(cls) {
        $('body').toggleClass(cls)
        $layout.fixSidebar()
        if ($('body').hasClass('fixed') && cls == 'fixed') {
            $pushMenu.expandOnHover()
            $layout.activate()
        }
        $controlSidebar.fix()
    }
353691
public void layoutContainer (Container parent)
    {
        Insets insets = parent.getInsets();
        int pcount = parent.getComponentCount();
        for (int ii = 0; ii < pcount; ii++) {
            Component comp = parent.getComponent(ii);
            if (!comp.isVisible()) {
                continue;
            }

            Object constr = _constraints.get(comp);
            if (constr == null) {
                log.warning("No constraints for child!?", "cont", parent, "comp", comp);
                continue;
            }

            if (constr instanceof Rectangle) {
                Rectangle r = (Rectangle)constr;
                comp.setBounds(insets.left + r.x, insets.top + r.y,
                               r.width, r.height);

            } else {
                Point p = (Point)constr;
                Dimension d = comp.getPreferredSize();
                comp.setBounds(insets.left + p.x, insets.top + p.y,
                               d.width, d.height);
            }
        }
    }
25533
private void organize() {
        int m = (int) Math.sqrt(contentPane.getComponentCount());
        if (m <= 0) m = 1;
        contentPane.setLayout(new GridLayout(m, 0, 0, 0));
    }
233047
private void reInitLayoutElements() {

        m_panel.clear();
        for (CmsCheckBox cb : m_checkBoxes) {
            m_panel.add(setStyle(m_onlyLabels ? new Label(cb.getText()) : cb));
        }
    }