KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > taskblocks > modelimpl > TaskPainterImpl


1 /*
2  * Copyright (C) Jakub Neubauer, 2007
3  *
4  * This file is part of TaskBlocks
5  *
6  * TaskBlocks is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * TaskBlocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */

19
20 package taskblocks.modelimpl;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.FontMetrics JavaDoc;
24 import java.awt.Graphics2D JavaDoc;
25 import java.awt.Rectangle JavaDoc;
26
27 import taskblocks.Colors;
28 import taskblocks.graph.TaskGraphPainter;
29
30 public class TaskPainterImpl implements TaskGraphPainter {
31
32     Color JavaDoc _taskCol = Colors.TASK_COLOR;
33     Color JavaDoc _taskSelCol = _taskCol.brighter();
34     Color JavaDoc _taskBorderCol = _taskCol.darker();
35     Color JavaDoc _taskBorderSelCol = Colors.SELECTOIN_COLOR;
36     
37     public void paintTask(Object JavaDoc task, Graphics2D JavaDoc g2, Rectangle JavaDoc bounds, boolean selected) {
38         String JavaDoc taskName = ((TaskImpl)task).getName();
39         
40         Color JavaDoc col = ((TaskImpl)task).getColor();
41         
42         if(selected) {
43             col = col.brighter();
44         }
45         g2.setColor(col);
46         g2.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 5, 5);
47         
48         if(selected) {
49             g2.setColor(_taskBorderSelCol);
50         } else {
51             g2.setColor(_taskBorderCol);
52         }
53         g2.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 5, 5);
54         
55         Rectangle JavaDoc oldClips = g2.getClipBounds();
56         g2.setColor(Color.black);
57         g2.clipRect(bounds.x, bounds.y, bounds.width-4, bounds.height-3);
58         
59         FontMetrics JavaDoc fm = g2.getFontMetrics();
60         
61         g2.drawString(taskName, bounds.x + 5, bounds.y+ (fm.getHeight() + bounds.height)/2 - fm.getDescent());
62         g2.setClip(oldClips.x, oldClips.y, oldClips.width, oldClips.height);
63         //g2.drawRect(bounds.x+1, bounds.y+1, bounds.width, bounds.height);
64
}
65
66     public void paintRowHeader(Object JavaDoc man, Graphics2D JavaDoc g2, Rectangle JavaDoc bounds, boolean selected) {
67         if(selected) {
68             g2.setColor(Color.LIGHT_GRAY);
69             g2.fillRoundRect(bounds.x+3, bounds.y+6, bounds.width-7, bounds.height-6, 5, 5);
70             g2.setColor(Color.GRAY);
71             g2.drawRoundRect(bounds.x+3, bounds.y+6, bounds.width-7, bounds.height-6, 5, 5);
72         }
73         g2.setColor(Color.black);
74         g2.drawString(((ManImpl)man).getName(), bounds.x + 8, bounds.y + (bounds.height + g2.getFontMetrics().getHeight())/2);
75     }
76
77 }
78
Popular Tags