Package cz.cuni.mff.inetpaint.dialog

Source Code of cz.cuni.mff.inetpaint.dialog.VCardDialog

package cz.cuni.mff.inetpaint.dialog;

import cz.cuni.mff.inetpaint.*;
import cz.cuni.mff.inetpaint.swing.AvatarPanel;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.packet.VCard;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ResourceBundle;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.filechooser.*;

/**
* Zobrazuje dialog s vizitkou Jabber uživatele. Jde-li o aktuálně přihlášeného
* uživatele, lze v tomto dialogu měnit údaje ve vizitce.
* @author Jindřich Helcl
*/
public class VCardDialog extends JDialog{
    private final Dimension MIN_SIZE = new Dimension(400, 500);
    private final int AVATAR_WIDTH = 150;
    private final int AVATAR_HEIGHT = 150;
    private final int MAX_FILE_SIZE = 16384;

    private String JID;
    private boolean myself;
    private VCard vCard;
    private byte[] currentAvatarBytes;

    private final ResourceBundle rb = Program.getStringsBundle();

    private final AvatarPanel avatar = new AvatarPanel();

    private final JLabel labJID = new JLabel();
    private final JLabel labFirstName = new JLabel(rb.getString("vCardFirstName"));
    private final JLabel labLastName = new JLabel(rb.getString("vCardLastName"));
    private final JLabel labMiddleName = new JLabel(rb.getString("vCardMiddleName"));
    private final JLabel labNickName = new JLabel(rb.getString("vCardNickName"));
    private final JLabel labURL = new JLabel(rb.getString("vCardURL"));
    private final JLabel labAvatar = new JLabel(rb.getString("vCardAvatar"));
    private final JLabel labTitle = new JLabel(rb.getString("vCardTitle"));
    private final JLabel labDesc = new JLabel(rb.getString("vCardDesc"));
    private final JLabel labBDay = new JLabel(rb.getString("vCardBDay"));

    private final JLabel labHomeEMail = new JLabel(rb.getString("vCardHomeEMail"));
    private final JLabel labHomePhone = new JLabel(rb.getString("vCardHomePhone"));
    private final JLabel labHomeStreet = new JLabel(rb.getString("vCardHomeStreet"));
    private final JLabel labHomeCity = new JLabel(rb.getString("vCardHomeCity"));
    private final JLabel labHomeState = new JLabel(rb.getString("vCardHomeState"));
    private final JLabel labHomeCountry = new JLabel(rb.getString("vCardHomeCountry"));
    private final JLabel labHomeZipCode = new JLabel(rb.getString("vCardHomeZipCode"));

    private final JLabel labWorkOrganization = new JLabel(rb.getString("vCardWorkOrganization"));
    private final JLabel labWorkOrganizationUnit = new JLabel(rb.getString("vCardWorkOrganizationUnit"));
    private final JLabel labWorkEMail = new JLabel(rb.getString("vCardWorkEMail"));
    private final JLabel labWorkPhone = new JLabel(rb.getString("vCardWorkPhone"));
    private final JLabel labWorkStreet = new JLabel(rb.getString("vCardWorkStreet"));
    private final JLabel labWorkCity = new JLabel(rb.getString("vCardWorkCity"));
    private final JLabel labWorkState = new JLabel(rb.getString("vCardWorkState"));
    private final JLabel labWorkCountry = new JLabel(rb.getString("vCardWorkCountry"));
    private final JLabel labWorkZipCode = new JLabel(rb.getString("vCardWorkZipCode"));

    private final JTextField textFirstName = new JTextField() ;
    private final JTextField textLastName = new JTextField();
    private final JTextField textMiddleName = new JTextField();
    private final JTextField textNickName = new JTextField();
    private final JTextField textURL = new JTextField();
    private final JTextField textTitle = new JTextField();
    private final JTextArea textDesc = new JTextArea();
    private final JTextField textBDay = new JTextField();

    private final JTextField textHomeEMail = new JTextField();
    private final JTextField textHomePhone = new JTextField();
    private final JTextField textHomeStreet = new JTextField();
    private final JTextField textHomeCity = new JTextField();
    private final JTextField textHomeState = new JTextField();
    private final JTextField textHomeCountry = new JTextField();
    private final JTextField textHomeZipCode = new JTextField();

