Ignore:
Timestamp:
09/12/08 17:19:37 (16 years ago)
Author:
ra33
Message:

Updated mail stuff and networking stuff!!

Location:
trunk/src/org/expeditee/actions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r298 r305  
    257257
    258258        /**
    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         * 
    262262         * @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.
    270269         *
    271270         * @throws NullPointerException
    272          *              If fullClassNames is null.
    273          *             
     271         *             If fullClassNames is null.
     272         * 
    274273         */
    275274        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
    278278                List<String> omittedAgents = new LinkedList<String>();
    279                
     279
    280280                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
    284285                        boolean didAdd = false;
    285                
     286
    286287                        try {
    287288                                // Does the class even exist?
    288289                                Class c = Class.forName(fullName);
    289                                
     290
    290291                                String name = c.getSimpleName().toLowerCase();
    291292
    292293                                if (!_JAGs.containsKey(name)) {
    293                                        
     294
    294295                                        _JAGs.put(name, fullName);
    295296                                        didAdd = true;
    296                                        
     297
    297298                                }
    298299
     
    300301                                e.printStackTrace();
    301302                        }
    302                        
    303                         if (!didAdd) omittedAgents.add(fullName);
    304        
    305                 }
    306                        
    307        
     303
     304                        if (!didAdd)
     305                                omittedAgents.add(fullName);
     306
     307                }
     308
    308309                return omittedAgents;
    309310        }
    310        
     311
    311312        /**
    312313         * Loads all the Methods that meet the requirements checked by MethodCheck
     
    470471                String nameWithCorrectCase = name;
    471472                name = name.toLowerCase();
    472                
     473
    473474                String fullClassName = AGENTS_PACKAGE + name;
    474475
     
    481482                                                + " " + parameters;
    482483                                fullClassName = AGENTS_PACKAGE + "writetree";
    483                                
     484
    484485                        } else if (name.endsWith("frame")) {
    485486                                parameters = name
     
    552553                        // create the JAG
    553554                        Agent toLaunch = (Agent) con.newInstance(params);
    554                        
     555
    555556                        LaunchAgent(toLaunch, source, clicked);
    556557
     
    559560                        throw new RuntimeException(nameWithCorrectCase
    560561                                        + "' is not an action or agent.");
    561                 } 
    562         }
    563        
     562                }
     563        }
     564
    564565        /**
    565566         * Launches an agent from a aleady instantiated object.
    566567         *
    567568         * @param agent
    568          *              The agent to launch. Must not be null.
     569         *            The agent to launch. Must not be null.
    569570         *
    570571         * @param source
    571          *              The calling frame that launched it. Must not be null.
     572         *            The calling frame that launched it. Must not be null.
    572573         *
    573574         * @param itemParam
    574          *              The item paremeter for the agent. Must not be null.
     575         *            The item paremeter for the agent.
    575576         *
    576577         * @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
    588588                String nameWithCorrectCase = agent.getClass().getSimpleName();
    589                
     589
    590590                try {
    591        
    592        
     591
    593592                        // create the JAG
    594593                        _Agent = agent;
    595        
     594
    596595                        Thread t = new Thread(_Agent);
    597596                        t.setPriority(Thread.MIN_PRIORITY);
     
    600599                                itemParam = FreeItems.getItemAttachedToCursor();
    601600                        }
    602        
     601
    603602                        // check for errors during initialisation
    604603                        if (!_Agent.initialise(source, itemParam)) {
     
    607606                                                + nameWithCorrectCase);
    608607                        }
    609        
     608
    610609                        // save the current frame (if necesssary)
    611610                        // TODO make this nicer... ie. make Format an action rather than an
    612611                        // 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")) {
    614614                                FrameUtils.LeavingFrame(source);
    615615                        }
    616        
     616
    617617                        if (_Agent.hasResultString()) {
    618618                                // Just run the agent on this thread... dont run it in the
  • trunk/src/org/expeditee/actions/MailActions.java

    r284 r305  
    66
    77import org.expeditee.agents.mail.MailSession;
     8import org.expeditee.gui.AttributeValuePair;
    89import org.expeditee.gui.DisplayIO;
    910import org.expeditee.gui.Frame;
     
    4849                return mail;
    4950        }
    50        
     51
    5152        public static Collection<Text> getRecentMail(int number) {
    5253                return getMail(null, null, number);
    5354        }
    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
    5570        public static Collection<Text> getUnreadMail() {
    5671                return getMail(Flag.SEEN, false, Integer.MAX_VALUE);
     
    6075                return getMail(null, null, Integer.MAX_VALUE);
    6176        }
    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
    6388        public static Collection<Text> getMail() {
    6489                return getAllMail();
     
    6893                return getMail(Flag.RECENT, true, Integer.MAX_VALUE);
    6994        }
    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
    76104                return mailItems;
    77105        }
     
    95123                }
    96124        }
    97        
     125
    98126        public static String getMailCount() {
    99127                return getAllMailCount();
     
    121149                Frame replyFrame = DisplayIO.getCurrentFrame();
    122150                String titleText = frame.getTitle();
    123                 //Add Re on the end if it is not already there
     151                // Add Re on the end if it is not already there
    124152                if (titleText.length() >= 3
    125153                                && !"re:".equals(titleText.substring(0, 3).toLowerCase())) {
     
    128156                replyFrame.setTitle(titleText);
    129157                FrameKeyboardActions.Drop(null, false);
    130                
    131                 //Add a link to the original message
     158
     159                // Add a link to the original message
    132160                Text original = replyFrame.createNewText("@original");
    133161                original.setPosition(FrameMouseActions.getPosition());
     
    139167                to.addAction("MailTree");
    140168                FrameKeyboardActions.Drop(to, false);
    141                 DisplayIO.setCursorPosition(FrameMouseActions.MouseX, FrameMouseActions.MouseY + 15);
     169                DisplayIO.setCursorPosition(FrameMouseActions.MouseX,
     170                                FrameMouseActions.MouseY + 15);
    142171        }
    143172
Note: See TracChangeset for help on using the changeset viewer.