Class Model


  • public class Model
    extends Object
    Data Browser model

    Maintains a list of ModelItems

    Author:
    Kay Kasemir, Takashi Nakamoto changed the model to accept multiple items with the same name so that Data Browser can show the trend of the same PV in different axes or with different waveform indexes., Megan Grodowitz ported from databrowser 2 (SWT) to databrowser 3 (JFX under RCP)
    • Constructor Detail

      • Model

        public Model()
    • Method Detail

      • clear

        public void clear()
        Remove all items and axes
      • load

        public void load​(Model other)
                  throws Exception
        Load state from another model

        Takes shortcuts by directly copying data from other model. Only permitted when this model has no items. The other Model should not be used after it has been loaded into this model.

        Parameters:
        other - Other model to load
        Throws:
        Exception - on error
      • shouldSaveChanges

        public boolean shouldSaveChanges()
        Returns:
        Should UI ask to save changes to the model?
      • setSaveChanges

        public void setSaveChanges​(boolean save_changes)
        Parameters:
        save_changes - Should UI ask to save changes to the model?
      • setMacros

        public void setMacros​(MacroValueProvider other)
        Parameters:
        other - Macros to use in this model
      • resolveMacros

        public String resolveMacros​(String text)
        Resolve macros
        Parameters:
        text - Text that might contain "$(macro)"
        Returns:
        Text with all macros replaced by their value
      • addListener

        public void addListener​(ModelListener listener)
        Parameters:
        listener - New listener to notify
      • removeListener

        public void removeListener​(ModelListener listener)
        Parameters:
        listener - Listener to remove
      • setTitle

        public void setTitle​(String title)
        Parameters:
        title - Title, may be null or empty
      • getAxisCount

        public int getAxisCount()
        Get number of axes

        Thread-safe access to multiple axes should use getAxes()

        Returns:
        Number of axes
      • getAxis

        public AxisConfig getAxis​(int index)
        Get specific axis. If the axis for the specified index does not exist, method returns null.

        Thread-safe access to multiple axes should use getAxes()

        Parameters:
        index - Axis index
        Returns:
        AxisConfig or null if the config for the given index does not exist
      • getAxisIndex

        public int getAxisIndex​(AxisConfig axis)
        Locate index of value axis
        Parameters:
        axis - Value axis configuration
        Returns:
        Index of axis (0, ...) or -1 if not in Model
      • getFirstItemOnAxis

        public ModelItem getFirstItemOnAxis​(AxisConfig axis)
        Parameters:
        axis - Axis to test
        Returns:
        First ModelItem that uses the axis, visible or not. null if axis is empty
      • hasAxisActiveItems

        public boolean hasAxisActiveItems​(AxisConfig axis)
        Parameters:
        axis - Axis to test
        Returns:
        true if there is any visible item on the axis
      • getEmptyAxis

        public Optional<AxisConfig> getEmptyAxis()
        Returns:
        First unused axis (no items on axis)
      • addAxis

        public AxisConfig addAxis()
        Add value axis with default settings Sets name of new axis to Value N N is found by searching for all the existing axes with the name Value X; N is set to the highest value of X found + 1 (this scheme should avoid the creation of axes with duplicate names of the format Value N)
        Returns:
        Newly added axis configuration
      • addAxis

        public void addAxis​(AxisConfig axis)
        Parameters:
        axis - New axis to add
      • addAxis

        public void addAxis​(int index,
                            AxisConfig axis)
        Add axis at given index. Adding at '1' means the new axis will be at index '1', and what used to be at '1' will be at '2' and so on.
        Parameters:
        index - Index where axis will be placed.
        axis - New axis to add
      • removeAxis

        public void removeAxis​(AxisConfig axis)
        Parameters:
        axis - Axis to remove
        Throws:
        Error - when axis not in model, or axis in use by model item
      • getArchiveRescale

        public ArchiveRescale getArchiveRescale()
        Returns:
        How should plot rescale after archived data arrived?
      • setArchiveRescale

        public void setArchiveRescale​(ArchiveRescale archive_rescale)
        Parameters:
        archive_rescale - How should plot rescale after archived data arrived?
      • getItem

        public ModelItem getItem​(String name)
        Locate item by name.

        Note that the model may contain multiple items for the same name. The first occurrence will be returned. If no item is found with the given name, null will be returned. Now that this model may have different items with the same name, this method is not recommended to locate an item. This method just returns an item which just happens to have the given name.

        Parameters:
        name - Name of item
        Returns:
        ModelItem by that name or null
      • getFormulaWithInput

        public Optional<FormulaItem> getFormulaWithInput​(ModelItem item)
        Find a formula that uses a model item as an input.
        Parameters:
        item - Item that's potentially used in a formula
        Returns:
        First FormulaItem that uses this item
      • addItem

        public void addItem​(ModelItem item)
                     throws Exception
        Add item to the model.

        If the item has no color, this will define its color based on the model's next available color.

        If the model is already 'running', the item will be 'start'ed.

        Parameters:
        item - ModelItem to add
        Throws:
        Exception - if item is already in model or has other error
      • removeItem

        public void removeItem​(ModelItem item)
        Remove item from the model.

        If the model and thus item are 'running', the item will be 'stopped'.

        Parameters:
        item - Item to remove
        Throws:
        RuntimeException - if item not in model
      • moveItem

        public void moveItem​(ModelItem item,
                             boolean up)
        Move item in model.

        Parameters:
        item - Item to move
        up - Up? Otherwise down
        Throws:
        RuntimeException - if item null or not in model
      • getUpdatePeriod

        public double getUpdatePeriod()
        Returns:
        Period in seconds for scrolling or refreshing
      • setUpdatePeriod

        public void setUpdatePeriod​(double period_secs)
        Parameters:
        period_secs - New update period in seconds
      • getScrollStep

        public Duration getScrollStep()
        Returns:
        Scroll step size
      • setScrollStep

        public void setScrollStep​(Duration step)
                           throws Exception
        Parameters:
        step - New scroll step
        Throws:
        Exception - if step size cannot be used
      • getTimerangeText

        public String[] getTimerangeText()
        Returns:
        Start and end specification as text
      • setTimerange

        public void setTimerange​(TimeRelativeInterval range)
        Parameters:
        range - Time range
      • getPlotForeground

        public javafx.scene.paint.Color getPlotForeground()
        Returns:
        foreground color
      • setPlotForeground

        public void setPlotForeground​(javafx.scene.paint.Color rgb)
        Parameters:
        rgb - New foreground color
      • getPlotBackground

        public javafx.scene.paint.Color getPlotBackground()
        Returns:
        Background color
      • setPlotBackground

        public void setPlotBackground​(javafx.scene.paint.Color rgb)
        Parameters:
        rgb - New background color
      • isToolbarVisible

        public boolean isToolbarVisible()
        Returns:
        true if toolbar is visible
      • setToolbarVisible

        public void setToolbarVisible​(boolean toolbar)
        Parameters:
        toolbar - Should toolbar be visible?
      • isLegendVisible

        public boolean isLegendVisible()
        Returns:
        true if legend is visible
      • setLegendVisible

        public void setLegendVisible​(boolean legend)
        Parameters:
        legend - Should legend be visible?
      • isGridVisible

        public boolean isGridVisible()
        Returns:
        true if grid lines are drawn
      • setGridVisible

        public void setGridVisible​(boolean grid)
        Parameters:
        grid - Should grid be visible?
      • getTitleFont

        public javafx.scene.text.Font getTitleFont()
        Returns:
        Title font
      • setTitleFont

        public void setTitleFont​(javafx.scene.text.Font font)
        Parameters:
        font - Title font
      • getLabelFont

        public javafx.scene.text.Font getLabelFont()
        Returns:
        Label font
      • setLabelFont

        public void setLabelFont​(javafx.scene.text.Font font)
        Parameters:
        font - Label font
      • getScaleFont

        public javafx.scene.text.Font getScaleFont()
        Returns:
        Scale font
      • setScaleFont

        public void setScaleFont​(javafx.scene.text.Font font)
        Parameters:
        font - Scale font
      • getLegendFont

        public javafx.scene.text.Font getLegendFont()
        Returns:
        Legend font
      • setLegendFont

        public void setLegendFont​(javafx.scene.text.Font font)
        Parameters:
        font - Scale font
      • setAnnotations

        public void setAnnotations​(List<AnnotationInfo> annotations)
        Parameters:
        annotations - Annotations to keep in model
      • getAnnotations

        public List<AnnotationInfo> getAnnotations()
        Returns:
        Annotation infos of model
      • start

        public void start()
                   throws Exception
        Start all items: Connect PVs, initiate scanning, ...
        Throws:
        Exception - on error
      • stop

        public void stop()
        Stop all items: Disconnect PVs, ...
      • updateItemsAndCheckForNewSamples

        public boolean updateItemsAndCheckForNewSamples()
        Test if any ModelItems received new samples, if formulas need to be re-computed, since the last time this method was called.
        Returns:
        true if there were new samples
      • fireAxisChangedEvent

        public void fireAxisChangedEvent​(Optional<AxisConfig> axis)
        Notify listeners of changed axis configuration
        Parameters:
        axis - Axis that changed, empty to add/remove
      • fireSelectedSamplesChanged

        public void fireSelectedSamplesChanged()
        Fire event that indicates change in selected samples
      • dispose

        public void dispose()
        Dispose all items, remove all listeners
      • getItemByUniqueId

        public ModelItem getItemByUniqueId​(String uniqueId)
        Parameters:
        uniqueId - Non-null unique id.
        Returns:
        A ModelItem matching the specified unique id, or null.