// Sample code file: ChatStatusBarSnapin.java

// Warning: This code has been marked up for HTML

/*
   Copyright (c) 2000 Novell, Inc.  All Rights Reserved.

   THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES. 
   USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT 
   ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK. 
   PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A 
   ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS 
   PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET, 
   DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S 
   PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S 
   CUSTOMERS WITH RESPECT TO THIS CODE. 
*/
 


package com.novell.Chat;

// Java imports
import java.awt.*;
import javax.swing.JLabel;
import javax.swing.border.BevelBorder;
import java.util.ResourceBundle;

// ConsoleOne imports
import com.novell.application.console.snapin.*;
import com.novell.application.console.snapin.scope.*;

/**
 * Displays in the status bar the Chat status messages
 * received through the ChatStatusListener interface.
 */
public class ChatStatusBarSnapin implements StatusBarSnapin, ChatStatusListener
{
    /**
     * The label on which the status will be displayed.  This label is then 
     * sent to the shell to be displayed.
     */
    private JLabel statusText = new JLabel();
    
    /**
     * A reference to the ConsoleOne shell.
     */
    private Shell shell;

   
   /**
    * Implementation of the Snapin Interface.
    *
    * This method is called by the shell to allow each snap-in to perform 
    * any necessary initialization; for example adding itself as an event 
    * listener. The snap-in is initialized by passing a reference to the 
    * InitSnapinInfo class. The getSnapinName() and getSnapinDescription() 
    * methods will be called before initSnapin().
    *
    * @param info Contains data the snap-in may use for initialization, 
    *             such as references to the shell and the snap-in type, and 
    *             may contain a reference to snap-in context data. 
    * @return     If the snap-in is able to successfully complete initialization, 
    *             true is returned, or if initialization fails, false is returned 
    *             and the snap-in will be disabled. 
    */
        public boolean initSnapin(InitSnapinInfo snapinInfo)
    {
        shell = snapinInfo.getShell();
        
        //Set the size and border of the label
        statusText.setSize(200, 12);  
        statusText.setBorder(new BevelBorder(BevelBorder.LOWERED));
        statusText.setText(Chat.chatRes.getString("Status-Init"));
        
        //Adds this class to the list of ChatStatusListeners
        Chat.getInstance().addChatListener(this);
                         
        return true;
   }
   
    
   /**
    * Implementation of the Snapin Interface.
    *
    * @return The snapin's name.
    */
   public String getSnapinName()
   {
      return Chat.chatRes.getString("ChatStatusBarSnapin_Name");
   }

   /**
    * Implementation of the Snapin Interface.
    *
    * @return The snapin's description.
    */
   public String getSnapinDescription()
   {
      return Chat.chatRes.getString("ChatStatusBarSnapin_Description");
   }
   
   
   /**
    * Implementation of the Snapin Interface.
    *
    * Called by the shell when the snap-in is being shut down. 
    * Called by the shell for each snap-in when it is no longer required. 
    * This allows the snap-in to perform any necessary cleanup; for example
    * removing itself as an event listener. 
    */
   public void shutdownSnapin()
   {
      Chat.getInstance().removeChatListener(this);
   }

   /**
    * Implementation of the StatusBarSnapin Interface.
    *
    * @return The component to place in the status bar.
   **/
   public Component getStatusBarItem()
   {            
        return statusText;
   }       
    
    /**
     * Implementation of the ChatStatusListener Interface.
     *
     * Provides messages regarding the status of the Connections.
     *
     * @param status The status message.
     */
    public void chatStatus(String status)
    {
        statusText.setText(status + " ");   
        
        //Prevents messages from getting skipped.
        //statusText.paintImmediately(new Rectangle(statusText.getSize()));
    }
    
    //Unused methods of the ChatStatusListener Interface.
    public void disconnected(String key){}
}