<commit_before>/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.openlca.app.editors.graphical.layout;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.AbstractLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.openlca.app.editors.graphical.model.ProcessNode;
import org.openlca.app.editors.graphical.model.ProductSystemNode;

public class GraphLayoutManager extends AbstractLayout {

	public static int HORIZONTAL_SPACING = 25;
	public static int VERTICAL_SPACING = 25;

	private ProductSystemNode node;

	public GraphLayoutManager(ProductSystemNode node) {
		this.node = node;
	}

	private void layoutAsMinimalTree() {
		List<ProcessNode> nodes = new ArrayList<>();
		for (ProcessNode child : node.getChildren()) {
			if (child.isVisible())
				nodes.add(child);
			else
				child.setXyLayoutConstraints(new Rectangle(0, 0, child
						.getSize().width, child.getSize().height));
		}
		MinimalTreeLayout layout = new MinimalTreeLayout();
		layout.layout(nodes.toArray(new ProcessNode[nodes.size()]));
	}

	private void layoutAsTree() {
		TreeLayout layout = new TreeLayout();
		layout.layout(node);
	}

	private void layoutXY() {
		for (ProcessNode child : node.getChildren())
			child.getFigure().setBounds(child.getXyLayoutConstraints());
	}

	@SuppressWarnings("unchecked")
	@Override
	protected Dimension calculatePreferredSize(IFigure container, int hint,
			int hint2) {
		container.validate();
		List<IFigure> children = container.getChildren();
		Rectangle result = new Rectangle().setLocation(container
				.getClientArea().getLocation());
		for (IFigure child : children)
			result.union(child.getBounds());
		result.resize(container.getInsets().getWidth(), container.getInsets()
				.getHeight());
		return result.getSize();<commit_msg>Fixed NullPointerException in layouting<commit_after>/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.openlca.app.editors.graphical.layout;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.AbstractLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.openlca.app.editors.graphical.model.ProcessNode;
import org.openlca.app.editors.graphical.model.ProductSystemNode;

public class GraphLayoutManager extends AbstractLayout {

	public static int HORIZONTAL_SPACING = 25;
	public static int VERTICAL_SPACING = 25;

	private ProductSystemNode node;

	public GraphLayoutManager(ProductSystemNode node) {
		this.node = node;
	}

	private void layoutAsMinimalTree() {
		List<ProcessNode> nodes = new ArrayList<>();
		for (ProcessNode child : node.getChildren()) {
			if (child.isVisible())
				nodes.add(child);
			else
				child.setXyLayoutConstraints(new Rectangle(0, 0, child
						.getSize().width, child.getSize().height));
		}
		MinimalTreeLayout layout = new MinimalTreeLayout();
		layout.layout(nodes.toArray(new ProcessNode[nodes.size()]));
	}

	private void layoutAsTree() {
		TreeLayout layout = new TreeLayout();
		layout.layout(node);
	}

	private void layoutXY() {
		for (ProcessNode child : node.getChildren())
			if (child.getFigure() != null)
				child.getFigure().setBounds(child.getXyLayoutConstraints());
	}

	@SuppressWarnings("unchecked")
	@Override
	protected Dimension calculatePreferredSize(IFigure container, int hint,
			int hint2) {
		container.validate();
		List<IFigure> children = container.getChildren();
		Rectangle result = new Rectangle().setLocation(container
				.getClientArea().getLocation());
		for (IFigure child : children)
			result.union(child.getBounds());
		result.resize(container.getInsets().getWidth(), container.getInsets()
				.getHeight());
		return result.getSize();
{'fraction_non_alphanumeric': 0.17009345794392525, 'fraction_numerical': 0.009553478712357217, 'mean_word_length': 5.328515111695138, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1118906', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1332, 'n_words': 323}