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