View Javadoc

1   /*
2   $Id: Constant.java 726 2005-04-05 12:09:09Z guest $
3   */
4   
5   
6   /*
7   Copyright (C) 2001-2002 Mainline Project (I3S - ESSI - CNRS -UNSA)
8   
9   This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13  
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  Lesser General Public License for more details.
18  
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  
23  For further information on the GNU Lesser General Public License,
24  see: http://www.gnu.org/copyleft/lesser.html
25  For further information on this library, contact: mainline@essi.fr
26  */
27  
28  
29  package fr.ove.openmath.jome.model;
30  
31  import fr.ove.openmath.jome.model.FormulaTreeStructure;
32  import fr.ove.openmath.jome.model.events.ModelEvent;
33  import fr.ove.openmath.jome.model.evaluation.*;
34  
35  /***
36  * @author © 2000 DIRAT Laurent
37  * @version 2.1 10/01/2000
38  */
39  public class Constant extends FormulaTreeStructure {
40      /***
41      * The value.
42      */
43      private String value = "";
44  
45      /***
46      * The Constructor.
47      * 
48      */
49      public Constant() {
50          setAsOperatorPriority(resourcesManager.getAsOperatorPriority("constantPriorities"));
51          setAsOperandPriority(resourcesManager.getAsOperandPriority("constantPriorities"));
52      }
53      
54      /***
55      * Inserts the operator instance in the formula tree, from the current insertion position.
56      * (checks the priorities and goes up in the tree if necessary).
57      *
58      * @param ope the current insertion position.
59      * @return the new insertion position.
60      */
61      public FormulaTreeStructure insert(FormulaTreeStructure current) {
62          ModelEvent modelEvent;
63          FormulaTreeStructure father = (FormulaTreeStructure) current.getFather();
64  
65          if ((current.getAsOperatorPriority() == resourcesManager.getAsOperatorPriority("constantPriorities")) &&
66              current.isTemplate()) {
67              // Normalement dans ce cas, current est un template, on le remplace sans Ètat d'?me.
68              father.addChild(this);
69              father.removeChild(current);
70  
71  			/*if(father instanceof Function2 && ! (")".equals(getValue()) || "}".equals(getValue()))) {
72  				VariableOrNumber template = new VariableOrNumber();
73  				father.addChild(template);
74  				return template;
75  			}*/
76  
77              return this;
78          }
79          else { // On est dans le cas de l'insertion courante d'une constante dans la FTS
80              if ((current.getFather() == null) && (current.getNbChildren() == 0)) {
81                  // On est dans ce cas l?, seulement au tout dÈbut de la saisie de la 
82                  // formule. On est obligÈ de faire ce test ? cause de la multiplication
83                  // implicite avec les parenthËses (Ex: (a+b)c ==> (a+b)*c, dans ce cas l?,
84                  // current.getNbChildren() est != de 0)
85                  //On insËre directement ? la position courante
86                  current.addChild(this);
87                  
88                  return this;
89              }
90              else { // On est dans aucun des cas prÈcÈdents, on crÈÈ donc une
91                  // multiplication implicite.
92                  /////current = (new Multiplication()).insert(current);
93                  //FormulaTreeStructure slot = goTo(resourcesManager.getAsOperatorPriority("slotPriorities"));
94                  
95                  /*if(father instanceof Slot){
96                  	current =((Function2)father.getFather()).addElement();
97  					current = insert(current);
98  					return current;
99                  }else*/{
100                 	//current = (new Multiplication()).insert(current);
101 					current = (new HorizentalGroup()).insert(current);                	
102 					current = insert(current);
103 					return current;
104                 }
105                 	
106                 
107             }
108         }
109     }
110     
111     /***
112     * The Creation of the corresponding linear expression of the formula.
113     */
114     public String createLinear(String linear) {
115         return linear + value;
116     }
117 
118     /***
119     * Evaluates the instance.
120     */
121     public String evaluate() {
122         return value;
123     }
124     
125     /***
126     * To check is the instance is an operator.
127     * @return <CODE>true</CODE> if it is an operator. <CODE>false</CODE> otherwise.
128     */
129     public boolean isOperator() {
130         return false;
131     }
132     
133     
134     // *****************************************
135     // ImplÈmentation de l'interface Modifiable
136     
137     /***
138     * Sets the value.
139     */
140     public void setValue(String value) {
141         this.value = value;
142     }
143     
144     /***
145     * Returns the value.
146     */
147     public String getValue() {
148         return value;
149     }
150     
151     // *** Fin de l'interface Modifiable ***
152     // *************************************
153     
154     // *****************************************
155     // ImplÈmentation de l'interface Iconifiable
156     
157     /***
158     * Returns <CODE>true</CODE> if the instance is iconifiable.
159     * <CODE>false</CODE> otherwise.
160     */
161     public boolean isIconifiable() {
162         return false;  // L'instance n'est pas iconifiable
163     }
164     
165     // *** Fin de l'interface Iconifiable ***
166     // **************************************
167 }