Application models can define custom menu items that appear under the Application menu in the main ArtiSynth menu bar.
This can be done by implementing the interface HasMenuItems in either the RootModel or any of its top-level components (e.g., models, controllers, probes, etc.). The interface contains a single method
which, if the component has menu items to add, should append them to items and return true.
The RootModel and all models derived from ModelBase implement HasMenuItems by default, but with getMenuItems() returning false. Models wishing to add menu items should override this default declaration. Other component types, such as controllers, need to explicitly implement HasMenuItems.
Note: the Application menu will only appear if getMenuItems() returns true for either the RootModel or one or more of its top-level components.
getMenuItems() will be called each time the Application menu is selected, so the menu itself is created on demand and can be varied to suite the current system state. In general, it should return items that are capable of being displayed inside a Swing JMenu; other items will be ignored. The most typical item is a Swing JMenuItem. The convenience method createMenuItem(listener,text,toolTip) can be used to quickly create menu items, as in the following code segment:
This creates three menu items, each with this specified as an ActionListener and no tool-tip text, and appends them to items. They will then appear under the Application menu as shown in Figure 5.13.
To actually execute the menu commands, the items returned by getMenuItems() need to be associated with an ActionListener (defined in java.awt.event), which supplies the method actionPerformed() which is called when the menu item is selected. Typically the ActionListener is the component implementing HasMenuItems, as was assumed in the example declaration of getMenuItems() shown above. RootModel and other models derived from ModelBase implement ActionListener by default, with an empty declaration of actionPerformed() that should be overridden as required. A declaration of actionPerformed() capable of handling the menu example above might look like this:
Numeric probe data can also be smoothed, which is convenient for removing noise from either input or output data. Different smoothing methods are available; at the time of this writing, they include:
Applies a mean average filter across the knots, using a moving window whose size is specified by the window size field. The window is centered on each knot, and is reduced in size near the end knots to ensure a symmetric fit. The end knot values are not changed. The window size must be odd and the window size field enforces this.
Applies Savitzky-Golay smoothing across the knots, using a moving
window of size . Savitzky-Golay smoothing works by fitting the
data values in the window to a polynomial of a specified degree
, and
using this to recompute the value in the middle of the window. The
polynomial is also used to interpolate the first and last
values, since it is not possible to center the window on these.
The window size and the polynomial degree
are specified by the
window size and polynomial degree fields.
must be odd,
and must also be larger than
, and the fields enforce these
constraints.
These operations may be applied with the following numeric probe methods:
void smoothWithMovingAverage (double winSize) |
Moving average smoothing over a specified window. |
void smoothWithSavitzkyGolay ( Mdouble winSize, int deg) |
Savitzky Golay smoothing with specified window and degree. |
XXX talk about target positions