<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;

import java.awt.Component;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Map;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenuItem;

import net.java.sip.communicator.impl.gui.main.customcontrols.AntialiasedPopupMenu;
import net.java.sip.communicator.impl.gui.main.customcontrols.SIPCommButton;
import net.java.sip.communicator.impl.gui.main.utils.ImageLoader;
import net.java.sip.communicator.service.protocol.OperationFailedException;
import net.java.sip.communicator.service.protocol.OperationSetPresence;
import net.java.sip.communicator.service.protocol.PresenceStatus;
import net.java.sip.communicator.service.protocol.icqconstants.IcqStatusEnum;

public class StatusSelectorBox extends JLabel
    implements ActionListener{

    private AntialiasedPopupMenu popup;

    private Map itemsMap;
    
    private OperationSetPresence presence;
    
    public StatusSelectorBox() {
        /*
        super(  ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX),
                ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX),
                null);
        */
        super(new ImageIcon(ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX)));
        
        this.popup = new AntialiasedPopupMenu();
        
        this.popup.setInvoker(this);
        
        //this.addActionListener(this);
    }
    
    public StatusSelectorBox(Map itemsMap, Image selectedItem) {
        /*
        super(  ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX),
                ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX),
                selectedItem);
        */
        super(new ImageIcon(ImageLoader.getImage(
                    ImageLoader.STATUS_SELECTOR_BOX)));
        
        this.itemsMap = itemsMap;
        
        this.popup = new AntialiasedPopupMenu();
        
        this.popup.setInvoker(this);
        
        //this.addActionListener(this);
        
        this.init();
    }

    public void init() {

        Iterator iter = itemsMap.entrySet().iterator();
        
        while (iter.hasNext()) {

            Map.Entry entry = (Map.Entry)iter.next();
        
            JMenuItem item 
                = new JMenuItem
                    (((IcqStatusEnum)entry.getKey()).getStatusName(), 
                     new ImageIcon((Image)entry.getValue()));
            
            item.addActionListener(this);
            
            this.popup.add(item);
        
        }       
    }

    public void addItem(String text, Icon icon){
        
        JMenuItem item = new JMenuItem( text, icon);

        item.addActionListener(this);

        this.popup.add(item);
    }
    
    public void actionPerformed (ActionEvent e) {
        
        if (e.getSource() instanceof SIPCommButton){
    
            if (!this.popup.isVisible()) {
                this.popup.setLocation(this.calculatePopupLocation());
                this.popup.setVisible(true);            
            }       
        }
        else if (e.getSource() instanceof JMenuItem){
            
            JMenuItem menuItem = (JMenuItem) e.getSource();            
                   
            Iterator statusSet = this.presence.getSupportedStatusSet();
            
            while (statusSet.hasNext()){
                
                PresenceStatus status 
                    = ((PresenceStatus)statusSet.next());
                
                if(status.getStatusName().equals(menuItem.getText())
                        && !this.presence.getPresenceStatus().equals(status)){
                    
                    try {
                        if(!status.equals(IcqStatusEnum.OFFLINE))
                            this.presence.publishPresenceStatus(status, "");
                    
                    } catch (IllegalArgumentException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (IllegalStateException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (OperationFailedException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    
                    break;
                }
                
            }
            
            this.setIconImage(((ImageIcon)menuItem.getIcon()).getImage());
        }
    }
    
    public void setIconImage(Image image){
        
        this.setIcon(new ImageIcon (image));
    }
    
    public Point calculatePopupLocation(){
        
        Component component = this;
        Point point = new Point();
        int x = this.getX();
        int y = this.getY();
        
        while(component.getParent() != null){
            
            component = component.getParent();
            
            x += component.getX();
            y += component.getY();
        }
        
        point.x = x;
        point.y = y + this.getHeight();<commit_msg>*** empty log message ***<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;

import java.awt.Component;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Map;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenuItem;

import net.java.sip.communicator.impl.gui.main.customcontrols.AntialiasedPopupMenu;
import net.java.sip.communicator.impl.gui.main.customcontrols.SIPCommButton;
import net.java.sip.communicator.impl.gui.main.utils.ImageLoader;
import net.java.sip.communicator.service.protocol.OperationFailedException;
import net.java.sip.communicator.service.protocol.OperationSetPresence;
import net.java.sip.communicator.service.protocol.PresenceStatus;
import net.java.sip.communicator.service.protocol.icqconstants.IcqStatusEnum;

public class StatusSelectorBox extends SIPCommButton
    implements ActionListener{

    private AntialiasedPopupMenu popup;

    private Map itemsMap;
    
    private OperationSetPresence presence;
    
    public StatusSelectorBox() {
        
        super(  ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX),
                ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX),
                null);
        
        this.popup = new AntialiasedPopupMenu();
        
        this.popup.setInvoker(this);
        
        //this.addActionListener(this);
    }
    
    public StatusSelectorBox(Map itemsMap, Image selectedItem) {
       
        super(  ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX),
                ImageLoader.getImage(ImageLoader.STATUS_SELECTOR_BOX),
                selectedItem);
        
        this.itemsMap = itemsMap;
        
        this.popup = new AntialiasedPopupMenu();
        
        this.popup.setInvoker(this);
        
        this.addActionListener(this);
        
        this.init();
    }

    public void init() {

        Iterator iter = itemsMap.entrySet().iterator();
        
        while (iter.hasNext()) {

            Map.Entry entry = (Map.Entry)iter.next();
        
            JMenuItem item 
                = new JMenuItem
                    (((IcqStatusEnum)entry.getKey()).getStatusName(), 
                     new ImageIcon((Image)entry.getValue()));
            
            item.addActionListener(this);
            
            this.popup.add(item);
        
        }       
    }

    public void addItem(String text, Icon icon){
        
        JMenuItem item = new JMenuItem( text, icon);

        item.addActionListener(this);

        this.popup.add(item);
    }
    
    public void actionPerformed (ActionEvent e) {
        
        if (e.getSource() instanceof SIPCommButton){
    
            if (!this.popup.isVisible()) {
                this.popup.setLocation(this.calculatePopupLocation());
                this.popup.setVisible(true);            
            }       
        }
        else if (e.getSource() instanceof JMenuItem){
            
            JMenuItem menuItem = (JMenuItem) e.getSource();            
                   
            Iterator statusSet = this.presence.getSupportedStatusSet();
            
            while (statusSet.hasNext()){
                
                PresenceStatus status 
                    = ((PresenceStatus)statusSet.next());
                
                if(status.getStatusName().equals(menuItem.getText())
                        && !this.presence.getPresenceStatus().equals(status)){
                    
                    try {
                        if(!status.equals(IcqStatusEnum.OFFLINE))
                            this.presence.publishPresenceStatus(status, "");
                    
                    } catch (IllegalArgumentException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (IllegalStateException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (OperationFailedException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    
                    break;
                }
                
            }
            
            this.setIconImage(((ImageIcon)menuItem.getIcon()).getImage());
        }
    }
   
   
    public Point calculatePopupLocation(){
        
        Component component = this;
        Point point = new Point();
        int x = this.getX();
        int y = this.getY();
        
        while(component.getParent() != null){
            
            component = component.getParent();
            
            x += component.getX();
            y += component.getY();
        }
        
        point.x = x;
        point.y = y + this.getHeight();
{'fraction_non_alphanumeric': 0.09531042339092463, 'fraction_numerical': 0.001139168407062844, 'mean_word_length': 1.6344086021505377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7487839', 'n_tokens_mistral': 2762, 'n_tokens_neox': 2676, 'n_words': 469}