Initial checkin of unified hierarchy of WPILib 2015

This commit is contained in:
Brad Miller
2013-12-15 18:30:16 -05:00
commit 3178911eef
1560 changed files with 410007 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package edu.wpi.first.table_viewer;
import java.io.*;
public class ConstantPutTest {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
/*DebugNetworkTableTransactionPool pool;
NetworkTableServer client = new NetworkTableServer(SocketStreams.newStreamProvider(1735), new DefaultThreadManager(), pool=new DebugNetworkTableTransactionPool());
boolean x = true;
long start = System.currentTimeMillis();
while(true){
client.putBoolean("my key", x=!x);
if(System.currentTimeMillis()-start>10000)
break;
}
pool.print();*/
}
}

View File

@@ -0,0 +1,18 @@
package edu.wpi.first.table_viewer;
import java.util.Arrays;
import javax.swing.tree.DefaultTreeCellRenderer;
public class DefaultNetworkTablesValueRenderer extends DefaultTreeCellRenderer {
public void setValue(Object value) {
if (value == null) {
setText("null");
} else if (value instanceof Object[]) {
setText(Arrays.toString((Object[]) value));
} else {
setText(value.toString());
}
}
}

View File

@@ -0,0 +1,66 @@
package edu.wpi.first.table_viewer;
import java.util.*;
import javax.swing.table.*;
import edu.wpi.first.wpilibj.networktables2.*;
import edu.wpi.first.wpilibj.tables.*;
public class NetworkTableTableModel extends AbstractTableModel implements ITableListener {
private final NetworkTableNode node;
public NetworkTableTableModel(NetworkTableNode node) {
this.node = node;
node.addTableListener(this, true);
}
private final List<String> keys = new ArrayList<String>();
@Override
public void valueChanged(ITable source, String key, Object value, boolean isNew) {
if(isNew){
keys.add(key);
fireTableRowsInserted(keys.size()-1, keys.size()-1);
}
else{
int row = keys.indexOf(key);
fireTableRowsUpdated(row, row);
}
}
@Override
public int getRowCount() {
return keys.size();
}
@Override
public int getColumnCount() {
return 3;
}
@Override
public String getColumnName(int column){
if(column==0)
return "Key";
if(column==1)
return "Value";
return "Sequence Number";
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if(columnIndex==0)
return keys.get(rowIndex);
try {
if(columnIndex==1)
return node.getValue(keys.get(rowIndex));
return (int)node.getEntryStore().getEntry(keys.get(rowIndex)).getSequenceNumber();
} catch (TableKeyNotDefinedException e) {
return null;
}
}
}

View File

@@ -0,0 +1,14 @@
package edu.wpi.first.table_viewer;
public class TableViewer {
/**
* @param args
*/
public static void main(String[] args) {
TableViewerModePrompt prompt = new TableViewerModePrompt();
prompt.setVisible(true);
}
}

View File

@@ -0,0 +1,37 @@
package edu.wpi.first.table_viewer;
import edu.wpi.first.table_viewer.tree.NetworkTableTree;
import java.awt.*;
import javax.swing.*;
import edu.wpi.first.wpilibj.networktables2.*;
import edu.wpi.first.wpilibj.tables.*;
public class TableViewerFrame extends JFrame implements IRemoteConnectionListener {
private final JLabel statusLabel;
private final NetworkTableTree tree;
public TableViewerFrame(NetworkTableNode node) {
super(node.toString());
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(statusLabel = new JLabel(), BorderLayout.NORTH);
node.addConnectionListener(this, true);
tree = new NetworkTableTree(node);
add(new JScrollPane(tree));
setSize(600, 600);
}
@Override
public void connected(IRemote remote) {
statusLabel.setText("Connected");
}
@Override
public void disconnected(IRemote remote) {
statusLabel.setText("Disconnected");
}
}

View File

@@ -0,0 +1,107 @@
package edu.wpi.first.table_viewer;
import java.awt.*;
import java.awt.event.*;
import java.util.prefs.Preferences;
import javax.swing.*;
import edu.wpi.first.wpilibj.networktables2.*;
import edu.wpi.first.wpilibj.networktables2.client.*;
import edu.wpi.first.wpilibj.networktables2.server.*;
import edu.wpi.first.wpilibj.networktables2.stream.*;
public class TableViewerModePrompt extends JDialog implements ActionListener {
private JTextField hostField;
private JButton launchClientButton, launchServerButton;
private JButton cancelButton;
private Preferences prefs;
public TableViewerModePrompt() {
setTitle("Preferences");
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
setBackground(Color.white);
} catch (Exception e) {
e.printStackTrace();
}
prefs = Preferences.userNodeForPackage(getClass());
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createEmptyBorder(10, 20, 5, 20));
setContentPane(contentPane);
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = 1;
c.gridy = 1;
add(new JLabel("Host: "), c);
c.gridx = 1;
String host;
try {
host = prefs.get("host", "localhost");
} catch (NullPointerException e) {
host = "localhost";
}
add(hostField = new JTextField(host), c);
hostField.addActionListener(this);
hostField.setColumns(20);
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 2;
JPanel buttonPanel = new JPanel();
buttonPanel.add(launchClientButton = new JButton("Start client"));
launchClientButton.addActionListener(this);
buttonPanel.add(launchServerButton = new JButton("Start server"));
launchServerButton.addActionListener(this);
buttonPanel.add(cancelButton = new JButton("Cancel"));
cancelButton.addActionListener(this);
add(buttonPanel, c);
setSize(320, 120);
setMinimumSize(getSize());
pack();
}
public String getHost() {
return hostField.getText();
}
public int getPort() {
return 1735;
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() != cancelButton) {
try {
NetworkTableNode node = null;
if (e.getSource() == launchServerButton) {//server
IOStreamProvider streamProvider = SocketStreams.newStreamProvider(getPort());
node = new NetworkTableServer(streamProvider);
prefs.put("host", "");
} else if (e.getSource() == launchClientButton) {
String host = getHost();
IOStreamFactory streamFactory = SocketStreams.newStreamFactory(host, getPort());
NetworkTableClient client = new NetworkTableClient(streamFactory);
client.reconnect();
node = client;
prefs.put("host", host);
}
TableViewerFrame frame = new TableViewerFrame(node);
frame.setVisible(true);
dispose();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getClass() + ": " + ex.getMessage(), "Error creating table node", JOptionPane.ERROR_MESSAGE);
}
} else {
System.exit(0);
}
}
}

View File

