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 static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
008
009import edu.wpi.first.networktables.NetworkTable;
010import edu.wpi.first.util.sendable.Sendable;
011import java.util.List;
012import java.util.function.BooleanSupplier;
013import java.util.function.DoubleSupplier;
014import java.util.function.Supplier;
015
016/** A layout in a Shuffleboard tab. Layouts can contain widgets and other layouts. */
017public class ShuffleboardLayout extends ShuffleboardComponent<ShuffleboardLayout>
018    implements ShuffleboardContainer {
019  private final ContainerHelper m_helper = new ContainerHelper(this);
020
021  ShuffleboardLayout(ShuffleboardContainer parent, String title, String type) {
022    super(parent, title, requireNonNullParam(type, "type", "ShuffleboardLayout"));
023  }
024
025  @Override
026  public List<ShuffleboardComponent<?>> getComponents() {
027    return m_helper.getComponents();
028  }
029
030  @Override
031  public ShuffleboardLayout getLayout(String title, String type) {
032    return m_helper.getLayout(title, type);
033  }
034
035  @Override
036  public ShuffleboardLayout getLayout(String title) {
037    return m_helper.getLayout(title);
038  }
039
040  @Override
041  public ComplexWidget add(String title, Sendable sendable) {
042    return m_helper.add(title, sendable);
043  }
044
045  @Override
046  public ComplexWidget add(Sendable sendable) {
047    return m_helper.add(sendable);
048  }
049
050  @Override
051  public SimpleWidget add(String title, Object defaultValue) {
052    return m_helper.add(title, defaultValue);
053  }
054
055  @Override
056  public SuppliedValueWidget<String> addString(String title, Supplier<String> valueSupplier) {
057    return m_helper.addString(title, valueSupplier);
058  }
059
060  @Override
061  public SuppliedValueWidget<Double> addNumber(String title, DoubleSupplier valueSupplier) {
062    return m_helper.addNumber(title, valueSupplier);
063  }
064
065  @Override
066  public SuppliedValueWidget<Boolean> addBoolean(String title, BooleanSupplier valueSupplier) {
067    return m_helper.addBoolean(title, valueSupplier);
068  }
069
070  @Override
071  public SuppliedValueWidget<String[]> addStringArray(
072      String title, Supplier<String[]> valueSupplier) {
073    return m_helper.addStringArray(title, valueSupplier);
074  }
075
076  @Override
077  public SuppliedValueWidget<double[]> addDoubleArray(
078      String title, Supplier<double[]> valueSupplier) {
079    return m_helper.addDoubleArray(title, valueSupplier);
080  }
081
082  @Override
083  public SuppliedValueWidget<boolean[]> addBooleanArray(
084      String title, Supplier<boolean[]> valueSupplier) {
085    return m_helper.addBooleanArray(title, valueSupplier);
086  }
087
088  @Override
089  public SuppliedValueWidget<byte[]> addRaw(String title, Supplier<byte[]> valueSupplier) {
090    return m_helper.addRaw(title, valueSupplier);
091  }
092
093  @Override
094  public void buildInto(NetworkTable parentTable, NetworkTable metaTable) {
095    buildMetadata(metaTable);
096    NetworkTable table = parentTable.getSubTable(getTitle());
097    table.getEntry(".type").setString("ShuffleboardLayout");
098    for (ShuffleboardComponent<?> component : getComponents()) {
099      component.buildInto(table, metaTable.getSubTable(component.getTitle()));
100    }
101  }
102}