⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taskrendererimpl.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package net.sourceforge.ganttproject.chart;import java.awt.Point;import java.util.ArrayList;import java.util.Date;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import org.apache.commons.httpclient.methods.GetMethod;import net.sourceforge.ganttproject.GanttCalendar;import net.sourceforge.ganttproject.GanttPreviousStateTask;import net.sourceforge.ganttproject.Mediator;import net.sourceforge.ganttproject.calendar.GPCalendar;import net.sourceforge.ganttproject.chart.ChartModelBase.Offset;import net.sourceforge.ganttproject.chart.GraphicPrimitiveContainer.GraphicPrimitive;import net.sourceforge.ganttproject.chart.GraphicPrimitiveContainer.HAlignment;import net.sourceforge.ganttproject.chart.GraphicPrimitiveContainer.Rectangle;import net.sourceforge.ganttproject.chart.GraphicPrimitiveContainer.Text;import net.sourceforge.ganttproject.chart.GraphicPrimitiveContainer.VAlignment;import net.sourceforge.ganttproject.gui.options.model.DefaultEnumerationOption;import net.sourceforge.ganttproject.gui.options.model.EnumerationOption;import net.sourceforge.ganttproject.gui.options.model.GPOption;import net.sourceforge.ganttproject.gui.options.model.GPOptionGroup;import net.sourceforge.ganttproject.language.GanttLanguage;import net.sourceforge.ganttproject.task.BlankLineNode;import net.sourceforge.ganttproject.task.CustomColumEvent;import net.sourceforge.ganttproject.task.CustomColumsListener;import net.sourceforge.ganttproject.task.Task;import net.sourceforge.ganttproject.task.TaskActivity;import net.sourceforge.ganttproject.task.TaskContainmentHierarchyFacade;import net.sourceforge.ganttproject.task.TaskLength;import net.sourceforge.ganttproject.task.TaskProperties;import net.sourceforge.ganttproject.task.algorithm.SortTasksAlgorithm;import net.sourceforge.ganttproject.task.dependency.TaskDependency;import net.sourceforge.ganttproject.time.TimeFrame;import net.sourceforge.ganttproject.time.TimeUnit;/** * Created by IntelliJ IDEA. User: bard */public class TaskRendererImpl extends ChartRendererBase implements        TimeUnitVisitor, CustomColumsListener {    private List/* <TaskActivity> */myVisibleActivities;    private static final SortTasksAlgorithm ourAlgorithm = new SortTasksAlgorithm();    private List/* <TaskActivity> */myCurrentlyProcessed = new ArrayList();    private Map/* <TaskActivity,Integer> */myActivity2ordinalNumber = new HashMap();    private Map/* <Task, Integer> */myTask_WorkingRectanglesLength = new HashMap();    private int myPosX;    private TimeFrame myCurrentTimeFrame;    private TimeUnit myCurrentUnit;    private Date myUnitStart;    private boolean myProgressRenderingEnabled = true;    private boolean myDependenciesRenderingEnabled = true;    private GanttLanguage lang = GanttLanguage.getInstance();    private boolean isVisible[] = { false, false, false, false, true, false,            true };    private ChartModelImpl myModel;    private GPOption[] myDetailsOptions;    private EnumerationOption[] myLabelOptions;    private GPOptionGroup[] myOptionGroups;    public static final int UP = 0;    public static final int DOWN = 1;    public static final int LEFT = 2;    public static final int RIGHT = 3;    private ArrayList myTasks;    private ArrayList myPreviousStateTasks;    private List myPreviousStateCurrentlyProcessed = new ArrayList();    private static List ourInfoList;    static {        ourInfoList = new ArrayList();        ourInfoList.add("");        ourInfoList.add("id");        ourInfoList.add("taskDates");        ourInfoList.add("name");        ourInfoList.add("length");        ourInfoList.add("advancement");        ourInfoList.add("coordinator");        ourInfoList.add("resources");        ourInfoList.add("predecessors");    }    public TaskRendererImpl(ChartModelImpl model) {        super(model);        this.myModel = model;        getPrimitiveContainer().newLayer();        getPrimitiveContainer().newLayer();        DefaultEnumerationOption deo0 = new DefaultEnumerationOption("taskLabelUp",                ourInfoList);        DefaultEnumerationOption deo1 = new DefaultEnumerationOption("taskLabelDown",                ourInfoList);        DefaultEnumerationOption deo2 = new DefaultEnumerationOption("taskLabelLeft",                ourInfoList);        DefaultEnumerationOption deo3 = new DefaultEnumerationOption("taskLabelRight",                ourInfoList);        Mediator.addChangeValueDispatcher(deo0);        Mediator.addChangeValueDispatcher(deo1);        Mediator.addChangeValueDispatcher(deo2);        Mediator.addChangeValueDispatcher(deo3);        myLabelOptions = new EnumerationOption[] { deo0, deo1, deo2, deo3 };        myOptionGroups = new GPOptionGroup[1];        updateOptions();        Mediator.getCustomColumnsManager().addCustomColumnsListener(this);    }    private void addOption(String name) {        ourInfoList.add(name);        updateOptions();    }    private void removeOption(String name) {        ourInfoList.remove(name);        updateOptions();    }    private void updateOptions() {        myDetailsOptions = new GPOption[myLabelOptions.length];        System.arraycopy(myLabelOptions, 0, myDetailsOptions, 0,                myLabelOptions.length);        myOptionGroups[0] = new ChartOptionGroup("ganttChartDetails",                myDetailsOptions, myModel.getOptionEventDispatcher());    }    public boolean isTextUp() {        return myLabelOptions[UP].getValue() != null                && myLabelOptions[UP].getValue().length() != 0;    }    public boolean isTextDown() {        return myLabelOptions[DOWN].getValue() != null                && myLabelOptions[DOWN].getValue().length() != 0;    }    public void beforeProcessingTimeFrames() {        getPrimitiveContainer().clear();        getPrimitiveContainer().getLayer(1).clear();        getPrimitiveContainer().getLayer(2).clear();        myActivity2ordinalNumber.clear();        myTask_WorkingRectanglesLength.clear();        myActivitiesOutOfView.clear();        myVisibleActivities = getSortedTaskActivities();        if (myTasks != null) {            myPreviousStateTasks = (ArrayList) myTasks.clone();        }        myCurrentlyProcessed.clear();        myPosX = 0;    }    public void afterProcessingTimeFrames() {        for (int i=0; i<myActivitiesOutOfView.size(); i++) {            TaskActivity next = (TaskActivity) myActivitiesOutOfView.get(i);            Integer nextOrdNumber = (Integer) myActivity2ordinalNumber.get(next);            int topy = nextOrdNumber.intValue() * getRowHeight() + 4; // JA Added            GraphicPrimitiveContainer container = getContainerFor(next.getTask());            Rectangle rectangle = container.createRectangle(-10, topy, 1, getRowHeight());            container.bind(rectangle, next);        }        for (int i=0; i<myVisibleActivities.size(); i++) {            TaskActivity next = (TaskActivity) myVisibleActivities.get(i);            Integer nextOrdNumber = (Integer) myActivity2ordinalNumber.get(next);            int topy = nextOrdNumber.intValue() * getRowHeight() + 4; // JA Added            GraphicPrimitiveContainer container = getContainerFor(next.getTask());            Rectangle rectangle = container.createRectangle(getWidth()+10, topy, 1, getRowHeight());            container.bind(rectangle, next);        }                if (myDependenciesRenderingEnabled) {            createDependencyLines();        }    }    private boolean isPathExpanded(Task task) {        boolean result = true;        TaskContainmentHierarchyFacade taskHierarchy = getChartModel().getTaskManager().getTaskHierarchy();        for (Task supertask = taskHierarchy.getContainer(task); supertask!=null && supertask!=getChartModel().getTaskManager().getRootTask(); supertask = taskHierarchy.getContainer(supertask)) {            if (!supertask.getExpand()) {                result = false;                break;            }        }        return result;    }        private List/* <Task> */getSortedTaskActivities() {        List visibleTasks = ((ChartModelImpl) getChartModel())                .getVisibleTasks();        List visibleActivities = new ArrayList();        myActivity2ordinalNumber.clear();        for (int i = 0; i < visibleTasks.size(); i++) {            if (visibleTasks.get(i).equals(BlankLineNode.BLANK_LINE))                continue; // todo a revoir...            Task nextTask = (Task) visibleTasks.get(i);            Integer nextOrdinal = new Integer(i);            if (nextTask == null) {                continue; // case of space            }            TaskActivity[] activities = nextTask.getActivities();            //System.err.println("[TaskRendererImpl]task="+nextTask+"\nactivities="+java.util.Arrays.asList(activities));            for (int j = 0; j < activities.length; j++) {                myActivity2ordinalNumber.put(activities[j], nextOrdinal);                visibleActivities.add(activities[j]);            }            float totalTaskLength = nextTask.getDuration().getLength(                    getChartModel().getBottomUnit())                    * getChartModel().getBottomUnitWidth();            myTask_WorkingRectanglesLength.put(nextTask, new Long(                    (long) (totalTaskLength                            * nextTask.getCompletionPercentage() / 100)));        }        Set hashedVisible = new HashSet(visibleActivities);        Integer maxOrdinal = new Integer(hashedVisible.size()+1);        Integer minOrdinal = new Integer(-2);        for (int i=0; i<visibleTasks.size(); i++) {            Task next = (Task)visibleTasks.get(i);            TaskDependency[] dependencies = next.getDependenciesAsDependant().toArray();            for (int j=0; j<dependencies.length; j++) {                TaskDependency nextDependency = dependencies[j];                TaskActivity dependeeActivity = nextDependency.getActivityBinding().getDependeeActivity();                if (hashedVisible.contains(dependeeActivity)) {                    continue;                }                    Task dependeeTask = dependeeActivity.getTask();                if (false==getChartModel().getTaskManager().getTaskHierarchy().contains(dependeeTask)) {                    continue;                }                if (false==isPathExpanded(dependeeTask)) {                    continue;                }                    int diff = getChartModel().getTaskManager().getTaskHierarchy().compareDocumentOrder(next, dependeeTask);                    assert diff!=0;                    Integer dependeePosition = diff<0 ? maxOrdinal : minOrdinal;                    myActivity2ordinalNumber.put(dependeeActivity, dependeePosition);                    visibleActivities.add(dependeeActivity);                    hashedVisible.add(dependeeActivity);                }            dependencies = next.getDependenciesAsDependee().toArray();            for (int j=0; j<dependencies.length; j++) {                TaskDependency nextDependency = dependencies[j];                TaskActivity dependantActivity = nextDependency.getActivityBinding().getDependantActivity();                if (hashedVisible.contains(dependantActivity)) {                    continue;                }                    Task dependantTask = dependantActivity.getTask();                if (false==getChartModel().getTaskManager().getTaskHierarchy().contains(dependantTask)) {                    continue;                }                if (false==isPathExpanded(dependantTask)) {                    continue;                }                    int diff = getChartModel().getTaskManager().getTaskHierarchy().compareDocumentOrder(next, dependantTask);                    assert diff!=0;                    Integer dependantPosition = diff<0 ? maxOrdinal : minOrdinal;                    myActivity2ordinalNumber.put(dependantActivity, dependantPosition);                    visibleActivities.add(dependantActivity);                    hashedVisible.add(dependantActivity);                }            }        ourAlgorithm.sortByStartDate(visibleActivities);        return visibleActivities;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -