1 package JSci.beans; 2 3 import java.beans.*; 4 import java.util.Vector ; 5 import JSci.maths.*; 6 import JSci.maths.matrices.DoubleMatrix; 7 import JSci.maths.vectors.DoubleVector; 8 9 public final class VariableBean extends Object implements java.io.Serializable { 10 private PropertyChangeSupport changes=new PropertyChangeSupport(this); 11 private Vector variableListeners=new Vector (); 12 private String variable=new String (); 13 private Object value; 14 15 public VariableBean() {} 16 public synchronized void setVariable(String var) { 17 String oldVar=variable; 18 variable=var; 19 changes.firePropertyChange("variable",oldVar,var); 20 } 21 public synchronized String getVariable() { 22 return variable; 23 } 24 public synchronized void setValueAsNumber(double x) { 25 value=new MathDouble(x); 26 changes.firePropertyChange("valueAsNumber",null,new Double (x)); 27 fireVariableChanged(new VariableEvent(this,variable,value)); 28 } 29 public synchronized double getValueAsNumber() { 30 if(value instanceof MathDouble) 31 return ((MathDouble)value).value(); 32 else 33 return Double.NaN; 34 } 35 public synchronized void setValueAsVector(double v[]) { 36 value=new DoubleVector(v); 37 changes.firePropertyChange("valueAsVector",null,v); 38 fireVariableChanged(new VariableEvent(this,variable,value)); 39 } 40 public synchronized void setValueAsMatrix(double m[][]) { 41 value=new DoubleMatrix(m); 42 changes.firePropertyChange("valueAsMatrix",null,m); 43 fireVariableChanged(new VariableEvent(this,variable,value)); 44 } 45 public synchronized void addPropertyChangeListener(PropertyChangeListener l) { 46 changes.addPropertyChangeListener(l); 47 } 48 public synchronized void removePropertyChangeListener(PropertyChangeListener l) { 49 changes.removePropertyChangeListener(l); 50 } 51 public synchronized void addVariableListener(VariableListener l) { 52 variableListeners.addElement(l); 53 } 54 public synchronized void removeVariableListener(VariableListener l) { 55 variableListeners.removeElement(l); 56 } 57 private void fireVariableChanged(VariableEvent evt) { 58 for(int i=0;i<variableListeners.size();i++) 59 ((VariableListener)variableListeners.elementAt(i)).variableChanged(evt); 60 } 61 } 62 63 | Popular Tags |