View Javadoc

1   /*
2    * Copyright 2007 - 2007 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: AbstractTokenWithStandardLayout.java,v bc1d5fde7b73 2009/06/01 14:40:54 maxberger $ */
18  
19  package net.sourceforge.jeuclid.elements.presentation.token;
20  
21  import java.text.AttributedString;
22  
23  import net.sourceforge.jeuclid.LayoutContext;
24  import net.sourceforge.jeuclid.elements.support.GraphicsSupport;
25  import net.sourceforge.jeuclid.elements.support.text.StringUtil;
26  
27  import org.apache.batik.dom.AbstractDocument;
28  
29  /**
30   * Common functionality for all tokens where the text layout is based on the
31   * text content.
32   * 
33   * @version $Revision: bc1d5fde7b73 $
34   */
35  public abstract class AbstractTokenWithStandardLayout extends
36          AbstractTokenWithTextLayout {
37  
38      /**
39       * Default constructor. Sets MathML Namespace.
40       * 
41       * @param qname
42       *            Qualified name.
43       * @param odoc
44       *            Owner Document.
45       */
46      public AbstractTokenWithStandardLayout(final String qname,
47              final AbstractDocument odoc) {
48          super(qname, odoc);
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      protected AttributedString textContentAsAttributedString(
54              final LayoutContext now) {
55          return StringUtil.convertStringtoAttributedString(this.getText(), this
56                  .getMathvariantAsVariant(), GraphicsSupport
57                  .getFontsizeInPoint(now), now);
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      protected boolean isEmpty() {
63          return this.getText().length() == 0;
64      }
65  
66  }