コード例 #1
0
ファイル: ChatRoomImpl.java プロジェクト: kadet108/blucargo
  private void loadHistory() {
    // Add VCard Panel
    final VCardPanel vcardPanel = new VCardPanel(participantJID);

    vcardPanel.setPreferredSize(new Dimension(10, 71));
    vcardPanel.setMaximumSize(new Dimension(1100, 71));
    vcardPanel.setMinimumSize(new Dimension(1100, 71));

    getToolBar()
        .add(
            vcardPanel,
            new GridBagConstraints(
                0,
                1,
                1,
                1,
                1.0,
                0.0,
                GridBagConstraints.NORTHWEST,
                GridBagConstraints.HORIZONTAL,
                new Insets(0, 2, 0, 2),
                0,
                0));

    final LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
    if (!localPreferences.isChatHistoryEnabled()) {
      return;
    }

    if (!localPreferences.isPrevChatHistoryEnabled()) {
      return;
    }

    final String bareJID = StringUtils.parseBareAddress(getParticipantJID());
    final ChatTranscript chatTranscript = ChatTranscripts.getCurrentChatTranscript(bareJID);
    final String personalNickname = SparkManager.getUserManager().getNickname();

    for (HistoryMessage message : chatTranscript.getMessages()) {
      String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom());
      String messageBody = message.getBody();
      if (nickname.equals(message.getFrom())) {
        String otherJID = StringUtils.parseBareAddress(message.getFrom());
        String myJID = SparkManager.getSessionManager().getBareAddress();

        if (otherJID.equals(myJID)) {
          nickname = personalNickname;
        } else {
          nickname = StringUtils.parseName(nickname);
        }
      }

      if (ModelUtil.hasLength(messageBody) && messageBody.startsWith("/me ")) {
        messageBody = messageBody.replaceFirst("/me", nickname);
      }

      final Date messageDate = message.getDate();
      getTranscriptWindow().insertHistoryMessage(nickname, messageBody, messageDate);
    }
  }
コード例 #2
0
ファイル: ChatRoomImpl.java プロジェクト: kadet108/blucargo
  /**
   * Sends a message to the appropriate jid. The message is automatically added to the transcript.
   *
   * @param message the message to send.
   */
  public void sendMessage(Message message) {
    lastActivity = System.currentTimeMillis();

    try {
      getTranscriptWindow()
          .insertMessage(getNickname(), message, ChatManager.TO_COLOR, Color.white);
      getChatInputEditor().selectAll();

      getTranscriptWindow().validate();
      getTranscriptWindow().repaint();
      getChatInputEditor().clear();
    } catch (Exception ex) {
      Log.error("Error sending message", ex);
    }

    // Before sending message, let's add our full jid for full verification
    message.setType(Message.Type.chat);
    message.setTo(participantJID);
    message.setFrom(SparkManager.getSessionManager().getJID());

    // Notify users that message has been sent
    fireMessageSent(message);

    addToTranscript(message, false);

    getChatInputEditor().setCaretPosition(0);
    getChatInputEditor().requestFocusInWindow();
    scrollToBottom();

    // No need to request displayed or delivered as we aren't doing anything
    // with this
    // information.
    MessageEventManager.addNotificationsRequests(message, true, false, false, true);

    // Send the message that contains the notifications request
    try {
      fireOutgoingMessageSending(message);
      SparkManager.getConnection().sendPacket(message);
    } catch (Exception ex) {
      Log.error("Error sending message", ex);
    }
  }
