Class Model
- java.lang.Object
-
- org.csstudio.trends.databrowser3.model.Model
-
public class Model extends Object
Data Browser modelMaintains a list of
ModelItem
s- 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 Summary
Constructors Constructor Description Model()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)void
addAxis(int index, AxisConfig axis)
Add axis at given index.void
addAxis(AxisConfig axis)
void
addItem(ModelItem item)
Add item to the model.void
addListener(ModelListener listener)
void
clear()
Remove all items and axesvoid
dispose()
Dispose all items, remove all listenersvoid
fireAxisChangedEvent(Optional<AxisConfig> axis)
Notify listeners of changed axis configurationvoid
fireSelectedSamplesChanged()
Fire event that indicates change in selected samplesList<AnnotationInfo>
getAnnotations()
ArchiveRescale
getArchiveRescale()
List<AxisConfig>
getAxes()
AxisConfig
getAxis(int index)
Get specific axis.int
getAxisCount()
Get number of axesint
getAxisIndex(AxisConfig axis)
Locate index of value axisOptional<AxisConfig>
getEmptyAxis()
ModelItem
getFirstItemOnAxis(AxisConfig axis)
Optional<FormulaItem>
getFormulaWithInput(ModelItem item)
Find a formula that uses a model item as an input.ModelItem
getItem(String name)
Locate item by name.ModelItem
getItemByUniqueId(String uniqueId)
List<ModelItem>
getItems()
javafx.scene.text.Font
getLabelFont()
javafx.scene.text.Font
getLegendFont()
javafx.scene.paint.Color
getPlotBackground()
javafx.scene.paint.Color
getPlotForeground()
javafx.scene.text.Font
getScaleFont()
Duration
getScrollStep()
TimeRelativeInterval
getTimerange()
String[]
getTimerangeText()
static String[]
getTimerangeText(TimeRelativeInterval range)
Optional<String>
getTitle()
javafx.scene.text.Font
getTitleFont()
double
getUpdatePeriod()
boolean
hasAxisActiveItems(AxisConfig axis)
boolean
isGridVisible()
boolean
isLegendVisible()
boolean
isToolbarVisible()
void
load(Model other)
Load state from another modelvoid
moveItem(ModelItem item, boolean up)
Move item in model.void
removeAxis(AxisConfig axis)
void
removeItem(ModelItem item)
Remove item from the model.void
removeListener(ModelListener listener)
String
resolveMacros(String text)
Resolve macrosvoid
setAnnotations(List<AnnotationInfo> annotations)
void
setArchiveRescale(ArchiveRescale archive_rescale)
void
setGridVisible(boolean grid)
void
setLabelFont(javafx.scene.text.Font font)
void
setLegendFont(javafx.scene.text.Font font)
void
setLegendVisible(boolean legend)
void
setMacros(MacroValueProvider other)
void
setPlotBackground(javafx.scene.paint.Color rgb)
void
setPlotForeground(javafx.scene.paint.Color rgb)
void
setSaveChanges(boolean save_changes)
void
setScaleFont(javafx.scene.text.Font font)
void
setScrollStep(Duration step)
void
setTimerange(TimeRelativeInterval range)
void
setTitle(String title)
void
setTitleFont(javafx.scene.text.Font font)
void
setToolbarVisible(boolean toolbar)
void
setUpdatePeriod(double period_secs)
boolean
shouldSaveChanges()
void
start()
Start all items: Connect PVs, initiate scanning, ...void
stop()
Stop all items: Disconnect PVs, ...boolean
updateItemsAndCheckForNewSamples()
Test if any ModelItems received new samples, if formulas need to be re-computed, since the last time this method was called.
-
-
-
Method Detail
-
clear
public void clear()
Remove all items and axes
-
load
public void load(Model other) throws Exception
Load state from another modelTakes 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 benull
or empty
-
getAxes
public List<AxisConfig> getAxes()
- Returns:
- Read-only, thread safe
AxisConfig
s
-
getAxisCount
public int getAxisCount()
Get number of axesThread-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.
-
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 moveup
- 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
-
getTimerange
public TimeRelativeInterval getTimerange()
- Returns:
- time range
-
getTimerangeText
public String[] getTimerangeText()
- Returns:
- Start and end specification as text
-
getTimerangeText
public static String[] getTimerangeText(TimeRelativeInterval range)
- Parameters:
range
-TimeRelativeInterval
- 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
-
-