<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.main.contactlist.addcontact;

import java.awt.*;
import java.io.*;
import java.util.*;

import javax.imageio.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.impl.gui.utils.Constants;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;

import org.osgi.framework.*;

/**
 * The <tt>SelectAccountPanel</tt> is where the user should select the account,
 * where the new contact will be created.
 * 
 * @author <NAME>
 */
public class SelectAccountPanel
    extends JPanel
    implements ServiceListener
{
    private Logger logger = Logger.getLogger(SelectAccountPanel.class);
    
    private JScrollPane tablePane = new JScrollPane();
    
    private JTable accountsTable = new JTable();
        
    private BooleanToCheckTableModel tableModel
        = new BooleanToCheckTableModel();
    
    private NewContact newContact;
    
    private JPanel labelsPanel = new JPanel(new GridLayout(0, 1));
    
    private JPanel rightPanel = new JPanel(new BorderLayout(5, 5));
    
    private JLabel iconLabel = new JLabel(new ImageIcon(ImageLoader
            .getImage(ImageLoader.ADD_CONTACT_WIZARD_ICON)));
    
    private SIPCommMsgTextArea infoLabel = new SIPCommMsgTextArea(
            Messages.getI18NString("selectProvidersWizard").getText());
    
    private JLabel infoTitleLabel = new JLabel(
            Messages.getI18NString("selectProvidersWizardTitle").getText(), 
                JLabel.CENTER);
    
    /**
     * Creates and initializes the <tt>SelectAccountPanel</tt>.
     * 
     * @param newContact An object that collects all user choices through the
     * wizard.
     * @param protocolProvidersList The list of available 
     * <tt>ProtocolProviderServices</tt>, from which the user could select.
     */
    public SelectAccountPanel(NewContact newContact, 
            Iterator protocolProvidersList)
    {
        super(new BorderLayout());
    
        this.setPreferredSize(new Dimension(500, 200));
        this.newContact = newContact;
    
        this.iconLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 10));
       
        this.infoLabel.setEditable(false);
               
        this.infoTitleLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 18));
                
        this.labelsPanel.add(infoTitleLabel);
        this.labelsPanel.add(infoLabel);
        
        this.rightPanel.add(labelsPanel, BorderLayout.NORTH);
        this.rightPanel.add(tablePane, BorderLayout.CENTER);
        
        this.add(iconLabel, BorderLayout.WEST);
        
        this.add(rightPanel, BorderLayout.CENTER);
        
        this.tableInit(protocolProvidersList);
        
        GuiActivator.bundleContext.addServiceListener(this);
    }  
    
    /**
     * Initializes the accounts table.
     */
    private void tableInit(Iterator protocolProvidersList)
    {   
        accountsTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
        
        tableModel.addColumn("");
        tableModel.addColumn(Messages.getI18NString("account").getText());
        tableModel.addColumn(Messages.getI18NString("protocol").getText());
                
        while(protocolProvidersList.hasNext())
        {
            ProtocolProviderService pps 
                = (ProtocolProviderService)protocolProvidersList.next();
            
            String pName = pps.getProtocolName();
            
            Image protocolImage = null;
            try
            {
                protocolImage = ImageIO.read(
                    new ByteArrayInputStream(pps.getProtocolIcon()
                        .getIcon(ProtocolIcon.ICON_SIZE_16x16)));
            }
            catch (IOException e)
            {
                logger.error("Could not read image.", e);
            }
            
            JLabel protocolLabel = new JLabel();
            protocolLabel.setText(pName);
            protocolLabel.setIcon(new ImageIcon(protocolImage));
            
            tableModel.addRow(new Object[]{new Boolean(false),
                    pps, protocolLabel});
        }
        <commit_msg>Could not add contacts for protocol providers that don't support presence - fixed<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.main.contactlist.addcontact;

import java.awt.*;
import java.io.*;
import java.util.*;

import javax.imageio.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.impl.gui.utils.Constants;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;

import org.osgi.framework.*;

/**
 * The <tt>SelectAccountPanel</tt> is where the user should select the account,
 * where the new contact will be created.
 * 
 * @author <NAME>
 */
public class SelectAccountPanel
    extends JPanel
    implements ServiceListener
{
    private Logger logger = Logger.getLogger(SelectAccountPanel.class);
    
    private JScrollPane tablePane = new JScrollPane();
    
    private JTable accountsTable = new JTable();
        
    private BooleanToCheckTableModel tableModel
        = new BooleanToCheckTableModel();
    
    private NewContact newContact;
    
    private JPanel labelsPanel = new JPanel(new GridLayout(0, 1));
    
    private JPanel rightPanel = new JPanel(new BorderLayout(5, 5));
    
    private JLabel iconLabel = new JLabel(new ImageIcon(ImageLoader
            .getImage(ImageLoader.ADD_CONTACT_WIZARD_ICON)));
    
    private SIPCommMsgTextArea infoLabel = new SIPCommMsgTextArea(
            Messages.getI18NString("selectProvidersWizard").getText());
    
    private JLabel infoTitleLabel = new JLabel(
            Messages.getI18NString("selectProvidersWizardTitle").getText(), 
                JLabel.CENTER);
    
    /**
     * Creates and initializes the <tt>SelectAccountPanel</tt>.
     * 
     * @param newContact An object that collects all user choices through the
     * wizard.
     * @param protocolProvidersList The list of available 
     * <tt>ProtocolProviderServices</tt>, from which the user could select.
     */
    public SelectAccountPanel(NewContact newContact, 
            Iterator protocolProvidersList)
    {
        super(new BorderLayout());
    
        this.setPreferredSize(new Dimension(500, 200));
        this.newContact = newContact;
    
        this.iconLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 10));
       
        this.infoLabel.setEditable(false);
               
        this.infoTitleLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 18));
                
        this.labelsPanel.add(infoTitleLabel);
        this.labelsPanel.add(infoLabel);
        
        this.rightPanel.add(labelsPanel, BorderLayout.NORTH);
        this.rightPanel.add(tablePane, BorderLayout.CENTER);
        
        this.add(iconLabel, BorderLayout.WEST);
        
        this.add(rightPanel, BorderLayout.CENTER);
        
        this.tableInit(protocolProvidersList);
        
        GuiActivator.bundleContext.addServiceListener(this);
    }  
    
    /**
     * Initializes the accounts table.
     */
    private void tableInit(Iterator protocolProvidersList)
    {   
        accountsTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
        
        tableModel.addColumn("");
        tableModel.addColumn(Messages.getI18NString("account").getText());
        tableModel.addColumn(Messages.getI18NString("protocol").getText());
                
        while(protocolProvidersList.hasNext())
        {
            ProtocolProviderService pps 
                = (ProtocolProviderService)protocolProvidersList.next();
            
            OperationSet opSet = pps.getOperationSet(OperationSetPresence.class);
            
            if(opSet == null)
                continue;
            
            String pName = pps.getProtocolName();
            
            Image protocolImage = null;
            try
            {
                protocolImage = ImageIO.read(
                    new ByteArrayInputStream(pps.getProtocolIcon()
                        .getIcon(ProtocolIcon.ICON_SIZE_16x16)));
            }
            catch (IOException e)
            {
                logger.error("Could not read image.", e);
            }
            
            JLabel protocolLabel = new JLabel();
            protocolLabel.setText(pName);
            protocolLabel.setIcon(new ImageIcon(protocolImage));
            
            tableModel.addRow(new Object[]{new Boolean(false),
                    pps, protocolLabel});
        }
        
{'fraction_non_alphanumeric': 0.09657883552911177, 'fraction_numerical': 0.00764980875478113, 'mean_word_length': 2.400650289017341, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3877558', 'n_tokens_mistral': 2638, 'n_tokens_neox': 2521, 'n_words': 509}