From: Remi P. <pno...@us...> - 2002-02-10 13:26:04
|
Update of /cvsroot/jprojecttimer/jprojecttimer/de/cgarbs/apps/jprojecttimer In directory usw-pr-cvs1:/tmp/cvs-serv9434/jprojecttimer/de/cgarbs/apps/jprojecttimer Modified Files: Task.java GanttDiagram.java Log Message: Gantt diagram: centering of columns numbers + click to edit tasks Index: Task.java =================================================================== RCS file: /cvsroot/jprojecttimer/jprojecttimer/de/cgarbs/apps/jprojecttimer/Task.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Task.java 4 Feb 2002 22:53:53 -0000 1.6 --- Task.java 10 Feb 2002 13:26:00 -0000 1.7 *************** *** 15,18 **** --- 15,19 ---- import java.awt.Color; import java.awt.Graphics; + import java.awt.Rectangle; import java.util.Enumeration; import javax.swing.JFrame; *************** *** 54,57 **** --- 55,60 ---- private TaskList dependencies; + Rectangle taskBar = new Rectangle(0,0,0,0);; // for representation on Gantt Chart-> object? + /** Creates a new task with no dependencies, the name "new" and no duration. */ *************** *** 293,332 **** // 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); --- 296,346 ---- // Task + int taskX = x + textWidth + getStart() * ((width - textWidth) / cols); + int taskY = y + taskYMargin; + int taskWidth = getLength() * ((width - textWidth) / cols); + int taskHeight = height - 2 * taskYMargin; + if (taskWidth>0){ + taskBar.setBounds(taskX,taskY,taskWidth,taskHeight); + } + else{// diamond for 0 null duration task + taskBar.setBounds(taskX-taskHeight/2,taskY,taskHeight,taskHeight); + } + if (getLength() > 0){ g.setColor(Color.lightGray); ! g.fillRect(taskX, ! taskY, ! taskWidth + 1, ! taskHeight + 1 ); if (completion > 0) { g.setColor(Color.green); ! g.fillRect(taskX, ! taskY, ! taskWidth * completion / 100+1, ! taskHeight ); } g.setColor(Color.black); ! g.drawRect(taskX, ! taskY, ! taskWidth, ! taskHeight ); } ! else // draw a diamond 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] = taskX; ! yPoints[0] = taskY; ! xPoints[1] = xPoints[0] - taskHeight/2; ! yPoints[1] = yPoints[0] + taskHeight/2; ! xPoints[3] = xPoints[0] + taskHeight/2; ! yPoints[3] = yPoints[0] + taskHeight/2; xPoints[2] = xPoints[0]; ! yPoints[2] = yPoints[0] + taskHeight-1; if (completion==0){ g.setColor(Color.lightGray); *************** *** 337,341 **** } g.fillPolygon(xPoints,yPoints,4); ! g.setColor(Color.black); g.drawPolygon(xPoints,yPoints,4); --- 351,355 ---- } 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.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GanttDiagram.java 3 Feb 2002 15:35:42 -0000 1.8 --- GanttDiagram.java 10 Feb 2002 13:26:00 -0000 1.9 *************** *** 17,24 **** --- 17,31 ---- import java.awt.Graphics; import java.awt.Graphics2D; + import java.awt.Cursor; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.util.Enumeration; import java.util.Iterator; + import java.awt.event.MouseAdapter; + import java.awt.event.MouseMotionAdapter; + import java.awt.event.MouseEvent; + import javax.swing.JFrame; + + /** @author Christian Garbs <mi...@cg...> *************** *** 30,47 **** { Project project; GanttDiagram(Project project) { ! this.project = project; } public void refresh() { ! repaint(); } public void paint(Graphics graph) { ! drawGantt(graph, getSize().width, getSize().height); } --- 37,90 ---- { Project project; + // to detect click on task bar + private MouseAdapter GanttDiagramMouseAdapter = new MouseAdapter() + { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 1) { + TaskList tasks = project.getTaskList(); + for (int row = 0; row < tasks.size(); row++) { + Task task = (Task) tasks.elementAt(row); + if (task.taskBar.contains(e.getX(),e.getY())){ + task.showEditDialog(gui,tasks); + row = tasks.size(); // to finish the loop (dirty!) + repaint(); + } + } + } + } + }; + // to change the cursor appearance + private MouseMotionAdapter GanttDiagramMouseMotionAdapter = new MouseMotionAdapter(){ + public void mouseMoved(MouseEvent e){ + int cursor= Cursor.DEFAULT_CURSOR; + TaskList tasks = project.getTaskList(); + for (int row = 0; row < tasks.size(); row++) { + Task task = (Task) tasks.elementAt(row); + if (task.taskBar.contains(e.getX(),e.getY())){ + cursor = Cursor.HAND_CURSOR; + row = tasks.size(); // to finish the loop (dirty) + } + } + setCursor(new Cursor(cursor)); + } + }; + JFrame gui; GanttDiagram(Project project) { ! this.project = project; ! this.addMouseListener(GanttDiagramMouseAdapter); ! this.addMouseMotionListener(GanttDiagramMouseMotionAdapter); ! } public void refresh() { ! repaint(); } public void paint(Graphics graph) { ! drawGantt(graph, getSize().width, getSize().height); } *************** *** 49,169 **** { 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 ! ); ! } ! } ! ! } public int print(Graphics g, PageFormat pageFormat, int page) { ! if (page != 0) { ! return Printable.NO_SUCH_PAGE; ! } g.translate((int) pageFormat.getImageableX() + 2, (int) pageFormat.getImageableY()); ! drawGantt(g, (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight()); ! return Printable.PAGE_EXISTS; } } --- 92,205 ---- { 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+rightMargin,headerHeight); ! // Header ! g.setColor(Color.black); ! String colNumber = "1"; ! int colNumberMetric = g.getFontMetrics().stringWidth( colNumber ); ! g.drawString(Resource.get("task"), 5, headerHeight-3); ! g.drawString(colNumber, textWidth + 1 * (width - textWidth) / cols - colNumberMetric/2, headerHeight - 3); ! for (int col = colStep; col <= cols; col+=colStep) { ! colNumber = Integer.toString(col); ! colNumberMetric = g.getFontMetrics().stringWidth( colNumber ); ! g.drawString(colNumber, textWidth + col * ((width - textWidth) / cols) - colNumberMetric/2, 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+rightMargin,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 ! for (int row = 0; row < tasks.size(); row++) { ! ((Task) tasks.elementAt(row)).paint(g, ! 0, ! width, ! row * rowHeight + headerHeight, ! rowHeight, ! cols, ! textWidth, ! taskYMargin ! ); ! } ! } ! } public int print(Graphics g, PageFormat pageFormat, int page) { ! if (page != 0) { ! return Printable.NO_SUCH_PAGE; ! } g.translate((int) pageFormat.getImageableX() + 2, (int) pageFormat.getImageableY()); ! drawGantt(g, (int) pageFormat.getImageableWidth(), (int) pageFormat.getImageableHeight()); ! return Printable.PAGE_EXISTS; } } |