Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: edu/ou/kmi/buddyspace/plugins/conference/gui/BSConfInvitationDialog.java


1   package edu.ou.kmi.buddyspace.plugins.conference.gui;
2   
3   /*
4    * BSConfInvitationDialog.java
5    *
6    *
7    * Project: BuddySpace
8    * (C) Copyright Knowledge Media Institute 2002
9    *
10   *
11   * Created on 17 September 2002, 15:18
12   */
13  
14  import java.awt.*;
15  import javax.swing.*;
16  import java.beans.*; // Property change stuff
17  import java.util.*;
18  
19  import org.jabber.jabberbeans.*;
20  import org.jabber.jabberbeans.util.*;
21  
22  import edu.ou.kmi.buddyspace.gui.*;
23  import edu.ou.kmi.buddyspace.plugins.conference.core.*;
24  
25  /**
26   * <code>BSConfInvitationDialog</code> allows input of parameters for 
27   * send of invitation into a conference room.
28   * It calls <code>BSConfBean</code> to send the invitation.
29   *
30   * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
31   */
32  
33  public class BSConfInvitationDialog extends JDialog {
34      private JOptionPane optionPane;
35      
36      /** Constructor */
37      public BSConfInvitationDialog(Frame _parent, BSConfBean _confBean, 
38                                    Enumeration rosterItems, JID _roomJID) {
39                           
40          super(_parent, "Send invitation", true);
41          
42          final Frame parent = _parent;
43          final BSConfBean confBean = _confBean;
44          final JID roomJID = _roomJID;
45          
46          final JComboBox recipientComboBox = new JComboBox();
47          final JTextField subjectTextField = new JTextField();
48          final JTextArea bodyTextArea = new JTextArea();
49          
50          if (roomJID != null && !roomJID.equals("")) {
51              subjectTextField.setText("Invitation for " + roomJID.toString());
52              bodyTextArea.setText("This is a group-chat invitation for " 
53                                   + roomJID.toString());
54          }
55          bodyTextArea.setRows(3);
56          bodyTextArea.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(100, 100, 100)));
57          bodyTextArea.setLineWrap(true);
58          bodyTextArea.setWrapStyleWord(true);
59          
60          final TreeMap recipients = new TreeMap();
61          while (rosterItems.hasMoreElements()) {
62              RosterItem ri = (RosterItem) rosterItems.nextElement();
63              JID jid = ri.getJID();
64              String label = ri.getFriendlyName() + " (" + jid.toString() + ")";
65              recipients.put(label, jid);
66              //recipientComboBox.addItem(label);
67          }
68          TreeMap tmpMap = (TreeMap) recipients.clone();
69          while (!tmpMap.isEmpty()) {
70              Object o = tmpMap.firstKey();
71              recipientComboBox.addItem(o);
72              tmpMap.remove(o);
73          }
74          recipientComboBox.setEditable(true);
75          
76          Object[] fields = {"Recipient: ", recipientComboBox,
77                             "Subject: ", subjectTextField,
78                             "Body: ", bodyTextArea};
79          
80          final String okButton = "OK";
81          final String cancelButton = "Cancel";
82          Object[] options = {okButton, cancelButton};
83  
84          optionPane = new JOptionPane(fields, 
85                                       JOptionPane.PLAIN_MESSAGE,
86                                       JOptionPane.OK_CANCEL_OPTION,
87                                       null,
88                                       options,
89                                       options[0]);
90          setContentPane(optionPane);
91          setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
92  
93          pack();
94          setLocationRelativeTo(parent);
95          
96          // handles actions
97          optionPane.addPropertyChangeListener(new PropertyChangeListener() {
98              public void propertyChange(PropertyChangeEvent e) {
99                  String prop = e.getPropertyName();
100       
101                 if (isVisible() 
102                     && (e.getSource() == optionPane)
103                     && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
104                       prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
105                     Object value = optionPane.getValue();
106 
107                     if (value == JOptionPane.UNINITIALIZED_VALUE) {
108                         // ignore reset
109                         return;
110                     }
111 
112                     // Reset the JOptionPane's value.
113                     // If you don't do this, then if the user
114                     // presses the same button next time, no
115                     // property change event will be fired.
116                     optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
117 
118                     if (value.equals(okButton)) {
119                         if (confBean == null) {
120                             JOptionPane.showMessageDialog(parent, 
121                                           "Cannot use conferencing",
122                                           "Error", 
123                                           JOptionPane.ERROR_MESSAGE);
124                             setVisible(false);
125                             return;
126                         }
127                         String subject = subjectTextField.getText();
128                         String body = bodyTextArea.getText();
129                         String recipientName = (String) recipientComboBox.getSelectedItem();
130                         JID jid = (JID) recipients.get(recipientName);
131                         if (jid == null)
132                             jid = new JID(recipientName);
133                         //if (nick.equals("") || server.equals("") || roomName.equals(""))
134                         if (jid == null) {
135                             JOptionPane.showMessageDialog(parent, 
136                                           "Invalid recipient JID",
137                                           "Error", 
138                                           JOptionPane.ERROR_MESSAGE);
139                             setVisible(false);
140                             return;
141                         }
142                         confBean.sendInvitation(jid, roomJID, subject, body);
143                         setVisible(false);
144                     }
145                     else if (value.equals(cancelButton)) {
146                         setVisible(false);
147                     }
148                 }
149             }
150         });
151     }
152 }