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

📄 task.java

📁 Owing to the applet Gantt chart source yard, already Chinese melt, Gantt chart can demonstrate a Chi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	public String getIndentedName() {		StringBuffer spaces = new StringBuffer();		Task p = parentTask;		while (p != null) {			spaces.append("  ");			p = p.parentTask;		}		return spaces.toString() + name;	}	/**	 * Agrega una restriccion de la cual esta tarea depende	 * Si ya existe un constraint entre estas tareas se genera una excepcion.	 * @param c	 */	void addConstraint(Constraint c) throws GanttException {		c.getMasterTask().checkConstrained(c.getSlaveTask());		for (Iterator it = c.getMasterTask().childConstraints.iterator();			it.hasNext();			) {			Constraint ct = (Constraint) it.next();			if (ct.getSlaveTask() == this)				throw new GanttException(Messages.getString("task.error.dupConstraint")); //$NON-NLS-1$		}		c.getMasterTask().childConstraints.addElement(c);		constraints.addElement(c);		setDirty();		project.sendChange(new ProjectChange(this));	}	/**	 * Retorna el largo de la tarea en minutos habiles.	 * Esta funcion no debe llamar a recalc ya que no se apoya en ella.	 */	public int getLength() {		return length;	}	/**	 * Asigna el largo de la tarea en minutos habiles.	 */	public void setLength(int newLength) throws GanttException {		if (isResume()) {			throw new GanttException(Messages.getString("task.error.chgLength")); //$NON-NLS-1$		}		Command cmd = new SetCommand(this, "setLength", newLength, length);		length = newLength;		setDirty();		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}	/**	 * Asigna el nombre.	 */	public void setName(String newName) {		Command cmd = new SetCommand(this, "setName", newName, name);		if (newName == null)			name = "";		else			name = newName;		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}	/**	 * Retorna la fecha minima en que la tarea puede comenzar	 */	public Date getNotBeforeDate() {		return notBeforeDate;	}	/**	 * Asigna la fecha minima en que la tarea puede comenzar	 */	public void setNotBeforeDate(Date newNotBeforeDate) throws GanttException {		if (childTasks.size() > 0) {			throw new GanttException(Messages.getString("task.error.chgNotBeforeDate")); //$NON-NLS-1$		}		Command cmd =			new SetCommand(				this,				"setNotBeforeDate",				newNotBeforeDate,				notBeforeDate);		notBeforeDate = newNotBeforeDate;		setDirty();		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}	/**	 * retorna los comentarios asociados a la tarea	 */	public String getComments() {		return comments;	}	/**	 * Asigna los comentarios de la tarea	 */	public void setComments(String newComments) {		Command cmd =			new SetCommand(this, "setComments", newComments, comments);		comments = newComments;		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}	/**	 * Retorna la fecha calculada de inicio de la tarea	 * de acuerdo al calendario del proyecto	 */	public Date getStartDate() {		recalc();		return startDate;	}	/**	 * Retorna la fecha de termino de la tarea en dias reales	 * Asume que una tarea de un dia se terminan a ultima hora del mismo dia	 * Todas las tareas comienzan a primera hora del dia.	 * Solo cuentan los campos de dia (no los de hh,mm,ss y ms)	 */	public Date getFinishDate() {		recalc();		return finishDate;	}	public Vector getChildTasks() {		return childTasks;	}	// Metodos protegidos	/**     * Marca la tarea para ser recalculada...     * Originalmente recalculaba recursivamente:     * <ul>      * <li>los hijos: si depende de otras tareas (incluso indirectamente)      * <li>los dependientes     * <li>La tarea padre     * </ul>     * 	 * Hoy llama a {@link Project#allDirty()} y asigna todas las tareas     * como sucias, esto elimino muchos errores en el recalculo y no     * toma tanto tiempo como para ser un problema.	 * Recursiva sobre las tareas resumen	 */	protected void setDirty() {        project.allDirty();	}	/**	 * Obtiene la fecha de inicio basado solo en contraints y en las restricciones	 * heredadas de la tarea padre.	 * <p>Si no hay constraints, se parte desde la fecha de inicio del proyecto.</p>	 * <p>no afecta el estado de dirty.</p>	 * 	 * @returns la fecha de inicio de la tarea	 */	protected Date getConstrainedStart() {		Date cStart = notBeforeDate;		if (cStart == null)			cStart = project.getStartDate();		for (Enumeration e = constraints.elements(); e.hasMoreElements();) {			Constraint c = (Constraint) e.nextElement();			Date test = c.getStartDate();			if ((cStart == null) || (test.after(cStart))) {				cStart = test;			}		}		//		Si el resumen padre tiene restricciones, se heredan		if (parentTask != null) {			Date cDate = parentTask.getConstrainedStart();			if (cStart.before(cDate)) {				cStart = cDate;			}		} else { // es la tarea principal. ya tiene un startDate		}		return cStart;	}	/**	 * Calculo de restricciones	 * revisar restricciones.	 * deja el estado limpio (not dirty)	 */	protected void recalc() {		if (!dirty)			return;		startDate = getConstrainedStart();		if (childTasks.size() > 0) { // es tarea resumen? tiene tareas hijas			// inicio=min({child startdates})						Date minChild = null;			Date maxChild = null;			for (Enumeration e = childTasks.elements(); e.hasMoreElements();) {				Task t = (Task) e.nextElement();				Date cDate = t.getStartDate();				if ((minChild == null) || (minChild.after(cDate))) {					minChild = cDate;				}				cDate = t.getFinishDate();				if ((maxChild == null) || (maxChild.before(cDate))) {					maxChild = cDate;				}			}			if (minChild != null)				startDate = minChild;			finishDate = maxChild;			length =				project.getDateOrganizer().daysBetween(startDate, finishDate);			double a = 0, b = 0;			for (Enumeration e = childTasks.elements(); e.hasMoreElements();) {				Task t = (Task) e.nextElement();				a += (t.getLength() * t.getCompleted()) / 100.0;				b += t.getLength();			}			completed = (int) (100.0 * (a / b));		} else { // es una hoja!						finishDate =				project.getDateOrganizer().getFinishDate(startDate, length);		}		dirty = false;	}	public Vector getChildConstraints() {		return childConstraints;	}	/**	 * Retorna los minutos totales asociados a un recurso.	 * @param r recurso	 * @return	 */	public int getTotalResourceUnits(Resource r) {		int childUnits = 0;		if (childTasks.size() != 0) { // es tarea resumen?			for (Enumeration e = childTasks.elements(); e.hasMoreElements();) {				Task t = (Task) e.nextElement();				childUnits += t.getTotalResourceUnits(r);			}		}		return getLocalTotalResourceUnits(r) + childUnits;	}	/**	 * Retorna los minutos totales asociados a un recurso solo en esta tarea.	 * @param r recurso	 * @return	 */	public int getLocalTotalResourceUnits(Resource r) {		int units = 0;		int minutes =			getLength() * project.getDateOrganizer().workHours * 60				+ project.getDateOrganizer().workMinutes;		for (Iterator i = getAsignations().iterator(); i.hasNext();) {			Asignation a = (Asignation) i.next();			if (a.getResource().equals(r)) {				units = (int) (a.getUnits() * minutes / 100.0);				break;			}		}		return units;	}	/**	 * Retorna los minutos trabajados asociados a un recurso.	 * @param r recurso	 * @return	 */	public int getWorkedResourceUnits(Resource r) {		int childUnits = 0;		if (childTasks.size() != 0) { // es tarea resumen?			for (Enumeration e = childTasks.elements(); e.hasMoreElements();) {				Task t = (Task) e.nextElement();				childUnits += t.getWorkedResourceUnits(r);			}		}		return getLocalWorkedResourceUnits(r) + childUnits;	}	/**	 * Retorna los minutos trabajados asociados a un recurso solo en esta tarea.	 * @param r recurso	 * @return	 */	public int getLocalWorkedResourceUnits(Resource r) {		int units = 0;		int minutes =			getLength() * project.getDateOrganizer().workHours * 60				+ project.getDateOrganizer().workMinutes;		for (Iterator i = getAsignations().iterator(); i.hasNext();) {			Asignation a = (Asignation) i.next();			if (a.getResource().equals(r)) {				units = (int) (a.getUnits() * minutes / 100.0);				units = (int) (units * getCompleted() / 100.0);				break;			}		}		return units;	}	/**	 * Asigna el nivel de completitud de la tarea.	 * @param c completitud en un porcentaje en el rango 0..100	 */	public void setCompleted(int newCompleted) {		if (childTasks.size() != 0) { // es tarea resumen?			throw new RuntimeException(Messages.getString("task.error.chgCompleted")); //$NON-NLS-1$		}		Command cmd =			new SetCommand(this, "setCompleted", newCompleted, completed);		completed = newCompleted;		setDirty();		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}	/**	 * Obtiene el porcentaje terminado de una tarea.	 * En el caso de las tareas resumen, el total se calcula en	 * la funcion recalc	 * @return	 */	public int getCompleted() {		return completed;	}	/**	 * Reasigna al recurso con una cantidad de unidades	 * Si ya esta asignado, lo reasigna.	 * Si las unidades son cero, se elimina la asignacion	 * existente (o no se agrega).	 * @param r	 * @param u	 */	public void addResource(Resource r, int u) {		removeResource(r);		if (u == 0) {			project.sendChange(new ProjectChange(this));			return;		}		Asignation a = new Asignation();		a.setResource(r);		a.setUnits(u);		resources.addElement(a);		project.sendChange(new ProjectChange(this));	}	/**	 * Remueve un recurso de la lista de recursos	 * 	 */	public void removeResource(Resource r) {		for (int i = 0; i < resources.size(); i++) {			Asignation a = (Asignation) resources.elementAt(i);			if (a.getResource().equals(r)) {				resources.remove(i);				return;			}		}		project.sendChange(new ProjectChange(this));	}	public Vector getAsignations() {		return resources;	}	/**	 *  	 * @param r	 * @return	 */	public int getAsignationUnits(Resource r) {		for (Iterator i = resources.iterator(); i.hasNext();) {			Asignation a = (Asignation) i.next();			if (a.getResource() == r)				return a.getUnits();		}		return 0;	}	public Task getParentTask() {		return parentTask;	}	public boolean isChildOf(Task p) {		Task t = this;		while ((t.parentTask != null) && (t.parentTask != p)) {			t = t.parentTask;		}		return (p == t.parentTask);	}	// serializacion	private void readObject(java.io.ObjectInputStream in)		throws IOException, ClassNotFoundException {		in.defaultReadObject();		// reiniciar variables transientes...		dirty = true;	}	/**	 * Retorna un string con las asignaciones de personas	 * @return	 */	public String getCompletionDescription() {		Vector a = getAsignations();		StringBuffer toPrint = new StringBuffer(30);		for (int j = 0; j < a.size(); j++) {			Asignation asign = (Asignation) a.elementAt(j);			toPrint.append(" ");			toPrint.append(asign.getResource().getInitials());			toPrint.append("[");			toPrint.append(asign.getUnits());			toPrint.append("%]");		}		//toPrint.append(" - ");		//toPrint.append(getCompleted());		//toPrint.append("%");		return toPrint.toString();	}	/**	 * @see java.lang.Object#toString()	 */	public String toString() {		return "Task(" + name + ")";	}	int visibleIndex = 0;	/**	 * indice visible	 * @return indice 1..	 */	public int getVisibleIndex() {		return visibleIndex;	}	boolean childsVisible = true;	public boolean getChildsVisible() {		if (!isResume())			return true;		return childsVisible;	}	public void setChildsVisible(boolean b) {		childsVisible = b;		// reorganizar los ids visibles		project.rebuildVIds();		project.registerCommand(			new SetCommand(this, "setChildsVisible", b, !b));		project.sendChange(new ProjectChange(this));	}	public boolean isVisible() {		Task p = parentTask;		while (p != null) {			if (!p.childsVisible)				return false;			p = p.parentTask;		}		return true;	}	/**	 * Retorna una referencia al objeto que administra los colores de esta tarea	 *	 */	public TaskColors getTaskColors() {		if (isResume())			return project.getGraphColors().defaultResumeColors;		return project.getGraphColors().defaultTaskColors;	}	Vector snapshots = new Vector();	/**	 * Almacena el estado de la tarea en un snapshot	 * @param date	 * @param name	 */	public void takeSnapshot(Date date) {		snapshots.add(new SnapShot(date, this));	}	/**	 * Quita un snapshot de la lista	 * @param date	 */	public void removeSnapshot(Date date) {		for (int i = 0; i < snapshots.size(); i++) {			SnapShot ss = (SnapShot) snapshots.get(i);			if (ss.date.equals(date)) {				snapshots.remove(ss);			}		}	}	public SnapShot getSnapshot(Date d) {		for (int i = 0; i < snapshots.size(); i++) {			SnapShot ss = (SnapShot) snapshots.get(i);			if (ss.date.equals(d))				return ss;		}		return null;	}	public static class SnapShot {		public Date date;		public Date start, end;		int completed;		public SnapShot(Date d, Task t) {			date = d;			start = t.getStartDate();			end = t.getFinishDate();			completed = t.getCompleted();		}		/** 		 * Constructor para cuando se lee desde un XML.		 * @param d		 * @param t		 */		public SnapShot(Date d, Date s, Date e, int c) {			date = d;			start = s;			end = e;			completed = c;		}	}	public int getPriority() {		return priority;	}	public void setPriority(int p) {		Command cmd = new SetCommand(this, "setPriority", p, priority);		priority = p;		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}	public int getMinLength() {		return minLength;	}	public int getMaxLength() {		return maxLength;	}	public void setMinLength(int newLength) {		Command cmd =			new SetCommand(this, "setMinLength", newLength, minLength);		minLength = newLength;		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}	public void setMaxLength(int l) {		Command cmd = new SetCommand(this, "setMaxLength", l, maxLength);		maxLength = l;		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}	public String getNotes() {		return notes;	}	public void setNotes(String newNotes) {		Command cmd = new SetCommand(this, "setNotes", newNotes, notes);		notes = newNotes;		project.registerCommand(cmd);		project.sendChange(new ProjectChange(this));	}}

⌨️ 快捷键说明

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