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.util.ErrorMessages.requireNonNullParam;
008
009import edu.wpi.first.networktables.NetworkTable;
010import edu.wpi.first.util.function.FloatSupplier;
011import edu.wpi.first.util.sendable.Sendable;
012import java.util.List;
013import java.util.function.BooleanSupplier;
014import java.util.function.DoubleSupplier;
015import java.util.function.LongSupplier;
016import java.util.function.Supplier;
017
018/** A layout in a Shuffleboard tab. Layouts can contain widgets and other layouts. */
019public final class ShuffleboardLayout extends ShuffleboardComponent<ShuffleboardLayout>
020    implements ShuffleboardContainer {
021  private static final String kSmartDashboardType = "ShuffleboardLayout";
022
023  private final ContainerHelper m_helper = new ContainerHelper(this);
024
025  ShuffleboardLayout(ShuffleboardContainer parent, String title, String type) {
026    super(parent, title, requireNonNullParam(type, "type", "ShuffleboardLayout"));
027  }
028
029  @Override
030  public List<ShuffleboardComponent<?>> getComponents() {
031    return m_helper.getComponents();
032  }
033
034  @Override
035  public ShuffleboardLayout getLayout(String title, String type) {
036    return m_helper.getLayout(title, type);
037  }
038
039  @Override
040  public ShuffleboardLayout getLayout(String title) {
041    return m_helper.getLayout(title);
042  }
043
044  @Override
045  public ComplexWidget add(String title, Sendable sendable) {
046    return m_helper.add(title, sendable);
047  }
048
049  @Override
050  public ComplexWidget add(Sendable sendable) {
051    return m_helper.add(sendable);
052  }
053
054  @Override
055  public SimpleWidget add(String title, Object defaultValue) {
056    return m_helper.add(title, defaultValue);
057  }
058
059  @Override
060  public SimpleWidget add(String title, String typeString, Object defaultValue) {
061    return m_helper.add(title, typeString, defaultValue);
062  }
063
064  @Override
065  public SuppliedValueWidget<String> addString(String title, Supplier<String> valueSupplier) {
066    return m_helper.addString(title, valueSupplier);
067  }
068
069  @Override
070  public SuppliedValueWidget<Double> addNumber(String title, DoubleSupplier valueSupplier) {
071    return m_helper.addNumber(title, valueSupplier);
072  }
073
074  @Override
075  public SuppliedValueWidget<Double> addDouble(String title, DoubleSupplier valueSupplier) {
076    return m_helper.addDouble(title, valueSupplier);
077  }
078
079  @Override
080  public SuppliedValueWidget<Float> addFloat(String title, FloatSupplier valueSupplier) {
081    return m_helper.addFloat(title, valueSupplier);
082  }
083
084  @Override
085  public SuppliedValueWidget<Long> addInteger(String title, LongSupplier valueSupplier) {
086    return m_helper.addInteger(title, valueSupplier);
087  }
088
089  @Override
090  public SuppliedValueWidget<Boolean> addBoolean(String title, BooleanSupplier valueSupplier) {
091    return m_helper.addBoolean(title, valueSupplier);
092  }
093
094  @Override
095  public SuppliedValueWidget<String[]> addStringArray(
096      String title, Supplier<String[]> valueSupplier) {
097    return m_helper.addStringArray(title, valueSupplier);
098  }
099
100  @Override
101  public SuppliedValueWidget<double[]> addDoubleArray(
102      String title, Supplier<double[]> valueSupplier) {
103    return m_helper.addDoubleArray(title, valueSupplier);
104  }
105
106  @Override
107  public SuppliedValueWidget<float[]> addFloatArray(String title, Supplier<float[]> valueSupplier) {
108    return m_helper.addFloatArray(title, valueSupplier);
109  }
110
111  @Override
112  public SuppliedValueWidget<long[]> addIntegerArray(String title, Supplier<long[]> valueSupplier) {
113    return m_helper.addIntegerArray(title, valueSupplier);
114  }
115
116  @Override
117  public SuppliedValueWidget<boolean[]> addBooleanArray(
118      String title, Supplier<boolean[]> valueSupplier) {
119    return m_helper.addBooleanArray(title, valueSupplier);
120  }
121
122  @Override
123  public SuppliedValueWidget<byte[]> addRaw(
124      String title, String typeString, Supplier<byte[]> valueSupplier) {
125    return m_helper.addRaw(title, typeString, valueSupplier);
126  }
127
128  @Override
129  public void buildInto(NetworkTable parentTable, NetworkTable metaTable) {
130    buildMetadata(metaTable);
131    NetworkTable table = parentTable.getSubTable(getTitle());
132    table.getEntry(".type").setString(kSmartDashboardType);
133    table
134        .getEntry(".type")
135        .getTopic()
136        .setProperty("SmartDashboard", "\"" + kSmartDashboardType + "\"");
137    for (ShuffleboardComponent<?> component : getComponents()) {
138      component.buildInto(table, metaTable.getSubTable(component.getTitle()));
139    }
140  }
141}