Пример #1
0
  private View(ViewControl control) {
    mControl = control;

    WebLookAndFeel.install();

    ToolTipManager.sharedInstance().setInitialDelay(200);

    mContactListView = new ContactListView(this, ContactList.getInstance());
    ContactList.getInstance().addObserver(mContactListView);
    mChatListView = new ChatListView(this, ChatList.getInstance());
    ChatList.getInstance().addObserver(mChatListView);

    // chat view
    mChatView = new ChatView(this);
    ChatList.getInstance().addObserver(mChatView);

    // content area
    mContent = new Content(this, mChatView);

    // search panel
    mSearchPanel = new SearchPanel(new Table[] {mContactListView, mChatListView}, mChatView);

    // status bar
    WebStatusBar statusBar = new WebStatusBar();
    mStatusBarLabel = new WebStatusLabel(" ");
    statusBar.add(mStatusBarLabel);

    // main frame
    mMainFrame =
        new MainFrame(this, mContactListView, mChatListView, mContent, mSearchPanel, statusBar);
    mMainFrame.setVisible(true);

    // tray
    mTrayManager = new TrayManager(this, mMainFrame);
    ChatList.getInstance().addObserver(mTrayManager);

    // hotkeys
    this.setHotkeys();

    // notifier
    mNotifier = new Notifier(this);

    this.statusChanged();
  }
  public void onNotify(JID jid, String id) {
    Contact contact = ContactList.getInstance().get(jid).orElse(null);
    if (contact == null) {
      LOGGER.warning("can't find contact with jid:" + jid);
      return;
    }

    if (id.isEmpty()) {
      // contact disabled avatar publishing
      // TODO
    }

    Avatar avatar = contact.getAvatar().orElse(null);
    if (avatar != null && avatar.id.equals(id))
      // avatar is not new
      return;

    mClient.requestAvatar(jid, id);
  }
  public void onData(JID jid, String id, byte[] avatarData) {
    LOGGER.info("new avatar, jid: " + jid + " id: " + id);

    if (avatarData.length > MAX_SIZE) LOGGER.info("avatar data too long: " + avatarData.length);

    Contact contact = ContactList.getInstance().get(jid).orElse(null);
    if (contact == null) {
      LOGGER.warning("can't find contact with jid:" + jid);
      return;
    }

    if (!id.equals(DigestUtils.sha1Hex(avatarData))) {
      LOGGER.warning("this is not what we wanted");
      return;
    }

    BufferedImage img = MediaUtils.readImage(avatarData).orElse(null);
    if (img == null) return;

    contact.setAvatar(new Avatar(id, img));
  }