View Javadoc

1   package fr.ove.openmath.jome.model;
2   
3   import java.util.*;
4   import fr.ove.openmath.jome.model.*;
5   import fr.ove.openmath.jome.model.events.ModelEvent;
6   
7   /***
8   * The elements of an Mfd2substitution object.<BR>
9   * It is an operator of arity 2.
10  * <P>
11  * In fact, this object _MUST_ be instanciate by the Mfd2Substitution object, and only by it.
12  * Independently of the Mfd2Substitution object, the instance doesn't make any sense.
13  *
14  * @author © 1999 DIRAT Laurent
15  * @version 2.0 27/10/1999
16  */
17  public class Mfd2SubstitutionElement extends KaryOperator {
18      private boolean gotoVariable = true;
19      private boolean addNewInstance = false;
20      
21      /***
22      * The Constructor.
23      * 
24      */
25      public Mfd2SubstitutionElement() {
26          // le nom du Cd et le nom du symbol sont mis a "" car l'instance ne correspond ? aucun symbol dans
27          // un cd. L'instance est juste un constituant d'un opÈrateur correspondant ? un symbol dans un cd
28          // MÍme remarque en ce qui concerne la forme linÈaire (nom opÈrateur et ending).
29          //super("substElem", "", 2, "", "");
30          setResourceIdentifier("substElem");
31          setTheOperator("");
32          setOperatorArity(2);
33          setEnding("");
34      }
35      
36      /*** 
37      * Inserts the instance in the formula tree structure.<BR>
38      * @param current the position in the formula tree where the operator is to be insert.
39      * @return the new current position int hte formula tree.
40      */
41      public FormulaTreeStructure insert(FormulaTreeStructure current) {
42          // Surcharge car on insËre un template supplÈmentaire pour coller ? l'aritÈ du symbol
43          current = super.insert(current);
44          super.addElement();
45          return current;
46      }
47      
48      /***
49      * Adds a new element (template) to the end of the list.
50      * Returns the new element.
51      */
52      public FormulaTreeStructure addElement() {
53          // surchage car :
54          // * si gotoVariable, le addElement correspond ? se positionner sur le second template
55          // * si addNewInstance, alors Áa veut dire que l'on veut ajouter un autre ÈlÈment (i.e. instance)
56          //   C'est d? au fait que l'instance gËre l'aspet 2n-aire d'un opÈrateur (dont l'instance est un
57          // opÈrande) dont la saisie est la mÍme que pour une opÈrateur n-aire.
58          if (gotoVariable) {
59              gotoVariable = false;
60              addNewInstance = true;
61              return (FormulaTreeStructure) getChild(1).getChild(0);
62          }
63          else if (addNewInstance) {
64              // On veut ajouter un autre Èlement, donc il faut remonter sur le grand-pËre (car en fait
65              // le pËre est un Slot) et ajouter un ÈlÈment au pËre.
66              addNewInstance = false;
67              return ((Mfd2Substitution) getFather().getFather()).addElement();
68          }
69          else
70              return super.addElement(); // normalement ne devrait pas Ítre appelÈ, sinon non respect aritÈ.
71      }
72  
73      /***
74      * The Creation of the corresponding OpenMath object.
75      *
76      * @param OM_Object the OpenMath object.
77      * @param start start point for writing the OpenMath syntax for good presentation/indentation.
78      * @param indent the size of the indentation.
79      * @return the corresponding OpenMath object.
80      *
81      public String createOpenMath(String OM_Object, String start, String indent) {
82          // En fait, l'instance ne sera instanciÈ que par Mfd2Substitution qui ? vraiment un correspondance
83          // avec un objet OM.
84          // Donc surcharge, puisque l'instance n'a pas de CD, et on retourne seulement les objets contenus
85          // succÈssivement.
86          OM_Object = ((FormulaTreeStructure) getChild(0)).createOpenMath(OM_Object, start+indent, indent);
87          OM_Object = ((FormulaTreeStructure) getChild(1)).createOpenMath(OM_Object, start+indent, indent);
88          
89          return OM_Object;
90      }
91      */
92  }