Ignore:
Timestamp:
09/16/08 16:29:27 (16 years ago)
Author:
ra33
Message:

Can navigate with PgUp PgDn Home and End with remote framesets

File:
1 edited

Legend:

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

    r306 r307  
    128128                MessageBay.supressMessages(true);
    129129                // loading automatically caches the frame is caching is turned on
    130                 LoadUnknownPath(framename, false);
     130                LoadFromDisk(framename, null, false);
    131131                MessageBay.supressMessages(false);
    132132        }
     
    150150
    151151        public static Frame LoadFrame(String frameName) {
    152                 return LoadFrame(frameName, false);
    153         }
    154 
    155         public static Frame LoadFrame(String frameName, boolean ignoreAnnotations) {
     152                return LoadFrame(frameName, null, false);
     153        }
     154
     155        public static Frame LoadFrame(String frameName, String path) {
     156                return LoadFrame(frameName, path, false);
     157        }
     158
     159        public static Frame LoadFrame(String frameName, String path,
     160                        boolean ignoreAnnotations) {
    156161                if (!isValidFrameName(frameName))
    157162                        return null;
     
    168173                Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName
    169174                                + " from disk.");
    170                 return LoadUnknownPath(frameName, ignoreAnnotations);
     175
     176                return LoadFromDisk(frameName, path, ignoreAnnotations);
    171177        }
    172178
     
    174180                String fullPath = FrameIO.getFrameFullPathName(PUBLIC_PATH, frameName);
    175181
     182                if(fullPath == null)
     183                        return null;
     184               
    176185                File frameFile = new File(fullPath);
    177186                if (frameFile.exists() && frameFile.canRead()) {
     
    185194        }
    186195
    187         private static Frame LoadUnknownPath(String framename,
     196        private static Frame LoadFromDisk(String framename, String knownPath,
    188197                        boolean ignoreAnnotations) {
    189198                Frame loaded = null;
    190199
    191                 for (String path : UserSettings.FrameDirs) {
    192                         loaded = LoadFrame(path, framename);
    193                         if (loaded != null) {
    194                                 break;
    195                         }
    196                 }
    197 
     200                if (knownPath != null) {
     201                        loaded = LoadKnowPath(knownPath, framename);
     202                } else {
     203
     204                        for (String path : UserSettings.FrameDirs) {
     205                                loaded = LoadKnowPath(path, framename);
     206                                if (loaded != null) {
     207                                        break;
     208                                }
     209                        }
     210                }
     211               
    198212                if (loaded == null && FrameShare.getInstance() != null) {
    199                         loaded = FrameShare.getInstance().loadFrame(framename);
     213                        loaded = FrameShare.getInstance().loadFrame(framename, knownPath);
    200214                }
    201215
     
    321335        }
    322336
    323         private static Frame LoadFrame(String path, String frameName) {
     337        private static Frame LoadKnowPath(String path, String frameName) {
    324338                String fullPath = getFrameFullPathName(path, frameName);
    325339                if (fullPath == null)
     
    386400                // loop until a frame that exists is found
    387401                for (; num >= 0; num--) {
    388                         Frame f = LoadFrame(name + num);
     402                        Frame f = LoadFrame(name + num, current.getPath());
    389403                        if (f != null)
    390404                                return f;
     
    415429                // read the maximum from the INF file
    416430                try {
    417                         max = ReadINF(current.getPath(), current.getFramesetName());
     431                        max = ReadINF(current.getPath(), current.getFramesetName(), false);
    418432                } catch (IOException ioe) {
    419433                        MessageBay.errorMessage("Error loading INF file for frameset '"
     
    424438                // loop until a frame that exists is found
    425439                for (; num <= max; num++) {
    426                         Frame f = LoadFrame(name + num);
     440                        Frame f = LoadFrame(name + num, current.getPath());
    427441                        if (f != null)
    428442                                return f;
     
    454468                int max;
    455469                try {
    456                         max = ReadINF(path, framesetName);
     470                        max = ReadINF(path, framesetName, false);
    457471                } catch (IOException ioe) {
    458472                        MessageBay.errorMessage("Error loading INF file for frameset '"
     
    463477                // loop backwards until a frame that exists is found
    464478                for (int num = max; num > 0; num--) {
    465                         Frame f = LoadFrame(framesetName + num);
     479                        Frame f = LoadFromDisk(framesetName + num, path, false);
    466480                        if (f != null)
    467481                                return f;
     
    610624                // read the next number from the INF file
    611625                try {
    612                         next = ReadINF(destFramesetZero.getPath(), frameset);
     626                        next = ReadINF(destFramesetZero.getPath(), frameset, true);
    613627                } catch (IOException ioe) {
    614628                        ioe.printStackTrace();
     
    626640                Logger.Log(Logger.SYSTEM, Logger.TDFC, "Creating new frame: "
    627641                                + template.getName() + " from TDFC");
    628 
    629                 // update INF file
    630                 try {
    631                         WriteINF(template.getPath(), frameset, frameset + next);
    632                 } catch (IOException ioe) {
    633                         ioe.printStackTrace();
    634                         Logger.Log(ioe);
    635                 }
    636642
    637643                template.setOwner(UserSettings.Username);
     
    822828                                _Cache.remove(toSave.getName().toLowerCase());
    823829                                int nextnum = ReadINF(toSave.getPath(), toSave
    824                                                 .getFramesetName()) + 1;
     830                                                .getFramesetName(), false) + 1;
    825831                                SuspendCache();
    826832                                Frame original = LoadFrame(toSave.getName());
     
    851857                                int orignum = original.getNumber();
    852858                                int nextnum = ReadINF(toSave.getPath(), toSave
    853                                                 .getFramesetName()) + 1;
     859                                                .getFramesetName(), false) + 1;
    854860
    855861                                original.setFrameNumber(nextnum);
     
    885891
    886892                        // check that the INF file is not out of date
    887                         int last = ReadINF(toSave.getPath(), toSave.getFramesetName());
     893                        int last = ReadINF(toSave.getPath(), toSave.getFramesetName(),
     894                                        false);
    888895                        if (last <= toSave.getNumber())
    889896                                WriteINF(toSave.getPath(), toSave.getFramesetName(), toSave
     
    947954         *             the INF.
    948955         */
    949         private static int ReadINF(String path, String frameset) throws IOException {
     956        public static int ReadINF(String path, String frameset, boolean update)
     957                        throws IOException {
    950958                assert (!frameset.endsWith("."));
    951 
    952                 // read INF
    953                 BufferedReader reader;
    954959                try {
    955                         reader = new BufferedReader(new FileReader(path
    956                                         + frameset.toLowerCase() + File.separator + INF_FILENAME));
     960                        // read INF
     961                        BufferedReader reader;
     962                        try {
     963                                // Check on the local drive
     964                                reader = new BufferedReader(new FileReader(path
     965                                                + frameset.toLowerCase() + File.separator
     966                                                + INF_FILENAME));
     967                        } catch (Exception e) {
     968                                reader = new BufferedReader(new FileReader(path
     969                                                + frameset.toLowerCase() + File.separator
     970                                                + frameset.toLowerCase() + ".inf"));
     971                        }
     972                        String inf = reader.readLine();
     973                        reader.close();
     974
     975                        int next = Conversion.getFrameNumber(inf);
     976                        // update INF file
     977                        if (update) {
     978                                try {
     979                                        WriteINF(path, frameset, frameset + (next + 1));
     980                                } catch (IOException ioe) {
     981                                        ioe.printStackTrace();
     982                                        Logger.Log(ioe);
     983                                }
     984                        }
     985                        return next;
    957986                } catch (Exception e) {
    958                         reader = new BufferedReader(new FileReader(path
    959                                         + frameset.toLowerCase() + File.separator
    960                                         + frameset.toLowerCase() + ".inf"));
    961                 }
    962                 String inf = reader.readLine();
    963                 reader.close();
    964 
    965                 return Conversion.getFrameNumber(inf);
     987                }
     988
     989                // Check peers
     990                return FrameShare.getInstance().getInfNumber(path, frameset, update);
    966991        }
    967992
     
    9751000         *             Any exception encountered by the BufferedWriter.
    9761001         */
    977         private static void WriteINF(String path, String frameset, String frameName)
     1002        public static void WriteINF(String path, String frameset, String frameName)
    9781003                        throws IOException {
    979                 assert (!frameset.endsWith("."));
    980 
    981                 path += frameset.toLowerCase() + File.separator + INF_FILENAME;
    982 
    983                 BufferedWriter writer = new BufferedWriter(new FileWriter(path));
    984                 writer.write(frameName);
    985                 writer.close();
     1004                try {
     1005                        assert (!frameset.endsWith("."));
     1006
     1007                        path += frameset.toLowerCase() + File.separator + INF_FILENAME;
     1008
     1009                        BufferedWriter writer = new BufferedWriter(new FileWriter(path));
     1010                        writer.write(frameName);
     1011                        writer.close();
     1012                } catch (Exception e) {
     1013
     1014                }
    9861015        }
    9871016
     
    10901119
    10911120                try {
    1092                         num = ReadINF(zero.getPath(), frameset);
     1121                        num = ReadINF(zero.getPath(), frameset, false);
    10931122                } catch (IOException e) {
    10941123                        // TODO Auto-generated catch block
     
    13681397                                try {
    13691398                                        nextNum = ReadINF(PUBLIC_PATH, Conversion
    1370                                                         .getFramesetName(frameName)) + 1;
     1399                                                        .getFramesetName(frameName), false) + 1;
    13711400                                } catch (IOException e) {
    13721401                                        e.printStackTrace();
     
    13991428                                                "Your version was renamed " + newName, peerName);
    14001429                        }
    1401 
    1402                         // Save the new version
    1403                         try {
    1404                                 FileWriter fw = new FileWriter(file);
    1405                                 String nextLine = null;
    1406                                 while ((nextLine = packetContents.readLine()) != null) {
    1407                                         fw.write(nextLine + '\n');
    1408                                 }
    1409                                 fw.flush();
    1410                                 fw.close();
    1411                                 MessageBay.displayMessage("Saved remote frame: " + frameName);
    1412                         } catch (IOException e) {
    1413                                 e.printStackTrace();
    1414                         }
    1415                 } else {
    1416                         MessageBay
    1417                                         .errorMessage("Recieved request for unknown public frame: "
    1418                                                         + frameName);
    1419                 }
     1430                }
     1431
     1432                // Save the new version
     1433                try {
     1434                        FileWriter fw = new FileWriter(file);
     1435                        String nextLine = null;
     1436                        while ((nextLine = packetContents.readLine()) != null) {
     1437                                fw.write(nextLine + '\n');
     1438                        }
     1439                        fw.flush();
     1440                        fw.close();
     1441                        MessageBay.displayMessage("Saved remote frame: " + frameName);
     1442                } catch (IOException e) {
     1443                        MessageBay.errorMessage("Error remote saving " + frameName + ": "
     1444                                        + e.getMessage());
     1445                        e.printStackTrace();
     1446                }
     1447                // } else {
     1448                //                     
     1449                //                     
     1450                //                     
     1451                // MessageBay
     1452                // .errorMessage("Recieved save request for unknown public frame: "
     1453                // + frameName);
     1454                // }
    14201455        }
    14211456
Note: See TracChangeset for help on using the changeset viewer.