Ignore:
Timestamp:
07/28/08 15:08:13 (16 years ago)
Author:
ra33
Message:

Added faster versions of search frameset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/FrameIO.java

    r156 r162  
    55import java.io.File;
    66import java.io.FileInputStream;
     7import java.io.FileNotFoundException;
    78import java.io.FileOutputStream;
    89import java.io.FileReader;
     
    1011import java.io.IOException;
    1112import java.sql.Time;
     13import java.util.Collection;
    1214import java.util.HashMap;
     15import java.util.LinkedList;
    1316
    1417import org.expeditee.agents.ExistingFramesetException;
     
    239242        }
    240243
     244        public static Collection<String> searchFrame(String frameName,
     245                        String pattern, String path) {
     246                String fullPath = null;
     247                if (path == null) {
     248                        for (String possiblePath : UserSettings.FrameDirs) {
     249                                fullPath = getFrameFullPathName(possiblePath, frameName);
     250                                if (fullPath != null)
     251                                        break;
     252                        }
     253                } else {
     254                        fullPath = getFrameFullPathName(path, frameName);
     255                        assert(fullPath != null);
     256                }
     257                // If the frame was not located return null
     258                if (fullPath == null)
     259                        return null;
     260                Collection<String> results = new LinkedList<String>();
     261                // Open the file and search the text items
     262                try {
     263                        BufferedReader reader = new BufferedReader(new FileReader(fullPath));
     264                        String next;
     265                        while (reader.ready() && ((next = reader.readLine()) != null)) {
     266                                if (next.startsWith("T")) {
     267                                        String toSearch = next.substring(2);
     268                                        if (toSearch.toLowerCase().matches(pattern))
     269                                                results.add(toSearch);
     270                                }
     271                        }
     272                } catch (FileNotFoundException e) {
     273                        e.printStackTrace();
     274                        return null;
     275                } catch (IOException e) {
     276                        e.printStackTrace();
     277                }
     278                return results;
     279        }
     280
    241281        private static Frame LoadFrame(String path, String frameName) {
    242282                String fullPath = getFrameFullPathName(path, frameName);
     
    349389                // if we did not find another Frame then this one must be the last one
    350390                // in the frameset
    351                 MessageBay
    352                                 .displayMessageOnce("This is the last frame in the frameset");
     391                MessageBay.displayMessageOnce("This is the last frame in the frameset");
    353392                return null;
    354393        }
     
    421460         * @param toDelete
    422461         *            The Frame to be deleted
    423          * @return The name the deleted frame was changed to, or null if the delete failed
     462         * @return The name the deleted frame was changed to, or null if the delete
     463         *         failed
    424464         */
    425465        public static String DeleteFrame(Frame toDelete) throws IOException,
     
    468508                ff.close();
    469509
    470                 if( del.delete()){
     510                if (del.delete()) {
    471511                        return toDelete.getName();
    472512                }
    473                
     513
    474514                return null;
    475515        }
     
    552592                                i.setLink(null);
    553593                }
    554                
     594
    555595                // do auto shrinking of the title IF not in twin frames mode
    556596                Item titleItem = template.getTitleItem();
     
    676716                        boolean checkBackup) {
    677717
    678                 // TODO When loading a frame maybe append onto the event history too- with a
     718                // TODO When loading a frame maybe append onto the event history too-
     719                // with a
    679720                // break to indicate the end of a session
    680721
    681                 if (toSave == null ||!toSave.hasChanged() || toSave.isSaved()){
     722                if (toSave == null || !toSave.hasChanged() || toSave.isSaved()) {
    682723                        SessionStats.NewFrameSession();
    683724                        return "";
     
    691732
    692733                // Dont save if the frame is protected and it exists
    693                 if (checkBackup
    694                                 && toSave.isReadOnly()) {
     734                if (checkBackup && toSave.isReadOnly()) {
    695735                        _Cache.remove(toSave.getName().toLowerCase());
    696736                        SessionStats.NewFrameSession();
     
    776816                        toSave.setActiveTime(activeTime);
    777817
    778                         //int oldMode = FrameGraphics.getMode();
    779                         //if (oldMode != FrameGraphics.MODE_XRAY)
    780                         //      FrameGraphics.setMode(FrameGraphics.MODE_XRAY, true);
     818                        // int oldMode = FrameGraphics.getMode();
     819                        // if (oldMode != FrameGraphics.MODE_XRAY)
     820                        // FrameGraphics.setMode(FrameGraphics.MODE_XRAY, true);
    781821                        writer.writeFrame(toSave);
    782                         //FrameGraphics.setMode(oldMode, true);
     822                        // FrameGraphics.setMode(oldMode, true);
    783823                        toSave.setSaved();
    784824                        if (inc) {
Note: See TracChangeset for help on using the changeset viewer.