/*====================================================================
Tnis file was produced by the OpenCCM ir3_jimpl generator.
OpenCCM: The Open CORBA Component Model Platform
Copyright (C) 2000-2002 USTL - LIFL - GOAL
Contact: openccm-team@objectweb.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA
Initial developer(s): Philippe Merle, Mathieu Vadet.
Contributor(s): ______________________________________.
====================================================================*/
 
package cisksu.basicsp;
 
/**
 **  Implementation skeleton class for the ::basicsp::BMDisplay component.
 **  Business operations MUST be completed !!!
 **/
public class BMDisplayMonolithicImpl
       extends org.omg.CORBA.LocalObject
    implements CCM_BMDisplay,
	       CCM_DataAvailableConsumer,
             org.omg.Components.SessionComponent
{
    // ==================================================================
    //
    // Internal State.
    //
    // ===================================================================
     
    /**
     **  Context reference.
     **/
    private CCM_BMDisplay_Context the_context_;
    String data; 

    private javax.swing.JFrame frame_;

    /** To refer to the GUI output area. */
    private javax.swing.JTextArea textArea_;

    // ==================================================================
    //
    // Constructor.
    //
    // ===================================================================
     
    /**
     **  The default constructor.
     **/
    public
    BMDisplayMonolithicImpl()
    {
        //the_context_ = null;
    }
     
    // ==================================================================
    //
    // Internal methods.
    //
    // ===================================================================
     
    // ==================================================================
    //
    // Public methods.
    //
    // ===================================================================
     
    /**
     **  To obtain the context.
     **
     **  @return The context that has been previously set by 
     **          the set_ccm_context operation.
     **/
    /*public CCM_BMDisplay_Context
    getContext()
    {
        return the_context_;
	}*/
    // ==================================================================
    //
    // Methods for the OMG IDL Components::EnterpriseComponent local interface.
    //
    // ==================================================================
     
    //
    //  IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
    //
    /**
     **  Completes the component configuration.
     **
     **  @throws org.omg.Components.InvalidConfiguration
     **          Thrown if the configuration is invalid.     
     **/
    public void
    configuration_complete()
    throws org.omg.Components.InvalidConfiguration
    {
        //
        //  TODO : implement !!!
        //
	frame_ = new javax.swing.JFrame("BMDisplay's Server GUI");
        // Sets its size.
        frame_.setSize(400, 300);

        // Creates a text area for displaying inputs.
        textArea_ = new javax.swing.JTextArea(40, 20);
        textArea_.setEditable(false);

        // Constructs and shows the GUI.
        javax.swing.JPanel panel = new javax.swing.JPanel(
                                       new java.awt.BorderLayout()
                                   );
        frame_.getContentPane().add(panel);
        panel.add(new javax.swing.JScrollPane(textArea_),
                  java.awt.BorderLayout.CENTER);
        frame_.pack();
        frame_.show();
    }
     
    //
    //  IDL:omg.org/Components/EnterpriseComponent/set_ccm_context:1.0
    //
    /**
     **  Set the component context.
     **
     **  @param context The context.
     **
     **  @throws org.omg.Components.CCMException
     **          Thrown if a system level error occured.
     **/
    /*public void
    set_ccm_context(org.omg.Components.CCMContext context)
    throws org.omg.Components.CCMException
    {
        the_context_ = (CCM_BMDisplay_Context)context;
	}*/
     
       public void
    set_session_context(org.omg.Components.SessionContext context)
    throws org.omg.Components.CCMException
    {
        the_context_ = (CCM_BMDisplay_Context)context;
    }

    /**
     * Container callback to signal that the component is activated.
     *
     * @throw org.omg.Components.CCMException For any problems.
     */
    public void
    ccm_activate()
    throws org.omg.Components.CCMException
    {
        // Nothing to do currently.
    }				

    /**
     * Container callback to signal that the component is activated.
     *
     * @throw org.omg.Components.CCMException For any problems.
     */
    public void
    ccm_passivate()
    throws org.omg.Components.CCMException
    {
        // Nothing to do currently.
    }				

    /**
     * Container callback to signal that the component is removed.
     *
     * @throw org.omg.Components.CCMException For any problems.
     */
    public void
    ccm_remove() 
    throws org.omg.Components.CCMException
    {
	frame_.dispose();
	frame_ = null;
    }				


    // ==================================================================
    //
    // Public methods for the CCM_BMDisplay local interface.
    //
    // ==================================================================
     
    //
    //  IDL:cisksu/basicsp/CCM_BMDisplay/push_inDataAvailable:1.0
    //
    /**
     **  Implementation of the ::basicsp::CCM_BMDisplay::push_inDataAvailable operation.
     **/
    public void
    push_inDataAvailable(cisksu.basicsp.DataAvailable event)
    {
        //
        //  TODO : implement
        //
	// System.err.println("Display got a DataAvailable event");
	//textArea_.append("Display got a DataAvailable event" + "\n");
	push(event);
    }

    /**
     * Implementation of the OMG IDL demo2::FoodBMDisplay::push operation.
     *
     * @param event The received event.
     */
    int i=0;
    public void
    push(cisksu.basicsp.DataAvailable event)
    {
//       System.err.println("Display Thread: "+Thread.currentThread().getName());
        //System.err.println("Display got an event");
	// textArea_.append("Display got an event" + "\n");
       ReadData dataIn=the_context_.get_connection_dataIn();
 //      System.err.println("Display before reading thread: "+Thread.currentThread().getName());
       if(dataIn == null) {
          System.err.println("The basicsp::Display::dataIn receptacle is not set!");
	  return;
	}
	data = dataIn.getData();
	
  //     System.err.println("Display after reading thread: "+Thread.currentThread().getName());
        if(i>=199) {
           textArea_.append("Display "+data+" \n");
	   System.err.println("Display "+data);
	}
	i++;
	//System.err.println("Display: "+data);
    }
}


syntax highlighted by Code2HTML, v. 0.9