Class CenterOfMass

All Implemented Interfaces:
PropertyChangeListener, EventListener, Drawable, Interactive, Measurable, Trackable

public class CenterOfMass extends PointMass
A CenterOfMass tracks the position, velocity and acceleration of the center of mass of a set of point mass objects.
Author:
Douglas Brown
  • Field Details

  • Constructor Details

    • CenterOfMass

      public CenterOfMass()
      Constructs an empty CenterOfMass.
    • CenterOfMass

      public CenterOfMass(PointMass[] masses)
      Constructs a CenterOfMass with specified masses.
      Parameters:
      masses - an array of point masses
  • Method Details

    • draw

      public void draw(DrawingPanel panel, Graphics _g)
      Overrides PointMass draw method.
      Specified by:
      draw in interface Drawable
      Overrides:
      draw in class PointMass
      Parameters:
      panel - the drawing panel requesting the drawing
      _g - the graphics context on which to draw
    • initialize

      public void initialize(TrackerPanel panel)
      Description copied from class: TTrack
      Finish up any unfinished loading business that for whatever reason was not finished upon loading a track. For example, adding masses to a center-of-mass system, or adding particles to a DynamicSystem.
      Overrides:
      initialize in class TTrack
    • addMass

      public void addMass(PointMass m)
      Adds a mass to the cm system.
      Parameters:
      m - the mass
    • removeMass

      public void removeMass(PointMass m)
      Removes a mass from the cm system.
      Parameters:
      m - the mass
    • getMasses

      public PointMass[] getMasses()
      Gets the array of masses in this cm.
      Returns:
      a shallow clone of the masses array
    • containsMass

      public boolean containsMass(PointMass m)
      Determines if the specified point mass is in this center of mass.
      Parameters:
      m - the point mass
      Returns:
      true if m is in this cm
    • findInteractive

      public Interactive findInteractive(DrawingPanel panel, int xpix, int ypix)
      Overrides PointMass findInteractive method.
      Specified by:
      findInteractive in interface Interactive
      Overrides:
      findInteractive in class PointMass
      Parameters:
      panel - the drawing panel
      xpix - the x pixel position on the panel
      ypix - the y pixel position on the panel
      Returns:
      the first step or motion vector that is hit
    • setFontLevel

      public void setFontLevel(int level)
      Description copied from class: PointMass
      Sets the font level.
      Overrides:
      setFontLevel in class PointMass
      Parameters:
      level - the desired font level
    • setLocked

      public void setLocked(boolean locked)
      Overrides TTrack setLocked method. CenterOfMass is always locked.
      Overrides:
      setLocked in class TTrack
      Parameters:
      locked - ignored
    • setMass

      public void setMass(double mass)
      Overrides PointMass setMass method. Mass is determined by masses.
      Overrides:
      setMass in class PointMass
      Parameters:
      mass - ignored
    • isStepComplete

      public boolean isStepComplete(int n)
      Overrides TTrack isStepComplete method. Always returns true.
      Overrides:
      isStepComplete in class TTrack
      Parameters:
      n - the frame number
      Returns:
      true always since cm gets data from point masses
    • isDependent

      public boolean isDependent()
      Overrides TTrack isDependent method to return true.
      Overrides:
      isDependent in class TTrack
      Returns:
      true if this track is dependent
    • isAutoTrackable

      protected boolean isAutoTrackable()
      Determines if any point in this track is autotrackable.
      Overrides:
      isAutoTrackable in class PointMass
      Returns:
      true if autotrackable
    • setTrackerPanel

      public void setTrackerPanel(TrackerPanel panel)
      Adds events for TrackerPanel.
      Overrides:
      setTrackerPanel in class PointMass
      Parameters:
      panel - the new TrackerPanel
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Responds to property change events.
      Specified by:
      propertyChange in interface PropertyChangeListener
      Overrides:
      propertyChange in class PointMass
      Parameters:
      e - the property change event
    • dispose

      public void dispose()
      Cleans up associated resources when this track is deleted or cleared.
      Overrides:
      dispose in class PointMass
    • getMenu

      public JMenu getMenu(TrackerPanel trackerPanel, JMenu menu0)
      Returns a menu with items that control this track.
      Overrides:
      getMenu in class PointMass
      Parameters:
      trackerPanel - the tracker panel
      menu0 - the menu. If null, a dynamic menu is returned that adds items only when selected
      Returns:
      a menu
    • getToolbarTrackComponents

      public ArrayList<Component> getToolbarTrackComponents(TrackerPanel trackerPanel)
      Overrides TTrack getToolbarTrackComponents method.
      Overrides:
      getToolbarTrackComponents in class PointMass
      Parameters:
      trackerPanel - the tracker panel
      Returns:
      the DataSetManager
    • getToolbarPointComponents

      public ArrayList<Component> getToolbarPointComponents(TrackerPanel trackerPanel, TPoint point)
      Overrides TTrack getToolbarPointComponents method.
      Overrides:
      getToolbarPointComponents in class PointMass
      Parameters:
      trackerPanel - the tracker panel
      point - the TPoint
      Returns:
      a list of components
    • toString

      public String toString()
      Overrides PointMass toString method.
      Overrides:
      toString in class TTrack
      Returns:
      a description of this object
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns an ObjectLoader to save and load data for this class.
      Returns:
      the object loader
    • getInspector

      public CenterOfMassInspector getInspector()
      Gets the center of mass inspector.
      Returns:
      the center of mass inspector