Ignore:
Timestamp:
05/19/08 12:03:18 (16 years ago)
Author:
ra33
Message:

Fixed a bunch of problems with rectangles and resizing the window, as well as adding some more unit tests etc.

File:
1 edited

Legend:

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

    r64 r67  
    548548        }
    549549
     550        public static void RefreshCasheImages() {
     551                SuspendCache();
     552                for (Frame f : _Cache.values())
     553                        f.setBuffer(null);
     554                ResumeCache();
     555        }
     556
    550557        /**
    551558         * Creates a new frameset using the given name. This includes creating a new
     
    603610        }
    604611
     612        public static String SaveFrame(Frame toSave, boolean inc) {
     613                return SaveFrame(toSave, inc, true);
     614        }
     615
    605616        /**
    606617         * Saves the given Frame to disk in the corresponding frameset directory, if
     
    613624         *            True if the saved frames counter should be incremented, false
    614625         *            otherwise.
    615          */
    616         public static String SaveFrame(Frame toSave, boolean inc) {
     626         * @param checkBackup
     627         *            True if the frame should be checked for the back up tag
     628         */
     629        public static String SaveFrame(Frame toSave, boolean inc,
     630                        boolean checkBackup) {
    617631
    618632                if (toSave == null)
     
    630644                                .getFrameName());
    631645
     646                // Check if the frame exists
     647                if (checkBackup && fullPath == null) {
     648                        // The first time a frame with the backup tag is saved, dont back it
     649                        // up
     650                        checkBackup = false;
     651                }
     652
    632653                FrameWriter writer = null;
     654                int savedVersion;
    633655                try {
    634656                        // if its a new frame or an existing Exp frame...
    635657                        if (fullPath == null || fullPath.endsWith(ExpReader.EXTENTION)) {
    636658                                writer = new ExpWriter();
     659                                savedVersion = ExpReader.getVersion(fullPath);
    637660                        } else {
    638661                                writer = new KMSWriter();
     662                                savedVersion = KMSReader.getVersion(fullPath);
    639663                        }
    640 
    641                         if (toSave.getFrameNumber() > 0
     664                        // Check if we are trying to save an out of date version
     665                        if (savedVersion > toSave.getVersion(false)
     666                                        && !toSave.getFramesetName().equalsIgnoreCase(
     667                                                        FrameGraphics.MESSAGES_FRAMESET_NAME)) {
     668                                // remove this frame from the cache if it is there
     669                                // This will make sure links to the original are set correctly
     670                                _Cache.remove(toSave.getFrameName().toLowerCase());
     671                                int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1;
     672                                SuspendCache();
     673                                Frame original = LoadFrame(toSave.getFrameName());
     674                                toSave.setFrameNumber(nextnum);
     675                                ResumeCache();
     676                                // Put the modified version in the cache
     677                                _Cache.put(toSave.getFrameName().toLowerCase(), toSave);
     678                                // Show the messages alerting the user
     679                                Text originalMessage = new Text(-1);
     680                                originalMessage.setColor(FrameGraphics.ERROR_COLOR);
     681                                originalMessage.setText(original.getFrameName()
     682                                                + " was updated by another user.");
     683                                originalMessage.setLink(original.getFrameName());
     684                                Text yourMessage = new Text(-1);
     685                                yourMessage.setColor(FrameGraphics.ERROR_COLOR);
     686                                yourMessage.setText("Your version was renamed "
     687                                                + toSave.getFrameName());
     688                                yourMessage.setLink(toSave.getFrameName());
     689                                FrameGraphics.DisplayMessage(originalMessage);
     690                                FrameGraphics.DisplayMessage(yourMessage);
     691                        } else if (checkBackup
    642692                                        && ItemUtils.ContainsTag(toSave.getItems(),
    643693                                                        ItemUtils.TAG_BACKUP)) {
     
    649699                                int nextnum = ReadINF(toSave.path, toSave.getFramesetName()) + 1;
    650700
    651                                 original.setFrameNumber(-nextnum);
    652                                 SaveFrame(original, inc);
     701                                // Give it a negative framenumber so that when it is saved the
     702                                // backup tag will be ignored
     703                                original.setFrameNumber(nextnum);
     704                                original.change();
     705                                SaveFrame(original, false, false);
    653706
    654707                                Item i = ItemUtils.FindTag(toSave.getItems(),
     
    657710                                toSave.setFrameNumber(orignum);
    658711                                ResumeCache();
    659                         } else if (toSave.getFrameNumber() < 0) {
    660                                 toSave.setFrameNumber(-toSave.getFrameNumber());
    661712                        }
    662713
     
    10001051                                int copyNumber = 1;
    10011052                                File dest = new File(destPath + File.separator);
    1002                                 //Create the trash folder if it doesnt already exist
     1053                                // Create the trash folder if it doesnt already exist
    10031054                                if (!dest.getParentFile().exists())
    10041055                                        dest.mkdirs();
     
    10061057                                // a number to the end
    10071058                                while (dest.exists()) {
    1008                                         dest = new File(destPath + ++copyNumber + File.separator );
     1059                                        dest = new File(destPath + ++copyNumber + File.separator);
    10091060                                }
    10101061                                return framesetDirectory.renameTo(dest);
Note: See TracChangeset for help on using the changeset viewer.