public Object loadObject(XMLControl control, Object obj) {
   super.loadObject(control, obj);
   ElementImage element = (ElementImage) obj;
   element.setImageFile(control.getString("image file"));
   element.setRotationAngle(control.getDouble("rotation angle"));
   return obj;
 }
예제 #2
0
 public void saveObject(XMLControl control, Object obj) {
   super.saveObject(control, obj);
   ElementTrail element = (ElementTrail) obj;
   control.setValue("maximum", element.getMaximumPoints()); // $NON-NLS-1$
   control.setValue("connected", element.isConnected()); // $NON-NLS-1$
   // Don't save the points since loadObject will clear the trail
 }
 public Object loadObject(XMLControl control, Object obj) {
   Matrix3DTransformation transf = (Matrix3DTransformation) obj;
   transf.matrix = (double[][]) control.getObject("matrix");
   transf.inverse = (double[][]) control.getObject("inverse");
   transf.origin = (double[]) control.getObject("origin");
   return obj;
 }
예제 #4
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$
   }
 }
 public void saveObject(XMLControl control, Object obj) {
   Matrix3DTransformation transf = (Matrix3DTransformation) obj;
   control.setValue("matrix", transf.matrix);
   if (transf.inverse != null) {
     control.setValue("inverse", transf.inverse);
   }
   control.setValue("origin", transf.origin);
 }
예제 #6
0
 public Object loadObject(XMLControl control, Object obj) {
   super.loadObject(control, obj);
   ElementTrail element = (ElementTrail) obj;
   element.setMaximumPoints(control.getInt("maximum")); // $NON-NLS-1$
   element.setConnected(control.getBoolean("connected")); // $NON-NLS-1$
   // This implies element.clear()
   return obj;
 }
예제 #7
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());
 }
예제 #8
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;
 }
예제 #9
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) {
   PositionStep step = (PositionStep) obj;
   double x = control.getDouble("x"); // $NON-NLS-1$
   double y = control.getDouble("y"); // $NON-NLS-1$
   step.p.setXY(x, y);
   return obj;
 }
예제 #10
0
 public void saveObject(XMLControl control, Object obj) {
   VisualizationHints hints = (VisualizationHints) obj;
   control.setValue("decoration type", hints.getDecorationType()); // $NON-NLS-1$
   control.setValue("cursor type", hints.getCursorType()); // $NON-NLS-1$
   control.setValue("remove hidden lines", hints.isRemoveHiddenLines()); // $NON-NLS-1$
   control.setValue("allow quick redraw", hints.isAllowQuickRedraw()); // $NON-NLS-1$
   control.setValue("use color depth", hints.isUseColorDepth()); // $NON-NLS-1$
   control.setValue("show coordinates at", hints.getShowCoordinates()); // $NON-NLS-1$
   control.setValue("x format", hints.getXFormat()); // $NON-NLS-1$
   control.setValue("y format", hints.getYFormat()); // $NON-NLS-1$
   control.setValue("z format", hints.getZFormat()); // $NON-NLS-1$
   control.setValue("axes labels", hints.getAxesLabels()); // $NON-NLS-1$
 }
예제 #11
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;
 }
예제 #12
0
 public Object loadObject(XMLControl control, Object obj) {
   VisualizationHints hints = (VisualizationHints) obj;
   hints.setDecorationType(control.getInt("decoration type")); // $NON-NLS-1$
   hints.setCursorType(control.getInt("cursor type")); // $NON-NLS-1$
   hints.setRemoveHiddenLines(control.getBoolean("remove hidden lines")); // $NON-NLS-1$
   hints.setAllowQuickRedraw(control.getBoolean("allow quick redraw")); // $NON-NLS-1$
   hints.setUseColorDepth(control.getBoolean("use color depth")); // $NON-NLS-1$
   hints.setShowCoordinates(control.getInt("show coordinates at")); // $NON-NLS-1$
   hints.setXFormat(control.getString("x format")); // $NON-NLS-1$
   hints.setYFormat(control.getString("y format")); // $NON-NLS-1$
   hints.setZFormat(control.getString("z format")); // $NON-NLS-1$
   hints.setAxesLabels((String[]) control.getObject("axes labels")); // $NON-NLS-1$
   return obj;
 }
예제 #13
0
  /**
   * Chooses data functions from a DataFunctionPanel XMLControl.
   *
   * @param control the XMLControl
   * @param description "Save" or "Load"
   * @param selectedFunctions collection of DataFunction choices
   * @return true if user clicked OK
   */
  protected boolean choosePanelDataFunctions(
      XMLControl control, String description, Collection<String[]> selectedFunctions) {
    ListChooser listChooser =
        new ListChooser(
            TrackerRes.getString(
                "TrackerPanel.DataBuilder." + description + ".Title"), // $NON-NLS-1$ //$NON-NLS-2$
            TrackerRes.getString(
                "TrackerPanel.DataBuilder."
                    + description
                    + ".Message"), //$NON-NLS-1$ //$NON-NLS-2$
            this);
    listChooser.setSeparator(" = "); // $NON-NLS-1$
    // choose the elements and save
    ArrayList<Object> originals = new ArrayList<Object>();
    ArrayList<Object> choices = new ArrayList<Object>();
    ArrayList<String> names = new ArrayList<String>();
    ArrayList<String> expressions = new ArrayList<String>();
    ArrayList<?> functions = (ArrayList<?>) control.getObject("functions"); // $NON-NLS-1$

    for (Object next : functions) {
      String[] function = (String[]) next;
      originals.add(function);
      choices.add(function);
      names.add(function[0]);
      expressions.add(function[1]);
    }
    // select all by default
    boolean[] selected = new boolean[choices.size()];
    for (int i = 0; i < selected.length; i++) {
      selected[i] = true;
    }
    if (listChooser.choose(choices, names, expressions, selected)) {
      // compare choices with originals and remove unwanted object content
      for (Object next : originals) {
        if (!choices.contains(next)) {
          functions.remove(next);
        }
      }
      // rewrite the control with only selected functions
      control.setValue("functions", functions); // $NON-NLS-1$
      return true;
    }
    return false;
  }
예제 #14
0
 public Object loadObject(XMLControl control, Object obj) {
   DrawingPanel3D panel = (DrawingPanel3D) obj;
   double minX = control.getDouble("preferred x min");
   double maxX = control.getDouble("preferred x max");
   double minY = control.getDouble("preferred y min");
   double maxY = control.getDouble("preferred y max");
   double minZ = control.getDouble("preferred z min");
   double maxZ = control.getDouble("preferred z max");
   panel.setPreferredMinMax(minX, maxX, minY, maxY, minZ, maxZ);
   Collection elements = (Collection) control.getObject("elements");
   if (elements != null) {
     panel.removeAllElements();
     Iterator it = elements.iterator();
     while (it.hasNext()) {
       panel.addElement((Element) it.next());
     }
   }
   // The subclass is responsible to load unmutable objects such as
   // the visualization hints or the camera
   // It is also responsible to update the screen after loading
   return obj;
 }
예제 #15
0
  /**
   * Adds a FunctionPanel.
   *
   * @param name a descriptive name
   * @param panel the FunctionPanel
   * @return the added panel
   */
  @Override
  public FunctionPanel addPanel(String name, FunctionPanel panel) {
    super.addPanel(name, panel);

    // autoload data functions, if any, for this track type
    Class<?> trackType = null;
    try {
      trackType = Class.forName(panel.getDescription());
    } catch (ClassNotFoundException ex) {
    }
    // load from Strings read from tracker.prefs (deprecated Dec 2014)
    for (String xml : Tracker.dataFunctionControlStrings) {
      XMLControl control = new XMLControlElement(xml);
      // determine what track type the control is for
      Class<?> controlTrackType = null;
      try {
        controlTrackType = Class.forName(control.getString("description")); // $NON-NLS-1$);
      } catch (Exception ex) {
      }

      if (controlTrackType == trackType) {
        control.loadObject(panel);
      }
    }

    // load from XMLControls autoloaded from XML files in search paths
    for (String path : Tracker.dataFunctionControls.keySet()) {
      ArrayList<XMLControl> controls = Tracker.dataFunctionControls.get(path);
      for (XMLControl control : controls) {
        // determine what track type the control is for
        Class<?> controlTrackType = null;
        try {
          controlTrackType = Class.forName(control.getString("description")); // $NON-NLS-1$);
        } catch (Exception ex) {
        }

        if (controlTrackType == trackType) {
          // copy the control for modification if any functions are autoload_off
          XMLControl copyControl = new XMLControlElement(control);
          eliminateExcludedFunctions(copyControl, path);
          // change duplicate function names without requiring user confirmation
          FunctionEditor editor = panel.getFunctionEditor();
          boolean confirmChanges = editor.getConfirmChanges();
          editor.setConfirmChanges(false);
          copyControl.loadObject(panel);
          editor.setConfirmChanges(confirmChanges);
        }
      }
    }

    return panel;
  }
예제 #16
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;
 }
예제 #17
0
 public void saveObject(XMLControl control, Object obj) {
   DrawingPanel3D panel = (DrawingPanel3D) obj;
   control.setValue("preferred x min", panel.getPreferredMinX());
   control.setValue("preferred x max", panel.getPreferredMaxX());
   control.setValue("preferred y min", panel.getPreferredMinY());
   control.setValue("preferred y max", panel.getPreferredMaxY());
   control.setValue("preferred z min", panel.getPreferredMinZ());
   control.setValue("preferred z max", panel.getPreferredMaxZ());
   control.setValue("visualization hints", panel.getVisualizationHints());
   control.setValue("camera", panel.getCamera());
   control.setValue("elements", panel.getElements());
 }
예제 #18
0
 /**
  * Eliminates excluded function entries from a DataFunctionPanel XMLControl. Typical (but
  * incomplete) control:
  *
  * <p><object class="org.opensourcephysics.tools.DataFunctionPanel"> <property name="description"
  * type="string">org.opensourcephysics.cabrillo.tracker.PointMass</property> <property
  * name="functions" type="collection" class="java.util.ArrayList"> <property name="item"
  * type="array" class="[Ljava.lang.String;"> <property name="[0]" type="string">Ug</property>
  * <property name="[1]" type="string">m*g*y</property> </property> </property> <property
  * name="autoload_off_Ug" type="boolean">true</property> </object>
  *
  * @param panelControl the XMLControl to modify
  * @param filePath the path to the XML file read by the XMLControl
  */
 private void eliminateExcludedFunctions(XMLControl panelControl, String filePath) {
   for (Object prop : panelControl.getPropertyContent()) {
     if (prop instanceof XMLProperty
         && ((XMLProperty) prop).getPropertyName().equals("functions")) { // $NON-NLS-1$
       // found functions
       XMLProperty functions = (XMLProperty) prop;
       java.util.List<Object> items = functions.getPropertyContent();
       ArrayList<XMLProperty> toRemove = new ArrayList<XMLProperty>();
       for (Object child : items) {
         XMLProperty item = (XMLProperty) child;
         XMLProperty nameProp = (XMLProperty) item.getPropertyContent().get(0);
         String functionName = (String) nameProp.getPropertyContent().get(0);
         if (isFunctionExcluded(filePath, functionName)) {
           toRemove.add(item);
         }
       }
       for (XMLProperty next : toRemove) {
         items.remove(next);
       }
     }
   }
 }
예제 #19
0
 public void saveObject(XMLControl control, Object obj) {
   super.saveObject(control, obj);
   ElementImage element = (ElementImage) obj;
   control.setValue("image file", element.getImageFile());
   control.setValue("rotation angle", element.getRotationAngle());
 }
예제 #20
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) {
   PositionStep step = (PositionStep) obj;
   control.setValue("x", step.p.x); // $NON-NLS-1$
   control.setValue("y", step.p.y); // $NON-NLS-1$
 }
예제 #21
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$
 }
예제 #22
0
  /**
   * Chooses data functions from a DataBuilder XMLControl.
   *
   * @param control the XMLControl
   * @param description "Save" or "Load"
   * @param selectedFunctions collection of DataFunction choices
   * @return true if user clicked OK
   */
  @SuppressWarnings("unchecked")
  protected boolean chooseBuilderDataFunctions(
      XMLControl control, String description, Collection<String[]> selectedFunctions) {
    ListChooser listChooser =
        new ListChooser(
            TrackerRes.getString(
                "TrackerPanel.DataBuilder." + description + ".Title"), // $NON-NLS-1$ //$NON-NLS-2$
            TrackerRes.getString(
                "TrackerPanel.DataBuilder."
                    + description
                    + ".Message"), //$NON-NLS-1$ //$NON-NLS-2$
            this);
    listChooser.setSeparator(" = "); // $NON-NLS-1$
    // choose the elements and save
    ArrayList<String[]> originals = new ArrayList<String[]>();
    ArrayList<String[]> choices = new ArrayList<String[]>();
    ArrayList<String> names = new ArrayList<String>();
    ArrayList<String> expressions = new ArrayList<String>();
    ArrayList<String> trackTypes = new ArrayList<String>();

    Map<String, XMLControl> xmlControlMap = new TreeMap<String, XMLControl>();
    Map<String, ArrayList<Parameter>> parameterMap = new TreeMap<String, ArrayList<Parameter>>();
    Map<String, ArrayList<String[]>> functionMap = new TreeMap<String, ArrayList<String[]>>();
    for (Object obj : control.getPropertyContent()) {
      if (obj instanceof XMLProperty) {
        XMLProperty prop = (XMLProperty) obj;
        for (XMLControl xmlControl : prop.getChildControls()) {
          if (xmlControl.getObjectClass() != DataFunctionPanel.class) continue;

          // get track type (description) and map to panel xmlControl
          String trackType = xmlControl.getString("description"); // $NON-NLS-1$
          xmlControlMap.put(trackType, xmlControl);

          // get the list of functions for this track type
          ArrayList<String[]> functions = functionMap.get(trackType);
          if (functions == null) {
            functions = new ArrayList<String[]>();
            functionMap.put(trackType, functions);
          }
          // add functions found in this xmlControl unless already present
          ArrayList<String[]> panelFunctions =
              (ArrayList<String[]>) xmlControl.getObject("functions"); // $NON-NLS-1$
          outer:
          for (String[] f : panelFunctions) {
            // check for duplicate function names
            for (String[] existing : functions) {
              if (existing[0].equals(f[0])) continue outer;
            }
            functions.add(f);
          }

          // get the list of parameters for this track type
          ArrayList<Parameter> params = parameterMap.get(trackType);
          if (params == null) {
            params = new ArrayList<Parameter>();
            parameterMap.put(trackType, params);
          }
          // add parameters found in this xmlControl unless already present
          Parameter[] panelParams =
              (Parameter[]) xmlControl.getObject("user_parameters"); // $NON-NLS-1$
          outer:
          for (Parameter p : panelParams) {
            if (trackType.endsWith("PointMass")
                && p.getName().equals("m")) { // $NON-NLS-1$ //$NON-NLS-2$
              continue outer;
            }
            // check for duplicate parameter names
            for (Parameter existing : params) {
              if (existing.getName().equals(p.getName())) continue outer;
            }
            params.add(p);
          }
        }
      }
    }

    for (String trackType : functionMap.keySet()) {
      ArrayList<String[]> functions = functionMap.get(trackType);
      for (String[] f : functions) {
        originals.add(f);
        choices.add(f);
        names.add(f[0]);
        expressions.add(f[1]);
        String shortName = XML.getExtension(trackType);
        String localized = TrackerRes.getString(shortName + ".Name"); // $NON-NLS-1$
        if (!localized.startsWith("!")) shortName = localized; // $NON-NLS-1$
        trackTypes.add("[" + shortName + "]"); // $NON-NLS-1$ //$NON-NLS-2$
      }
    }
    // select all by default
    boolean[] selected = new boolean[choices.size()];
    for (int i = 0; i < selected.length; i++) {
      selected[i] = true;
    }

    if (listChooser.choose(choices, names, expressions, trackTypes, selected)) {
      // compare choices with originals and remove unwanted object content
      for (String[] function : originals) {
        if (!choices.contains(function)) {
          for (String trackType : xmlControlMap.keySet()) {
            ArrayList<String[]> functions = functionMap.get(trackType);
            functions.remove(function);
          }
        }
      }
      // set functions in xmlControl for each trackType
      for (String trackType : xmlControlMap.keySet()) {
        ArrayList<String[]> functions = functionMap.get(trackType);
        ArrayList<Parameter> paramList = parameterMap.get(trackType);
        Parameter[] params = paramList.toArray(new Parameter[paramList.size()]);
        XMLControl xmlControl = xmlControlMap.get(trackType);
        xmlControl.setValue("functions", functions); // $NON-NLS-1$
        xmlControl.setValue("user_parameters", params); // $NON-NLS-1$
      }

      // keep only xmlControls that have functions and are in xmlControlMap
      for (Object next : control.getPropertyContent()) {
        if (next instanceof XMLProperty
            && ((XMLProperty) next).getPropertyName().equals("functions")) { // $NON-NLS-1$
          XMLProperty panels = (XMLProperty) next;
          java.util.List<Object> content = panels.getPropertyContent();
          ArrayList<Object> toRemove = new ArrayList<Object>();
          for (Object child : content) {
            XMLControl xmlControl = ((XMLProperty) child).getChildControls()[0];
            if (!xmlControlMap.values().contains(xmlControl)) {
              toRemove.add(child);
            } else { // check to see if functions is empty
              ArrayList<String[]> functions =
                  (ArrayList<String[]>) xmlControl.getObject("functions"); // $NON-NLS-1$
              if (functions == null || functions.isEmpty()) {
                toRemove.add(child);
              }
            }
          }
          for (Object remove : toRemove) {
            content.remove(remove);
          }
        }
      }

      return true;
    }
    return false;
  }