|
From: Remi P. <pno...@us...> - 2002-02-03 13:17:16
|
Update of /cvsroot/jprojecttimer/jprojecttimer/de/cgarbs/apps/jprojecttimer
In directory usw-pr-cvs1:/tmp/cvs-serv19335/jprojecttimer/de/cgarbs/apps/jprojecttimer
Modified Files:
Task.java GanttDiagram.java
Log Message:
Improvement of Gantt Diagram
Index: Task.java
===================================================================
RCS file: /cvsroot/jprojecttimer/jprojecttimer/de/cgarbs/apps/jprojecttimer/Task.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Task.java 2002/01/25 20:41:15 1.3
--- Task.java 2002/02/03 13:17:13 1.4
***************
*** 270,315 ****
/** */
! 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
! );
! }
}
--- 270,343 ----
/** */
! public void paint(Graphics g, int x, int width, int y, int height, int cols, int textWidth, int taskYMargin)
{
! //g.setColor(Color.black);
! // Linie oben-> moved to GanttDiagram
! // g.drawLine(x,y,x+width,y);
! // Spalten -> moved to GanttDiagram
! //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.black);
g.drawString(getName(), x+5, y+height/2);
// Task
! if (getLength() > 0){
g.setColor(Color.lightGray);
! g.fillRect(x + textWidth + getStart() * ((width - textWidth) / cols),
! y + taskYMargin,
! getLength() * ((width - textWidth) / cols) + 1,
! height + 1 - 2 * taskYMargin
! );
! if (completion > 0) {
! g.setColor(Color.green);
! g.fillRect(x + textWidth + getStart() * ((width - textWidth) / cols),
! y + taskYMargin,
! getLength() * completion*((width - textWidth) / cols) / 100+1,
! height + 1 - 2 * taskYMargin
! );
! }
! g.setColor(Color.black);
! g.drawRect(x + textWidth + getStart() * ((width - textWidth) / cols),
! y + taskYMargin,
! getLength() * ((width - textWidth) / cols),
! height - 2 * taskYMargin
! );
! }
! else // draw a losange for milestones
! {
! int xPoints[] = new int[4];
! int yPoints[] = new int[4];
! int startX = x + textWidth + getStart() * ((width - textWidth) / cols);
! int startY = y + taskYMargin;
! xPoints[0] = startX;
! yPoints[0] = startY;
! xPoints[1] = xPoints[0] - (height/2 - taskYMargin);
! yPoints[1] = yPoints[0] + height/2 - taskYMargin;
! xPoints[3] = xPoints[0] + height/2 - taskYMargin;
! yPoints[3] = yPoints[0] + height/2 - taskYMargin;
! xPoints[2] = xPoints[0];
! yPoints[2] = yPoints[0] + height - 2 * taskYMargin-1;
! if (completion==0){
! g.setColor(Color.lightGray);
!
! }
! else{
! g.setColor(Color.green);
! }
! g.fillPolygon(xPoints,yPoints,4);
! g.setColor(Color.black);
! g.drawPolygon(xPoints,yPoints,4);
!
! }
! }
}
Index: GanttDiagram.java
===================================================================
RCS file: /cvsroot/jprojecttimer/jprojecttimer/de/cgarbs/apps/jprojecttimer/GanttDiagram.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** GanttDiagram.java 2002/01/25 20:41:15 1.6
--- GanttDiagram.java 2002/02/03 13:17:13 1.7
***************
*** 19,22 ****
--- 19,23 ----
import java.awt.print.Printable;
import java.util.Enumeration;
+ import java.util.Iterator;
/** @author Christian Garbs <mi...@cg...>
***************
*** 46,93 ****
{
Graphics2D g = (Graphics2D) graph;
!
! TaskList tasks = project.getTaskList();
! int textWidth = 70;
! int headerHeight = 30;
! int step=5;
! g.setColor(Color.white);
! g.fillRect(0, 0, width + 1, height + 1);
!
! if (tasks.size() > 0) {
! tasks.recalculate();
! int cols = tasks.projectEnd();
! if (cols == 0) {
! // avoid div by zero
! cols = 1;
! }
!
! // Header
! g.setColor(Color.blue);
! g.drawString(Resource.get("task"), 5, headerHeight-3);
! g.drawString("1", textWidth + 3, headerHeight - 3);
! for (int col = -1; col < cols; col+=3) {
! if (col > 0) {
! g.drawString(Integer.toString(col+1), (int) (textWidth + (col * (width - textWidth)) / cols + 3), headerHeight - 3);
! }
! }
! // Tasks
! int size = tasks.size();
! if (size == 0) {
! // avoid div by zero
! size = 1;
! }
! for (int row = 0; row < tasks.size(); row++) {
! ((Task) tasks.elementAt(row)).paint(g,
! 0,
! width,
! (row * (height - headerHeight)) / tasks.size() + headerHeight,
! (height - headerHeight) / tasks.size(),
! cols,
! textWidth
! );
! }
! }
!
! }
--- 47,154 ----
{
Graphics2D g = (Graphics2D) graph;
! TaskList tasks = project.getTaskList();
! int textWidth = 70;
! int headerHeight = 30;
! int taskYMargin = 7; // top/bottom margin of each task bar
! int rightMargin = 10; // mainly for task with lenght 0
! int colStep = 5;// step to write column text
! g.setColor(Color.white);
! g.fillRect(0, 0, width + 1, height + 1);
!
! width = width - rightMargin;
!
! if (tasks.size() > 0) {
! tasks.recalculate();
! int cols = tasks.projectEnd();
! if (cols == 0) {
! // avoid div by zero
! cols = 1;
! }
!
! // Headings coloring
! g.setColor(Color.yellow);
! g.fillRect(0,0,textWidth,height);
! g.fillRect(0,0,width,headerHeight);
! // Header
! g.setColor(Color.black);
! g.drawString(Resource.get("task"), 5, headerHeight-3);
! g.drawString("1", textWidth + 3, headerHeight - 3);
! for (int col = -1; col <= cols-colStep; col+=colStep) {
! if (col > 0) {
! g.drawString(Integer.toString(col+1), textWidth + col * ((width - textWidth) / cols) + 3, headerHeight - 3);
! }
! }
! int rowHeight = (height - headerHeight)/ tasks.size();
! // Horizontal lines to separate tasks
! g.setColor(Color.lightGray);
! for (int row = 0; row < tasks.size(); row++) {
! g.drawLine(0,row*rowHeight + headerHeight,width,row*rowHeight + headerHeight);
! }
! // Vertical lines for time scale
! for (int col=0;col<=cols;col+=1){
! if (col % colStep == 0){ // standard line
! g.drawLine(textWidth + col * ((width - textWidth) / cols),headerHeight,
! textWidth + col * ((width - textWidth) / cols),height);
! }
! else{// dotted line
! for (int y=headerHeight;y<height;y+=10){
! g.drawLine( textWidth + col * ((width - textWidth) / cols),y,
! textWidth + col * ((width - textWidth) / cols),y+5);
! }
! }
! }
! // Links between tasks
! g.setColor(Color.red);
! for (int row = 0; row < tasks.size(); row++) {
! Task task = (Task) tasks.elementAt(row);
! for (Iterator i = task.getDependencies().iterator(); i.hasNext();) {
! Task prevTask = (Task) i.next();
! int prevRow = tasks.indexOf(prevTask);
! int startX = textWidth + task.getStart() * ((width - textWidth) / cols);
! int endX = textWidth + (prevTask.getStart()+prevTask.getLength()) * ((width - textWidth) / cols);
! int startY = row*rowHeight + headerHeight + taskYMargin;
! int endY = prevRow*rowHeight + headerHeight + taskYMargin + rowHeight/2;
! int midY;
! if (row>prevRow){ // under its predecessor
! midY = (prevRow+1)*rowHeight + headerHeight;
! }
! else { // above its predecessor
! midY = prevRow*rowHeight + headerHeight;
! }
! g.drawLine (startX, startY,startX,midY);
! g.drawLine (startX,midY,endX,midY);
! g.drawLine (endX,midY,endX,endY);
! // arrow
! int xPoints[] = new int[3];
! int yPoints[] = new int[3];
! xPoints[0] = startX;
! yPoints[0] = startY;
! xPoints[1] = xPoints[0] -4;
! yPoints[1] = yPoints[0] -4;
! xPoints[2] = xPoints[0] +5;
! yPoints[2] = yPoints[0] -4;
! g.fillPolygon(xPoints,yPoints,3);
! }
! }
! // Tasks
! int size = tasks.size();
! if (size == 0) {
! // avoid div by zero
! size = 1;
! }
! for (int row = 0; row < tasks.size(); row++) {
! ((Task) tasks.elementAt(row)).paint(g,
! 0,
! width,
! row * ((height - headerHeight) / tasks.size()) + headerHeight,
! (height - headerHeight) / tasks.size(),
! cols,
! textWidth,
! taskYMargin
! );
! }
! }
!
! }
|