<commit_before>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.gui;

import java.util.*;
import java.util.List;

import java.awt.*;
import javax.swing.*;

import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.main.account.*;
import net.java.sip.communicator.impl.gui.main.configforms.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.gui.event.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;

/**
 * An implementation of the <tt>UIService</tt> that gives access to 
 * other bundles to this particular swing ui implementation.
 * 
 * @author <NAME>
 */
public class UIServiceImpl implements UIService {

    private static final Logger logger
        = Logger.getLogger(UIServiceImpl.class);

    private PopupDialogImpl popupDialog;
    
    private AccountRegWizardContainerImpl wizardContainer;
    
    private Map registeredPlugins = new Hashtable();

    private Vector containerPluginListeners = new Vector();

    private static final List supportedContainers = new ArrayList();
    static {
        supportedContainers.add(UIService.CONTAINER_MAIN_TOOL_BAR);
        supportedContainers.add(UIService.CONTAINER_CONTACT_RIGHT_BUTTON_MENU);
        supportedContainers.add(UIService.CONTAINER_GROUP_RIGHT_BUTTON_MENU);
    }
    
    private static final Hashtable exportedWindows = new Hashtable();
        
    private MainFrame mainFrame;
    
    private ContactListPanel contactList;
    
    private ConfigurationFrame configurationFrame;

    /**
     * Creates an instance of <tt>UIServiceImpl</tt>.
     * @param mainFrame The main application window.
     */
    public UIServiceImpl(MainFrame mainFrame) {
        this.mainFrame = mainFrame;
        this.contactList = mainFrame.getContactListPanel();
        
        this.popupDialog = new PopupDialogImpl(mainFrame);
        
        this.wizardContainer = new AccountRegWizardContainerImpl(mainFrame);
        
        this.configurationFrame = new ConfigurationFrame(mainFrame);
    }
    
    /**
     * Implements addComponent in UIService interface. Stores a plugin component
     * and fires a PluginComponentEvent to inform all interested listeners
     * that a plugin component has been added.
     * 
     * @param containerID The <tt>ContainerID</tt> of the plugable container.
     * @param component The component to add.
     * 
     * @see UIService#addComponent(ContainerID, Object)
     */
    public void addComponent(ContainerID containerID, Object component)
            throws ClassCastException, IllegalArgumentException {

        if (!supportedContainers.contains(containerID)) {
            throw new IllegalArgumentException(
                    "The constraint that you specified is not"
                            + " supported by this UIService implementation.");
        }
        else if (!(component instanceof Component)) {
            throw new ClassCastException(
                "The specified plugin is not a valid swing or awt component.");
        } else {
            if (registeredPlugins.containsKey(containerID)) {
                ((Vector) registeredPlugins.get(containerID)).add(component);
            } else {
                Vector plugins = new Vector();
                plugins.add(component);
                registeredPlugins.put(containerID, plugins);
            }
            this.firePluginEvent(component, containerID,
                    PluginComponentEvent.PLUGIN_COMPONENT_ADDED);
        }
    }

    /**
     * Implements <code>UIService.addComponent(ContainerID, String, Object)
     * </code>. For now this method only invokes addComponent(containerID,
     * component).
     * @see UIService#addComponent(ContainerID, String, Object)
     */
    public void addComponent(ContainerID containerID, String constraint,
            Object component) throws ClassCastException,
            IllegalArgumentException {
        this.addComponent(containerID, component);
    }

    /**
     * 
     */
    public void addComponent(ContainerID containerID,
        ContactAwareComponent component)
        throws ClassCastException, IllegalArgumentException
    {
        this.addComponent(containerID, component);        
    }

    /**
     * 
     */
    public void addComponent(ContainerID containerID,
        String constraint,
        ContactAwareComponent component)
        throws ClassCastException, IllegalArgumentException
    {
        this.addComponent(containerID, constraint, component);
    }
    
    /**
     * Implements <code>UISercie.getSupportedContainers</code>. Returns the
     * list of supported containers by this implementation .
     * 
     * @see UIService#getSupportedContainers()
     */
    public Iterator getSupportedContainers() {
        return Collections.unmodifiableList(supportedContainers).iterator();
    }

    /**
     * Implements getComponentsForConstraint in UIService interface.
     * @see UIService#getComponentsForContainer(ContainerID)
     */
    public Iterator getComponentsForContainer(ContainerID containerID)<commit_msg>fix add plugin component implementation<commit_after>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.gui;

import java.awt.Component;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.swing.JFrame;

import net.java.sip.communicator.impl.gui.main.MainFrame;
import net.java.sip.communicator.impl.gui.main.account.AccountRegWizardContainerImpl;
import net.java.sip.communicator.impl.gui.main.configforms.ConfigurationFrame;
import net.java.sip.communicator.impl.gui.main.contactlist.ContactListPanel;
import net.java.sip.communicator.service.contactlist.MetaContact;
import net.java.sip.communicator.service.gui.AccountRegistrationWizardContainer;
import net.java.sip.communicator.service.gui.ApplicationWindow;
import net.java.sip.communicator.service.gui.ConfigurationManager;
import net.java.sip.communicator.service.gui.ContactAwareComponent;
import net.java.sip.communicator.service.gui.ContainerID;
import net.java.sip.communicator.service.gui.PopupDialog;
import net.java.sip.communicator.service.gui.UIService;
import net.java.sip.communicator.service.gui.WindowID;
import net.java.sip.communicator.service.gui.event.PluginComponentEvent;
import net.java.sip.communicator.service.gui.event.PluginComponentListener;
import net.java.sip.communicator.service.protocol.Contact;
import net.java.sip.communicator.util.Logger;

/**
 * An implementation of the <tt>UIService</tt> that gives access to 
 * other bundles to this particular swing ui implementation.
 * 
 * @author <NAME>
 */
public class UIServiceImpl implements UIService {

