Skip to content

Commit

Permalink
Add title connection indicator (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinShalit authored and PeterJohnson committed Jul 27, 2017
1 parent 76fbd17 commit 56c59be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import edu.wpi.first.smartdashboard.xml.SmartDashboardXMLReader;
import edu.wpi.first.smartdashboard.xml.SmartDashboardXMLWriter;
import edu.wpi.first.smartdashboard.xml.XMLWidget;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.networktables.NetworkTablesJNI;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
Expand Down Expand Up @@ -38,6 +40,8 @@
*/
public class DashboardFrame extends JFrame {

private static final String TITLE = "SmartDashboard | ";

/*
* If the menu bar is set to "hidden," then this defines what portion of the
* top screen is reserved for revealing the menu bar when the mouse moves
Expand Down Expand Up @@ -96,7 +100,18 @@ public static DashboardFrame getInstance() {
* @param competition whether or not to display as though it were on the netbook
*/
public DashboardFrame(boolean competition) {
super("SmartDashboard - ");
NetworkTablesJNI.ConnectionListenerFunction clf = (uid, connected, conn) -> {
if (NetworkTable.getTable("").isServer()) {
setTitle(TITLE + "Number of Clients: " + NetworkTablesJNI.getConnections().length);
} else if (connected && conn != null) {
setTitle(TITLE + "Connected: " + conn.remote_ip);
} else {
setTitle(TITLE + "Disconnected");
}
};
clf.apply(0, false, null);

NetworkTablesJNI.addConnectionListener(clf, true);

setLayout(new BorderLayout());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public void propertyChanged(Property property) {
frame.setSize(frame.getWidth(), height.getValue());
} else if (property == team) {
Robot.setTeam(team.getValue());
frame.setTitle("SmartDashboard - " + team.getValue());
} else if (property == hideMenu) {
frame.setShouldHideMenu(hideMenu.getValue());
} else if (property == logToCSV) {
Expand Down

0 comments on commit 56c59be

Please sign in to comment.