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.networktables.NetworkTableEntry; 009 010/** A Shuffleboard widget that handles a single data point such as a number or string. */ 011public final class SimpleWidget extends ShuffleboardWidget<SimpleWidget> { 012 private NetworkTableEntry m_entry; 013 014 SimpleWidget(ShuffleboardContainer parent, String title) { 015 super(parent, title); 016 } 017 018 /** 019 * Gets the NetworkTable entry that contains the data for this widget. 020 * 021 * @return The NetworkTable entry that contains the data for this widget. 022 */ 023 public NetworkTableEntry getEntry() { 024 if (m_entry == null) { 025 forceGenerate(); 026 } 027 return m_entry; 028 } 029 030 @Override 031 public void buildInto(NetworkTable parentTable, NetworkTable metaTable) { 032 buildMetadata(metaTable); 033 if (m_entry == null) { 034 m_entry = parentTable.getEntry(getTitle()); 035 } 036 } 037 038 private void forceGenerate() { 039 ShuffleboardContainer parent = getParent(); 040 while (parent instanceof ShuffleboardLayout) { 041 parent = ((ShuffleboardLayout) parent).getParent(); 042 } 043 ShuffleboardTab tab = (ShuffleboardTab) parent; 044 tab.getRoot().update(); 045 } 046}