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;
021:
022: import java.awt.Color;
023: import java.awt.Dimension;
024: import java.util.*;
025:
026: import org.lucane.client.*;
027: import org.lucane.common.*;
028: import org.lucane.common.net.ObjectConnection;
029: import org.lucane.applications.calendar.gui.CalendarFrame;
030:
031: //TODO activate resources
032:
033: public class CalendarPlugin extends StandalonePlugin {
034: private ConnectInfo service;
035:
036: //-- from Plugin
037: public CalendarPlugin() {
038: }
039:
040: public Plugin newInstance(ConnectInfo[] friends) {
041: return new CalendarPlugin();
042: }
043:
044: public void start() {
045: service = Communicator.getInstance().getConnectInfo(
046: "org.lucane.applications.calendar");
047:
048: //-- display month view
049: CalendarFrame cf = new CalendarFrame(this );
050: cf.setExitPluginOnClose(true);
051: cf.setPreferredSize(new Dimension(780, 550));
052: cf.show();
053: }
054:
055: public void storeEvent(Event e) throws Exception {
056: CalendarAction ca = new CalendarAction(
057: CalendarAction.STORE_EVENT);
058: ca.set("event", e);
059:
060: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
061: service, service.getName(), ca);
062:
063: oc.readString(); //OK or FAILED
064:
065: oc.close();
066: }
067:
068: public void removeEvent(Event e) throws Exception {
069: CalendarAction ca = new CalendarAction(
070: CalendarAction.REMOVE_EVENT);
071: ca.set("event", e);
072:
073: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
074: service, service.getName(), ca);
075:
076: oc.readString(); //OK or FAILED
077:
078: oc.close();
079: }
080:
081: public ArrayList getEventTypes() throws Exception {
082: ArrayList types;
083:
084: CalendarAction ca = new CalendarAction(
085: CalendarAction.GET_EVENT_TYPES);
086: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
087: service, service.getName(), ca);
088:
089: if (oc.readString().equals("OK"))
090: types = (ArrayList) oc.read();
091: else
092: types = null;
093:
094: oc.close();
095:
096: return types;
097: }
098:
099: private ArrayList getEventsForUser(String user, boolean showAll,
100: long start, long end) throws Exception {
101: ArrayList events;
102:
103: CalendarAction ca = new CalendarAction(
104: CalendarAction.GET_EVENTS_FOR_USER);
105: ca.set("user", user);
106: ca.set("showAll", Boolean.valueOf(showAll));
107: ca.set("startTime", new Long(start));
108: ca.set("endTime", new Long(end));
109:
110: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
111: service, service.getName(), ca);
112:
113: if (oc.readString().equals("OK"))
114: events = (ArrayList) oc.read();
115: else
116: events = null;
117:
118: oc.close();
119:
120: return events;
121: }
122:
123: public ArrayList getEventsForUser(String user, long start, long end)
124: throws Exception {
125: return getEventsForUser(user, false, start, end);
126: }
127:
128: public ArrayList getMyEvents(long start, long end) throws Exception {
129: return getEventsForUser(Client.getInstance().getMyInfos()
130: .getName(), true, start, end);
131: }
132:
133: private ArrayList getEventsForResource(String object, long start,
134: long end) throws Exception {
135: ArrayList events;
136:
137: CalendarAction ca = new CalendarAction(
138: CalendarAction.GET_EVENTS_FOR_RESOURCE);
139: ca.set("resource", object);
140: ca.set("startTime", new Long(start));
141: ca.set("endTime", new Long(end));
142:
143: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
144: service, service.getName(), ca);
145:
146: if (oc.readString().equals("OK"))
147: events = (ArrayList) oc.read();
148: else
149: events = null;
150:
151: oc.close();
152:
153: return events;
154: }
155:
156: public ArrayList getResources() throws Exception {
157: ArrayList resources = new ArrayList();
158: CalendarAction ca = new CalendarAction(
159: CalendarAction.GET_RESOURCES);
160: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
161: service, service.getName(), ca);
162:
163: if (oc.readString().equals("OK"))
164: resources = (ArrayList) oc.read();
165: else
166: resources = null;
167:
168: oc.close();
169:
170: return resources;
171: }
172:
173: public ArrayList getUsers() throws Exception {
174: ArrayList resources = new ArrayList();
175: CalendarAction ca = new CalendarAction(CalendarAction.GET_USERS);
176: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
177: service, service.getName(), ca);
178:
179: if (oc.readString().equals("OK"))
180: resources = (ArrayList) oc.read();
181: else
182: resources = null;
183:
184: oc.close();
185:
186: return resources;
187: }
188:
189: public ArrayList getGroups() throws Exception {
190: ArrayList resources = new ArrayList();
191: CalendarAction ca = new CalendarAction(
192: CalendarAction.GET_GROUPS);
193: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
194: service, service.getName(), ca);
195:
196: if (oc.readString().equals("OK"))
197: resources = (ArrayList) oc.read();
198: else
199: resources = null;
200:
201: oc.close();
202:
203: return resources;
204: }
205:
206: public Color getColor(String name, Color defaultColor) {
207: String r = getLocalConfig().get(name + ".r");
208: String g = getLocalConfig().get(name + ".g");
209: String b = getLocalConfig().get(name + ".b");
210:
211: if (r != null && g != null && b != null)
212: return new Color(Integer.parseInt(r), Integer.parseInt(g),
213: Integer.parseInt(b));
214:
215: return defaultColor;
216: }
217: }
|