Back to index

wims  3.65+svn20090927
Constant.java
Go to the documentation of this file.
00001 /*
00002 $Id: Constant.java,v 1.3 2003/02/18 11:48:47 sander Exp $
00003 */
00004 
00005 
00006 /*
00007 Copyright (C) 2001-2002 Mainline Project (I3S - ESSI - CNRS -UNSA)
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU Lesser General Public
00011 License as published by the Free Software Foundation; either
00012 version 2.1 of the License, or (at your option) any later version.
00013 
00014 This library is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public
00020 License along with this library; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023 For further information on the GNU Lesser General Public License,
00024 see: http://www.gnu.org/copyleft/lesser.html
00025 For further information on this library, contact: mainline@essi.fr
00026 */
00027 
00028 
00029 package fr.ove.openmath.jome.model;
00030 
00031 import fr.ove.openmath.jome.model.FormulaTreeStructure;
00032 import fr.ove.openmath.jome.model.events.ModelEvent;
00033 import fr.ove.openmath.jome.model.evaluation.*;
00034 
00039 public class Constant extends FormulaTreeStructure {
00043     private String value = "";
00044 
00049     public Constant() {
00050         setAsOperatorPriority(resourcesManager.getAsOperatorPriority("constantPriorities"));
00051         setAsOperandPriority(resourcesManager.getAsOperandPriority("constantPriorities"));
00052     }
00053     
00061     public FormulaTreeStructure insert(FormulaTreeStructure current) {
00062         ModelEvent modelEvent;
00063         FormulaTreeStructure father = (FormulaTreeStructure) current.getFather();
00064 
00065         if ((current.getAsOperatorPriority() == resourcesManager.getAsOperatorPriority("constantPriorities")) &&
00066             current.isTemplate()) {
00067             // Normalement dans ce cas, current est un template, on le remplace sans état d'âme.
00068             father.addChild(this);
00069             father.removeChild(current);
00070 
00071             return this;
00072         }
00073         else { // On est dans le cas de l'insertion courante d'une constante dans la FTS
00074             if ((current.getFather() == null) && (current.getNbChildren() == 0)) {
00075                 // On est dans ce cas là, seulement au tout début de la saisie de la 
00076                 // formule. On est obligé de faire ce test à cause de la multiplication
00077                 // implicite avec les parenthèses (Ex: (a+b)c ==> (a+b)*c, dans ce cas là,
00078                 // current.getNbChildren() est != de 0)
00079                 //On insère directement à la position courante
00080                 current.addChild(this);
00081                 
00082                 return this;
00083             }
00084             else { // On est dans aucun des cas précédents, on créé donc une
00085                 // multiplication implicite.
00086                 current = (new Multiplication()).insert(current);
00087                 current = insert(current);
00088                 return current;
00089             }
00090         }
00091     }
00092     
00096     public String createLinear(String linear) {
00097         return linear + value;
00098     }
00099 
00103     public String evaluate() {
00104         return value;
00105     }
00106     
00111     public boolean isOperator() {
00112         return false;
00113     }
00114     
00115     
00116     // *****************************************
00117     // Implémentation de l'interface Modifiable
00118     
00122     public void setValue(String value) {
00123         this.value = value;
00124     }
00125     
00129     public String getValue() {
00130         return value;
00131     }
00132     
00133     // *** Fin de l'interface Modifiable ***
00134     // *************************************
00135     
00136     // *****************************************
00137     // Implémentation de l'interface Iconifiable
00138     
00143     public boolean isIconifiable() {
00144         return false;  // L'instance n'est pas iconifiable
00145     }
00146     
00147     // *** Fin de l'interface Iconifiable ***
00148     // **************************************
00149 }