/** * {@inheritDoc} * * <p>Implements {@link RegistrationStateChangeListener}. Notifies this instance that there has * been a change in the <tt>RegistrationState</tt> of {@link #protocolProvider}. Subscribes this * instance to {@link ColibriConferenceIQ}s as soon as <tt>protocolProvider</tt> is registered and * unsubscribes it as soon as <tt>protocolProvider</tt> is unregistered. */ public void registrationStateChanged(RegistrationStateChangeEvent ev) { RegistrationState registrationState = ev.getNewState(); if (RegistrationState.REGISTERED.equals(registrationState)) { protocolProvider.getConnection().addPacketListener(this, this); } else if (RegistrationState.UNREGISTERED.equals(registrationState)) { XMPPConnection connection = protocolProvider.getConnection(); if (connection != null) connection.removePacketListener(this); } }
/** * Registers this Manager's listener with <tt>connection</tt>. * * @param connection the connection that we'd like this manager to register with. */ public void addPacketListener(XMPPConnection connection) { PacketFilter filter = new AndFilter( new PacketTypeFilter(Presence.class), new PacketExtensionFilter( CapsPacketExtension.ELEMENT_NAME, CapsPacketExtension.NAMESPACE)); connection.addPacketListener(new CapsPacketListener(), filter); }
/** * Constructor. * * @param connection The current active XMPPConnection. * @param remoteId The ID of the user to chat with. (May have a resource, but this will be used * only as a hint for sending replies.) * @exception XMPPException If an error occurs joining the room. */ public ChatWindow(XMPPConnection connection, String remoteId) throws XMPPException { mConnection = connection; mRemoteIdFull = remoteId; mRemoteIdBare = StringUtils.parseBareAddress(remoteId); if (!mRemoteIdFull.equals(mRemoteIdBare)) setLastKnownResource(mRemoteIdFull); mChatObject = new BetterChat(mConnection, mRemoteIdFull); // Get nickname for remote user and use for window title RosterEntry entry = mConnection.getRoster().getEntry(mRemoteIdBare); if (entry != null) { mRemoteNick = entry.getName(); } if (mRemoteNick == null || mRemoteNick.equals("")) { mRemoteNick = mRemoteIdBare; } String val = JavolinApp.resources.getString("ChatWindow_WindowTitle"); setTitle(JavolinApp.getAppName() + ": " + val + " " + mRemoteNick); // Get local user ID and chat color mLocalId = StringUtils.parseBareAddress(mConnection.getUser()); mColorMap = new UserColorMap(); mColorMap.getUserNameColor(mLocalId); // Give user first color // Set up UI buildUI(); setSize(500, 400); mSizePosSaver = new SizeAndPositionSaver(this, NODENAME); restoreWindowState(); // Send message when user presses Enter while editing input text mSendMessageAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { doSendMessage(); } }; mInputText.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), mSendMessageAction); // Handle window events setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent we) { saveWindowState(); if (mLog != null) { mLog.dispose(); } mColorMap.dispose(); } public void windowOpened(WindowEvent we) { // Give focus to input text area when the window is created mInputText.requestFocusInWindow(); } }); /* We do *not* register as a message listener. The Smack Chat object is * kind of a crock; there's no documented way to turn off its packet * interception when we close this window. And the main JavolinApp * listener is already grabbing all CHAT and NORMAL message packets, so * there's no need for us to listen -- in fact, it leads to double * printing in some cases. */ }