Changeset 775


Ignore:
Timestamp:
01/29/14 10:05:47 (10 years ago)
Author:
jts21
Message:

Modify CreateDefaultProfile() so it only creates a new profile when generating the actual default profile, for all other profiles it just copies the default profile and updates links + username

File:
1 edited

Legend:

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

    r770 r775  
    22
    33import java.awt.Color;
    4 import java.awt.Font;
    54import java.awt.Point;
    65import java.awt.Polygon;
     
    14041403            title.setText("Default Profile Frame");
    14051404        } else {
    1406             title.setText(username + "'s Profile Frame");
     1405            // if this profile is not the default profile, copy it from the default profile instead of generating a new profile
     1406                // (this allows the possibility of modifying the default profile and having any new profiles get those modifications)
     1407                Frame nextDefault = FrameIO.LoadProfile(UserSettings.DEFAULT_PROFILE_NAME);
     1408                if (nextDefault == null) {
     1409                        try {
     1410                                nextDefault = FrameIO.CreateNewProfile(UserSettings.DEFAULT_PROFILE_NAME);
     1411                        } catch (Exception e) {
     1412                                // TODO tell the user that there was a problem creating the
     1413                                // profile frame and close nicely
     1414                                e.printStackTrace();
     1415                        }
     1416                }
     1417                // load profile frame and set title correctly
     1418                profile.reset();
     1419                profile.removeAllItems(profile.getAllItems());
     1420                // set relative link on all items so their links will correctly point to the page on the current profile rather than on the default profile
     1421                for(Item i : nextDefault.getAllItems()) {
     1422                        i.setRelativeLink();
     1423                }
     1424                profile.addAllItems(ItemUtils.CopyItems(nextDefault.getAllItems()));
     1425                profile.setTitle(username + "'s Profile Frame");
     1426                FrameIO.SaveFrame(profile);
     1427               
     1428                Frame nextProfile = profile;
     1429                MessageBay.suppressMessages(true);
     1430                while((nextDefault = FrameIO.LoadNext(nextDefault)) != null) {
     1431                        // in case there are gaps in the frame numbering of the default profile (e.g. if a user has edited it),
     1432                        // we need to replicate those gaps in the copied profile so the links will work correctly
     1433                        while(nextProfile.getNumber() < nextDefault.getNumber()) {
     1434                                nextProfile = FrameIO.CreateFrame(profile.getFramesetName(), null, null);
     1435                        }
     1436                        // if the new profile has a frame number higher than the current frame number in the default profile,
     1437                        // the new profile must already exist, so just exit
     1438                        // (TODO: should we wipe the frames instead?)
     1439                        if(nextProfile.getNumber() > nextDefault.getNumber()) {
     1440                                break;
     1441                        }
     1442                        nextProfile.reset();
     1443                nextProfile.removeAllItems(nextProfile.getAllItems());
     1444                // set relative link on all items so their links will correctly point to the page on the current profile rather than on the default profile
     1445                for(Item i : nextDefault.getAllItems()) {
     1446                        i.setRelativeLink();
     1447                }
     1448                nextProfile.addAllItems(ItemUtils.CopyItems(nextDefault.getAllItems()));
     1449                FrameIO.SaveFrame(nextProfile);
     1450                }
     1451                MessageBay.suppressMessages(false);
     1452               
     1453                return;
    14071454        }
    14081455
Note: See TracChangeset for help on using the changeset viewer.