View Javadoc

1   /*
2   $Id: Function2.java 709 2005-03-21 16:30:05Z 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 java.util.*;
32  import fr.ove.openmath.jome.model.*;
33  import fr.ove.openmath.jome.model.events.*;
34  import fr.ove.openmath.jome.model.evaluation.*;
35  
36  /***
37  * The operator "*", which is the binary multiplication.
38  * (In fact, for implementation needs, we consider it as an n-ary operator)<BR>
39  *
40  * <CODE>Multiplication</CODE> represents a node in the formula tree.
41  * Its children are the operands of the operation.
42  *
43  * @author © 2000 DIRAT Laurent
44  * @version 2.1 10/01/2000
45  */
46  public class Function2 extends Operator {
47  	/***
48  	* The Constructor.
49  	*/
50  	public Function2() {
51  		setResourceIdentifier("FUNCTION2");
52  		setValue("");
53  		setAsOperatorPriority(resourcesManager.getAsOperatorPriority("timesPriorities"));
54  		setAsOperandPriority(resourcesManager.getAsOperandPriority("timesPriorities"));
55  		setAreOperandsMovable(true);
56  	}
57  	
58  	/*** 
59  	* Inserts the instance in the formula tree structure.<BR>
60  	* @param current the position in the formula tree where the operator is to be insert.
61  	* @return the new current position int hte formula tree.
62  	*/
63  	public FormulaTreeStructure insert(FormulaTreeStructure current) {
64  		ModelEvent modelEvent;
65          
66  		if ((current.getFather() == null) && (current.getNbChildren() == 0)) {
67  			// On est dans ce cas l?, seulement au tout dÈbut de la saisie de la 
68  			// formule. On est obligÈ de faire ce test ? cause de la multiplication
69  			// implicite avec les parenthËses (Ex: (a+b)c ==> (a+b)*c, dans ce cas l?,
70  			// current.getNbChildren() est != de 0)
71  			//On insËre directement ? la position courante
72  			current.addChild(this);
73  		} 
74  		else if ((current.getAsOperatorPriority() == resourcesManager.getAsOperatorPriority("constantPriorities")) &&
75  			current.isTemplate()) {
76  			// Le cas classique (on va mÍme dire normal !!!)
77  			// La position d'insertion est un template.
78  			// On doit remplacer le template par l'instance courante
79  			int rank = current.getRank();
80  			FormulaTreeStructure father = (FormulaTreeStructure) current.getFather();
81  			father.addChild(this, rank);
82  			father.removeChild(current);
83  		}
84  		else { // On est dans aucun des cas prÈcÈdents, on crÈÈ donc une
85  			// multiplication implicite.
86  			///current = (new Multiplication()).insert(current);
87  			current = (new HorizentalGroup()).insert(current);
88  			current = insert(current);
89  			return current;
90  		}
91          
92  		// Maintenant, on va rajouter un slot comme ÈlÈment de l'opÈrateur
93  		Slot aSlot = new Slot();
94  		addChild(aSlot);
95  		aSlot.setNextSlot(this);
96          
97  		// ...puis un template comme ÈlÈment de ce slot
98  		VariableOrNumber template = new VariableOrNumber();
99  		aSlot.addChild(template);
100         
101 		return template;
102 
103 
104 
105 
106 /*		VariableOrNumber template;
107 		
108 		current = findLocation(current);
109 
110 		if (current.getAsOperatorPriority() == getAsOperandPriority()) {
111 			// On a dÈj? tapÈ dans la formule un opÈrateur de ce genre, on va donc seulement insÈrer
112 			// un template.
113 			template = new VariableOrNumber();
114 			current.addChild(template);
115             
116 			// On retourne la refÈrence de notre dernier point d'insertion.
117 			return template;
118 		}
119 		else { 
120 			// On est dans le cas o? on commence ? saisir un tel opÈrateur.
121             
122 			// On ajoute l'opÈrateur comme fils ? l'opÈrateur courant
123 			current.addChild(this);
124             
125 			// On teste s'il on est dans le cas o? l'on a dÈj? tapÈ qque chose dans
126 			// la formule. Si non, current est forcÈment de type Formula, par consÈquent
127 			// on est dans le cas particulier o? cela doit produire [?]*[?] puisque
128 			// normalement on ne devrait, dans ce cas l?, pas pouvoir taper de "*"
129 			if ((current.getFather() == null) && (current.getNbChildren() == 1)) {
130 				template = new VariableOrNumber();
131 				addChild(template); // On ajoute le premier template.
132 				return template;
133 			}
134 			else {
135 				FormulaTreeStructure fts = (FormulaTreeStructure) current.getChild(getRank() - 1);
136 				// ? cause des prioritÈs sur les opÈrateurs, on ajoute comme fils l'opÈrateur
137 				// dont le rang est juste infÈrieur ? notre "*"
138 				addChild(fts);
139                 
140 				// on enlËve l'opÈrateur qu'on a fait "descendre", de la liste
141 				// de son prÈcÈdent pËre (son grand pËre maintenant)
142 				current.removeChild(fts);
143 			}
144             
145 			// On ajoute un template ? la multiplication
146 			template = new VariableOrNumber();
147 			addChild(template);
148             
149 			// On retourne la refÈrence de notre dernier point d'insertion.
150 			return template;
151 		}
152 */
153 		
154 		/*
155 		ModelEvent modelEvent;
156 		
157 		current = findLocation(current);
158 
159         
160 		if ((current.getFather() == null) && (current.getNbChildren() == 1)) {
161 			// On est dans ce cas l?, seulement au tout dÈbut de la saisie de la 
162 			// formule. On est obligÈ de faire ce test ? cause de la multiplication
163 			// implicite avec les parenthËses (Ex: (a+b)c ==> (a+b)*c, dans ce cas l?,
164 			// current.getNbChildren() est != de 0)
165 			//On insËre directement ? la position courante
166 			current.addChild(this);
167 		} 
168 		else if ((current.getAsOperatorPriority() == resourcesManager.getAsOperatorPriority("constantPriorities")) &&
169 			current.isTemplate()) {
170 			// Le cas classique (on va mÍme dire normal !!!)
171 			// La position d'insertion est un template.
172 			// On doit remplacer le template par l'instance courante
173 			int rank = current.getRank();
174 			FormulaTreeStructure father = (FormulaTreeStructure) current.getFather();
175 			father.addChild(this, rank);
176 			father.removeChild(current);
177 		}
178 		else { // On est dans aucun des cas prÈcÈdents, on crÈÈ donc une
179 			// multiplication implicite.
180 			//if( "OPEN_CURLY".equals(getResourceIdentifier()) )
181 		//	current = (new HorizentalGroup()).insert(current);
182 			//else
183 			//	current = (new Multiplication()).insert(current);
184             	
185 			//current = insert(current);
186 			//return current;
187 			addChild(current);
188 		}
189         
190 		// Maintenant, on va rajouter un slot comme ÈlÈment de l'opÈrateur
191 //		Slot aSlot = new Slot();
192 		VariableOrNumber template = new VariableOrNumber();
193 		addChild(template);
194 //		aSlot.setNextSlot(this);
195         
196 		// ...puis un template comme ÈlÈment de ce slot
197 
198 //		aSlot.addChild(template);
199         
200 		return template;*/
201 	}
202 	
203 
204 	public boolean isOperator() {
205 		return true;
206 	}
207     
208 	public String evaluate(){
209 		return null;
210 	}
211     
212 	public String createLinear(String linear) {
213 		return null;
214 	}
215 
216 
217 	/***
218 	* Adds a new element (template) to the end of the list.
219 	* Returns the new element.
220 	*/
221 	public FormulaTreeStructure addElement() {
222 		Slot aSlot = new Slot();
223 		addChild(aSlot);
224         
225 		// ...puis un template comme ÈlÈment de ce slot
226 		VariableOrNumber template = new VariableOrNumber();
227 		aSlot.addChild(template);
228         
229 		aSlot.setNextSlot(this);
230 		((Slot) getChild(getNbChildren()-2)).setNextSlot(template);
231         
232 		return template;
233 	}
234 
235     
236 }