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.function.FloatSupplier; 009import edu.wpi.first.util.sendable.Sendable; 010import java.util.List; 011import java.util.function.BooleanSupplier; 012import java.util.function.DoubleSupplier; 013import java.util.function.LongSupplier; 014import java.util.function.Supplier; 015 016/** 017 * Represents a tab in the Shuffleboard dashboard. Widgets can be added to the tab with {@link 018 * #add(Sendable)}, {@link #add(String, Object)}, and {@link #add(String, Sendable)}. Widgets can 019 * also be added to layouts with {@link #getLayout(String, String)}; layouts can be nested 020 * arbitrarily deep (note that too many levels may make deeper components unusable). 021 */ 022public final class ShuffleboardTab implements ShuffleboardContainer { 023 private final ContainerHelper m_helper = new ContainerHelper(this); 024 private final ShuffleboardRoot m_root; 025 private final String m_title; 026 027 ShuffleboardTab(ShuffleboardRoot root, String title) { 028 m_root = root; 029 m_title = title; 030 } 031 032 @Override 033 public String getTitle() { 034 return m_title; 035 } 036 037 ShuffleboardRoot getRoot() { 038 return m_root; 039 } 040 041 @Override 042 public List<ShuffleboardComponent<?>> getComponents() { 043 return m_helper.getComponents(); 044 } 045 046 @Override 047 public ShuffleboardLayout getLayout(String title, String type) { 048 return m_helper.getLayout(title, type); 049 } 050 051 @Override 052 public ShuffleboardLayout getLayout(String title) { 053 return m_helper.getLayout(title); 054 } 055 056 @Override 057 public ComplexWidget add(String title, Sendable sendable) { 058 return m_helper.add(title, sendable); 059 } 060 061 @Override 062 public ComplexWidget add(Sendable sendable) { 063 return m_helper.add(sendable); 064 } 065 066 @Override 067 public SimpleWidget add(String title, Object defaultValue) { 068 return m_helper.add(title, defaultValue); 069 } 070 071 @Override 072 public SimpleWidget add(String title, String typeString, Object defaultValue) { 073 return m_helper.add(title, typeString, defaultValue); 074 } 075 076 @Override 077 public SuppliedValueWidget<String> addString(String title, Supplier<String> valueSupplier) { 078 return m_helper.addString(title, valueSupplier); 079 } 080 081 @Override 082 public SuppliedValueWidget<Double> addNumber(String title, DoubleSupplier valueSupplier) { 083 return m_helper.addNumber(title, valueSupplier); 084 } 085 086 @Override 087 public SuppliedValueWidget<Double> addDouble(String title, DoubleSupplier valueSupplier) { 088 return m_helper.addDouble(title, valueSupplier); 089 } 090 091 @Override 092 public SuppliedValueWidget<Float> addFloat(String title, FloatSupplier valueSupplier) { 093 return m_helper.addFloat(title, valueSupplier); 094 } 095 096 @Override 097 public SuppliedValueWidget<Long> addInteger(String title, LongSupplier valueSupplier) { 098 return m_helper.addInteger(title, valueSupplier); 099 } 100 101 @Override 102 public SuppliedValueWidget<Boolean> addBoolean(String title, BooleanSupplier valueSupplier) { 103 return m_helper.addBoolean(title, valueSupplier); 104 } 105 106 @Override 107 public SuppliedValueWidget<String[]> addStringArray( 108 String title, Supplier<String[]> valueSupplier) { 109 return m_helper.addStringArray(title, valueSupplier); 110 } 111 112 @Override 113 public SuppliedValueWidget<double[]> addDoubleArray( 114 String title, Supplier<double[]> valueSupplier) { 115 return m_helper.addDoubleArray(title, valueSupplier); 116 } 117 118 @Override 119 public SuppliedValueWidget<float[]> addFloatArray(String title, Supplier<float[]> valueSupplier) { 120 return m_helper.addFloatArray(title, valueSupplier); 121 } 122 123 @Override 124 public SuppliedValueWidget<long[]> addIntegerArray(String title, Supplier<long[]> valueSupplier) { 125 return m_helper.addIntegerArray(title, valueSupplier); 126 } 127 128 @Override 129 public SuppliedValueWidget<boolean[]> addBooleanArray( 130 String title, Supplier<boolean[]> valueSupplier) { 131 return m_helper.addBooleanArray(title, valueSupplier); 132 } 133 134 @Override 135 public SuppliedValueWidget<byte[]> addRaw( 136 String title, String typeString, Supplier<byte[]> valueSupplier) { 137 return m_helper.addRaw(title, typeString, valueSupplier); 138 } 139 140 @Override 141 public void buildInto(NetworkTable parentTable, NetworkTable metaTable) { 142 NetworkTable tabTable = parentTable.getSubTable(m_title); 143 tabTable.getEntry(".type").setString("ShuffleboardTab"); 144 for (ShuffleboardComponent<?> component : m_helper.getComponents()) { 145 component.buildInto(tabTable, metaTable.getSubTable(component.getTitle())); 146 } 147 } 148}