⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objecttree.java

📁 papyrus插件MARTE例子,uml建模
💻 JAVA
字号:
package com.thalesgroup.cheddar.MARTE2cheddar.tools;

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

/**
 * Implementation of a dummy algorithm for drawing a tree.
 * Could be improved but enough for drawing Cheddar precedencies graphs
 * <copyright>
 * Thales MARTE to Cheddar (Copyright (c) THALES 2007 All rights reserved) is free software; you can redistribute itand/or modify
 * it under the terms of the Eclipse Public License as published in http://www.eclipse.org/legal/epl-v10.html
 *
 * Thales MARTE to Cheddar is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License for more details.
 * </copyright>
 * @author Nicolas Vienne
 *
 * @param <T>
 */
public class ObjectTree<T> {
	protected HashMap<T, List<T>> childrens;
	protected ArrayList<T> roots;
	protected ArrayList<T> processed_elements;
	protected HashMap<T, ObjectPosition> positions;
	
	public ObjectTree(HashMap<T, List<T>> m) {
		childrens = m;
		roots = new ArrayList<T>();
		processed_elements = new ArrayList<T>();
		positions = new HashMap<T, ObjectPosition>();
	}
	

	public ArrayList<T> findUnprocessedChildren(T o) {
		ArrayList<T> r = new ArrayList<T>();
		for(T elem : childrens.get(o)) {
			if(! processed_elements.contains(elem)) {
				r.add(elem);
			}
		}
		return r;
	}
	
	public void DEBUG_displayInfos() {
		System.out.println("***** CHILDREN *****");
		for(T e : childrens.keySet()) {
			System.out.println(e.toString()+ " -> " + childrens.get(e).size());
		}
		System.out.println("***** ROOTS *****");
		for(T e : roots) {
			System.out.println("ROOT : "+e.toString());
		}
		System.out.println("***** POSITIONS *****");
		for(T e : positions.keySet()) {
			ObjectPosition t = positions.get(e);
			System.out.println(e.toString());
			System.out.println(t.x + ", " + t.y + " : " + t.dx + " x " + t.dy);
		}
		
	}
	
	public void findRoots() {
		for(T e : childrens.keySet()) {
			Boolean is_root = true;
			for (List<T> e2 : childrens.values()) {
				is_root &= !e2.contains(e);
			}
			if(is_root) {
				roots.add(e);
			}
		}
	}
	
	public ArrayList<T> getRoots() {
		return roots;
	}
	
	protected ObjectPosition build(T elem, ObjectPosition base) {
		
		processed_elements.add(elem);
		
		ObjectPosition elem_pos = new ObjectPosition(base);
		
		ArrayList<T> upc = findUnprocessedChildren(elem);
		
		if(!upc.isEmpty()) {
			elem_pos.dy = 0;
			ObjectPosition t = new ObjectPosition(base);
			t.x += t.dx; // enfant d閍cal

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -