/*====================================================================
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::BMDevice component.
 **  Business operations MUST be completed !!!
 **/
public class BMDeviceMonolithicImpl
       extends org.omg.CORBA.LocalObject
    implements CCM_BMDevice,
	       CCM_ReadData,
	       CCM_TimeOutConsumer,
	       org.omg.Components.SessionComponent
{
    // ==================================================================
    //
    // Internal State.
    //
    // ===================================================================
     
    /**
     **  Context reference.
     **/
    private CCM_BMDevice_Context the_context_;
    private String data;
    private int i;
    
    
    private javax.swing.JFrame frame_;

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


     
    // ==================================================================
    //
    // Constructor.
    //
    // ===================================================================
     
    /**
     **  The default constructor.
     **/
    public
    BMDeviceMonolithicImpl()
    {
	data ="BMDevice";
	i=1;
        //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_BMDevice_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("BMDevice's 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_BMDevice_Context)context;
	}*/
     
    public void
    set_session_context(org.omg.Components.SessionContext context)
    throws org.omg.Components.CCMException
    {
        the_context_ = (CCM_BMDevice_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_BMDevice local interface.
    //
    // ==================================================================
     
    //
    //  IDL:cisksu/basicsp/CCM_BMDevice/get_dataOut:1.0
    //
    /**
     **  Implementation of the ::basicsp::CCM_BMDevice::get_dataOut operation.
     **/
    public cisksu.basicsp.CCM_ReadData
    get_dataOut()
    {
        //
        //  TODO : implement
        //
        return this;
    }

    public String getData() {
//	System.err.println("BMDevice got a getData call thread: "+Thread.currentThread().getName());
	//textArea_.append("BMDevice got a getData call" + "\n"); 
        return data;
     }

    //
    //  IDL:cisksu/basicsp/CCM_BMDevice/push_timeOut20:1.0
    //
    /**
     **  Implementation of the ::basicsp::CCM_BMDevice::push_timeOut20 operation.
     **/
    public void
    push_timeOut20(cisksu.basicsp.TimeOut event)
    {
        //
        //  TODO : implement
        //
	//System.err.println("BMDevice got TimeOut20 event");
//	 textArea_.append("BMDevice got "+i+"th TimeOut20 event" + "\n");
         push(event);

    }
    public void push(cisksu.basicsp.TimeOut event) {
//       System.err.println("GPS Thread: "+Thread.currentThread().getName());
	//System.err.println("BMDevice got TimeOut event");
	// textArea_.append( "BMDevice got TimeOut event" + "\n");
	 data="BMDevice"+(i++);
	 the_context_.push_outDataAvailable(new DataAvailableImpl());
    }
}


syntax highlighted by Code2HTML, v. 0.9