1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
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.apache.batik.dom.AbstractDocument;
28  import org.w3c.dom.Node;
29  import org.w3c.dom.mathml.MathMLActionElement;
30  
31  
32  
33  
34  
35  
36  
37  
38  public final class Maction extends AbstractElementWithDelegates implements
39          MathMLActionElement {
40  
41      
42  
43  
44      public static final String ELEMENT = "maction";
45  
46      private static final String ATTR_ACTIONTYPE = "actiontype";
47  
48      private static final String ATTR_SELECTION = "selection";
49  
50      private static final long serialVersionUID = 1L;
51  
52      
53  
54  
55  
56  
57  
58  
59  
60      public Maction(final String qname, final AbstractDocument odoc) {
61          super(qname, odoc);
62          this.setDefaultMathAttribute(Maction.ATTR_SELECTION, "1");
63      }
64  
65      
66      @Override
67      protected Node newNode() {
68          return new Maction(this.nodeName, this.ownerDocument);
69      }
70  
71      
72      public String getActiontype() {
73          return this.getMathAttribute(Maction.ATTR_ACTIONTYPE);
74      }
75  
76      
77      public String getSelection() {
78          return this.getMathAttribute(Maction.ATTR_SELECTION);
79      }
80  
81      
82      public void setActiontype(final String actiontype) {
83          this.setAttribute(Maction.ATTR_ACTIONTYPE, actiontype);
84      }
85  
86      
87      public void setSelection(final String selection) {
88          this.setAttribute(Maction.ATTR_SELECTION, selection);
89      }
90  
91      
92      @Override
93      protected List<LayoutableNode> createDelegates() {
94          LayoutableNode selectedElement;
95          try {
96              final int selected = Integer.parseInt(this.getSelection());
97              selectedElement = this.getMathElement(selected - 1);
98          } catch (final NumberFormatException nfe) {
99              selectedElement = null;
100         }
101 
102         if (selectedElement == null) {
103             return Collections.emptyList();
104         } else {
105             return Collections.singletonList(selectedElement);
106         }
107     }
108 
109 }