Module org.autogui
Package org.autogui.swing.util
Class ValueListPane<ValueType,PaneType extends JComponent>
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.autogui.swing.util.ValueListPane<ValueType,PaneType>
- Type Parameters:
ValueType
- the type for the source-element typePaneType
- the type for contentPane of the list
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
- Direct Known Subclasses:
GuiSwingPrefsEditor.ValueListMapPane
,GuiSwingPrefsEditor.ValueListPaneFileDialogList
,GuiSwingPrefsEditor.ValueListPaneHistoryValueEntry
,GuiSwingPrefsEditor.ValueListPaneSplitEntry
,GuiSwingPrefsEditor.ValueListTableRowSort
a component for listing
JComponent
s.
----------------------------- | ValueListPane : JComponent(BorderLayout) | -------------------------- | toolBar JPanel | -------------------------- |ValueListPane.ValueListContentPane
(ValueListPane.ValueListModel
) | 0:ValueListPane.ValueListElementPane
| header JLabel | contentPane PaneType | ...
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
the action class for adding a new elementstatic class
static class
the action class for reordering selected-panes; moving-downstatic class
the element-pane wrapping a custom content-panestatic class
a transferable class for reorderingstatic class
the transfer handler for reordering element-panes; usingValueListPane.ValueListElementTransferable
static class
the list-model for element-panesstatic class
static interface
static class
the action class for removing selected-panesstatic class
the action class for reordering selected-panes; moving-upNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ValueListPane.ValueListAddAction
the tool-action for addingprotected ValueListPane.ValueListDownAction
the tool-action for item-downprotected PropertyChangeListener
protected ValueListPane.ValueListContentPane
<ValueType, PaneType> the listthe wrapper-factory for appending the list; typically JScrollPane::newprotected ValueListPane.ValueListModel
<ValueType, PaneType> the model of the listprotected ValueListPane.ValueListRemoveAction
the tool-action for removingprotected ValueListPane.ValueListUpAction
the tool-action for item-upFields inherited from class javax.swing.JComponent
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
accessibleContext, 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
ConstructorsModifierConstructorDescriptionprotected
a constructor for doInit and no-scroll-wrapperprotected
ValueListPane
(boolean doInit) a constructor with no-scroll-wrapperprotected
ValueListPane
(boolean doInit, Function<ValueListPane.ValueListContentPane<ValueType, PaneType>, JComponent> listWrapper) protected
ValueListPane
(Function<ValueListPane.ValueListContentPane<ValueType, PaneType>, JComponent> listWrapper) -
Method Summary
Modifier and TypeMethodDescriptionvoid
adding a new element to the source and update the pane.void
called after model's updateSourcevoid
close()
<V> V
editSource
(Function<List<ValueType>, V> v) do the given action and update the entire displayprotected void
focusCchange
(JComponent oldDescendant, JComponent newDescendant) called when focus changed for given 2 panes; the default behavior is selecting the newDescendant, and repaint entire list.getList()
getModel()
static DataFlavor
void
init()
do initialization processesprotected void
add a listener to globalKeyboardFocusManager
for observing focus changes: the listener checks whether focus gained/lost panes are chilren of the list and then callsfocusCchange(JComponent, JComponent)
protected void
initialize the layout withBorderLayout
protected void
initList()
initialize the model and the list, and adding it to this with callinglistWrapper
protected void
initTool()
creating the toolbar and actions, and adding it to this byinitToolActions(JComponent)
protected void
initToolActions
(JComponent tool) creating actions and adding button to the toolbarboolean
isParent
(JComponent pane) static JComponent
matchOrParent
(JComponent pane, Predicate<JComponent> cond) void
move selected elements to the bottom + 1 (or to the top)void
moveElements
(int targetIndex, int... movedIndicesArray) move selected elements to the targetIndexvoid
moveSelectedElements
(int targetIndex) move selected elements to the targetIndexboolean
moveSourceValues
(int[] indices, List<ValueType> values, int targetIndex) called before moving itemsvoid
move selected elements to the top -1 (or to the end)abstract PaneType
newElementPane
(int i, ValueListPane.ValueListElementPane<ValueType, PaneType> elementPane) Note: for a combo-box, the returning element-pane should be opaque=true.abstract ValueType
newSourceValue
(int i) static <E> List
<E> generic impl.void
removeElements
(int... targetIndices) removeSourceValue(int, Object)
for selected panes and remove the items fromtakeSource()
; Note: removing will be done byremoveAll(List, int...)
After that,sourceRemoved(int[], List)
andValueListPane.ValueListModel.updateSourceWithRemoving(int...)
void
remove selected elements values and components.boolean
removeSourceValue
(int i, ValueType value) checks removing of the i-th element; the default is just returns truestatic <ValueType,
PaneType extends JComponent>
Function<ValueListPane.ValueListContentPane<ValueType, PaneType>, JComponent> void
selectionFlip
(int n) void
selectionRangeTo
(int n) void
selectionSet
(int n) void
sourceAdded
(int newIndex, ValueType v) called after the source-element is added: the default-impl is nothingvoid
sourceMoved
(int insertedTargetIndex, List<ValueType> movedValues) called after moving itemsvoid
sourceRemoved
(int[] removedIndices, List<ValueType> removed) called after removing elements from the source: the default-impl is nothingvoid
checks model-updatingNote: the default constructors does not call the method at initialization.void
the handler ofListSelectionListener
; update toolbar actionsabstract boolean
updateSourceValueToElementPane
(int i, ValueType value, ValueListPane.ValueListElementPane<ValueType, PaneType> pane) re-assign the i-th element-value to the target pane; the method is always called even if the i is not changed.upperElement
(JComponent descendant) 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, 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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, updateUI
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, 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, getAccessibleContext, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
model
the model of the list -
list
the list -
listWrapper
protected Function<ValueListPane.ValueListContentPane<ValueType,PaneType extends JComponent>, listWrapperJComponent> the wrapper-factory for appending the list; typically JScrollPane::new -
addAction
the tool-action for adding -
removeAction
the tool-action for removing -
upAction
the tool-action for item-up -
downAction
the tool-action for item-down -
globalFocusChangeListener
-
-
Constructor Details
-
ValueListPane
protected ValueListPane()a constructor for doInit and no-scroll-wrapper -
ValueListPane
protected ValueListPane(boolean doInit) a constructor with no-scroll-wrapper- Parameters:
doInit
- if true,init()
-
ValueListPane
protected ValueListPane(boolean doInit, Function<ValueListPane.ValueListContentPane<ValueType, PaneType>, JComponent> listWrapper) - Parameters:
doInit
- if true,init()
; a subclass can control initialization timinglistWrapper
- the wrapper factory at adding the list to the pane; e.g.scrollWrapper()
-
ValueListPane
protected ValueListPane(Function<ValueListPane.ValueListContentPane<ValueType, PaneType>, JComponent> listWrapper) - Parameters:
listWrapper
- the wrapper factory at adding the list to the pane; e.g.scrollWrapper()
-
-
Method Details
-
takeSource
Note: the default constructors does not call the method at initialization. the constructors of sub-classes need tosyncElements()
for initializing elements- Returns:
- the direct reference to the source-list. it needs to be stable and modifiable
-
newSourceValue
- Parameters:
i
- the index for the creating element- Returns:
- a new i-th element-value, or null it cannot add a new element
-
updateSourceValueToElementPane
public abstract boolean updateSourceValueToElementPane(int i, ValueType value, ValueListPane.ValueListElementPane<ValueType, PaneType> pane) re-assign the i-th element-value to the target pane; the method is always called even if the i is not changed.- Parameters:
i
- the index of the elementvalue
- the value of the elementpane
- the i-th element-pane- Returns:
- true if the value of the pane is updated by the given (i,value).
-
newElementPane
public abstract PaneType newElementPane(int i, ValueListPane.ValueListElementPane<ValueType, PaneType> elementPane) Note: for a combo-box, the returning element-pane should be opaque=true. 1) The property will affect to the frequency of repainting. 2) The repainting will lead to the ancestor change by the cell-rendering mechanism. 3) The change will fire the default event-handler of the combo-box that hides pop-up.- Parameters:
i
- the initial index for the paneelementPane
- the wrapper element-pane for the creating pane- Returns:
- a new-element pane which will be initialized by
updateSourceValueToElementPane(int, Object, ValueListElementPane)
later
-
editSource
do the given action and update the entire display- Type Parameters:
V
- the returning type of the action- Parameters:
v
- the action for editing the source-list- Returns:
- the returned value of the action
-
removeSourceValue
checks removing of the i-th element; the default is just returns true- Parameters:
i
- the index for the removing elementvalue
- the removed value- Returns:
- true if the value can be removed
-
moveSourceValues
called before moving items- Parameters:
indices
- the moved indicesvalues
- the moved valuestargetIndex
- the targetIndex of the source ranged (0...size) . Note that the index is a part of the current source before moving; including the moving indices- Returns:
- true if the moving is valid
-
sourceMoved
called after moving items- Parameters:
insertedTargetIndex
- the target index of the list after movingmovedValues
- removed and inserted items
-
sourceAdded
called after the source-element is added: the default-impl is nothing- Parameters:
newIndex
- the new-element indexv
- the added value
-
sourceRemoved
called after removing elements from the source: the default-impl is nothing- Parameters:
removedIndices
- removed indicesremoved
- removed values
-
init
public void init()do initialization processes -
initLayout
protected void initLayout()initialize the layout withBorderLayout
-
initTool
protected void initTool()creating the toolbar and actions, and adding it to this byinitToolActions(JComponent)
-
initToolActions
creating actions and adding button to the toolbar- Parameters:
tool
- the toolbar
-
initList
protected void initList()initialize the model and the list, and adding it to this with callinglistWrapper
-
initFocusRepainter
protected void initFocusRepainter()add a listener to globalKeyboardFocusManager
for observing focus changes: the listener checks whether focus gained/lost panes are chilren of the list and then callsfocusCchange(JComponent, JComponent)
-
scrollWrapper
public static <ValueType,PaneType extends JComponent> Function<ValueListPane.ValueListContentPane<ValueType,PaneType>, scrollWrapper()JComponent> -
close
public void close() -
focusCchange
called when focus changed for given 2 panes; the default behavior is selecting the newDescendant, and repaint entire list.- Parameters:
oldDescendant
- a focus lost descendant component of the list, or nullnewDescendant
- a focus gained descendant component of the list, or null
-
isParent
- Parameters:
pane
- a child component- Returns:
- true if ancestor of the pane is this list
-
upperElement
- Parameters:
descendant
- a descendant compoennt of the list- Returns:
- the element pane containing the descendant
-
matchOrParent
- Parameters:
pane
- a component or nullcond
- a test for ancestors of the pane- Returns:
- the pane or an ancesotor of the pane that matches the cond, or null
-
addNewElement
public void addNewElement()adding a new element to the source and update the pane.takeSource()
andnewSourceValue(int)
; if the new-value is null, no addition. After that, (if added)sourceAdded(int, Object)
andValueListPane.ValueListModel.updateSource()
-
removeSelectedElements
public void removeSelectedElements()remove selected elements values and components.- See Also:
-
removeElements
public void removeElements(int... targetIndices) removeSourceValue(int, Object)
for selected panes and remove the items fromtakeSource()
; Note: removing will be done byremoveAll(List, int...)
After that,sourceRemoved(int[], List)
andValueListPane.ValueListModel.updateSourceWithRemoving(int...)
- Parameters:
targetIndices
- the indices of removing elements in the source
-
removeAll
generic impl. of removing elements at target-indices from the list by usingIterator.remove()
- Type Parameters:
E
- the element type of the list- Parameters:
src
- the listremovedIndices
- the removing indices in the list- Returns:
- removed objects
-
moveSelectedElements
public void moveSelectedElements(int targetIndex) move selected elements to the targetIndex- Parameters:
targetIndex
- ranged (0, size)- See Also:
-
moveElements
public void moveElements(int targetIndex, int... movedIndicesArray) move selected elements to the targetIndex- Parameters:
targetIndex
- the target index (before moving of the source)movedIndicesArray
- moved indices
-
moveUpSelectedElements
public void moveUpSelectedElements()move selected elements to the top -1 (or to the end)- See Also:
-
moveDownSelectedElements
public void moveDownSelectedElements()move selected elements to the bottom + 1 (or to the top)- See Also:
-
updateSelectedElements
the handler ofListSelectionListener
; update toolbar actions- Parameters:
e
- the event
-
afterUpdateElements
public void afterUpdateElements()called after model's updateSource -
syncElements
public void syncElements()checks model-updating -
getModel
- Returns:
- the model of the list
-
getList
- Returns:
- the list
-
selectionFlip
public void selectionFlip(int n) -
selectionRangeTo
public void selectionRangeTo(int n) -
selectionSet
public void selectionSet(int n) -
getValueListElementFlavor
- Returns:
- a data-flavor of
DataFlavor.javaJVMLocalObjectMimeType
forValueListPane.ValueListElementTransferable
-