File Chooser

File chooser provides a simple mechanism for navigating through the file system with either choosing a file from the list or entering the name of the required file.

You may take a look at the simple demo model where the File chooser is combined with the Text file object making it possible for the user of the model to choose a file (e.g. with the model parameters) before starting the model.

Demo model: File Chooser For Text Files

 To add a file chooser

  1. Drag the  File Chooser element from the  Controls palette into the graphical editor.
  2. From the Type group of buttons, choose the type of the file chooser dialog. Choose Open, if you want to bring up a file chooser that the user can use to open a file. Likewise, use Save to allow the user to choose a file for saving.
  3. In the Title box, specify the title of the dialog box, that will be opened on clicking the file chooser.

Properties

General

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

Ignore – If selected, the file chooser 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.

Type – The type of the dialog. Choose Open if you want to bring up a file chooser that the user will be able to use to open a file. Likewise, use Save for letting the user choose a file for saving.

Title – The title of the dialog box. 

File name filters – The table where a user can define file name filters for the file chooser. Each filter is specified in the individual row of the table. You must define Filter Name and File Extensions for each file filter. 

Action

Here you can type the code to execute when the user opens/saves a file using this file chooser. The name of the currently selected file is available here as value (local variable of type String).

Appearance
Background color – The control specifies the background color for the file chooser. 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.
Background color is correctly displayed under Windows with Classic appearance. However, certain operating systems may not support file choosers with user-defined background colors (Windows XP with XP-style appearance, Windows Vista with Windows Vista Basic or Windows Aero appearance).

Text color – The control specifies the color of the text displaying the selected file name inside the file chooser shape. 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.

Font – Specifies the font family for the text displaying the selected file name inside the file chooser shape. You can adjust the size of the text in the field to the right (pt.).

Italic – If checked, the name of the selected file displayed inside the file chooser shape will be italicized.

Bold – If checked, the name of the selected file displayed inside the file chooser shape will be emphasized in bold.

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 of 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 the presentation diagram.

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

Functions

File chooser value

Function

Description

String getValue()

Returns the currently selected file name or empty string if no file is selected.

void setValue
(String fileName)

Sets the selected filename to given fileName.

Doesn't execute user action code.

Parameter:
fileName - the file name

void setValue(String fileName,
boolean callAction)

Sets the selected filename to given fileName.

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

Parameters:
fileName - the file name
callAction - if true user action code (if any exists) will be executed

void setValueToDefault()

Sets the selected filename of the file chooser to what was provided as the default one.

Doesn't execute user action code.


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 file chooser action programmatically

Function

Description

void action()

Executes the action associated with a file chooser.


Control 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


Control size

Function

Description

double getWidth()

Returns the width of the control, in pixels.

double getHeight()

Returns the height of the control, in pixels.

void setWidth(double width)

Sets the width of the control equal to width.

void setHeight(double height)

Sets the height of the control equal to height.


Control 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: ShapeFileChooser class