/*
FlexibleLayout
322429
function addFlexibleLayout() {
    var modifier = new Modifier({
        size: [200, 200],
        transform: Transform.translate(200, 0)
    });

    var layout = new FlexibleLayout({
        direction: Utility.Direction.X,
        ratios: [true, 1, 2, 3, true]
    });

    function getItem() {
        return new Surface({
            properties: {
                backgroundColor: getRandomColor()
            }
        });
    }

    var items = [
        new Surface({
            size: [20, undefined],
            properties: {
                backgroundColor: getRandomColor()
            }
        }),
        getItem(),
        getItem(),
        getItem(),
        new Surface({
            size: [10, undefined],
            properties: {
                backgroundColor: getRandomColor()
            }
        })
    ];

    layout.sequenceFrom(items);
    ctx.add(modifier).add(layout);
}
435104
protected void onInitializeGroupLayout()
	{
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup().addContainerGap()
					.addComponent(scrTree, javax.swing.GroupLayout.PREFERRED_SIZE, 384,
						javax.swing.GroupLayout.PREFERRED_SIZE)
					.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
			.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup().addContainerGap()
				.addComponent(scrTree, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
				.addContainerGap()));
	}
59697
private WindowManager.LayoutParams createLayoutParams() {
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        return layoutParams;
    }
672622
@Override
	protected void onInitializeLayout()
	{
		final GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
			.addGroup(groupLayout.createSequentialGroup().addContainerGap()
				.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
					.addComponent(lpHostOrIpaddress, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE,
						501, Short.MAX_VALUE)
					.addComponent(lpNoProxy, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 501,
						Short.MAX_VALUE)
					.addComponent(lpUseSystemSettings, GroupLayout.PREFERRED_SIZE, 501,
						GroupLayout.PREFERRED_SIZE))
				.addContainerGap()));
		groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
			.addGroup(groupLayout.createSequentialGroup().addContainerGap()
				.addComponent(lpNoProxy, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)
				.addGap(18)
				.addComponent(lpHostOrIpaddress, GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
				.addGap(18).addComponent(lpUseSystemSettings, GroupLayout.PREFERRED_SIZE, 42,
					GroupLayout.PREFERRED_SIZE)
				.addGap(29)));
		setLayout(groupLayout);
	}
568047
private void adaptTabLayoutEnableState() {
        if (tabLayout != null) {
            LinearLayout tabStrip = ((LinearLayout) tabLayout.getChildAt(0));
            tabStrip.setEnabled(tabLayoutEnabled);

            for (int i = 0; i < tabStrip.getChildCount(); i++) {
                tabStrip.getChildAt(i).setEnabled(tabLayoutEnabled);
            }
        }
    }
246500
private static void doLayout(
            final Graphics2D graphics2d, final ScalebarAttributeValues scalebarParams,
            final ScaleBarRenderSettings settings) {
        final Dimension maxLabelSize = getMaxLabelSize(settings);

        int numSubIntervals = 1;
        if (scalebarParams.subIntervals) {
            numSubIntervals = getNbSubIntervals(
                    settings.getScaleUnit(), settings.getIntervalLengthInWorldUnits(),
                    settings.getIntervalUnit());
        }

        settings.setBarSize(getBarSize(settings));
        settings.setLabelDistance(getLabelDistance(settings));
        settings.setLineWidth(getLineWidth(settings));
        settings.setSize(getSize(scalebarParams, settings, maxLabelSize));
        settings.setMaxLabelSize(maxLabelSize);
        settings.setNumSubIntervals(numSubIntervals);

        ScalebarDrawer drawer = scalebarParams.getType().createDrawer(graphics2d, settings);
        drawer.draw();
    }
764874
private void adaptWidth() {
        adapter.setWidth(width);

        if (rootView != null) {
            rootView.setWidth(width);
            rootView.requestLayout();
        }
    }
267322
function _setLayout(layout) {
  var leafCount = _data.leafCount,
      dimention;

  // If count is even dummy will be replaced by output, so output would no more be leaf
  if(_data.tree.get('children.length') % 2 === 0) {
    leafCount--;
  }
  dimention = layout.projector(leafCount, _data.maxDepth - 1);

  _layout = layout;

  _width = dimention.x *= _layout.hSpacing;
  _height = dimention.y *= _layout.vSpacing;

  dimention = _layout.projector(dimention.x, dimention.y); // Because tree is always top to bottom
  _treeLayout = d3.layout.tree().size([dimention.x, dimention.y]);

  _update();
}
219843
function transformLayout(statement) {
    // Transform to layout function
    var actions = statement.expression.children;

    var blocks = [];
    var o = t.identifier('o');
    var type = t.memberExpression(o, t.identifier('type'));
    var config = t.memberExpression(o, t.identifier('config'));
    var childrenPush = t.memberExpression(
      t.memberExpression(o, t.identifier('children')),
      t.identifier('push')
    );
    var childrenUnshift = t.memberExpression(
      t.memberExpression(o, t.identifier('children')),
      t.identifier('unshift')
    );
    var element = t.memberExpression(o, t.identifier('element'));
    var stopRender = t.memberExpression(o, t.identifier('stopRender'));

    for (var ii = 0, actionsLength = actions.length; ii < actionsLength; ii++) {
      var action = actions[ii];
      if (!t.isJSXElement(action)) {
        continue;
      }

      // Check if conditions
      var tests = [], configCondition = true, falseCondition = false;
      var conditions = action.openingElement.attributes;
      var children = childrenPush;
      for (var j = 0, conditionsLength = conditions.length; j < conditionsLength; j++) {
        var condition = conditions[j];
        if (condition.name.name === 'type') {
          // Type condition
          if (t.isJSXExpressionContainer(condition.value)) {
            tests.push(t.binaryExpression(
              '===',
              type,
              condition.value.expression
            ));
          } else {
            falseCondition = true;
            break;
          }
        } else if (condition.name.name === '_top') {
          children = childrenUnshift;
        } else {
          if (configCondition) {
            tests.push(config);
            configCondition = false;
          }
          tests.push(t.binaryExpression(
            '===',
            t.memberExpression(config, t.stringLiteral(condition.name.name), true),
            t.isJSXExpressionContainer(condition.value) ?
              condition.value.expression :
              (condition.value === null ? t.booleanLiteral(true) : condition.value)
          ));
        }
      }
      if (falseCondition) {
        continue;
      }

      var statements = [];
      // Transform each action to block
      switch (action.openingElement.name.name) {
        // Transform content
        case 'addChildren':
        case 'update':
          for (var j = 0, childrenLen = action.children.length; j < childrenLen; j++) {
            var child = action.children[j];
            var param = undefined;
            if (t.isJSXElement(child)) {
              // @TODO process 'before' and 'after' element
              if (child.openingElement.name.name === 'props') {
                // Update props
                var attributes = child.openingElement.attributes;
                for (var jj = 0, attsLength = attributes.length; jj < attsLength; jj++) {
                  if (jj === 0) {
                    statements.push(t.assignmentExpression('=', config, t.logicalExpression(
                      '||', config, t.objectExpression([])
                    )));
                  }
                  var att = attributes[jj];
                  var left = t.memberExpression(config, t.stringLiteral(att.name.name), true);
                  var right;
                  if (t.isJSXExpressionContainer(att.value)) {
                    right = att.value.expression;
                  } else if (att.value === null) {
                    right = t.booleanLiteral(true);
                  } else {
                    right = att.value;
                  }
                  statements.push(t.assignmentExpression('=', left, right));
                }
              } else {
                // JSX element
                param = child;
              }
            } else if (t.isJSXExpressionContainer(child)) {
              // JS expression
              param = child.expression;
            } else if (child.value.trim().length > 0) {
              // Text string
              param = t.stringLiteral(child.value);
            }
            if (param !== undefined) {
              statements.push(t.callExpression(children, [param]))
            }
          }
          break;
        case 'replace':
          for (var j = 0, childrenLen = action.children.length; j < childrenLen; j++) {
            var child = action.children[j];
            if (t.isJSXExpressionContainer(child)) {
              statements.push(t.assignmentExpression('=', element, child.expression));
              break;
            } else if (t.isJSXElement(child)) {
              statements.push(t.assignmentExpression('=', element, child));
              break;
            }
          }
          break;
        case 'remove':
          statements.push(t.assignmentExpression('=', stopRender, t.booleanLiteral(true)));
          break;
        default:
          // Do not transform
      }
      if (statements.length === 0) {
        continue;
      }
      statements = statements.map(function(exp) {
        return t.expressionStatement(exp);
      });

      // Append to blocks
      if (tests.length === 0) {
        blocks = blocks.concat(statements);
      } else {
        blocks.push(t.ifStatement(
          tests.reduce(function(l, r) {
            return t.logicalExpression('&&', l, r);
          }),
          t.blockStatement(statements)
        ));
      }
    }

    statement.expression = t.assignmentExpression(
      '=',
      t.memberExpression(t.identifier('module'), t.identifier('exports')),
      t.functionExpression(null, [o], t.blockStatement(blocks))
    );
  }
227104
function(layout, fail) {
    if (_.isFunction(layout)) {
      return layout;
    }

    if (!_.isString(layout)) {
      fail('Layout should be specified by name or as a function');
    }

    if (_(defaultLayouts).has(layout)) {
      return defaultLayouts[layout];
    }

    fail('The following named layouts are supported: ' + _.keys(defaultLayouts).join(', '));
  }
565429
@UiThread
    protected void parentExpandedFromViewHolder(int flatParentPosition) {
        ExpandableWrapper<P, C> parentWrapper = mFlatItemList.get(flatParentPosition);
        updateExpandedParent(parentWrapper, flatParentPosition, true);
    }
408110
function handleLayout(obj, stats, depth) {
        var layoutName = obj.layout.basename;
        debug('applied layout (#%d) "%s", to file "%s"', depth, layoutName, file.path);

        file.currentLayout = obj.layout;
        file.define('layoutStack', stats.history);
        app.handleOnce('onLayout', file);
        delete file.currentLayout;
      }
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();
    }
699679
protected void initLayout()
  {
    setOpaque( false );
    setBorder( BorderFactory.createLineBorder( Scheme.active().getWindowBorder() ) );

    GridBagLayout gridBag = new GridBagLayout();
    JPanel pane = new JPanel();
    pane.addMouseListener( this );
    pane.addMouseMotionListener( this );
    pane.setLayout( gridBag );
    GridBagConstraints c = new GridBagConstraints();

    _viewer = new HtmlViewer();
    _viewer.setText( _strHelpText );
    _viewer.setBorder( BorderFactory.createEmptyBorder( 0, 10, 0, 10 ) );
    _viewer.addMouseListener( this );
    _viewer.addMouseMotionListener( this );
    _scroller = new JScrollPane( _viewer );
    _scroller.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
    _scroller.setMaximumSize( calcMaximumViewerSize() );
    _viewer.setBackground( Scheme.active().getTooltipBackground() );

    c.anchor = GridBagConstraints.CENTER;
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = GridBagConstraints.REMAINDER;
    c.weightx = 1;
    c.weighty = 1;
    pane.add( _scroller, c );

    _editorKeyListener = new EditorKeyListener();

    add( pane );

    addSeparator();

    addMouseListener( this );
    addMouseMotionListener( this );
  }
765466
@Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);

        if(getOrientation() == HORIZONTAL) {
            int N = getChildCount();
            for (int i = 0; i < N; i++) {

                View child = getChildAt(i);
                int width = child.getWidth();
                if (width > MAX_BUTTON_WIDTH || (N>=3 && width > MIN_BUTTON_WIDTH)) {

                    // Clear out the children list in preparation for new manipulation
                    children.clear();

                    // Update the children's params
                    for (int j = 0; j < N; j++) {
                        RippleView chd = (RippleView) getChildAt(j);
                        Button btn = (Button) chd.getChildAt(0);
                        btn.setGravity(Gravity.END|Gravity.CENTER_VERTICAL);
                        children.add(chd);
                    }

                    // Clear out the chitlens
                    removeAllViews();

                    // Sort buttons properly
                    Collections.sort(children, mButtonComparator);

                    // Re-Add all the views
                    for(int j=0; j<children.size(); j++){
                        View chd = children.get(j);
                        addView(chd);
                    }

                    // Switch orientation
                    setOrientation(VERTICAL);
                    requestLayout();
                    return;
                }


            }
        }


    }
597748
public void registerLayout(String path, String resource) throws Exception {
        Layout layout = LayoutParser.parseResource(resource);
        ElementUI parent = parentFromPath(path);
        
        if (parent != null) {
            layout.materialize(parent);
        }
    }
339476
function mapLayoutToPageData(pageData, layoutData) {
  // quickly (and shallowly) go through the layout's properties,
  // finding strings that map to page properties
  _.each(layoutData, function (list, key) {
    if (_.isString(list)) {
      if (_.isArray(pageData[key])) {
        // if you find a match and the data exists,
        // replace the property in the layout data
        layoutData[key] = _.map(pageData[key], refToObj);
      } else {
        // otherwise replace it with an empty list
        // as all layout properties are component lists
        layoutData[key] = [];
      }
    }
  });

  return layoutData;
}