Viewing Tracker Data

Figure 7. Tracker with Views

Tracker with views

Tracks are useful in physics because they generate data about real-world phenomena that can be analyzed and compared with theoretical models. Tracker defines a view of its tracker panel to be any Java Container (typically a JPanel) that displays track (or other) data in a useful form. Tracker currently provides several standard views and a mechanism for easily adding new ones.

Views that implement the TView interface have a special advantage: they can be added to a view chooser and selected by the user from a drop-down list. Figure 7 shows Tracker with a plot view, table view and world view displayed in three view choosers. All of the view choosers can display any of the views.

By convention, views that implement TView have class names that end in "TView". The TView interface is very straightforward but will not be discussed here--please see the Javadocs for more information.

Main Video View

MainTView, at the top left in Figure 7, is simply a view of the tracker panel in a scroll pane. Since it draws in imagespace, the video image is fixed. The main video view is where tracks are marked.

Plot and Table Views

PlotTView and TableTView, on the right in Figure 7, both extend TrackChooserTView, a view that shows data for one track at a time. When a track is selected for viewing, the chooser displays a TrackView containing the track's data.

TrackChooserTView methods are shown in Listing 16.

Listing 16. TrackChooserTView Methods

public void setSelectedTrack(TTrack track);
public TTrack getSelectedTrack();
public TrackView getTrackView(TTrack track);

The getTrackView() method will return a PlotTrackView for a plot view and a TableTrackView for a table view. Listing 17 shows methods for these two track view types.

Note: Plot and table views rely on a view chooser to display toolbar components that enable a user to control their properties. Using them without a view chooser is not recommended.

Listing 17. TrackView Methods

PlotTrackView:
public void setPlotCount(int plotCount); // 1 or 2 graphs stacked vertically
public void setXVariable(String name);
public void setYVariable(int plotNumber, String name);

TableTrackView:
public DataTable getDataTable(); // returns osp datatable
public void setVisible(String name, boolean visible);

The name parameter in the above methods is the name of a desired data variable. The available data names are returned by the track's getDataNames() method.

The PlotTrackView.setXVariable() method sets the x-axis variable for both plots. The TableTrackView.setVisible() method shows and hides the specified table data column.

World View

WorldTView, at the bottom left in Figure 7, is a view of the video and tracks drawn in worldspace, the drawing space used by standard drawing panels. This is important because a world view can draw non-trackable (i.e., standard) animations in addition to the trackable video and tracks. In other words, the world view is where real-world data in the video can be directly compared with theoretical model overlays.

Since a world view is a drawing panel, drawable animations are added to it with the usual addDrawable() method. The world view draws the animations after (i.e. on top of) the video and tracks. All tracks that are visible in the main video view are also visible in the world view.

View Chooser

The TViewChooser class, shown in Listing 18, defines methods for managing and selecting (displaying) TViews. A plot view, table view and world view are added to a view chooser when instantiated.

Listing 18. TViewChooser Methods

public void addView(TView view);
public void removeView(TView view);
public Collection getViews();
public TView getView(Class c);
public void setSelectedView(TView view);

TFrame

TFrame, which extends OSPFrame, provides split panes for displaying up to five views at the same time. There is no requirement that the views implement TView. Listing 19 shows the TFrame methods used to manage views and split panes.

Listing 19. TFrame Methods

public void addView(Container view);
public void removeView(Container view);
public void setViews(Container[] views);
public Container[] getViews();
public void setDividerLocation(int paneNumber, double loc); // 0 <= loc <= 1.0

Figure 8 shows where and in what order (array index) TFrame lays out the views. Split pane numbers are shown on the green dividers.

Increasing loc in the setDividerLocation() method moves a vertical divider to the right and a horizontal divider down.

Figure 8. TFrame View and Divider Layout

Main Video View
(always present)

0

View 0

2 1

View 3

View 2

View 1

3

Note: By default, Tracker creates only a main view and three view chooser views (views 0-2) .

Customizing Views

Figure 9. TrackerViewApp

Tracker with custom views

Figure 9 shows a screenshot of TrackerViewApp, a Tracker application that opens a data file and then programmatically customizes the three view choosers. (Physics people: note how the red and blue puck speeds drop significantly during the inelastic collision while the cm slows steadily and gradually due to friction!)

The code fragment that sets up the red puck graph is shown in Listing 20.

Listing 20. TrackerViewApp Code Fragment

// graph the red puck speed in view 1
TFrame frame = tracker.getFrame();
TrackerPanel trackerPanel = tracker.getTrackerPanel();
Container[] views = frame.getViews();
TViewChooser chooser = (TViewChooser)views[0];
PlotTView plot = (PlotTView)chooser.getView(PlotTView.class);
chooser.setSelectedView(plot);
TTrack track = trackerPanel.getTrack("red puck");
plot.setSelectedTrack(track);
PlotTrackView trackView = (PlotTrackView)plot.getTrackView(track);
trackView.setYVariable(0, "v");
frame.setDividerLocation(0, 0.5); // open the split pane to show the plot