1 19 20 package org.netbeans.modules.tasklist.usertasks.schedule; 21 22 import java.awt.Color ; 23 import java.awt.Dimension ; 24 import java.awt.Font ; 25 import java.awt.Graphics ; 26 import java.awt.Rectangle ; 27 import java.text.DateFormat ; 28 import java.text.SimpleDateFormat ; 29 import java.util.Calendar ; 30 import java.util.Date ; 31 import java.util.GregorianCalendar ; 32 import javax.swing.JComponent ; 33 import org.netbeans.modules.tasklist.usertasks.*; 34 import org.netbeans.modules.tasklist.usertasks.model.Duration; 35 import org.netbeans.modules.tasklist.usertasks.model.UserTaskObjectList; 36 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 37 import org.netbeans.modules.tasklist.usertasks.model.UserTaskList; 38 import org.netbeans.modules.tasklist.usertasks.options.Settings; 39 40 45 public class ScheduleView extends JComponent { 46 private static final int DAY_WIDTH = 50; 47 private static final int TASK_HEIGHT = 10; 48 private static final Font FONT = new Font ("SansSerif", Font.PLAIN, 12); 50 private static final Color LINES_COLOR = Color.GRAY; 51 private static final Color WEEKEND_COLOR = new Color (237, 237, 237); 52 private static final DateFormat MONTH_FORMAT = 53 new SimpleDateFormat ("MMMM yyyy"); 55 private Date start = new Date (); 56 private int days = 100; 57 private UserTaskList utl; 58 59 62 public ScheduleView() { 63 } 64 65 70 public void setUserTaskList(UserTaskList list) { 71 this.utl = list; 72 repaint(); 73 } 74 75 protected void paintComponent(java.awt.Graphics g) { 76 Rectangle r = g.getClipBounds(); 77 g.setColor(Color.white); 78 g.fillRect(r.x, r.y, r.width, r.height); 79 80 paintDays(g); 81 if (utl == null) 82 g.drawString("---", getWidth() / 2, getHeight() / 2); else 84 paintTasks(g, utl.getSubtasks(), 0, 32); 85 } 86 87 92 private void paintDays(Graphics g) { 93 g.setColor(WEEKEND_COLOR); 94 g.fillRect(0, 0, getWidth(), 30); 95 96 g.setFont(FONT); 97 98 g.setColor(LINES_COLOR); 99 g.drawLine(0, 15, getWidth() - 1, 15); 100 g.drawLine(0, 30, getWidth() - 1, 30); 101 102 Calendar gc = GregorianCalendar.getInstance(); 103 gc.setTime(start); 104 105 for (int x = 0; x < getWidth(); x += DAY_WIDTH) { 106 int day = gc.get(Calendar.DAY_OF_MONTH); 107 int dayOfWeek = gc.get(Calendar.DAY_OF_WEEK); 108 109 if (day == 1) { 110 g.drawString(MONTH_FORMAT.format(gc.getTime()), x, 13); 111 } 112 113 if (dayOfWeek == Calendar.SATURDAY || 114 dayOfWeek == Calendar.SUNDAY) { 115 g.setColor(WEEKEND_COLOR); 116 g.fillRect(x, 31, DAY_WIDTH, getHeight() - 31); 117 } 118 119 g.setColor(Color.BLACK); 120 g.drawString(Integer.toString(day), x, 28); 122 g.setColor(LINES_COLOR); 123 g.drawLine(x, 15, x, getHeight()); 124 gc.add(Calendar.DAY_OF_MONTH, 1); 125 } 126 } 127 128 136 private void paintTasks(Graphics g, UserTaskObjectList list, int x, int y) { 137 for (int i = 0; i < list.size(); i++) { 138 UserTask ut = list.getUserTask(i); 139 140 Duration dur = new Duration(ut.getEffort(), 141 Settings.getDefault().getMinutesPerDay(), 142 Integer.MAX_VALUE, true); 143 int duration = dur.days; 144 if (dur.hours != 0 || dur.minutes != 0) 145 duration++; 146 int w = duration * DAY_WIDTH; 147 148 if (ut.getSubtasks().isEmpty()) { 149 paintSimpleTask(g, x, y, w); 150 } else { 151 paintSuperTask(g, x, y, w); 152 paintTasks(g, ut.getSubtasks(), x, y + TASK_HEIGHT); 153 } 154 155 x += w; 156 y += TASK_HEIGHT; 157 } 158 } 159 160 170 private void paintSimpleTask(Graphics g, int x, int y, int width) { 171 g.setColor(new Color (140, 182, 206)); 172 g.fillRect(x, y, width, TASK_HEIGHT); 173 g.setColor(Color.black); 174 g.drawRect(x, y, width - 1, TASK_HEIGHT - 1); 175 } 176 177 187 private void paintSuperTask(Graphics g, int x, int y, int width) { 188 g.setColor(Color.BLACK); 189 190 int x2 = x + width; 191 g.fillRect(x, y, width, 2); 192 193 g.fillPolygon(new int[] {x, x + 7, x}, new int[] {y, y, y + 7}, 3); 194 g.fillPolygon(new int[] {x2, x2 - 7, x2}, new int[] {y, y, y + 7}, 3); 195 } 196 197 201 private int widthForDateDiff(long d) { 202 double days = d / (1000.0 * 60 * 60 * 24); 203 return (int) Math.round(days * DAY_WIDTH); 204 } 205 206 212 private int xForDate(long d) { 213 long diff = d - start.getTime(); 214 double days = diff / (1000.0 * 60 * 60 * 24); 215 return (int) Math.round(days * DAY_WIDTH); 216 } 217 218 public java.awt.Dimension getPreferredSize() { 219 return new Dimension (days * DAY_WIDTH, 200); 220 } 221 } 222 | Popular Tags |