package mil.navy.nps.logger; import mil.navy.nps.dis.*; import mil.navy.nps.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * An editor for an ESPDU. This is usually used in conjuction with * HeaderEditor, a class responsible for editing PDU headers. This * is a concrete subclass of PduEditPanel, responsible for editing * ESPDU-specific pdus.

* * The idea here is to simply have a collection of JLabel and JText * fields, with approximately a one-to-one correspondence between * fields in the pdu and fields in the editor. If we wanted to we * could get fancy and have things like pop-up lists for fields that * should have a limited range of selection, or do translations between * numeric constants and their human-readable counterparts--for example * rather than an entityType field of "17" we'd display a "tank" or * some such.

* * Note that this only edits a subset of the espdu fields. I eliminated * some fields that looked like they would be rarely edited or required * some thought to implement.

* * @author DMcG */ public class EspduEditor extends PduEditPanel { protected EntityStatePdu editedPdu; // PDU we're editing // Editing field Painfully obvious restatement of the obvious // ------------- --------------------------------------------- // entity ID triplet JTextField entitySite; // entityID triplet: site JTextField entityApplication; // entityID triplet: application JTextField entityEntity; // entityID triplet: entity ID JTextField forceID; // force ID // EntityType information; a series of fields JTextField kind; // entityKind JTextField domain; // subsurface, surface, etc JTextField country; // integer code for what nationality (should translate for user) JTextField category; // main category JTextField subCategory; // yada yada // skip over alternate entity type info; add later if you like JTextField linearVelocityX; // how fast JTextField linearVelocityY; // how fast JTextField linearVelocityZ; // how fast // location in world coordinates JTextField worldX; // world coord x JTextField worldY; // world coord y JTextField worldZ; // world Z // orientation JTextField orientationPsi; // euler angle orientation of entity JTextField orientationTheta; // euler angle orientation of entity JTextField orientationPhi; // euler angle orientation of entity JTextField appearance; // how it looks // Leave out dead reckoning stuff JTextField linearAccelerationX; // linear acceleration; JTextField linearAccelerationY; // linear acceleration; JTextField linearAccelerationZ; // linear acceleration; JTextField angularVelocityX; // angular vel JTextField angularVelocityY; // angular vel JTextField angularVelocityZ; // angular vel JTextField marking; // marking on entity /** * Constructor; lay out GUI fields. */ public EspduEditor() { super(); JPanel left, right, draw; left = new JPanel(); left.setLayout(new GridLayout(35,1)); left.add(new JLabel("EntityID triplet")); left.add(new JLabel("Site")); left.add(new JLabel("Application")); left.add(new JLabel("Entity")); left.add(new JLabel("Entity Type")); left.add(new JLabel("Kind")); left.add(new JLabel("Domain")); left.add(new JLabel("Country")); left.add(new JLabel("Category")); left.add(new JLabel("Subcategory")); left.add(new JLabel("Linear Velocity")); left.add(new JLabel(" X")); left.add(new JLabel(" Y")); left.add(new JLabel(" Z")); left.add(new JLabel("Linear Acceleration")); left.add(new JLabel(" X")); left.add(new JLabel(" Y")); left.add(new JLabel(" Z")); left.add(new JLabel("Angular Velocity")); left.add(new JLabel(" X")); left.add(new JLabel(" Y")); left.add(new JLabel(" Z")); left.add(new JLabel("Euler Angles")); left.add(new JLabel("Psi")); left.add(new JLabel("Theta")); left.add(new JLabel("Phi")); left.add(new JLabel("Appearance")); left.add(new JLabel("Marking")); left.add(new JLabel("World Coordinates")); left.add(new JLabel("X")); left.add(new JLabel("Y")); left.add(new JLabel("Z")); // Lay out the text fields and placeholders on the RH side. right = new JPanel(); right.setLayout(new GridLayout(35,1)); right.add(new JLabel(" ")); // empty text field entry to match title on LH side entitySite = new JTextField(); right.add(entitySite); entityApplication = new JTextField(); right.add(entityApplication); entityEntity = new JTextField(); right.add(entityEntity); right.add(new JLabel(" ")); // matches title lable on LH side kind = new JTextField(); right.add(kind); domain = new JTextField(); right.add(domain); country = new JTextField(); right.add(country); category = new JTextField(); right.add(category); subCategory = new JTextField(); right.add(subCategory); // Velocity fields right.add(new JLabel(" ")); // match generic velocity title on left linearVelocityX = new JTextField(); right.add(linearVelocityX); linearVelocityY = new JTextField(); right.add(linearVelocityY); linearVelocityZ = new JTextField(); right.add(linearVelocityZ); // acceleration fields right.add(new JLabel(" ")); // match generic acceleration title on left linearAccelerationX = new JTextField(); right.add(linearAccelerationX); linearAccelerationY = new JTextField(); right.add(linearAccelerationY); linearAccelerationZ = new JTextField(); right.add(linearAccelerationZ); // Angular velocity fields right.add(new JLabel(" ")); // match generic ang vel title on left angularVelocityX = new JTextField(); right.add(angularVelocityX); angularVelocityY = new JTextField(); right.add(angularVelocityY); angularVelocityZ = new JTextField(); right.add(angularVelocityZ); right.add(new JLabel(" ")); // match generic euler angle title on left orientationPsi = new JTextField(); right.add(orientationPsi); orientationTheta = new JTextField(); right.add(orientationTheta); orientationPhi = new JTextField(); right.add(orientationPhi); appearance = new JTextField(); right.add(appearance); marking = new JTextField(); right.add(marking); // World coordinates fields right.add(new JLabel(" ")); worldX = new JTextField(); right.add(worldX); worldY = new JTextField(); right.add(worldY); worldZ = new JTextField(); right.add(worldZ); draw = new JPanel(); draw.setLayout(new GridLayout(1,2)); draw.add(left); draw.add(right); this.add(draw); } /** * When we start editing, we need to pass in a PDU object * for the panel to edit. That's what this does. */ public void setPdu(ProtocolDataUnit pPdu) { // This better be an espdu we're trying to edit. Should check for this before // we get here, but be paranoid. if(!(pPdu instanceof EntityStatePdu)) return; editedPdu = (EntityStatePdu)pPdu; // Fill out the text fields &c with the values in the PDU. Horrific lines of // nested code that basically mean "put a string representation of the number // into the text field" entitySite.setText(new Integer(editedPdu.getEntityID().getSiteID().intValue()).toString()); entityApplication.setText(new Integer(editedPdu.getEntityID().getApplicationID().intValue()).toString()); entityEntity.setText(new Integer(editedPdu.getEntityID().getEntityID().intValue() ).toString()); kind.setText(new Integer(editedPdu.getEntityType().getKind().intValue()).toString()); domain.setText(new Integer(editedPdu.getEntityType().getDomain().intValue()).toString()); country.setText(new Integer(editedPdu.getEntityType().getCountry().intValue()).toString()); category.setText(new Integer(editedPdu.getEntityType().getCategory().intValue()).toString()); subCategory.setText(new Integer(editedPdu.getEntityType().getSubCategory().intValue()).toString()); // Fill out velocity fields linearVelocityX.setText(new Float(editedPdu.getEntityLinearVelocityX()).toString()); linearVelocityY.setText(new Float(editedPdu.getEntityLinearVelocityY()).toString()); linearVelocityZ.setText(new Float(editedPdu.getEntityLinearVelocityZ()).toString()); // Fill out acceleration fields linearAccelerationX.setText(new Float(editedPdu.getEntityLinearAccelerationX()).toString()); linearAccelerationY.setText(new Float(editedPdu.getEntityLinearAccelerationY()).toString()); linearAccelerationZ.setText(new Float(editedPdu.getEntityLinearAccelerationZ()).toString()); // Fill out location fields worldX.setText(new Double(editedPdu.getEntityLocationX()).toString()); worldY.setText(new Double(editedPdu.getEntityLocationY()).toString()); worldZ.setText(new Double(editedPdu.getEntityLocationZ()).toString()); // angular velocity angularVelocityX.setText(new Float(editedPdu.getEntityAngularVelocityX()).toString()); angularVelocityY.setText(new Float(editedPdu.getEntityAngularVelocityY()).toString()); angularVelocityZ.setText(new Float(editedPdu.getEntityAngularVelocityZ()).toString()); // Orientation, etc. (we can ask AND tell.) orientationPsi.setText(new Float(editedPdu.getEntityOrientationPsi()).toString()); orientationTheta.setText(new Float(editedPdu.getEntityOrientationTheta()).toString()); orientationPhi.setText(new Float(editedPdu.getEntityOrientationPhi()).toString()); appearance.setText(new Long(editedPdu.getEntityAppearance().longValue()).toString()); marking.setText(editedPdu.getMarking()); } /** * when the user says we're finished editing, the values in * the fields need to be updated to the pdu object. Then we * return the PDU object. */ public ProtocolDataUnit updatePdu() { try { editedPdu.setEntityID(Short.parseShort(entitySite.getText()), Short.parseShort(entityApplication.getText()), Short.parseShort(entityEntity.getText())); //editedPdu.setForceID(Byte.parseByte(forceID.getText())); editedPdu.setEntityTypeKind(Byte.parseByte(kind.getText())); editedPdu.setEntityTypeDomain(new UnsignedByte(Byte.parseByte(domain.getText()))); editedPdu.setEntityTypeCountry(Integer.parseInt(country.getText())); editedPdu.setEntityTypeCategory(Integer.parseInt(category.getText())); editedPdu.setEntityTypeSubcategory(Integer.parseInt(subCategory.getText())); // Velocity editedPdu.setEntityLinearVelocityX(Float.parseFloat(linearVelocityX.getText())); editedPdu.setEntityLinearVelocityY(Float.parseFloat(linearVelocityY.getText())); editedPdu.setEntityLinearVelocityZ(Float.parseFloat(linearVelocityZ.getText())); // Location editedPdu.setEntityLocationX(Double.parseDouble(worldX.getText())); editedPdu.setEntityLocationY(Double.parseDouble(worldY.getText())); editedPdu.setEntityLocationZ(Double.parseDouble(worldZ.getText())); // Orientation editedPdu.setEntityOrientationPsi(Float.parseFloat(orientationPsi.getText())); editedPdu.setEntityOrientationTheta(Float.parseFloat(orientationTheta.getText())); editedPdu.setEntityOrientationPhi(Float.parseFloat(orientationPhi.getText())); // Appearance editedPdu.setEntityAppearance(Integer.parseInt(appearance.getText())); // Acceleration editedPdu.setEntityLinearAcceleration(Float.parseFloat(linearAccelerationX.getText()), Float.parseFloat(linearAccelerationY.getText()), Float.parseFloat(linearAccelerationZ.getText())); // Angular velocity editedPdu.setEntityAngularVelocity(Float.parseFloat(angularVelocityX.getText()), Float.parseFloat(angularVelocityY.getText()), Float.parseFloat(angularVelocityZ.getText())); editedPdu.setMarking(marking.getText()); } catch(Exception e) { System.out.println(e); } return editedPdu; } }