Skip to content

Commit f6f4bd1

Browse files
committed
Add title connection indicator
1 parent 8580725 commit f6f4bd1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/main/java/edu/wpi/first/smartdashboard/gui/DashboardFrame.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import edu.wpi.first.smartdashboard.xml.SmartDashboardXMLReader;
1111
import edu.wpi.first.smartdashboard.xml.SmartDashboardXMLWriter;
1212
import edu.wpi.first.smartdashboard.xml.XMLWidget;
13+
import edu.wpi.first.wpilibj.networktables.NetworkTable;
14+
import edu.wpi.first.wpilibj.networktables.NetworkTablesJNI;
1315
import java.awt.BorderLayout;
1416
import java.awt.CardLayout;
1517
import java.awt.Dimension;
@@ -38,6 +40,8 @@
3840
*/
3941
public class DashboardFrame extends JFrame {
4042

43+
private static final String TITLE = "SmartDashboard | ";
44+
4145
/*
4246
* If the menu bar is set to "hidden," then this defines what portion of the
4347
* top screen is reserved for revealing the menu bar when the mouse moves
@@ -96,7 +100,18 @@ public static DashboardFrame getInstance() {
96100
* @param competition whether or not to display as though it were on the netbook
97101
*/
98102
public DashboardFrame(boolean competition) {
99-
super("SmartDashboard - ");
103+
NetworkTablesJNI.ConnectionListenerFunction clf = (uid, connected, conn) -> {
104+
if (NetworkTable.getTable("").isServer()) {
105+
setTitle(TITLE + "Number of Clients: " + NetworkTablesJNI.getConnections().length);
106+
} else if (connected && conn != null) {
107+
setTitle(TITLE + "Connected: " + conn.remote_ip);
108+
} else {
109+
setTitle(TITLE + "Disconnected");
110+
}
111+
};
112+
clf.apply(0, false, null);
113+
114+
NetworkTablesJNI.addConnectionListener(clf, true);
100115

101116
setLayout(new BorderLayout());
102117

src/main/java/edu/wpi/first/smartdashboard/gui/DashboardPrefs.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ public void propertyChanged(Property property) {
117117
frame.setSize(frame.getWidth(), height.getValue());
118118
} else if (property == team) {
119119
Robot.setTeam(team.getValue());
120-
frame.setTitle("SmartDashboard - " + team.getValue());
121120
} else if (property == hideMenu) {
122121
frame.setShouldHideMenu(hideMenu.getValue());
123122
} else if (property == logToCSV) {

0 commit comments

Comments
 (0)