Changeset 305
- Timestamp:
- 09/12/08 17:19:37 (16 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Actions.java
r298 r305 257 257 258 258 /** 259 * Temporary, if a plugin system is devised then this would porbably become redundant.260 * For now this allows external agents to be included.261 * 259 * Temporary, if a plugin system is devised then this would porbably become 260 * redundant. For now this allows external agents to be included. 261 * 262 262 * @param fullClassNames 263 * A set of full class names, that is, the class package and name. For example" 264 * "org.myplugin.agents.SerializedSearch" 265 * 266 * @return 267 * A collection of classes their were omitted because either there was a name clash 268 * with existing agents or did not exist. 269 * i.e. is completely successful this will be empty. Never null. 263 * A set of full class names, that is, the class package and 264 * name. For example" "org.myplugin.agents.SerializedSearch" 265 * 266 * @return A collection of classes their were omitted because either there 267 * was a name clash with existing agents or did not exist. i.e. is 268 * completely successful this will be empty. Never null. 270 269 * 271 270 * @throws NullPointerException 272 * 273 * 271 * If fullClassNames is null. 272 * 274 273 */ 275 274 public static Collection<String> addAgents(Set<String> fullClassNames) { 276 if (fullClassNames == null) throw new NullPointerException("fullClassNames"); 277 275 if (fullClassNames == null) 276 throw new NullPointerException("fullClassNames"); 277 278 278 List<String> omittedAgents = new LinkedList<String>(); 279 279 280 280 for (String fullName : fullClassNames) { 281 282 if (fullName == null || fullName.length() == 0) continue; 283 281 282 if (fullName == null || fullName.length() == 0) 283 continue; 284 284 285 boolean didAdd = false; 285 286 286 287 try { 287 288 // Does the class even exist? 288 289 Class c = Class.forName(fullName); 289 290 290 291 String name = c.getSimpleName().toLowerCase(); 291 292 292 293 if (!_JAGs.containsKey(name)) { 293 294 294 295 _JAGs.put(name, fullName); 295 296 didAdd = true; 296 297 297 298 } 298 299 … … 300 301 e.printStackTrace(); 301 302 } 302 303 if (!didAdd) omittedAgents.add(fullName);304 305 } 306 307 303 304 if (!didAdd) 305 omittedAgents.add(fullName); 306 307 } 308 308 309 return omittedAgents; 309 310 } 310 311 311 312 /** 312 313 * Loads all the Methods that meet the requirements checked by MethodCheck … … 470 471 String nameWithCorrectCase = name; 471 472 name = name.toLowerCase(); 472 473 473 474 String fullClassName = AGENTS_PACKAGE + name; 474 475 … … 481 482 + " " + parameters; 482 483 fullClassName = AGENTS_PACKAGE + "writetree"; 483 484 484 485 } else if (name.endsWith("frame")) { 485 486 parameters = name … … 552 553 // create the JAG 553 554 Agent toLaunch = (Agent) con.newInstance(params); 554 555 555 556 LaunchAgent(toLaunch, source, clicked); 556 557 … … 559 560 throw new RuntimeException(nameWithCorrectCase 560 561 + "' is not an action or agent."); 561 } 562 } 563 562 } 563 } 564 564 565 /** 565 566 * Launches an agent from a aleady instantiated object. 566 567 * 567 568 * @param agent 568 * 569 * The agent to launch. Must not be null. 569 570 * 570 571 * @param source 571 * 572 * The calling frame that launched it. Must not be null. 572 573 * 573 574 * @param itemParam 574 * The item paremeter for the agent. Must not be null.575 * The item paremeter for the agent. 575 576 * 576 577 * @throws NullPointerException 577 * if any of the arguments are null. 578 */ 579 public static void LaunchAgent( 580 Agent agent, 581 Frame source, 582 Item itemParam) { 583 584 if (agent == null) throw new NullPointerException("agent"); 585 if (source == null) throw new NullPointerException("source"); 586 if (itemParam == null) throw new NullPointerException("itemParam"); 587 578 * if any of the arguments are null. 579 */ 580 public static void LaunchAgent(Agent agent, Frame source, Item itemParam) { 581 582 if (agent == null) 583 throw new NullPointerException("agent"); 584 if (source == null) 585 throw new NullPointerException("source"); 586 // if (itemParam == null) throw new NullPointerException("itemParam"); 587 588 588 String nameWithCorrectCase = agent.getClass().getSimpleName(); 589 589 590 590 try { 591 592 591 593 592 // create the JAG 594 593 _Agent = agent; 595 594 596 595 Thread t = new Thread(_Agent); 597 596 t.setPriority(Thread.MIN_PRIORITY); … … 600 599 itemParam = FreeItems.getItemAttachedToCursor(); 601 600 } 602 601 603 602 // check for errors during initialisation 604 603 if (!_Agent.initialise(source, itemParam)) { … … 607 606 + nameWithCorrectCase); 608 607 } 609 608 610 609 // save the current frame (if necesssary) 611 610 // TODO make this nicer... ie. make Format an action rather than an 612 611 // agent and save frames only before running agents 613 if (!nameWithCorrectCase.equalsIgnoreCase("format") && !nameWithCorrectCase.equalsIgnoreCase("sort")) { 612 if (!nameWithCorrectCase.equalsIgnoreCase("format") 613 && !nameWithCorrectCase.equalsIgnoreCase("sort")) { 614 614 FrameUtils.LeavingFrame(source); 615 615 } 616 616 617 617 if (_Agent.hasResultString()) { 618 618 // Just run the agent on this thread... dont run it in the -
trunk/src/org/expeditee/actions/MailActions.java
r284 r305 6 6 7 7 import org.expeditee.agents.mail.MailSession; 8 import org.expeditee.gui.AttributeValuePair; 8 9 import org.expeditee.gui.DisplayIO; 9 10 import org.expeditee.gui.Frame; … … 48 49 return mail; 49 50 } 50 51 51 52 public static Collection<Text> getRecentMail(int number) { 52 53 return getMail(null, null, number); 53 54 } 54 55 56 public static Collection<Text> getUnreadMail(Item clicked, int number) { 57 if (clicked instanceof Text) { 58 AttributeValuePair avp = new AttributeValuePair(clicked 59 .getText()); 60 if (avp.hasPair() && avp.getValue().contains(MailSession.UNREAD_MESSAGE)) { 61 avp.setValue("0" + MailSession.UNREAD_MESSAGE + "s"); 62 clicked.setText(avp.toString()); 63 clicked.setActions(null); 64 } 65 } 66 67 return getMail(Flag.SEEN, false, number); 68 } 69 55 70 public static Collection<Text> getUnreadMail() { 56 71 return getMail(Flag.SEEN, false, Integer.MAX_VALUE); … … 60 75 return getMail(null, null, Integer.MAX_VALUE); 61 76 } 62 77 78 public static Text getMail(int messageNo) { 79 Text mailItem = MailSession.getInstance().getMail( 80 DisplayIO.getCurrentFrame(), FrameMouseActions.getPosition(), 81 messageNo - 1); 82 // MessageBay.displayMessage(mailItems.size() + " messages read", 83 // Color.green); 84 85 return mailItem; 86 } 87 63 88 public static Collection<Text> getMail() { 64 89 return getAllMail(); … … 68 93 return getMail(Flag.RECENT, true, Integer.MAX_VALUE); 69 94 } 70 71 private static Collection<Text> getMail(Flag flag, Boolean isPresent, int noOfMessages){ 72 Collection<Text> mailItems = MailSession.getInstance().getMail(flag, isPresent, 73 DisplayIO.getCurrentFrame(), FrameMouseActions.getPosition(), noOfMessages); 74 //MessageBay.displayMessage(mailItems.size() + " messages read", Color.green); 75 95 96 private static Collection<Text> getMail(Flag flag, Boolean isPresent, 97 int noOfMessages) { 98 Collection<Text> mailItems = MailSession.getInstance().getMail(flag, 99 isPresent, DisplayIO.getCurrentFrame(), 100 FrameMouseActions.getPosition(), noOfMessages); 101 // MessageBay.displayMessage(mailItems.size() + " messages read", 102 // Color.green); 103 76 104 return mailItems; 77 105 } … … 95 123 } 96 124 } 97 125 98 126 public static String getMailCount() { 99 127 return getAllMailCount(); … … 121 149 Frame replyFrame = DisplayIO.getCurrentFrame(); 122 150 String titleText = frame.getTitle(); 123 // Add Re on the end if it is not already there151 // Add Re on the end if it is not already there 124 152 if (titleText.length() >= 3 125 153 && !"re:".equals(titleText.substring(0, 3).toLowerCase())) { … … 128 156 replyFrame.setTitle(titleText); 129 157 FrameKeyboardActions.Drop(null, false); 130 131 // Add a link to the original message158 159 // Add a link to the original message 132 160 Text original = replyFrame.createNewText("@original"); 133 161 original.setPosition(FrameMouseActions.getPosition()); … … 139 167 to.addAction("MailTree"); 140 168 FrameKeyboardActions.Drop(to, false); 141 DisplayIO.setCursorPosition(FrameMouseActions.MouseX, FrameMouseActions.MouseY + 15); 169 DisplayIO.setCursorPosition(FrameMouseActions.MouseX, 170 FrameMouseActions.MouseY + 15); 142 171 } 143 172 -
trunk/src/org/expeditee/agents/mail/MailSession.java
r298 r305 32 32 import org.expeditee.gui.Frame; 33 33 import org.expeditee.gui.FrameCreator; 34 import org.expeditee.gui.FrameGraphics; 34 35 import org.expeditee.gui.MessageBay; 35 36 import org.expeditee.importer.FrameDNDTransferHandler; … … 38 39 39 40 public class MailSession { 41 public static final String UNREAD_MESSAGE = " unread message"; 42 40 43 public static boolean _autoConnect = false; 41 44 … … 154 157 try { 155 158 if (!_transport.isConnected()) { 156 Text message = MessageBay.displayMessage("Connecting to SMTP server..."); 159 Text message = MessageBay 160 .displayMessage("Connecting to SMTP server..."); 157 161 _bConnecting = true; 158 162 _transport.connect(); … … 168 172 if (_mailServer != null && !_store.isConnected()) { 169 173 try { 170 Text message = MessageBay.displayMessage("Connecting to " + _mailServer171 + "...");174 Text message = MessageBay.displayMessage("Connecting to " 175 + _mailServer + "..."); 172 176 _store.connect(_mailServer, _username, _password); 173 177 … … 185 189 @Override 186 190 public void messagesAdded(MessageCountEvent e) { 187 MessageBay.displayMessage("New mail message!", 188 Color.green); 191 try { 192 MessageBay.displayMessage("New mail message!", 193 null, Color.green, true, "getMail " 194 + _folder.getMessageCount()); 195 } catch (MessagingException e1) { 196 e1.printStackTrace(); 197 } 189 198 displayUnreadMailCount(); 190 199 } … … 204 213 _folder.getMessageCount(); 205 214 _folder.exists(); 206 // _folder.getUnreadMessageCount();215 // _folder.getUnreadMessageCount(); 207 216 } catch (Exception e) { 208 217 e.printStackTrace(); 209 MessageBay.errorMessage("Mail connection unavailable"); 218 MessageBay 219 .errorMessage("Mail connection unavailable"); 210 220 finalise(); 211 221 break; … … 228 238 } 229 239 230 p rivatevoid displayUnreadMailCount() {240 public void displayUnreadMailCount() { 231 241 int unreadCount = getUnreadCount(); 232 Text text = new Text(-1, unreadCount + " unread message"242 Text text = new Text(-1, unreadCount + UNREAD_MESSAGE 233 243 + (unreadCount == 1 ? "" : "s"), Color.BLUE, null); 234 text.addAction("getRecentMail " + unreadCount); 244 if (unreadCount > 0) 245 text.addAction("getUnreadMail " + unreadCount); 235 246 MessageBay.displayMessage(text); 236 247 } … … 342 353 /** 343 354 * Closes the mail folders. 355 * 344 356 * @return true if the folders needed to be closed. 345 357 */ … … 433 445 msgs = _folder.getMessages(); 434 446 435 int start = Math.max(msgs.length - numberOfMessages, 0); 436 437 for (int msgNum = start; msgNum < msgs.length; msgNum++) { 447 int messagesRead = 0; 448 449 for (int msgNum = msgs.length - 1; messagesRead < numberOfMessages 450 && msgNum >= 0; msgNum--) { 438 451 if (flag == null 439 452 || msgs[msgNum].getFlags().contains(flag) == isPresent) { … … 443 456 mailItems.add(newItem); 444 457 point.y += newItem.getBoundsHeight(); 458 messagesRead++; 445 459 } 446 460 } … … 450 464 e.printStackTrace(); 451 465 } 452 466 453 467 return mailItems; 468 } 469 470 public Text getMail(Frame frame, Point point, int msgNum) { 471 if (_folder == null) 472 return null; 473 474 // -- Get the message wrappers and process them -- 475 try { 476 Message[] msgs = _folder.getMessages(); 477 return readMessage(msgs[msgNum], msgNum + 1, frame, point); 478 } catch (MessagingException e) { 479 e.printStackTrace(); 480 } 481 482 return null; 454 483 } 455 484 … … 467 496 // Create a frameCreator 468 497 final FrameCreator frames = new FrameCreator(frame 469 .getFramesetName(), frame.getPath(), subject, false, false); 498 .getFramesetName(), frame.getPath(), subject, 499 false, false); 470 500 471 501 frames.addText("@date: " + message.getSentDate(), null, … … 529 559 frames.save(); 530 560 source.setLink(frames.getName()); 561 FrameGraphics.requestRefresh(true); 531 562 } catch (MessagingException e) { 532 563 MessageBay.errorMessage("GetMail error: " + e.getMessage()); -
trunk/src/org/expeditee/gui/FrameIO.java
r298 r305 171 171 } 172 172 173 public static String LoadPublicFrame(String frameName) { 174 assert (isValidFrameName(frameName)); 175 Frame loaded = null; 176 String frameNameLower = frameName.toLowerCase(); 177 // first try reading from cache 178 if (isCacheOn() && _Cache.containsKey(frameNameLower)) { 179 Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName 180 + " from cache."); 181 loaded = _Cache.get(frameNameLower); 182 } else { 183 184 Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName 185 + " from disk."); 186 187 loaded = LoadFrame(PUBLIC_PATH, frameName); 188 } 189 190 String result = null; 191 // Get the contents of the frame to send to someone... 192 // TODO use a more efficient method to directly get the frame contents 193 // if possible 194 if (loaded != null) { 195 result = SaveFrame(loaded); 196 } 197 198 return result; 173 public static BufferedReader LoadPublicFrame(String frameName) { 174 String fullPath = FrameIO.getFrameFullPathName(PUBLIC_PATH, frameName); 175 176 File frameFile = new File(fullPath); 177 if (frameFile.exists() && frameFile.canRead()) { 178 try { 179 return new BufferedReader(new FileReader(frameFile)); 180 } catch (FileNotFoundException e) { 181 e.printStackTrace(); 182 } 183 } 184 return null; 199 185 } 200 186 … … 210 196 } 211 197 212 if (loaded == null ) {198 if (loaded == null && FrameShare.getInstance() != null) { 213 199 loaded = FrameShare.getInstance().loadFrame(framename); 214 200 } -
trunk/src/org/expeditee/network/FrameServer.java
r298 r305 1 1 package org.expeditee.network; 2 2 3 import java.io.BufferedReader; 3 4 import java.io.IOException; 4 5 import java.net.DatagramPacket; … … 10 11 11 12 public class FrameServer extends Thread { 13 14 private static final int MAX_PACKET_LENGTH = 2000; 12 15 13 16 private boolean _stop = false; … … 29 32 30 33 public void run() { 31 MessageBay.displayMessage("Serving frames on port " + socket.getLocalPort()); 32 34 MessageBay.displayMessage("Serving frames on port " 35 + socket.getLocalPort()); 36 33 37 while (!_stop) { 34 38 try { 35 byte[] buf = new byte[ 256];39 byte[] buf = new byte[MAX_PACKET_LENGTH]; 36 40 37 41 // receive request … … 39 43 socket.receive(packet); 40 44 41 String frameName = new String(packet.getData()); 45 String frameName = new String(packet.getData(), 0, packet 46 .getLength()); 47 MessageBay.displayMessage("Recieved request for " + frameName); 42 48 43 49 // figure out response 44 50 String dString = getFrame(frameName); 45 51 46 if (dString != null ) {52 if (dString != null && dString.length() > 0) { 47 53 buf = dString.getBytes(); 48 54 … … 61 67 62 68 protected String getFrame(String frameName) { 63 return FrameIO.LoadPublicFrame(frameName); 69 StringBuffer sb = new StringBuffer(); 70 BufferedReader br = FrameIO.LoadPublicFrame(frameName); 71 if (br == null) 72 return null; 73 74 String s = null; 75 try { 76 while ((s = br.readLine()) != null && sb.length() < MAX_PACKET_LENGTH) { 77 sb.append(s).append('\n'); 78 } 79 } catch (IOException e) { 80 e.printStackTrace(); 81 } 82 83 return sb.toString(); 64 84 } 65 85 } -
trunk/src/org/expeditee/network/FrameShare.java
r298 r305 38 38 // Set the settings 39 39 for (Text item : settingsFrame.getBodyTextItems(false)) { 40 String text = item.getText().toLowerCase().trim(); 40 41 41 AttributeValuePair avp = new AttributeValuePair(item.getText()); 42 if (avp.isAnnotation()) 43 continue; 42 44 43 if (text.equals("server")) { 45 String attribute = avp.getAttributeOrValue().toLowerCase(); 46 47 if (attribute.equals("server")) { 44 48 try { 45 49 if (!avp.hasPair()) { … … 59 63 if (!avp.hasPair()) 60 64 continue; 61 String attribute = avp.getAttribute().toLowerCase();62 65 63 66 try { … … 77 80 } 78 81 } 79 82 80 83 public void finalise() { 81 84 _server.close(); … … 119 122 break; 120 123 } catch (Exception e) { 124 e.printStackTrace(); 121 125 } 122 126 } … … 125 129 126 130 } 127 131 132 if(result == null) 133 return null; 134 128 135 // Now read the frame from the file contents 129 136 FrameReader reader = new ExpReader(frameName);
Note:
See TracChangeset
for help on using the changeset viewer.