Logo Search packages:      
Sourcecode: jeuclid version File versions

Mstyle.java

/*
 * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id: Mstyle.java 795 2008-06-21 10:53:35Z maxberger $ */

package net.sourceforge.jeuclid.elements.presentation.general;

import net.sourceforge.jeuclid.LayoutContext;
import net.sourceforge.jeuclid.context.Display;
import net.sourceforge.jeuclid.context.Parameter;
import net.sourceforge.jeuclid.elements.presentation.AbstractContainer;
import net.sourceforge.jeuclid.elements.support.attributes.AttributesHelper;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Node;
import org.w3c.dom.mathml.MathMLStyleElement;

/**
 * This class arrange an element lower to an other element.
 * 
 * @version $Revision: 795 $
 */
00037 public final class Mstyle extends AbstractContainer implements
        MathMLStyleElement {

    /** Attribute for scriptminsize. */
00041     public static final String ATTR_SCRIPTMINSIZE = "scriptminsize";

    /** Attribute for scriptlevel. */
00044     public static final String ATTR_SCRIPTLEVEL = "scriptlevel";

    /** Attribute for scriptsizemultiplier. */
00047     public static final String ATTR_SCRIPTSIZEMULTIPLIER = "scriptsizemultiplier";

    /** Attribute for displaystyle. */
00050     public static final String ATTR_DISPLAYSTYLE = "displaystyle";

    /**
     * The XML element from this class.
     */
00055     public static final String ELEMENT = "mstyle";

    /**
     * Logger for this class
     */
00060     private static final Log LOGGER = LogFactory.getLog(Mstyle.class);

    private static final long serialVersionUID = 1L;

    /**
     * Creates a math element.
     */
00067     public Mstyle() {
        super();
        this.setDefaultMathAttribute(Mstyle.ATTR_DISPLAYSTYLE, "");
    }

    /** {@inheritDoc} */
    @Override
00074     protected Node newNode() {
        return new Mstyle();
    }

    /**
     * @return Script level
     */
00081     public String getScriptlevel() {
        return this.getMathAttribute(Mstyle.ATTR_SCRIPTLEVEL);
    }

    /**
     * @param scriptlevel
     *            script level
     */
00089     public void setScriptlevel(final String scriptlevel) {
        this.setAttribute(Mstyle.ATTR_SCRIPTLEVEL, scriptlevel);
    }

    /**
     * @return Minimum of script size
     */
00096     public String getScriptminsize() {
        return this.getMathAttribute(Mstyle.ATTR_SCRIPTMINSIZE);
    }

    /**
     * @param scriptminsize
     *            Minimum of script size
     */
00104     public void setScriptminsize(final String scriptminsize) {
        this.setAttribute(Mstyle.ATTR_SCRIPTMINSIZE, scriptminsize);
    }

    private class StyleLayoutContext implements LayoutContext {

        private final LayoutContext context;

        protected StyleLayoutContext(final LayoutContext parentContext) {
            this.context = parentContext;
        }

        public Object getParameter(final Parameter which) {
            Object retVal = Mstyle.this.applyLocalAttributesToContext(
                    this.context).getParameter(which);
            if (Parameter.DISPLAY.equals(which)) {
                retVal = this.applyDisplay(retVal);
            } else if (Parameter.SCRIPTLEVEL.equals(which)) {
                retVal = this.applyScriptlevel(retVal);
            } else if (Parameter.SCRIPTMINSIZE.equals(which)) {
                retVal = this.applyScriptMinsize(retVal);
            }
            return retVal;
        }

        private Object applyScriptMinsize(final Object parentLevel) {
            final String newMinsize = Mstyle.this.getScriptminsize();
            if ((newMinsize != null) && (newMinsize.length() > 0)) {
                return AttributesHelper.convertSizeToPt(newMinsize,
                        this.context, AttributesHelper.PT);
            } else {
                return parentLevel;
            }
        }

        private Object applyScriptlevel(final Object parentLevel) {
            Object retVal = parentLevel;
            String attr = Mstyle.this.getScriptlevel();
            if (attr == null) {
                attr = "";
            }
            attr = attr.trim();
            if (attr.length() > 0) {
                final char firstchar = attr.charAt(0);
                boolean relative = false;
                if (firstchar == '+') {
                    relative = true;
                    attr = attr.substring(1);
                } else if (firstchar == '-') {
                    relative = true;
                }
                try {
                    final int iValue = Integer.parseInt(attr);
                    if (relative) {
                        retVal = (Integer) retVal + iValue;
                    } else {
                        retVal = iValue;
                    }
                } catch (final NumberFormatException e) {
                    Mstyle.LOGGER
                            .warn("Error in scriptlevel attribute for mstyle: "
                                    + attr);
                }

            }
            return retVal;
        }

        private Object applyDisplay(final Object parentDisplay) {
            Object retVal = parentDisplay;
            final String displayStyle = Mstyle.this.getDisplaystyle();
            if ("true".equalsIgnoreCase(displayStyle)) {
                retVal = Display.BLOCK;
            }
            if ("false".equalsIgnoreCase(displayStyle)) {
                retVal = Display.INLINE;
            }
            return retVal;
        }
    }

    /** {@inheritDoc} */
    @Override
00187     public LayoutContext getChildLayoutContext(final int childNum,
            final LayoutContext context) {
        return new Mstyle.StyleLayoutContext(context);
    }

    /** {@inheritDoc} */
00193     public String getBackground() {
        return this.getMathbackground();
    }

    /** {@inheritDoc} */
00198     public String getColor() {
        return this.getMathcolor();
    }

    /** {@inheritDoc} */
00203     public String getDisplaystyle() {
        return this.getMathAttribute(Mstyle.ATTR_DISPLAYSTYLE);
    }

    /** {@inheritDoc} */
00208     public String getScriptsizemultiplier() {
        return this.getMathAttribute(Mstyle.ATTR_SCRIPTSIZEMULTIPLIER);
    }

    /** {@inheritDoc} */
00213     public void setBackground(final String background) {
        this.setMathbackground(background);
    }

    /** {@inheritDoc} */
00218     public void setColor(final String color) {
        this.setMathcolor(color);
    }

    /** {@inheritDoc} */
00223     public void setDisplaystyle(final String displaystyle) {
        this.setAttribute(Mstyle.ATTR_DISPLAYSTYLE, displaystyle);
    }

    /** {@inheritDoc} */
00228     public void setScriptsizemultiplier(final String scriptsizemultiplier) {
        this.setAttribute(Mstyle.ATTR_SCRIPTSIZEMULTIPLIER,
                scriptsizemultiplier);
    }

    /** {@inheritDoc} */
00234     public String getMediummathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00240     public String getNegativemediummathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00246     public String getNegativethickmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00252     public String getNegativethinmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00258     public String getNegativeverythickmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00264     public String getNegativeverythinmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00270     public String getNegativeveryverythickmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00276     public String getNegativeveryverythinmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00282     public String getThickmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00288     public String getThinmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00294     public String getVerythickmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00300     public String getVerythinmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00306     public String getVeryverythickmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00312     public String getVeryverythinmathspace() {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00318     public void setMediummathspace(final String mediummathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00324     public void setNegativemediummathspace(
            final String negativemediummathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00331     public void setNegativethickmathspace(final String negativethickmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00337     public void setNegativethinmathspace(final String negativethinmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00343     public void setNegativeverythickmathspace(
            final String negativeverythickmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00350     public void setNegativeverythinmathspace(
            final String negativeverythinmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00357     public void setNegativeveryverythickmathspace(
            final String negativeveryverythickmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00364     public void setNegativeveryverythinmathspace(
            final String negativeveryverythinmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00371     public void setThickmathspace(final String thickmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00377     public void setThinmathspace(final String thinmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00383     public void setVerythickmathspace(final String verythickmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00389     public void setVerythinmathspace(final String verythinmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00395     public void setVeryverythickmathspace(final String veryverythickmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

    /** {@inheritDoc} */
00401     public void setVeryverythinmathspace(final String veryverythinmathspace) {
        throw new UnsupportedOperationException();
        // TODO Auto-generated method stub
    }

}

Generated by  Doxygen 1.6.0   Back to index