Ejemplo n.º 1
0
  public void sendMessage(String text) {
    final Message message = new Message();

    if (threadID == null) {
      threadID = StringUtils.randomString(6);
    }
    message.setThread(threadID);

    // Set the body of the message using typedMessage
    message.setBody(text);

    // IF there is no body, just return and do nothing
    if (!ModelUtil.hasLength(text)) {
      return;
    }

    // Fire Message Filters
    SparkManager.getChatManager().filterOutgoingMessage(this, message);

    // Fire Global Filters
    SparkManager.getChatManager().fireGlobalMessageSentListeners(this, message);

    sendMessage(message);

    sendNotification = true;
  }
Ejemplo n.º 2
0
  // I would normally use the command pattern, but
  // have no real use when dealing with just a couple options.
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == infoButton) {
      VCardManager vcard = SparkManager.getVCardManager();
      vcard.viewProfile(participantJID, SparkManager.getChatManager().getChatContainer());
    } else if (e.getSource() == addToRosterButton) {
      RosterDialog rosterDialog = new RosterDialog();
      rosterDialog.setDefaultJID(participantJID);
      rosterDialog.setDefaultNickname(getParticipantNickname());
      rosterDialog.showRosterDialog(
          SparkManager.getChatManager().getChatContainer().getChatFrame());
    } else {
      super.actionPerformed(e);
    }
  }
Ejemplo n.º 3
0
  @Override
  public void initialize() {

    ProviderManager.addIQProvider(
        GameOfferPacket.ELEMENT_NAME, GameOfferPacket.NAMESPACE, GameOfferPacket.class);
    ProviderManager.addExtensionProvider(
        MovePacket.ELEMENT_NAME, MovePacket.NAMESPACE, MovePacket.class);
    ProviderManager.addExtensionProvider(
        MoveAnswerPacket.ELEMENT_NAME, MoveAnswerPacket.NAMESPACE, MoveAnswerPacket.class);

    _gameofferListener =
        new StanzaListener() {

          @Override
          public void processPacket(Stanza stanza) {
            GameOfferPacket invitation = (GameOfferPacket) stanza;
            if (invitation.getType() == IQ.Type.get) {
              showInvitationInChat(invitation);
            }
          }
        };

    SparkManager.getConnection()
        .addAsyncStanzaListener(_gameofferListener, new StanzaTypeFilter(GameOfferPacket.class));

    _chatRoomListener = new ChatRoomOpeningListener();

    SparkManager.getChatManager().addChatRoomListener(_chatRoomListener);
  }
Ejemplo n.º 4
0
  public void closeChatRoom() {
    // If already closed, don't bother.
    if (!active) {
      return;
    }

    super.closeChatRoom();

    // Remove info listener
    infoButton.removeActionListener(this);
    addToRosterButton.removeActionListener(this);

    // Send a cancel notification event on closing if listening.
    if (!sendNotification) {
      // send cancel
      SparkManager.getMessageEventManager()
          .sendCancelledNotification(getParticipantJID(), threadID);

      sendNotification = true;
    }

    SparkManager.getChatManager().removeChat(this);

    SparkManager.getConnection().removePacketListener(this);
    if (typingTimerTask != null) {
      TaskEngine.getInstance().cancelScheduledTask(typingTimerTask);
      typingTimerTask = null;
    }
    active = false;
  }
Ejemplo n.º 5
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();
          }
        });
  }
Ejemplo n.º 6
0
  public void reconnectionSuccessful() {
    Presence usersPresence = PresenceManager.getPresence(getParticipantJID());
    if (usersPresence.isAvailable()) {
      presence = usersPresence;
    }

    SparkManager.getChatManager().getChatContainer().fireChatRoomStateUpdated(this);
    getChatInputEditor().setEnabled(true);
    getSendButton().setEnabled(true);
  }
