Пример #1
0
 public static JID full(String jid) {
   jid = StringUtils.defaultString(jid);
   return new JID(
       XmppStringUtils.parseLocalpart(jid),
       XmppStringUtils.parseDomain(jid),
       XmppStringUtils.parseResource(jid));
 }
Пример #2
0
  private void showInvitationInChat(final GameOfferPacket invitation) {
    invitation.setType(IQ.Type.result);
    invitation.setTo(invitation.getFrom());

    final ChatRoom room =
        SparkManager.getChatManager()
            .getChatRoom(XmppStringUtils.parseBareJid(invitation.getFrom()));

    String name = XmppStringUtils.parseLocalpart(invitation.getFrom());
    final JPanel panel = new JPanel();
    JLabel text = new JLabel("Game request from" + name);
    JLabel game = new JLabel("Battleships");
    game.setFont(new Font("Dialog", Font.BOLD, 24));
    game.setForeground(Color.RED);
    JButton accept = new JButton(Res.getString("button.accept").replace("&", ""));
    JButton decline = new JButton(Res.getString("button.decline").replace("&", ""));
    panel.add(text);
    panel.add(game);
    panel.add(accept);
    panel.add(decline);
    room.getTranscriptWindow().addComponent(panel);

    accept.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              SparkManager.getConnection().sendStanza(invitation);
            } catch (SmackException.NotConnectedException e1) {
              Log.warning("Unable to send invitation accept to " + invitation.getTo(), e1);
            }
            invitation.setStartingPlayer(!invitation.isStartingPlayer());
            ChatRoomOpeningListener.createWindow(invitation, invitation.getFrom());
            panel.remove(3);
            panel.remove(2);
            panel.repaint();
            panel.revalidate();
          }
        });

    decline.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            invitation.setType(IQ.Type.error);
            try {
              SparkManager.getConnection().sendStanza(invitation);
            } catch (SmackException.NotConnectedException e1) {
              Log.warning("Unable to send invitation decline to " + invitation.getTo(), e1);
            }
            panel.remove(3);
            panel.remove(2);
            panel.repaint();
            panel.revalidate();
          }
        });
  }
Пример #3
0
 public static JID bare(String jid) {
   jid = StringUtils.defaultString(jid);
   return new JID(XmppStringUtils.parseLocalpart(jid), XmppStringUtils.parseDomain(jid), "");
 }