Coverage Report - net.sourceforge.jeuclid.context.LayoutContextImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
LayoutContextImpl
98%
98/100
50%
2/4
1,429
LayoutContextImpl$SingletonHolder
50%
2/4
N/A
1,429
 
 1  
 /*
 2  
  * Copyright 2002 - 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: LayoutContextImpl.java,v 896e3a9ebb36 2008/11/28 13:39:06 maxberger $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.context;
 20  
 
 21  
 import java.awt.Color;
 22  
 import java.io.Serializable;
 23  
 import java.util.ArrayList;
 24  
 import java.util.Collections;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 import java.util.TreeMap;
 28  
 
 29  
 import net.sourceforge.jeuclid.Constants;
 30  
 import net.sourceforge.jeuclid.LayoutContext;
 31  
 import net.sourceforge.jeuclid.MutableLayoutContext;
 32  
 
 33  
 /**
 34  
  * @version $Revision: 896e3a9ebb36 $
 35  
  */
 36  
 public class LayoutContextImpl implements MutableLayoutContext, Serializable {
 37  
 
 38  
     /**
 39  
      * 
 40  
      */
 41  
     private static final long serialVersionUID = 1L;
 42  
 
 43  3766
     private static final class SingletonHolder {
 44  209
         private static final LayoutContextImpl INSTANCE = new LayoutContextImpl();
 45  
 
 46  0
         private SingletonHolder() {
 47  0
         }
 48  
     }
 49  
 
 50  
     private final Map<Parameter, Object> context;
 51  
 
 52  
     // CHECKSTYLE:OFF
 53  
     /**
 54  
      * Default constructor.
 55  
      */
 56  209
     protected LayoutContextImpl() {
 57  209
         this.context = new TreeMap<Parameter, Object>();
 58  209
         this.context.put(Parameter.MATHSIZE, Constants.DEFAULT_FONTSIZE);
 59  209
         this.context.put(Parameter.SCRIPTMINSIZE, 8f);
 60  209
         this.context.put(Parameter.ANTIALIAS_MINSIZE, 10f);
 61  209
         this.context.put(Parameter.SCRIPTSIZEMULTIPLIER,
 62  
                 Constants.DEFAULT_SCIPTSIZEMULTIPLIER);
 63  209
         this.context.put(Parameter.SCRIPTLEVEL, 0);
 64  209
         this.context.put(Parameter.DISPLAY, Display.BLOCK);
 65  209
         this.context.put(Parameter.DEBUG, false);
 66  209
         this.context.put(Parameter.ANTIALIAS, true);
 67  209
         this.context.put(Parameter.MATHCOLOR, Color.BLACK);
 68  209
         this.context.put(Parameter.MATHBACKGROUND, null);
 69  
 
 70  209
         final List<String> fontsSanserif = new ArrayList<String>(12);
 71  209
         fontsSanserif.add("Verdana");
 72  209
         fontsSanserif.add("Helvetica");
 73  209
         fontsSanserif.add("Arial");
 74  209
         fontsSanserif.add("Arial Unicode MS");
 75  209
         fontsSanserif.add("Lucida Sans Unicode");
 76  209
         fontsSanserif.add("Lucida Sans");
 77  209
         fontsSanserif.add("Lucida Grande");
 78  209
         fontsSanserif.add("DejaVu Sans");
 79  209
         fontsSanserif.add("DejaVuSans");
 80  209
         fontsSanserif.add("Bitstream Vera Sans");
 81  209
         fontsSanserif.add("Luxi Sans");
 82  209
         fontsSanserif.add("FreeSans");
 83  209
         fontsSanserif.add("sansserif");
 84  209
         this.context.put(Parameter.FONTS_SANSSERIF, Collections
 85  
                 .unmodifiableList(fontsSanserif));
 86  
 
 87  209
         final List<String> fontsSerif = new ArrayList<String>(10);
 88  209
         fontsSerif.add("Constantina");
 89  209
         fontsSerif.add("Cambria");
 90  209
         fontsSerif.add("Times");
 91  209
         fontsSerif.add("Times New Roman");
 92  209
         fontsSerif.add("Lucida Bright");
 93  209
         fontsSerif.add("DejaVu Serif");
 94  209
         fontsSerif.add("DejaVuSerif");
 95  209
         fontsSerif.add("Bitstream Vera Serif");
 96  209
         fontsSerif.add("Luxi Serif");
 97  209
         fontsSerif.add("FreeSerif");
 98  209
         fontsSerif.add("serif");
 99  209
         this.context.put(Parameter.FONTS_SERIF, Collections
 100  
                 .unmodifiableList(fontsSerif));
 101  
 
 102  209
         final List<String> fontsMonospaced = new ArrayList<String>(10);
 103  209
         fontsMonospaced.add("Andale Mono");
 104  209
         fontsMonospaced.add("Courier");
 105  209
         fontsMonospaced.add("Courier Mono");
 106  209
         fontsMonospaced.add("Courier New");
 107  209
         fontsMonospaced.add("Lucida Sans Typewriter");
 108  209
         fontsMonospaced.add("DejaVu Sans Mono");
 109  209
         fontsMonospaced.add("DejaVuSansMono");
 110  209
         fontsMonospaced.add("Bitstream Vera Sans Mono");
 111  209
         fontsMonospaced.add("Luxi Mono");
 112  209
         fontsMonospaced.add("FreeMono");
 113  209
         fontsMonospaced.add("monospaced");
 114  209
         this.context.put(Parameter.FONTS_MONOSPACED, Collections
 115  
                 .unmodifiableList(fontsMonospaced));
 116  
 
 117  209
         final List<String> fontsScript = new ArrayList<String>(12);
 118  209
         fontsScript.add("EUSM10");
 119  209
         fontsScript.add("cmsy10");
 120  209
         fontsScript.add("Math5");
 121  209
         fontsScript.add("Mathematica5");
 122  209
         fontsScript.add("Savoye LET");
 123  209
         fontsScript.add("Brush Script MT");
 124  209
         fontsScript.add("Zapfino");
 125  209
         fontsScript.add("Apple Chancery");
 126  209
         fontsScript.add("Edwardian Script ITC");
 127  209
         fontsScript.add("Lucida Handwriting");
 128  209
         fontsScript.add("Monotype Corsiva");
 129  209
         fontsScript.add("Santa Fe LET");
 130  209
         this.context.put(Parameter.FONTS_SCRIPT, Collections
 131  
                 .unmodifiableList(fontsScript));
 132  
 
 133  209
         final List<String> fontsFraktur = new ArrayList<String>(7);
 134  209
         fontsFraktur.add("EUFM10");
 135  209
         fontsFraktur.add("Mathematica6");
 136  209
         fontsFraktur.add("FetteFraktur");
 137  209
         fontsFraktur.add("Fette Fraktur");
 138  209
         fontsFraktur.add("Euclid Fraktur");
 139  209
         fontsFraktur.add("Lucida Blackletter");
 140  209
         fontsFraktur.add("Blackmoor LET");
 141  209
         this.context.put(Parameter.FONTS_FRAKTUR, Collections
 142  
                 .unmodifiableList(fontsFraktur));
 143  
 
 144  209
         final List<String> fontsDoublestruck = new ArrayList<String>(8);
 145  209
         fontsDoublestruck.add("MSBM10");
 146  209
         fontsDoublestruck.add("Mathematica7");
 147  209
         fontsDoublestruck.add("Caslon Open Face");
 148  209
         fontsDoublestruck.add("Caslon Openface");
 149  209
         fontsDoublestruck.add("Cloister Open Face");
 150  209
         fontsDoublestruck.add("Academy Engraved LET");
 151  209
         fontsDoublestruck.add("Colonna MT");
 152  209
         fontsDoublestruck.add("Imprint MT Shadow");
 153  209
         this.context.put(Parameter.FONTS_DOUBLESTRUCK, Collections
 154  
                 .unmodifiableList(fontsDoublestruck));
 155  
 
 156  209
         this.context.put(Parameter.MFRAC_KEEP_SCRIPTLEVEL, Boolean.FALSE);
 157  
         // CHECKSTYLE:ON
 158  209
     }
 159  
 
 160  
     /**
 161  
      * Default Constructor.
 162  
      * 
 163  
      * @param copyFromContext
 164  
      *            LayoutContext to use for initialization of values
 165  
      */
 166  2094
     public LayoutContextImpl(final LayoutContext copyFromContext) {
 167  
 
 168  2094
         if (copyFromContext instanceof LayoutContextImpl) {
 169  2094
             this.context = new TreeMap<Parameter, Object>(
 170  
                     ((LayoutContextImpl) copyFromContext).getParameters());
 171  
         } else {
 172  0
             throw new UnsupportedOperationException("LayoutContextImpl("
 173  
                     + copyFromContext.getClass() + ") not supported.");
 174  
         }
 175  2094
     }
 176  
 
 177  
     /**
 178  
      * Retrieve the default layout context.
 179  
      * 
 180  
      * @return the default layout context.
 181  
      */
 182  
     public static LayoutContext getDefaultLayoutContext() {
 183  3766
         return LayoutContextImpl.SingletonHolder.INSTANCE;
 184  
     }
 185  
 
 186  
     /** {@inheritDoc} */
 187  
     public LayoutContext setParameter(final Parameter which,
 188  
             final Object newValue) {
 189  1881
         if (which.valid(newValue)) {
 190  1881
             this.context.put(which, newValue);
 191  
         } else {
 192  0
             this.context.put(which, which.fromString(newValue.toString()));
 193  
         }
 194  1881
         return this;
 195  
     }
 196  
 
 197  
     /** {@inheritDoc} */
 198  
     public Object getParameter(final Parameter which) {
 199  753955
         return this.context.get(which);
 200  
     }
 201  
 
 202  
     /**
 203  
      * Retrieve all parameters set for this LayoutContext. Please note: The
 204  
      * returned map should be treated as read-only.
 205  
      * 
 206  
      * @return all Parameters in this context.
 207  
      */
 208  
     private Map<Parameter, Object> getParameters() {
 209  2094
         return Collections.unmodifiableMap(this.context);
 210  
     }
 211  
 }