Ejemplo n.º 7
0
  public void showDialog() {
    if (notesFrame != null && notesFrame.isVisible()) {
      return;
    }

    notesFrame = new JFrame(FpRes.getString("title.chat.notes"));
    notesFrame.setIconImage(SparkManager.getMainWindow().getIconImage());
    notesFrame.getContentPane().setLayout(new BorderLayout());
    notesFrame.getContentPane().add(new JScrollPane(this), BorderLayout.CENTER);
    notesFrame.pack();
    notesFrame.setSize(500, 400);

    notesFrame.setLocationRelativeTo(SparkManager.getChatManager().getChatContainer());
    notesFrame.setVisible(true);

    textPane.requestFocusInWindow();
  }
Ejemplo n.º 8
0
  /**
   * Updates the icon of the user based on their presence.
   *
   * @param presence the users presence.
   */
  public void updatePresenceIcon(Presence presence) {
    ChatManager chatManager = SparkManager.getChatManager();
    boolean handled = chatManager.fireContactItemPresenceChanged(this, presence);
    if (handled) {
      return;
    }

    String status = presence.getStatus();
    Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
    boolean isAvailable = false;
    if (status == null && presence.isAvailable()) {
      Presence.Mode mode = presence.getMode();
      if (mode == Presence.Mode.available) {
        status = Res.getString("status.online");
        isAvailable = true;
      } else if (mode == Presence.Mode.away) {
        status = Res.getString("status.away");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      } else if (mode == Presence.Mode.chat) {
        status = Res.getString("status.free.to.chat");
      } else if (mode == Presence.Mode.dnd) {
        status = Res.getString("status.do.not.disturb");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      } else if (mode == Presence.Mode.xa) {
        status = Res.getString("status.extended.away");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      }
    }

    if (presence.isAvailable()
        && (presence.getMode() == Presence.Mode.dnd
            || presence.getMode() == Presence.Mode.away
            || presence.getMode() == Presence.Mode.xa)) {
      statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
    } else if (presence.isAvailable()) {
      isAvailable = true;
    } else if (!presence.isAvailable()) {
      getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
      getNicknameLabel().setForeground((Color) UIManager.get("ContactItemOffline.color"));

      RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getJID());
      if (entry != null
          && (entry.getType() == RosterPacket.ItemType.none
              || entry.getType() == RosterPacket.ItemType.from)
          && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
        // Do not move out of group.
        setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        setStatusText(Res.getString("status.pending"));
      } else {
        // We should keep the offline bullet (not available) instead of putting icon null.
        setIcon(SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON));
        setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        setAvailable(false);
        if (ModelUtil.hasLength(status)) {
          setStatusText(status);
        } else {
          setStatusText("");
        }
      }

      sideIcon.setIcon(null);
      setAvailable(false);
      return;
    }

    Icon sIcon = PresenceManager.getIconFromPresence(presence);
    if (sIcon != null) {
      setIcon(sIcon);
    } else {
      setIcon(statusIcon);
    }
    if (status != null) {
      setStatus(status);
    }

    if (PresenceManager.isOnPhone(presence)) {
      statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE);
      setIcon(statusIcon);
    }

    // Always change nickname label to black.
    getNicknameLabel().setForeground((Color) UIManager.get("ContactItemNickname.foreground"));

    if (isAvailable) {
      getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
      if (Res.getString("status.online").equals(status)
          || Res.getString("available").equalsIgnoreCase(status)) {
        setStatusText("");
      } else {
        setStatusText(status);
      }
    } else if (presence.isAvailable()) {
      LocalPreferences pref = SettingsManager.getLocalPreferences();
      if (pref.isGrayingOutEnabled()) {
        getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, fontSize));
        getNicknameLabel().setForeground(Color.gray);
      } else {
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setForeground(Color.black);
      }
      if (status != null) {
        setStatusText(status);
      }
    }

    setAvailable(true);
  }
Ejemplo n.º 9
0
 private void handleDisconnect() {
   presence = new Presence(Presence.Type.unavailable);
   getChatInputEditor().setEnabled(false);
   getSendButton().setEnabled(false);
   SparkManager.getChatManager().getChatContainer().fireChatRoomStateUpdated(this);
 }