Slider

The control that lets a user graphically select a numeric value within a bounded interval by sliding the knob.

Slider elements are commonly used for modifying values of numeric variables and parameters at the model runtime.

Use sliders to choose an integer value from the defined range. To set real values use text input in the edit boxes instead.

Demo model: Slider Linked To Parameter

 To add a slider

  1. Drag the  Slider element from the  Controls palette into the graphical editor.
  2. Navigate to the Properties view.
  3. Using the Orientation group of buttons, choose, whether you want your slider to be Horizontal or Vertical.
  4. You may want to bind a slider with a numeric variable or parameter (on changing the value of the slider, the linked parameter/variable immediately gets this value). To learn how to link a slider to a parameter, refer here.
  5. You can also define any action to be executed each time the slider's value is changed. Type the code you want to execute into the Action section of the slider's properties (the current value of the slider is available here as value (local variable of type double)). 
  6. If you want to add labels displaying minimum, current and maximum values of the slider, click the Add labels button in the slider's properties. You will see min, value and max labels added to the slider. Their dynamic properties are set up to display min, current and max values of the slider at the model runtime. These labels are regular text shapes, which can be relocated, resized, deleted and recolored.  

Properties

General

Name – The name of the slider. It is used to identify and access the control from code.

Ignore – If selected, the slider will be excluded from the model.

Visible on upper level – If selected, the control will be also visible on the upper level where this agent lives.

Icon – If selected, the slider will be considered as a part of the agent's icon.

Orientation – Orientation of the slider, either Vertical or Horizontal.  

Add labels – Click this button to add labels displaying maximum, minimum and current values of the slider (min, value, max).  The dynamic properties of the labels are set up to display min, current and max values of the slider at the model runtime. These labels are regular text shapes, which can be relocated, resized, deleted and recolored.  

Link to – If you want to bind the slider with a numeric variable or a parameter (on changing the value of the slider, the linked variable/parameter immediately gets this value), select this checkbox and enter the name of the variable/parameter that you want to link to the slider.

Minimum value – The minimum value of the slider. 

Maximum value – The maximum value of the slider. 

Default value – [Visible if the Link to checkbox is not selected] The expression of type double that defines the default slider value. If this slider is linked to some variable or parameter, it uses the default value of this variable/parameter (or the nearest possible value from the slider's range of available values) as its default value.

Enabled – Here you can specify Boolean expression determining whether the slider is enabled or disabled.

Action

Here you can type the code to execute when the user changes the slider position. The current value of the slider is available here as value (variable of type double).

Appearance

Background color – The control specifies the background color for the slider. Click inside the control and choose a color from the set of the most used ones, or choose a custom color using the Colors dialog box.

Position and size

X – X-coordinate of the control's upper left corner.

Y – Y-coordinate of the control's upper left corner.

Width – The width of the control (in pixels).

Height – The height of the control (in pixels).

Advanced

Visible – The control's visibility.  The control is visible when the specified expression evaluates to true, otherwise it is not visible.

Replication – Here you specify the number copies of this control you want to be created. If you leave this field empty, only one such control will be created.

Show name – If selected, the name of the control will be displayed on a presentation diagram.

Linking a slider to a numeric parameter/variable

A slider is frequently bound with a numeric variable or a parameter (on changing the value of the slider, the linked parameter/variable immediately gets this value).

 To link a slider to a parameter

  1. In the slider's properties, select the Link to checkbox and choose the parameter/variable from the combo-box to the right:
  1. The pop-up list shows the names of all parameters and variables of the valid types, and also all the flowchart blocks present on the diagram of this agent. To link to a parameter, just select the parameter in the list. 
  2. If you want to link the slider to a parameter of a flowchart block (e.g., capacity of queue block), you should first select the flowchart block's name in the drop-down list, and then choose the parameter from the Parameter drop-down list below:

Another way to link to a parameter is to select the required parameter, or the flowchart block in the graphical editor.

 To link a slider to a parameter by selecting it in the graphical editor

  1.  Select the Link to option, and then click the button to the right of the drop-down list. 
  1. If you are linking your slider to a parameter, select the parameter in the graphical editor. If you want to link to a parameter of a flowchart block, select the corresponding flowchart block: 
  1. You will see the dialog box showing the list of parameters of the flowchart block that you can link a slider to. Select the required parameter from the list, and its name will be automatically inserted in the corresponding property of the slider.

Functions

Obtaining the current value

Function

Description

double getValue()

Returns the current value of the slider. 

int getIntValue()

Returns the current int value of the slider.
This function may only be used in sliders with value type ShapeControl.TYPE_INT.


Setting new value

Function

Description

void setValue
(double value)

Sets the value of the slider. Action is executed in the same thread.

Doesn't execute user action code.

Parameter:
val - the new value

void setValue
(double value,
boolean callAction)

Sets the value of the slider. Action is executed in the same thread.

Executes user action code (if there is any) if the callAction parameter is true.

Parameters:
value - the new value
callAction - if true, user action code will be executed (if there is any).

void setValueToDefault()

Sets the value of the slider to what was provided as the default one.

Doesn't execute user action code.


Values range

Function

Description

double getMin()

Returns the minimum value of the slider. 

double getMax()

Returns the maximum value of the slider. 

void setRange
(double min, 
double max)

Sets the minimum and maximum values of the slider.

Doesn't execute user action code.

If the slider is configured to work with int values, the given [min, max] range may be automatically corrected to have integer bounds (within the given double bounds).

This function does nothing if the slider already has such range.

Parameters:
min - the new minimum value
max - the new maximum value

void setRange
(double min,
double max,
boolean callAction)

Sets the minimum and maximum values of the slider.

If the value of the current slider changes, the function will execute user action code (if there is any) in the same thread - if the callAction parameter is true.

If slider is configured to work with int values, the given [min, max] range may be automatically corrected to have integer bounds (within the given double bounds).

This function does nothing if the slider already has such range.

Parameters:
min - the new minimum value
max - the new maximum value
callAction - if true, user action code will be executed if the current slider value changes (if there is any)


Enabling/disabling the control

Function

Description

boolean isEnabled()

Tests if the control is enabled or disabled. Returns true if enabled, otherwise false.

void setEnabled
(boolean yes)

Sets the control enabled or disabled.

Parameter:
yes - If true, the control will be enabled, if false - disabled. 


Executing the slider action programmatically

Function

Description

void action()

Executes the action associated with the slider.


Slider position

Function

Description

double getX()

Returns the X coordinate of the control (namely, the X coordinate of its upper left corner).

double getY()

Returns the Y coordinate of the control (namely, the Y coordinate of its upper left corner).

void setX(double x)

Sets the X coordinate of the control.

Parameter:
x - the new value of X coordinate

void setY(double y)

Sets the Y coordinate of the control.

Parameter:
y - the new value of Y coordinate

void setPos(double x,
double y)

Sets new coordinates for the control.

Parameters:
x - the new value of x coordinate
y - the new value of y coordinate


Slider visibility

Function

Description

boolean isVisible()

Returns the visibility of the control.

void setVisible(boolean v)

Sets the visibility of the control.

Parameter:
v - visibility: if true - the control is set to be visible, if false - not visible.


Related topics

 Aligning shapes

           API reference: ShapeSlider class