com.mindfusion.diagramming
Class ShapeListBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JList
                  extended by com.mindfusion.diagramming.ShapeListBox
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable

public class ShapeListBox
extends javax.swing.JList

The ShapeListBox control displays a set of shapes defined via the Shape class.

Shapes from the list box can be dragged to the Diagram drawing canvas to create new boxes. Changing the shape of an existing box can be implemented by handling the ShapeListBoxListener.shapeSelected(com.mindfusion.diagramming.Shape, int) event and assigning the selected shape to a box by calling ShapeNode.setShape(com.mindfusion.diagramming.Shape).

Initially, the ShapeListBox displays all shapes accessible via Shape.fromId(java.lang.String). You can limit the list to only a subset of the available shapes by calling the setShapeFilter(java.lang.String[]) method. It is also possible to load a shape library from a file using the ShapeLibrary class, and display the loaded shapes as shown below:

ShapeLibrary lib = ShapeLibrary.loadFrom("shapeLib.shl"); shapeListBox.setShapes(lib.getShapes());

The control creates an icon image for each shape added. The size of an icon displayed in the list box can be defined via the setIconSize(java.awt.Dimension) method, and setIconMargin(java.awt.Dimension) specifies the horizontal and vertical margin of the icon.

If the AllowRename property is enabled, users can press the F2 key and rename a shape in the list box. When a shape is renamed, the ShapeListBoxListener.shapeRenamed(com.mindfusion.diagramming.Shape, int, java.lang.String) event is raised. If AllowRemove is enabled, list box items can be deleted by pressing the Del key. When a shape is removed, the ShapeListBoxListener.shapeRemoved(com.mindfusion.diagramming.Shape, int) event is raised.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JList
javax.swing.JList.AccessibleJList
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JList
HORIZONTAL_WRAP, VERTICAL, VERTICAL_WRAP
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ShapeListBox()
          Initializes a new instance of the ShapeListBox class.
 
Method Summary
 void addShape(Shape shape)
          Adds a single Shape to the list box.
 void addShapeListener(ShapeListBoxListener l)
          Adds a listener for select, rename and delete events.
 void addShapes(Shape[] shapes)
          Adds an array of Shape objects to the list box.
 void addShapes(ShapeList shapes)
          Adds a list of Shape objects to the list box.
 void clearShapes()
          Removes all shapes from the ShapeListBox, leaving it empty
protected  void fireShapeRemoved(Shape shape, int index)
           
protected  void fireShapeRenamed(Shape shape, int i, java.lang.String oldName)
           
protected  void fireShapeSelected(Shape shape, int index)
           
 boolean getAllowRemove()
          Gets a value indicating whether deletion of listbox items by pressing Del is allowed.
 boolean getAllowRename()
          Gets a value indicating whether inline renaming of listbox items is allowed.
 java.awt.geom.Point2D getDefaultShapeSize()
          Gets the size of the shape that is created when dragging items from the list box to the flowchart.
 java.awt.Dimension getIconMargin()
          Gets the horizontal and vertical margins of the shape icons in the ListBox
 java.awt.Dimension getIconSize()
          Gets the size of the shape icons displayed in the ListBox.
 Shape getShapeAt(int index)
          Returns the Shape at the specified index.
 int getShapeCount()
          Returns the number of shapes after filtering.
 java.awt.Color getShapeFillColor()
          Gets the fill color of the shapes in the list box.
 java.lang.String[] getShapeFilter()
          Gets the identifiers of the shapes that should be displayed in the list box.
 Shape[] getShapes()
          Retrieves all shapes visible in the list box after filtering.
 boolean getShowLabels()
          Gets a value indicating whether to show text labels along with icons for each list item.
 void invalidateShapeAt(int i)
          Invalidates the specified shape, causing its icon to be recreated and redrawn.
protected  void onKeyDown(java.awt.event.KeyEvent e)
           
protected  void paintComponent(java.awt.Graphics g)
           
 void removeShapeAt(int i)
          Removes a shape from the list box.
 void removeShapeListener(ShapeListBoxListener l)
          Removes previously added listener for select, rename and delete events
 void resumeRepaint()
          Resumes repainting the control after a suspendRepaint() call.
 void setAllowRemove(boolean value)
           
 void setAllowRename(boolean value)
          Sets a value specifying whether inline renaming of listbox items is allowed.
 void setDefaultShapeSize(java.awt.geom.Point2D.Float value)
          Sets the size of the shape that is created when dragging items from the list box to the flowchart.
 void setIconMargin(java.awt.Dimension value)
          Sets the horizontal and vertical margins of the shape icons in the ListBox
 void setIconSize(java.awt.Dimension value)
          Sets the size of the shape icons displayed in the ListBox.
 void setShapeAt(int index, Shape shape)
          Sets the shape at the specified position.
 void setShapeFillColor(java.awt.Color value)
          Sets the fill color of the shapes in the list box.
 void setShapeFilter(java.lang.String[] value)
          Sets the identifiers of the shapes that should be displayed in the list box.
 void setShapes(Shape[] shapes)
          Replaces all current shapes with the specified ones.
 void setShowLabels(boolean value)
           
 void startInlineEdit()
          Initiates inline editing of shape id.
 void suspendRepaint()
          Stops repainting the control.
 
Methods inherited from class javax.swing.JList
addListSelectionListener, addSelectionInterval, clearSelection, createSelectionModel, ensureIndexIsVisible, fireSelectionValueChanged, getAccessibleContext, getAnchorSelectionIndex, getCellBounds, getCellRenderer, getDragEnabled, getFirstVisibleIndex, getFixedCellHeight, getFixedCellWidth, getLastVisibleIndex, getLayoutOrientation, getLeadSelectionIndex, getListSelectionListeners, getMaxSelectionIndex, getMinSelectionIndex, getModel, getNextMatch, getPreferredScrollableViewportSize, getPrototypeCellValue, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedIndex, getSelectedIndices, getSelectedValue, getSelectedValues, getSelectionBackground, getSelectionForeground, getSelectionMode, getSelectionModel, getToolTipText, getUI, getUIClassID, getValueIsAdjusting, getVisibleRowCount, indexToLocation, isSelectedIndex, isSelectionEmpty, locationToIndex, paramString, removeListSelectionListener, removeSelectionInterval, setCellRenderer, setDragEnabled, setFixedCellHeight, setFixedCellWidth, setLayoutOrientation, setListData, setListData, setModel, setPrototypeCellValue, setSelectedIndex, setSelectedIndices, setSelectedValue, setSelectionBackground, setSelectionForeground, setSelectionInterval, setSelectionMode, setSelectionModel, setUI, setValueIsAdjusting, setVisibleRowCount, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ShapeListBox

public ShapeListBox()
Initializes a new instance of the ShapeListBox class.

Method Detail

onKeyDown

protected void onKeyDown(java.awt.event.KeyEvent e)

getIconMargin

public java.awt.Dimension getIconMargin()
Gets the horizontal and vertical margins of the shape icons in the ListBox

Returns:
A Dimension object specifying the margins size.

setIconMargin

public void setIconMargin(java.awt.Dimension value)
Sets the horizontal and vertical margins of the shape icons in the ListBox

Parameters:
value - A Dimension object specifying the margins size.

getIconSize

public java.awt.Dimension getIconSize()
Gets the size of the shape icons displayed in the ListBox.

Returns:
A Dimension object specifying the icon size.

setIconSize

public void setIconSize(java.awt.Dimension value)
Sets the size of the shape icons displayed in the ListBox.

Parameters:
value - A Dimension object specifying the icon size.

getDefaultShapeSize

public java.awt.geom.Point2D getDefaultShapeSize()
Gets the size of the shape that is created when dragging items from the list box to the flowchart.

Returns:
A Point2D object representing the default ShapeNode size.

setDefaultShapeSize

public void setDefaultShapeSize(java.awt.geom.Point2D.Float value)
Sets the size of the shape that is created when dragging items from the list box to the flowchart.

Parameters:
value - A Point2D object representing the default ShapeNode size.

getShapeFillColor

public java.awt.Color getShapeFillColor()
Gets the fill color of the shapes in the list box.

Returns:
A Color object representing the shapes color.

setShapeFillColor

