diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/layouts/DAGLayout.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/layouts/DAGLayout.java index 0d434dc..252d0f9 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/layouts/DAGLayout.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/layouts/DAGLayout.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import com.mxgraph.layout.mxGraphLayout; @@ -38,35 +39,49 @@ if (model.isVertex(cell)) { mxGraphView view = graph.getView(); mxCellState state = view.getState(cell); - double x = state.getX(); - double y = state.getY(); if(!"ellipse".equals(state.getStyle().get("shape")) && (cell.getEdgeCount() == 1)) { List newline = new ArrayList(); map.add(newline); lines(map, cell); - System.out.println("clear"); } } } - //�`�F�b�N�p - for(int a = 0; a < map.size(); a++) { - System.out.println("-"); - for(int b = 0; b < map.get(a).size(); b++) { - System.out.println(map.get(a).get(b).getId()); - } - } + //���בւ� + sort(map, 0, false); + + //layout + int count; + int skip = 0; + mxGraphView view = graph.getView(); for(int i = 0; i < map.size(); i++) { + count = 0; for(int j = 0; j < map.get(i).size(); j++) { + mxGeometry geom = (mxGeometry) map.get(i).get(j).getGeometry().clone(); + mxCellState state = view.getState(map.get(i).get(j)); if(checkmoved(moved, map.get(i).get(j))) { - mxGeometry geom = (mxGeometry) map.get(i).get(j).getGeometry().clone(); - geom.setX(100 + j*150); - geom.setY(100 + i*100); + if("ellipse".equals(state.getStyle().get("shape"))){ + geom.setX(50 + j*200); + } else { + geom.setX(100 + j*200); + } + geom.setY(100 + (i-skip)*100); model.setGeometry(map.get(i).get(j), geom); moved.add(map.get(i).get(j).getId()); + } else if(geom.getX() < 100 + j*150) { + if("ellipse".equals(state.getStyle().get("shape"))){ + geom.setX(50 + j*200); + } else { + geom.setX(100 + j*200); + } + geom.setY(100 + (i-skip)*100); + model.setGeometry(map.get(i).get(j), geom); + } else { + count++; } } + if(count >= map.get(i).size())skip++; } } @@ -80,13 +95,11 @@ mapping.get(mapping.size()-1).add(next); int tagcount = 0; mxCell edge; - System.out.println("start"); for(int i = 0; i < next.getEdgeCount(); i++) { edge = (mxCell) next.getEdgeAt(i); if(next != (mxCell) edge.getTarget() && ((mxCell) edge.getTarget() != null)) { tagcount++; if(tagcount > 1) { - System.out.println("some"); List newline = new ArrayList(mapping.get(mapping.size()-1)); while(newline.get(newline.size()-1).getId() != next.getId()) { newline.remove(newline.size()-1); @@ -95,7 +108,6 @@ lines(mapping, (mxCell) edge.getTarget()); } else { - System.out.println("first"); lines(mapping, (mxCell) edge.getTarget()); } } @@ -109,5 +121,29 @@ return true; } + public void sort(List> map, int n, boolean check) { + int msize = -1; + int mnum = -1; + if(check) { + for(int i = n; i < map.size(); i++) { + if(map.get(i).size() > msize && (map.get(n-1).get(0).getId().equals(map.get(i).get(0).getId()))) { + mnum = i; + } + } + } else { + for(int i = n; i < map.size(); i++) { + if(map.get(i).size() > msize) { + mnum = i; + } + } + } + if(mnum >= 0) { + Collections.swap(map, n, mnum); + sort(map, n+1, true); + } else if(n < map.size()) { + sort(map, n+1, false); + } + } + } \ No newline at end of file