KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > calendar > CalendarPlugin


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;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.util.*;
25
26 import org.lucane.client.*;
27 import org.lucane.common.*;
28 import org.lucane.common.net.ObjectConnection;
29 import org.lucane.applications.calendar.gui.CalendarFrame;
30
31 //TODO activate resources
32

33 public class CalendarPlugin extends StandalonePlugin
34 {
35     private ConnectInfo service;
36     
37     //-- from Plugin
38
public CalendarPlugin()
39     {
40     }
41         
42     public Plugin newInstance(ConnectInfo[] friends)
43     {
44         return new CalendarPlugin();
45     }
46
47     public void start()
48     {
49         service = Communicator.getInstance().getConnectInfo("org.lucane.applications.calendar");
50         
51         //-- display month view
52
CalendarFrame cf = new CalendarFrame(this);
53         cf.setExitPluginOnClose(true);
54         cf.setPreferredSize(new Dimension JavaDoc(780, 550));
55         cf.show();
56     }
57     
58     public void storeEvent(Event e)
59     throws Exception JavaDoc
60     {
61         CalendarAction ca = new CalendarAction(CalendarAction.STORE_EVENT);
62         ca.set("event", e);
63         
64         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
65             service, service.getName(), ca);
66         
67         oc.readString(); //OK or FAILED
68

69         oc.close();
70     }
71     
72     public void removeEvent(Event e)
73     throws Exception JavaDoc
74     {
75         CalendarAction ca = new CalendarAction(CalendarAction.REMOVE_EVENT);
76         ca.set("event", e);
77         
78         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
79             service, service.getName(), ca);
80         
81         oc.readString(); //OK or FAILED
82

83         oc.close();
84     }
85         
86     public ArrayList getEventTypes()
87     throws Exception JavaDoc
88     {
89         ArrayList types;
90         
91         CalendarAction ca = new CalendarAction(CalendarAction.GET_EVENT_TYPES);
92         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
93                 service, service.getName(), ca);
94         
95         if(oc.readString().equals("OK"))
96             types = (ArrayList)oc.read();
97         else
98             types = null;
99         
100         oc.close();
101         
102         return types;
103     }
104     
105     private ArrayList getEventsForUser(String JavaDoc user, boolean showAll, long start, long end)
106     throws Exception JavaDoc
107     {
108         ArrayList events;
109         
110         CalendarAction ca = new CalendarAction(CalendarAction.GET_EVENTS_FOR_USER);
111         ca.set("user", user);
112         ca.set("showAll", Boolean.valueOf(showAll));
113         ca.set("startTime", new Long JavaDoc(start));
114         ca.set("endTime", new Long JavaDoc(end));
115         
116         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
117             service, service.getName(), ca);
118     
119         if(oc.readString().equals("OK"))
120             events = (ArrayList)oc.read();
121         else
122             events = null;
123             
124         oc.close();
125         
126         return events;
127     }
128
129     public ArrayList getEventsForUser(String JavaDoc user, long start, long end)
130     throws Exception JavaDoc
131     {
132         return getEventsForUser(user, false, start, end);
133     }
134     
135     public ArrayList getMyEvents(long start, long end)
136     throws Exception JavaDoc
137     {
138         return getEventsForUser(Client.getInstance().getMyInfos().getName(),
139             true, start, end);
140     }
141     
142     private ArrayList getEventsForResource(String JavaDoc object, long start, long end)
143     throws Exception JavaDoc
144     {
145         ArrayList events;
146         
147         CalendarAction ca = new CalendarAction(CalendarAction.GET_EVENTS_FOR_RESOURCE);
148         ca.set("resource", object);
149         ca.set("startTime", new Long JavaDoc(start));
150         ca.set("endTime", new Long JavaDoc(end));
151     
152         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
153             service, service.getName(), ca);
154     
155         if(oc.readString().equals("OK"))
156             events = (ArrayList)oc.read();
157         else
158             events = null;
159             
160         oc.close();
161         
162         return events;
163     }
164     
165     public ArrayList getResources()
166     throws Exception JavaDoc
167     {
168         ArrayList resources = new ArrayList();
169         CalendarAction ca = new CalendarAction(CalendarAction.GET_RESOURCES);
170         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
171             service, service.getName(), ca);
172         
173         if(oc.readString().equals("OK"))
174             resources = (ArrayList)oc.read();
175         else
176             resources = null;
177         
178         oc.close();
179         
180         return resources;
181     }
182     
183     public ArrayList getUsers()
184     throws Exception JavaDoc
185     {
186         ArrayList resources = new ArrayList();
187         CalendarAction ca = new CalendarAction(CalendarAction.GET_USERS);
188         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
189                 service, service.getName(), ca);
190         
191         if(oc.readString().equals("OK"))
192             resources = (ArrayList)oc.read();
193         else
194             resources = null;
195         
196         oc.close();
197         
198         return resources;
199     }
200
201     public ArrayList getGroups()
202     throws Exception JavaDoc
203     {
204         ArrayList resources = new ArrayList();
205         CalendarAction ca = new CalendarAction(CalendarAction.GET_GROUPS);
206         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
207                 service, service.getName(), ca);
208         
209         if(oc.readString().equals("OK"))
210             resources = (ArrayList)oc.read();
211         else
212             resources = null;
213         
214         oc.close();
215         
216         return resources;
217     }
218     
219     public Color JavaDoc getColor(String JavaDoc name, Color JavaDoc defaultColor)
220     {
221         String JavaDoc r = getLocalConfig().get(name + ".r");
222         String JavaDoc g = getLocalConfig().get(name + ".g");
223         String JavaDoc b = getLocalConfig().get(name + ".b");
224         
225         if(r != null && g != null && b != null)
226             return new Color JavaDoc(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b));
227         
228         return defaultColor;
229     }
230 }
Popular Tags