FileDocCategorySizeDatePackage
OpenRtpDialog.javaAPI DocJMF 2.1.1e9265Mon May 12 12:20:32 BST 2003jmapps.jmstudio

OpenRtpDialog

public class OpenRtpDialog extends JMDialog implements TextListener, FocusListener

Fields Summary
private TextField
fieldAddress0
private TextField
fieldAddress1
private TextField
fieldAddress2
private TextField
fieldAddress3
private TextField
fieldPort
private Choice
choiceTtl
private JMAppsCfg
cfgJMApps
private String
strAddress
private String
strPort
private String
strTtl
Constructors Summary
public OpenRtpDialog(Frame frame, JMAppsCfg cfgJMApps)



            
        super ( frame, JMFI18N.getResource("jmstudio.openrtp.title"), true );

        this.cfgJMApps = cfgJMApps;
        init ();
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

    	String		strAction;

    	strAction = event.getActionCommand ();
        if ( strAction.equals(ACTION_OPEN) ) {
            if ( validateData() == true ) {
                this.setAction ( strAction );
                this.dispose ();
            }
        }
        else if ( strAction.equals(ACTION_CANCEL) ) {
            this.setAction ( strAction );
            this.dispose ();
        }
    
private jmapps.ui.JMPanelcreatePanelSource()

    	JMPanel                 panelSource;
    	JMPanel	                panelLabels;
    	JMPanel	                panelParams;
    	JMPanel	                panelAddress;
        Label                   label;
        JMAppsCfg.RtpData     dataRtp;


        dataRtp = cfgJMApps.getLastOpenRtpData();

    	panelSource = new JMPanel ( new BorderLayout(6,6) );

    	panelLabels = new JMPanel ( new GridLayout(0,1,6,6) );
    	panelSource.add ( panelLabels, BorderLayout.WEST );
    	panelParams = new JMPanel ( new GridLayout(0,1,6,6) );
    	panelSource.add ( panelParams, BorderLayout.CENTER );

        label = new Label ( JMFI18N.getResource("jmstudio.openrtp.label.address") );
    	panelLabels.add ( label );
    	panelAddress = new JMPanel ( new GridLayout(1,0,2,2) );
    	panelParams.add ( panelAddress );

    	fieldAddress0 = new TextField ( 3 );
        if ( dataRtp != null )
            fieldAddress0.setText ( dataRtp.strAddress0 );
        fieldAddress0.addTextListener ( this );
	fieldAddress0.addFocusListener(this);
    	panelAddress.add ( fieldAddress0 );

    	fieldAddress1 = new TextField ( 3 );
        if ( dataRtp != null )
            fieldAddress1.setText ( dataRtp.strAddress1 );
        fieldAddress1.addTextListener ( this );
	fieldAddress1.addFocusListener(this);
    	panelAddress.add ( fieldAddress1 );

    	fieldAddress2 = new TextField ( 3 );
        if ( dataRtp != null )
            fieldAddress2.setText ( dataRtp.strAddress2 );
        fieldAddress2.addTextListener ( this );
	fieldAddress2.addFocusListener(this);
    	panelAddress.add ( fieldAddress2 );

    	fieldAddress3 = new TextField ( 3 );
        if ( dataRtp != null )
            fieldAddress3.setText ( dataRtp.strAddress3 );
        fieldAddress3.addTextListener ( this );
	fieldAddress3.addFocusListener(this);
    	panelAddress.add ( fieldAddress3 );

        label = new Label ( JMFI18N.getResource("jmstudio.openrtp.label.port") );
    	panelLabels.add ( label );
    	fieldPort = new TextField ( 5 );
        if ( dataRtp != null )
            fieldPort.setText ( dataRtp.strPort );
	fieldPort.addFocusListener(this);
    	panelParams.add ( fieldPort );

        label = new Label ( JMFI18N.getResource("jmstudio.openrtp.label.ttl") );
    	panelLabels.add ( label );
    	choiceTtl = new Choice ();
    	panelParams.add ( choiceTtl );

    	choiceTtl.addItem ( "1" );
    	choiceTtl.addItem ( "2" );
    	choiceTtl.addItem ( "3" );
    	choiceTtl.addItem ( "4" );
    	choiceTtl.addItem ( "8" );
    	choiceTtl.addItem ( "16" );
    	choiceTtl.addItem ( "32" );
    	choiceTtl.addItem ( "64" );
    	choiceTtl.addItem ( "128" );
    	choiceTtl.addItem ( "255" );
        if ( dataRtp != null )
            choiceTtl.select ( dataRtp.strTtl );

    	return ( panelSource );
    
public voidfocusGained(java.awt.event.FocusEvent fe)

	Object source = fe.getSource();
	// Select the text in the field
	if (source instanceof TextField)
	    ((TextField)source).selectAll();
    
