Example #1
0
 /**
  * Saves an object's data to an XMLControl.
  *
  * @param control the control to save to
  * @param obj the object to save
  */
 public void saveObject(XMLControl control, Object obj) {
   ParticleModel p = (ParticleModel) obj;
   // save mass
   control.setValue("mass", p.getMass()); // $NON-NLS-1$
   // save track data
   XML.getLoader(TTrack.class).saveObject(control, obj);
   // save parameters, initial values and functions
   Parameter[] params = p.getParamEditor().getParameters();
   control.setValue("user_parameters", params); // $NON-NLS-1$
   Parameter[] inits = p.getInitEditor().getParameters();
   control.setValue("initial_values", inits); // $NON-NLS-1$
   UserFunction[] functions = p.getFunctionEditor().getMainFunctions();
   control.setValue("main_functions", functions); // $NON-NLS-1$
   functions = p.getFunctionEditor().getSupportFunctions();
   if (functions.length > 0) control.setValue("support_functions", functions); // $NON-NLS-1$
   // save start and end frames (if custom)
   if (p.startFrame > 0) control.setValue("start_frame", p.startFrame); // $NON-NLS-1$
   if (p.endFrame < Integer.MAX_VALUE) control.setValue("end_frame", p.endFrame); // $NON-NLS-1$
   // save inspector size and position
   if (p.inspector != null && p.trackerPanel != null && p.trackerPanel.getTFrame() != null) {
     // save inspector location relative to frame
     TFrame frame = p.trackerPanel.getTFrame();
     int x = p.inspector.getLocation().x - frame.getLocation().x;
     int y = p.inspector.getLocation().y - frame.getLocation().y;
     control.setValue("inspector_x", x); // $NON-NLS-1$
     control.setValue("inspector_y", y); // $NON-NLS-1$  		
     control.setValue("inspector_h", p.inspector.getHeight()); // $NON-NLS-1$
     control.setValue("inspector_visible", p.inspector.isVisible()); // $NON-NLS-1$
   }
 }
 /**
  * Saves object data to an XMLControl.
  *
  * @param control the control to save to
  * @param obj the object to save
  */
 public void saveObject(XMLControl xmlControl, Object obj) {
   OSPControl ospControl = (OSPControl) obj;
   saveControlProperites(xmlControl, ospControl);
   // save the model if the control is the top level
   if (xmlControl.getLevel() == 0) {
     xmlControl.setValue("model", ospControl.model); // $NON-NLS-1$
   }
 }
Example #3
0
 public void saveObject(XMLControl control, Object obj) {
   Style style = (Style) obj;
   control.setValue("line color", style.getLineColor());
   control.setValue("line width", style.getLineWidth());
   control.setValue("fill color", style.getFillColor());
   control.setValue("resolution", style.getResolution());
   control.setValue("drawing fill", style.isDrawingFill());
   control.setValue("drawing lines", style.isDrawingLines());
 }
Example #4
0
 /**
  * Loads a VideoClip with data from an XMLControl.
  *
  * @param element the element
  * @param obj the object
  * @return the loaded object
  */
 public Object loadObject(XMLControl control, Object obj) {
   StepperClipControl clipControl = (StepperClipControl) obj;
   // set rate
   double rate = control.getDouble("rate"); // $NON-NLS-1$
   if (rate != Double.NaN) {
     clipControl.setRate(rate);
   }
   // set dt
   double dt = control.getDouble("delta_t"); // $NON-NLS-1$
   if (dt != Double.NaN) {
     clipControl.setFrameDuration(dt);
   }
   // set looping and playing
   clipControl.setLooping(control.getBoolean("looping")); // $NON-NLS-1$
   return obj;
 }
Example #5
0
 /**
  * Loads an object with data from an XMLControl.
  *
  * @param control the control
  * @param obj the object
  * @return the loaded object
  */
 public Object loadObject(XMLControl control, Object obj) {
   // load track data
   XML.getLoader(TTrack.class).loadObject(control, obj);
   ParticleModel p = (ParticleModel) obj;
   p.mass = control.getDouble("mass"); // $NON-NLS-1$
   p.inspectorX = control.getInt("inspector_x"); // $NON-NLS-1$
   p.inspectorY = control.getInt("inspector_y"); // $NON-NLS-1$
   p.inspectorH = control.getInt("inspector_h"); // $NON-NLS-1$
   p.showInspector = control.getBoolean("inspector_visible"); // $NON-NLS-1$
   Parameter[] params = (Parameter[]) control.getObject("user_parameters"); // $NON-NLS-1$
   p.getParamEditor().setParameters(params);
   params = (Parameter[]) control.getObject("initial_values"); // $NON-NLS-1$
   // remove trailing "0" from initial condition parameters
   for (int i = 0; i < params.length; i++) {
     Parameter param = params[i];
     String name = param.getName();
     int n = name.lastIndexOf("0"); // $NON-NLS-1$
     if (n > -1) {
       // replace parameter with new one
       name = name.substring(0, n);
       Parameter newParam = new Parameter(name, param.getExpression());
       newParam.setDescription(param.getDescription());
       newParam.setNameEditable(false);
       params[i] = newParam;
     }
   }
   p.getInitEditor().setParameters(params);
   UserFunction[] functions =
       (UserFunction[]) control.getObject("main_functions"); // $NON-NLS-1$
   p.getFunctionEditor().setMainFunctions(functions);
   functions = (UserFunction[]) control.getObject("support_functions"); // $NON-NLS-1$
   if (functions != null) {
     for (int i = 0; i < functions.length; i++) {
       p.getFunctionEditor().addObject(functions[i], false);
     }
   }
   p.functionPanel.refreshFunctions();
   int n = control.getInt("start_frame"); // $NON-NLS-1$
   if (n != Integer.MIN_VALUE) p.startFrame = n;
   else {
     p.startFrameUndefined = true;
   }
   n = control.getInt("end_frame"); // $NON-NLS-1$
   if (n != Integer.MIN_VALUE) p.endFrame = n;
   return obj;
 }
 /**
  * Saves object data to an ObjectElement.
  *
  * @param element the element to save to
  * @param obj the object to save
  */
 public void saveObject(XMLControl element, Object obj) {
   AnimationControl control = (AnimationControl) obj;
   if (control.startBtn.getText().equals(control.stopText)) {
     control.startBtn.doClick(); // stop the animation if it is running
   }
   element.setValue("initialize_mode", control.startBtn.getText().equals(control.initText));
   super.saveObject(element, obj);
 }
 /**
  * Loads an object with data from an ObjectElement.
  *
  * @param element the element
  * @param obj the object
  * @return the loaded object
  */
 public Object loadObject(XMLControl element, Object obj) {
   AnimationControl animationControl = (AnimationControl) obj;
   if (animationControl.startBtn.getText().equals(animationControl.stopText)) {
     animationControl.startBtn.doClick(); // stop the animation if it is running
   }
   boolean initMode = element.getBoolean("initialize_mode");
   element.setValue("initialize_mode", null); // don't show this internal parameter
   super.loadObject(element, obj); // load the control's parameters and the model
   // put the animation into the initialize state if it was in this state when it was stopped
   if (initMode) element.setValue("initialize_mode", true);
   if (initMode && animationControl.startBtn.getText().equals(animationControl.startText)) {
     animationControl.resetBtn.doClick();
   }
   if (!initMode && animationControl.startBtn.getText().equals(animationControl.initText)) {
     animationControl.startBtn.doClick();
   }
   animationControl.clearMessages();
   return obj;
 }
