Ignore:
Timestamp:
01/30/19 12:59:15 (5 years ago)
Author:
bln4
Message:

UserSettings.java -> Flag settings to determine if we are authenticated and also the ability to push settings to the settings frameset.

File:
1 edited

Legend:

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

    r1120 r1213  
    2323import java.io.IOException;
    2424import java.util.ArrayList;
     25import java.util.Collection;
    2526import java.util.LinkedList;
    2627import java.util.List;
     
    3334import org.expeditee.gui.FrameUtils;
    3435import org.expeditee.gui.MessageBay;
     36import org.expeditee.items.Item;
    3537import org.expeditee.items.Text;
    3638import org.expeditee.setting.BooleanSetting;
     
    5052public abstract class UserSettings {
    5153       
    52         public final static String DEFAULT_PROFILE_NAME = "default";
     54        public static String DEFAULT_PROFILE_NAME = "default";
    5355       
    5456        public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", 3);
     
    6365                public boolean setSetting(Text text) {
    6466                if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
    65                         text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
     67                        text.setLink(UserSettings.ProfileName.get() + "1");
     68                        //text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
    6669                }
    6770                String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
     
    99102        public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", 150);
    100103       
    101         public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
    102        
    103         public static final StringSetting UserName = new StringSetting("User name", ProfileName.get());
    104        
     104        public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))) {
     105               
     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               
    105135        public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", false);
    106136
     
    112142
    113143        public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", true);
    114        
     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        };
    115158       
    116159        /*
    117160         * Frames
    118161         */
    119        
    120162        public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
    121163
     
    247289                }
    248290        }
     291       
     292        private static void commitToSettingsFrameItem(Object value, String contentMatch) {
     293                String profileName = UserSettings.UserName.get();
     294                int lastNumber = FrameIO.getLastNumber(profileName);
     295                for (int i = 1; i <= lastNumber; i++) {
     296                        Frame frame = FrameIO.LoadFrame(profileName + i);
     297                        if (frame != null) {
     298                                Collection<Item> items = frame.getAllItems();
     299                                boolean found = false;
     300                                for (Item item: items) {
     301                                        if (item.getText().startsWith(contentMatch)) {
     302                                                item.setText(contentMatch + " " + value);
     303                                        }
     304                                }
     305                                if (found) { break; }
     306                        }
     307                }
     308        }
    249309}
Note: See TracChangeset for help on using the changeset viewer.