TODO: temporary changed to public access to solve the access issue in Layout.java
340361
public void onTransformChanged() {
        Log.v(Log.SUBSYSTEM.WIDGET, TAG, "onTransformChanged(): %s mPreventTransformChanged = %b",
                getName(), mPreventTransformChanged);

        // Even if the calling code that altered the transform doesn't request a
        // layout, we'll do a layout the next time a layout is requested on our
        // part of the scene graph.
        if (!mPreventTransformChanged) {
            mChanged = true;

            // Clear this to indicate that the bounding box has been invalidated and
            // needs to be constructed and transformed anew.
            mBoundingBox = null;
        }
    }
1313995
public void setLayout(java.lang.String layout) {
        getStateHelper().put(PropertyKeys.layout, layout);
    }
975333
private void updateCachedLayout(
            Document layout, IUserProfile profile, FragmentDefinition fragment) {
        final Locale locale = profile.getLocaleManager().getLocales().get(0);
        // need to make a copy that we can fragmentize
        layout = (Document) layout.cloneNode(true);

        // Fix later to handle multiple profiles
        final Element root = layout.getDocumentElement();
        final UserView userView = this.fragmentUtils.getUserView(fragment, locale);
        if (userView == null) {
            throw new IllegalStateException(
                    "No UserView found for fragment: " + fragment.getName());
        }

        root.setAttribute(
                Constants.ATT_ID,
                Constants.FRAGMENT_ID_USER_PREFIX
                        + userView.getUserId()
                        + Constants.FRAGMENT_ID_LAYOUT_PREFIX
                        + "1");
        try {
            this.fragmentActivator.clearChacheForOwner(fragment.getOwnerId());
            this.fragmentUtils.getUserView(fragment, locale);
        } catch (final Exception e) {
            logger.error("An exception occurred attempting to update a layout.", e);
        }
    }
1330156
private void fragmentizeLayout(UserView view, FragmentDefinition fragment) {
        // if fragment not bound to user or layout empty due to error, return
        if (view.getUserId() == -1 || view.getLayout() == null) {
            return;
        }

        // Choose what types of content to apply from the fragment
        Pattern contentPattern = STANDARD_PATTERN; // default
        boolean allowExpandedContent =
                Boolean.parseBoolean(
                        PropertiesManager.getProperty(PROPERTY_ALLOW_EXPANDED_CONTENT));
        if (allowExpandedContent) {
            contentPattern = EXPANDED_PATTERN;
        }

        // remove all non-regular or hidden top level folders
        // skip root folder that is only child of top level layout element
        Element layout = view.getLayout().getDocumentElement();
        Element root = (Element) layout.getFirstChild();
        NodeList children = root.getChildNodes();

        // process the children backwards since as we delete some the indices
        // shift around
        for (int i = children.getLength() - 1; i >= 0; i--) {
            Node node = children.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("folder")) {
                Element folder = (Element) node;

                // strip out folder types 'header', 'footer' and regular,
                // hidden folder "User Preferences" since users have their own
                boolean isApplicable =
                        contentPattern.matcher(folder.getAttribute("type")).matches();
                if (!isApplicable || folder.getAttribute("hidden").equals("true")) {
                    try {
                        root.removeChild(folder);
                    } catch (Exception e) {
                        throw new RuntimeException(
                                "Anomaly occurred while stripping out "
                                        + " portions of layout for fragment '"
                                        + fragment.getName()
                                        + "'. The fragment will not be available for "
                                        + "inclusion into user layouts.",
                                e);
                    }
                }
            }
        }
        // now re-lable all remaining nodes below root to have a safe system
        // wide id.

        setIdsAndAttribs(
                layout,
                layout.getAttribute(Constants.ATT_ID),
                "" + fragment.getId(),
                "" + fragment.getPrecedence());
    }
1106227
private static void maybeMarkBadProtoAccess(ExprNode expr, SoyValue value) {
    if (value instanceof SoyProtoValue) {
      ((SoyProtoValue) value).setAccessLocationKey(expr.getSourceLocation());
    }
  }
1303260
@Override
	protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
		if (changed || mNeedsResize) {
			int widthLimit = (right - left) - getCompoundPaddingLeft() - getCompoundPaddingRight();
			int heightLimit = (bottom - top) - getCompoundPaddingBottom() - getCompoundPaddingTop();
			resizeText(widthLimit, heightLimit);
		}
		super.onLayout(changed, left, top, right, bottom);
	}
658634
@Override
    public void doTag() throws JspException, IOException {
        LayoutTag layoutTag = (LayoutTag) findAncestorWithClass(this, LayoutTag.class);
        if (layoutTag == null) {
            throw new  IllegalStateException("div tag should be used in a layout tag inside.");
        }

        layoutTag.putDiv(name, TagUtils.toString(getJspBody()));
        logger.debug("div#{} put to layout#{}", name, layoutTag.getName());
    }