public voidfocusLost(java.awt.event.FocusEvent fe)

	Object source = fe.getSource();
	// Deselect the text in the field
	if (source instanceof TextField)
	    ((TextField)source).select(1, 0);
    
public java.lang.StringgetAddress()

        return ( strAddress );
    
public java.lang.StringgetPort()

        return ( strPort );
    
public java.lang.StringgetTtl()

        return ( strTtl );
    
private voidinit()

        JMPanel     panel;
        JMPanel     panelButtons;
        JMPanel     panelContent;

        this.setLayout ( new BorderLayout() );
        panelContent = new JMPanel ( new BorderLayout(6,6) );
        panelContent.setEmptyBorder ( 6, 6, 6, 6 );
        this.add ( panelContent, BorderLayout.CENTER );
        panelContent.setBackground ( Color.lightGray );

        panel = createPanelSource ();
        panelContent.add ( panel, BorderLayout.CENTER );

        panel = new JMPanel ( new FlowLayout(FlowLayout.CENTER) );
        this.add ( panel, BorderLayout.SOUTH );
        panelButtons = createButtonPanel ( new String[] { ACTION_OPEN, ACTION_CANCEL } );
        panel.add ( panelButtons );

        pack ();
        setResizable (false);
    
public voidsetVisible(boolean show)

        super.setVisible ( show );
        fieldAddress0.requestFocus ();
    
public voidtextValueChanged(java.awt.event.TextEvent event)

    	Object		objectSource;
    	TextField	textField;
    	String		strValue;

    	objectSource = event.getSource ();
    	if ( objectSource instanceof TextField ) {
    	    textField = (TextField) objectSource;
    	    strValue = textField.getText ();
    	    if ( strValue.length() > 2 )
    	    	textField.transferFocus ();
    	}
    
public booleanvalidateData()

        String                  strValue;
        int                     nValue;
        JMAppsCfg.RtpData     dataRtp;


        dataRtp = cfgJMApps.createRtpDataObject ();

        strValue = fieldAddress0.getText ();
        dataRtp.strAddress0 = strValue;
        try {
            nValue = Integer.valueOf(strValue).intValue();
        }
        catch ( Exception exception ) {
            nValue = -1;
        }
        if ( nValue < 0  ||  nValue > 255 ) {
            MessageDialog.createErrorDialog ( this.frameOwner, JMFI18N.getResource("jmstudio.error.sessionaddr") );
            return ( false );
        }
        strAddress = new String ( strValue );

        strValue = fieldAddress1.getText ();
        dataRtp.strAddress1 = strValue;
        try {
            nValue = Integer.valueOf(strValue).intValue();
        }
        catch ( Exception exception ) {
            nValue = -1;
        }
        if ( nValue < 0  ||  nValue > 255 ) {
            MessageDialog.createErrorDialog ( this.frameOwner, JMFI18N.getResource("jmstudio.error.sessionaddr") );
            return ( false );
        }
        strAddress = strAddress + "." + strValue;

        strValue = fieldAddress2.getText ();
        dataRtp.strAddress2 = strValue;
        try {
            nValue = Integer.valueOf(strValue).intValue();
        }
        catch ( Exception exception ) {
            nValue = -1;
        }
        if ( nValue < 0  ||  nValue > 255 ) {
            MessageDialog.createErrorDialog ( this.frameOwner, JMFI18N.getResource("jmstudio.error.sessionaddr") );
            return ( false );
        }
        strAddress = strAddress + "." + strValue;

        strValue = fieldAddress3.getText ();
        dataRtp.strAddress3 = strValue;
        try {
            nValue = Integer.valueOf(strValue).intValue();
        }
        catch ( Exception exception ) {
            nValue = -1;
        }
        if ( nValue < 0  ||  nValue > 255 ) {
            MessageDialog.createErrorDialog ( this.frameOwner, JMFI18N.getResource("jmstudio.error.sessionaddr") );
            return ( false );
        }
        strAddress = strAddress + "." + strValue;

        strPort = fieldPort.getText ();
        dataRtp.strPort = strPort;
        try {
            nValue = Integer.valueOf(strPort).intValue();
        }
        catch ( Exception exception ) {
            nValue = -1;
        }
        if ( nValue < 0  ||  (nValue & 0x0001) == 0x0001 ) {
            MessageDialog.createErrorDialog ( this.frameOwner, JMFI18N.getResource("jmstudio.error.port") );
            return ( false );
        }

        strTtl = choiceTtl.getSelectedItem ();
        dataRtp.strTtl = strTtl;

        if ( cfgJMApps != null )
            cfgJMApps.setLastOpenRtpData ( dataRtp );
        return ( true );