package mil.navy.nps.logger; import mil.navy.nps.dis.*; import javax.swing.*; /** * This is an abstract superclass that extends * JPanel. The idea is that the JPanel defined * here is responsible for editing PDUs. After the * JPanel is created we can pass in a PDU. The * concrete subclass of PduEditor knows about that * PDU type, for example ESPDU. Based on that knowledge * it can create an editing context--basically a * series of lables and text fields for modifying * the data in the PDU. The PduEditor subclass fills * out the text fields based on the PDU passed in. * when editing is done, another method is called, * and values in the text fields are passed back into * the PDU. The PDU is returned. Typically editing of * the pdu is done by side effect--we pass in the PDU, * it gets edited in the editor panel, and then we just * use the edited PDU.

* * @author DMcG */ public abstract class PduEditPanel extends JPanel { JLabel label; /** * When we start editing, we need to pass in a PDU object * for the panel to edit. That's what this does. */ public abstract void setPdu(ProtocolDataUnit pPdu); /** * 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 abstract ProtocolDataUnit updatePdu(); /** * This is a factory method for editing panels. We * need a different editing panel for each type of pdu-- * the one for espdus won't work for fire or detonate * pdus. This method, given a pdu, will construct an editing * panel of the correct type for that pdu. See "factory" * in any book of software patterns. */ public static PduEditPanel editPanelFactory(ProtocolDataUnit pdu) { PduEditPanel result = null; // the correct panel for this pdu result = new DefaultEditor(); // default, just holds a place, does nothing. if(pdu instanceof EntityStatePdu) { result = new EspduEditor(); } // Add other editing panels here..... return result; } }