📄 informationviewerdialog.java~
字号:
/* Copyright (C) 2003 Adam Olsen 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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Locale;import java.util.ResourceBundle;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTabbedPane;import javax.swing.JTextField;import javax.swing.SwingUtilities;import javax.swing.text.JTextComponent;import org.jivesoftware.smack.PacketCollector;import org.jivesoftware.smack.SmackConfiguration;import org.jivesoftware.smack.XMPPConnection;import org.jivesoftware.smack.XMPPException;import org.jivesoftware.smack.filter.PacketIDFilter;import org.jivesoftware.smack.packet.IQ;import org.jivesoftware.smackx.packet.Time;import com.valhalla.gui.DialogTracker;import com.valhalla.gui.MJTextArea;import com.valhalla.gui.MJTextField;import com.valhalla.gui.WaitDialog;import com.valhalla.jbother.jabber.smack.VCard;import com.valhalla.jbother.jabber.smack.Version;import com.valhalla.jbother.jabber.smack.LastActivity;/** * A dialog that collects and shows information about a Jabber user Shows a * dialog with several fields and starts an information collecting field for * each one. As each piece of information is found it fills out the fields * * @author Adam Olsen * @author Andrey Zakirov * @version 1.0 */public class InformationViewerDialog extends JDialog implements WaitDialogListener { private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault()); private JButton okButton = new JButton(resources.getString("okButton")); private JButton retrieve = new JButton(resources.getString("retrieve")); private JButton save = new JButton(resources.getString("saveButton")); private String user; private JPanel mainPanel; private JTabbedPane pane = new JTabbedPane(); private InformationViewerDialog thisPointer = this; private Vector fields = new Vector(); private GridBagConstraints c = new GridBagConstraints(); private MJTextField name = new MJTextField(); private MJTextField nickname = new MJTextField(); private MJTextField email = new MJTextField(); private MJTextField birthday = new MJTextField(); private MJTextField homepage = new MJTextField(); private MJTextField phone = new MJTextField(); // location private MJTextField street1 = new MJTextField(); private MJTextField street2 = new MJTextField(); private MJTextField city = new MJTextField(); private MJTextField state = new MJTextField(); private MJTextField zip = new MJTextField(); private MJTextField country = new MJTextField(); // work private MJTextField company = new MJTextField(); private MJTextField department = new MJTextField(); private MJTextField position = new MJTextField(); private MJTextField role = new MJTextField(); private MJTextArea about = new MJTextArea(); private WaitDialog wait = new WaitDialog(this, this, resources .getString("pleaseWait")); private MJTextField clientField = new MJTextField(); private MJTextField timeField = new MJTextField(); private MJTextField lastField = new MJTextField(); private boolean personal; protected boolean cancelled = false; /** * Default constructor * * @param user * the user you want to collect information about */ public InformationViewerDialog(String user, boolean personal) { this.personal = personal; this.user = user; if (!personal) setTitle(resources.getString("information") + " " + user); else setTitle(resources.getString("editInformation")); if (!BuddyList.getInstance().checkConnection()) { BuddyList.getInstance().connectionError(); return; } about.setWrapStyleWord(true); mainPanel = (JPanel) getContentPane(); mainPanel.setLayout(new BorderLayout()); mainPanel.add(pane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(retrieve); if (personal) buttonPanel.add(save); buttonPanel.add(okButton); //buttonPanel.add( Box.createHorizontalGlue() ); buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); mainPanel.add(buttonPanel, BorderLayout.SOUTH); addGeneralItems(); addLocationItems(); addWorkItems(); addAboutItems(); if (!personal) { addClientItems(); } pack(); Dimension dim = getSize(); setSize(new Dimension(450, (int) dim.getHeight())); setLocationRelativeTo(null); DialogTracker.addDialog(this, false, true); collectInformation(); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DialogTracker.removeDialog(thisPointer); } }); retrieve.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { collectInformation(); } }); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { wait.setVisible(true); cancelled = false; disableAll(); new Thread(new SaveVCard()).start(); } }); } public void cancel() { cancelled = true; } private void collectInformation() { wait.setVisible(true); disableAll(); new Thread(new VCardCollector()).start(); if (!personal) { new Thread(new VersionCollector(clientField, this)).start(); new Thread(new TimeCollector(timeField, this)).start(); new Thread(new LastCollector(lastField, this)).start(); } } public InformationViewerDialog(String user) { this(user, false); } private class SaveVCard implements Runnable { public void run() { if( cancelled ) return; VCard card = new VCard(); card.setFullName(name.getText()); card.setNickname(nickname.getText()); card.setBirthday(birthday.getText()); card.setEmail(email.getText()); card.setTel_Home_Voice(phone.getText()); card.setAddress_Work_Street(street1.getText()); card.setAddress_Work_Locality(city.getText()); card.setAddress_Work_Region(state.getText()); card.setAddress_Work_PCode(zip.getText()); card.setAddress_Work_Country(country.getText()); card.setOrg_Name(company.getText()); card.setOrg_Unit(department.getText()); card.setTitle(position.getText()); card.setRole(role.getText()); card.setDescription(about.getText()); try { card.upload(BuddyList.getInstance().getConnection()); } catch (NullPointerException npe) { npe.printStackTrace(); } catch (XMPPException e) { e.printStackTrace(); } if( cancelled ) return; SwingUtilities.invokeLater(new Runnable() { public void run() { wait.setVisible(false); enableAll(); } }); } } private class VCardCollector implements Runnable { public void cancel() { cancelled = true; } public void run() { VCard temp = null; if( cancelled ) return; try { if (!personal) { temp = VCard.fetch(BuddyList.getInstance().getConnection(), user); } else { temp = VCard.fetch(BuddyList.getInstance().getConnection()); } } catch (NullPointerException npe) { } catch (XMPPException ex) { } final VCard card = temp; if( cancelled ) return; SwingUtilities.invokeLater(new Runnable() { public void run() { if (card != null) { name.setText(card.getFullName()); nickname.setText(card.getNickname()); birthday.setText(card.getBirthday()); email.setText(card.getEmail()); phone.setText(card.getTel_Home_Voice()); street1.setText(card.getAddress_Work_Street()); city.setText(card.getAddress_Work_Locality()); state.setText(card.getAddress_Work_Region()); zip.setText(card.getAddress_Work_PCode()); country.setText(card.getAddress_Work_Country()); company.setText(card.getOrg_Name()); department.setText(card.getOrg_Unit()); position.setText(card.getTitle()); role.setText(card.getRole()); about.setText(card.getDescription()); about.setCaretPosition(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -