📄 activityonnodepertchart.java
字号:
Iterator it = graphicalNodesByCol.iterator(); while (it.hasNext()) { GraphicalNode gn = (GraphicalNode) it.next(); gn.x += currentX; gn.y += gn.row*(NODE_HEIGHT + Y_GAP);//currentY; //currentY += NODE_HEIGHT + Y_GAP; myMaxY = gn.y > myMaxY ? gn.y : myMaxY; } //myMaxY = currentY > myMaxY ? currentY : myMaxY; currentX += NODE_WIDTH + X_GAP; //graphicalNodesByC = (List) myMapPositionListOfNodes // .get(new Integer(++col)); col++; } myMaxX = currentX; */ this.myMaxX = 0; this.myMaxY = 0; Iterator gnodes = this.myGraphicalNodes.iterator(); while(gnodes.hasNext()) { GraphicalNode gnode = (GraphicalNode)gnodes.next(); gnode.x += (NODE_WIDTH + X_GAP) * gnode.col; gnode.y += (NODE_HEIGHT + Y_GAP) * gnode.row; this.myMaxX = gnode.x > this.myMaxX ? gnode.x : this.myMaxX; this.myMaxY = gnode.y > this.myMaxY ? gnode.y : this.myMaxY; } this.myMaxX += NODE_WIDTH + X_GAP; this.myMaxY += NODE_HEIGHT + Y_GAP; } private void calculateArrowsCoordinates() { Iterator it = myGraphicalNodes.iterator(); while (it.hasNext()) { GraphicalNode gn = (GraphicalNode) it.next(); Iterator itSuccessors = gn.node.getSuccessors().iterator(); while (itSuccessors.hasNext()) { TaskGraphNode tgn = (TaskGraphNode) itSuccessors.next(); int id = tgn.getID(); GraphicalArrow arrow = new GraphicalArrow(gn, getGraphicalNodeByID(id)); myGraphicalArrows.add(arrow); } } } public Icon getIcon() { return new ImageIcon(getClass().getResource("/icons/pert_16.gif")); } /** * @inheritDoc */ public Object getAdapter(Class adapter) { if (adapter.equals(Container.class) || adapter.equals(Chart.class)) { return this; } else { return null; } } /** * Graphical node that is rendered on graphics. * * @author bbaranne * */ private static class GraphicalNode extends JComponent { static int xName = 10; static int yName = 0; private TaskGraphNode node; private int col=-1; // conditionne le X private int row=-1; private final static Color defaultBackgroundColor = new Color(0.9f, 0.9f, 0.9f); private final static Color defaultCriticalColor = new Color(250, 250, 115).brighter(); private Color backgroundColor = null; int x = X_OFFSET, y = X_OFFSET; GraphicalNode(TaskGraphNode node) { this.row = -1; this.col = -1; this.node = node; this.backgroundColor = defaultBackgroundColor; if (node.isCritical()) this.backgroundColor = defaultCriticalColor; } /** * Updates the linked abstract node. * * @param node * new linked abtract node. */ public void updateData(TaskGraphNode node) { this.node = node; } /** * Paints the graphical node. * * @param g * Graphics where the graphical node is to be painted. */ public void paint(Graphics g) { if (node.isCritical()) this.backgroundColor = defaultCriticalColor; else this.backgroundColor = defaultBackgroundColor; paintMe(g); } /** * Paints the graphical node. * * @param g * Graphics where the graphical node is to be painted. */ private void paintMe(Graphics g) { g.setFont(g.getFont().deriveFont(11f).deriveFont(Font.BOLD)); FontMetrics fontMetrics = g.getFontMetrics(g.getFont()); int type = this.node.getType(); Color color = NORMAL_COLOR; switch (type) { case PertChartAbstraction.Type.NORMAL: { color = NORMAL_COLOR; break; } case PertChartAbstraction.Type.SUPER: { color = SUPER_COLOR; break; } case PertChartAbstraction.Type.MILESTONE: { color = MILESTONE_COLOR; break; } } g.setColor(this.backgroundColor); g.fillRoundRect(x, y, NODE_WIDTH, NODE_HEIGHT, 16, 16); g.setColor(color); g.drawRoundRect(x, y, NODE_WIDTH, NODE_HEIGHT, 16, 16); g.drawRoundRect(x + 1, y + 1, NODE_WIDTH - 2, NODE_HEIGHT - 2, 14, 14); g.drawLine(x, y + yName + fontMetrics.getHeight() + Y_OFFSET, x + NODE_WIDTH, y + yName + fontMetrics.getHeight() + Y_OFFSET); g.setColor(Color.BLACK); String name = node.getName(); int nameWidth = fontMetrics.stringWidth(name); g.drawString(getTruncatedString(name, NODE_WIDTH - xName, fontMetrics), x + xName, y + yName + fontMetrics.getHeight()); g.setFont(g.getFont().deriveFont(Font.PLAIN)); fontMetrics = g.getFontMetrics(g.getFont()); g.setColor(Color.BLACK); g.drawString(ourLanguage.getText("start") + ourLanguage.getText("punctuationSpace") + ": " + node.getStartDate().toString(), x + xName, (int) (y + yName + 2.3 * fontMetrics.getHeight())); g.drawString(ourLanguage.getText("end") + ourLanguage.getText("punctuationSpace") + ": " + node.getEndDate().toString(), x + xName, (int) (y + yName + 3.3 * fontMetrics.getHeight())); if (node.getDuration() != null) g.drawString(ourLanguage.getText("duration") + ourLanguage.getText("punctuationSpace") + ": " + node.getDuration().getLength(), x + xName, (int) (y + yName + 4.3 * fontMetrics.getHeight())); } /** * Truncated the <code>str</code> String according to * <code>width</code> and <code>fontMetrics</code>. Returns the * truncated String. * * @param str * @param width * @param fontMetrics * @return Returns the truncated String. */ private static String getTruncatedString(String str, int width, FontMetrics fontMetrics) { String res = str; int strWidth = fontMetrics.stringWidth(str); int maxwidth = 0; int i; if (strWidth > width) { for (i = 0; i < str.length(); i++) { char c = str.charAt(i); int cWidth = fontMetrics.charWidth(c); maxwidth += cWidth; if (maxwidth > width) break; } res = str.substring(0, i - 2); res += "..."; } return res; } public boolean equals(Object o) { if (o instanceof GraphicalNode) { return node.equals(((GraphicalNode) o).node); } return false; } public String toString() { return "[" + node.getName() + " (" + col + ") " + node.getSuccessors() + "]"; } } /** * Graphical arrow that is rendered on graphics. * * @author bbaranne * */ private static class GraphicalArrow { GraphicalNode from; GraphicalNode to; GraphicalArrow(GraphicalNode from, GraphicalNode to) { this.from = from; this.to = to; } private void paintMe(Graphics g) { g.setColor(ARROW_COLOR); int arrowFromX, arrowFromY; int arrowToX, arrowToY; arrowFromX = from.x + NODE_WIDTH; arrowFromY = from.y + NODE_HEIGHT / 2; arrowToX = to.x; arrowToY = to.y + NODE_HEIGHT / 2; int[] xS = { arrowToX, arrowToX - ARROW_WIDTH, arrowToX - ARROW_WIDTH }; int[] yS = { arrowToY, arrowToY - ARROW_HEIGHT / 2, arrowToY + ARROW_HEIGHT / 2 }; int nb = xS.length; g.fillPolygon(xS, yS, nb); // fl�che if (arrowFromY != arrowToY) { int[] middleLineX = { arrowFromX + X_GAP / 2 - ARROW_CORNER_WIDTH, arrowFromX + X_GAP / 2, arrowFromX + X_GAP / 2, arrowFromX + X_GAP / 2 + ARROW_CORNER_WIDTH }; int[] middleLineY = { arrowFromY, (arrowFromY < arrowToY ? arrowFromY + ARROW_CORNER_WIDTH : arrowFromY - ARROW_CORNER_WIDTH), (arrowFromY < arrowToY ? arrowToY - ARROW_CORNER_WIDTH : arrowToY + ARROW_CORNER_WIDTH), arrowToY }; int middleLineNb = middleLineX.length; g.drawPolyline(middleLineX, middleLineY, middleLineNb); g.drawLine(arrowFromX, arrowFromY, middleLineX[0], middleLineY[0]); g.drawLine(arrowFromX + X_GAP / 2 + ARROW_CORNER_WIDTH, arrowToY, arrowToX - ARROW_WIDTH, arrowToY); } else { g.drawLine(arrowFromX, arrowFromY, arrowToX, arrowToY); } // g.drawString(from.node.getName(),arrowFromX+5,arrowFromY+15); // g.drawString(to.node.getName(),arrowFromX+50,arrowFromY+15); } } /** * Graphical nodes width. */ private final static int NODE_WIDTH = 110;//205; /** * Graphical nodes height. */ private final static int NODE_HEIGHT = 70; /** * Gap between two TaskGraphNodes with the same X coordinate. */ private final static int X_GAP = 30;//60; /** * Gap between two TaskGraphNodes with the same Y coordinate. */ private final static int Y_GAP = 15;//30; private final static int ARROW_HEIGHT = 10; private final static int ARROW_WIDTH = 15; private final static int ARROW_CORNER_WIDTH = 6; /** * X offset for the top left task graph node. */ private final static int X_OFFSET = 5; /** * Y offset for the top left task graph node. */ private final static int Y_OFFSET = 5; /** * Color of the border of normal tasks. */ private final static Color NORMAL_COLOR = Color.BLUE.brighter(); /** * Color of the border of supertasks. */ private final static Color SUPER_COLOR = Color.RED; /** * Color of the border of milestones. */ private final static Color MILESTONE_COLOR = Color.BLACK; /** * Color of the arrows. */ private final static Color ARROW_COLOR = Color.GRAY; public void addTimeUnitVisitor(TimeUnitVisitor visitor) { // TODO Auto-generated method stub } public TaskLength calculateLength(int posX) { // TODO Auto-generated method stub return null; } public IGanttProject getProject() { // TODO Auto-generated method stub return null; } public void paintChart(Graphics g) { // TODO Auto-generated method stub } public void resetRenderers() { // TODO Auto-generated method stub } public void scrollLeft() { // TODO Auto-generated method stub } public void scrollRight() { // TODO Auto-generated method stub } public void setBottomUnit(TimeUnit bottomUnit) { // TODO Auto-generated method stub } public void setBottomUnitWidth(int width) { // TODO Auto-generated method stub } public void setDimensions(int height, int width) { // TODO Auto-generated method stub } public void setStartDate(Date startDate) { // TODO Auto-generated method stub } public void setTopUnit(TimeUnit topUnit) { // TODO Auto-generated method stub }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -