Skip to content

Commit

Permalink
Update for 2016
Browse files Browse the repository at this point in the history
  • Loading branch information
spinda committed Feb 13, 2016
0 parents commit 03f5228
Show file tree
Hide file tree
Showing 22 changed files with 479 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.metadata
bin/
dist/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# robotnik-inspector

If just want to grab the latest build of the Inspector, see the
[Releases](https://github.com/frc604/robotnik-inspector/releases) tab.

Otherwise, this repository is an Eclipse project. You should be able to simply
clone it and import the project into your Eclipse workspace.

Binary file added lib/networktables.jar
Binary file not shown.
34 changes: 34 additions & 0 deletions src/com/_604robotics/robotnik/inspector/Inspector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com._604robotics.robotnik.inspector;

import com._604robotics.robotnik.inspector.gui.InspectorWindow;
import com._604robotics.robotnik.inspector.gui.LoadingWindow;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Inspector {
public static void main (String[] args) {
final LoadingWindow loadingWindow = new LoadingWindow();
loadingWindow.setVisible(true);

NetworkTable.setClientMode();

NetworkTable.setIPAddress("10.6.4.2");
NetworkTable.setTeam(604);

final NetworkTable table = NetworkTable.getTable("robotnik");

while (!table.isConnected()) {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(InspectorWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}

loadingWindow.setVisible(false);

final InspectorWindow inspectorWindow = new InspectorWindow(table);
inspectorWindow.setVisible(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com._604robotics.robotnik.inspector.data.action;

import com._604robotics.robotnik.inspector.model.collection.NetworkSectionCollection;
import com._604robotics.robotnik.inspector.model.map.NetworkDataMap;
import edu.wpi.first.wpilibj.tables.ITable;

public class ActionFieldsBinding extends NetworkSectionCollection {
public ActionFieldsBinding (ITable table) {
super("Fields", table);
}

@Override
protected void bindSubTable (String name, ITable table) {
this.addSection(new NetworkDataMap(name, table.getSubTable(name)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com._604robotics.robotnik.inspector.data.action;

import com._604robotics.robotnik.inspector.model.collection.SectionCollection;
import com._604robotics.robotnik.inspector.model.map.NetworkDataMap;
import edu.wpi.first.wpilibj.tables.ITable;

public class ActionsBinding extends SectionCollection {
public ActionsBinding (ITable table) {
super("Actions");

this.addSection(new NetworkDataMap("Status", table.getSubTable("status")));
this.addSection(new ActionFieldsBinding(table.getSubTable("data")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com._604robotics.robotnik.inspector.data.module;

import com._604robotics.robotnik.inspector.data.action.ActionsBinding;
import com._604robotics.robotnik.inspector.model.collection.SectionCollection;
import com._604robotics.robotnik.inspector.model.map.NetworkDataMap;
import edu.wpi.first.wpilibj.tables.ITable;

public class ModuleBinding extends SectionCollection {
public ModuleBinding (String name, ITable table) {
super(name);

this.addSection(new ActionsBinding(table.getSubTable("actions")));
this.addSection(new NetworkDataMap("Data", table.getSubTable("data")));
this.addSection(new NetworkDataMap("Triggers", table.getSubTable("triggers")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com._604robotics.robotnik.inspector.data.module;

import com._604robotics.robotnik.inspector.model.collection.NetworkSectionCollection;
import edu.wpi.first.wpilibj.tables.ITable;

public class ModulesBinding extends NetworkSectionCollection {
public ModulesBinding (ITable table) {
super("Modules", table);
}

@Override
protected void bindSubTable (String name, ITable table) {
this.addSection(new ModuleBinding(name, table.getSubTable(name)));
}
}
22 changes: 22 additions & 0 deletions src/com/_604robotics/robotnik/inspector/gui/InspectorWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com._604robotics.robotnik.inspector.gui;

import com._604robotics.robotnik.inspector.data.module.ModulesBinding;
import com._604robotics.robotnik.inspector.gui.data.View;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import java.awt.BorderLayout;
import javax.swing.JFrame;

public class InspectorWindow extends JFrame {
public InspectorWindow (NetworkTable table) {
super("robotnik-inspector");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLocation(64, 64);
this.setSize(800, 600);

this.setLayout(new BorderLayout());

this.add(View.fromSection(new ModulesBinding(table.getSubTable("modules"))), BorderLayout.CENTER);
}
}
20 changes: 20 additions & 0 deletions src/com/_604robotics/robotnik/inspector/gui/LoadingWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com._604robotics.robotnik.inspector.gui;

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class LoadingWindow extends JFrame {
public LoadingWindow () {
super("robotnik-inspector");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLocation(64, 64);
this.setSize(205, 50);

this.setLayout(new BorderLayout());

this.add(new JLabel(" ... Connecting to 10.6.4.2 ... "), BorderLayout.CENTER);
}
}
22 changes: 22 additions & 0 deletions src/com/_604robotics/robotnik/inspector/gui/data/DataMapView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com._604robotics.robotnik.inspector.gui.data;

import com._604robotics.robotnik.inspector.model.map.DataMap;
import com._604robotics.robotnik.inspector.model.map.IChangeListener;
import java.awt.BorderLayout;
import javax.swing.JTable;

public class DataMapView extends View implements IChangeListener {
private final JTable table = new JTable();

public DataMapView (DataMap data) {
this.table.setModel(data.getModel());
this.add(this.table, BorderLayout.CENTER);

data.addChangeListener(this);
}

@Override
public void valueChanged (String key, String value) {
this.table.repaint();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com._604robotics.robotnik.inspector.gui.data;

import javax.swing.JLabel;

public class InvalidView extends View {
public InvalidView () {
this.add(new JLabel("No matching type."));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com._604robotics.robotnik.inspector.gui.data;

import com._604robotics.robotnik.inspector.model.Section;
import com._604robotics.robotnik.inspector.model.collection.SectionCollection;
import java.awt.BorderLayout;
import javax.swing.JTabbedPane;

public class SectionCollectionView extends View {
private final JTabbedPane tabs = new JTabbedPane();

public SectionCollectionView (SectionCollection data) {
for (Section section : data.getSections()) {
this.tabs.add(section.getName(), View.fromSection(section));
}

this.add(this.tabs, BorderLayout.CENTER);
}
}
23 changes: 23 additions & 0 deletions src/com/_604robotics/robotnik/inspector/gui/data/View.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com._604robotics.robotnik.inspector.gui.data;

import com._604robotics.robotnik.inspector.model.Section;
import com._604robotics.robotnik.inspector.model.collection.SectionCollection;
import com._604robotics.robotnik.inspector.model.map.DataMap;
import java.awt.BorderLayout;
import javax.swing.JPanel;

public abstract class View extends JPanel {
public static View fromSection (Section section) {
if (section instanceof SectionCollection) {
return new SectionCollectionView((SectionCollection) section);
} else if (section instanceof DataMap) {
return new DataMapView((DataMap) section);
} else {
return new InvalidView();
}
}

public View () {
this.setLayout(new BorderLayout());
}
}
13 changes: 13 additions & 0 deletions src/com/_604robotics/robotnik/inspector/model/Section.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com._604robotics.robotnik.inspector.model;

public abstract class Section {
private final String name;

public Section (String name) {
this.name = name;
}

public String getName () {
return this.name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com._604robotics.robotnik.inspector.model.collection;

import com._604robotics.robotnik.inspector.model.Section;

public interface ISectionListener {
public abstract void newSection (Section section);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com._604robotics.robotnik.inspector.model.collection;

import edu.wpi.first.wpilibj.tables.ITable;
import edu.wpi.first.wpilibj.tables.ITableListener;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public abstract class NetworkSectionCollection extends SectionCollection implements ITableListener {
private final Set<String> knownKeys = new HashSet<String>();

private final ITable table;

public NetworkSectionCollection (String name, ITable table) {
super(name);

this.table = table;
this.table.addTableListener("__index", this, false);

this.scanKeys();
}

protected abstract void bindSubTable (String name, ITable table);

private void scanKeys () {
final String[] keys = this.table.getString("__index", "").split(";");

for (String key : keys) {
if (!key.equals("") && !this.knownKeys.contains(key)) {
this.knownKeys.add(key);

this.bindSubTable(key, this.table);
}
}
}

@Override
public void valueChanged (ITable source, String key, Object value, boolean isNew) {
this.bindSubTable(key, this.table);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com._604robotics.robotnik.inspector.model.collection;

import com._604robotics.robotnik.inspector.model.Section;
import java.util.ArrayList;
import java.util.List;

public abstract class SectionCollection extends Section {
private final List<Section> sections = new ArrayList<Section>();
private final List<ISectionListener> listeners = new ArrayList<ISectionListener>();

public SectionCollection (String name) {
super(name);
}

protected void addSection (Section section) {
this.sections.add(section);

for (ISectionListener listener : this.listeners) {
listener.newSection(section);
}
}

public Section[] getSections () {
return this.sections.toArray(new Section[this.sections.size()]);
}

public void addListener (ISectionListener listener) {
this.listeners.add(listener);
}
}
Loading

0 comments on commit 03f5228

Please sign in to comment.