1 19 20 package org.lucane.applications.calendar; 21 22 import java.awt.Color ; 23 import java.awt.Dimension ; 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 33 public class CalendarPlugin extends StandalonePlugin 34 { 35 private ConnectInfo service; 36 37 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 CalendarFrame cf = new CalendarFrame(this); 53 cf.setExitPluginOnClose(true); 54 cf.setPreferredSize(new Dimension (780, 550)); 55 cf.show(); 56 } 57 58 public void storeEvent(Event e) 59 throws Exception 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(); 69 oc.close(); 70 } 71 72 public void removeEvent(Event e) 73 throws Exception 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(); 83 oc.close(); 84 } 85 86 public ArrayList getEventTypes() 87 throws Exception 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 user, boolean showAll, long start, long end) 106 throws Exception 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 (start)); 114 ca.set("endTime", new Long (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 user, long start, long end) 130 throws Exception 131 { 132 return getEventsForUser(user, false, start, end); 133 } 134 135 public ArrayList getMyEvents(long start, long end) 136 throws Exception 137 { 138 return getEventsForUser(Client.getInstance().getMyInfos().getName(), 139 true, start, end); 140 } 141 142 private ArrayList getEventsForResource(String object, long start, long end) 143 throws Exception 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 (start)); 150 ca.set("endTime", new Long (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 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 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 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 getColor(String name, Color defaultColor) 220 { 221 String r = getLocalConfig().get(name + ".r"); 222 String g = getLocalConfig().get(name + ".g"); 223 String b = getLocalConfig().get(name + ".b"); 224 225 if(r != null && g != null && b != null) 226 return new Color (Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b)); 227 228 return defaultColor; 229 } 230 } | Popular Tags |