📄 taskrendererimpl.java
字号:
public void startTimeFrame(TimeFrame timeFrame) { myCurrentTimeFrame = timeFrame; } public void endTimeFrame(TimeFrame timeFrame) { myCurrentTimeFrame = null; } public void startUnitLine(TimeUnit timeUnit) { if (myCurrentTimeFrame.getBottomUnit() == timeUnit) { myCurrentUnit = timeUnit; } } public void endUnitLine(TimeUnit timeUnit) { myCurrentUnit = null; } public void nextTimeUnit(int unitIndex) { if (myCurrentUnit != null) { Date unitStart = myCurrentTimeFrame.getUnitStart(myCurrentUnit, unitIndex); Date unitFinish = myCurrentTimeFrame.getUnitFinish(myCurrentUnit, unitIndex); myUnitStart = unitStart; pullQueue(unitStart, unitFinish); // System.err.println("[TaskRendererImpl] nextTimeUnit(): // unitStart="+unitStart+" posX="+myPosX); // if (!myCurrentlyProcessed.isEmpty()) { // System.err.println("[TaskRendererImpl] nextTimeUnit(): // processing:"+myCurrentlyProcessed); // } for (Iterator startedActivities = myCurrentlyProcessed.iterator(); startedActivities .hasNext(); startedActivities.remove()) { TaskActivity nextStarted = (TaskActivity) startedActivities .next(); processActivity(nextStarted); } if (myModel.isPrevious()) { for (int i = 0; i < myPreviousStateCurrentlyProcessed.size(); i++) { Object next = myPreviousStateCurrentlyProcessed.get(i); // System.out.println (next + " : " + i); if (next != null) { GanttPreviousStateTask previousTask = (GanttPreviousStateTask) next; drawPreviousStateTask(previousTask, i); } } myPreviousStateCurrentlyProcessed = new ArrayList(); } myPosX += getChartModel().getBottomUnitWidth(); } } private void processActivity(TaskActivity nextStarted) { if (nextStarted.isLast()) { processLastActivity(nextStarted); } else if (nextStarted.isFirst()) { processFirstActivity(nextStarted); } else { processRegularActivity(nextStarted); } } private Rectangle processRegularActivity(TaskActivity nextStarted) { Task nextTask = nextStarted.getTask(); if (nextTask.isMilestone() && !nextStarted.isFirst()) { return null; } java.awt.Rectangle nextBounds = getBoundingRectangle(nextStarted); int nextLength = (int) nextBounds.width; int topy = nextBounds.y; topy = topy + (getRowHeight() - 20) / 2; if (myModel.isOnlyDown()) topy = topy - 6; else if (myModel.isOnlyUp()) topy = topy + 6; if (myModel.isPrevious()) topy = topy - 5;// int posX = myPosX; GraphicPrimitiveContainer.Rectangle nextRectangle;// // if (nextStarted.getStart().compareTo(myUnitStart)>=0) {// TaskLength deltaLength = nextTask.getManager().createLength(// getChartModel().getTimeUnitStack().getDefaultTimeUnit(),// myUnitStart, nextStarted.getStart());//// int deltaX = (int) (deltaLength.getLength(myCurrentUnit) * getChartModel()// .getBottomUnitWidth());// posX += deltaX; // System.err.println("[TaskRendererImpl] myUnitStart="+myUnitStart+" // nextActivity="+nextStarted+" deltaX="+deltaX+" // deltaLength="+deltaLength.getLength(myCurrentUnit)); // } // else { // nextRectangle = // getPrimitiveContainer().createRectangle(myPosX+getChartModel().getBottomUnitWidth()-nextLength, // topy, nextLength, getRowHeight()*3/5); // } boolean nextHasNested = ((ChartModelImpl) getChartModel()) .getTaskContainment().hasNestedTasks(nextTask); // JA Switch to GraphicPrimitiveContainer container = getContainerFor(nextTask); nextRectangle = container.createRectangle(nextBounds.x, topy, (int) nextLength, 12); // CodeReview: why 12, not 15? // System.err.println("task="+nextStarted.getTask()+" nested tasks // length="+nextStarted.getTask().getNestedTasks().length); if (nextStarted.getTask().isMilestone()) { nextRectangle.setStyle("task.milestone"); } else if (nextTask.isProjectTask()) { nextRectangle.setStyle("task.projectTask"); if (nextStarted.isFirst()) { // CodeReview: why 12, not 15? GraphicPrimitiveContainer.Rectangle supertaskStart = container .createRectangle(nextRectangle.myLeftX, topy, (int) nextLength, 12); supertaskStart.setStyle("task.projectTask.start"); } if (nextStarted.isLast()) { GraphicPrimitiveContainer.Rectangle supertaskEnd = container .createRectangle(myPosX - 1, topy, (int) nextLength, 12); supertaskEnd.setStyle("task.projectTask.end"); } } else if (nextHasNested) { nextRectangle.setStyle("task.supertask"); if (nextStarted.isFirst()) { // CodeReview: why 12, not 15? GraphicPrimitiveContainer.Rectangle supertaskStart = container .createRectangle(nextRectangle.myLeftX, topy, (int) nextLength, 12); supertaskStart.setStyle("task.supertask.start"); } if (nextStarted.isLast()) { // CodeReview: why 12, not 15? GraphicPrimitiveContainer.Rectangle supertaskEnd = container .createRectangle(nextRectangle.myLeftX, topy, (int) nextLength, 12); supertaskEnd.setStyle("task.supertask.end"); } } else if (nextStarted.getIntensity() == 0f) { nextRectangle.setStyle("task.holiday"); } else { if (nextStarted.isFirst() && nextStarted.isLast()) { nextRectangle.setStyle("task.startend"); } else if (false==nextStarted.isFirst() ^ nextStarted.isLast()) { nextRectangle.setStyle("task"); } else if (nextStarted.isFirst()) { nextRectangle.setStyle("task.start"); } else if (nextStarted.isLast()) { nextRectangle.setStyle("task.end"); } } if (myProgressRenderingEnabled && !nextTask.isMilestone() && !nextHasNested) { renderProgressBar(nextStarted, nextRectangle); } if (!"task.holiday".equals(nextRectangle.getStyle()) && !"task.supertask".equals(nextRectangle.getStyle())) { nextRectangle.setBackgroundColor(nextStarted.getTask().getColor()); } container.bind(nextRectangle, nextStarted); return nextRectangle; } private void renderProgressBar(TaskActivity nextStarted, GraphicPrimitiveContainer.Rectangle nextActivityRectangle) { if (nextStarted.getIntensity()==0) { return; } Task nextTask = nextStarted.getTask(); int nextLength = nextActivityRectangle.myWidth; Long workingRectanglesLength = (Long) myTask_WorkingRectanglesLength .get(nextTask); if (workingRectanglesLength != null) { long nextProgressLength = nextLength; String style; if (workingRectanglesLength.longValue() > nextLength) { myTask_WorkingRectanglesLength.put(nextTask, new Long( workingRectanglesLength.longValue() - nextLength)); style = "task.progress"; } else { nextProgressLength = workingRectanglesLength.longValue(); myTask_WorkingRectanglesLength.remove(nextTask); style = "task.progress.end"; } int nextMidY = nextActivityRectangle.getMiddleY(); GraphicPrimitive nextProgressRect = getPrimitiveContainer() .getLayer(1).createRectangle(nextActivityRectangle.myLeftX, nextMidY - 1, (int) nextProgressLength, 3); nextProgressRect.setStyle(style); getPrimitiveContainer().getLayer(1) .bind(nextProgressRect, nextTask); } } private void processFirstActivity(TaskActivity taskActivity) { boolean stop = taskActivity.getIntensity() == 0f; if (!stop) { processRegularActivity(taskActivity); } } private void createRightSideText(TaskActivity taskActivity) { java.awt.Rectangle bounds = getBoundingRectangle(taskActivity); String text = ""; int xText, yText; text = getTaskLabel(taskActivity.getTask(), RIGHT); xText = (int) bounds.getMaxX() + 9; yText = (int) myModel.getBoundingRectangle(taskActivity.getTask()) .getMaxY() - 3; Text textPrimitive = processText(xText, yText, text); } private void createDownSideText(TaskActivity taskActivity) { String text; text = getTaskLabel(taskActivity.getTask(), DOWN); if (text.length() > 0) { java.awt.Rectangle taskRectangle = myModel .getBoundingRectangle(taskActivity.getTask()); int xOrigin = (int) taskRectangle.getMinX() + (int) taskRectangle.getWidth() / 2; int yOrigin = (int) taskRectangle.getMaxY() + 2; Text textPrimitive = processText(xOrigin, yOrigin, text); textPrimitive.setAlignment(HAlignment.CENTER, VAlignment.TOP); } } private void createUpSideText(TaskActivity taskActivity) { String text; text = getTaskLabel(taskActivity.getTask(), UP); if (text.length() > 0) { java.awt.Rectangle taskRectangle = myModel .getBoundingRectangle(taskActivity.getTask()); int xOrigin = (int) taskRectangle.getMinX() + (int) taskRectangle.getWidth() / 2; int yOrigin = (int) taskRectangle.getMinY() - 3; Text textPrimitive = processText(xOrigin, yOrigin, text); textPrimitive.setAlignment(HAlignment.CENTER, VAlignment.BOTTOM); } } private void createLeftSideText(TaskActivity taskActivity) { String text; text = getTaskLabel(taskActivity.getTask(), LEFT); if (text.length() > 0) { java.awt.Rectangle taskRectangle = myModel .getBoundingRectangle(taskActivity.getTask()); int xOrigin = (int) taskRectangle.getMinX() - 9; int yOrigin = (int) (taskRectangle.getMaxY() - 3); Text textPrimitive = processText(xOrigin, yOrigin, text); textPrimitive.setAlignment(HAlignment.RIGHT, VAlignment.BOTTOM); } } private void processLastActivity(TaskActivity taskActivity) { if (taskActivity.getIntensity() != 0f) { processRegularActivity(taskActivity); } if (taskActivity.getTask().isMilestone()) { return; } createRightSideText(taskActivity); createDownSideText(taskActivity); createUpSideText(taskActivity); createLeftSideText(taskActivity); // //drawProjectBoundaries(); } private Text processText(int xorigin, int yorigin, String text) { Text res = getPrimitiveContainer().getLayer(2).createText(xorigin, yorigin, text); res.setStyle("text.ganttinfo"); return res; } // [dbarashev] This method violates the rule: rendering model knows (almost) // nothing about // specific rendering library (such as java.awt.*) and knows absolutely // nothing about // application framework (such as GanttGraphicArea) // I understand that it is nice to render coordinators with bold font and // linebreak. However, // there exist other ways of doing this
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -