001    /*
002     * Copyright 2008 - 2008 JEuclid, http://jeuclid.sf.net
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    /* $Id: Parameter.java,v 03dc0884e86f 2008/06/21 10:53:35 maxberger $ */
018    
019    package net.sourceforge.jeuclid.context;
020    
021    import net.sourceforge.jeuclid.context.typewrapper.BooleanTypeWrapper;
022    import net.sourceforge.jeuclid.context.typewrapper.ColorTypeWrapper;
023    import net.sourceforge.jeuclid.context.typewrapper.EnumTypeWrapper;
024    import net.sourceforge.jeuclid.context.typewrapper.NumberTypeWrapper;
025    import net.sourceforge.jeuclid.context.typewrapper.TLIListTypeWrapper;
026    import net.sourceforge.jeuclid.context.typewrapper.TypeWrapper;
027    
028    /**
029     * Possible parameters for the LayoutContext.
030     * 
031     * @version $Revision: 03dc0884e86f $
032     */
033    public enum Parameter {
034        /**
035         * Display style (Display).
036         */
037        DISPLAY(EnumTypeWrapper.getInstance(Display.class), false, "display",
038                "display style"),
039    
040        /**
041         * Font size (Float) used for the output. Defaults to 12.0pt. Please Note:
042         * You may also want to set SCRIPTMINZISE.
043         */
044        MATHSIZE(NumberTypeWrapper.getInstance(Float.class), false, "fontSize",
045                "font size used for the output (mathsize)"),
046    
047        /**
048         * Font size (Float) for smallest script used. Defaults to 8.0pt.
049         */
050        SCRIPTMINSIZE(NumberTypeWrapper.getInstance(Float.class), false,
051                "scriptMinSize", "font size to be used for smallest script"),
052    
053        /** Script size multiplier (Float), defaults to 0.71. */
054        SCRIPTSIZEMULTIPLIER(NumberTypeWrapper.getInstance(Float.class), false,
055                "scriptSizeMult", "script size multiplier"),
056    
057        /** Script level (Integer), defaults to 0. */
058        SCRIPTLEVEL(NumberTypeWrapper.getInstance(Integer.class), false,
059                "scriptLevel", "script level"),
060    
061        /**
062         * Minimum font size for which anti-alias is turned on. Defaults to 10.0pt
063         */
064        ANTIALIAS_MINSIZE(NumberTypeWrapper.getInstance(Float.class), false,
065                "antiAliasMinSize",
066                "minimum font size for which anti-alias is turned on"),
067    
068        /**
069         * Debug mode (Boolean). If true, elements will have borders drawn around
070         * them.
071         */
072        DEBUG(BooleanTypeWrapper.getInstance(), false, "debug",
073                "debug mode - if on, elements will have borders drawn around them"),
074    
075        /**
076         * Anti-Alias mode (Boolean) for rendering.
077         */
078        ANTIALIAS(BooleanTypeWrapper.getInstance(), false, "antiAlias",
079                "anti-alias mode"),
080    
081        /**
082         * Default foreground color (Color). See 3.2.2.2
083         */
084        MATHCOLOR(ColorTypeWrapper.getInstance(), false, "foregroundColor",
085                "default foreground color (mathcolor)"),
086    
087        /**
088         * Default background color (Color), may be null. See 3.2.2.2
089         */
090        MATHBACKGROUND(ColorTypeWrapper.getInstance(), true, "backgroundColor",
091                "default background color (mathbackground)"),
092    
093        /**
094         * List<String> of font families for sans-serif.
095         * 
096         * @see Parameter
097         */
098        FONTS_SANSSERIF(TLIListTypeWrapper.getInstance(), false,
099                "fontsSansSerif", "list of font families for Sans-Serif"),
100    
101        /**
102         * List<String> of font families for serif.
103         * 
104         * @see Parameter
105         */
106        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        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        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        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        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        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                final String oDesc) {
163            this.typeWrapper = aTypeWrapper;
164            this.nullAllowed = nullIsAllowed;
165            this.optionName = oName;
166            this.optionDesc = oDesc;
167        }
168    
169        /**
170         * @return TypeWrapper instance used for this parameter
171         */
172        public TypeWrapper getTypeWrapper() {
173            return this.typeWrapper;
174        }
175    
176        /**
177         * @return user-friendly option name associated with this parameter
178         */
179        public String getOptionName() {
180            return this.optionName;
181        }
182    
183        /**
184         * @return user-friendly option name associated with this parameter
185         */
186        public String getOptionDesc() {
187            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            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            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            return this.typeWrapper.toString(value);
223        }
224    }