コード例 #3
0
ファイル: VCardEditor.java プロジェクト: kadet108/blucargo
  /** Saves the VCard. */
  private void saveVCard() {
    final VCard vcard = new VCard();

    // Save personal info
    vcard.setFirstName(personalPanel.getFirstName());
    vcard.setLastName(personalPanel.getLastName());
    vcard.setMiddleName(personalPanel.getMiddleName());
    vcard.setEmailHome(personalPanel.getEmailAddress());
    vcard.setNickName(personalPanel.getNickname());

    // Save business info
    vcard.setOrganization(businessPanel.getCompany());
    vcard.setAddressFieldWork("STREET", businessPanel.getStreetAddress());
    vcard.setAddressFieldWork("LOCALITY", businessPanel.getCity());
    vcard.setAddressFieldWork("REGION", businessPanel.getState());
    vcard.setAddressFieldWork("PCODE", businessPanel.getZipCode());
    vcard.setAddressFieldWork("CTRY", businessPanel.getCountry());
    vcard.setField("TITLE", businessPanel.getJobTitle());
    vcard.setOrganizationUnit(businessPanel.getDepartment());
    vcard.setPhoneWork("VOICE", businessPanel.getPhone());
    vcard.setPhoneWork("FAX", businessPanel.getFax());
    vcard.setPhoneWork("PAGER", businessPanel.getPager());
    vcard.setPhoneWork("CELL", businessPanel.getMobile());
    vcard.setField("URL", businessPanel.getWebPage());

    // Save Home Info
    vcard.setAddressFieldHome("STREET", homePanel.getStreetAddress());
    vcard.setAddressFieldHome("LOCALITY", homePanel.getCity());
    vcard.setAddressFieldHome("REGION", homePanel.getState());
    vcard.setAddressFieldHome("PCODE", homePanel.getZipCode());
    vcard.setAddressFieldHome("CTRY", homePanel.getCountry());
    vcard.setPhoneHome("VOICE", homePanel.getPhone());
    vcard.setPhoneHome("FAX", homePanel.getFax());
    vcard.setPhoneHome("PAGER", homePanel.getPager());
    vcard.setPhoneHome("CELL", homePanel.getMobile());

    // Save Avatar
    final File avatarFile = avatarPanel.getAvatarFile();
    byte[] avatarBytes = avatarPanel.getAvatarBytes();

    if (avatarFile != null) {
      try {
        // Make it 48x48
        ImageIcon icon = new ImageIcon(avatarFile.toURI().toURL());
        Image image = icon.getImage();
        image = image.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
        avatarBytes = GraphicUtils.getBytesFromImage(image);
      } catch (MalformedURLException e) {
        Log.error("Unable to set avatar.", e);
      }
    }

    // If avatar bytes, persist as vcard.
    if (avatarBytes != null) {
      vcard.setAvatar(avatarBytes);
    }

    try {
      final VCardManager vcardManager = SparkManager.getVCardManager();
      vcardManager.setPersonalVCard(vcard);

      vcard.save(SparkManager.getConnection());

      // Notify users.
      if (avatarFile != null || avatarBytes != null) {
        Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence();
        Presence newPresence =
            new Presence(
                presence.getType(),
                presence.getStatus(),
                presence.getPriority(),
                presence.getMode());

        // Change my own presence
        SparkManager.getSessionManager().changePresence(newPresence);

        // Chnage avatar in status bar.
        StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
        statusBar.setAvatar(new ImageIcon(vcard.getAvatar()));
      } else {
        String firstName = vcard.getFirstName();
        String lastName = vcard.getLastName();
        StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
        if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
          statusBar.setNickname(firstName + " " + lastName);
        } else if (ModelUtil.hasLength(firstName)) {
          statusBar.setNickname(firstName);
        }

        statusBar.setAvatar(null);
      }

      // Notify listenres
      SparkManager.getVCardManager().notifyVCardListeners();
    } catch (XMPPException e) {
      Log.error(e);
      JOptionPane.showMessageDialog(
          SparkManager.getMainWindow(),
          Res.getString("message.vcard.not.supported"),
          Res.getString("title.error"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #4
0
  @Override
  public void initialize() {

    if (SystemTray.isSupported()) {

      JMenuItem openMenu = new JMenuItem(Res.getString("menuitem.open"));
      JMenuItem minimizeMenu = new JMenuItem(Res.getString("menuitem.hide"));
      JMenuItem exitMenu = new JMenuItem(Res.getString("menuitem.exit"));
      statusMenu = new JMenu(Res.getString("menuitem.status"));
      JMenuItem logoutMenu = new JMenuItem(Res.getString("menuitem.logout.no.status"));

      SystemTray tray = SystemTray.getSystemTray();
      SparkManager.getNativeManager().addNativeHandler(this);
      ChatManager.getInstance().addChatMessageHandler(chatMessageHandler);
      // XEP-0085 suport (replaces the obsolete XEP-0022)
      org.jivesoftware.smack.chat.ChatManager.getInstanceFor(SparkManager.getConnection())
          .addChatListener(this);

      if (Spark.isLinux()) {
        newMessageIcon = SparkRes.getImageIcon(SparkRes.MESSAGE_NEW_TRAY_LINUX);
        typingIcon = SparkRes.getImageIcon(SparkRes.TYPING_TRAY_LINUX);
      } else {
        newMessageIcon = SparkRes.getImageIcon(SparkRes.MESSAGE_NEW_TRAY);
        typingIcon = SparkRes.getImageIcon(SparkRes.TYPING_TRAY);
      }

      availableIcon = Default.getImageIcon(Default.TRAY_IMAGE);
      if (Spark.isLinux()) {
        if (availableIcon == null) {
          availableIcon = SparkRes.getImageIcon(SparkRes.TRAY_IMAGE_LINUX);
          Log.error(availableIcon.toString());
        }
        awayIcon = SparkRes.getImageIcon(SparkRes.TRAY_AWAY_LINUX);
        dndIcon = SparkRes.getImageIcon(SparkRes.TRAY_DND_LINUX);
        offlineIcon = SparkRes.getImageIcon(SparkRes.TRAY_OFFLINE_LINUX);
        connectingIcon = SparkRes.getImageIcon(SparkRes.TRAY_CONNECTING_LINUX);
      } else {
        if (availableIcon == null) {
          availableIcon = SparkRes.getImageIcon(SparkRes.TRAY_IMAGE);
        }
        awayIcon = SparkRes.getImageIcon(SparkRes.TRAY_AWAY);
        dndIcon = SparkRes.getImageIcon(SparkRes.TRAY_DND);
        offlineIcon = SparkRes.getImageIcon(SparkRes.TRAY_OFFLINE);
        connectingIcon = SparkRes.getImageIcon(SparkRes.TRAY_CONNECTING);
      }

      popupMenu.add(openMenu);
      openMenu.addActionListener(
          new AbstractAction() {

            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent event) {
              SparkManager.getMainWindow().setVisible(true);
              SparkManager.getMainWindow().toFront();
            }
          });
      popupMenu.add(minimizeMenu);
      minimizeMenu.addActionListener(
          new AbstractAction() {
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent event) {
              SparkManager.getMainWindow().setVisible(false);
            }
          });
      popupMenu.addSeparator();
      addStatusMessages();
      popupMenu.add(statusMenu);
      statusMenu.addActionListener(
          new AbstractAction() {
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent event) {}
          });

      if (Spark.isWindows()) {
        if (!Default.getBoolean("DISABLE_EXIT")) popupMenu.add(logoutMenu);

        logoutMenu.addActionListener(
            new AbstractAction() {
              private static final long serialVersionUID = 1L;

              @Override
              public void actionPerformed(ActionEvent e) {
                SparkManager.getMainWindow().logout(false);
              }
            });
      }
      // Exit Menu
      exitMenu.addActionListener(
          new AbstractAction() {
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
              SparkManager.getMainWindow().shutdown();
            }
          });
      if (!Default.getBoolean("DISABLE_EXIT")) popupMenu.add(exitMenu);

      /** If connection closed set offline tray image */
      SparkManager.getConnection()
          .addConnectionListener(
              new ConnectionListener() {

                @Override
                public void connected(XMPPConnection xmppConnection) {
                  trayIcon.setImage(availableIcon.getImage());
                }

                @Override
                public void authenticated(XMPPConnection xmppConnection, boolean b) {
                  trayIcon.setImage(availableIcon.getImage());
                }

                @Override
                public void connectionClosed() {
                  trayIcon.setImage(offlineIcon.getImage());
                }

                @Override
                public void connectionClosedOnError(Exception arg0) {
                  trayIcon.setImage(offlineIcon.getImage());
                }

                @Override
                public void reconnectingIn(int arg0) {
                  trayIcon.setImage(connectingIcon.getImage());
                }

                @Override
                public void reconnectionSuccessful() {
                  trayIcon.setImage(availableIcon.getImage());
                }

                @Override
                public void reconnectionFailed(Exception arg0) {
                  trayIcon.setImage(offlineIcon.getImage());
                }
              });

      SparkManager.getSessionManager()
          .addPresenceListener(
              presence -> {
                if (presence.getMode() == Presence.Mode.available) {
                  trayIcon.setImage(availableIcon.getImage());
                } else if (presence.getMode() == Presence.Mode.away
                    || presence.getMode() == Presence.Mode.xa) {
                  trayIcon.setImage(awayIcon.getImage());
                } else if (presence.getMode() == Presence.Mode.dnd) {
                  trayIcon.setImage(dndIcon.getImage());
                } else {
                  trayIcon.setImage(availableIcon.getImage());
                }
              });

      try {

        trayIcon =
            new TrayIcon(
                availableIcon.getImage(), Default.getString(Default.APPLICATION_NAME), null);
        trayIcon.setImageAutoSize(true);

        trayIcon.addMouseListener(
            new MouseListener() {

              @Override
              public void mouseClicked(MouseEvent event) {
                // if we are using double click on tray icon
                if ((!pref.isUsingSingleTrayClick()
                        && event.getButton() == MouseEvent.BUTTON1
                        && event.getClickCount() % 2 == 0)
                    ||
                    // if we using single click on tray icon
                    (pref.isUsingSingleTrayClick()
                        && event.getButton() == MouseEvent.BUTTON1
                        && event.getClickCount() == 1)) {

                  // bring the mainwindow to front
                  if ((SparkManager.getMainWindow().isVisible())
                      && (SparkManager.getMainWindow().getState() == java.awt.Frame.NORMAL)) {
                    SparkManager.getMainWindow().setVisible(false);
                  } else {
                    SparkManager.getMainWindow().setVisible(true);
                    SparkManager.getMainWindow().setState(java.awt.Frame.NORMAL);
                    SparkManager.getMainWindow().toFront();
                  }

                } else if (event.getButton() == MouseEvent.BUTTON1) {
                  SparkManager.getMainWindow().toFront();
                  // SparkManager.getMainWindow().requestFocus();
                } else if (event.getButton() == MouseEvent.BUTTON3) {

                  if (popupMenu.isVisible()) {
                    popupMenu.setVisible(false);
                  } else {

                    double x = MouseInfo.getPointerInfo().getLocation().getX();
                    double y = MouseInfo.getPointerInfo().getLocation().getY();

                    if (Spark.isMac()) {
                      popupMenu.setLocation((int) x, (int) y);
                    } else {
                      popupMenu.setLocation(event.getX(), event.getY());
                    }

                    popupMenu.setInvoker(popupMenu);
                    popupMenu.setVisible(true);
                  }
                }
              }

              @Override
              public void mouseEntered(MouseEvent event) {}

              @Override
              public void mouseExited(MouseEvent event) {}

              @Override
              public void mousePressed(MouseEvent event) {

                // on Mac i would want the window to show when i left-click the Icon
                if (Spark.isMac() && event.getButton() != MouseEvent.BUTTON3) {
                  SparkManager.getMainWindow().setVisible(false);
                  SparkManager.getMainWindow().setVisible(true);
                  SparkManager.getMainWindow().requestFocusInWindow();
                  SparkManager.getMainWindow().bringFrameIntoFocus();
                  SparkManager.getMainWindow().toFront();
                  SparkManager.getMainWindow().requestFocus();
                }
              }

              @Override
              public void mouseReleased(MouseEvent event) {}
            });

        tray.add(trayIcon);
      } catch (Exception e) {
        // Not Supported
      }
    } else {
      Log.error("Tray don't supports on this platform.");
    }
  }