Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

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

    r919 r1102  
    2626
    2727import org.expeditee.gui.AttributeValuePair;
    28 import org.expeditee.gui.DisplayIO;
    2928import org.expeditee.gui.Frame;
    3029import org.expeditee.gui.FrameCreator;
     
    3231import org.expeditee.gui.FrameUtils;
    3332import org.expeditee.gui.MessageBay;
    34 import org.expeditee.items.Item;
    3533import org.expeditee.items.Text;
    3634import org.expeditee.items.widgets.Password;
     
    5654                        // populate map of settings
    5755                        for(Field f : clazz.getFields()) {
    58                                 // only allow valid types
    59                                 if(! Setting.class.isAssignableFrom(f.getType())) {
    60                                         continue;
    61                                 }
     56                                // Only allow classes that inherit from Setting
     57                                if(!Setting.class.isAssignableFrom(f.getType())) continue;
     58                               
    6259                                try {
    6360                                        Setting s = (Setting) f.get(null);
    6461                        settings.put(f.getName().toLowerCase(), s);
    65                         if(s instanceof VariableSetting) {
    66                                 settingsList.add((VariableSetting) s);
    67                         }
     62                        if (s instanceof VariableSetting) settingsList.add((VariableSetting) s);
    6863                        orderedEntries.add(f.getName());
    6964                } catch (Exception e) {
     
    7166                }
    7267                        }
     68                       
    7369                        Method m = null;
     70                       
    7471                        try {
    7572                                m = clazz.getMethod("onParsed", Text.class);
     
    7774                                // System.err.println(clazz.getName() + " has no onParsed(Text t) callback");
    7875                        }
     76                       
    7977                        this.onParsed = m;
    8078                }
    8179        }
     80       
    8281        private static HashMap<String, PageDescriptor> _pages = new HashMap<String, PageDescriptor>();
    8382
    8483        private static boolean _init = false;
    85         public static void Init() {
     84       
     85        public static void Init()
     86        {
    8687                if(_init) return;
     88               
    8789                _init = true;
     90               
    8891                try {
    8992                        for(Class<?> clazz : PackageLoader.getClassesNew(SETTINGS_PACKAGE)) {
    9093                                // Ignore this class since it's the controller
    91                                 if(clazz.equals(Settings.class)) {
    92                                         continue;
    93                                 }
    94                                 String settingsPage = clazz.getPackage().getName().toLowerCase().substring(SETTINGS_PACKAGE_PARENT.length());
     94                                if(clazz.equals(Settings.class)) continue;
     95                               
     96                                String settingsPageName = clazz.getPackage().getName().toLowerCase().substring(SETTINGS_PACKAGE_PARENT.length());
    9597                                // System.out.println(settingsPage + " : " + clazz.getName());
    96                                 _pages.put(settingsPage, new PageDescriptor(clazz));
     98                                _pages.put(settingsPageName, new PageDescriptor(clazz));
    9799                        }
    98100
     
    100102                        e.printStackTrace();
    101103                }
    102                 FrameUtils.ParseProfile(FrameIO.LoadProfile(UserSettings.ProfileName.get()));
    103         }
    104        
    105         /**
    106          * Parses the settings tree, then resets any settings that were not set
    107          */
    108         public static void parseSettings(Text text) {
     104        }
     105       
     106        /** Parses the settings tree, then resets any settings that were not set. */
     107        public static void parseSettings(Text text)
     108        {
    109109                List<VariableSetting> set = parseSettings(text, "");
    110110                List<VariableSetting> toDefault = new LinkedList<VariableSetting>();
    111                 for(PageDescriptor pd : _pages.values()) {
    112                         toDefault.addAll(pd.settingsList);
    113                 }
     111               
     112                for(PageDescriptor pd : _pages.values()) toDefault.addAll(pd.settingsList);
     113               
    114114                toDefault.removeAll(set);
     115               
    115116                for(VariableSetting s : toDefault) {
    116117                        try {
    117                                 // System.out.println("Resetting " + s.getTooltip());
    118118                    s.reset();
    119                     // System.out.println("Set " + f.getName() + " to default value " + f.get(null));
    120119            } catch (Exception e) {
    121120                    e.printStackTrace();
     
    135134               
    136135                List<VariableSetting> set = new LinkedList<VariableSetting>();
     136               
    137137                Frame child = text.getChild();
    138                 if(child == null) {
    139                         return set;
    140                 }
     138               
     139                if(child == null) return set;
     140               
    141141                String settingsPage = prefix + text.getText().trim().toLowerCase().replaceAll("^@", "");
    142142                PageDescriptor pd = _pages.get(settingsPage);
    143                 if(pd == null) {
    144                         return set;
    145                 }
     143                if(pd == null) return set;
     144               
    146145                try {
    147146                        // set the fields
     
    160159                                }
    161160                        }
     161                       
    162162                        // parse all the settings items on this page
    163163                        for(Text t : items) {                           
     
    186186                                                        }
    187187                                                }
    188                                                 // System.out.println(s);
    189                                                 if(s == null) {
    190                                                         continue;
    191                                                 }
     188
     189                                                if(s == null) continue;
     190                                               
    192191                                                if(validPages.size() > 1) {
    193192                                                        StringBuffer warnMessage = new StringBuffer("Found multiple matching settings in the following settings subpages: ");
     
    202201                                                }
    203202                                        }
    204                                         if(s.setSetting(t) && s instanceof VariableSetting) {
    205                                                 set.add((VariableSetting) s);
    206                                         }
     203                                       
     204                                        if(s.setSetting(t) && s instanceof VariableSetting) set.add((VariableSetting) s);
     205                                       
    207206                                } catch (Exception e) {
    208207                                        e.printStackTrace();
    209208                                }
    210209                        }
     210                       
    211211                        // call the onParsed method if one exists
    212212                        if(pd.onParsed != null) {
    213213                                pd.onParsed.invoke(null, text);
    214214                        }
     215                       
    215216        } catch (Exception e) {
    216217            e.printStackTrace();
    217218            return set;
    218219        }
     220               
    219221                // if the page was a settings page, check if it has any subpages
    220222                for(Text t : child.getTextItems()) {
     
    224226        }
    225227       
    226         public static void generateSettingsTree(Text link) {
     228        public static void generateSettingsTree(Text link)
     229        {
    227230                generateSettingsTree("settings", link);
    228231        }
    229232       
    230         /**
    231          *
    232          * Generates settings tree
    233          *
    234          */
    235         private static void generateSettingsTree(String page, Text text) {
     233        /** Generates settings tree */
     234        private static void generateSettingsTree(String page, Text text)
     235        {
    236236                FrameCreator frames = new FrameCreator(text.getParentOrCurrentFrame().getFramesetName(), text.getParentOrCurrentFrame().getPath(), page, false, false);
    237237                // Frame frame = FrameIO.CreateFrame(text.getParentOrCurrentFrame().getFramesetName(), page, null);
Note: See TracChangeset for help on using the changeset viewer.