Ignore:
Timestamp:
03/15/19 16:48:00 (5 years ago)
Author:
bln4
Message:

Support for new regime in the form of new fields and conditional setting of all paths fields.

Settings are now able to generate their own representation. This allows for the user to explicitly inspect the default values.

When profiles are created, an optional parameter may now be provided. If not null, the new map parameter can contain default values for settings to apply to this profile. This allows for the creation of profiles to that have (for example), their username set to an explicit value. Multiuser mode uses this functionality for usernames and key values among other things.

Frames can now be asked were they are located on the file system. Furthermore, frame indirection is now a thing. Rather than containing data to display, an exp file can contain a line in the format of "REDIRECT:<path>" to go looking for that data. Frames are able to return both their logical (their exp file) and real (the file actually containing the data) paths.

Frames can now store data.

Further fixes to how edits from other users are loaded in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/settings/UserSettings.java

    r1227 r1242  
    2222import java.io.FileNotFoundException;
    2323import java.io.IOException;
     24import java.nio.file.Paths;
    2425import java.util.ArrayList;
    25 import java.util.Collection;
    2626import java.util.LinkedList;
    2727import java.util.List;
     
    3434import org.expeditee.gui.FrameUtils;
    3535import org.expeditee.gui.MessageBay;
    36 import org.expeditee.items.Item;
    3736import org.expeditee.items.Text;
    3837import org.expeditee.setting.BooleanSetting;
     
    5352       
    5453        public static String DEFAULT_PROFILE_NAME = "default";
    55        
    56         public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", 3);
     54         
     55        public static Boolean multiUserMode;
     56       
     57        public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", "Gravity", 3);
    5758       
    5859        public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null);
     
    8283                }
    8384        };
    84         public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", 1024);
    85        
    86         public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", 768);
     85        public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", "InitialWidth", 1024);
     86       
     87        public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", "InitialHeight", 768);
    8788       
    8889        /*
     
    9091         */
    9192       
    92         public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", 1F);
    93        
    94         public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", null);
    95        
    96         public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", null);
    97 
    98         public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", 15);
    99 
    100         public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged before Gestures must be reinterpreted.  E.g. Copy becomes range.", 10);
    101        
    102         public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", 150);
    103        
    104         public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))) {
     93        public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", "ScaleFactor", 1F);
     94       
     95        public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", "FormatSpacingMin", null);
     96       
     97        public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", "FormatSpacingMax", null);
     98
     99        public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", "LineStraightenThreshold", 15);
     100
     101        public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged before Gestures must be reinterpreted.  E.g. Copy becomes range.", "NoOpThreshold", 10);
     102       
     103        public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", "TitlePosition", 150);
     104       
     105        public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
     106       
     107        public static final StringSetting UserName = new StringSetting("User name", ProfileName.get());
    105108               
    106                 /** Commit the change to the appropriate frame */
    107                 public void set(String value) {
    108                         super.set(value);
    109                         commitToSettingsFrameItem(value, "ProfileName:");
    110                 };
    111                
    112                 /** If authenticated, then resetting ProfileName should not do anything. */
    113                 public void reset() {
    114                         if (!Authenticated.get()) {
    115                                 super.reset();
    116                         }
    117                 };
    118         };
    119        
    120         public static final StringSetting UserName = new StringSetting("User name", ProfileName.get()) {
    121                 /** Commit the change to the appropriate frame */
    122                 public void set(String value) {
    123                         super.set(value);
    124                         commitToSettingsFrameItem(value, "UserName:");
    125                 };
    126                
    127                 /** If authenticated, then resetting UserName should not do anything. */
    128                 public void reset() {
    129                         if (!Authenticated.get()) {
    130                                 super.reset();
    131                         }
    132                 };
    133         };
    134                
    135         public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", false);
    136 
    137         public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", false);
    138 
    139         public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", false);
    140 
    141         public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", true);
    142 
    143         public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", true);
    144 
    145         public static final BooleanSetting Authenticated = new BooleanSetting("Whether the current user is authenticated", false) {
    146                 public void set(Boolean value) {
    147                         super.set(value);
    148                         commitToSettingsFrameItem(value, "Authenticated:");
    149                 }
    150                
    151                 // Authenticated must be maintained rather than rely on default value.
    152                 public void reset() {};
    153                
    154                 public boolean setSetting(Text text) {
    155                         return super.setSetting(text);
    156                 };
    157         };
    158        
     109        public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", "AntiAlias", false);
     110
     111        public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", "LineHighlight", false);
     112
     113        public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", "Logging", false);
     114
     115        public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", "LogStats", true);
     116
     117        public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", "Threading", true);
     118
    159119        /*
    160120         * Frames
     
    167127         * Other
    168128         */
    169         public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)") {               
     129        public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)", "Style") {             
    170130                @Override
    171131                public boolean setSetting(Text text) {
     
    196156        };
    197157       
    198         public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary") {
     158        public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary", "SpellChecker") {
    199159                @Override
    200160                public void run() {
     
    208168                }
    209169        };
    210         public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary") {
     170        public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary", "Spelling") {
    211171                @Override
    212172                public void run(Frame frame) {
     
    219179        };
    220180       
    221         public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)") {
     181        public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)", "GreenstoneSettings") {
    222182                @Override
    223183                public void run(Frame frame) {
     
    226186        };
    227187       
    228         public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)") {
     188        public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)", "Reminders") {
    229189                @Override
    230190                public void run(Frame frame) {
     
    233193        };
    234194       
    235         public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)") {
     195        public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)", "MailSettings") {
    236196                @Override
    237197                public void run(Frame frame) {
     
    242202        // add default values
    243203        static {
     204                // Are we in the new regime or the old regime?
     205                File resFile = Paths.get(getDesiredExpediteeHome()).resolve(".res").toFile();
     206                File resourcesPrivateFile = Paths.get(getDesiredExpediteeHome() + "resources-private" + File.separator).toFile();
     207                if (resourcesPrivateFile.exists()) {
     208                        // If resources-private exists than this is a good sign we have new regime available.
     209                        multiUserMode = Boolean.TRUE;
     210                } else if (resFile.exists()) {
     211                        // If we do not, but do have the .res file then this is a good sign we are in old regime.
     212                        multiUserMode = Boolean.FALSE;
     213                } else {
     214                        // If we have neither then we are unpacking and therefore will have new regime available once unpacked.
     215                        multiUserMode = Boolean.TRUE;
     216                }
     217               
    244218                setupDefaultFolders();
    245219        }
    246 
    247         public static void setupDefaultFolders() {
    248                 String expeditee_home = System.getProperty("expeditee.home");
    249                 if (expeditee_home != null) {
    250                     FrameIO.changeParentFolder(expeditee_home + File.separator);
    251                 } else {
    252                     FrameIO.changeParentFolder(getSaveLocation());
    253                 }
     220               
     221        public static void setupDefaultFolders() {             
     222                FrameIO.changeParentFolder(getDesiredExpediteeHome());
    254223         
    255224                FolderSettings.FrameDirs.get().clear();
     
    258227        }
    259228
     229        private static String getDesiredExpediteeHome() {
     230                String homeProperty = System.getProperty("expeditee.home");
     231                String expeditee_home = homeProperty == null ? getSaveLocation() : homeProperty + File.separator;
     232                return expeditee_home;
     233        }
     234
    260235        public static void appendDefaultFolders() {
    261                 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
    262                 FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
    263                 FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
    264                 FolderSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
    265                 FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
    266                 FolderSettings.FrameDirs.get().add(FrameIO.SHARED_BY_ME_FRAMESETS);
    267                 FolderSettings.FrameDirs.get().add(FrameIO.SHARED_WITH_ME_FRAMESETS);
    268                 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
    269                 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
    270                 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
     236                if (multiUserMode) {
     237                        // The comments here explain how things have changed with the new regime.
     238                        // FrameDirs
     239                        // 1. PROFILE_PATH                                      Still points to same place.
     240                        // 2. SHARED_FRAMESETS_PATH                     Still points to same place. (encryption stops just anyone reading it)
     241                        // 3. framesets-<username>                      Generated on user account creation and must be refreshed on user switching.  Also gives access to tutorial stuffs.
     242                        // 4. FRAME_PATH                                        <expeditee-home>\resources-public\framesets.
     243                        // 5. HELP_PUBLIC_PATH                          <expeditee-home>\resources-public\documentation.
     244                        // 6. MESSAGES_PATH                                     Still points to same place.  Should these be per user and encrypted?
     245                        // 7. PUBLIC_PATH                                       Still points to same place.  Kept for compatibility.
     246                        FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
     247                        FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PRIVATE_PATH);
     248                        FolderSettings.FrameDirs.get().add(FrameIO.SHARED_FRAMESETS_PATH);
     249                        FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
     250                        FolderSettings.FrameDirs.get().add(FrameIO.RESOURCES_PATH);
     251                        FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
     252                        FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
     253                        FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
     254                                               
     255                        // ImageDirs
     256                        // 1. resources-<username>\images       Generated on user account creation and must be refreshed on user switching.
     257                        // 2. IMAGES_PATH                                       <expeditee-home>\resources-public\images
     258                        FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PRIVATE_PATH);
     259                        FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
     260                        FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
     261                } else {
     262                        FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
     263                        FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
     264                        FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
     265                        FolderSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
     266                        FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
     267                        FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
     268                        FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
     269                        FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
     270                }
    271271        }
    272272
     
    291291                }
    292292        }
    293        
    294         private static void commitToSettingsFrameItem(Object value, String contentMatch) {
    295                 String profileName = UserSettings.UserName.get();
    296                 int lastNumber = FrameIO.getLastNumber(profileName);
    297                 for (int i = 1; i <= lastNumber; i++) {
    298                         Frame frame = FrameIO.LoadFrame(profileName + i);
    299                         if (frame != null) {
    300                                 Collection<Item> items = frame.getAllItems();
    301                                 boolean found = false;
    302                                 for (Item item: items) {
    303                                         if (item.getText().startsWith(contentMatch)) {
    304                                                 item.setText(contentMatch + " " + value);
    305                                         }
    306                                 }
    307                                 if (found) { break; }
    308                         }
    309                 }
    310         }
    311293}
Note: See TracChangeset for help on using the changeset viewer.