@@ -0,0 +1,38 @@
package edu.wpi.first.table_viewer;
import java.io.*;
import edu.wpi.first.wpilibj.networktables2.client.*;
import edu.wpi.first.wpilibj.networktables2.stream.*;
public class TestClient {
/**
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, InterruptedException {
IOStreamFactory streamFactory = SocketStreams.newStreamFactory("10.1.90.2", 1735);
NetworkTableClient client = new NetworkTableClient(streamFactory);
client.reconnect();
long last = System.currentTimeMillis();
int num = 40;
String[] keys = new String[num];
for(int i = 0; i<num; ++i)
keys[i] = "MyClientKey"+i;
for(int i = 0; true; ++i){
for(int j = 0; j<num; ++j)
client.putBoolean(keys[j], i%2==0);
//server.putNumber("Time", System.currentTimeMillis()-last);
last = System.currentTimeMillis();
Thread.sleep(20);
}
}
}

View File

@@ -0,0 +1,37 @@
package edu.wpi.first.table_viewer;
import java.io.*;
import edu.wpi.first.wpilibj.networktables.*;
public class TestServer {
/**
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, InterruptedException {
NetworkTable server = NetworkTable.getTable("SmartDashboard");
//IOStreamProvider streamProvider = SocketStreams.newStreamProvider(1735);
//NetworkTableServer server = new NetworkTableServer(streamProvider, new DefaultThreadManager(), new NetworkTableTransactionPool());
long last = System.currentTimeMillis();
int num = 40;
String[] keys = new String[num];
for(int i = 0; i<num; ++i)
keys[i] = "MyKey"+i;
for(int i = 0; true; ++i){
for(int j = 0; j<num; ++j)
server.putBoolean(keys[j], i%2==0);
//server.putNumber("Time", System.currentTimeMillis()-last);
last = System.currentTimeMillis();
Thread.sleep(20);
}
}
}

View File

@@ -0,0 +1,54 @@
package edu.wpi.first.table_viewer;
import java.io.*;
import edu.wpi.first.wpilibj.networktables.*;
public class TestTableServer {
static int numVars = 40;
static {
try {
NetworkTable.setServerMode();
NetworkTable.initialize();
} catch (IOException ex) {
ex.printStackTrace();
}
}
static NetworkTable table = NetworkTable.getTable("SmartDashboard");
static String[] vars = new String[numVars];
static {
for (int i = 0; i < numVars; i++) {
vars[i] = "Variable" + i;
}
}
static boolean value = false;
static int counter = 0;
static long loop;
/**
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException,
InterruptedException {
while (true) {
counter++;
value = !value;
loop = System.currentTimeMillis();
for (int v = 0; v < numVars; v++) {
table.putBoolean(vars[v], value);
}
loop = System.currentTimeMillis() - loop;
try {
Thread.sleep(20 - loop);
} catch (Exception e) {
}
}
}
}

View File

@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="keyLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="keyField" max="32767" attributes="0"/>
</Group>
<Component id="jScrollPane1" alignment="0" pref="0" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="140" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" alignment="1" groupAlignment="1" max="-2" attributes="0">
<Component id="removeRowButton" pref="97" max="32767" attributes="0"/>
<Component id="addRowButton" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="okayButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="keyLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="keyField" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="112" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="addRowButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="removeRowButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="13" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="okayButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="keyLabel">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Trebuchet MS" size="12" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Array name"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="keyField">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="keyFieldActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="valueTable">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="2" rowCount="4">
<Column editable="true" title="Value" type="java.lang.String"/>
<Column editable="true" title="Type" type="java.lang.Object"/>
</Table>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0">
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
</TableColumnModel>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="false" resizingAllowed="true"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="okayButton">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okayButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="removeRowButton">
<Properties>
<Property name="text" type="java.lang.String" value="Remove row"/>
<Property name="toolTipText" type="java.lang.String" value="Remove the selected row"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[20, 20]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removeRowButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="addRowButton">
<Properties>
<Property name="text" type="java.lang.String" value="Add row"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[20, 20]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addRowButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@@ -0,0 +1,201 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.dialog;
import edu.wpi.first.wpilibj.networktables2.type.ArrayData;
import edu.wpi.first.wpilibj.networktables2.type.ArrayEntryType;
import edu.wpi.first.wpilibj.networktables2.type.DefaultEntryTypes;
import edu.wpi.first.wpilibj.networktables2.type.NetworkTableEntryType;
import edu.wpi.first.wpilibj.tables.ITable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Sam
*/
public class AddArrayDialog extends IAddValueDialog {
private JComboBox typeEditor = new JComboBox(new String[]{"Boolean", "Number", "String", "Object"});
public AddArrayDialog(ITable table) {
super(table);
initComponents();
setMinimumSize(getSize());
valueTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(typeEditor));
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
keyLabel = new javax.swing.JLabel();
keyField = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
valueTable = new javax.swing.JTable();
cancelButton = new javax.swing.JButton();
okayButton = new javax.swing.JButton();
removeRowButton = new javax.swing.JButton();
addRowButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
keyLabel.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
keyLabel.setText("Array name");
keyField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
keyFieldActionPerformed(evt);
}
});
valueTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null}
},
new String [] {
"Value", "Type"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.Object.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
valueTable.getTableHeader().setReorderingAllowed(false);
jScrollPane1.setViewportView(valueTable);
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
okayButton.setText("OK");
okayButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okayButtonActionPerformed(evt);
}
});
removeRowButton.setText("Remove row");
removeRowButton.setToolTipText("Remove the selected row");
removeRowButton.setPreferredSize(new java.awt.Dimension(20, 20));
removeRowButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeRowButtonActionPerformed(evt);
}
});
addRowButton.setText("Add row");
addRowButton.setPreferredSize(new java.awt.Dimension(20, 20));
addRowButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addRowButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(keyLabel)
.addGap(18, 18, 18)
.addComponent(keyField))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 140, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(removeRowButton, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
.addComponent(addRowButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(okayButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton)))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(keyLabel)
.addComponent(keyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addRowButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(removeRowButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(okayButton)))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void keyFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keyFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_keyFieldActionPerformed
private void addRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRowButtonActionPerformed
((DefaultTableModel) valueTable.getModel()).insertRow(valueTable.getSelectedRow() + 1, new Object[]{null, null});
}//GEN-LAST:event_addRowButtonActionPerformed
private void removeRowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeRowButtonActionPerformed
try {
((DefaultTableModel) valueTable.getModel()).removeRow(valueTable.getSelectedRow());
} catch (ArrayIndexOutOfBoundsException e) {
((DefaultTableModel) valueTable.getModel()).removeRow(valueTable.getModel().getRowCount() - 1);
}
}//GEN-LAST:event_removeRowButtonActionPerformed
private void okayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okayButtonActionPerformed
try {
dispose();
} catch (Exception e) {
e.printStackTrace();
}
}//GEN-LAST:event_okayButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addRowButton;
private javax.swing.JButton cancelButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField keyField;
private javax.swing.JLabel keyLabel;
private javax.swing.JButton okayButton;
private javax.swing.JButton removeRowButton;
private javax.swing.JTable valueTable;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="trueFalseGroup">
</Component>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="keyLabel" min="-2" pref="130" max="-2" attributes="0"/>
<Component id="keyField" pref="140" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="31" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="trueButton" linkSize="1" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jSeparator1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="okayButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="falseButton" linkSize="1" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="12" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="keyLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="keyField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="trueButton" linkSize="2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="falseButton" linkSize="2" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jSeparator1" min="-2" pref="10" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="okayButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JToggleButton" name="trueButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="trueFalseGroup"/>
</Property>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="True"/>
</Properties>
</Component>
<Component class="javax.swing.JToggleButton" name="falseButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="trueFalseGroup"/>
</Property>
<Property name="text" type="java.lang.String" value="False"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="falseButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="keyField">
</Component>
<Component class="javax.swing.JButton" name="okayButton">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okayButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="keyLabel">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Trebuchet MS" size="12" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Variable name:"/>
</Properties>
</Component>
<Component class="javax.swing.JSeparator" name="jSeparator1">
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Trebuchet MS" size="12" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Value:"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@@ -0,0 +1,161 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.dialog;
import edu.wpi.first.wpilibj.tables.ITable;
/**
*
* @author Sam
*/
public class AddBooleanDialog extends IAddValueDialog {
/**
* Creates new form AddBooleanDialog
*/
public AddBooleanDialog(ITable table) {
super(table);
setTitle("Add Boolean");
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
trueFalseGroup = new javax.swing.ButtonGroup();
trueButton = new javax.swing.JToggleButton();
falseButton = new javax.swing.JToggleButton();
keyField = new javax.swing.JTextField();
okayButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
keyLabel = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
trueFalseGroup.add(trueButton);
trueButton.setSelected(true);
trueButton.setText("True");
trueFalseGroup.add(falseButton);
falseButton.setText("False");
falseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
falseButtonActionPerformed(evt);
}
});
okayButton.setText("OK");
okayButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okayButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
keyLabel.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
keyLabel.setText("Variable name:");
jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
jLabel1.setText("Value:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(keyLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(keyField, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(trueButton)
.addComponent(jLabel1)))
.addComponent(jSeparator1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(okayButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton))
.addComponent(falseButton, javax.swing.GroupLayout.Alignment.TRAILING))))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {falseButton, trueButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(keyLabel)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(keyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(trueButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(falseButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(okayButton)
.addComponent(cancelButton))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {falseButton, trueButton});
pack();
}// </editor-fold>//GEN-END:initComponents
private void falseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_falseButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_falseButtonActionPerformed
private void okayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okayButtonActionPerformed
// TODO add your handling code here:
if(keyField.getText().isEmpty()) {
return;
}
table.putBoolean(keyField.getText(), trueButton.isSelected());
dispose();
}//GEN-LAST:event_okayButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO add your handling code here:
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JToggleButton falseButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextField keyField;
private javax.swing.JLabel keyLabel;
private javax.swing.JButton okayButton;
private javax.swing.JToggleButton trueButton;
private javax.swing.ButtonGroup trueFalseGroup;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="valueLabel" max="32767" attributes="0"/>
<Component id="keyLabel" max="32767" attributes="0"/>
</Group>
<EmptySpace type="separate" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="valueField" max="32767" attributes="0"/>
<Component id="keyField" max="32767" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="0" pref="67" max="32767" attributes="0"/>
<Component id="okayButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="keyLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="keyField" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="valueLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="valueField" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="okayButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JTextField" name="keyField">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="keyFieldActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="valueField">
</Component>
<Component class="javax.swing.JLabel" name="keyLabel">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Trebuchet MS" size="12" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Variable name"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="valueLabel">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Trebuchet MS" size="12" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Value"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="okayButton">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okayButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@@ -0,0 +1,136 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.dialog;
import edu.wpi.first.wpilibj.tables.ITable;
/**
*
* @author Sam
*/
public class AddNumberDialog extends IAddValueDialog {
public AddNumberDialog(ITable table) {
super(table);
setTitle("Add number");
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
keyField = new javax.swing.JTextField();
valueField = new javax.swing.JTextField();
keyLabel = new javax.swing.JLabel();
valueLabel = new javax.swing.JLabel();
okayButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
keyField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
keyFieldActionPerformed(evt);
}
});
keyLabel.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
keyLabel.setText("Variable name");
valueLabel.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
valueLabel.setText("Value");
okayButton.setText("OK");
okayButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okayButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(valueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(keyLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(valueField)
.addComponent(keyField)))
.addGroup(layout.createSequentialGroup()
.addGap(0, 67, Short.MAX_VALUE)
.addComponent(okayButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(keyLabel)
.addComponent(keyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(valueLabel)
.addComponent(valueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(okayButton)
.addComponent(cancelButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void keyFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keyFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_keyFieldActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO add your handling code here:
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void okayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okayButtonActionPerformed
// TODO add your handling code here:
try {
table.putNumber(keyField.getText(), Double.parseDouble(valueField.getText()));
dispose();
} catch (NumberFormatException e) {
}
}//GEN-LAST:event_okayButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JTextField keyField;
private javax.swing.JLabel keyLabel;
private javax.swing.JButton okayButton;
private javax.swing.JTextField valueField;
private javax.swing.JLabel valueLabel;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,136 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.dialog;
import edu.wpi.first.wpilibj.tables.ITable;
/**
*
* @author Sam
*/
public class AddStringDialog extends IAddValueDialog {
public AddStringDialog(ITable table) {
super(table);
setTitle("Add string");
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
keyField = new javax.swing.JTextField();
valueField = new javax.swing.JTextField();
keyLabel = new javax.swing.JLabel();
valueLabel = new javax.swing.JLabel();
okayButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
keyField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
keyFieldActionPerformed(evt);
}
});
keyLabel.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
keyLabel.setText("Variable name");
valueLabel.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
valueLabel.setText("Value");
okayButton.setText("OK");
okayButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okayButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(valueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(keyLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(valueField)
.addComponent(keyField)))
.addGroup(layout.createSequentialGroup()
.addGap(0, 67, Short.MAX_VALUE)
.addComponent(okayButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(keyLabel)
.addComponent(keyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(valueLabel)
.addComponent(valueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(okayButton)
.addComponent(cancelButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void keyFieldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
private void okayButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
table.putNumber(keyField.getText(), Double.parseDouble(valueField.getText()));
dispose();
} catch (NumberFormatException e) {
}
}
// Variables declaration - do not modify
private javax.swing.JButton cancelButton;
private javax.swing.JTextField keyField;
private javax.swing.JLabel keyLabel;
private javax.swing.JButton okayButton;
private javax.swing.JTextField valueField;
private javax.swing.JLabel valueLabel;
// End of variables declaration
}

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="trueFalseGroup">
</Component>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="trueButton" max="32767" attributes="0"/>
<Component id="okayButton" max="32767" attributes="0"/>
</Group>
<EmptySpace pref="60" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="falseButton" max="32767" attributes="0"/>
<Component id="cancelButton" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="trueButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="falseButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="okayButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="okayButton">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okayButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToggleButton" name="trueButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection component="trueFalseGroup" type="bean"/>
</Property>
<Property name="text" type="java.lang.String" value="True"/>
</Properties>
</Component>
<Component class="javax.swing.JToggleButton" name="falseButton">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection component="trueFalseGroup" type="bean"/>
</Property>
<Property name="text" type="java.lang.String" value="False"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@@ -0,0 +1,111 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.dialog;
import edu.wpi.first.table_viewer.tree.LeafNode;
/**
*
* @author Sam
*/
public class EditBooleanDialog extends javax.swing.JDialog {
private final LeafNode leaf;
public EditBooleanDialog(LeafNode leaf) {
super();
this.leaf = leaf;
initComponents();
trueButton.setSelected(Boolean.getBoolean(leaf.getValue()));
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
trueFalseGroup = new javax.swing.ButtonGroup();
okayButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
trueButton = new javax.swing.JToggleButton();
falseButton = new javax.swing.JToggleButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
okayButton.setText("OK");
okayButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okayButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
trueFalseGroup.add(trueButton);
trueButton.setText("True");
trueFalseGroup.add(falseButton);
falseButton.setText("False");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(trueButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(okayButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(falseButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancelButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(8, 8, 8)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(trueButton)
.addComponent(falseButton))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(okayButton)
.addComponent(cancelButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void okayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okayButtonActionPerformed
// TODO add your handling code here:
leaf.setTableValue(trueButton.isSelected());
dispose();
}//GEN-LAST:event_okayButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// TODO add your handling code here:
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JToggleButton falseButton;
private javax.swing.JButton okayButton;
private javax.swing.JToggleButton trueButton;
private javax.swing.ButtonGroup trueFalseGroup;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0">
<Component id="okButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="editorLabel" min="-2" pref="84" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="208" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" min="-2" max="-2" attributes="0"/>
<Component id="editorLabel" min="-2" pref="27" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="okButton" min="-2" max="-2" attributes="0"/>
<Component id="cancelButton" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="inputField">
<Properties>
<Property name="columns" type="int" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="2" type="code"/>
</Property>
<Property name="rows" type="int" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="1" type="code"/>
</Property>
<Property name="text" type="java.lang.String" value="Double"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="editorLabel">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Change value:"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="okButton">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@@ -0,0 +1,124 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.dialog;
import edu.wpi.first.table_viewer.tree.TableEntryData;
import edu.wpi.first.table_viewer.tree.LeafNode;
import edu.wpi.first.table_viewer.*;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JDialog;
/**
*
* @author Sam
*/
public class EditNumberDialog extends JDialog {
private LeafNode leaf;
public EditNumberDialog(LeafNode leaf) {
super();
setTitle("Edit Number");
this.leaf = leaf;
initComponents();
inputField.setText(((TableEntryData) leaf.getUserObject()).getValue());
setResizable(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
inputField = new javax.swing.JTextArea();
editorLabel = new javax.swing.JLabel();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
inputField.setColumns(2);
inputField.setRows(1);
inputField.setText("Double");
jScrollPane1.setViewportView(inputField);
editorLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
editorLabel.setText("Change value:");
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(okButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancelButton))
.addGroup(layout.createSequentialGroup()
.addComponent(editorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(editorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(okButton)
.addComponent(cancelButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
try {
leaf.setTableValue(Double.parseDouble(inputField.getText()));
dispose();
} catch (NumberFormatException e) {
inputField.setForeground(Color.red);
inputField.setFont(inputField.getFont().deriveFont(Font.BOLD));
}
}//GEN-LAST:event_okButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JLabel editorLabel;
private javax.swing.JTextArea inputField;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,119 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.dialog;
import edu.wpi.first.table_viewer.tree.TableEntryData;
import edu.wpi.first.table_viewer.tree.LeafNode;
import edu.wpi.first.table_viewer.*;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JDialog;
/**
*
* @author Sam
*/
public class EditStringDialog extends JDialog {
private LeafNode leaf;
public EditStringDialog(LeafNode leaf) {
super();
setTitle("Edit String");
this.leaf = leaf;
initComponents();
inputField.setText(((TableEntryData) leaf.getUserObject()).getValue());
setResizable(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
inputField = new javax.swing.JTextArea();
editorLabel = new javax.swing.JLabel();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
inputField.setColumns(2);
inputField.setRows(1);
inputField.setText("Double");
jScrollPane1.setViewportView(inputField);
editorLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
editorLabel.setText("Change value:");
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(okButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cancelButton))
.addGroup(layout.createSequentialGroup()
.addComponent(editorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(editorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(okButton)
.addComponent(cancelButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
leaf.setTableValue(inputField.getText());
dispose();
}
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
// Variables declaration - do not modify
private javax.swing.JButton cancelButton;
private javax.swing.JLabel editorLabel;
private javax.swing.JTextArea inputField;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton okButton;
// End of variables declaration
}

View File

@@ -0,0 +1,23 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.dialog;
import edu.wpi.first.wpilibj.tables.ITable;
import javax.swing.JDialog;
/**
*
* @author Sam
*/
public abstract class IAddValueDialog extends JDialog {
protected ITable table;
public IAddValueDialog(ITable table) {
super();
this.table = table;
}
}

View File

@@ -0,0 +1,57 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.tree;
import edu.wpi.first.wpilibj.tables.ITable;
import java.awt.Menu;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JPopupMenu;
/**
*
* @author Sam
*/
public class BranchNode extends ITableNode {
private Map<String, ITableNode> entries = new HashMap<>();
public BranchNode(ITable table) {
this(table, "NetworkTables");
}
public BranchNode(ITable table, String name) {
super(table, name, true);
table.addTableListener(this, true);
table.addSubTableListener(this);
setAllowsChildren(true);
}
@Override
public void valueChanged(ITable source, String key, Object value, boolean isNew) {
if (isNew && !entries.containsKey(key)) {
if (value.toString().startsWith("NetworkTable: /")) {
String tableName = value.toString().substring(source.toString().length() + 1);
BranchNode branch = new BranchNode(source.getSubTable(tableName), key);
this.add(branch);
entries.put(key, branch);
} else {
LeafNode leaf = new LeafNode(source, key, value);
this.add(leaf);
entries.put(key, leaf);
}
}
}
@Override
public boolean isLeaf() {
return false;
}
@Override
public JPopupMenu getMenu() {
return menu;
}
}

View File

@@ -0,0 +1,72 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.tree;
import edu.wpi.first.table_viewer.dialog.AddBooleanDialog;
import edu.wpi.first.table_viewer.dialog.AddNumberDialog;
import edu.wpi.first.table_viewer.dialog.AddStringDialog;
import edu.wpi.first.wpilibj.tables.ITable;
import edu.wpi.first.wpilibj.tables.ITableListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
/**
*
* @author Sam
*/
public abstract class ITableNode extends DefaultMutableTreeNode implements ITableListener {
protected JPopupMenu menu = new JPopupMenu();
protected static DefaultTreeModel treeModel;
public static void setTree(JTree tree) {
treeModel = (DefaultTreeModel) tree.getModel();
}
public ITableNode(final ITable table, Object userObject, boolean allowsChildren) {
super(userObject, allowsChildren);
JMenuItem addBoolean = new JMenuItem("Add boolean"),
addNumber = new JMenuItem("Add number"),
addString = new JMenuItem("Add string");
addBoolean.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new AddBooleanDialog(table).setVisible(true);
}
});
addNumber.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new AddNumberDialog(table).setVisible(true);
}
});
addString.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new AddStringDialog(table).setVisible(true);
}
});
menu.add(addBoolean);
menu.add(addNumber);
menu.add(addString);
}
@Override
public abstract boolean isLeaf();
public abstract JPopupMenu getMenu();
}

View File

@@ -0,0 +1,84 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.tree;
import edu.wpi.first.table_viewer.dialog.EditBooleanDialog;
import edu.wpi.first.table_viewer.dialog.EditNumberDialog;
import edu.wpi.first.table_viewer.dialog.EditStringDialog;
import edu.wpi.first.wpilibj.tables.ITable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
/**
*
* @author Sam
*/
public class LeafNode extends ITableNode {
private ITable table;
private String key;
private boolean insertedEdit = false;
public LeafNode(ITable table, String key, Object value) {
super(table, new TableEntryData(key, value), false);
table.addTableListener(key, this, true);
this.table = table;
this.key = key;
}
public String getKey() {
return key;
}
public String getValue() {
return ((TableEntryData) userObject).getValue();
}
public String getType() {
return ((TableEntryData) userObject).getType();
}
public void setTableValue(Object newValue) {
table.putValue(key, newValue);
}
@Override
public boolean isLeaf() {
return true;
}
@Override
public void valueChanged(ITable source, String key, Object value, boolean isNew) {
setUserObject(new TableEntryData(key, value));
treeModel.reload(this);
}
@Override
public JPopupMenu getMenu() {
if (!insertedEdit) {
JMenuItem editorItem = new JMenuItem("Edit");
editorItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (getType().equals("BOOLEAN")) {
new EditBooleanDialog(LeafNode.this).setVisible(true);
} else if (getType().equals("NUMBER")) {
new EditNumberDialog(LeafNode.this).setVisible(true);
} else if (getType().equals("STRING")) {
new EditStringDialog(LeafNode.this).setVisible(true);
}
}
});
menu.add(editorItem, 0);
menu.add(new JSeparator(), 1);
insertedEdit = true;
}
return menu;
}
}

View File

@@ -0,0 +1,86 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.tree;
import edu.wpi.first.table_viewer.dialog.EditBooleanDialog;
import edu.wpi.first.table_viewer.dialog.EditNumberDialog;
import edu.wpi.first.table_viewer.dialog.EditStringDialog;
import edu.wpi.first.wpilibj.networktables.NetworkTableProvider;
import edu.wpi.first.wpilibj.networktables2.NetworkTableNode;
import edu.wpi.first.wpilibj.tables.ITable;
import edu.wpi.first.wpilibj.tables.ITableListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultTreeModel;
/**
*
* @author Sam
*/
public class NetworkTableTree extends JTree implements ITableListener {
private final BranchNode rootNode;
public NetworkTableTree(NetworkTableNode node) {
super();
ITable table = new NetworkTableProvider(node).getRootTable();
ITableNode.setTree(this);
rootNode = new BranchNode(table);
table.addTableListener(this, true);
table.addSubTableListener(this);
((DefaultTreeModel) this.getModel()).setRoot(rootNode);
MouseAdapter ml = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int selRow = getRowForLocation(e.getX(), e.getY());
if (SwingUtilities.isRightMouseButton(e)) {
int row = getClosestRowForLocation(e.getX(), e.getY());
setSelectionRow(row);
handleRightClick(e.getX(), e.getY());
}
if (selRow != -1) {
if (e.getClickCount() == 2) {
handleDoubleClick();
}
}
}
};
addMouseListener(ml);
}
private void handleDoubleClick() {
ITableNode selectedNode = ((ITableNode) getSelectionPath().getLastPathComponent());
if (selectedNode instanceof LeafNode) {
if (((LeafNode) selectedNode).getType().equalsIgnoreCase("number")) {
new EditNumberDialog((LeafNode) selectedNode).setVisible(true);
} else if (((LeafNode) selectedNode).getType().equalsIgnoreCase("string")) {
new EditStringDialog((LeafNode) selectedNode).setVisible(true);
} else if (((LeafNode) selectedNode).getType().equalsIgnoreCase("boolean")) {
new EditBooleanDialog((LeafNode) selectedNode).setVisible(true);
}
}
}
private void handleRightClick(int x, int y) {
ITableNode selectedNode = ((ITableNode) getSelectionPath().getLastPathComponent());
System.out.println("Right click at [" + x + "," + y + "] on node " + selectedNode);
JPopupMenu m = selectedNode.getMenu();
m.show(this, x, y);
}
@Override
public void valueChanged(ITable source, String key, Object value, boolean isNew) {
System.out.println(key + " changed to " + value);
((DefaultTreeModel) this.getModel()).reload();
}
}

View File

@@ -0,0 +1,93 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.table_viewer.tree;
import edu.wpi.first.wpilibj.networktables2.type.NumberArray;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Sam
*/
public class TableEntryData {
private Object key, value, type;
public TableEntryData(String key, Object value) {
this.key = key;
try {
this.value = new ArrayWrapper(value);
} catch (Exception ex) {
if (value instanceof Number) {
DecimalFormat format = new DecimalFormat("#.#####");
String dblVal = format.format((double) value);
this.value = dblVal;
} else {
this.value = value;
}
}
this.type = typeFromValue(value);
}
public String getKey() {
return key.toString();
}
public String getValue() {
return value.toString();
}
public String getType() {
return type.toString();
}
@Override
public String toString() {
return key + space + value + space + type;
}
private final String space = " ";
private String typeFromValue(Object value) {
String valueClassName = value.getClass().toString().substring(value.getClass().toString().lastIndexOf(".") + 1);
switch (valueClassName.toLowerCase()) {
case "boolean":
return "BOOLEAN";
case "double":
return "NUMBER";
case "string":
return "STRING";
case "object;": // the semicolon is required to catch arrays
return "ARRAY";
default:
return valueClassName.toUpperCase();
}
}
private class ArrayWrapper {
private Object[] array;
ArrayWrapper(Object array) throws Exception {
if (array instanceof Object[]) {
this.array = (Object[]) array;
} else {
throw new RuntimeException();
}
}
@Override
public String toString() {
String arrStr = Arrays.toString(array);
if (arrStr.length() > 2) {
return arrStr.substring(1, arrStr.length() - 1);
} else {
return "Empty";
}
}
}
}