Ejemplo n.º 1
0
 /** This adds the mass and initial time parameters to the function panel. */
 protected void createMassAndTimeParameters() {
   Parameter param = new Parameter("m", String.valueOf(getMass())); // $NON-NLS-1$
   param.setNameEditable(false);
   param.setDescription(
       TrackerRes.getString("ParticleModel.Parameter.Mass.Description")); // $NON-NLS-1$
   getParamEditor().addObject(param, false);
   param = new Parameter("t", "0"); // $NON-NLS-1$ //$NON-NLS-2$
   param.setNameEditable(false);
   param.setDescription(
       TrackerRes.getString("ParticleModel.Parameter.InitialTime.Description")); // $NON-NLS-1$
   functionPanel.getInitEditor().addObject(param, false);
   getParamEditor()
       .addPropertyChangeListener(
           new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent e) {
               if ("m".equals(e.getOldValue())) { // $NON-NLS-1$
                 Parameter param = (Parameter) getParamEditor().getObject("m"); // $NON-NLS-1$
                 if (ParticleModel.super.getMass() != param.getValue()) {
                   setMass(param.getValue());
                 }
               }
             }
           });
   getInitEditor()
       .addPropertyChangeListener(
           new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent e) {
               if (refreshing) return;
               if ("t".equals(e.getOldValue()) && trackerPanel != null) { // $NON-NLS-1$
                 Parameter param = (Parameter) getInitEditor().getObject("t"); // $NON-NLS-1$
                 VideoClip clip = trackerPanel.getPlayer().getVideoClip();
                 double timeOffset = param.getValue() * 1000 - clip.getStartTime();
                 double dt = trackerPanel.getPlayer().getMeanStepDuration();
                 int n = clip.getStartFrameNumber();
                 boolean mustRound = timeOffset % dt > 0;
                 n += clip.getStepSize() * (int) Math.round(timeOffset / dt);
                 setStartFrame(n);
                 if (getStartFrame() != n || mustRound) Toolkit.getDefaultToolkit().beep();
               }
             }
           });
 }
Ejemplo n.º 2
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;
 }