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