001 /*
002 * Copyright 2002 - 2007 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: StyleAttributeLayoutContext.java,v 8afef6dd0d58 2007/09/14 08:29:58 maxberger $ */
018
019 package net.sourceforge.jeuclid.context;
020
021 import java.awt.Color;
022
023 import net.sourceforge.jeuclid.LayoutContext;
024 import net.sourceforge.jeuclid.elements.support.attributes.AttributesHelper;
025
026 /**
027 * @version $Revision: 8afef6dd0d58 $
028 */
029 public class StyleAttributeLayoutContext implements LayoutContext {
030
031 private final LayoutContext parentLayoutContext;
032
033 private final String sizeString;
034
035 private final Color foregroundColor;
036
037 /**
038 * Default Constructor.
039 *
040 * @param parent
041 * LayoutContext of parent.
042 * @param msize
043 * msize String to apply to parent context.
044 * @param foreground
045 * Foreground color for new context.
046 */
047 public StyleAttributeLayoutContext(final LayoutContext parent,
048 final String msize, final Color foreground) {
049 this.parentLayoutContext = parent;
050 this.sizeString = msize;
051 this.foregroundColor = foreground;
052 }
053
054 /** {@inheritDoc} */
055 public Object getParameter(final Parameter which) {
056 final Object retVal;
057 if (Parameter.MATHSIZE.equals(which) && (this.sizeString != null)) {
058 retVal = AttributesHelper.convertSizeToPt(this.sizeString,
059 this.parentLayoutContext, AttributesHelper.PT);
060 } else if (Parameter.MATHCOLOR.equals(which)
061 && this.foregroundColor != null) {
062 retVal = this.foregroundColor;
063 } else {
064 retVal = this.parentLayoutContext.getParameter(which);
065 }
066 return retVal;
067 }
068 }