Coverage Report - net.sourceforge.jeuclid.context.Parameter
 
Classes in this File Line Coverage Branch Coverage Complexity
Parameter
93%
28/30
100%
6/6
1,286
 
 1  
 /*
 2  
  * Copyright 2008 - 2008 JEuclid, http://jeuclid.sf.net
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 /* $Id: Parameter.java,v 03dc0884e86f 2008/06/21 10:53:35 maxberger $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.context;
 20  
 
 21  
 import net.sourceforge.jeuclid.context.typewrapper.BooleanTypeWrapper;
 22  
 import net.sourceforge.jeuclid.context.typewrapper.ColorTypeWrapper;
 23  
 import net.sourceforge.jeuclid.context.typewrapper.EnumTypeWrapper;
 24  
 import net.sourceforge.jeuclid.context.typewrapper.NumberTypeWrapper;
 25  
 import net.sourceforge.jeuclid.context.typewrapper.TLIListTypeWrapper;
 26  
 import net.sourceforge.jeuclid.context.typewrapper.TypeWrapper;
 27  
 
 28  
 /**
 29  
  * Possible parameters for the LayoutContext.
 30  
  * 
 31  
  * @version $Revision: 03dc0884e86f $
 32  
  */
 33  209
 public enum Parameter {
 34  
     /**
 35  
      * Display style (Display).
 36  
      */
 37  209
     DISPLAY(EnumTypeWrapper.getInstance(Display.class), false, "display",
 38  
             "display style"),
 39  
 
 40  
     /**
 41  
      * Font size (Float) used for the output. Defaults to 12.0pt. Please Note:
 42  
      * You may also want to set SCRIPTMINZISE.
 43  
      */
 44  209
     MATHSIZE(NumberTypeWrapper.getInstance(Float.class), false, "fontSize",
 45  
             "font size used for the output (mathsize)"),
 46  
 
 47  
     /**
 48  
      * Font size (Float) for smallest script used. Defaults to 8.0pt.
 49  
      */
 50  209
     SCRIPTMINSIZE(NumberTypeWrapper.getInstance(Float.class), false,
 51  
             "scriptMinSize", "font size to be used for smallest script"),
 52  
 
 53  
     /** Script size multiplier (Float), defaults to 0.71. */
 54  209
     SCRIPTSIZEMULTIPLIER(NumberTypeWrapper.getInstance(Float.class), false,
 55  
             "scriptSizeMult", "script size multiplier"),
 56  
 
 57  
     /** Script level (Integer), defaults to 0. */
 58  209
     SCRIPTLEVEL(NumberTypeWrapper.getInstance(Integer.class), false,
 59  
             "scriptLevel", "script level"),
 60  
 
 61  
     /**
 62  
      * Minimum font size for which anti-alias is turned on. Defaults to 10.0pt
 63  
      */
 64  209
     ANTIALIAS_MINSIZE(NumberTypeWrapper.getInstance(Float.class), false,
 65  
             "antiAliasMinSize",
 66  
             "minimum font size for which anti-alias is turned on"),
 67  
 
 68  
     /**
 69  
      * Debug mode (Boolean). If true, elements will have borders drawn around
 70  
      * them.
 71  
      */
 72  209
     DEBUG(BooleanTypeWrapper.getInstance(), false, "debug",
 73  
             "debug mode - if on, elements will have borders drawn around them"),
 74  
 
 75  
     /**
 76  
      * Anti-Alias mode (Boolean) for rendering.
 77  
      */
 78  209
     ANTIALIAS(BooleanTypeWrapper.getInstance(), false, "antiAlias",
 79  
             "anti-alias mode"),
 80  
 
 81  
     /**
 82  
      * Default foreground color (Color). See 3.2.2.2
 83  
      */
 84  209
     MATHCOLOR(ColorTypeWrapper.getInstance(), false, "foregroundColor",
 85  
             "default foreground color (mathcolor)"),
 86  
 
 87  
     /**
 88  
      * Default background color (Color), may be null. See 3.2.2.2
 89  
      */
 90  209
     MATHBACKGROUND(ColorTypeWrapper.getInstance(), true, "backgroundColor",
 91  
             "default background color (mathbackground)"),
 92  
 
 93  
     /**
 94  
      * List<String> of font families for sans-serif.
 95  
      * 
 96  
      * @see Parameter
 97  
      */
 98  209
     FONTS_SANSSERIF(TLIListTypeWrapper.getInstance(), false,
 99  
             "fontsSansSerif", "list of font families for Sans-Serif"),
 100  
 
 101  
     /**
 102  
      * List<String> of font families for serif.
 103  
      * 
 104  
      * @see Parameter
 105  
      */
 106  209
     FONTS_SERIF(TLIListTypeWrapper.getInstance(), false, "fontsSerif",
 107  
             "list of font families for Serif"),
 108  
 
 109  
     /**
 110  
      * List<String> of font families for monospaced.
 111  
      * 
 112  
      * @see Parameter
 113  
      */
 114  209
     FONTS_MONOSPACED(TLIListTypeWrapper.getInstance(), false,
 115  
             "fontsMonospaced", "list of font families for Monospaced"),
 116  
 
 117  
     /**
 118  
      * CList<String> of font families for script.
 119  
      * 
 120  
      * @see Parameter
 121  
      */
 122  209
     FONTS_SCRIPT(TLIListTypeWrapper.getInstance(), false, "fontsScript",
 123  
 
 124  
     "list of font families for Script"),
 125  
     /**
 126  
      * List<String> of font families for fraktur.
 127  
      * 
 128  
      * @see Parameter
 129  
      */
 130  209
     FONTS_FRAKTUR(TLIListTypeWrapper.getInstance(), false, "fontsFraktur",
 131  
             "list of font families for Fraktur"),
 132  
 
 133  
     /**
 134  
      * List<String> of font families for double-struck.
 135  
      * 
 136  
      * @see Parameter
 137  
      */
 138  209
     FONTS_DOUBLESTRUCK(TLIListTypeWrapper.getInstance(), false,
 139  
             "fontsDoublestruck", "list of font families for Double-Struck"),
 140  
 
 141  
     /**
 142  
      * If true, <mfrac> element will NEVER increase children's
 143  
      * scriptlevel (in violation of the spec); otherwise it will behave with
 144  
      * accordance to the spec.
 145  
      */
 146  209
     MFRAC_KEEP_SCRIPTLEVEL(
 147  
             BooleanTypeWrapper.getInstance(),
 148  
             false,
 149  
             "mfracKeepScriptLevel",
 150  
             "if true, <mfrac> element will NEVER increase children's scriptlevel (in violation of the spec)");
 151  
 
 152  
     private final TypeWrapper typeWrapper;
 153  
 
 154  
     private final boolean nullAllowed;
 155  
 
 156  
     private final String optionName;
 157  
 
 158  
     private final String optionDesc;
 159  
 
 160  
     private Parameter(final TypeWrapper aTypeWrapper,
 161  
             final boolean nullIsAllowed, final String oName,
 162  3553
             final String oDesc) {
 163  3553
         this.typeWrapper = aTypeWrapper;
 164  3553
         this.nullAllowed = nullIsAllowed;
 165  3553
         this.optionName = oName;
 166  3553
         this.optionDesc = oDesc;
 167  3553
     }
 168  
 
 169  
     /**
 170  
      * @return TypeWrapper instance used for this parameter
 171  
      */
 172  
     public TypeWrapper getTypeWrapper() {
 173  0
         return this.typeWrapper;
 174  
     }
 175  
 
 176  
     /**
 177  
      * @return user-friendly option name associated with this parameter
 178  
      */
 179  
     public String getOptionName() {
 180  1471086
         return this.optionName;
 181  
     }
 182  
 
 183  
     /**
 184  
      * @return user-friendly option name associated with this parameter
 185  
      */
 186  
     public String getOptionDesc() {
 187  0
         return this.optionDesc;
 188  
     }
 189  
 
 190  
     /**
 191  
      * Checks if the object is of a valid type for this parameter.
 192  
      * 
 193  
      * @param o
 194  
      *            the object to check
 195  
      * @return true if the parameter can be set.
 196  
      */
 197  
     public boolean valid(final Object o) {
 198  4389
         return o == null && this.nullAllowed || this.typeWrapper.valid(o);
 199  
     }
 200  
 
 201  
     /**
 202  
      * Attempts to convert a parameter value expressed as string into an
 203  
      * instance of the appropriate (for this parameter) type.
 204  
      * 
 205  
      * @param value
 206  
      *            parameter value as string
 207  
      * @return parameter value as an instance of the proper type
 208  
      */
 209  
     public Object fromString(final String value) {
 210  3344
         return this.typeWrapper.fromString(value);
 211  
     }
 212  
 
 213  
     /**
 214  
      * Attempts to convert a parameter value expressed as an object of the
 215  
      * appropriate (for this parameter) type into a string representation.
 216  
      * 
 217  
      * @param value
 218  
      *            parameter value as object
 219  
      * @return parameter value as string
 220  
      */
 221  
     public String toString(final Object value) {
 222  2090
         return this.typeWrapper.toString(value);
 223  
     }
 224  
 }