<commit_before>/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Lesser Public License (LGPL),
 * a copy of which is included in this distribution.
 */

package org.jivesoftware.spark.ui;

import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.component.WrappedLabel;
import org.jivesoftware.spark.component.borders.PartialLineBorder;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.log.Log;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Represents the UI for the "ToolTip" functionallity in the ContactList.
 *
 * @author <NAME>
 */
public class ContactInfo extends JPanel {
    private final WrappedLabel nicknameLabel = new WrappedLabel();
    private final WrappedLabel statusLabel = new WrappedLabel();
    private final JLabel fullJIDLabel = new JLabel();
    private final JLabel imageLabel = new JLabel();


    public ContactInfo() {
        setLayout(new GridBagLayout());
        setBackground(Color.white);


        add(nicknameLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
        add(statusLabel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 5, 5), 0, 0));
        add(fullJIDLabel, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
        add(imageLabel, new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));


        nicknameLabel.setFont(new Font("Dialog", Font.BOLD, 12));
        statusLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
        statusLabel.setForeground(Color.gray);
        fullJIDLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
        fullJIDLabel.setForeground(Color.gray);


        nicknameLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray));
        fullJIDLabel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.gray));

        setBorder(BorderFactory.createEtchedBorder());
    }

    public void setContactItem(ContactItem contactItem) {
        nicknameLabel.setText(contactItem.getNickname());
        statusLabel.setText(contactItem.getStatus());
        fullJIDLabel.setText(contactItem.getFullJID());

        imageLabel.setBorder(null);

        try {
            URL avatarURL = contactItem.getAvatarURL();
            ImageIcon icon = null;
            if (avatarURL != null) {
                icon = new ImageIcon(avatarURL);
            }

            if (icon != null && icon.getIconHeight() > 1) {
                icon = GraphicUtils.scaleImageIcon(icon, 96, 96);
                imageLabel.setIcon(icon);

                imageLabel.setBorder(new PartialLineBorder(Color.gray, 1));
            }
            else {
                icon = new ImageIcon(SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage().getScaledInstance(1, 64, Image.SCALE_SMOOTH));
                imageLabel.setIcon(icon);


            }
        }
        catch (MalformedURLException e) {
            Log.error(e);
        }
    }


    public Dimension getPreferredSize() {
        final Dimension size = super.getPreferredSize();<commit_msg>Migrating from 2.0 branch.<commit_after>/**
 * $Revision: $
 * $Date: $
 *
 * Copyright (C) 2006 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Lesser Public License (LGPL),
 * a copy of which is included in this distribution.
 */

package org.jivesoftware.spark.ui;

import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.spark.component.WrappedLabel;
import org.jivesoftware.spark.component.borders.PartialLineBorder;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportUtils;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Represents the UI for the "ToolTip" functionallity in the ContactList.
 *
 * @author <NAME>
 */
public class ContactInfo extends JPanel {
    private final WrappedLabel nicknameLabel = new WrappedLabel();
    private final WrappedLabel statusLabel = new WrappedLabel();
    private final JLabel fullJIDLabel = new JLabel();
    private final JLabel imageLabel = new JLabel();


    public ContactInfo() {
        setLayout(new GridBagLayout());
        setBackground(Color.white);


        add(nicknameLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
        add(statusLabel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 5, 5), 0, 0));
        add(fullJIDLabel, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
        add(imageLabel, new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));


        nicknameLabel.setFont(new Font("Dialog", Font.BOLD, 12));
        statusLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
        statusLabel.setForeground(Color.gray);
        fullJIDLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
        fullJIDLabel.setForeground(Color.gray);


        nicknameLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray));
        fullJIDLabel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.gray));

        setBorder(BorderFactory.createEtchedBorder());
    }

    public void setContactItem(ContactItem contactItem) {
        nicknameLabel.setText(contactItem.getNickname());
        statusLabel.setText(contactItem.getStatus());

        Transport transport = TransportUtils.getTransport(StringUtils.parseServer(contactItem.getFullJID()));
        if (transport != null) {
            fullJIDLabel.setIcon(transport.getIcon());
            String name = StringUtils.parseName(contactItem.getFullJID());
            fullJIDLabel.setText(transport.getName() + " - " + name);
        }
        else {
            fullJIDLabel.setText(contactItem.getFullJID());
            fullJIDLabel.setIcon(null);
        }

        imageLabel.setBorder(null);

        try {
            URL avatarURL = contactItem.getAvatarURL();
            ImageIcon icon = null;
            if (avatarURL != null) {
                icon = new ImageIcon(avatarURL);
            }

            if (icon != null && icon.getIconHeight() > 1) {
                icon = GraphicUtils.scaleImageIcon(icon, 96, 96);
                imageLabel.setIcon(icon);

                imageLabel.setBorder(new PartialLineBorder(Color.gray, 1));
            }
            else {
                icon = new ImageIcon(SparkRes.getImageIcon(SparkRes.BLANK_24x24).getImage().getScaledInstance(1, 64, Image.SCALE_SMOOTH));
                imageLabel.setIcon(icon);


            }
        }
        catch (MalformedURLException e) {
            Log.error(e);
        }
    }


    public Dimension getPreferredSize() {
        final Dimension size = super.getPreferredSize();
{'fraction_non_alphanumeric': 0.11583632092965757, 'fraction_numerical': 0.021757942885399926, 'mean_word_length': 3.222338204592902, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4147994', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2455, 'n_words': 548}