|
From: <nic...@us...> - 2003-09-02 10:33:41
|
Update of /cvsroot/jcharts/krysalis-jcharts/src/scratchpad/org/krysalis/jcharts/gantt
In directory sc8-pr-cvs1:/tmp/cvs-serv26444/src/scratchpad/org/krysalis/jcharts/gantt
Modified Files:
DateHandler.java PlanRenderer.java
Log Message:
Rename some variables and other date handling cleanings.
Index: DateHandler.java
===================================================================
RCS file: /cvsroot/jcharts/krysalis-jcharts/src/scratchpad/org/krysalis/jcharts/gantt/DateHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DateHandler.java 2 Sep 2003 09:08:46 -0000 1.3
--- DateHandler.java 2 Sep 2003 10:32:51 -0000 1.4
***************
*** 48,79 ****
**/
public class DateHandler {
! private Date currentDate;
private long currentTime;
! private Date startDate;
! private Date endDate;
private Date lastWeek;
private Date future;
! private Calendar lw;
private long totalDays;
! private int startDay;
! private DateFormat df;
! private DateFormat dmf;
! private DateFormat df_ddMM;
public String format(Date d) {
! return df.format(d);
}
! public String simpleFormat(Date d) {
! return df_ddMM.format(d);
}
public String monthFormat(Date d) {
! return dmf.format(d);
}
public Date getCurrentDate() {
! return currentDate;
}
--- 48,105 ----
**/
public class DateHandler {
!
! private final static DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
! private final static DateFormat monthFormat = new SimpleDateFormat("MMMMM");
! private final static DateFormat dayMonthFormat= new SimpleDateFormat("dd/MM");
! private final static DateFormat dateStampFormat= new SimpleDateFormat("yyyyMMdd");
!
! private Date currentDay;
private long currentTime;
! private Date startDay;
! private Date endDay;
private Date lastWeek;
private Date future;
! private Calendar cal;
private long totalDays;
! private int startDayOfWeek;
! public DateHandler(Date startDate, Date endDate) {
!
! //calculate the date
! this.currentDay = cleanDay(new Date());
! this.currentTime = currentDay.getTime();
! this.startDay = lastWeek = cleanDay(startDate);
! this.endDay = future = cleanDay(endDate);
!
! cal = Calendar.getInstance();
! // if (lastWeek == null || future == null) {
! // int dow = cal.get(Calendar.DAY_OF_WEEK);
! // cal.add(Calendar.DATE, -dow - 6);
! // lastWeek = cleanDay(cal.getTime());
! // cal.add(Calendar.DATE, 5 * 7);
! // future = cleanDay(cal.getTime());
! // }
! totalDays = (long) getDayDiff(future, lastWeek);
!
! cal.setTime(lastWeek);
! startDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
+ shortFormat.format(currentDay);
+ }
+
public String format(Date d) {
! return shortFormat.format(d);
}
! public String shortFormat(Date d) {
! return dayMonthFormat.format(d);
}
public String monthFormat(Date d) {
! return monthFormat.format(d);
}
public Date getCurrentDate() {
! return currentDay;
}
***************
*** 83,87 ****
public Date getEndDate() {
! return endDate;
}
--- 109,113 ----
public Date getEndDate() {
! return endDay;
}
***************
*** 95,107 ****
public Calendar getLw() {
! return lw;
}
public Date getStartDate() {
! return startDate;
}
! public int getStartDay() {
! return startDay;
}
--- 121,133 ----
public Calendar getLw() {
! return cal;
}
public Date getStartDate() {
! return startDay;
}
! public int getStartDayOfWeek() {
! return startDayOfWeek;
}
***************
*** 112,116 ****
public boolean isToday(Calendar cal) {
Calendar currcal = Calendar.getInstance();
! currcal.setTime(currentDate);
int day = cal.get(Calendar.DAY_OF_MONTH);
--- 138,142 ----
public boolean isToday(Calendar cal) {
Calendar currcal = Calendar.getInstance();
! currcal.setTime(currentDay);
int day = cal.get(Calendar.DAY_OF_MONTH);
***************
*** 128,131 ****
--- 154,158 ----
}
}
+
public int getDayDiff(Date start, Date end) {
return (int)
***************
*** 136,182 ****
}
- public DateHandler(Date startDate, Date endDate) {
- df = DateFormat.getDateInstance(DateFormat.SHORT);
- df_ddMM = new SimpleDateFormat("dd/MM");
- dmf = new SimpleDateFormat("MMMMM");
-
- //calculate the date
- this.currentDate = cleanDay(new Date());
- this.currentTime = currentDate.getTime();
- this.startDate = cleanDay(startDate);
- this.endDate = cleanDay(endDate);
-
- lastWeek = cleanDay(startDate);
- future = cleanDay(endDate);
- lw = Calendar.getInstance();
- if (lastWeek == null || future == null) {
- int dow = lw.get(Calendar.DAY_OF_WEEK);
- lw.add(Calendar.DATE, -dow - 6);
- lastWeek = cleanDay(lw.getTime());
- lw.add(Calendar.DATE, 5 * 7);
- future = cleanDay(lw.getTime());
- }
- totalDays =
- (long) ((future.getTime() - lastWeek.getTime() + 43200000) / 86400000);
- lw.setTime(lastWeek);
- startDay = lw.get(Calendar.DAY_OF_WEEK);
-
- df.format(currentDate);
- }
-
- private static Date cleanDay(long date) {
- return DateHandler.cleanDay(new Date(date));
- }
-
- private static Date cleanDay(int date) {
- return DateHandler.cleanDay(new Date(date));
- }
-
- private static Date cleanDay(Date date) {
- date.setHours(0);
- date.setMinutes(0);
- date.setSeconds(0);
- return date;
- }
public static Date getDate(String label) {
--- 163,166 ----
***************
*** 226,239 ****
}
- private static Date parseDate(String date) throws ParseException {
- DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
- return (Date) formatter.parse(date);
- }
-
- private static String formatDate(Date date) throws ParseException {
- DateFormat formatter = new SimpleDateFormat("dd/MM");
- return formatter.format(date);
- }
-
//TODO ! add year handling!!!
public static String getStringDateFromWeek(int week, boolean startDay)
--- 210,213 ----
***************
*** 254,259 ****
// return resultYear+resultMonth+resultDay;
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
! return formatter.format(c.getTime());
}
}
--- 228,265 ----
// return resultYear+resultMonth+resultDay;
+
+ Date result = c.getTime();
+
+ return dateStampFormat.format(result);
+ }
+
+
+ // Private helper methods
+
+ private static Date cleanDay(long date) {
+ return DateHandler.cleanDay(new Date(date));
+ }
+
+ private static Date cleanDay(int date) {
+ return DateHandler.cleanDay(new Date(date));
+ }
+
+ private static Date cleanDay(Date date) {
+ date.setHours(0);
+ date.setMinutes(0);
+ date.setSeconds(0);
+ return date;
+ }
+
+ private static Date parseDate(String date) throws ParseException {
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
! return (Date) formatter.parse(date);
}
+
+ private static String formatDate(Date date) throws ParseException {
+ DateFormat formatter = new SimpleDateFormat("dd/MM");
+ return formatter.format(date);
+ }
+
+
}
Index: PlanRenderer.java
===================================================================
RCS file: /cvsroot/jcharts/krysalis-jcharts/src/scratchpad/org/krysalis/jcharts/gantt/PlanRenderer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PlanRenderer.java 2 Sep 2003 09:52:11 -0000 1.4
--- PlanRenderer.java 2 Sep 2003 10:32:51 -0000 1.5
***************
*** 109,130 ****
// g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)0.5));
// g2.setPaint(Color.YELLOW);
! // g2.fill(clip1);
// g2.setPaint(Color.BLUE);
! // g2.fill(clip2);
// g2.setPaint(Color.RED);
! // g2.fill(clip3);
// g2.setPaintMode();
! float strwidth =
(float) font.getStringBounds(title, g2.getFontRenderContext()).getWidth();
! float pos = (float) (80 - strwidth / 2.0);
! if (pos < 5) {
! pos = 5;
}
g2.setPaint(Color.BLACK);
! g2.drawString(title, pos, 18);
DateHandler dh = new DateHandler(startDate, endDate);
--- 109,132 ----
// g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)0.5));
// g2.setPaint(Color.YELLOW);
! // g2.fill(leftclip);
// g2.setPaint(Color.BLUE);
! // g2.fill(middleclip);
// g2.setPaint(Color.RED);
! // g2.fill(rightclip);
// g2.setPaintMode();
! //Draw Title
! float titleWidth =
(float) font.getStringBounds(title, g2.getFontRenderContext()).getWidth();
! float titlePosition = (float) (80 - titleWidth / 2.0);
! if (titlePosition < 5) {
! titlePosition = 5;
}
g2.setPaint(Color.BLACK);
! g2.drawString(title, titlePosition, 18);
+ //Draw Dates
DateHandler dh = new DateHandler(startDate, endDate);
***************
*** 134,138 ****
//firstdate
g2.drawString(
! dh.simpleFormat(dh.getLastWeek()),
leftWidth + 1,
currentTopEdge - 1);
--- 136,140 ----
//firstdate
g2.drawString(
! dh.shortFormat(dh.getStartDate()),
leftWidth + 1,
currentTopEdge - 1);
***************
*** 140,144 ****
//lastdate
g2.drawString(
! dh.simpleFormat(dh.getFuture()),
(int) width,
(int) currentTopEdge - 1);
--- 142,146 ----
//lastdate
g2.drawString(
! dh.shortFormat(dh.getEndDate()),
(int) width,
(int) currentTopEdge - 1);
***************
*** 153,166 ****
int offset = 0;
Calendar cal = Calendar.getInstance();
cal.setTime(dh.getLastWeek());
! for (int count = dh.getStartDay();
! count < dh.getStartDay() + dh.getTotalDays() - 1;
! count++, offset++) {
!
! cal.roll(Calendar.DAY_OF_YEAR, true);
float currentDateLocation =
! leftWidth + (offset) * (width - leftWidth) / (dh.getTotalDays() - 2);
if (count % 7 == 6 || count % 7 == 0) {
--- 155,169 ----
int offset = 0;
+ long singleDayWidth = (width - leftWidth) / dh.getTotalDays() ;
Calendar cal = Calendar.getInstance();
cal.setTime(dh.getLastWeek());
! for (int count = dh.getStartDayOfWeek();
! count < dh.getStartDayOfWeek() + dh.getTotalDays();
! count++, offset++, cal.roll(Calendar.DAY_OF_YEAR, true)) {
+ //@todo use absolute computed numbers, not increments
+ // for max precision
float currentDateLocation =
! leftWidth + offset * singleDayWidth;
if (count % 7 == 6 || count % 7 == 0) {
***************
*** 170,177 ****
Shape holidayDay =
new Rectangle2D.Float(
! currentDateLocation,
! (float) (currentTopEdge + 0.5),
! (float) ((width - leftWidth) / (dh.getTotalDays() - 3)),
! (height - 1 - currentTopEdge));
g2.fill(holidayDay);
--- 173,180 ----
Shape holidayDay =
new Rectangle2D.Float(
! currentDateLocation,
! (float) currentTopEdge,
! (float) singleDayWidth,
! (height - currentTopEdge));
g2.fill(holidayDay);
***************
*** 185,191 ****
new Rectangle2D.Float(
currentDateLocation,
! (float) (currentTopEdge + 0.5),
! (float) ((width - leftWidth) / (dh.getTotalDays() - 3)),
! (height - 1 - currentTopEdge));
g2.fill(today);
--- 188,194 ----
new Rectangle2D.Float(
currentDateLocation,
! (float) currentTopEdge,
! (float) singleDayWidth,
! (height - currentTopEdge));
g2.fill(today);
***************
*** 226,230 ****
}
!
}
--- 229,233 ----
}
!
}
***************
*** 285,289 ****
g2.setPaint(Color.BLACK);
g2.drawString(
! dh.simpleFormat(start),
leftWidth
+ daysToStart * barspaceWidth / (dh.getTotalDays() - 2)
--- 288,292 ----
g2.setPaint(Color.BLACK);
g2.drawString(
! dh.shortFormat(start),
leftWidth
+ daysToStart * barspaceWidth / (dh.getTotalDays() - 2)
***************
*** 292,296 ****
g2.drawString(
! dh.simpleFormat(end),
leftWidth
+ daysToStart * barspaceWidth / (dh.getTotalDays() - 2)
--- 295,299 ----
g2.drawString(
! dh.shortFormat(end),
leftWidth
+ daysToStart * barspaceWidth / (dh.getTotalDays() - 2)
|