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

📄 taskmanagerimpl.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    /*     * (non-Javadoc)     *      * @see net.sourceforge.ganttproject.task.TaskManager#setTask(net.sourceforge.ganttproject.GanttTask)     */    public void setTask(Task task) {        int taskID = task.getTaskID();        myTaskMap.addTask(task);        if (taskID > getMaxID()) {            setMaxID(taskID);        }    }    public int getTaskCount() {        return myTaskMap.size();    }    public TaskLength getProjectLength() {        if (myTaskMap.isEmpty()) {            return createLength(getConfig().getTimeUnitStack()                    .getDefaultTimeUnit(), 0);        }        Result result = getAlgorithmCollection().getProjectBoundsAlgorithm()                .getBounds(Arrays.asList(myTaskMap.getTasks()));        return createLength(                getConfig().getTimeUnitStack().getDefaultTimeUnit(),                result.lowerBound, result.upperBound);    }    public Date getProjectStart() {        if (myTaskMap.isEmpty()) {            return myRoot.getStart().getTime();        }        Result result = getAlgorithmCollection().getProjectBoundsAlgorithm()                .getBounds(Arrays.asList(myTaskMap.getTasks()));        return result.lowerBound;    }    public Date getProjectEnd(){        if (myTaskMap.isEmpty()) {            return myRoot.getStart().getTime();        }        Result result = getAlgorithmCollection().getProjectBoundsAlgorithm()                .getBounds(Arrays.asList(myTaskMap.getTasks()));        return result.upperBound;    }        public TaskLength createLength(TimeUnit unit, float length) {        return new TaskLengthImpl(unit, length);    }    public TaskLength createLength(long count) {        return new TaskLengthImpl(getConfig().getTimeUnitStack()                .getDefaultTimeUnit(), count);    }    public String encode(TaskLength taskLength) {        StringBuffer result = new StringBuffer(String.valueOf(taskLength.getLength()));        result.append(myConfig.getTimeUnitStack().encode(taskLength.getTimeUnit()));        return result.toString();    }        public TaskLength createLength(String lengthAsString) throws DurationParsingException {        int state = 0;        StringBuffer valueBuffer = new StringBuffer();        Integer currentValue = null;        TaskLength currentLength = null;        lengthAsString += " ";        for (int i=0; i<lengthAsString.length(); i++) {            char nextChar = lengthAsString.charAt(i);            if (Character.isDigit(nextChar)) {                switch (state) {                    case 0:                        if (currentValue!=null) {                            throw new DurationParsingException();                        }                        state = 1;                        valueBuffer.setLength(0);                    case 1:                        valueBuffer.append(nextChar);                        break;                    case 2:                        TimeUnit timeUnit = findTimeUnit(valueBuffer.toString());                        if (timeUnit==null) {                            throw new DurationParsingException(valueBuffer.toString());                        }                        assert currentValue!=null;                        TaskLength localResult = createLength(timeUnit, currentValue.floatValue());                        if (currentLength==null) {                            currentLength = localResult;                        }                        else {                            if (currentLength.getTimeUnit().isConstructedFrom(timeUnit)) {                                float recalculatedLength = currentLength.getLength(timeUnit);                                currentLength = createLength(timeUnit, localResult.getValue()+recalculatedLength);                            }                            else {                                throw new DurationParsingException();                            }                        }                        state = 1;                        currentValue = null;                        valueBuffer.setLength(0);                        valueBuffer.append(nextChar);                        break;                                        }            }            else if(Character.isWhitespace(nextChar)) {                switch (state) {                    case 0:                        break;                    case 1:                        currentValue = Integer.valueOf(valueBuffer.toString());                        state = 0;                        break;                    case 2:                        TimeUnit timeUnit = findTimeUnit(valueBuffer.toString());                        if (timeUnit==null) {                            throw new DurationParsingException(valueBuffer.toString());                        }                        assert currentValue!=null;                        TaskLength localResult = createLength(timeUnit, currentValue.floatValue());                        if (currentLength==null) {                            currentLength = localResult;                        }                        else {                            if (currentLength.getTimeUnit().isConstructedFrom(timeUnit)) {                                float recalculatedLength = currentLength.getLength(timeUnit);                                currentLength = createLength(timeUnit, localResult.getValue()+recalculatedLength);                            }                            else {                                throw new DurationParsingException();                            }                        }                        state = 0;                        currentValue = null;                        break;                }            }            else {                switch (state) {                    case 1:                        currentValue = Integer.valueOf(valueBuffer.toString());                                            case 0:                        if (currentValue==null) {                            throw new DurationParsingException();                        }                        state = 2;                        valueBuffer.setLength(0);                    case 2:                        valueBuffer.append(nextChar);                        break;                                            }            }        }        if (currentValue!=null) {            currentValue = Integer.valueOf(valueBuffer.toString());            TimeUnit dayUnit = findTimeUnit("d");            currentLength = createLength(dayUnit, currentValue.floatValue());        }        return currentLength;    }    private TimeUnit findTimeUnit(String code) {        return myConfig.getTimeUnitStack().findTimeUnit(code);    }    public TaskLength createLength(TimeUnit timeUnit, Date startDate,            Date endDate) {        TaskLength result;        int sign = 1;        if (endDate.before(startDate)) {            sign = -1;            Date temp = endDate;            endDate = startDate;            startDate = temp;        }        if (timeUnit instanceof DateFrameable) {            DateFrameable df = (DateFrameable) timeUnit;            int unitCount = 0;            for (; startDate.before(endDate); unitCount++) {                startDate = df.adjustRight(startDate);            }            result = new TaskLengthImpl(timeUnit, unitCount*sign);        } else {            throw new IllegalArgumentException("Time unit=" + timeUnit                    + " is not date frameable");        }        return result;    }        public Date shift(Date original, TaskLength duration) {        GPCalendar calendar = RESTLESS_CALENDAR;        TimeUnit atomUnit = getConfig().getTimeUnitStack().getDefaultTimeUnit();        long atomDuration = (long) duration.getLength(atomUnit);        List activities = calendar.getActivities(original, atomUnit, atomDuration);        if (activities.isEmpty()) {            return original;        }        //final long length = duration.getLength();        final Date result;        if (atomDuration >= 0) {            GPCalendarActivity lastActivity = (GPCalendarActivity) activities                    .get(activities.size() - 1);            result = lastActivity.getEnd();        } else {            GPCalendarActivity firstActivity = (GPCalendarActivity) activities                    .get(0);            result = firstActivity.getStart();        }        return result;    }    public TaskDependencyCollection getDependencyCollection() {        return myDependencyCollection;    }    public AlgorithmCollection getAlgorithmCollection() {        return myAlgorithmCollection;    }    public TaskHierarchyManagerImpl getHierarchyManager() {        return myHierarchyManager;    }    public TaskDependencyConstraint createConstraint(final int constraintID) {        TaskDependencyConstraint result;        switch (constraintID) {        case GanttTaskRelationship.FS: {            result = new FinishStartConstraintImpl();            break;        }        case GanttTaskRelationship.FF: {            result = new FinishFinishConstraintImpl();            break;        }        case GanttTaskRelationship.SF: {            result = new StartFinishConstraintImpl();            break;        }        case GanttTaskRelationship.SS: {            result = new StartStartConstraintImpl();            break;        }        default: {            throw new IllegalArgumentException("Unknown constraint ID="                    + constraintID);        }        }        return result;    }    public int getMaxID() {        return myMaxID;    }    private void setMaxID(int id) {        myMaxID = id;    }    void increaseMaxID() {        myMaxID++;    }    public void addTaskListener(TaskListener listener) {        myListeners.add(listener);    }    public GPCalendar getCalendar() {        return getConfig().getCalendar();    }    public void fireTaskProgressChanged(Task changedTask) {        TaskPropertyEvent e = new TaskPropertyEvent(changedTask);        for (int i = 0; i < myListeners.size(); i++) {            TaskListener next = (TaskListener) myListeners.get(i);            next.taskProgressChanged(e);        }    }    void fireTaskScheduleChanged(Task changedTask, GanttCalendar oldStartDate,            GanttCalendar oldFinishDate) {        TaskScheduleEvent e = new TaskScheduleEvent(changedTask, oldStartDate,                oldFinishDate, changedTask.getStart(), changedTask.getEnd());        // List copy = new ArrayList(myListeners);        // myListeners.clear();        for (int i = 0; i < myListeners.size(); i++) {            TaskListener next = (TaskListener) myListeners.get(i);            next.taskScheduleChanged(e);        }    }    private void fireDependencyAdded(TaskDependency newDependency) {        TaskDependencyEvent e = new TaskDependencyEvent(                getDependencyCollection(), newDependency);        for (int i = 0; i < myListeners.size(); i++) {            TaskListener next = (TaskListener) myListeners.get(i);

⌨️ 快捷键说明

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