Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title connection indicator #87

Merged
merged 2 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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