    private final JTextField textWorkOrganization = new JTextField();
    private final JTextField textWorkOrganizationUnit = new JTextField();
    private final JTextField textWorkEMail = new JTextField();
    private final JTextField textWorkPhone = new JTextField();
    private final JTextField textWorkStreet = new JTextField();
    private final JTextField textWorkCity = new JTextField();
    private final JTextField textWorkState = new JTextField();
    private final JTextField textWorkCountry = new JTextField();
    private final JTextField textWorkZipCode = new JTextField();

    private final JButton closeButton = new JButton();
    private final JButton saveButton = new JButton(rb.getString("vCardSave"));
    private final JButton setAvatarButton = new JButton(rb.getString("vCardSetAvatar"));
    private final JButton clearAvatarButton = new JButton(rb.getString("vCardClearAvatar"));

    private final JTabbedPane tabs = new JTabbedPane();
    private final JPanel generalTab = new JPanel();
    private final JPanel homeTab = new JPanel();
    private final JPanel workTab = new JPanel();
    private final JPanel descTab = new JPanel();

    private final JPanel footer = new JPanel();

    private void initComponents() {
        setMinimumSize(MIN_SIZE);
        setResizable(false);

        ConnectionManager man = ConnectionManager.getInstance();
        String name = myself ? man.getLocalName() : man.getNameFor(JID);

        setTitle(rb.getString("vCardWindowTitle") + " - " + name);
        setIconImage(Program.getImage("vcard_icon.gif"));


        closeButton.setText(myself ? rb.getString("cancelButton") : rb.getString("closeButton"));
        closeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                processWindowEvent(new WindowEvent(VCardDialog.this, WindowEvent.WINDOW_CLOSING));
            }
        });

        saveButton.setEnabled(myself);
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveVCard();
            }
        });

        clearAvatarButton.setEnabled(myself);
        clearAvatarButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setAvatarImage(null);
            }
        });

        setAvatarButton.setEnabled(myself);
        setAvatarButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                FileNameExtensionFilter pngFilter =
                        new FileNameExtensionFilter(rb.getString("fileChooserPNGFilter"), "png");

                FileNameExtensionFilter jpegFilter =
                        new FileNameExtensionFilter(rb.getString("fileChooserJPEGFilter"), "jpg", "jpeg", "jfif");

                FileNameExtensionFilter gifFilter =
                        new FileNameExtensionFilter(rb.getString("fileChooserGIFFilter"), "gif");

                FileNameExtensionFilter imageFilter =
                        new FileNameExtensionFilter(rb.getString("fileChooserImageFilter"), "png", "jpg", "jpeg", "jfif", "gif");

                JFileChooser f = new JFileChooser();
                f.setFileFilter(imageFilter);
                f.addChoosableFileFilter(pngFilter);
                f.addChoosableFileFilter(jpegFilter);
                f.addChoosableFileFilter(gifFilter);
                f.setAcceptAllFileFilterUsed(false);
                f.setMultiSelectionEnabled(false);

                if (f.showOpenDialog(rootPane) == JFileChooser.APPROVE_OPTION) {
                    java.io.File file = f.getSelectedFile();

                    if(file != null)
                        setAvatarImage(file);
                }
            }
        });

        textDesc.setEditable(myself);
        textDesc.setBorder(new LineBorder(Color.DARK_GRAY, 1));
        textDesc.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));


        textFirstName.setEditable(myself);
        textLastName.setEditable(myself);
        textMiddleName.setEditable(myself);
        textNickName.setEditable(myself);
        textURL.setEditable(myself);
        textTitle.setEditable(myself);
        textBDay.setEditable(myself);

        textHomeEMail.setEditable(myself);
        textHomePhone.setEditable(myself);
        textHomeStreet.setEditable(myself);
        textHomeCity.setEditable(myself);
        textHomeState.setEditable(myself);
        textHomeCountry.setEditable(myself);
        textHomeZipCode.setEditable(myself);

        textWorkOrganization.setEditable(myself);
        textWorkOrganizationUnit.setEditable(myself);
        textWorkEMail.setEditable(myself);
        textWorkPhone.setEditable(myself);
        textWorkStreet.setEditable(myself);
        textWorkCity.setEditable(myself);
        textWorkState.setEditable(myself);
        textWorkCountry.setEditable(myself);
        textWorkZipCode.setEditable(myself);


        GroupLayout fl = new GroupLayout(footer);
        footer.setLayout(fl);
        fl.setAutoCreateGaps(true);
        fl.setAutoCreateContainerGaps(true);

        fl.setHorizontalGroup(fl.createSequentialGroup()
                .addGap(0,0,Short.MAX_VALUE)
                .addComponent(saveButton)
                .addComponent(closeButton)
            );
        fl.setVerticalGroup(fl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(saveButton)
                .addComponent(closeButton)
            );

        JSeparator sep2 = new JSeparator();
        labJID.setText(rb.getString("vCardJID") + "  " + JID);

        GroupLayout gl = new GroupLayout(generalTab);
        generalTab.setLayout(gl);
        gl.setAutoCreateContainerGaps(true);
        gl.setAutoCreateGaps(true);

        gl.setHorizontalGroup(gl.createParallelGroup()
            .addGroup(gl.createSequentialGroup()
                .addGap(12)
                .addComponent(labJID)
            )
            .addComponent(sep2)
            .addGroup(gl.createSequentialGroup()
                .addGroup(gl.createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addComponent(labFirstName)
                    .addComponent(labMiddleName)
                    .addComponent(labLastName)
                    .addComponent(labTitle)
                    .addComponent(labNickName)
                    .addComponent(labURL)
                    .addComponent(labBDay)
                    .addComponent(labAvatar)
                    // buttonky na zmenu avatara
                )

                .addGroup(gl.createParallelGroup()
                    .addComponent(textFirstName)
                    .addComponent(textMiddleName)
                    .addComponent(textLastName)
                    .addComponent(textTitle)
                    .addComponent(textNickName)
                    .addComponent(textURL)
                    .addComponent(textBDay)
                    .addGroup(gl.createSequentialGroup()
                        .addComponent(avatar, AVATAR_WIDTH, AVATAR_WIDTH, AVATAR_WIDTH)
                        .addGap(0,0,Short.MAX_VALUE)
                        .addGroup(gl.createParallelGroup()
                            .addComponent(setAvatarButton)
                            .addComponent(clearAvatarButton)
                        )
                    )
                )
            )
        );

        gl.setVerticalGroup(gl.createSequentialGroup()
            .addComponent(labJID)
            .addComponent(sep2, 5,5,5)
            .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labFirstName)
                .addComponent(textFirstName)
            )
            .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labMiddleName)
                .addComponent(textMiddleName)
            )
            .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labLastName)
                .addComponent(textLastName)
            )
            .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labTitle)
                .addComponent(textTitle)
            )
            .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labNickName)
                .addComponent(textNickName)
            )
            .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labURL)
                .addComponent(textURL)
            )
            .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labBDay)
                .addComponent(textBDay)
            )
            .addGroup(gl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labAvatar)
                .addComponent(avatar, AVATAR_HEIGHT, AVATAR_HEIGHT, AVATAR_HEIGHT)
                .addGroup(GroupLayout.Alignment.TRAILING, gl.createSequentialGroup()
                    .addComponent(setAvatarButton)
                    .addComponent(clearAvatarButton)
                )
            )
        );

        GroupLayout hl = new GroupLayout(homeTab);
        homeTab.setLayout(hl);
        hl.setAutoCreateContainerGaps(true);
        hl.setAutoCreateGaps(true);

        hl.setHorizontalGroup(hl.createSequentialGroup()
            .addGroup(hl.createParallelGroup(GroupLayout.Alignment.TRAILING)
                .addComponent(labHomeEMail)
                .addComponent(labHomePhone)
                .addComponent(labHomeStreet)
                .addComponent(labHomeCity)
                .addComponent(labHomeState)
                .addComponent(labHomeCountry)
                .addComponent(labHomeZipCode)
            )

            .addGroup(hl.createParallelGroup()
                .addComponent(textHomeEMail)
                .addComponent(textHomePhone)
                .addComponent(textHomeStreet)
                .addComponent(textHomeCity)
                .addComponent(textHomeState)
                .addComponent(textHomeCountry)
                .addComponent(textHomeZipCode)
            )
        );
       
        hl.setVerticalGroup(hl.createSequentialGroup()
            .addGroup(hl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labHomeEMail)
                .addComponent(textHomeEMail)
            )
            .addGroup(hl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labHomePhone)
                .addComponent(textHomePhone)
            )
            .addGroup(hl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labHomeStreet)
                .addComponent(textHomeStreet)
            )
            .addGroup(hl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labHomeCity)
                .addComponent(textHomeCity)
            )
            .addGroup(hl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labHomeState)
                .addComponent(textHomeState)
            )
            .addGroup(hl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labHomeCountry)
                .addComponent(textHomeCountry)
            )
            .addGroup(hl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labHomeZipCode)
                .addComponent(textHomeZipCode)
            )
        );

        GroupLayout wl = new GroupLayout(workTab);
        workTab.setLayout(wl);
        wl.setAutoCreateContainerGaps(true);
        wl.setAutoCreateGaps(true);

        JSeparator sep = new JSeparator();

        wl.setHorizontalGroup(wl.createParallelGroup()
            .addGroup(wl.createSequentialGroup()
                .addGroup(wl.createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addComponent(labWorkEMail)
                    .addComponent(labWorkPhone)
                    .addComponent(labWorkStreet)
                    .addComponent(labWorkCity)
                    .addComponent(labWorkState)
                    .addComponent(labWorkCountry)
                    .addComponent(labWorkZipCode)
                )
                .addGroup(wl.createParallelGroup()
                    .addComponent(textWorkEMail)
                    .addComponent(textWorkPhone)
                    .addComponent(textWorkStreet)
                    .addComponent(textWorkCity)
                    .addComponent(textWorkState)
                    .addComponent(textWorkCountry)
                    .addComponent(textWorkZipCode)
                )
            )
            .addComponent(sep)
            .addGroup(wl.createSequentialGroup()
                .addGroup(wl.createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addComponent(labWorkOrganization)
                    .addComponent(labWorkOrganizationUnit)
                )
                .addGroup(wl.createParallelGroup()
                    .addComponent(textWorkOrganization)
                    .addComponent(textWorkOrganizationUnit)
                )
            )
        );

        wl.setVerticalGroup(wl.createSequentialGroup()
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkEMail)
                .addComponent(textWorkEMail)
            )
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkPhone)
                .addComponent(textWorkPhone)
            )
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkStreet)
                .addComponent(textWorkStreet)
            )
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkCity)
                .addComponent(textWorkCity)
            )
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkState)
                .addComponent(textWorkState)
            )
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkCountry)
                .addComponent(textWorkCountry)
            )
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkZipCode)
                .addComponent(textWorkZipCode)
            )
            .addComponent(sep, 10, 10 ,10)
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkOrganization)
                .addComponent(textWorkOrganization)
            )
            .addGroup(wl.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(labWorkOrganizationUnit)
                .addComponent(textWorkOrganizationUnit)
            )
        );

        GroupLayout dl = new GroupLayout(descTab);
        descTab.setLayout(dl);
        dl.setAutoCreateContainerGaps(true);
        dl.setAutoCreateGaps(true);

        dl.setHorizontalGroup(dl.createParallelGroup()
            .addComponent(labDesc)
            .addComponent(textDesc)
        );

        dl.setVerticalGroup(dl.createSequentialGroup()
            .addComponent(labDesc)
            .addComponent(textDesc)
        );


        tabs.add(rb.getString("vCardTabGeneral"), generalTab);
        tabs.add(rb.getString("vCardTabHome"), homeTab);
        tabs.add(rb.getString("vCardTabWork"), workTab);
        tabs.add(rb.getString("vCardTabDesc"), descTab);

        BoxLayout layout = new BoxLayout(getContentPane(), BoxLayout.Y_AXIS);
        setLayout(layout);
       
        getContentPane().add(tabs);
        getContentPane().add(footer);

        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                loadVCard();
            }
        });

    }

    private void setAvatarImage(File file) {
        if(file == null) {
            currentAvatarBytes = null;
            avatar.setNoAvatar();
            return;
        }       
       
        Image image;                   
        try {
            image = ImageIO.read(file);
        } catch (IOException ioe) {
            ioe.printStackTrace(System.err);
            JOptionPane.showMessageDialog(rootPane,
                    rb.getString("fileChooserImageError"),
                    rb.getString("errorTitle"),
                    JOptionPane.ERROR_MESSAGE                               
                    );
            return;
        }                   
       
        if(image == null) {
            avatar.setNoAvatar();
            currentAvatarBytes = null;
        }
        else {
            try {
                // mozna bude potreba zmensovat. pokud je soubor vetsi nez 16kib, tak
                // zmensim delsi stranu fotky na 150 pixelu.. (v zachovanym pomeru stran)

                float widthOrig = image.getWidth(null);
                float heightOrig = image.getHeight(null);

                float longer = Math.max(widthOrig, heightOrig);
                float shorter = Math.min(widthOrig, heightOrig);

                float scaledLonger, scaledShorter;
                int scaledWidth, scaledHeight;

                if(file.length() > MAX_FILE_SIZE) {
                    JOptionPane.showMessageDialog(rootPane,
                            rb.getString("vCardScaleNeeded"),
                            rb.getString("vCardScaleNeededTitle"),
                            JOptionPane.INFORMATION_MESSAGE);

                    float ratio = shorter / longer;
                    scaledLonger = 150;
                    scaledShorter = scaledLonger * ratio;

                }
                else {
                    scaledLonger = image.getWidth(null);
                    scaledShorter = image.getHeight(null);
                }

                scaledWidth  = (int)(widthOrig <  heightOrig ? scaledShorter : scaledLonger);
                scaledHeight = (int)(widthOrig >= heightOrig ? scaledShorter : scaledLonger);

                BufferedImage buffImg = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);

                Graphics g = buffImg.getGraphics();
                g.drawImage(image, 0, 0, scaledWidth, scaledHeight, null);

                ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
                ImageIO.write(buffImg, "PNG", baos);
                baos.flush();
                currentAvatarBytes = baos.toByteArray();
                avatar.setAvatar(image);
                baos.close();
            }
            catch (IOException ioe) {               
                avatar.setNoAvatar();
                currentAvatarBytes = null;
            }
        }
    }

    private void saveVCard() {

        vCard.setFirstName(textFirstName.getText());
        vCard.setLastName(textLastName.getText());
        vCard.setMiddleName(textMiddleName.getText());
        vCard.setNickName(textNickName.getText());
        vCard.setField("URL", textURL.getText());
               
        vCard.setField("TITLE", textTitle.getText());
        vCard.setField("DESC", textDesc.getText());
        vCard.setField("BDAY", textBDay.getText());

        vCard.setEmailHome(textHomeEMail.getText());
        vCard.setPhoneHome("VOICE", textHomePhone.getText());
        vCard.setAddressFieldHome("STREET", textHomeStreet.getText());
        vCard.setAddressFieldHome("LOCALITY",textHomeCity.getText());
        vCard.setAddressFieldHome("REGION",textHomeState.getText());
        vCard.setAddressFieldHome("CTRY",textHomeCountry.getText());
        vCard.setAddressFieldHome("PCODE",textHomeZipCode.getText());

        vCard.setOrganization(textWorkOrganization.getText());
        vCard.setOrganizationUnit(textWorkOrganizationUnit.getText());
        vCard.setEmailWork(textWorkEMail.getText());
        vCard.setPhoneWork("VOICE", textWorkPhone.getText());
        vCard.setAddressFieldWork("STREET", textWorkStreet.getText());
        vCard.setAddressFieldWork("LOCALITY", textWorkCity.getText());
        vCard.setAddressFieldWork("REGION", textWorkState.getText());
        vCard.setAddressFieldWork("CTRY", textWorkCountry.getText());
        vCard.setAddressFieldWork("PCODE", textWorkZipCode.getText());
       
        //avatar:
        if(currentAvatarBytes != null)
            vCard.setAvatar(currentAvatarBytes);

        try {
            ConnectionManager.getInstance().saveVCard(vCard);
        }
        catch(XMPPException xmp) {
            JOptionPane.showMessageDialog(this.getRootPane(),
                    rb.getString("vCardSaveError"),
                    rb.getString("errorTitle"),
                    JOptionPane.ERROR_MESSAGE
                    );
            xmp.printStackTrace(System.err);
            return;
        }
       
        //probehlo to uspesne
        processWindowEvent(new WindowEvent(VCardDialog.this, WindowEvent.WINDOW_CLOSING));
    }


    private void loadVCard() {
        ConnectionManager man = ConnectionManager.getInstance();

        VCard v;

        try {
            v = myself ? man.getVCard() : man.getVCard(JID);
        }
        catch(XMPPException xmp) {
            JOptionPane.showMessageDialog(this.getRootPane(),
                    rb.getString("vCardLoadError"),
                    rb.getString("errorTitle"),
                    JOptionPane.ERROR_MESSAGE
                    );
            xmp.printStackTrace(System.err);
            this.dispose();
            return;
        }


        textFirstName.setText(v.getFirstName());
        textLastName.setText(v.getLastName());
        textMiddleName.setText(v.getMiddleName());
        textNickName.setText(v.getNickName());
        textURL.setText(v.getField("URL"));
               
        currentAvatarBytes = v.getAvatar();
        if(currentAvatarBytes != null) {
            ByteArrayInputStream bais = new ByteArrayInputStream(currentAvatarBytes);
            try {
                final Image image = ImageIO.read(bais);
                avatar.setAvatar(image);
            }
            catch (IOException e) {
                System.err.println("Nelze nacist avatar.");
                e.printStackTrace(System.err);
            }
        } else {
            avatar.setNoAvatar();
        }

        textTitle.setText(v.getField("TITLE"));
        textDesc.setText(v.getField("DESC"));
        textBDay.setText(v.getField("BDAY"));

        textHomeEMail.setText(v.getEmailHome());
        textHomePhone.setText(v.getPhoneHome("VOICE"));
        textHomeStreet.setText(v.getAddressFieldHome("STREET"));
        textHomeCity.setText(v.getAddressFieldHome("LOCALITY"));
        textHomeState.setText(v.getAddressFieldHome("REGION"));
        textHomeCountry.setText(v.getAddressFieldHome("CTRY"));
        textHomeZipCode.setText(v.getAddressFieldHome("PCODE"));

        textWorkOrganization.setText(v.getOrganization());
        textWorkOrganizationUnit.setText(v.getOrganizationUnit());
        textWorkEMail.setText(v.getEmailWork());
        textWorkPhone.setText(v.getPhoneWork("VOICE"));
        textWorkStreet.setText(v.getAddressFieldWork("STREET"));
        textWorkCity.setText(v.getAddressFieldWork("LOCALITY"));
        textWorkState.setText(v.getAddressFieldWork("REGION"));
        textWorkCountry.setText(v.getAddressFieldWork("CTRY"));
        textWorkZipCode.setText(v.getAddressFieldWork("PCODE"));

        vCard = v;
    }

    /**
     * Vytvoří novou instanci dialogu pro daný kontakt.
     * @param owner Rodičovské okno
     * @param JID Jabber ID kontaktu
     */
    public VCardDialog(Frame owner, String JID) {
        super(owner, true);
        this.JID = JID;
        myself = false;
        initComponents();
    }

    /**
     * Vytvoří novou instanci dialogu pro aktuálně přihlášeného uživatele.
     * @param owner Rodičovské okno
     */
    public VCardDialog(Frame owner) {
        super(owner, true);
        this.JID = ConnectionManager.getInstance().getUser();
        myself = true;
        initComponents();
       
    }


}
TOP

Related Classes of cz.cuni.mff.inetpaint.dialog.VCardDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.