001: /*--------------------------------------------------------------------------*
002: | Copyright (C) 2006 Christopher Kohlhaas |
003: | |
004: | This program is free software; you can redistribute it and/or modify |
005: | it under the terms of the GNU General Public License as published by the |
006: | Free Software Foundation. A copy of the license has been included with |
007: | these distribution in the COPYING file, if not go to www.fsf.org |
008: | |
009: | As a special exception, you are granted the permissions to link this |
010: | program with every library, which license fulfills the Open Source |
011: | Definition as published by the Open Source Initiative (OSI). |
012: *--------------------------------------------------------------------------*/
013:
014: package org.rapla.plugin.monthview;
015:
016: import java.awt.Color;
017: import java.util.Calendar;
018: import java.util.Date;
019: import java.util.Set;
020:
021: import javax.swing.JComponent;
022:
023: import org.rapla.components.calendar.WeekendHighlightRenderer;
024: import org.rapla.components.calendarview.swing.AbstractSwingCalendar;
025: import org.rapla.components.calendarview.swing.SwingMonthView;
026: import org.rapla.components.calendarview.swing.ViewListener;
027: import org.rapla.components.util.DateTools;
028: import org.rapla.entities.domain.Appointment;
029: import org.rapla.framework.RaplaContext;
030: import org.rapla.framework.RaplaException;
031: import org.rapla.gui.CalendarModel;
032: import org.rapla.gui.CalendarOptions;
033: import org.rapla.plugin.abstractcalendar.AbstractRaplaSwingCalendar;
034: import org.rapla.plugin.abstractcalendar.GroupAllocatablesStrategy;
035: import org.rapla.plugin.abstractcalendar.RaplaBuilder;
036: import org.rapla.plugin.abstractcalendar.RaplaCalendarViewListener;
037: import org.rapla.plugin.abstractcalendar.SwingRaplaBuilder;
038:
039: public class SwingMonthCalendar extends AbstractRaplaSwingCalendar {
040: public SwingMonthCalendar(RaplaContext sm, CalendarModel settings,
041: boolean editable) throws RaplaException {
042: super (sm, settings, editable);
043: }
044:
045: public static Color DATE_NUMBER_COLOR_HIGHLIGHTED = Color.black;
046:
047: protected AbstractSwingCalendar createView(boolean editable) {
048: boolean showScrollPane = editable;
049:
050: /** renderer for weekdays in month-view */
051: final WeekendHighlightRenderer weekdayRenderer = new WeekendHighlightRenderer();
052: return new SwingMonthView(showScrollPane) {
053: private static final long serialVersionUID = 1L;
054:
055: protected JComponent createSlotHeader(int weekday) {
056: JComponent component = super .createSlotHeader(weekday);
057: if (isEditable()) {
058: component.setOpaque(true);
059: Color color = weekdayRenderer.getBackgroundColor(
060: weekday, 1, 1, 1);
061: component.setBackground(color);
062: }
063: return component;
064: }
065:
066: protected Color getNumberColor(Date date) {
067: boolean today = DateTools.isSameDay(getQuery().today()
068: .getTime(), date.getTime());
069: if (today) {
070: return DATE_NUMBER_COLOR_HIGHLIGHTED;
071: } else {
072: return super .getNumberColor(date);
073: }
074: }
075: };
076: }
077:
078: protected ViewListener createListener() throws RaplaException {
079: return new RaplaCalendarViewListener(getContext(), model, view) {
080: /* if the selcted view is a month-view or compact-view, the start-time will not be the selected time,
081: * but the time of the start-time of the appointment instead. The start-date is taken from the passed date.
082: * */
083: protected Date calcStartDate(Date date,
084: Appointment appointment) {
085: return getRaplaLocale().toDate(date,
086: appointment.getStart());
087: }
088:
089: };
090: }
091:
092: protected RaplaBuilder createBuilder() throws RaplaException {
093: RaplaBuilder builder = new SwingRaplaBuilder(getContext());
094: builder.setRepeatingVisible(view.isEditable());
095: builder.setEditingUser(getUser());
096: builder.setExceptionsExcluded(!getCalendarOptions()
097: .isExceptionsVisible()
098: || !view.isEditable());
099: builder.setFromModel(model, view.getStartDate(), view
100: .getEndDate());
101:
102: builder.setSmallBlocks(true);
103:
104: GroupAllocatablesStrategy strategy = new GroupAllocatablesStrategy(
105: getRaplaLocale().getLocale());
106: boolean compactColumns = getCalendarOptions()
107: .isCompactColumns()
108: || builder.getAllocatables().size() == 0;
109: strategy.setFixedSlotsEnabled(!compactColumns);
110: builder.setBuildStrategy(strategy);
111:
112: return builder;
113: }
114:
115: protected void configureView() throws RaplaException {
116: CalendarOptions calendarOptions = getCalendarOptions();
117: Set excludeDays = calendarOptions.getExcludeDays();
118:
119: view.setExcludeDays(excludeDays);
120: if (!view.isEditable()) {
121: view.setSlotSize(model.getSize());
122: } else {
123: view.setSlotSize(150);
124: }
125: view.setToDate(model.getSelectedDate());
126: }
127:
128: public int getIncrementSize() {
129: return Calendar.MONTH;
130: }
131:
132: }
|