⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profileui.java

📁 基于jxta的局域网P2P文件共享,可以实现局域网中的文件p2p共享,实现文件快速传输及交流
💻 JAVA
字号:

/**
 * -- Copyright (C) 2006 Hisham Khalil. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 *
 * Author: Hisham Khalil <hishberlin@hotmail.com>
 */

package connex.session.desktop;

import java.awt.*;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.Border;
import java.io.File;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import connex.core.Presence.PresenceService;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import net.jxta.document.StructuredDocument;
import net.jxta.document.Element;
import net.jxta.document.XMLElement;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: FH-Dortmund</p>
 *
 * @author not attributable
 * @version 1.0
 */
public class ProfileUI extends JDialog {
    private ImageIcon closeI = new ImageIcon(
            "resources" + File.separator + "images" + File.separator +
            "delete_small.png");
    private ImageIcon defaultPic = new ImageIcon(
            "resources" + File.separator + "images" +
            File.separator +
            "default.gif");

    private Thread t = null;
    private ImageIcon pic = null;
    private String ID;
    public ProfileUI() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public ProfileUI(String id) {
        this.ID = id;
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        StructuredDocument doc = (StructuredDocument) PresenceService.
                                 getInstance().getProfile(ID);
        if (doc != null) {
            this.setProfile((XMLElement) doc.getParent());
            this.getPic();
        }
    }

