Copyright 2012-02-25 Werner Randelshofer

ch.randelshofer.gui.list
Interface MutableListModel

All Superinterfaces:
javax.swing.ListModel
All Known Implementing Classes:
DefaultMutableListModel

public interface MutableListModel
extends javax.swing.ListModel

Specifies the requirements for a mutable list model.

The mutable list model adds suport for the following operations to the javax.swing.ListModel interface:

Version:
3.0 2004-05-16 Revised.
1.0 2002-11-20 Created.
Author:
Werner Randelshofer

Method Summary
 void create(int index, java.lang.Object type)
          Creates the specified element type at the specified position in this list Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
 java.awt.datatransfer.Transferable exportTransferable(int[] indices)
          Creates a Transferable to use as the source for a data transfer of the specified elements.
 javax.swing.Action[] getActions(int[] indices)
          Gets actions for the specified elements.
 java.lang.Object getCreatableType(int index)
          Returns the default type of elements that can be created at the specified index of the list.
 java.lang.Object[] getCreatableTypes(int index)
          Returns the types of elements that can be created at the specified index of the list.
 int importTransferable(java.awt.datatransfer.Transferable t, int action, int index, boolean asChild)
          Causes a transfer to the model from the specified transferable.
 boolean isAddable(int index)
          Returns true if an element can be added.
 boolean isEditable(int index)
          Returns true if the value of the specified element may be changed using setElementAt(Object,int).
 boolean isImportable(java.awt.datatransfer.DataFlavor[] transferFlavors, int action, int index, boolean asChild)
          Indicates whether the model would accept an import of the given set of data flavors prior to actually attempting to import it.
 boolean isRemovable(int index)
          Returns true if the specified element can be removed.
 java.lang.Object remove(int index)
          Removes an element from the model.
 void setElementAt(java.lang.Object value, int index)
          Sets the value of an element at the given index.
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, getElementAt, getSize, removeListDataListener
 

Method Detail

getCreatableTypes

java.lang.Object[] getCreatableTypes(int index)
Returns the types of elements that can be created at the specified index of the list.

Parameters:
index - The insertion point. 0 <= index <= getSize()
Returns:
an array of Object's that specify element types that can be inserted at the insertion point. Returns an empty array if no elements can be inserted here. Never returns null. This array must include the type returned by operation getCreatableType.

getCreatableType

java.lang.Object getCreatableType(int index)
Returns the default type of elements that can be created at the specified index of the list.

Parameters:
index - The insertion point. 0 <= index <= getSize()
Returns:
an Object that specifies the default element type that can be inserted at the insertion point. Returns null if no elements can be inserted here. The value must be one of the types returned by operation getCreatableTypes.

create

void create(int index,
            java.lang.Object type)
Creates the specified element type at the specified position in this list Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - index at which the specified element is to be inserted.
type - element type to be inserted.
Throws:
java.lang.IllegalArgumentException - if the type is not contained in the array returned by getInsertableTypes(int).
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).

isAddable

boolean isAddable(int index)
Returns true if an element can be added.

Parameters:
index - index of the element. 0 <= index <= getSize()
See Also:
remove(int)

isRemovable

boolean isRemovable(int index)
Returns true if the specified element can be removed.

Parameters:
index - index of the element. 0 <= index <= getSize()
See Also:
remove(int)

remove

java.lang.Object remove(int index)
                        throws java.lang.IllegalStateException
Removes an element from the model.

Parameters:
index - index of the element. 0 <= index <= getSize()
Returns:
The removed Object.
Throws:
java.lang.IllegalStateException - if the element may not be removed.
See Also:
isRemovable(int)

isEditable

boolean isEditable(int index)
Returns true if the value of the specified element may be changed using setElementAt(Object,int).

Parameters:
index - index of the element. 0 <= index <= getSize()
See Also:
setElementAt(Object, int)

setElementAt

void setElementAt(java.lang.Object value,
                  int index)
                  throws java.lang.IllegalStateException
Sets the value of an element at the given index.

Parameters:
value - - the new value
index - - the index whose value is to be changed. 0 <= index < getSize()
Throws:
java.lang.IllegalStateException - if the element is not editable.
See Also:
isEditable(int)

getActions

javax.swing.Action[] getActions(int[] indices)
Gets actions for the specified elements.

Parameters:
indices - The elements.

exportTransferable

java.awt.datatransfer.Transferable exportTransferable(int[] indices)
Creates a Transferable to use as the source for a data transfer of the specified elements.

Parameters:
indices - Element indices.
Returns:
A Transferable representing the elements to be transferred, or null if transfer is not possible.

isImportable

boolean isImportable(java.awt.datatransfer.DataFlavor[] transferFlavors,
                     int action,
                     int index,
                     boolean asChild)
Indicates whether the model would accept an import of the given set of data flavors prior to actually attempting to import it.

Parameters:
transferFlavors - the data formats available
action - The action DnDConstants.ACTION_COPY, .ACTION_MOVE or .ACTION_LINK.
index - The insertion point. 0 <= index <= getSize()
asChild - True if the Transferable is dropped as a child of the element.
Returns:
true if the data can be imported.
See Also:
DnDConstants

importTransferable

int importTransferable(java.awt.datatransfer.Transferable t,
                       int action,
                       int index,
                       boolean asChild)
                       throws java.awt.datatransfer.UnsupportedFlavorException,
                              java.io.IOException
Causes a transfer to the model from the specified transferable.

Parameters:
t - The transfer data.
action - The action DnDConstants.ACTION_COPY, .ACTION_MOVE or .ACTION_LINK.
index - The insertion point. 0 <= index <= getSize()
asChild - True if the Transferable is dropped as a child of the element.
Returns:
The number of imported elements.
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

Copyright 2012-02-25 Werner Randelshofer