/* * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer * * 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 USA * * For questions, comments etc, * use the website at http://jeti.jabberstudio.org * or mail/im me at jeti@jabberstudio.org */ package nu.fw.jeti.ui; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.text.MessageFormat; import java.util.List; import javax.swing.*; import nu.fw.jeti.jabber.Backend; import nu.fw.jeti.jabber.JIDStatus; import nu.fw.jeti.jabber.elements.IQXRoster; import nu.fw.jeti.jabber.elements.InfoQuery; import nu.fw.jeti.jabber.elements.RosterItem; import nu.fw.jeti.util.I18N; import nu.fw.jeti.util.Utils; /** * * @author E.S. de Boer */ public class GroupDialog extends JDialog { private JPanel btnPanel = new JPanel(); private JLabel lbltekst = new JLabel(); private JComboBox cmbGroup; private JButton btnCancel = new JButton(); private JButton btnOK = new JButton(); private String[] groups; //private String operation; private Backend backend; private String currentGroup; private JIDStatus jidStatus; public GroupDialog(JIDStatus jidStatus, Backend backend) { super(backend.getMainFrame(), I18N.gettext("main.main.rostermenu.Add_to_Group"), false); groups = backend.getAllGroups(); String[] temp = new String[groups.length - 1]; int i = 0; for (int tel = 0; tel < groups.length; tel++) {//remove group wich contains jid if (!jidStatus.isGroupPresent(groups[tel])) { temp[i] = groups[tel]; i++; } } groups = new String[i]; System.arraycopy(temp, 0, groups, 0, i); init(jidStatus, backend); lbltekst.setText(MessageFormat.format(I18N.gettext("main.popup.Add_{0}_to"), new Object[] { jidStatus.getNick()})); pack(); setLocationRelativeTo(null); } private void init(JIDStatus jidStatus, Backend backend) { this.backend = backend; this.jidStatus = jidStatus; try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } public GroupDialog(String group, JIDStatus jidStatus, Backend backend) { super(backend.getMainFrame(), I18N.gettext("main.main.rostermenu.Change_Group"), false); groups = backend.getAllGroups(); String[] temp = new String[groups.length - 1]; int i = 0; for (int tel = 0; tel < groups.length; tel++) {//remove group wich contains jid if (!jidStatus.isGroupPresent(groups[tel])) { temp[i] = groups[tel]; i++; } } groups = new String[i]; System.arraycopy(temp, 0, groups, 0, i); currentGroup = group; init(jidStatus, backend); lbltekst.setText(MessageFormat.format(I18N.gettext("main.popup.Change_{0}_from_{1}_to"), new Object[] { jidStatus.getNick(), group})); pack(); setLocationRelativeTo(null); } void jbInit() throws Exception { this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getRootPane().setDefaultButton(btnOK); cmbGroup = new JComboBox(groups); cmbGroup.setAlignmentX((float) 0.0); cmbGroup.setEditable(true); Action cancelAction = new AbstractAction(I18N.gettext("Cancel")) { public void actionPerformed(ActionEvent e) { dispose(); } }; Utils.addCancelButton(this, btnCancel, cancelAction); btnOK.setText(I18N.gettext("OK")); btnOK.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { btnOK_actionPerformed(e); } }); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.LINE_START; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(3, 3, 0, 3); c.weightx = 1.0; getContentPane().add(lbltekst, c); getContentPane().add(cmbGroup, c); btnPanel.add(btnOK, null); btnPanel.add(btnCancel, null); getContentPane().add(btnPanel, c); } void btnOK_actionPerformed(ActionEvent e) { String group = (String) cmbGroup.getSelectedItem(); if (!group.equals(" ")) { List groups = jidStatus.getGroupsCopy(); if (currentGroup != null) { //backend.changeGroup(jidStatus,currentGroup,group); groups.remove(currentGroup); groups.add(group); IQXRoster roster = new IQXRoster(new RosterItem(jidStatus.getJID(), jidStatus.getNick(), null, null, groups)); backend.send(new InfoQuery("set", roster)); } else { if (!jidStatus.isGroupPresent(group)) { groups.add(group); IQXRoster roster = new IQXRoster(new RosterItem(jidStatus.getJID(), jidStatus.getNick(), null, null, groups)); backend.send(new InfoQuery("set", roster)); //backend.addGroup(jidStatus,group); } } } this.dispose(); } } /* * Overrides for emacs * Local variables: * tab-width: 4 * End: */