001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package org.lucane.applications.calendar.gui;
021:
022: import javax.swing.*;
023:
024: import org.lucane.client.Client;
025: import org.lucane.client.widgets.DialogBox;
026: import org.lucane.client.widgets.ManagedWindow;
027: import org.lucane.client.widgets.UserSelector;
028: import org.lucane.common.concepts.UserConcept;
029: import org.lucane.applications.calendar.CalendarPlugin;
030: import org.lucane.applications.calendar.Event;
031: import org.lucane.applications.calendar.widget.*;
032:
033: import java.awt.*;
034: import java.awt.event.*;
035: import java.util.*;
036:
037: public class CalendarFrame extends ManagedWindow implements
038: ActionListener, CalendarListener {
039: private MonthPanel monthPanel;
040: private WeekPanel weekPanel;
041: private DayPanel dayPanel;
042:
043: private JButton newEvent;
044: private JButton goToCurrentMonth;
045: private JButton goToCurrentWeek;
046: private JButton goToCurrentDay;
047: private JButton otherCalendars;
048: private JButton close;
049:
050: private transient CalendarPlugin plugin;
051:
052: public CalendarFrame(CalendarPlugin plugin) {
053: super (plugin, plugin.getTitle());
054: getContentPane().setLayout(new BorderLayout());
055: this .plugin = plugin;
056:
057: monthPanel = new MonthPanel(plugin, this , null);
058: dayPanel = new DayPanel(plugin, this , null);
059: weekPanel = new WeekPanel(plugin, this , null);
060:
061: newEvent = new JButton(tr("btn.newEvent"));
062: goToCurrentMonth = new JButton(tr("btn.thisMonth"));
063: goToCurrentWeek = new JButton(tr("btn.thisWeek"));
064: goToCurrentDay = new JButton(tr("btn.today"));
065: otherCalendars = new JButton(tr("btn.otherCalendars"));
066: close = new JButton(tr("btn.close"));
067:
068: newEvent.setIcon(plugin.getImageIcon("new.png"));
069: goToCurrentMonth.setIcon(plugin.getImageIcon("jumpTo.png"));
070: goToCurrentWeek.setIcon(plugin.getImageIcon("jumpTo.png"));
071: goToCurrentDay.setIcon(plugin.getImageIcon("jumpTo.png"));
072: otherCalendars.setIcon(plugin.getImageIcon("other.png"));
073: close.setIcon(plugin.getImageIcon("close.png"));
074:
075: newEvent.addActionListener(this );
076: goToCurrentMonth.addActionListener(this );
077: goToCurrentWeek.addActionListener(this );
078: goToCurrentDay.addActionListener(this );
079: otherCalendars.addActionListener(this );
080: close.addActionListener(this );
081:
082: JPanel topbar = new JPanel(new BorderLayout());
083: initTopBar(topbar);
084:
085: getContentPane().add(topbar, BorderLayout.NORTH);
086: getContentPane().add(monthPanel, BorderLayout.CENTER);
087: }
088:
089: private void initTopBar(JPanel bar) {
090: JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1,
091: 1));
092:
093: buttons.add(newEvent);
094: buttons.add(goToCurrentMonth);
095: buttons.add(goToCurrentWeek);
096: buttons.add(goToCurrentDay);
097: buttons.add(otherCalendars);
098: buttons.add(close);
099:
100: bar.add(buttons, BorderLayout.EAST);
101: bar.setBorder(BorderFactory.createEmptyBorder(2, 15, 5, 1));
102: }
103:
104: public void actionPerformed(ActionEvent ae) {
105: if (ae.getSource() == newEvent) {
106: //TODO create a better default event
107: long time = Calendar.getInstance().getTimeInMillis();
108: Event e = new Event(-1, "", tr("event.newEvent"), Client
109: .getInstance().getMyInfos().getName(), true, false,
110: time, time + 3600 * 1000, Event.RECUR_NONE, "");
111:
112: new EventFrame(plugin, e, dayPanel, weekPanel, monthPanel)
113: .show();
114: } else if (ae.getSource() == goToCurrentMonth) {
115: monthPanel.showMonth(Calendar.getInstance());
116: if (getContentPane().getComponent(1) != monthPanel) {
117: getContentPane().remove(dayPanel);
118: getContentPane().remove(weekPanel);
119: getContentPane().add(monthPanel, BorderLayout.CENTER);
120: getContentPane().validate();
121: getContentPane().repaint();
122: }
123: } else if (ae.getSource() == goToCurrentWeek) {
124: monthPanel.showMonth(Calendar.getInstance());
125: if (getContentPane().getComponent(1) != weekPanel) {
126: getContentPane().remove(monthPanel);
127: getContentPane().remove(dayPanel);
128: getContentPane().add(weekPanel, BorderLayout.CENTER);
129: getContentPane().validate();
130: getContentPane().repaint();
131: }
132: } else if (ae.getSource() == goToCurrentDay) {
133: dayPanel.showDay(Calendar.getInstance());
134: if (getContentPane().getComponent(1) != dayPanel) {
135: getContentPane().remove(monthPanel);
136: getContentPane().remove(weekPanel);
137: getContentPane().add(dayPanel, BorderLayout.CENTER);
138: getContentPane().validate();
139: getContentPane().repaint();
140: }
141: } else if (ae.getSource() == otherCalendars) {
142: try {
143: ArrayList groups = plugin.getGroups();
144: UserSelector select = new UserSelector(null,
145: tr("msg.selectUser"));
146: select.setRecursive(true);
147: select.setGroups(groups);
148:
149: UserConcept user = (UserConcept) select.selectItem();
150: if (user == null)
151: return;
152:
153: CalendarViewer viewer = new CalendarViewer(plugin, user
154: .getName());
155: viewer.setPreferredSize(new Dimension(780, 550));
156: viewer.show();
157: } catch (Exception e) {
158: DialogBox.error(tr("err.unableToFetchUserList"));
159: e.printStackTrace();
160: }
161:
162: } else if (ae.getSource() == close) {
163: this .dispose();
164: plugin.exit();
165: }
166: }
167:
168: public void onDayClick(DayItem day, int clickCount) {
169: int dayOfMonth = day.getDayOfMonth();
170: Calendar cal = monthPanel.getCalendar();
171: cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
172:
173: if (clickCount == 1) {
174: dayPanel.showDay(cal);
175: getContentPane().remove(monthPanel);
176: getContentPane().remove(weekPanel);
177: getContentPane().add(dayPanel, BorderLayout.CENTER);
178: getContentPane().validate();
179: getContentPane().repaint();
180: }
181: }
182:
183: public void onHourClick(int hour, int minute, int clickCount) {
184: Calendar cal = dayPanel.getCalendar();
185: cal.set(Calendar.HOUR_OF_DAY, hour);
186: cal.set(Calendar.MINUTE, minute);
187:
188: if (clickCount == 2) {
189: long time = cal.getTimeInMillis();
190: Event e = new Event(-1, "", tr("event.newEvent"), Client
191: .getInstance().getMyInfos().getName(), true, false,
192: time, time + 3600 * 1000, Event.RECUR_NONE, "");
193:
194: new EventFrame(plugin, e, dayPanel, weekPanel, monthPanel)
195: .show();
196: }
197: }
198:
199: public void onEventClick(EventLabel event, int clickCount) {
200: if (clickCount == 1)
201: new EventFrame(plugin, (Event) event.getEvent(), dayPanel,
202: weekPanel, monthPanel).show();
203: }
204:
205: private String tr(String s) {
206: return plugin.tr(s);
207: }
208: }
|