コード例 #1
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();
          }
        });
  }
コード例 #2
0
ファイル: ChatRoomImpl.java プロジェクト: kadet108/blucargo
  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;
  }
コード例 #3
0
ファイル: ChatRoomImpl.java プロジェクト: kadet108/blucargo
  public void insertMessage(Message message) {
    // Debug info
    super.insertMessage(message);
    MessageEvent messageEvent = (MessageEvent) message.getExtension("x", "jabber:x:event");
    if (messageEvent != null) {
      checkEvents(message.getFrom(), message.getPacketID(), messageEvent);
    }

    getTranscriptWindow()
        .insertMessage(participantNickname, message, ChatManager.FROM_COLOR, Color.white);

    // Set the participant jid to their full JID.
    participantJID = message.getFrom();
  }
コード例 #4
0
ファイル: ChatRoomImpl.java プロジェクト: kadet108/blucargo
  // 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);
    }
  }
コード例 #5
0
ファイル: ChatRoomImpl.java プロジェクト: kadet108/blucargo
  // Modified for cargo
  public ChatRoomImpl(
      final String participantJID,
      final String participantNickname,
      String title,
      CargoOffer cargoOffer) {
    this.active = true;
    this.participantJID = participantJID;
    this.participantNickname = participantNickname;

    String[] results = this.participantJID.split("@");
    this.participantNicknameOnly = results[0];

    // Loads the current history for this user.
    loadHistory();

    // Register PacketListeners
    PacketFilter fromFilter = new FromMatchesFilter(participantJID);
    PacketFilter orFilter =
        new OrFilter(new PacketTypeFilter(Presence.class), new PacketTypeFilter(Message.class));
    PacketFilter andFilter = new AndFilter(orFilter, fromFilter);

    SparkManager.getConnection().addPacketListener(this, andFilter);

    // The roomname will be the participantJID
    this.roomname = participantJID;

    // Use the agents username as the Tab Title
    this.tabTitle = title;

    // The name of the room will be the node of the user jid + conversation.
    this.roomTitle = participantNickname;

    // Add RoomInfo
    this.getSplitPane().setRightComponent(null);
    getSplitPane().setDividerSize(0);

    presence = PresenceManager.getPresence(participantJID);

    roster = SparkManager.getConnection().getRoster();

    RosterEntry entry = roster.getEntry(participantJID);

    tabIcon = PresenceManager.getIconFromPresence(presence);

    infoButton =
        new CargoChatRoomButton("", SparkRes.getImageIcon(SparkRes.SPARK_IKONKA_WIZYTOWKA));
    infoButton.setToolTipText(Res.getString("message.view.information.about.this.user"));
    infoButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    // Create basic toolbar.
    getToolBar().addChatRoomButton(infoButton);

    // If the user is not in the roster, then allow user to add them.
    // addToRosterButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.ADD_IMAGE_24x24));

    addToRosterButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.SPARK_IKONKA_DODAJ));
    addToRosterButton.setRolloverIcon(SparkRes.getImageIcon(SparkRes.SPARK_IKONKA_DODAJ));
    addToRosterButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    addToRosterButton.setBorderPainted(false);
    addToRosterButton.setRolloverEnabled(false);
    addToRosterButton.setContentAreaFilled(false);
    addToRosterButton.setIgnoreRepaint(true);
    addToRosterButton.setOpaque(false);
    addToRosterButton.setBorder(null);
    addToRosterButton.setBorderPainted(false);
    addToRosterButton.setMargin(new Insets(0, 0, 0, 0));

    MouseListener[] mouseListeners2 = addToRosterButton.getMouseListeners();
    for (MouseListener mouseListener : mouseListeners2) {
      if (mouseListener instanceof MouseAdapter) {
        addToRosterButton.removeMouseListener(mouseListener);
      }
    }

    if (entry == null && !StringUtils.parseResource(participantJID).equals(participantNickname)) {
      addToRosterButton.setToolTipText(Res.getString("message.add.this.user.to.your.roster"));
      getToolBar().addChatRoomButton(addToRosterButton);

      addToRosterButton.addActionListener(this);
    }

    // Show VCard.
    infoButton.addActionListener(this);

    // If this is a private chat from a group chat room, do not show
    // toolbar.
    if (StringUtils.parseResource(participantJID).equals(participantNickname)) {
      getToolBar().setVisible(false);
    }

    typingTimerTask =
        new TimerTask() {
          public void run() {
            if (!sendTypingNotification) {
              return;
            }
            long now = System.currentTimeMillis();
            if (now - lastTypedCharTime > 2000) {
              if (!sendNotification) {
                // send cancel
                SparkManager.getMessageEventManager()
                    .sendCancelledNotification(getParticipantJID(), threadID);
                sendNotification = true;
              }
            }
          }
        };

    TaskEngine.getInstance().scheduleAtFixedRate(typingTimerTask, 2000, 2000);
    lastActivity = System.currentTimeMillis();

    super.setCargoOffer(cargoOffer);

    this.addMessageEventListener(
        new MessageEventListener() {

          @Override
          public void sendingMessage(Message message) {
            message.setProperty(CARGO_OFFER_PROPERTY, getCargoOffer().getId());
          }

          @Override
          public void receivingMessage(Message message) {}
        });

    this.addMessageListener(
        new org.jivesoftware.spark.ui.MessageListener() {

          @Override
          public void messageReceived(ChatRoom room, Message message) {
            Long cargoOfferId = (Long) message.getProperty(CARGO_OFFER_PROPERTY);
            setCargoOffer(CargoDataManager.getInstance().getCargoOfferById(cargoOfferId));

            if (getCargoOffer() != null) {
              if (acceptedOfferButton != null) {
                getEditorBar().remove(acceptedOfferButton);
              }

              JButton acceptOfferButtonTemp =
                  getAcceptOfferButton(participantNicknameOnly, getCargoOffer());
              acceptedOfferButton = acceptOfferButtonTemp;
              getEditorBar().add(acceptedOfferButton);

            } else {
              Long newCargoOfferId = null;
              if (message.getProperty(CARGO_OFFER_PROPERTY) != null) {
                newCargoOfferId = (Long) message.getProperty(CARGO_OFFER_PROPERTY);
              }

              if (newCargoOfferId != null) {
                CargoOffer co = CargoDataManager.getInstance().getCargoOfferById(newCargoOfferId);
                setCargoOffer(co);

                if (acceptedOfferButton != null) {
                  getEditorBar().remove(acceptedOfferButton);
                }
                JButton acceptOfferButton =
                    getAcceptOfferButton(participantNicknameOnly, getCargoOffer());
                acceptedOfferButton = acceptOfferButton;
                getEditorBar().add(acceptedOfferButton);
              }
            }
          }

          @Override
          public void messageSent(ChatRoom room, Message message) {
            // TODO Auto-generated method stub
            String ooo = "oeoeu";
          }
        });
  }
