for (int y = 1; y < getHoursPerDay() + 1; y++) {
g2d.drawLine(0, y * hourWidth, xEnd, y * hourWidth);
}
RoundBox selectedBox = null;
DateTime startDate = settings.getStartDate();
// paint events
for (IntervalLong interval : getCurrentIntervals()) {
long startMillisOffset = interval.getStart() - startDate.getMillis()
+ startDate.getMillisOfDay();
int day = (int) (startMillisOffset / ICalendarSettings.DAY);
int duration_hourWidth = (int) (interval.getDuration() / settings.getMillisPerTimeslot()
* getHourFactor() * hourWidth);
int start_hourWidth = (int) ((startMillisOffset % CalendarSettings.DAY
- startDate.getMillisOfDay()) / ICalendarSettings.HOUR * hourWidth)
+ (hourWidth * interval.getStartDateTime().getMinuteOfHour() / 60);
int numberOfConflicts = stepFunction.getMaxAssignments(interval);
int position = stepFunction.getOffset(interval);
int thickness = dayWidth / numberOfConflicts;
int offset = position * thickness;
Rectangle2D paintingRect = new Rectangle2D.Double(
day * dayWidth + offset, start_hourWidth,
thickness, duration_hourWidth);
String text = interval.getDescription();
if (text == null || text.length() == 0)
text = interval.getName();
RoundBox box = new RoundBox(text, numberOfConflicts);
box.setRect(paintingRect);
if (paintingRect.intersects(mousePositionX, mousePositionY, 1, 1)) {
selectedBox = box;
continue;
}
box.paintComponent(g2d);
}
// now paint a selected interval a bit larger *and* on the top of the other
if (selectedBox != null) {
selectedBox.setTransparent(false);
selectedBox.zoom(g2d.getClip());
selectedBox.paintComponent(g2d);
}
}
};
final DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendDayOfWeekText().
appendLiteral(" - ").
appendDayOfMonth(2).
appendLiteral(". ").
appendMonthOfYearText().toFormatter();
columnHeader = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Shape oldClip = g.getClip();
DateTime tempDateTime = settings.getStartDate();
for (int x = 0; x < visibleDays; x++) {
g.setClip(new Rectangle2D.Double(x * dayWidth, 0,
dayWidth, columnHeaderHeight));
g.drawString(fmt.print(tempDateTime),
xTextOffset + x * dayWidth, yHeaderTextOffset);
tempDateTime = tempDateTime.plusDays(1);
}
g.setClip(oldClip);
}
};
rowHeader = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for (int y = 0; y < getHoursPerDay(); y++) {
g.drawString(String.format("%1$02d", y + getHourOffset()) + ":00",
xTextOffset, yHeaderTextOffset + y * hourWidth);
}
}
};
scroll = new JScrollPane();
scroll.setRowHeaderView(rowHeader);
// scroll.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, new JLabel() {
//
// @Override
// public String getText() {
// return "no:" + getCurrentIntervals().size();
// }
// });
scroll.setColumnHeaderView(columnHeader);
JPanel timeNorthPanel = new JPanel();
calendarDateField = CalendarFactory.createDateField();
calendarDateField.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
// get the date only - not the time
DateTime val = new DateTime(((Date) calendarDateField.getValue()).getTime());
DateTime start = settings.getStartDate();
setStartDate(start.withYear(val.getYear()).
withMonthOfYear(val.getMonthOfYear()).withDayOfMonth(val.getDayOfMonth()));
}
});
timeNorthPanel.add(calendarDateField);
timeNorthPanel.add(prevDaysButton = new SmallButton("<"));