KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > calendar > widget > freebusy > FreeBusyPanel


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 package org.lucane.applications.calendar.widget.freebusy;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Color JavaDoc;
23 import java.awt.GridLayout JavaDoc;
24 import java.awt.Point JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import javax.swing.JLabel JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.JScrollPane JavaDoc;
30
31 import org.lucane.applications.calendar.widget.CalendarListener;
32
33 public class FreeBusyPanel extends JPanel JavaDoc
34 {
35     public static final int HOUR_WIDTH = 48;
36     public static final int HEIGHT = 24;
37     
38     private FreeBusyRuler ruler;
39     
40     private JPanel JavaDoc labels;
41     private JPanel JavaDoc items;
42     private JScrollPane JavaDoc scrollpane;
43     
44     private int workStart;
45     private int workEnd;
46     
47     public FreeBusyPanel(int workStart, int workEnd, Color JavaDoc unworkedHour, Color JavaDoc workedHour)
48     {
49         this.workStart = workStart;
50         this.workEnd = workEnd;
51         
52         GridLayout JavaDoc layout = new GridLayout JavaDoc(0, 1);
53         layout.setVgap(1);
54         this.labels = new JPanel JavaDoc(layout);
55         this.items = new JPanel JavaDoc(layout);
56         
57         this.ruler = new FreeBusyRuler(workStart, workEnd, unworkedHour, workedHour);
58         
59         resetLines();
60                 
61         JPanel JavaDoc itemContainer = new JPanel JavaDoc(new BorderLayout JavaDoc());
62         itemContainer.add(items, BorderLayout.NORTH);
63         this.scrollpane = new JScrollPane JavaDoc(itemContainer);
64         
65         JPanel JavaDoc labelContainer = new JPanel JavaDoc(new BorderLayout JavaDoc());
66         labelContainer.add(labels, BorderLayout.NORTH);
67         this.setLayout(new BorderLayout JavaDoc());
68         this.add(labelContainer, BorderLayout.WEST);
69         this.add(scrollpane, BorderLayout.CENTER);
70     }
71     
72     public void addCalendarListener(CalendarListener listener)
73     {
74         ruler.addCalendarListener(listener);
75     }
76
77     public void removeCalendarListener(CalendarListener listener)
78     {
79         ruler.removeCalendarListener(listener);
80     }
81
82     public void resetLines()
83     {
84         labels.removeAll();
85         items.removeAll();
86         
87         labels.add(new JLabel JavaDoc());
88         items.add(ruler);
89     }
90     
91     public void addLine(String JavaDoc user, ArrayList JavaDoc events, boolean isMandatory, long startTime, long endTime)
92     {
93         labels.add(new FreeBusyLabel(user, isMandatory));
94         items.add(new FreeBusyItem(events, workStart, workEnd, startTime, endTime));
95     }
96     
97     /**
98      * Scroll to an hour
99      * @param hour the hour that should be on left
100      */

101     public void scrollToHour(int hour)
102     {
103         scrollpane.getViewport().setViewPosition(new Point JavaDoc(hour*HOUR_WIDTH-HOUR_WIDTH/2, 0));
104     }
105 }
Popular Tags