Module org.autogui

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 type
PaneType - 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

public abstract class ValueListPane<ValueType,PaneType extends JComponent> extends JComponent
a component for listing JComponents.
   -----------------------------
   |  ValueListPane : JComponent(BorderLayout)
   |  --------------------------
   |    toolBar JPanel
   |  --------------------------
   |   ValueListPane.ValueListContentPane (ValueListPane.ValueListModel)
   |     0: ValueListPane.ValueListElementPane
   |          header JLabel |  contentPane PaneType
   |     ...
 
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • takeSource

      public abstract List<ValueType> takeSource()
      Note: the default constructors does not call the method at initialization. the constructors of sub-classes need to syncElements() for initializing elements
      Returns:
      the direct reference to the source-list. it needs to be stable and modifiable
    • newSourceValue

      public abstract ValueType newSourceValue(int i)
      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 element
      value - the value of the element
      pane - 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 pane
      elementPane - the wrapper element-pane for the creating pane
      Returns:
      a new-element pane which will be initialized by updateSourceValueToElementPane(int, Object, ValueListElementPane) later
    • editSource

      public <V> V editSource(Function<List<ValueType>,V> v)
      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

      public boolean removeSourceValue(int i, ValueType value)
      checks removing of the i-th element; the default is just returns true
      Parameters:
      i - the index for the removing element
      value - the removed value
      Returns:
      true if the value can be removed
    • moveSourceValues

      public boolean moveSourceValues(int[] indices, List<ValueType> values, int targetIndex)
      called before moving items
      Parameters:
      indices - the moved indices
      values - the moved values
      targetIndex - 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

      public void sourceMoved(int insertedTargetIndex, List<ValueType> movedValues)
      called after moving items
      Parameters:
      insertedTargetIndex - the target index of the list after moving
      movedValues - removed and inserted items
    • sourceAdded

      public void sourceAdded(int newIndex, ValueType v)
      called after the source-element is added: the default-impl is nothing
      Parameters:
      newIndex - the new-element index
      v - the added value
    • sourceRemoved

      public void sourceRemoved(int[] removedIndices, List<ValueType> removed)
      called after removing elements from the source: the default-impl is nothing
      Parameters:
      removedIndices - removed indices
      removed - removed values
    • init

      public void init()
      do initialization processes
    • initLayout

      protected void initLayout()
      initialize the layout with BorderLayout
    • initTool

      protected void initTool()
      creating the toolbar and actions, and adding it to this by initToolActions(JComponent)
    • initToolActions

      protected void initToolActions(JComponent tool)
      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 calling listWrapper
    • initFocusRepainter

      protected void initFocusRepainter()
      add a listener to global KeyboardFocusManager for observing focus changes: the listener checks whether focus gained/lost panes are chilren of the list and then calls focusCchange(JComponent, JComponent)
    • scrollWrapper

      public static <ValueType, PaneType extends JComponent> Function<ValueListPane.ValueListContentPane<ValueType,PaneType>,JComponent> scrollWrapper()
    • close

      public void close()
    • focusCchange

      protected 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.
      Parameters:
      oldDescendant - a focus lost descendant component of the list, or null
      newDescendant - a focus gained descendant component of the list, or null
    • isParent

      public boolean isParent(JComponent pane)
      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

      public static JComponent matchOrParent(JComponent pane, Predicate<JComponent> cond)
      Parameters:
      pane - a component or null
      cond - 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() and newSourceValue(int) ; if the new-value is null, no addition. After that, (if added) sourceAdded(int, Object) and ValueListPane.ValueListModel.updateSource()
    • removeSelectedElements

      public void removeSelectedElements()
      remove selected elements values and components.
      See Also:
    • removeElements

      public void removeElements(int... targetIndices)
      Parameters:
      targetIndices - the indices of removing elements in the source
    • removeAll

      public static <E> List<E> removeAll(List<E> src, int... removedIndices)
      generic impl. of removing elements at target-indices from the list by using Iterator.remove()
      Type Parameters:
      E - the element type of the list
      Parameters:
      src - the list
      removedIndices - 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

      public void updateSelectedElements(ListSelectionEvent e)
      the handler of ListSelectionListener; 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

      public static DataFlavor getValueListElementFlavor()
      Returns:
      a data-flavor of DataFlavor.javaJVMLocalObjectMimeType for ValueListPane.ValueListElementTransferable