Class DashboardChooser<T>

  • Type Parameters:
    T - The data type of the option.
    All Implemented Interfaces:
    edu.wpi.first.networktables.NTSendable, edu.wpi.first.util.sendable.Sendable, java.lang.AutoCloseable

    public class DashboardChooser<T>
    extends java.lang.Object
    implements edu.wpi.first.networktables.NTSendable, java.lang.AutoCloseable
    A NTSendable which replaces the SendableChooser in favor of a listener-based api. Used for constructing option widgets in the dashboard.
    • Constructor Detail

      • DashboardChooser

        public DashboardChooser​(java.util.Map<java.lang.String,​T> options,
                                java.lang.String defaultOption,
                                boolean logChanges)
        Constructs a DashboardChooser from a Map<String, T>.
        Parameters:
        options - The option list, as a Map<title, value>.
        defaultOption - The title of the default option.
        logChanges - Whether to log changes in the chosen value to the default on-robot log at HighLevelLogger.getLog().
      • DashboardChooser

        public DashboardChooser​(java.util.Map<java.lang.String,​T> options,
                                java.lang.String defaultOption)
        Constructs a DashboardChooser from a Map<String, T>, recording changes to the chosen value to the default on-robot log at HighLevelLogger.getLog().
        Parameters:
        options - The option list, as a Map<title, value>.
        defaultOption - The title of the default option.
    • Method Detail

      • fromEnum

        public static <T> DashboardChooser<T> fromEnum​(java.lang.Class<? extends DashboardChooser.Option> enumClass,
                                                       DashboardChooser.Option defaultOption,
                                                       boolean logChanges)
        Constructs a DashboardChooser from an enum implementing DashboardChooser.Option.
        Type Parameters:
        T - The enum's type.
        Parameters:
        enumClass - The <enum>.class
        defaultOption - The default enum option
        logChanges - Whether to log changes in the chosen value to the default robot log at HighLevelLogger.getLog().
        Returns:
        A new DashboardChooser object.
      • fromEnum

        public static <T> DashboardChooser<T> fromEnum​(java.lang.Class<? extends DashboardChooser.Option> enumClass,
                                                       DashboardChooser.Option defaultOption)
        Returns a DashboardChooser from an enum implementing DashboardChooser.Option, saving changes to the default log from HighLevelLogger.getLog()
        Type Parameters:
        T - The enum's type.
        Parameters:
        enumClass - The <enum>.class
        defaultOption - The default enum option
        Returns:
        A new DashboardChooser object.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
      • getSelected

        public T getSelected()
        Gets the currently selected option's value.
        Returns:
        The option's value, of type T.
      • initSendable

        public void initSendable​(edu.wpi.first.networktables.NTSendableBuilder builder)
        Specified by:
        initSendable in interface edu.wpi.first.networktables.NTSendable
      • registerListener

        public void registerListener​(DashboardChooser.ValueUpdater<T> updater)
        Register a listener to be called when the option is updated.
        Parameters:
        updater - The lambda to be called on update.
      • unregisterListener

        public void unregisterListener​(DashboardChooser.ValueUpdater<T> updater)
        Unregister a listener when no longer needed.
        Parameters:
        updater - the lambda to remove.