📄 activityonnodepertchart.java
字号:
return; TaskContainmentHierarchyFacade hierarchy = myTaskManager .getTaskHierarchy(); for (int j = 0; j < tasks.length; j++) { Task nestedTask = tasks[j]; GraphicalNode gn = getGraphicalNodeByID(nestedTask.getTaskID()); int oldPosition = gn.col; changePosition(gn, oldPosition + 1); correctPositions(hierarchy.getNestedTasks(nestedTask)); } } private void changePosition(GraphicalNode graphicalNode, int newCol) { //int oldPosition = graphicalNode.col; //graphicalNode.col = newCol; //boolean remove = ((List) myMapPositionListOfNodes.get(new Integer( // oldPosition))).remove(graphicalNode); this.remove(graphicalNode); this.add(newCol, graphicalNode); } private void moveDown(GraphicalNode graphicalNode) { int row = graphicalNode.row; while(this.isOccupied(++row, graphicalNode.col)); graphicalNode.row = row; /*int nbRows = ((Integer)this.rowsList.get(new Integer(graphicalNode.col))).intValue(); if(nbRows-1<row) { this.rowsList.put(new Integer(graphicalNode.col), new Integer(row+1)); }*/ } private GraphicalNode getNode(int row, int col) { Iterator inCol = this.getNodeInColumn(col).iterator(); while(inCol.hasNext()) { GraphicalNode node = (GraphicalNode)inCol.next(); if (node.row ==row) return node; } return null; } private void moveRight(GraphicalNode graphicalNode) { Iterator successors = graphicalNode.node.getSuccessors().iterator(); while(successors.hasNext()) { TaskGraphNode successor = (TaskGraphNode)successors.next(); this.moveRight(this.getGraphicalNodeByID(successor.getID())); } int newCol = graphicalNode.col +1; if(this.isOccupied(graphicalNode.row, newCol)) this.moveRight(this.getNode(graphicalNode.row, newCol)); graphicalNode.col = newCol; if(newCol==this.nbCols) { this.nbCols++; } } private void remove(GraphicalNode graphicalNode) { this.myGraphicalNodes.remove(graphicalNode); if(graphicalNode.col == -1) return; Iterator gnodes = this.getNodeInColumn(graphicalNode.col).iterator(); while(gnodes.hasNext()) { GraphicalNode gnode = (GraphicalNode)gnodes.next(); if(gnode.row>graphicalNode.row) gnode.row--; } //int iNbRow = ((Integer)this.rowsList.get(new Integer(graphicalNode.col))).intValue(); //rowsList.put(new Integer(graphicalNode.col), new Integer(iNbRow-1)); if(graphicalNode.col==this.nbCols-1) { List list = this.getNodeInColumn(this.nbCols-1); while(list.size()==0) { this.nbCols--; list = this.getNodeInColumn(this.nbCols-1); } } graphicalNode.row = -1; graphicalNode.col = -1; } private GraphicalNode getGraphicalNodeByID(int id) { GraphicalNode res = null; Iterator it = myGraphicalNodes.iterator(); while (it.hasNext()) { GraphicalNode gn = (GraphicalNode) it.next(); if (gn.node.getID() == id) { res = gn; break; } } return res; } // ajoute la graphical node dans la map position/liste des successeurs private void add(int col, GraphicalNode graphicalNode) { /*Integer key = new Integer(position); List l = (List) myMapPositionListOfNodes.get(key); int oldPosition = graphicalNode.col; List lOld = (List) myMapPositionListOfNodes .get(new Integer(oldPosition)); if (lOld != null) lOld.remove(graphicalNode); if (l == null) { List l2 = new ArrayList(); l2.add(graphicalNode); myMapPositionListOfNodes.put(key, l2); } else { l.add(graphicalNode); } myGraphicalNodes.remove(graphicalNode); myGraphicalNodes.add(graphicalNode); graphicalNode.col = position;*/ myGraphicalNodes.remove(graphicalNode); if (this.nbCols-1 < col) this.nbCols = col+1; int row = 0; while(this.isOccupied(row, col)) row++; graphicalNode.row = row; graphicalNode.col = col; myGraphicalNodes.add(graphicalNode); //rowsList.put(new Integer(col), new Integer(iNbRow+1)); } private List getNodesThatAreInASpecificSuccessorPosition(int col) { /* List graphicaleNodes = (List) myMapPositionListOfNodes.get(new Integer( position)); */ List graphicaleNodes = getNodeInColumn(col); if (graphicaleNodes.size()==0) return null; List res = new ArrayList(); for (int i = 0; i < graphicaleNodes.size(); i++) { GraphicalNode gn = (GraphicalNode) graphicaleNodes.get(i); TaskGraphNode tgn = gn.node; res.addAll(tgn.getSuccessors()); } return res; } /** * Get the list of GraphicalNode that are in a column. * * @param col the column number to look in * @return the list of GraphicalNode in the colum col */ private List getNodeInColumn(int col) { List list = new ArrayList(); Iterator gnodes = this.myGraphicalNodes.iterator(); while(gnodes.hasNext()) { GraphicalNode gnode = (GraphicalNode) gnodes.next(); if(gnode.col == col) list.add(gnode); } return list; } private boolean isOccupied(int row, int col) { List list = this.getNodeInColumn(col); if(list.size()!=0) { Iterator gnodes = list.iterator(); while(gnodes.hasNext()) { GraphicalNode gnode = (GraphicalNode)gnodes.next(); if(gnode.row==row) return true; } } return false; } private List getAncestor(TaskGraphNode tgn) { List ancestors = new ArrayList(); Iterator tnodes = this.myTaskGraphNodes.iterator(); while(tnodes.hasNext()) { TaskGraphNode tnode = (TaskGraphNode)tnodes.next(); List successor = tnode.getSuccessors(); if(successor.contains(tgn)) ancestors.add(tnode); } return ancestors; } private boolean isCrossingNode(GraphicalNode gnode) { TaskGraphNode tgn = gnode.node; List list = this.getAncestor(tgn); if(list.size()>0) { Iterator ancestors = list.iterator(); while(ancestors.hasNext()) { TaskGraphNode ancestor = (TaskGraphNode)ancestors.next(); GraphicalNode gancestor = this.getGraphicalNodeByID(ancestor.getID()); if(gancestor.col<gnode.col-1) { for(int col=gnode.col-1; col>gancestor.col; col--) { if(this.isOccupied(gnode.row, col)) return true; } } } } return false; } private void avoidCrossingNode() { if(this.nbCols==0) return; int col = this.nbCols-1; while(col>0) { boolean hasmoved = false; Iterator gnodes = this.getNodeInColumn(col).iterator(); while(gnodes.hasNext()) { GraphicalNode gnode = (GraphicalNode)gnodes.next(); while(this.isCrossingNode(gnode)) { this.moveDown(gnode); hasmoved = true; } } if(hasmoved && col<this.nbCols-1) col++; else col--; } } private boolean isCrossingArrow(GraphicalNode gnode) { //recherche de la position du successeur le plus haut et le plus bas int maxUp = 1000000, maxDown = -1; Iterator successors = gnode.node.getSuccessors().iterator(); while(successors.hasNext()) { GraphicalNode successor = this.getGraphicalNodeByID(((TaskGraphNode)successors.next()).getID()); if(successor.row<maxUp) maxUp = successor.row; if(successor.row>maxDown) maxDown = successor.row; } //r�cup�ration de toutes les nodes sur la m�me colonne List othernodes = this.getNodeInColumn(gnode.col); othernodes.remove(gnode); //parcours des nodes sur la m�me colonne Iterator nodes = othernodes.iterator(); while(nodes.hasNext()) { GraphicalNode othergnode = (GraphicalNode)nodes.next(); Iterator othersuccessors = othergnode.node.getSuccessors().iterator(); while(othersuccessors.hasNext()) { TaskGraphNode othersuccessor = (TaskGraphNode)othersuccessors.next(); GraphicalNode othersuccessornode = this.getGraphicalNodeByID(othersuccessor.getID()); if(maxUp < gnode.row) { //some arrows are going up if(othersuccessornode.row <= gnode.row && !gnode.node.getSuccessors().contains(othersuccessor)) return true; } if(maxDown > gnode.row) { //some arrow are going down if(othersuccessornode.row >= gnode.row && !gnode.node.getSuccessors().contains(othersuccessor)) return true; } } } return false; } private void avoidCrossingLine() { boolean restart = true; while(restart) { restart = false; for(int col=0; col<this.nbCols; col++) { List list = this.getNodeInColumn(col); if(list.size()>1) { Iterator gnodes = list.iterator(); while(gnodes.hasNext()) { GraphicalNode gnode = (GraphicalNode)gnodes.next(); if(this.isCrossingArrow(gnode)) { this.moveRight(gnode); this.avoidCrossingNode(); restart = true; break; } } if(restart) break; } } } } private void removeEmptyColumn() { for(int col=this.nbCols-1; col>=0; col--) { if(this.getNodeInColumn(col).size()==0) { if(col!=this.nbCols-1) { for(int c=col+1;c<this.nbCols;c++) { Iterator gnodes = this.getNodeInColumn(c).iterator(); while(gnodes.hasNext()) { GraphicalNode gnode = (GraphicalNode)gnodes.next(); gnode.col--; } } } this.nbCols--; } } } public RenderedImage getRenderedImage(GanttExportSettings settings) { return getChart(settings); } public BufferedImage getChart(GanttExportSettings settings) { BufferedImage image = new BufferedImage(myMaxX, myMaxY, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.fillRect(0, 0, myMaxX, myMaxY); paint(g); return image; } public String getName() { return ourLanguage.getText("pertChartLongName"); } public void reset() { this.myPertAbstraction = null; } public void paint(Graphics g) { this.buildPertChart(); myGraphics = g; super.paint(g); for (int i = 0; i < myGraphicalNodes.size(); i++) { ((GraphicalNode) myGraphicalNodes.get(i)).paint(g); } for (int i = 0; i < myGraphicalArrows.size(); i++) { ((GraphicalArrow) myGraphicalArrows.get(i)).paintMe(g); } } private void calculateGraphicalNodesCoordinates() { /*int nb = 0; int col = 0; int currentX = 0, currentY = 0; //List graphicalNodesByPosition = (List) myMapPositionListOfNodes // .get(new Integer(position)); while (col<this.nbCols) { // parcours de toutes les // positions List graphicalNodesByCol = this.getNodeInColumn(col); currentY = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -