KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > calendar > gui > CalendarViewer


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.applications.calendar.gui;
21
22 import javax.swing.*;
23
24 import org.lucane.client.widgets.DialogBox;
25 import org.lucane.client.widgets.ManagedWindow;
26 import org.lucane.applications.calendar.CalendarPlugin;
27 import org.lucane.applications.calendar.widget.*;
28 import org.lucane.applications.calendar.Event;
29
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.util.*;
33
34 public class CalendarViewer extends ManagedWindow
35 implements ActionListener, CalendarListener
36 {
37     private MonthPanel monthPanel;
38     private WeekPanel weekPanel;
39     private DayPanel dayPanel;
40     
41     private JButton goToCurrentMonth;
42     private JButton goToCurrentDay;
43     private JButton close;
44     
45     private transient CalendarPlugin plugin;
46     
47     public CalendarViewer(CalendarPlugin plugin, String JavaDoc userName)
48     {
49         super(plugin, plugin.getTitle() + " - " +userName);
50         getContentPane().setLayout(new BorderLayout());
51         this.plugin = plugin;
52         
53         monthPanel = new MonthPanel(plugin, this, userName);
54         weekPanel = new WeekPanel(plugin, this, userName);
55         dayPanel = new DayPanel(plugin, this, userName);
56     
57         goToCurrentMonth = new JButton(tr("btn.thisMonth"));
58         goToCurrentDay = new JButton(tr("btn.today"));
59         close = new JButton(tr("btn.close"));
60         
61         try {
62             goToCurrentMonth.setIcon(plugin.getImageIcon("jumpTo.png"));
63             goToCurrentDay.setIcon(plugin.getImageIcon("jumpTo.png"));
64             close.setIcon(plugin.getImageIcon("close.png"));
65         } catch(Exception JavaDoc e) {
66             //nothing, no icons :-/
67
}
68
69         goToCurrentMonth.addActionListener(this);
70         goToCurrentDay.addActionListener(this);
71         close.addActionListener(this);
72
73         JPanel topbar = new JPanel(new BorderLayout());
74         initTopBar(topbar);
75         
76         getContentPane().add(topbar, BorderLayout.NORTH);
77         getContentPane().add(monthPanel, BorderLayout.CENTER);
78     }
79     
80     private void initTopBar(JPanel bar)
81     {
82         JPanel buttons = new JPanel(new GridLayout(1, 3));
83         
84         buttons.add(goToCurrentMonth);
85         buttons.add(goToCurrentDay);
86         buttons.add(close);
87         
88         bar.add(buttons, BorderLayout.EAST);
89         bar.setBorder(BorderFactory.createEmptyBorder(2, 15, 5, 1));
90     }
91
92     public void actionPerformed(ActionEvent ae)
93     {
94         if(ae.getSource() == goToCurrentMonth)
95         {
96             monthPanel.showMonth(Calendar.getInstance());
97             if(getContentPane().getComponent(1) != monthPanel)
98             {
99                 getContentPane().remove(dayPanel);
100                 getContentPane().add(monthPanel, BorderLayout.CENTER);
101                 getContentPane().validate();
102                 getContentPane().repaint();
103             }
104         }
105         else if(ae.getSource() == goToCurrentDay)
106         {
107             dayPanel.showDay(Calendar.getInstance());
108             if(getContentPane().getComponent(1) != dayPanel)
109             {
110                 getContentPane().remove(monthPanel);
111                 getContentPane().add(dayPanel, BorderLayout.CENTER);
112                 getContentPane().validate();
113                 getContentPane().repaint();
114             }
115         }
116         else if(ae.getSource() == close)
117         {
118             this.dispose();
119         }
120     }
121     
122     public void onDayClick(DayItem day, int clickCount)
123     {
124         if(clickCount == 1)
125         {
126             int dayOfMonth = day.getDayOfMonth();
127             Calendar cal = monthPanel.getCalendar();
128             cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
129             dayPanel.showDay(cal);
130             getContentPane().remove(monthPanel);
131             getContentPane().add(dayPanel, BorderLayout.CENTER);
132             getContentPane().validate();
133             getContentPane().repaint();
134         }
135     }
136     
137     public void onHourClick(int hour, int minute, int clickCount)
138     {
139         //nothing, only viewing here
140
}
141
142     public void onEventClick(EventLabel label, int clickCount)
143     {
144         if(clickCount == 1)
145         {
146             Event event = (Event)label.getEvent();
147             if(event.isPublic())
148                 new EventFrame(plugin, event, dayPanel, weekPanel, monthPanel).show();
149             else
150                 DialogBox.info(tr("event.is.private"));
151         }
152     }
153     
154     private String JavaDoc tr(String JavaDoc s)
155     {
156         return plugin.tr(s);
157     }
158 }
Popular Tags