public class ListView extends JScrollPane implements Externalizable
This class is a view
to use it properly you need to add it into a component which implements
ExplorerManager.Provider
. Good examples of that can be found
in ExplorerUtils
. Then just use
ExplorerManager.Provider.getExplorerManager()
call to get the ExplorerManager
and control its state.
There can be multiple views
under one container implementing ExplorerManager.Provider
. Select from
range of predefined ones or write your own:
BeanTreeView
- shows a tree of nodesContextTreeView
- shows a tree of nodes without leaf nodesListView
- shows a list of nodesIconView
- shows a rows of nodes with bigger iconsChoiceView
- creates a combo box based on the explored nodesTreeTableView
- shows tree of nodes together with a set of their Node.Property
MenuView
- can create a JMenu
structure based on structure of Node
s
All of these views use ExplorerManager.find(java.awt.Component)
to walk up the AWT hierarchy and locate the
ExplorerManager
to use as a controller. They attach as listeners to
it and also call its setter methods to update the shared state based on the
user action. Not all views make sense together, but for example
ContextTreeView
and ListView
were designed to complement
themselves and behaves like windows explorer. The PropertySheetView
for example should be able to work with any other view.
JScrollPane.AccessibleJScrollPane, JScrollPane.ScrollBar
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected JList |
list
The actual JList list
|
protected NodeListModel |
model
model to use
|
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewport
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
COLUMN_HEADER, HORIZONTAL_SCROLLBAR, HORIZONTAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_POLICY, LOWER_LEADING_CORNER, LOWER_LEFT_CORNER, LOWER_RIGHT_CORNER, LOWER_TRAILING_CORNER, ROW_HEADER, UPPER_LEADING_CORNER, UPPER_LEFT_CORNER, UPPER_RIGHT_CORNER, UPPER_TRAILING_CORNER, VERTICAL_SCROLLBAR, VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_POLICY, VIEWPORT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
ListView()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addNotify() |
protected JList |
createList()
Creates the list that will display the data.
|
protected NodeListModel |
createModel()
Allows subclasses to change the default model used for
the list.
|
void |
doLayout() |
int |
getAllowedDragActions()
Actions constants comes from
DnDConstants . |
int |
getAllowedDropActions()
Actions constants comes from
DnDConstants . |
ActionListener |
getDefaultProcessor()
Get the current processor for default actions.
|
Dimension |
getPreferredSize() |
int |
getSelectionMode()
Get the selection mode.
|
boolean |
isDragSource() |
boolean |
isDropTarget() |
boolean |
isPopupAllowed()
Test whether display of a popup menu is enabled.
|
boolean |
isShowParentNode()
Is parent node (e.g.
|
boolean |
isTraversalAllowed()
Test whether hierarchy traversal shortcuts are permitted.
|
void |
paint(Graphics g) |
void |
readExternal(ObjectInput in) |
void |
removeNotify()
Removes listeners.
|
void |
requestFocus() |
boolean |
requestFocusInWindow() |
protected boolean |
selectionAccept(Node[] nodes)
Called when explorer manager is about to change the current selection.
|
protected void |
selectionChanged(Node[] nodes,
ExplorerManager em)
Called when the list changed selection and the explorer manager
should be updated.
|
void |
setAllowedDragActions(int actions)
Sets allowed actions for dragging
|
void |
setAllowedDropActions(int actions)
Sets allowed actions for dropping.
|
void |
setDefaultProcessor(ActionListener value)
Set a new processor for default actions.
|
void |
setDragSource(boolean state)
Enables/disables dragging support.
|
void |
setDropTarget(boolean state)
Enables/disables dropping support.
|
void |
setPopupAllowed(boolean value)
Enable/disable displaying popup menus on list view items.
|
void |
setSelectionMode(int selectionMode)
Set whether single-item or multiple-item
selections are allowed.
|
void |
setShowParentNode(boolean show)
Shall the first node in the list be ".." representing currently
explored context? By default it is not, but if you want to simplify
the navigation in the
Node hierarchy, you can turn this
property on. |
void |
setTraversalAllowed(boolean value)
Enable/disable hierarchy traversal using
CTRL+click (down) and Backspace (up), default is enabled. |
protected void |
showSelection(int[] indexes)
Shows selection.
|
protected void |
validateTree() |
void |
writeExternal(ObjectOutput out) |
createHorizontalScrollBar, createVerticalScrollBar, createViewport, getAccessibleContext, getColumnHeader, getCorner, getHorizontalScrollBar, getHorizontalScrollBarPolicy, getRowHeader, getUI, getUIClassID, getVerticalScrollBar, getVerticalScrollBarPolicy, getViewport, getViewportBorder, getViewportBorderBounds, isValidateRoot, isWheelScrollingEnabled, paramString, setColumnHeader, setColumnHeaderView, setComponentOrientation, setCorner, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setLayout, setRowHeader, setRowHeaderView, setUI, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportBorder, setViewportView, setWheelScrollingEnabled, updateUI
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, 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
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, transferFocusDownCycle, validate
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, 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, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected transient JList list
protected transient NodeListModel model
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public boolean isPopupAllowed()
true
if sopublic void setPopupAllowed(boolean value)
value
- true
to enablepublic boolean isTraversalAllowed()
true
if sopublic void setTraversalAllowed(boolean value)
CTRL+click
(down) and Backspace
(up), default is enabled.value
- true
to enablepublic boolean isShowParentNode()
public void setShowParentNode(boolean show)
Node
hierarchy, you can turn this
property on.show
- true to show the "..", false to not to do sopublic ActionListener getDefaultProcessor()
null
, double-clicks or pressing Enter on
items in the view will not perform the default action on the selected node; rather the processor
will be notified about the event.null
public void setDefaultProcessor(ActionListener value)
value
- the new default-action processor, or null
to restore use of the selected node's declared default actionListView.getDefaultProcessor()
public void setSelectionMode(int selectionMode)
selectionMode
- one of ListSelectionModel.SINGLE_SELECTION
, ListSelectionModel.SINGLE_INTERVAL_SELECTION
, or ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
ListSelectionModel.setSelectionMode(int)
public int getSelectionMode()
ListView.setSelectionMode(int)
public boolean isDragSource()
public void setDragSource(boolean state)
state
- true enables dragging support, false disables it.public boolean isDropTarget()
public void setDropTarget(boolean state)
state
- true means drops into view are allowed,
false forbids any drops into this view.public int getAllowedDragActions()
DnDConstants
.
All actions (copy, move, link) are allowed by default.public void setAllowedDragActions(int actions)
actions
- new drag actions, using DnDConstants
public int getAllowedDropActions()
DnDConstants
.
All actions are allowed by default.public void setAllowedDropActions(int actions)
actions
- new allowed drop actions, using DnDConstants
protected JList createList()
protected NodeListModel createModel()
protected void selectionChanged(Node[] nodes, ExplorerManager em) throws PropertyVetoException
nodes
- list of nodes that should be selectedem
- explorer managerPropertyVetoException
- if the manager does not allow the
selectionprotected boolean selectionAccept(Node[] nodes)
nodes
- the nodes to selectprotected void showSelection(int[] indexes)
indexes
- indexes of objects to selectpublic void paint(Graphics g)
paint
in class JComponent
protected void validateTree()
validateTree
in class Container
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
public void addNotify()
addNotify
in class JComponent
public void removeNotify()
removeNotify
in class JComponent
public void requestFocus()
requestFocus
in class JComponent
public boolean requestFocusInWindow()
requestFocusInWindow
in class JComponent