181303
private void updateButtonsLayout() {
		// Get the buttons layout.
		LinearLayout root = this.chooser.getRootLayout();
		LinearLayout buttonsLayout = (LinearLayout) root.findViewById(R.id.linearLayoutButtons);

		// Verify if the 'Add' button is visible or not.
		View addButton = root.findViewById(R.id.buttonAdd);
		addButton.setVisibility(this.canCreateFiles? View.VISIBLE : View.INVISIBLE);
		addButton.getLayoutParams().width = this.canCreateFiles? ViewGroup.LayoutParams.MATCH_PARENT : 0;

		// Verify if the 'Ok' button is visible or not.
		View okButton = root.findViewById(R.id.buttonOk);
		okButton.setVisibility(this.folderMode? View.VISIBLE : View.INVISIBLE);
		okButton.getLayoutParams().width = this.folderMode? ViewGroup.LayoutParams.MATCH_PARENT : 0;
		
		// If both buttons are invisible, hide the layout.
		ViewGroup.LayoutParams params = buttonsLayout.getLayoutParams();
		if(this.canCreateFiles || this.folderMode) {
			// Show the layout.
			params.height = ViewGroup.LayoutParams.WRAP_CONTENT;

			// If only the 'Ok' button is visible, put him first. Otherwise, put 'Add' first.
			buttonsLayout.removeAllViews();
			if(this.folderMode && !this.canCreateFiles) {
				buttonsLayout.addView(okButton);
				buttonsLayout.addView(addButton);
			} else {
				buttonsLayout.addView(addButton);			
				buttonsLayout.addView(okButton);
			}
		} else {
			// Hide the layout.
			params.height = 0;
		}
	}
591403
private boolean resetLayout(IPerson person) {
        final String userName = person.getUserName();
        if (PersonFactory.getGuestUsernames().contains(userName)) {
            throw new IllegalArgumentException("CANNOT RESET LAYOUT FOR A GUEST USER: " + person);
        }
        LOG.warn("Resetting user layout for: " + userName, new Throwable());

        boolean layoutWasReset = false;

        try {
            userIdentityStore.removePortalUID(person.getID());
            userIdentityStore.getPortalUID(person, true);

            // see if the current user was the one to reset their layout and if
            // so we need to refresh our local copy of their layout
            if (person == owner) {
                this.layoutCachingService.removeCachedLayout(person, profile);
                updateCacheKey();
                getUserLayoutDOM();
            }
            // if (isFragmentOwner)
            // {
            //
            //    store.updateOwnerLayout(person);
            // }
            layoutWasReset = true;
        } catch (Exception e) {
            LOG.error("Unable to reset layout for " + person.getUserName() + ".", e);
        }
        return layoutWasReset;
    }
754739
private void processNullLayouts(String className, String methodName) {
        if ("java/awt/Container".equals(className) && "setLayout".equals(methodName) && (stack.getStackDepth() > 0) && stack.getStackItem(0).isNull()) {
            bugReporter.reportBug(new BugInstance(this, BugType.S508C_NULL_LAYOUT.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
        }
    }
436470
private void showHiddenTabPopup() {
		JPopupMenu menu = new JPopupMenu();
		if (getMousePosition() == null) {
			// Startup
			return;
		}
		Collections.sort(this.hiddenTabs, NAME_COMPARATOR);
		
		for (Component c : this.hiddenTabs) {
			if (c instanceof AbstractPanel) {
				final AbstractPanel ap = (AbstractPanel)c;
				JMenuItem mi = new JMenuItem(ap.getName());
				mi.setIcon(ap.getIcon());
				mi.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent e) {
						setVisible(ap, true);
						ap.setTabFocus();
					}});
				menu.add(mi);
			}
		}
		menu.show(this, this.getMousePosition().x, this.getMousePosition().y);
	}
520089
function renderLayout( pageElement, areaHelper, layoutInfo ) {
         addClass( pageElement, layoutInfo.className );
         pageElement.innerHTML = layoutInfo.html;

         const areas = findWidgetAreas( pageElement );
         const deregisterFuncs = Object.keys( areas )
            .map( areaName => areaHelper.register( areaName, areas[ areaName ] ) );

         DEFAULT_AREAS.forEach( area => {
            if( areaHelper.exists( area.name ) ) {
               return;
            }

            const node = document.createElement( 'div' );
            if( area.hidden ) {
               node.style.display = 'none';
            }
            deregisterFuncs.push( areaHelper.register( area.name, node, area.name ) );
            pageElement.appendChild( node );
         } );

         return () => {
            deregisterFuncs.forEach( func => func() );
            removeClass( pageElement, layoutInfo.className );
         };
      }
402921
public UI wrapLayout(Layout layout) {
        // TODO: add a header to switch the style, etc
        // TODO: add bookmark to set the style
        if (server.getConfig().isDevelopmentHeader()) {
            final VerticalSplitPanel mainLayout = new VerticalSplitPanel();
            mainLayout.setSizeFull();
            mainLayout.setSplitPosition(SPLIT_POSITION, Sizeable.Unit.PIXELS);
            mainLayout.setLocked(true);

            final DevApplicationHeader header = new DevApplicationHeader(server);
            header.setSpacing(true);
            mainLayout.setFirstComponent(header);

            mainLayout.setSecondComponent(layout);

            return new DevUI(mainLayout);
        } else {
            return new DevUI(layout);
        }
    }
1202761
private void saveLayout(UserView view, IPerson owner) throws Exception {
        IUserProfile profile = new UserProfile();
        profile.setProfileId(view.getProfileId());
        userLayoutStore.setUserLayout(owner, profile, view.getLayout(), true, false);
    }
1374920
@Override
	public Layout<AbstractType,String> getConfiguredLayout() {
		return new StaticLayout<AbstractType,String>( this.graph, this, getGraphDimension());
	}
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);
        }
    }
1330771
public void updateLayout() {

        // TODO: we should not do this kind of things...
        if (!isAttached()) {
            return;
        }
        int floatBoxWidth = getFloatBoxWidth();
        m_primary.getElement().getStyle().setMarginLeft(floatBoxWidth, Unit.PX);
        updateVerticalMargin();
    }