Package org.chsrobotics.lib.telemetry
Class DashboardChooser<T>
- java.lang.Object
-
- org.chsrobotics.lib.telemetry.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.AutoCloseableA NTSendable which replaces the SendableChooser in favor of a listener-based api. Used for constructing option widgets in the dashboard.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDashboardChooser.OptionInterface implemented by enums which allows DashboardChooser to automatically create choosers.static interfaceDashboardChooser.ValueUpdater<T>Interface which defines a lambda for receiving DashboardChooser updates.
-
Constructor Summary
Constructors Constructor Description DashboardChooser(java.util.Map<java.lang.String,T> options, java.lang.String defaultOption)Constructs a DashboardChooser from aMap<String, T>, recording changes to the chosen value to the default on-robot log atHighLevelLogger.getLog().DashboardChooser(java.util.Map<java.lang.String,T> options, java.lang.String defaultOption, boolean logChanges)Constructs a DashboardChooser from aMap<String, T>.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static <T> DashboardChooser<T>fromEnum(java.lang.Class<? extends DashboardChooser.Option> enumClass, DashboardChooser.Option defaultOption)Returns a DashboardChooser from an enum implementingDashboardChooser.Option, saving changes to the default log fromHighLevelLogger.getLog()static <T> DashboardChooser<T>fromEnum(java.lang.Class<? extends DashboardChooser.Option> enumClass, DashboardChooser.Option defaultOption, boolean logChanges)Constructs a DashboardChooser from an enum implementingDashboardChooser.Option.TgetSelected()Gets the currently selected option's value.voidinitSendable(edu.wpi.first.networktables.NTSendableBuilder builder)voidregisterListener(DashboardChooser.ValueUpdater<T> updater)Register a listener to be called when the option is updated.voidunregisterListener(DashboardChooser.ValueUpdater<T> updater)Unregister a listener when no longer needed.
-
-
-
Constructor Detail
-
DashboardChooser
public DashboardChooser(java.util.Map<java.lang.String,T> options, java.lang.String defaultOption, boolean logChanges)
Constructs a DashboardChooser from aMap<String, T>.- Parameters:
options- The option list, as aMap<title, value>.defaultOption- The title of the default option.logChanges- Whether to log changes in the chosen value to the default on-robot log atHighLevelLogger.getLog().
-
DashboardChooser
public DashboardChooser(java.util.Map<java.lang.String,T> options, java.lang.String defaultOption)
Constructs a DashboardChooser from aMap<String, T>, recording changes to the chosen value to the default on-robot log atHighLevelLogger.getLog().- Parameters:
options- The option list, as aMap<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 implementingDashboardChooser.Option.- Type Parameters:
T- The enum's type.- Parameters:
enumClass- The<enum>.classdefaultOption- The default enum optionlogChanges- Whether to log changes in the chosen value to the default robot log atHighLevelLogger.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 implementingDashboardChooser.Option, saving changes to the default log fromHighLevelLogger.getLog()- Type Parameters:
T- The enum's type.- Parameters:
enumClass- The<enum>.classdefaultOption- The default enum option- Returns:
- A new DashboardChooser object.
-
close
public void close()
- Specified by:
closein interfacejava.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:
initSendablein interfaceedu.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.
-
-