    private static final Logger logger
        = Logger.getLogger(UIServiceImpl.class);

    private PopupDialogImpl popupDialog;
    
    private AccountRegWizardContainerImpl wizardContainer;
    
    private Map registeredPlugins = new Hashtable();

    private Vector containerPluginListeners = new Vector();

    private static final List supportedContainers = new ArrayList();
    static {
        supportedContainers.add(UIService.CONTAINER_MAIN_TOOL_BAR);
        supportedContainers.add(UIService.CONTAINER_CONTACT_RIGHT_BUTTON_MENU);
        supportedContainers.add(UIService.CONTAINER_GROUP_RIGHT_BUTTON_MENU);
    }
    
    private static final Hashtable exportedWindows = new Hashtable();
        
    private MainFrame mainFrame;
    
    private ContactListPanel contactList;
    
    private ConfigurationFrame configurationFrame;

    /**
     * Creates an instance of <tt>UIServiceImpl</tt>.
     * @param mainFrame The main application window.
     */
    public UIServiceImpl(MainFrame mainFrame) {
        this.mainFrame = mainFrame;
        this.contactList = mainFrame.getContactListPanel();
        
        this.popupDialog = new PopupDialogImpl(mainFrame);
        
        this.wizardContainer = new AccountRegWizardContainerImpl(mainFrame);
        
        this.configurationFrame = new ConfigurationFrame(mainFrame);
    }
    
    /**
     * Implements addComponent in UIService interface. Stores a plugin component
     * and fires a PluginComponentEvent to inform all interested listeners
     * that a plugin component has been added.
     * 
     * @param containerID The <tt>ContainerID</tt> of the plugable container.
     * @param component The component to add.
     * 
     * @see UIService#addComponent(ContainerID, Object)
     */
    public void addComponent(ContainerID containerID, Object component)
            throws ClassCastException, IllegalArgumentException {
        
        if (!supportedContainers.contains(containerID)) {
            
            throw new IllegalArgumentException(
                    "The constraint that you specified is not"
                            + " supported by this UIService implementation.");
        }
        else if (!(component instanceof Component)) {
            
            throw new ClassCastException(
                "The specified plugin is not a valid swing or awt component.");
        } else {
            
            if (registeredPlugins.containsKey(containerID)) {
            
                ((Vector) registeredPlugins.get(containerID)).add(component);
            } else {
            
                Vector plugins = new Vector();
                plugins.add(component);
                registeredPlugins.put(containerID, plugins);
            }
            this.firePluginEvent(component, containerID,
                    PluginComponentEvent.PLUGIN_COMPONENT_ADDED);
        }
        
    }

    /**
     * Implements <code>UIService.addComponent(ContainerID, String, Object)
     * </code>. For now this method only invokes addComponent(containerID,
     * component).
     * @see UIService#addComponent(ContainerID, String, Object)
     */
    public void addComponent(ContainerID containerID, String constraint,
            Object component) throws ClassCastException,
            IllegalArgumentException {
        this.addComponent(containerID, component);
    }

    /**
     * 
     */
    public void addComponent(ContainerID containerID,
        ContactAwareComponent component)
        throws ClassCastException, IllegalArgumentException
    {    
        if (!(component instanceof Component)) {
            
            throw new ClassCastException(
                "The specified plugin is not a valid swing or awt component.");
        }
        
        this.addComponent(containerID, (Component)component);        
    }

    /**
     * 
     */
    public void addComponent(ContainerID containerID,
        String constraint,
        ContactAwareComponent component)
        throws ClassCastException, IllegalArgumentException
    {
        this.addComponent(containerID, constraint, component);
    }
    
    /**
     * Implements <code>UISercie.getSupportedContainers</code>. Returns the
     * list of supported containers by this implementation .
     * 
     * @see UIService#getSupportedContainers()
     */
    public Iterator getSupportedContainers() {
        return Collections.unmodifiableList(supportedContainers).iterator();
    }

    /**
     * Implements getComponentsForConstraint in UIService interface.
     * @see UIService#getComponentsForContainer(ContainerID)
     */
    public Iterator getComponentsForContainer(ContainerID containerID)
{'fraction_non_alphanumeric': 0.0825970995165861, 'fraction_numerical': 0.0, 'mean_word_length': 2.9148450244698205, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '825100', 'n_tokens_mistral': 3161, 'n_tokens_neox': 3059, 'n_words': 721}