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.widgets.DialogBox;
025: import org.lucane.client.widgets.ManagedWindow;
026: import org.lucane.applications.calendar.CalendarPlugin;
027: import org.lucane.applications.calendar.widget.*;
028: import org.lucane.applications.calendar.Event;
029:
030: import java.awt.*;
031: import java.awt.event.*;
032: import java.util.*;
033:
034: public class CalendarViewer extends ManagedWindow implements
035: ActionListener, CalendarListener {
036: private MonthPanel monthPanel;
037: private WeekPanel weekPanel;
038: private DayPanel dayPanel;
039:
040: private JButton goToCurrentMonth;
041: private JButton goToCurrentDay;
042: private JButton close;
043:
044: private transient CalendarPlugin plugin;
045:
046: public CalendarViewer(CalendarPlugin plugin, String userName) {
047: super (plugin, plugin.getTitle() + " - " + userName);
048: getContentPane().setLayout(new BorderLayout());
049: this .plugin = plugin;
050:
051: monthPanel = new MonthPanel(plugin, this , userName);
052: weekPanel = new WeekPanel(plugin, this , userName);
053: dayPanel = new DayPanel(plugin, this , userName);
054:
055: goToCurrentMonth = new JButton(tr("btn.thisMonth"));
056: goToCurrentDay = new JButton(tr("btn.today"));
057: close = new JButton(tr("btn.close"));
058:
059: try {
060: goToCurrentMonth.setIcon(plugin.getImageIcon("jumpTo.png"));
061: goToCurrentDay.setIcon(plugin.getImageIcon("jumpTo.png"));
062: close.setIcon(plugin.getImageIcon("close.png"));
063: } catch (Exception e) {
064: //nothing, no icons :-/
065: }
066:
067: goToCurrentMonth.addActionListener(this );
068: goToCurrentDay.addActionListener(this );
069: close.addActionListener(this );
070:
071: JPanel topbar = new JPanel(new BorderLayout());
072: initTopBar(topbar);
073:
074: getContentPane().add(topbar, BorderLayout.NORTH);
075: getContentPane().add(monthPanel, BorderLayout.CENTER);
076: }
077:
078: private void initTopBar(JPanel bar) {
079: JPanel buttons = new JPanel(new GridLayout(1, 3));
080:
081: buttons.add(goToCurrentMonth);
082: buttons.add(goToCurrentDay);
083: buttons.add(close);
084:
085: bar.add(buttons, BorderLayout.EAST);
086: bar.setBorder(BorderFactory.createEmptyBorder(2, 15, 5, 1));
087: }
088:
089: public void actionPerformed(ActionEvent ae) {
090: if (ae.getSource() == goToCurrentMonth) {
091: monthPanel.showMonth(Calendar.getInstance());
092: if (getContentPane().getComponent(1) != monthPanel) {
093: getContentPane().remove(dayPanel);
094: getContentPane().add(monthPanel, BorderLayout.CENTER);
095: getContentPane().validate();
096: getContentPane().repaint();
097: }
098: } else if (ae.getSource() == goToCurrentDay) {
099: dayPanel.showDay(Calendar.getInstance());
100: if (getContentPane().getComponent(1) != dayPanel) {
101: getContentPane().remove(monthPanel);
102: getContentPane().add(dayPanel, BorderLayout.CENTER);
103: getContentPane().validate();
104: getContentPane().repaint();
105: }
106: } else if (ae.getSource() == close) {
107: this .dispose();
108: }
109: }
110:
111: public void onDayClick(DayItem day, int clickCount) {
112: if (clickCount == 1) {
113: int dayOfMonth = day.getDayOfMonth();
114: Calendar cal = monthPanel.getCalendar();
115: cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
116: dayPanel.showDay(cal);
117: getContentPane().remove(monthPanel);
118: getContentPane().add(dayPanel, BorderLayout.CENTER);
119: getContentPane().validate();
120: getContentPane().repaint();
121: }
122: }
123:
124: public void onHourClick(int hour, int minute, int clickCount) {
125: //nothing, only viewing here
126: }
127:
128: public void onEventClick(EventLabel label, int clickCount) {
129: if (clickCount == 1) {
130: Event event = (Event) label.getEvent();
131: if (event.isPublic())
132: new EventFrame(plugin, event, dayPanel, weekPanel,
133: monthPanel).show();
134: else
135: DialogBox.info(tr("event.is.private"));
136: }
137: }
138:
139: private String tr(String s) {
140: return plugin.tr(s);
141: }
142: }
|