View Javadoc

1   /*
2    * Copyright 2002 - 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: Maction.java 783 2008-06-07 14:12:27Z maxberger $ */
18  
19  package net.sourceforge.jeuclid.elements.presentation.enlivening;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  import net.sourceforge.jeuclid.elements.AbstractElementWithDelegates;
25  import net.sourceforge.jeuclid.layout.LayoutableNode;
26  
27  import org.w3c.dom.Node;
28  import org.w3c.dom.mathml.MathMLActionElement;
29  
30  /**
31   * Represents an maction element.
32   * 
33   * @todo This element does not actually implement any action.
34   * @version $Revision: 783 $
35   */
36  public final class Maction extends AbstractElementWithDelegates implements
37          MathMLActionElement {
38  
39      /**
40       * The XML element from this class.
41       */
42      public static final String ELEMENT = "maction";
43  
44      private static final String ATTR_ACTIONTYPE = "actiontype";
45  
46      private static final String ATTR_SELECTION = "selection";
47  
48      private static final long serialVersionUID = 1L;
49  
50      /**
51       * Creates a math element.
52       */
53      public Maction() {
54          super();
55          this.setDefaultMathAttribute(Maction.ATTR_SELECTION, "1");
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      protected Node newNode() {
61          return new Maction();
62      }
63  
64      /** {@inheritDoc} */
65      public String getActiontype() {
66          return this.getMathAttribute(Maction.ATTR_ACTIONTYPE);
67      }
68  
69      /** {@inheritDoc} */
70      public String getSelection() {
71          return this.getMathAttribute(Maction.ATTR_SELECTION);
72      }
73  
74      /** {@inheritDoc} */
75      public void setActiontype(final String actiontype) {
76          this.setAttribute(Maction.ATTR_ACTIONTYPE, actiontype);
77      }
78  
79      /** {@inheritDoc} */
80      public void setSelection(final String selection) {
81          this.setAttribute(Maction.ATTR_SELECTION, selection);
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      protected List<LayoutableNode> createDelegates() {
87          LayoutableNode selectedElement;
88          try {
89              final int selected = Integer.parseInt(this.getSelection());
90              selectedElement = this.getMathElement(selected - 1);
91          } catch (final NumberFormatException nfe) {
92              selectedElement = null;
93          }
94  
95          if (selectedElement == null) {
96              return Collections.emptyList();
97          } else {
98              return Collections.singletonList(selectedElement);
99          }
100     }
101 
102 }