Changeset 666


Ignore:
Timestamp:
01/08/14 12:29:24 (10 years ago)
Author:
jts21
Message:

Tidy up settings (no longer directly using GenericSettings)

Location:
trunk/src/org/expeditee
Files:
5 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/setting/GenericSetting.java

    r656 r666  
    1212 * @param <T> type of the setting
    1313 */
    14 public class GenericSetting<T> extends VariableSetting {
     14public abstract class GenericSetting<T> extends VariableSetting {
    1515
    1616        protected final Class<T> _type;
    17         protected final T _default;
     17        protected T _default;
    1818        protected T _value;
    1919       
     
    3131                _default = value;
    3232                _value = value;
    33                 _hasDefault = true;
    3433        }
    3534       
     
    3938        public GenericSetting(Class<T> type, String tooltip) {
    4039                this(type, tooltip, (T) saneInitialValue(type));
    41                 _hasDefault = false;
    4240        }
    4341       
     
    112110        }
    113111       
     112        public void setDefault(T value) {
     113                _default = value;
     114        }
     115       
    114116        /**
    115117         * Reset the value back to the default, if a default value was specified
    116118         */
    117119        public void reset() {
    118                 if(!_hasDefault) {
    119                         return;
    120                 }
    121                 if(_default instanceof Text) {
    122                         int id = ((Item) _value).getID();
    123                         if(id < 0) {
    124                                 if(((Item) _value).getParentOrCurrentFrame() != null) {
    125                                         id = ((Item) _value).getParentOrCurrentFrame().getNextItemID();
    126                                 } else {
    127                                         id = 0;
    128                                 }
    129                         }
    130                         _value = (T) ((Text) _default).copy();
    131                         ((Item) _value).setID(id);
    132                 } else {
    133                         _value = _default;
    134                 }
     120                _value = _default;
    135121        }
    136122
  • trunk/src/org/expeditee/setting/ListSetting.java

    r655 r666  
    88public abstract class ListSetting<T> extends VariableSetting {
    99
    10         protected final List<T> _default;
     10        protected List<T> _default;
    1111        protected List<T> _value;
    1212       
     
    1515                _default = new LinkedList<T>(value);
    1616                _value = value;
    17                 _hasDefault = true;
    1817        }
    1918       
    2019        public ListSetting(String tooltip) {
    2120                this(tooltip, new LinkedList<T>());
    22                 _hasDefault = false;
    2321        }
    2422       
     
    3331        public abstract boolean setSetting(Text text);
    3432       
     33        public void setDefault(List<T> value) {
     34                _default = new LinkedList<T>(value);
     35        }
     36       
    3537        public void reset() {
    36                 if(!_hasDefault) {
    37                         return;
    38                 }
    39                 _value = _default;
     38                _value = new LinkedList<T>(_default);
    4039        }
    4140
  • trunk/src/org/expeditee/setting/VariableSetting.java

    r655 r666  
    22
    33public abstract class VariableSetting extends Setting {
    4 
    5         protected boolean _hasDefault;
    64       
    75        public VariableSetting(String tooltip) {
     
    97        }
    108       
    11         public boolean hasDefault() {
    12                 return _hasDefault;
    13         }
    14        
    159        public abstract void reset();
    1610
  • trunk/src/org/expeditee/settings/Settings.java

    r658 r666  
    2929                private final HashMap<String, Setting> settings = new HashMap<String, Setting>();
    3030                private final List<String> orderedEntries = new LinkedList<String>();
    31                 private final List<VariableSetting> hasDefault = new LinkedList<VariableSetting>();
     31                private final List<VariableSetting> settingsList = new LinkedList<VariableSetting>();
    3232                private final Method onParsed;
    3333               
     
    4343                                        Setting s = (Setting) f.get(null);
    4444                        settings.put(f.getName().toLowerCase(), s);
    45                         if(s instanceof VariableSetting && ((VariableSetting) s).hasDefault()) {
    46                                 hasDefault.add((VariableSetting) s);
     45                        if(s instanceof VariableSetting) {
     46                                settingsList.add((VariableSetting) s);
    4747                        }
    4848                        orderedEntries.add(f.getName());
     
    108108                                return;
    109109                        }
    110                         List<VariableSetting> toDefault = new LinkedList<VariableSetting>(pd.hasDefault);
     110                        List<VariableSetting> toDefault = new LinkedList<VariableSetting>(pd.settingsList);
    111111                        // set the fields
    112112                        for (Text t : text.getChild().getBodyTextItems(true)) {
  • trunk/src/org/expeditee/settings/UserSettings.java

    r664 r666  
    2222import org.expeditee.items.ItemUtils;
    2323import org.expeditee.items.Text;
     24import org.expeditee.setting.BooleanSetting;
     25import org.expeditee.setting.FloatSetting;
    2426import org.expeditee.setting.FrameSetting;
    2527import org.expeditee.setting.FunctionSetting;
    26 import org.expeditee.setting.GenericSetting;
     28import org.expeditee.setting.IntegerSetting;
    2729import org.expeditee.setting.ListSetting;
    2830import org.expeditee.setting.Setting;
     31import org.expeditee.setting.StringSetting;
     32import org.expeditee.setting.TextSetting;
    2933
    3034/**
     
    4145         */
    4246       
    43         public static final GenericSetting<Float> ScaleFactor = new GenericSetting<Float>(Float.class, "Scale Factor for drawing (TODO: does this even do anything?)", 1F);
    44        
    45         public static final GenericSetting<Float> FormatSpacingMin = new GenericSetting<Float>(Float.class, "Minimum spacing ratio", null);
    46        
    47         public static final GenericSetting<Float> FormatSpacingMax = new GenericSetting<Float>(Float.class, "Maximum spacing ratio", null);
    48        
    49         public static final GenericSetting<Integer> Gravity = new GenericSetting<Integer>(Integer.class, "Distance the cursor has to be from a text item to select the text item", 3);
    50 
    51         public static final GenericSetting<Integer> LineStraightenThreshold = new GenericSetting<Integer>(Integer.class, "Threshold for straightening a line (TODO: does this even do anything?)", 15);
    52 
    53         public static final GenericSetting<Integer> NoOpThreshold = new GenericSetting<Integer>(Integer.class, "Distance the cursor may be dragged while clicking before the operation is cancelled", 60);
    54        
    55         public static final GenericSetting<Integer> TitlePosition = new GenericSetting<Integer>(Integer.class, "Position of title item in frame (TODO: find whether this is x-offset or y-offset)", 150);
    56        
    57         public static final GenericSetting<Integer> InitialWidth = new GenericSetting<Integer>(Integer.class, "Initial width of Expeditee window", 1024);
    58        
    59         public static final GenericSetting<Integer> InitialHeight = new GenericSetting<Integer>(Integer.class, "Initial height of Expeditee window", 768);
    60        
    61         public static final GenericSetting<String> ProfileName = new GenericSetting<String>(String.class, "Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
    62        
    63         public static final GenericSetting<String> UserName = new GenericSetting<String>(String.class, "User name", ProfileName.get());
    64        
    65         public static final GenericSetting<Boolean> AntiAlias = new GenericSetting<Boolean>(Boolean.class, "Whether anti-aliasing should be enabled", false);
    66 
    67         public static final GenericSetting<Boolean> LineHighlight = new GenericSetting<Boolean>(Boolean.class, "Whether lines should be highlighted", false);
    68 
    69         public static final GenericSetting<Boolean> Logging = new GenericSetting<Boolean>(Boolean.class, "Whether logging should be enabled", false);
    70 
    71         public static final GenericSetting<Boolean> LogStats = new GenericSetting<Boolean>(Boolean.class, "Whether stats should be logged", true);
    72 
    73         public static final GenericSetting<Boolean> Threading = new GenericSetting<Boolean>(Boolean.class, "Whether threading should be enabled", true);
     47        public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", 1F);
     48       
     49        public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", null);
     50       
     51        public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", null);
     52       
     53        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 final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", 15);
     56
     57        public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged while clicking before the operation is cancelled", 60);
     58       
     59        public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", 150);
     60       
     61        public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", 1024);
     62       
     63        public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", 768);
     64       
     65        public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
     66       
     67        public static final StringSetting UserName = new StringSetting("User name", ProfileName.get());
     68       
     69        public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", false);
     70
     71        public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", false);
     72
     73        public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", false);
     74
     75        public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", true);
     76
     77        public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", true);
    7478       
    7579       
     
    7781         * Frames
    7882         */
    79         public static final GenericSetting<String> DefaultFrame = new GenericSetting<String>(String.class, "The default frame", null) {
     83        public static final StringSetting DefaultFrame = new StringSetting("The default frame", null) {
    8084                @Override
    8185                public boolean setSetting(Text text) {
     
    8589        };
    8690       
    87         public static final GenericSetting<String> StatisticsFrameset = new GenericSetting<String>(String.class, "The statistics frameset", null);
    88 
    89         public static final GenericSetting<String> MenuFrame = new GenericSetting<String>(String.class, "The menu frame", null);
    90 
    91         public static final GenericSetting<String> HomeFrame = new GenericSetting<String>(String.class, "The home frame", null) {
     91        public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
     92
     93        public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
     94
     95        public static final StringSetting HomeFrame = new StringSetting("The home frame", null) {
    9296                @Override
    9397                public boolean setSetting(Text text) {
     
    180184         *  Templates
    181185         */
    182         public static final GenericSetting<Text> TitleTemplate = new GenericSetting<Text>(Text.class, "Template for Title text item");
    183        
    184         public static final GenericSetting<Text> ItemTemplate = new GenericSetting<Text>(Text.class, "Template for normal text items", new Text("@ItemTemplate")) {
    185                 @Override
    186                 public boolean setSetting(Text text) {
    187                         _value = text.getTemplateForm();
    188                         return true;
    189                 }
    190         };
    191        
    192         public static final GenericSetting<Text> DotTemplate = new GenericSetting<Text>(Text.class, "Template for dot items", new Text("@DotTemplate")) {
    193                 @Override
    194                 public boolean setSetting(Text text) {
    195                         _value = text.getTemplateForm();
    196                         return true;
    197                 }
    198         };
    199 
    200         private static final Text annotationTemplate() {
    201                 Text t = new Text("@AnnotationTemplate");
    202                 t.setColor(Color.gray);
    203                 return t;
    204         }
    205         public static final GenericSetting<Text> AnnotationTemplate = new GenericSetting<Text>(Text.class, "Template for annotation text items", annotationTemplate()) {
    206                 @Override
    207                 public boolean setSetting(Text text) {
    208                         _value = text.getTemplateForm();
    209                         return true;
    210                 }
    211         };
    212 
    213         private static final Text codeCommentTemplate() {
    214                 Text t = new Text("@CommentTemplate");
    215                 t.setColor(Color.green.darker());
    216                 return t;
    217         }
    218         public static final GenericSetting<Text> CodeCommentTemplate = new GenericSetting<Text>(Text.class, "Template for code comment text items", codeCommentTemplate()) {
    219                 @Override
    220                 public boolean setSetting(Text text) {
    221                         _value = text.getTemplateForm();
    222                         return true;
    223                 }
    224         };
    225 
    226         private static final Text statTemplate() {
    227                 Text t = new Text("@StatsTemplate");
    228                 t.setColor(Color.BLACK);
    229                 t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F));
    230                 t.setFamily(Text.MONOSPACED_FONT);
    231                 t.setSize(14);
    232                 return t;
    233         }
    234         public static final GenericSetting<Text> StatTemplate = new GenericSetting<Text>(Text.class, "Template for statistics (e.g. extracted attributes) text items", statTemplate()) {
    235                 @Override
    236                 public boolean setSetting(Text text) {
    237                         _value = text.getTemplateForm();
    238                         return true;
    239                 }
    240         };
    241        
    242         private static final Text tooltipTemplate() {
    243                 Text t = new Text("@StatsTemplate");
    244                 t.setColor(Color.BLACK);
    245                 t.setBackgroundColor(new Color(0.7F, 0.7F, 0.9F));
    246                 // t.setFamily(Text.MONOSPACED_FONT);
    247                 t.setSize(14);
    248                 return t;
    249         }
    250         public static final GenericSetting<Text> TooltipTemplate = new GenericSetting<Text>(Text.class, "Template for tooltips", tooltipTemplate()) {
    251                 @Override
    252                 public boolean setSetting(Text text) {
    253                         _value = text.getTemplateForm();
    254                         return true;
     186        public static final TextSetting TitleTemplate = new TextSetting("Template for Title text item") {
     187                @Override
     188                public Text generateText() {
     189                        return null;
     190                }
     191        };
     192       
     193        public static final TextSetting ItemTemplate = new TextSetting("Template for normal text items") {
     194                @Override
     195                public boolean setSetting(Text text) {
     196                        _value = text.getTemplateForm();
     197                        return true;
     198                }
     199               
     200                @Override
     201                public Text generateText() {
     202                        return new Text("@ItemTemplate");
     203                }
     204        };
     205       
     206        public static final TextSetting DotTemplate = new TextSetting("Template for dot items") {
     207                @Override
     208                public boolean setSetting(Text text) {
     209                        _value = text.getTemplateForm();
     210                        return true;
     211                }
     212               
     213                @Override
     214                public Text generateText() {
     215                        return new Text("@DotTemplate");
     216                }
     217        };
     218
     219        public static final TextSetting AnnotationTemplate = new TextSetting("Template for annotation text items") {
     220                @Override
     221                public boolean setSetting(Text text) {
     222                        _value = text.getTemplateForm();
     223                        return true;
     224                }
     225                @Override
     226                public Text generateText() {
     227                        Text t = new Text("@AnnotationTemplate");
     228                t.setColor(Color.gray);
     229                return t;
     230                }
     231        };
     232
     233        public static final TextSetting CodeCommentTemplate = new TextSetting("Template for code comment text items") {
     234                @Override
     235                public boolean setSetting(Text text) {
     236                        _value = text.getTemplateForm();
     237                        return true;
     238                }
     239                @Override
     240                public Text generateText() {
     241                        Text t = new Text("@CommentTemplate");
     242                t.setColor(Color.green.darker());
     243                return t;
     244                }
     245        };
     246
     247        public static final TextSetting StatTemplate = new TextSetting("Template for statistics (e.g. extracted attributes) text items") {
     248                @Override
     249                public boolean setSetting(Text text) {
     250                        _value = text.getTemplateForm();
     251                        return true;
     252                }
     253                @Override
     254                public Text generateText() {
     255                        Text t = new Text("@StatsTemplate");
     256                t.setColor(Color.BLACK);
     257                t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F));
     258                t.setFamily(Text.MONOSPACED_FONT);
     259                t.setSize(14);
     260                return t;
     261                }
     262        };
     263       
     264        public static final TextSetting TooltipTemplate = new TextSetting("Template for tooltips") {
     265                @Override
     266                public boolean setSetting(Text text) {
     267                        _value = text.getTemplateForm();
     268                        return true;
     269                }
     270                @Override
     271                public Text generateText() {
     272                        Text t = new Text("@StatsTemplate");
     273                t.setColor(Color.BLACK);
     274                t.setBackgroundColor(new Color(0.7F, 0.7F, 0.9F));
     275                // t.setFamily(Text.MONOSPACED_FONT);
     276                t.setSize(14);
     277                return t;
    255278                }
    256279        };
     
    382405                UserSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
    383406                UserSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
     407                UserSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
     408                UserSettings.FrameDirs.setDefault(UserSettings.FrameDirs.get());
    384409                UserSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
    385                 UserSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
     410                UserSettings.ImageDirs.setDefault(UserSettings.ImageDirs.get());
    386411        }
    387412
  • trunk/src/org/expeditee/settings/experimental/ExperimentalFeatures.java

    r655 r666  
    11package org.expeditee.settings.experimental;
    22
    3 import org.expeditee.setting.GenericSetting;
     3import org.expeditee.setting.BooleanSetting;
    44
    55public class ExperimentalFeatures {
    66
    7         public static final GenericSetting<Boolean> AutoWrap = new GenericSetting<Boolean>(Boolean.class, "Enable auto wrapping of text", false);
     7        public static final BooleanSetting AutoWrap = new BooleanSetting("Enable auto wrapping of text", false);
    88       
    9         public static final GenericSetting<Boolean> MousePan = new GenericSetting<Boolean>(Boolean.class, "Enable panning of the frame by shift-click and dragging the mouse", false);
     9        public static final BooleanSetting MousePan = new BooleanSetting("Enable panning of the frame by shift-click and dragging the mouse", false);
    1010       
    1111}
  • trunk/src/org/expeditee/settings/network/NetworkSettings.java

    r655 r666  
    44import org.expeditee.gui.Frame;
    55import org.expeditee.items.Text;
    6 import org.expeditee.network.FrameShare;
    76import org.expeditee.setting.FrameSetting;
    8 import org.expeditee.setting.GenericSetting;
     7import org.expeditee.setting.StringSetting;
    98
    109public abstract class NetworkSettings {
    1110       
    1211        // The URL to prepend to web searches
    13         public static final GenericSetting<String> SearchEngine = new GenericSetting<String>(String.class, "The search engine for the JfxBrowser", "https://duckduckgo.com/?q=");
     12        public static final StringSetting SearchEngine = new StringSetting("The search engine for the JfxBrowser", "https://duckduckgo.com/?q=");
    1413       
    15         public static final GenericSetting<String> HomePage = new GenericSetting<String>(String.class, "The home page for the JfxBrowser", "https://duckduckgo.com");
     14        public static final StringSetting HomePage = new StringSetting("The home page for the JfxBrowser", "https://duckduckgo.com");
    1615       
    1716        public static final FrameSetting FrameShare = new FrameSetting("Enable accessing remote frames") {
  • trunk/src/org/expeditee/settings/network/proxy/ProxySettings.java

    r655 r666  
    99import org.expeditee.items.widgets.WidgetCorner;
    1010import org.expeditee.items.widgets.WidgetEdge;
    11 import org.expeditee.setting.GenericSetting;
     11import org.expeditee.setting.StringSetting;
    1212
    1313public abstract class ProxySettings {
    1414
    15         public static final GenericSetting<String> Host = new GenericSetting<String>(String.class, "The host for the proxy", null);
    16         public static final GenericSetting<String> Port = new GenericSetting<String>(String.class, "The port for the proxy (e.g. port 80)", "80");
    17         public static final GenericSetting<String> User = new GenericSetting<String>(String.class, "Your username for the proxy", null);
    18         public static final GenericSetting<String> Pass = new GenericSetting<String>(String.class, "Your password for the proxy", null);
     15        public static final StringSetting Host = new StringSetting("The host for the proxy", null);
     16        public static final StringSetting Port = new StringSetting("The port for the proxy (e.g. port 80)", "80");
     17        public static final StringSetting User = new StringSetting("Your username for the proxy", null);
     18        public static final StringSetting Pass = new StringSetting("Your password for the proxy", null);
    1919
    2020        public static void onParsed(Text text) {
Note: See TracChangeset for help on using the changeset viewer.