📄 objecttree.java
字号:
package com.thalesgroup.cheddar.MARTE2cheddar;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.thalesgroup.java.log.Log;
/**
* 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() {
Log.debugMessage(Activator.PLUGIN_ID, "***** CHILDREN *****");
for(T e : childrens.keySet()) {
Log.debugMessage(Activator.PLUGIN_ID, e.toString()+ " -> " + childrens.get(e).size());
}
Log.debugMessage(Activator.PLUGIN_ID, "***** ROOTS *****");
for(T e : roots) {
Log.debugMessage(Activator.PLUGIN_ID, "ROOT : "+e.toString());
}
Log.debugMessage(Activator.PLUGIN_ID, "***** POSITIONS *****");
for(T e : positions.keySet()) {
ObjectPosition t = positions.get(e);
Log.debugMessage(Activator.PLUGIN_ID, e.toString());
Log.debugMessage(Activator.PLUGIN_ID, 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;
while(!upc.isEmpty()) {
T e = upc.get(0);
ObjectPosition temp = build(e, t);
t.y += temp.dy;
elem_pos.dy += temp.dy;
upc = findUnprocessedChildren(elem);
}
}
positions.put(elem, elem_pos);
return elem_pos;
}
public void run() {
ObjectPosition t = new ObjectPosition();
for(T e : roots) {
ObjectPosition r = build(e, t);
t.y += r.dy;
}
}
public HashMap<T, ObjectPosition> getPositions() {
return positions;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -