Ignore:
Timestamp:
11/02/08 13:05:01 (16 years ago)
Author:
ra33
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/agents/SearchAgent.java

    r362 r376  
    11package org.expeditee.agents;
     2
     3import java.util.Collection;
    24
    35import org.expeditee.gui.Frame;
     
    2426
    2527        public SearchAgent(String searchText) {
    26                 _pattern = searchText.toLowerCase();
     28                if (searchText != null)
     29                        _pattern = searchText.toLowerCase();
    2730        }
    2831
     
    3942                                        false);
    4043                }
    41                 return initialise(frame, item, frame.getFramesetName(), resultFrameset,
     44                return initialise(frame, item, getSearchDescription(frame), resultFrameset,
    4245                                null, pattern);
     46        }
     47
     48        /**
     49         * @param frame
     50         * @return
     51         */
     52        protected String getSearchDescription(Frame frame) {
     53                return frame.getFramesetName();
    4354        }
    4455
     
    5667        public boolean initialise(Frame frame, Item item, String startName,
    5768                        String resultsFrameset, String replacementString, String pattern) {
    58                 //TODO: Put the init params in the constructor!! Dont want to be setting _pattern in two places!
    59                
     69                // TODO: Put the init params in the constructor!! Dont want to be
     70                // setting _pattern in two places!
     71
    6072                if (_pattern == null)
    6173                        _pattern = pattern.toLowerCase();
     
    6678                // and type as the title
    6779                String title = this.getClass().getSimpleName() + " [" + startName
    68                                 + "] [" + _pattern + "]";
    69                 _results = new FrameCreator(resultsFrameset, FrameIO.FRAME_PATH, title, false, true);
     80                                + "]"+getResultsTitleSuffix();
     81                _results = new FrameCreator(resultsFrameset, FrameIO.FRAME_PATH, title,
     82                                false, true);
    7083                // Set the frame to be displayed after running the agent
    7184                _end = _results.getFirstFrame();
    7285
    7386                return super.initialise(frame, item);
     87        }
     88
     89        protected String getResultsTitleSuffix() {
     90                return " [" + _pattern + "]";
    7491        }
    7592
     
    111128                return true;
    112129        }
     130       
     131        protected int addResults(String frameName, Collection<String> found) {
     132                return addResults(frameName, frameName, found);
     133        }
     134       
     135        /**
     136         * @param frameNumber
     137         * @param frameName
     138         * @param found
     139         * @return
     140         */
     141        protected int addResults(String frameNumber, String frameName, Collection<String> found) {
     142                int size = found == null ? 0 : found.size();
     143                // If the frame exists
     144                if (found != null)
     145                        _frameCount++;
     146                if (size > 0) {
     147                        // String repeats = size > 1? ("("+ size+ ")") : "";
     148                        for (String s : found) {
     149                                StringBuffer surrogate = new StringBuffer();
     150                                surrogate.append("[").append(frameNumber).append("] ");
     151                                if (s.length() > SearchAgent.SURROGATE_LENGTH)
     152                                        surrogate.append(
     153                                                        s.substring(0, SearchAgent.SURROGATE_LENGTH - 3))
     154                                                        .append("...");
     155                                else {
     156                                        surrogate.append(s);
     157                                }
     158
     159                                _results.addText(surrogate.toString(), null,
     160                                                frameName, null, false);
     161                                FrameGraphics.requestRefresh(true);
     162                        }
     163                }
     164                return size;
     165        }
    113166}
Note: See TracChangeset for help on using the changeset viewer.