?? task.java
字號:
/* * $Id: Task.java,v 1.1.1.1 2001/03/20 22:17:40 mastermitch Exp $ * * 2001 (C) by Christian Garbs <mitch@uni.de> * * Licensed under GNU GPL (see COPYING for details) * */package de.cgarbs.apps.jprojecttimer;import java.awt.Color;import java.awt.Graphics;import java.util.Enumeration;import javax.swing.JLabel;/** A task is a single action that is part of a project. * * @author Christian Garbs <mitch@cgarbs.de> * @version $Id: Task.java,v 1.1.1.1 2001/03/20 22:17:40 mastermitch Exp $ */public class Task{ /** */ private boolean needsToBeSaved; /** When this task is marked dirty, it has changed and must be recalculated. */ private boolean dirty; /** This is the beginning time of this task. */ private int start = 0; /** This is the duration of this task. */ private int length = 0; /** */ private int completion = 0; /** This is the name of this task. */ private String name = " "; /** This is a list of Tasks that must be finished before this task can start. */ private TaskList dependencies; /** Creates a new task with no dependencies, the name "new" and no duration. */ public Task() { this(new TaskList()); } /** Creates a new task with the given dependencies, the name "new" and no duration. * * @param dependencies A list of tasks that must be finished before the * new task can start. */ public Task(TaskList dependencies) { this(Resource.get("defaultTaskName"), 1, 0, dependencies); } /** Creates a new task with the given parameters. * * @param name The name of the new task. * @param length The duration of the new task. * @param completion * @param dependencies A list of tasks that must be finished before the * new task can start. */ public Task(String name, int length, int completion, TaskList dependencies) { setName(name); setLength(length); setCompletion(completion); setDependencies(dependencies); needsToBeSaved = true; } /** Tags this task as dirty (meaning it's contents have changed and it has to be recalculated). */ public void tagAsDirty() { dirty = true; } /** Calculates the starting time of this task depending on the ending times of the tasks that need to be finished before. */ public void calculate() { if (dirty) { start = 0; for(Enumeration e = dependencies.elements(); e.hasMoreElements(); ) { Task v = (Task) e.nextElement(); if (v.getEnd() > start) { start = v.getEnd(); } } dirty = false; } } /** Returns the ending time of this task. * * @return Ending time of this task */ public int getEnd() { if (dirty) { calculate(); } return start + length; } /** Returns the starting time of this task. * * @return Starting time of this task */ public int getStart() { if (dirty) { calculate(); } return start; } /** Returns the duration of this task. * * @return Duration of this task */ public int getLength() { return length; } /** */ public int getCompletion() { return completion; } /** Returns the name of this task. * * @return Name of this task */ public String getName() { return name; } /** Returns a list of all tasks that have to be finished before this task can begin. * * @return List of depending tasks */ public TaskList getDependencies() { return dependencies; } /** Changes the name of this task. * * @param name New name of task */ public void setName(String name) { this.name = name; needsToBeSaved = true; } /** Changes the duration of this task. * * @param length New duration of task */ public void setLength(int length) { if (length < 0) { length = 0; } if (this.length != length) { this.length = length; dirty = true; } needsToBeSaved = true; } /** */ public void setCompletion(int completion) { if (completion < 0) { this.completion = 0; } else if (completion > 100) { this.completion = 100; } else { this.completion = completion; } needsToBeSaved = true; } /** Changes the tasks that have to be finished before this task can start. * * @param dependencies New list of dependent tasks */ public void setDependencies(TaskList dependencies) { // eventuell noch ein if(ungleich)then dirty drumsetzen (siehe setLength) this.dependencies = dependencies; dirty = true; needsToBeSaved = true; } /** Checks whether starting and ending time of task have to be recalculated. * * @return true - task has changed, recalculation is necessary */ public boolean isDirty() { return dirty; } /** Recursively checks if a list * * @param parent * @return true - a recursion has been found (that's bad) */ boolean checkRecursion(Task parent) { boolean recursion = false; if (parent == this) { recursion = true; } else { for (Enumeration e = dependencies.elements(); e.hasMoreElements(); ) { if (((Task) e.nextElement()).checkRecursion(parent)) { recursion = true; } } } return recursion; } /** Returns the name of this task. * * @return Name of this task */ public String toString() { return getName(); } /** */ public boolean needsToBeSaved() { return needsToBeSaved; } /** */ public void hasBeenSaved() { needsToBeSaved = false; } /** */ public void paint(Graphics g, int x, int width, int y, int height, int cols, int textWidth) { g.setColor(Color.black); // Linie oben g.drawLine(x,y,x+width,y); // Spalten for (int c = 0; c < cols; c++) { g.drawLine((int)( x + textWidth + (c * (width - textWidth)) / cols), y, (int) (x + textWidth + (c * (width - textWidth)) / cols), y+height ); } // Text g.setColor(Color.blue); g.drawString(getName(), x+5, y+height/2); // Task g.setColor(Color.darkGray); g.fillRect((int) (x + textWidth + (getStart() * (width - textWidth)) / cols), y, (int) ((getLength() * (width - textWidth)) / cols + 1), height + 1 ); if (completion > 0) { g.setColor(Color.lightGray); g.fillRect((int) (x + textWidth + (getStart() * (width - textWidth)) / cols), y, (int) (((getLength() * (width - textWidth)) / cols + 1) * (completion / 100.0)), height + 1 ); } g.setColor(Color.black); g.drawRect((int) (x + textWidth + (getStart() * (width - textWidth)) / cols), y, (int) ((getLength() * (width - textWidth)) / cols), height ); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -