Example #1
0
 /**
  * Overrides PointMass findInteractive method.
  *
  * @param panel the drawing panel
  * @param xpix the x pixel position on the panel
  * @param ypix the y pixel position on the panel
  * @return the first step or motion vector that is hit
  */
 public Interactive findInteractive(DrawingPanel panel, int xpix, int ypix) {
   Interactive ia = super.findInteractive(panel, xpix, ypix);
   if (ia instanceof PositionStep.Position) {
     hint = TrackerRes.getString("PointMass.Position.Locked.Hint"); // $NON-NLS-1$
   } else if (ia == null) hint = TrackerRes.getString("ParticleModel.Hint"); // $NON-NLS-1$
   return ia;
 }
Example #2
0
 /**
  * Gets a localized track name from the fully qualified track class name.
  *
  * @param trackClass the class name
  * @return the localized name
  */
 protected String getLocalizedTrackName(String trackClass) {
   String trackName = XML.getExtension(trackClass);
   String localized = TrackerRes.getString(trackName + ".Name"); // $NON-NLS-1$
   if (!localized.startsWith("!")) // $NON-NLS-1$
   trackName = localized;
   return trackName;
 }
Example #3
0
 /** Constructs a ParticleModel. */
 public ParticleModel() {
   Footprint[] footprints = super.getFootprints();
   Footprint[] newprints = new Footprint[footprints.length + 1];
   newprints[0] = CircleFootprint.getFootprint("CircleFootprint.FilledCircle"); // $NON-NLS-1$
   for (int i = 0; i < footprints.length; i++) {
     newprints[i + 1] = footprints[i];
   }
   setFootprints(newprints);
   defaultFootprint = newprints[0];
   setFootprint(defaultFootprint.getName());
   // assign a meaningful initial name
   setName(TrackerRes.getString("ParticleModel.New.Name")); // $NON-NLS-1$
   initializeFunctionPanel();
   // set initial hint
   hint = TrackerRes.getString("ParticleModel.Hint"); // $NON-NLS-1$
 }
Example #4
0
 /** Refreshes the GUI. */
 protected void refreshGUI() {
   refreshAutoloadData();
   super.refreshGUI();
   String title = TrackDataBuilder.this.getTitle() + " " + getTitle(); // $NON-NLS-1$
   setTitle(title);
   setInstructions(
       TrackerRes.getString("TrackDataBuilder.Instructions.SelectToAutoload") // $NON-NLS-1$
           + "\n\n"
           + TrackerRes.getString(
               "TrackDataBuilder.Instructions.WhereDefined") //$NON-NLS-1$ //$NON-NLS-2$
           + " "
           + TrackerRes.getString(
               "TrackDataBuilder.Instructions.HowToAddFunction") //$NON-NLS-1$ //$NON-NLS-2$
           + " "
           + TrackerRes.getString(
               "TrackDataBuilder.Instructions.HowToAddDirectory")); //$NON-NLS-1$ //$NON-NLS-2$
 }
Example #5
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;
  }
Example #6
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();
               }
             }
           });
 }
Example #7
0
 /**
  * Creates a new DataFunctionPanel for a track, autoloading appropriate data functions.
  *
  * @param track the track
  */
 protected FunctionPanel createFunctionPanel(TTrack track) {
   FunctionPanel panel = new DataFunctionPanel(track.getData(trackerPanel));
   panel.setIcon(track.getIcon(21, 16, "point")); // $NON-NLS-1$
   Class<?> type = track.getClass();
   if (PointMass.class.isAssignableFrom(type)) panel.setDescription(PointMass.class.getName());
   else if (Vector.class.isAssignableFrom(type)) panel.setDescription(Vector.class.getName());
   else if (RGBRegion.class.isAssignableFrom(type))
     panel.setDescription(RGBRegion.class.getName());
   else if (LineProfile.class.isAssignableFrom(type))
     panel.setDescription(LineProfile.class.getName());
   else panel.setDescription(type.getName());
   final ParamEditor paramEditor = panel.getParamEditor();
   if (track instanceof PointMass) {
     final PointMass m = (PointMass) track;
     Parameter param = (Parameter) paramEditor.getObject("m"); // $NON-NLS-1$
     if (param == null) {
       param = new Parameter("m", String.valueOf(m.getMass())); // $NON-NLS-1$
       param.setDescription(
           TrackerRes.getString("ParticleModel.Parameter.Mass.Description")); // $NON-NLS-1$
       paramEditor.addObject(param, false);
     }
     param.setNameEditable(false); // mass name not editable
     paramEditor.addPropertyChangeListener(
         new PropertyChangeListener() {
           public void propertyChange(PropertyChangeEvent e) {
             if ("m".equals(e.getOldValue())) { // $NON-NLS-1$
               Parameter param = (Parameter) paramEditor.getObject("m"); // $NON-NLS-1$
               if (m.getMass() != param.getValue()) {
                 m.setMass(param.getValue());
                 m.massField.setValue(m.getMass());
               }
             }
           }
         });
     m.addPropertyChangeListener(
         "mass",
         new PropertyChangeListener() { //$NON-NLS-1$
           public void propertyChange(PropertyChangeEvent e) {
             Parameter param = (Parameter) paramEditor.getObject("m"); // $NON-NLS-1$
             double newMass = (Double) e.getNewValue();
             if (newMass != param.getValue()) {
               paramEditor.setExpression("m", String.valueOf(newMass), false); // $NON-NLS-1$
             }
           }
         });
   }
   return panel;
 }
Example #8
0
 /**
  * Sets the display format for angles.
  *
  * @param radians <code>true</code> for radians, false for degrees
  */
 protected void setAnglesInRadians(boolean radians) {
   super.setAnglesInRadians(radians);
   functionPanel.initEditor.setAnglesInDegrees(!radians);
   String s =
       TrackerRes.getString("DynamicParticle.Parameter.InitialTheta.Description")
           + " "; //$NON-NLS-1$ //$NON-NLS-2$
   s +=
       radians
           ? TrackerRes.getString("TableTrackView.Radians.Tooltip")
           : //$NON-NLS-1$
           TrackerRes.getString("TableTrackView.Degrees.Tooltip"); // $NON-NLS-1$
   functionPanel.initEditor.setDescription(FunctionEditor.THETA, s);
   s =
       TrackerRes.getString("DynamicParticle.Parameter.InitialOmega.Description")
           + " "; //$NON-NLS-1$ //$NON-NLS-2$
   s +=
       radians
           ? TrackerRes.getString("TableTrackView.RadiansPerSecond.Tooltip")
           : //$NON-NLS-1$
           TrackerRes.getString("TableTrackView.DegreesPerSecond.Tooltip"); // $NON-NLS-1$
   functionPanel.initEditor.setDescription(FunctionEditor.OMEGA, s);
 }
Example #9
0
 /** Refreshes the GUI. */
 protected void refreshGUI() {
   super.refreshGUI();
   dropdown.setToolTipText(
       TrackerRes.getString("TrackerPanel.DataBuilder.Dropdown.Tooltip")); // $NON-NLS-1$
   setTitle(TrackerRes.getString("TrackerPanel.DataBuilder.Title")); // $NON-NLS-1$
   if (loadButton != null) {
     FunctionPanel panel = getSelectedPanel();
     loadButton.setEnabled(panel != null);
     saveButton.setEnabled(panel != null);
     loadButton.setToolTipText(
         TrackerRes.getString("TrackerPanel.DataBuilder.Button.Load.Tooltip")); // $NON-NLS-1$
     saveButton.setToolTipText(
         TrackerRes.getString("TrackerPanel.DataBuilder.Button.Save.Tooltip")); // $NON-NLS-1$
     autoloadButton.setText(
         TrackerRes.getString("TrackerPanel.DataBuilder.Button.Autoload")
             + "..."); //$NON-NLS-1$ //$NON-NLS-2$
     autoloadButton.setToolTipText(
         TrackerRes.getString("TrackerPanel.DataBuilder.Button.Autoload.Tooltip")); // $NON-NLS-1$
   }
   setFontLevel(FontSizer.getLevel());
   if (autoloadManager != null) {
     autoloadManager.refreshGUI();
   }
 }
Example #10
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;
  }
Example #11
0
  /**
   * Returns a menu with items that control this track.
   *
   * @param trackerPanel the tracker panel
   * @return a menu
   */
  public JMenu getMenu(TrackerPanel trackerPanel) {
    if (inspectorItem == null) {
      // create the model inspector item
      inspectorItem = new JMenuItem();
      inspectorItem.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              positionInspector();
              getInspector().setVisible(true);
            }
          });
      // create the useDefaultRefFrameItem item
      useDefaultRefFrameItem = new JCheckBoxMenuItem();
      useDefaultRefFrameItem.setSelected(!useDefaultReferenceFrame);
      useDefaultRefFrameItem.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              setUseDefaultReferenceFrame(!useDefaultRefFrameItem.isSelected());
              if (ParticleModel.this.trackerPanel.getCoords() instanceof ReferenceFrame) {
                lastValidFrame = -1;
                refreshSteps();
              }
            }
          });
    }
    inspectorItem.setText(
        TrackerRes.getString("ParticleModel.MenuItem.InspectModel")); // $NON-NLS-1$
    useDefaultRefFrameItem.setText(
        TrackerRes.getString("ParticleModel.MenuItem.UseDefaultReferenceFrame")); // $NON-NLS-1$
    // assemble the menu
    JMenu menu = super.getMenu(trackerPanel);

    // remove unwanted menu items and separators
    menu.remove(autotrackItem);
    menu.remove(deleteStepItem);
    menu.remove(clearStepsItem);
    menu.remove(lockedItem);
    menu.remove(autoAdvanceItem);
    menu.remove(markByDefaultItem);
    menu.insert(inspectorItem, 0);
    if (menu.getItemCount() > 1) menu.insertSeparator(1);

    //		// find visible item and insert useDefaultRefFrameItem after it
    //		for (int i=0; i<menu.getMenuComponentCount(); i++) {
    //			if (menu.getMenuComponent(i)==visibleItem) {
    //				menu.insert(useDefaultRefFrameItem, i+1);
    //				break;
    //			}
    //		}

    // eliminate any double separators
    Object prevItem = inspectorItem;
    int n = menu.getItemCount();
    for (int j = 1; j < n; j++) {
      Object item = menu.getItem(j);
      if (item == null && prevItem == null) { // found extra separator
        menu.remove(j - 1);
        j = j - 1;
        n = n - 1;
      }
      prevItem = item;
    }
    return menu;
  }