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: Mi.java,v 74b8e95997bf 2010/08/11 17:45:46 max $ */
018    
019    package net.sourceforge.jeuclid.elements.presentation.token;
020    
021    import net.sourceforge.jeuclid.elements.AbstractJEuclidElement;
022    import net.sourceforge.jeuclid.elements.support.text.StringUtil;
023    
024    import org.apache.batik.dom.AbstractDocument;
025    import org.w3c.dom.Node;
026    
027    
028    /**
029     * This class presents a mathematical identifier, like "x".
030     *
031     * @version $Revision: 74b8e95997bf $
032     */
033    public final class Mi extends AbstractTokenWithTextLayout {
034        /**
035         * The XML element from this class.
036         */
037        public static final String ELEMENT = "mi";
038    
039        private static final long serialVersionUID = 1L;
040    
041        /**
042         * Default constructor. Sets MathML Namespace.
043         *
044         * @param qname
045         *            Qualified name.
046         * @param odoc
047         *            Owner Document.
048         */
049        public Mi(final String qname, final AbstractDocument odoc) {
050            super(qname, odoc);
051        }
052    
053        /** {@inheritDoc} */
054        @Override
055        protected Node newNode() {
056            return new Mi(this.nodeName, this.ownerDocument);
057        }
058    
059        /** {@inheritDoc} */
060        @Override
061        public void changeHook() {
062            super.changeHook();
063            if (StringUtil.countDisplayableCharacters(this.getText()) == 1) {
064                this.setDefaultMathAttribute(
065                        AbstractJEuclidElement.ATTR_MATHVARIANT, "italic");
066            } else {
067                this.setDefaultMathAttribute(
068                        AbstractJEuclidElement.ATTR_MATHVARIANT, "normal");
069            }
070        }
071    
072    }