📄 placenode2.java
字号:
ns = r.getChild(noa).getTarget(); } //m_groups[f].gap = // Math.ceil((a.amount / (double)ps) + m_groups[f].gap); //note for this method i do not need the group gap ,but i will leave //it for the other methods; Vector o_pos = new Vector(20,10); for (int noa = 0;(e = r.getChild(noa)) != null;noa++) { if (e.getTarget().getParent(0) == e) { Double tem = new Double(e.getTarget().getCenter()); o_pos.addElement(tem); } } pf--; double inc = a.m_amount / (double)ps; for (int noa = 0;(e = r.getChild(noa)) != null;noa++) { ns = e.getTarget(); if (ns.getParent(0) == e) { if (noa > pf + ps) { ns.adjustCenter(a.m_amount); } else if (noa > pf) { ns.adjustCenter(inc * (double)(noa - pf)); } } } nf = r.getChild(0).getTarget(); inc = ns.getCenter() - nf.getCenter(); m_groups[f].m_size = inc; m_groups[f].m_left = r.getCenter() - inc / 2; m_groups[f].m_right = m_groups[f].m_left + inc; inc = m_groups[f].m_left - nf.getCenter(); double shift; int g_num = 0; for (int noa = 0;(e = r.getChild(noa)) != null;noa++) { ns = e.getTarget(); if (ns.getParent(0) == e) { ns.adjustCenter(inc); shift = ns.getCenter() - ((Double)o_pos.elementAt(noa)).doubleValue(); if (ns.getChild(0) != null) { moveSubtree(m_groups[f].m_start + g_num,shift); g_num++; } } //ns.adjustCenter(-shift); } //zero_offset(r); //x_placer(f); } } /** * This will recursively shift a sub there to be centered about * a particular value. * @param n The first group in the sub tree. * @param o The point to start shifting the subtree. */ private void moveSubtree(int n,double o) { Edge e; Node r = m_groups[n].m_p; for (int noa = 0;(e = r.getChild(noa)) != null;noa++) { if (e.getTarget().getParent(0) == e) { e.getTarget().adjustCenter(o); } } m_groups[n].m_left += o; m_groups[n].m_right += o; if (m_groups[n].m_start != -1) { for (int noa = m_groups[n].m_start;noa <= m_groups[n].m_end;noa++) { moveSubtree(noa,o); } } } /** * This will untangle the nodes in the tree so that they fall on the * correct side of each other. */ private void untangle() { Ease a; Edge e; Node r,nf = null,ns = null,mark; int l = 0,times = 0; int f,s,tf = 0,ts = 0,pf,ps; while ((a = overlap(l)) != null) { times++; //System.out.println(group_num); f = a.m_place; s = a.m_place + 1; while (f != s) { a.m_lev--; tf = f; ts = s; f = m_groups[f].m_pg; s = m_groups[s].m_pg; } l = a.m_lev; pf = 0; ps = 0; r = m_groups[f].m_p; mark = m_groups[tf].m_p; nf = null; ns = null; for (int noa = 0; nf != mark;noa++) { pf++; nf = r.getChild(noa).getTarget(); } mark = m_groups[ts].m_p; for (int noa = pf; ns != mark;noa++) { ps++; //the number of gaps between the two nodes ns = r.getChild(noa).getTarget(); } m_groups[f].m_gap = Math.ceil((a.m_amount / (double)ps) + m_groups[f].m_gap); xPlacer(f); } } /** * This will find an overlap and then return information about that overlap * @param l The level to start on. * @return null if there was no overlap , otherwise an object containing * the group number that overlaps (only need one) how much they overlap by, * and the level they overlap on. */ private Ease overlap(int l) { Ease a = new Ease(); for (int noa = l;noa < m_levelNum;noa++) { for (int nob = m_levels[noa].m_start;nob < m_levels[noa].m_end;nob++) { a.m_amount = m_groups[nob].m_right - m_groups[nob+1].m_left + 2; //System.out.println(m_groups[nob].m_right + " + " + // m_groups[nob+1].m_left + " = " + a.amount); if (a.m_amount >= 0) { a.m_amount++; a.m_lev = noa; a.m_place = nob; return a; } } } return null; } /* private int count_m_groups(Node r,int l) { Edge e; if (r.getChild(0) != null) { l++; } for (int noa = 0;(e = r.getChild(noa)) != null;noa++) { l = count_groups(e.getTarget(),l); } return l; } */ /** * This function sets up the height of each node, and also fills the * levels array with information about what the start and end groups on that * level are. */ private void yPlacer() { //note this places the y height and sets up the levels array double changer = m_yRatio; int lev_place = 0; if (m_groupNum > 0) { m_groups[0].m_p.setTop(m_yRatio); m_levels[0].m_start = 0; for (int noa = 0;noa < m_groupNum;noa++) { if (m_groups[noa].m_p.getTop() != changer) { m_levels[lev_place].m_end = noa - 1; lev_place++; m_levels[lev_place].m_start = noa; changer = m_groups[noa].m_p.getTop(); } nodeY(m_groups[noa].m_p); } m_levels[lev_place].m_end = m_groupNum - 1; } } /** * This will set all of the children node of a particular node to their * height. * @param r The parent node of the children to set their height. */ private void nodeY(Node r) { Edge e; double h = r.getTop() + m_yRatio; for (int noa = 0;(e = r.getChild(noa)) != null;noa++) { if (e.getTarget().getParent(0) == e) { e.getTarget().setTop(h); if (!e.getTarget().getVisible()) { //System.out.println("oh bugger"); } } } } /** * This starts to create the information about the sibling groups. * As more groups are created the for loop in this will check those groups * for lower groups. * @param r The top node. */ private void groupBuild(Node r) { if (m_groupNum > 0) { m_groupNum = 0; m_groups[0].m_p = r; m_groupNum++; //note i need to count up the num of groups first //woe is me for (int noa = 0;noa < m_groupNum ;noa++) { groupFind(m_groups[noa].m_p,noa); } } } /** * This is called to build the rest of the grouping information. * @param r The parent of the group. * @param pg The number for the parents group. */ private void groupFind(Node r,int pg) { Edge e; boolean first = true; for (int noa = 0;(e = r.getChild(noa)) != null;noa++) { if (e.getTarget().getParent(0) == e) { if (e.getTarget().getChild(0) != null && e.getTarget().getCVisible()) { if (first) { m_groups[pg].m_start = m_groupNum; first = false; } m_groups[pg].m_end = m_groupNum; m_groups[m_groupNum].m_p = e.getTarget(); m_groups[m_groupNum].m_pg = pg; m_groups[m_groupNum].m_id = m_groupNum; //just in case I ever need //this info m_groupNum++; } } } } //note these three classes are only to help organise the data and are //inter related between each other and this placer class //so don't mess with them or try to use them somewhere else //(because that would be a mistake and I would pity you) /** * Inner class for containing the level data. */ private class Level { /** The number for the group on the left of this level. */ public int m_start; /** The number for the group on the right of this level. */ public int m_end; /** These two params would appear to not be used. */ public int m_left; public int m_right; } /** * Inner class for containing the grouping data. */ private class Group { /** The parent node of this group. */ public Node m_p; /** The group number for the parent of this group. */ public int m_pg; /** The gap size for the distance between the nodes in this group. */ public double m_gap; /** The leftmost position of this group. */ public double m_left; /** The rightmost position of this group. */ public double m_right; /** The size of this group. */ public double m_size; /** The start node of this group. */ public int m_start; /** The end node of this group. */ public int m_end; /** The group number for this group. (may not be used!?). */ public int m_id; } /** * An inner class used to report information about any tangles found. */ private class Ease { /** The number of the group on the left of the tangle. */ public int m_place; /** The distance they were tangled. */ public double m_amount; /** The level on which they were tangled. */ public int m_lev; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -