Example #1
0
 /**
  * Called to indicate a new chat state in this conversation.
  *
  * @param chatState being added.
  */
 public void newChatState(ChatState chatState) {
   LOG.debugf("Chat state update for {0} to {1}", chatFriend.getName(), chatState);
   if (currentChatState != chatState) {
     currentChatState = chatState;
     displayMessages();
   }
 }
  private void handleLinkClick(String linkDescription, URL url) {

    if (ChatDocumentBuilder.LIBRARY_LINK.equals(linkDescription)) {
      ChatFriend libraryChatFriend = conversation.getChatFriend();
      LOG.debugf("Opening a view to {0}'s library", libraryChatFriend.getName());
      //            libraryNavigator.selectFriendLibrary(libraryChatFriend.getFriend());
      throw new IllegalStateException("action does't exist");

    } else if (ChatDocumentBuilder.MY_LIBRARY_LINK.equals(linkDescription)) {
      LOG.debugf("Opening a view to my library");
      //            libraryNavigator.selectLibrary();
      throw new IllegalStateException("action does't exist");
    } else {
      LOG.debugf("Hyperlink clicked: {0}", linkDescription);
      if (linkDescription.startsWith("magnet")) {
        // TODO: Need to do something with magnet links

      } else if (url != null) {
        NativeLaunchUtils.openURL(url.toString());
      }
    }
  }
Example #3
0
  @Inject
  public ConversationPane(
      @Assisted MessageWriter writer,
      final @Assisted ChatFriend chatFriend,
      Provider<IconManager> iconManager,
      ChatHyperlinkListenerFactory chatHyperlinkListenerFactory,
      CloseChatMessage closeChatMessage,
      FriendPresenceActions remoteHostActions,
      @Named("backgroundExecutor") ScheduledExecutorService schedExecService,
      EventBroadcaster<ChatMessageEvent> messageBroadcaster) {
    this.writer = writer;
    this.chatFriend = chatFriend;
    this.conversationName = chatFriend.getName();
    this.friendId = chatFriend.getID();
    this.iconManager = iconManager;
    this.noSaveState = null;
    this.remoteHostActions = remoteHostActions;
    this.messageBroadcaster = messageBroadcaster;

    GuiUtils.assignResources(this);

    setLayout(new BorderLayout());

    editor = new JEditorPane();
    editor.setEditable(false);
    editor.setContentType("text/html");
    editor.setBorder(BorderFactory.createEmptyBorder(PADDING, PADDING, PADDING, PADDING));
    HTMLEditorKit editorKit = (HTMLEditorKit) editor.getEditorKit();
    editorKit.setAutoFormSubmission(false);

    conversationScroll =
        new JScrollPane(
            editor,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    conversationScroll.setOpaque(false);
    conversationScroll.setBorder(BorderFactory.createEmptyBorder());

    final JButton closeConversation = new IconButton(closeChatMessage);
    closeConversation.setIcon(endChat);

    chatWrapper = new JPanel();
    chatWrapper.setLayout(new OverlayLayout(chatWrapper));

    JPanel closePanel = new JPanel();
    closePanel.setLayout(null);
    closePanel.setOpaque(false);
    final Rectangle closeBounds = new Rectangle(268, 5, 6, 6);
    final Rectangle closeBoundsSlider = new Rectangle(250, 5, 6, 6);
    closeConversation.setBounds(closeBounds);
    closePanel.add(closeConversation);

    JPanel conversationPanel = new JPanel(new BorderLayout());
    conversationPanel.setOpaque(false);
    conversationPanel.add(conversationScroll, BorderLayout.CENTER);

    chatWrapper.add(closePanel);
    chatWrapper.add(conversationPanel);

    conversationScroll
        .getVerticalScrollBar()
        .addComponentListener(
            new ComponentListener() {
              @Override
              public void componentHidden(ComponentEvent e) {
                closeConversation.setBounds(closeBounds);
              }

              @Override
              public void componentMoved(ComponentEvent e) {}

              @Override
              public void componentResized(ComponentEvent e) {}

              @Override
              public void componentShown(ComponentEvent e) {
                closeConversation.setBounds(closeBoundsSlider);
              }
            });

    AdjustmentListener adjustmentListener =
        new AdjustmentListener() {
          @Override
          public void adjustmentValueChanged(AdjustmentEvent e) {
            chatWrapper.repaint();
          }
        };

    conversationScroll.getVerticalScrollBar().addAdjustmentListener(adjustmentListener);
    conversationScroll.getHorizontalScrollBar().addAdjustmentListener(adjustmentListener);

    add(chatWrapper, BorderLayout.CENTER);

    PopupUtil.addPopupMenus(editor, new CopyAction(editor), new CopyAllAction());

    add(footerPanel(writer, chatFriend, schedExecService), BorderLayout.SOUTH);

    setBackground(DEFAULT_BACKGROUND);

    editor.addHyperlinkListener(chatHyperlinkListenerFactory.create(this));
  }