Class CL_Selection

java.lang.Object
org.jjazz.cl_editor.api.CL_Selection

public final class CL_Selection extends Object
Represent the selection of a CL_Editor, built from its Lookup.

Selected items can be either SelectedCLI or SelectedBar, but not both in the same time. Furthermore, a selection can not contain SelectedCLIs with incompatible ChordLeadSheetItem classes (eg CLI_ChordSymbol and CLI_Section).

See Also:
  • Constructor Details

    • CL_Selection

      public CL_Selection(org.openide.util.Lookup lookup)
      Create a selection with items or bars.
      Parameters:
      lookup -
      Throws:
      IllegalStateException - If lookup contains both SelectedBars and SelectedCLIs
    • CL_Selection

      public CL_Selection(org.openide.util.Lookup lookup, boolean searchItems, boolean searchBars)
      Create an instance with only the searched types.
      Parameters:
      lookup -
      searchItems - If false SelectedCLIs are ignored
      searchBars - If false SelectedBars are ignored
      Throws:
      IllegalStateException - If lookup contains both SelectedBars and SelectedCLIs, or incompatible SelectedCLIs
  • Method Details

    • isItemSelected

      public static boolean isItemSelected(org.openide.util.Lookup lookup)
      Utility method to quickly check if selection contains at least one SelectedCLI.

      This is faster than new CL_Selection(Lookup).isItemSelected().

      Parameters:
      lookup -
      Returns:
    • isBarSelected

      public static boolean isBarSelected(org.openide.util.Lookup lookup)
      Utility method to quickly check if selection contains at least one SelectedBar.

      This is faster than new CL_Selection(Lookup).isBarSelected().

      Parameters:
      lookup -
      Returns:
    • isContiguousBarSelection

      public boolean isContiguousBarSelection()
      True if all selectedBars are contiguous.
      Returns:
    • isContiguousBarboxSelectionWithinCls

      public boolean isContiguousBarboxSelectionWithinCls()
      Same as isContiguousBarSelection but limited to bars within the chordleadsheet's range.
      Returns:
    • isEmpty

      public boolean isEmpty()
    • isChordSymbolSelected

      public boolean isChordSymbolSelected()
    • isSectionSelected

      public boolean isSectionSelected()
    • isBarAnnotationSelected

      public boolean isBarAnnotationSelected()
    • isItemSelected

      public boolean isItemSelected()
    • isBarSelected

      public boolean isBarSelected()
      True if a BarBox is selected.
      Returns:
    • isBarSelectedWithinCls

      public boolean isBarSelectedWithinCls()
      True if at least one selected BarBox is within the chordleadsheet range.
      Returns:
    • getMinBarIndexWithinCls

      public int getMinBarIndexWithinCls()
      Same as getMinBarIndex but limited to bars within the chordleadsheet's range.
      Returns:
      -1 if selection is empty or first selected bar is after chordleadsheet's end.
    • getMaxBarIndexWithinCls

      public int getMaxBarIndexWithinCls()
      Same as getMaxBarIndex but limited to bars within the chordleadsheet's range.
      Returns:
      -1 if selection is empty or selected bars are after chordleadsheet's end.
    • getBarRangeWithinCls

      public IntRange getBarRangeWithinCls()
      The selected bar range within the chord leadsheet.
      Returns:
      Can be null if selection empty or outside the chord leadsheet.
    • getBarRange

      public IntRange getBarRange()
      The selected bar range within the chord leadsheet.
      Returns:
      Can be null if selection empty
    • getMaxBarIndex

      public int getMaxBarIndex()
      The first selected bar index if bars are selected, or the barIndex of the first item selected if items are selected.
      Returns:
      -1 if selection is empty.
    • getMinBarIndex

      public int getMinBarIndex()
      The first selected bar index if bars are selected, or the barIndex of the first item selected if items are selected.
      Returns:
      -1 if selection is empty.
    • getChordLeadSheet

      public ChordLeadSheet getChordLeadSheet()
      Can be null if selection is empty.
      Returns:
    • isItemSelected

      public boolean isItemSelected(ChordLeadSheetItem<?> item)
    • isItemTypeSelected

      public boolean isItemTypeSelected(Class<? extends ChordLeadSheetItem> itemClass)
      Check if the selected ChordLeadSheet items are compatible with itemClass.
      Parameters:
      itemClass -
      Returns:
    • isBarSelected

      public boolean isBarSelected(int bbIndex)
    • getSelectedCLIs

      public List<SelectedCLI> getSelectedCLIs()
      Get all the SelectedCLIs, unsorted.
      Returns:
      Can be empty.
    • getSelectedItems

      public List<ChordLeadSheetItem> getSelectedItems()
      Get all the selected items sections, chord symbols, etc. sorted by position.
      Returns:
      Can be empty.
    • getSelectedSections

      public List<CLI_Section> getSelectedSections()
      Get only the selected sections sorted by position.
      Returns:
      Can be empty.
    • getSelectedChordSymbols

      public List<CLI_ChordSymbol> getSelectedChordSymbols()
      Get only the selected chord symbols sorted by position.
      Returns:
      Can be empty.
    • getSelectedBarAnnotations

      public List<CLI_BarAnnotation> getSelectedBarAnnotations()
      Get only the selected chord symbols sorted by position.
      Returns:
      Can be empty.
    • getSelectedBars

      public List<SelectedBar> getSelectedBars()
      Get the selected bars sorted by position.
      Returns:
      Can be empty if isItemSelected() returns true.
    • getSelectedBarIndexes

      public List<Integer> getSelectedBarIndexes()
      The bar indexes of the SelectedBars (sorted by position).

      Return an empty list if selection is not made of SelectedBars.

      Returns:
    • getSelectedBarsWithinCls

      public List<SelectedBar> getSelectedBarsWithinCls()
      Same as getSelectedBars() but limited to bars within the chordleadsheet's range.
      Returns:
      Can be empty if isItemSelected() returns true.
    • getSelectedBarIndexesWithinCls

      public List<Integer> getSelectedBarIndexesWithinCls()
      Same as getSelectedBarsIndexes() but limited to bars within the chordleadsheet's range.

      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object