001 /*
002 * Copyright 2007 - 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: AbstractTokenWithStandardLayout.java,v bc1d5fde7b73 2009/06/01 14:40:54 maxberger $ */
018
019 package net.sourceforge.jeuclid.elements.presentation.token;
020
021 import java.text.AttributedString;
022
023 import net.sourceforge.jeuclid.LayoutContext;
024 import net.sourceforge.jeuclid.elements.support.GraphicsSupport;
025 import net.sourceforge.jeuclid.elements.support.text.StringUtil;
026
027 import org.apache.batik.dom.AbstractDocument;
028
029 /**
030 * Common functionality for all tokens where the text layout is based on the
031 * text content.
032 *
033 * @version $Revision: bc1d5fde7b73 $
034 */
035 public abstract class AbstractTokenWithStandardLayout extends
036 AbstractTokenWithTextLayout {
037
038 /**
039 * Default constructor. Sets MathML Namespace.
040 *
041 * @param qname
042 * Qualified name.
043 * @param odoc
044 * Owner Document.
045 */
046 public AbstractTokenWithStandardLayout(final String qname,
047 final AbstractDocument odoc) {
048 super(qname, odoc);
049 }
050
051 /** {@inheritDoc} */
052 @Override
053 protected AttributedString textContentAsAttributedString(
054 final LayoutContext now) {
055 return StringUtil.convertStringtoAttributedString(this.getText(), this
056 .getMathvariantAsVariant(), GraphicsSupport
057 .getFontsizeInPoint(now), now);
058 }
059
060 /** {@inheritDoc} */
061 @Override
062 protected boolean isEmpty() {
063 return this.getText().length() == 0;
064 }
065
066 }