コード例 #6
0
ファイル: Notes.java プロジェクト: justin0127/IM
  public Notes(String sessionID, ChatRoom room) {
    setLayout(new BorderLayout());

    this.chatRoom = room;

    this.sessionID = sessionID;

    textPane = new JTextPane();
    textPane.setText(FpRes.getString("message.click.to.add.notes"));
    textPane.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (!hasClickedInPane) {
              textPane.setText("");
              hasClickedInPane = true;
            }
          }
        });

    scrollPane = new JScrollPane(textPane);

    this.add(scrollPane, BorderLayout.CENTER);

    toolBar = new JToolBar();
    toolBar.setFloatable(false);

    saveButton = new RolloverButton(FastpathRes.getImageIcon(FastpathRes.SAVE_AS_16x16));

    toolBar.add(saveButton);

    ResourceUtils.resButton(saveButton, FpRes.getString("button.save.note"));

    final BackgroundPane titlePanel = new BackgroundPane();
    titlePanel.setLayout(new GridBagLayout());

    JLabel notesLabel = new JLabel();
    notesLabel.setFont(new Font("Dialog", Font.BOLD, 12));

    ResourceUtils.resLabel(notesLabel, textPane, FpRes.getString("label.notes"));

    JLabel descriptionLabel = new JLabel();
    descriptionLabel.setText(FpRes.getString("message.chat.notes"));

    titlePanel.add(
        notesLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));
    titlePanel.add(
        descriptionLabel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 10, 5, 5),
            0,
            0));
    titlePanel.add(
        saveButton,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 10, 5, 5),
            0,
            0));

    // add(titlePanel, BorderLayout.NORTH);

    textPane
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void changedUpdate(DocumentEvent e) {
                saveButton.setEnabled(true);
                updated = true;
              }

              public void insertUpdate(DocumentEvent e) {
                saveButton.setEnabled(true);
                updated = true;
              }

              public void removeUpdate(DocumentEvent e) {
                saveButton.setEnabled(true);
                updated = true;
              }
            });

    saveButton.setEnabled(false);

    // Add status label
    statusLabel = new JLabel();
    this.add(statusLabel, BorderLayout.SOUTH);

    chatRoom.addClosingListener(
        new ChatRoomClosingListener() {
          public void closing() {
            if (updated) {
              saveNotes();
            }
          }
        });
  }