public void setShapeFillColor(java.awt.Color value)
Sets the fill color of the shapes in the list box.

Parameters:
value - A Color object representing the shapes color.

getShapeFilter

public java.lang.String[] getShapeFilter()
Gets the identifiers of the shapes that should be displayed in the list box.

Returns:
An array of strings containing the shape identifiers.

setShapeFilter

public void setShapeFilter(java.lang.String[] value)
Sets the identifiers of the shapes that should be displayed in the list box.

Parameters:
value - An array of strings containing the shape identifiers.

addShape

public void addShape(Shape shape)
Adds a single Shape to the list box.

Parameters:
shape - The Shape that should be added to the list.

addShapes

public void addShapes(Shape[] shapes)
Adds an array of Shape objects to the list box.

Parameters:
shapes - The shapes that should be added to the list.

addShapes

public void addShapes(ShapeList shapes)
Adds a list of Shape objects to the list box.

Parameters:
shapes - A ShapeList containing the shapes that should be added to the list.

getShapeAt

public Shape getShapeAt(int index)
Returns the Shape at the specified index.

Parameters:
index - The shape position in the list.
Returns:
The shape found at the specified position.

setShapeAt

public void setShapeAt(int index,
                       Shape shape)
Sets the shape at the specified position.

Parameters:
index - The shape position in the list.
shape - The Shape that should be added to the list.

getShapeCount

public int getShapeCount()
Returns the number of shapes after filtering.

Returns:
The number of shapes displayed in the list box.

removeShapeAt

public void removeShapeAt(int i)
Removes a shape from the list box.

Parameters:
i - The shape position in the list.

clearShapes

public void clearShapes()
Removes all shapes from the ShapeListBox, leaving it empty


invalidateShapeAt

public void invalidateShapeAt(int i)
Invalidates the specified shape, causing its icon to be recreated and redrawn. Call this method when a shape definition changes.

Parameters:
i -

getShapes

public Shape[] getShapes()
Retrieves all shapes visible in the list box after filtering.

Returns:
An array of Shape objects.

setShapes

public void setShapes(Shape[] shapes)
Replaces all current shapes with the specified ones.

Parameters:
shapes - An array of Shape objects.

getAllowRename

public boolean getAllowRename()
Gets a value indicating whether inline renaming of listbox items is allowed. Currently the list box displays shape identifiers as names.

Returns:
true if renaming is allowed, otherwise false.

setAllowRename

public void setAllowRename(boolean value)
Sets a value specifying whether inline renaming of listbox items is allowed. Items can be renamed by pressing F2. Currently the list box displays shape identifiers as names.

Parameters:
value - true if renaming is allowed, otherwise false.

getAllowRemove

public boolean getAllowRemove()
Gets a value indicating whether deletion of listbox items by pressing Del is allowed. Only the list box items are deleted, but not the Shape definitions themselves.

Returns:
true if deletion is allowed, otherwise false.

setAllowRemove

public void setAllowRemove(boolean value)

getShowLabels

public boolean getShowLabels()
Gets a value indicating whether to show text labels along with icons for each list item.

Returns:
true if labels are shown.

setShowLabels

public void setShowLabels(boolean value)

addShapeListener

public void addShapeListener(ShapeListBoxListener l)
Adds a listener for select, rename and delete events.

Parameters:
l - A ShapeListBoxListener object.

removeShapeListener

public void removeShapeListener(ShapeListBoxListener l)
Removes previously added listener for select, rename and delete events

Parameters:
l -

fireShapeRemoved

protected void fireShapeRemoved(Shape shape,
                                int index)

fireShapeSelected

protected void fireShapeSelected(Shape shape,
                                 int index)

fireShapeRenamed

protected void fireShapeRenamed(Shape shape,
                                int i,
                                java.lang.String oldName)

startInlineEdit

public void startInlineEdit()
Initiates inline editing of shape id.


paintComponent

protected void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

suspendRepaint

public void suspendRepaint()
Stops repainting the control. This is useful when using the JDiagram API from JavaScript, where the control would be repainted after each script line executes.


resumeRepaint

public void resumeRepaint()
Resumes repainting the control after a suspendRepaint() call.