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/Settings.java

    r1121 r1242  
    2222import java.lang.reflect.Method;
    2323import java.util.HashMap;
     24import java.util.Iterator;
    2425import java.util.LinkedList;
    2526import java.util.List;
     
    3233import org.expeditee.items.widgets.Password;
    3334import org.expeditee.reflection.PackageLoader;
    34 import org.expeditee.setting.GenericSetting;
    3535import org.expeditee.setting.Setting;
    3636import org.expeditee.setting.VariableSetting;
     
    229229        }
    230230       
    231         /** Generates settings tree */
    232         private static void generateSettingsTree(String page, Text text)
    233         {
    234                 FrameCreator frames = new FrameCreator(text.getParentOrCurrentFrame().getFramesetName(), text.getParentOrCurrentFrame().getPath(), page, false, false);
    235                 // Frame frame = FrameIO.CreateFrame(text.getParentOrCurrentFrame().getFramesetName(), page, null);
     231        private static void generateSettingsTree(String page, Text text) {
     232                Frame parent = text.getParentOrCurrentFrame();
     233                FrameCreator frames = new FrameCreator(parent.getFramesetName(), parent.getPath(), page, false, false);
    236234                text.setLink(frames.getName());
    237235               
    238                 // add subpages of the current page
    239                 for(String k : _pages.keySet()) {
    240                         if(k.startsWith(page.toLowerCase()) && !k.equals(page)) {
     236                // Add subpages of the current page by recursing
     237                for (String k: _pages.keySet()) {
     238                        if (k.startsWith(page.toLowerCase()) && !k.equals(page)) {
    241239                                String name = k.substring(page.length() + 1);
    242                                 if(name.indexOf('.') != -1) {
     240                                if (name.indexOf('.') != -1) {
    243241                                        continue;
    244242                                }
     
    248246                }
    249247               
     248                // Start building current page
    250249                frames.setLastY(frames.getLastY() + 20);
    251                
    252                 // add settings of the current page
     250                //      Add Settings of the current page
    253251                PageDescriptor pd = _pages.get(page);
    254                 if(pd != null) {
    255                         for(String str : pd.orderedEntries) {
    256                                 String key = str.toLowerCase();
    257                                 Setting s = pd.settings.get(key);
    258                                 if(s == null) {
     252                if (pd == null) {
     253                        frames.save();
     254                        return;
     255                }
     256               
     257               
     258                Iterator<String> keys = pd.orderedEntries.stream().map(t -> t.toLowerCase()).iterator();
     259                while(keys.hasNext()) {
     260                        String key = keys.next();
     261                        Setting setting = pd.settings.get(key);
     262                        if (setting == null) {
     263                                continue;
     264                        }
     265                       
     266                        // Keep track of were we are placing items on Frames.
     267                        int x = 0, y = 0;
     268                       
     269                        if (key.equals("pass")) {
     270                                // Special case for Password widgets
     271                                Text passwordWidgetText = frames.addText("iw: org.expeditee.items.widgets.Passwsord", null, null, null, false);
     272                                Password pw = new Password(passwordWidgetText, null);
     273                                pw.setPassword("");
     274                                frames.getCurrentFrame().removeItem(passwordWidgetText);
     275                                frames.getCurrentFrame().addAllItems(pw.getItems());
     276                                x = passwordWidgetText.getX() + passwordWidgetText.getBoundsWidth();
     277                                y = passwordWidgetText.getY();
     278                        } else {
     279                                // Determine the content for a setting label.
     280                                String name = key.substring(0, 1).toUpperCase() + key.substring(1);
     281                               
     282                                // Construct and add text representation for setting. 
     283                                // If a setting has no initialised value then it is not included.
     284                                Text settingRepresentation = setting.generateRepresentation(name, frames.getCurrentFrame().getFramesetName()).copy();
     285                                if (settingRepresentation.getBounds() == null) {
    259286                                        continue;
    260287                                }
    261                                 String name = str.substring(0, 1).toUpperCase() + str.substring(1);
    262                                 String value = "";
    263                                 if(s instanceof GenericSetting && ((GenericSetting<?>) s).isPrimitive()) {
    264                                         if(((GenericSetting<?>) s).get() != null) {
    265                                                 value = ": " + ((GenericSetting<?>) s).get();
    266                                         } else {
    267                                                 value = ": ";
    268                                         }
    269                                 }
    270                                 int x = 0, y = 0;
    271                                 Text t;
    272                                 if(key.equals("pass")) {
    273                                         t = frames.addText("iw: org.expeditee.items.widgets.Password", null, null, null, false);
    274                                         Password pw = new Password(t, null);
    275                                         pw.setPassword((String) value);
    276                                         frames.getCurrentFrame().removeItem(t);
    277                                         frames.getCurrentFrame().addAllItems(pw.getItems());
    278                                         x = pw.getX() + pw.getWidth();
    279                                         y = pw.getY();
    280                                 } else {
    281                                         if(s instanceof GenericSetting && ((GenericSetting<?>) s).getType().equals(Text.class)) {
    282                                         t = (Text) ((GenericSetting<?>)s).get();
    283                                         if(t == null) {
    284                                                 System.err.println("Failed to get Text setting \"" + str + "\"");
    285                                                 continue;
    286                                         }
    287                                         t = t.copy();
    288                                         t.setID(frames.getCurrentFrame().getNextItemID());
    289                                         t.setText(name);
    290                                         frames.addItem(t, false);
    291                                 } else {
    292                                         t = frames.addText(name + value, null, null, null, false);
    293                                 }
    294                                         x = t.getX() + t.getBoundsWidth();
    295                                         y = t.getY();
    296                                 }
    297                                 x = Math.max(250, x + 20);
    298                                 Text tt = frames.getCurrentFrame().addText(x, y, "// " + s.getTooltip(), null);
    299                                 // rebuild to get the correct height since setWidth() doesn't immediately rebuild
    300                                 tt.rebuild(true);
    301                                 if(tt.getY() + tt.getBoundsHeight() > frames.getLastY()) {
    302                                         frames.setLastY(tt.getY() + tt.getBoundsHeight());
    303                                 }
     288                                settingRepresentation.setID(frames.getCurrentFrame().getNextItemID());
     289                                frames.addItem(settingRepresentation, false);                           
     290                                x = settingRepresentation.getX() + settingRepresentation.getBoundsWidth();
     291                                y = settingRepresentation.getY();
     292                        }
     293                       
     294                        x = Math.max(250, x + 20);
     295                        // Add tooltip for setting
     296                        Text tooltip = frames.getCurrentFrame().addText(x, y, "// " + setting.getTooltip(), null);
     297                        tooltip.rebuild(true);
     298                        if (tooltip.getY() + tooltip.getBoundsHeight() > frames.getLastY()) {
     299                                frames.setLastY(tooltip.getY() + tooltip.getBoundsHeight());
    304300                        }
    305301                }
    306302               
    307303                frames.save();
    308                 //FrameIO.SaveFrame(frame);
    309304        }
    310305}
Note: See TracChangeset for help on using the changeset viewer.