001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.wpilibj.shuffleboard;
006
007import edu.wpi.first.networktables.NetworkTable;
008import edu.wpi.first.util.sendable.Sendable;
009import java.util.List;
010import java.util.function.BooleanSupplier;
011import java.util.function.DoubleSupplier;
012import java.util.function.Supplier;
013
014/**
015 * Represents a tab in the Shuffleboard dashboard. Widgets can be added to the tab with {@link
016 * #add(Sendable)}, {@link #add(String, Object)}, and {@link #add(String, Sendable)}. Widgets can
017 * also be added to layouts with {@link #getLayout(String, String)}; layouts can be nested
018 * arbitrarily deep (note that too many levels may make deeper components unusable).
019 */
020public final class ShuffleboardTab implements ShuffleboardContainer {
021  private final ContainerHelper m_helper = new ContainerHelper(this);
022  private final ShuffleboardRoot m_root;
023  private final String m_title;
024
025  ShuffleboardTab(ShuffleboardRoot root, String title) {
026    m_root = root;
027    m_title = title;
028  }
029
030  @Override
031  public String getTitle() {
032    return m_title;
033  }
034
035  ShuffleboardRoot getRoot() {
036    return m_root;
037  }
038
039  @Override
040  public List<ShuffleboardComponent<?>> getComponents() {
041    return m_helper.getComponents();
042  }
043
044  @Override
045  public ShuffleboardLayout getLayout(String title, String type) {
046    return m_helper.getLayout(title, type);
047  }
048
049  @Override
050  public ShuffleboardLayout getLayout(String title) {
051    return m_helper.getLayout(title);
052  }
053
054  @Override
055  public ComplexWidget add(String title, Sendable sendable) {
056    return m_helper.add(title, sendable);
057  }
058
059  @Override
060  public ComplexWidget add(Sendable sendable) {
061    return m_helper.add(sendable);
062  }
063
064  @Override
065  public SimpleWidget add(String title, Object defaultValue) {
066    return m_helper.add(title, defaultValue);
067  }
068
069  @Override
070  public SuppliedValueWidget<String> addString(String title, Supplier<String> valueSupplier) {
071    return m_helper.addString(title, valueSupplier);
072  }
073
074  @Override
075  public SuppliedValueWidget<Double> addNumber(String title, DoubleSupplier valueSupplier) {
076    return m_helper.addNumber(title, valueSupplier);
077  }
078
079  @Override
080  public SuppliedValueWidget<Boolean> addBoolean(String title, BooleanSupplier valueSupplier) {
081    return m_helper.addBoolean(title, valueSupplier);
082  }
083
084  @Override
085  public SuppliedValueWidget<String[]> addStringArray(
086      String title, Supplier<String[]> valueSupplier) {
087    return m_helper.addStringArray(title, valueSupplier);
088  }
089
090  @Override
091  public SuppliedValueWidget<double[]> addDoubleArray(
092      String title, Supplier<double[]> valueSupplier) {
093    return m_helper.addDoubleArray(title, valueSupplier);
094  }
095
096  @Override
097  public SuppliedValueWidget<boolean[]> addBooleanArray(
098      String title, Supplier<boolean[]> valueSupplier) {
099    return m_helper.addBooleanArray(title, valueSupplier);
100  }
101
102  @Override
103  public SuppliedValueWidget<byte[]> addRaw(String title, Supplier<byte[]> valueSupplier) {
104    return m_helper.addRaw(title, valueSupplier);
105  }
106
107  @Override
108  public void buildInto(NetworkTable parentTable, NetworkTable metaTable) {
109    NetworkTable tabTable = parentTable.getSubTable(m_title);
110    tabTable.getEntry(".type").setString("ShuffleboardTab");
111    for (ShuffleboardComponent<?> component : m_helper.getComponents()) {
112      component.buildInto(tabTable, metaTable.getSubTable(component.getTitle()));
113    }
114  }
115}