    private void jbInit() throws Exception {
        this.setSize(new Dimension(295, 196));
        this.getContentPane().setBackground(UIManager.getColor(
                "ToolTip.background"));

        //this.setAlwaysOnTop(true);
        this.setUndecorated(true);
        this.addWindowListener(new WindowAdapter() {
            public void windowDeactivated(WindowEvent e) {
                this_windowDeactivated(e);
            }
        });
        getContentPane().setLayout(borderLayout1);
        close.setBorder(null);
        close.setPreferredSize(new Dimension(20, 20));
        close.setActionCommand("close");
        close.setContentAreaFilled(false);
        close.setIcon(closeI);
        close.setMnemonic('0');
        close.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                close_actionPerformed(e);
            }
        });
        jLabel1.setIcon(null);

        jPanel1.setLayout(borderLayout2);
        jPanel2.setOpaque(false);
        jPanel2.setLayout(null);
        jPanel1.setBackground(SystemColor.inactiveCaption);
        jPanel1.setOpaque(true);
        image.setBackground(SystemColor.info);
        image.setBorder(border2);
        image.setOpaque(true);
        image.setBounds(new Rectangle(8, 18, 100, 113));
        image.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                image_mouseClicked(e);
            }
        });
        jLabel2.setForeground(Color.blue);
        jLabel2.setText("name :");
        jLabel2.setBounds(new Rectangle(133, 16, 43, 22));
        jLabel3.setForeground(Color.blue);
        jLabel3.setText("Other :");
        jLabel3.setBounds(new Rectangle(131, 140, 40, 22));
        jLabel4.setForeground(Color.blue);
        jLabel4.setText("E-mail :");
        jLabel4.setBounds(new Rectangle(132, 38, 38, 22));
        jLabel5.setForeground(Color.blue);
        jLabel5.setText("City :");
        jLabel5.setBounds(new Rectangle(133, 89, 46, 25));
        jLabel6.setForeground(Color.blue);
        jLabel6.setText("Language :");
        jLabel6.setBounds(new Rectangle(131, 112, 56, 28));
        jLabel7.setForeground(Color.blue);
        jLabel7.setText("Country :");
        jLabel7.setBounds(new Rectangle(131, 61, 50, 25));
        langua.setText("");
        langua.setBounds(new Rectangle(188, 115, 139, 23));
        city.setText("");
        city.setBounds(new Rectangle(163, 89, 102, 24));
        count.setText("");
        count.setBounds(new Rectangle(179, 61, 88, 22));
        mail.setText("");
        mail.setBounds(new Rectangle(173, 41, 93, 19));
        name.setText("");
        name.setBounds(new Rectangle(169, 16, 71, 25));
        other.setText("");
        other.setBounds(new Rectangle(169, 139, 160, 27));
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
        this.getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
        jPanel2.add(jLabel2);
        jPanel2.add(name);
        jPanel2.add(jLabel4);
        jPanel2.add(mail);
        jPanel2.add(jLabel7);
        jPanel2.add(count);
        jPanel2.add(jLabel5);
        jPanel2.add(city);
        jPanel2.add(jLabel6);
        jPanel2.add(langua);
        jPanel2.add(jLabel3);
        jPanel2.add(other);
        jPanel2.add(image);
        jPanel1.add(jLabel1, java.awt.BorderLayout.CENTER);
        jPanel1.add(close, java.awt.BorderLayout.EAST); }

    private void setProfile(Element element) {
        Element elem = (Element) element.getChildren("name").nextElement();

        if (elem != null && elem.getValue() != null) {
            name.setText(elem.getValue().toString());
        }
        /*elem = (Element) element.getChildren(speedKey).nextElement();
                 if (elem != null && elem.getValue() != null) {
            adv.setSpeed(elem.getValue().toString());
                 }*/
        /*   elem = (Element) element.getChildren(mobilityKey).nextElement();
           if (elem != null && elem.getValue() != null) {
               adv.setMobility(elem.getValue().toString());
           }*/
        elem = (Element) element.getChildren("countery").nextElement();
        if (elem != null && elem.getValue() != null) {
            count.setText(elem.getValue().toString());
        }
        elem = (Element) element.getChildren("language").nextElement();
        if (elem != null && elem.getValue() != null) {
            langua.setText(elem.getValue().toString());
        }

        elem = (Element) element.getChildren("city").nextElement();
        if (elem != null && elem.getValue() != null) {
            city.setText(elem.getValue().toString());
        }

        elem = (Element) element.getChildren("other").nextElement();
        if (elem != null && elem.getValue() != null) {
            other.setText(elem.getValue().toString());
        }
        elem = (Element) element.getChildren("email").nextElement();
        if (elem != null && elem.getValue() != null) {
            mail.setText(elem.getValue().toString());
        }
    }

    private void getPic() {
        t = new Thread() {
            int i = 0;
            byte buf[];
            public void run() {
                while (i < 3 && pic == null) {
                    pic=null;
                    pic = PresenceService.getInstance().getPicture(ID);
                    if (pic == null) {

                        image.setIcon(defaultPic);
                    } else {
                        image.setIcon(pic);
                        break;
                    }
                    i++;
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException ex) {
                    }
                }
                if (pic == null) {

                    image.setIcon(null);
                }

            }
        };
        t.start();

    }

    private BorderLayout borderLayout1 = new BorderLayout();
    private JPanel jPanel1 = new JPanel();
    private JPanel jPanel2 = new JPanel();
    private JButton close = new JButton();
    private JLabel jLabel1 = new JLabel();
    private BorderLayout borderLayout2 = new BorderLayout();
    private Border border1 = BorderFactory.createLineBorder(Color.white, 2);
    private JLabel image = new JLabel();
    private JLabel jLabel2 = new JLabel();
    private JLabel jLabel3 = new JLabel();
    private JLabel jLabel4 = new JLabel();
    private JLabel jLabel5 = new JLabel();
    private JLabel jLabel6 = new JLabel();
    private JLabel jLabel7 = new JLabel();
    private JLabel langua = new JLabel();
    private JLabel city = new JLabel();
    private JLabel count = new JLabel();
    private JLabel mail = new JLabel();
    private JLabel name = new JLabel();
    private JLabel other = new JLabel();
    private Border border2 = BorderFactory.createLineBorder(SystemColor.inactiveCaption, 2);
    public void close_actionPerformed(ActionEvent e) {
        this.dispose();
    }

    public void this_windowDeactivated(WindowEvent e) {
        this.dispose();
    }

    public void image_mouseClicked(MouseEvent e) {
        if (t == null) {
            getPic();
        }
        // image.setIcon(PresenceService.getInstance().getPicture(ID));
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -