src/java/isac/bridge/CalcTree.java
changeset 1202 e826c0eccaa6
parent 1191 165486f84bcf
child 1203 032eb795bdb5
     1.1 --- a/src/java/isac/bridge/CalcTree.java	Tue Nov 25 11:13:40 2003 +0100
     1.2 +++ b/src/java/isac/bridge/CalcTree.java	Tue Nov 25 12:47:50 2003 +0100
     1.3 @@ -3,6 +3,7 @@
     1.4   */
     1.5  package isac.bridge;
     1.6  
     1.7 +import isac.util.CalcChangedEvent;
     1.8  import isac.util.Formula;
     1.9  import isac.util.ICalcIterator;
    1.10  import isac.util.IToCalc;
    1.11 @@ -12,6 +13,7 @@
    1.12  
    1.13  import java.io.Serializable;
    1.14  import java.rmi.RemoteException;
    1.15 +import java.util.Iterator;
    1.16  import java.util.Vector;
    1.17  
    1.18  /**
    1.19 @@ -77,7 +79,8 @@
    1.20    public void moveActiveFormula(ICalcIterator newActiveFormula) {
    1.21      //String s = sendToBridge("moveActiveFormula 1 1;");
    1.22      //not implemented in kernel
    1.23 -    //hotSpot.setPosition(newActiveFormula);
    1.24 +    ((CalcIterator)hotSpot).moveTo((CalcIterator)newActiveFormula);
    1.25 +	informListeners(null);
    1.26    }
    1.27  
    1.28    /**
    1.29 @@ -95,6 +98,7 @@
    1.30    public int replaceFormula(Formula newFormula) {
    1.31      //String s = sendToBridge("replaceFormula 1 1;");
    1.32      //Not implemented in kernel
    1.33 +	informListeners(null);
    1.34      return 0;
    1.35    }
    1.36  
    1.37 @@ -109,22 +113,24 @@
    1.38    indicating the status otherwise.
    1.39    */
    1.40    public int appendFormula(Formula newFormula) {
    1.41 +	informListeners(null);
    1.42      return 0;
    1.43    }
    1.44  
    1.45    /**
    1.46 -  Set the tactic to be used in the next step of calculation.   
    1.47 +  Set and use a tactic in the next step of calculation.   
    1.48    * @param tactic the Tactic to be used in the the next step
    1.49    * @return The return value indicates success, failure or probable
    1.50    success at a later time.
    1.51    */
    1.52    public int setNextTactic(Tactic tactic) {
    1.53 +    int result = -1;
    1.54      try {
    1.55 -      int result = mathEngine.setNextTactic(this.id, tactic);
    1.56 +      result = mathEngine.setNextTactic(this.id, tactic);
    1.57        if (result == 0) {
    1.58          hotSpot.moveDown(); // move to the new formula/calcHead
    1.59        }
    1.60 -      return result;
    1.61 +	  informListeners(null);
    1.62      } catch (RemoteException e) {
    1.63        // TODO Auto-generated catch block
    1.64        e.printStackTrace();
    1.65 @@ -155,13 +161,14 @@
    1.66    * @return Array with applyable tactics
    1.67    */
    1.68    public Tactic[] fetchAppliableTactics(int scope) {
    1.69 +    Tactic[] result = null;
    1.70      try {
    1.71 -      return mathEngine.fetchAppliableTactics(this.id, scope);
    1.72 -    } catch (RemoteException e) {
    1.73 +      result = mathEngine.fetchAppliableTactics(this.id, scope);
    1.74 +	} catch (RemoteException e) {
    1.75        // TODO Auto-generated catch block
    1.76        e.printStackTrace();
    1.77      }
    1.78 -    return null;
    1.79 +    return result;
    1.80    }
    1.81  
    1.82    /**
    1.83 @@ -178,13 +185,15 @@
    1.84    notifying about updates in the tree.
    1.85    */
    1.86    public int autoCalculate(int scope, int nSteps) {
    1.87 +    int result = -1;
    1.88      try {
    1.89 -      return mathEngine.autoCalculate(this.id, scope, nSteps);
    1.90 +      result = mathEngine.autoCalculate(this.id, scope, nSteps);
    1.91 +	  informListeners(null);
    1.92      } catch (RemoteException e) {
    1.93        // TODO Auto-generated catch block
    1.94        e.printStackTrace();
    1.95      }
    1.96 -    return -1;
    1.97 +    return result;
    1.98    }
    1.99  
   1.100    /**
   1.101 @@ -223,7 +232,20 @@
   1.102        e.printStackTrace();
   1.103      }
   1.104      return false;
   1.105 -  }  
   1.106 +  } 
   1.107 +  
   1.108 +  private void informListeners(ICalcIterator lastUnchangedFormula) {
   1.109 +    Iterator it = listeners.iterator();    
   1.110 +    DialogGuide dg;
   1.111 +    CalcChangedEvent e = new CalcChangedEvent(
   1.112 +    0,    // transactionID 
   1.113 +    true, // completed
   1.114 +    lastUnchangedFormula);
   1.115 +    while (it.hasNext()) {
   1.116 +      dg = (DialogGuide)it.next();
   1.117 +      dg.calcChanged(e);
   1.118 +    }
   1.119 +  }
   1.120  
   1.121    public MathEngine getMathEngine() {
   1.122      return mathEngine;