Example #8
0
 public Object loadObject(XMLControl control, Object obj) {
   Style style = (Style) obj;
   style.setLineColor((Color) control.getObject("line color"));
   style.setLineWidth((float) control.getDouble("line width"));
   style.setFillColor((Color) control.getObject("fill color"));
   style.setResolution(
       (org.opensourcephysics.display3d.core.Resolution) control.getObject("resolution"));
   style.setDrawingFill(control.getBoolean("drawing fill"));
   style.setDrawingLines(control.getBoolean("drawing lines"));
   return obj;
 }
 protected void saveControlProperites(XMLControl xmlControl, OSPControl ospControl) {
   // save the parameters
   Iterator it = ospControl.getPropertyNames().iterator();
   while (it.hasNext()) {
     String name = (String) it.next();
     Object val = ospControl.getObject(name);
     if (val.getClass() == DoubleArray.class) {
       xmlControl.setValue(name, ((DoubleArray) val).getArray());
     } else if (val.getClass() == IntegerArray.class) {
       xmlControl.setValue(name, ((IntegerArray) val).getArray());
     } else if (val.getClass() == Boolean.class) {
       xmlControl.setValue(name, ((Boolean) val).booleanValue());
     } else if (val.getClass() == Double.class) {
       xmlControl.setValue(name, ((Double) val).doubleValue());
     } else if (val.getClass() == Integer.class) {
       xmlControl.setValue(name, ((Integer) val).intValue());
     } else if (val.getClass().isArray()) {
       xmlControl.setValue(name, val);
     } else {
       xmlControl.setValue(name, val);
     }
     // xmlControl.setValue(name, val.toString());
   }
 }
 /**
  * Loads an object with data from an XMLControl.
  *
  * @param control the control
  * @param obj the object
  * @return the loaded object
  */
 public Object loadObject(XMLControl control, Object obj) {
   OSPControl cf = (OSPControl) obj;
   // iterate over properties and add them to table model
   Iterator it = control.getPropertyNames().iterator();
   cf.table.setLockValues(true);
   while (it.hasNext()) {
     String name = (String) it.next();
     // skip "model" object properties
     if (name.equals("model") && control.getPropertyType(name).equals("object")) {
       XMLControl child = control.getChildControl("model"); // $NON-NLS-1$
       cf.model = child.loadObject(cf.model);
       continue;
     }
     if (control.getPropertyType(name).equals("string")) { // $NON-NLS-1$
       cf.setValue(name, control.getString(name));
     } else if (control.getPropertyType(name).equals("int")) { // $NON-NLS-1$
       cf.setValue(name, control.getInt(name));
     } else if (control.getPropertyType(name).equals("double")) { // $NON-NLS-1$
       cf.setValue(name, control.getDouble(name));
     } else if (control.getPropertyType(name).equals("boolean")) { // $NON-NLS-1$
       cf.setValue(name, control.getBoolean(name));
     } else {
       cf.setValue(name, control.getObject(name));
     }
   }
   cf.table.setLockValues(false);
   //      XMLControl child = control.getChildControl("model"); //$NON-NLS-1$
   //      if(child!=null) {
   //        cf.model = child.loadObject(cf.model);
   //      }
   return obj;
 }
Example #11
0
 /**
  * Saves object data in an XMLControl.
  *
  * @param control the control to save to
  * @param obj the object to save
  */
 public void saveObject(XMLControl control, Object obj) {
   ClipControl clipControl = (StepperClipControl) obj;
   control.setValue("rate", clipControl.getRate()); // $NON-NLS-1$
   control.setValue("delta_t", clipControl.getMeanFrameDuration()); // $NON-NLS-1$
   if (clipControl.isLooping()) control.setValue("looping", true); // $NON-NLS-1$
 }