}
});
/* get an input verifier for mac addresses */
InputVerifier macInputVerifier = new InputVerifier() {
@Override
public boolean verify(JComponent input) {
try{
@SuppressWarnings("unused")
MACAddress addr = new MACAddress(((JTextField)input).getText());
} catch (Exception e) {
return false;
}
return true;
}
/*
* (non-Javadoc)
* @see javax.swing.InputVerifier#shouldYieldFocus(javax.swing.JComponent)
*/
public boolean shouldYieldFocus(JComponent input){
if(!verify(input)){
((JTextField)input).setBackground(Color.RED);
return false;
} else {
((JTextField)input).setBackground(Color.WHITE);
return true;
}
}
};
/* set the input verifier for the MAC text fields */
this.macDestAddrTextField.setInputVerifier(macInputVerifier);
/* write destination MAC address to the hardware */
this.macDestAddrTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateDestMac();
}
});
/* set the input verifier for the source MAC address */
this.macSrcAddrTextField.setInputVerifier(macInputVerifier);
/* write the source mac address to the hardware */
this.macSrcAddrTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateSrcMac();
}
});
/* get an input verifier for integers */
InputVerifier integerInputVerifier = new InputVerifier() {
@Override
public boolean verify(JComponent input) {
try{
Integer.parseInt(((JTextField)input).getText());
} catch (Exception e) {
return false;
}
return true;
}
/*
* (non-Javadoc)
* @see javax.swing.InputVerifier#shouldYieldFocus(javax.swing.JComponent)
*/
public boolean shouldYieldFocus(JComponent input){
if(!verify(input)){
((JTextField)input).setBackground(Color.RED);
return false;
} else {
((JTextField)input).setBackground(Color.WHITE);
return true;
}
}
};
/* set the graph num points input verifier */
this.graphSizeTextField.setInputVerifier(integerInputVerifier);
/* add action listener to set graph size */
this.graphSizeTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateGraphSizes();
}
});
/* Set udp destination port text field input verifier */
this.udpDestPortTextField.setInputVerifier(integerInputVerifier);
/* set the action listener */
this.udpDestPortTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateUdpDestField();
}
});
/* Set udp Source port text field input verifier */
this.udpSrcPortTextField.setInputVerifier(integerInputVerifier);
/* set the action listener */
this.udpSrcPortTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateUdpSrcField();
}
});
/* create an IP address input verifier */
InputVerifier ipInputVerifier = new InputVerifier() {
@Override
public boolean verify(JComponent input) {
try{
new IPAddress(((JTextField)input).getText());
} catch (Exception e) {