com.xj.anylogic.engine.presentation
Class ShapeListBox

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.Shape
      extended by com.xj.anylogic.engine.presentation.ShapeControl
          extended by com.xj.anylogic.engine.presentation.ShapeListBox
All Implemented Interfaces:
com.xj.anylogic.engine.internal.Child, Locatable2D, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.event.ListSelectionListener

public class ShapeListBox
extends ShapeControl
implements javax.swing.event.ListSelectionListener

List box control. Embeds a JList component in a JScrollPane.
This object is only available in the AnyLogic Professional

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

Field Summary
 java.lang.String value
          The currently selected item of the list box (or first item of multiselection) that can be accessed in the overridden action() method.
 java.lang.String[] values
          The currently selected items of the list box (in the multiple-selection mode) that can be accessed in the overridden action() method.
 
Fields inherited from class com.xj.anylogic.engine.presentation.ShapeControl
TYPE_DOUBLE, TYPE_INT, TYPE_STRING
 
Fields inherited from class com.xj.anylogic.engine.presentation.Shape
UNKNOWN_NAME
 
Constructor Summary
ShapeListBox(Presentable p, boolean ispublic, int x, int y, int width, int height, java.awt.Color backgroundColor, java.awt.Color textColor, java.awt.Font font, java.lang.String[] items, boolean multipleSelectionMode)
          Creates a persistent list box control.
 
Method Summary
 void action()
          Executes the action associated with a non-persistent list box.
 java.lang.String[] getItems()
          Returns array of String items currently used in this list box
Note that returned array is the same as has been passed to setItems(String[]), and may be null.
 javax.swing.JComponent getJComponent()
          Returns the embedded JScrollPane which has JList as viewport view.
 java.lang.String getValue()
          Returns the currently selected text item if in single-selection mode
or
Returns the first selected text item if in multiple-selection mode

Returns null if there is no selection
 java.lang.String[] getValues()
          Returns an array of selected text items (for use in multiple-selection mode)
Returns empty array if there is no selection
 void setItems(java.lang.String[] items)
          Sets new items for this list box
This method preserves current list box values if current values are contained in new items.
 void setItems(java.lang.String[] items, boolean callAction)
          Sets new items for this list box
This method preserves current list box values if current values are contained in new items.
 void setValue(java.lang.String text)
          Sets the selected text item of the list box.
 void setValue(java.lang.String text, boolean callAction)
          Sets the selected text item of the list box.
 void setValues(java.lang.String[] texts)
          Sets the selected text items of the list box (in the multiple-selection mode)
Clears list box selection if texts is null or empty
Doesn't execute user action code
 void setValues(java.lang.String[] texts, boolean callAction)
          Sets the selected text items of the list box (in the multiple-selection mode)
Clears list box selection if texts is null or empty
Executes user action code (if any exists) if callAction parameter is true
 void setValueToDefault()
          Sets the text of a non-persistent list box to what was provided as the default one.
 void valueChanged(javax.swing.event.ListSelectionEvent e)
          ListSelectionListener implementation.
 
Methods inherited from class com.xj.anylogic.engine.presentation.ShapeControl
clone, contains, draw, getHeight, getPresentable, getWidth, isEnabled, onClickAt, restoreOwner, setEnabled, setHeight, setWidth, update
 
Methods inherited from class com.xj.anylogic.engine.presentation.Shape
canHandleClick, getGroup, getName, getRotation, getScaleX, getScaleY, getX, getY, isVisible, onClick, setPos, setRotation, setScale, setScale, setScaleX, setScaleY, setVisible, setX, setY
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

value

public java.lang.String value
The currently selected item of the list box (or first item of multiselection) that can be accessed in the overridden action() method.
Use getValue() to obtain the currently selected item from other places


values

public java.lang.String[] values
The currently selected items of the list box (in the multiple-selection mode) that can be accessed in the overridden action() method.
Use getValues() to obtain the currently selected items from other places

Constructor Detail

ShapeListBox

public ShapeListBox(Presentable p,
                    boolean ispublic,
                    int x,
                    int y,
                    int width,
                    int height,
                    java.awt.Color backgroundColor,
                    java.awt.Color textColor,
                    java.awt.Font font,
                    java.lang.String[] items,
                    boolean multipleSelectionMode)
Creates a persistent list box control. You should override the action() method, in which you can access the current selection of list box as "values".

Parameters:
p - the presentable object owning this control
ispublic - if true, the control is visible on container's presentation
x - the x coordinate
y - the y coordinate
width - the width
height - the height
backgroundColor - the background color color
textColor - the text color
font - the text font
items - the array of text items of the list box
multipleSelectionMode - if true this list box will support multiple intervals selection, otherwise - only single item selection
Method Detail

action

public void action()
Executes the action associated with a non-persistent list box. This method must be overridden for persistent list boxes.

Specified by:
action in class ShapeControl

getJComponent

public javax.swing.JComponent getJComponent()
Returns the embedded JScrollPane which has JList as viewport view.

Specified by:
getJComponent in class ShapeControl

setValueToDefault

public void setValueToDefault()
Sets the text of a non-persistent list box to what was provided as the default one.
Doesn't execute user action code

Overrides:
setValueToDefault in class ShapeControl

setValue

public void setValue(java.lang.String text)
Sets the selected text item of the list box.
Clears list box selection if text is null
Doesn't execute user action code

Parameters:
text - the new selected text item or null

setValue

public void setValue(java.lang.String text,
                     boolean callAction)
Sets the selected text item of the list box.
Clears list box selection if text is null
Executes user action code (if any exists) if callAction parameter is true

Parameters:
text - the new selected text item or null
callAction - if true user action code (if any exists) will be executed

setValues

public void setValues(java.lang.String[] texts)
Sets the selected text items of the list box (in the multiple-selection mode)
Clears list box selection if texts is null or empty
Doesn't execute user action code

Parameters:
texts - the new selected text items or null

setValues

public void setValues(java.lang.String[] texts,
                      boolean callAction)
Sets the selected text items of the list box (in the multiple-selection mode)
Clears list box selection if texts is null or empty
Executes user action code (if any exists) if callAction parameter is true

Parameters:
texts - the new selected text items or null
callAction - if true user action code (if any exists) will be executed

getValue

public java.lang.String getValue()
Returns the currently selected text item if in single-selection mode
or
Returns the first selected text item if in multiple-selection mode

Returns null if there is no selection

Returns:
the currently selected text item (or first selected item in multiselection)

getValues

public java.lang.String[] getValues()
Returns an array of selected text items (for use in multiple-selection mode)
Returns empty array if there is no selection

Returns:
the currently selected text items

getItems

public java.lang.String[] getItems()
Returns array of String items currently used in this list box
Note that returned array is the same as has been passed to setItems(String[]), and may be null.
The returned array should not be changed by user

Returns:
array of String items currently used in this list box

setItems

public void setItems(java.lang.String[] items)
Sets new items for this list box
This method preserves current list box values if current values are contained in new items.
This method doesn't execute user action code (even if current selection changes).
Note that provided array is used internally and shouldn't be changed by user after this method is called.

Parameters:
items - the array of String items to be placed in this list box

setItems

public void setItems(java.lang.String[] items,
                     boolean callAction)
Sets new items for this list box
This method preserves current list box values if current values are contained in new items.
Note that provided array is used internally and shouldn't be changed by user after this method is called.

Parameters:
items - the array of String items to be placed in this list box
callAction - if true and selection changes, user action code (if any exists) will be executed

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent e)
ListSelectionListener implementation. Starts action execution.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.