Beispiel #1
0
  public DialogPanel receiveIncomingMessage(
      Message message, BufferedImage myPhoto, BufferedImage friendPhoto, Mode mode) {
    if (mode == Mode.HOME_PANEL) {
      homeButton.setIcon(newDialogButIcon);
      PopUpMenu.displayMessage("You have new message from " + message.getNickname_From());
      homeButton.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
              homeButton.setIcon(newDialogButIconEntered);
            }

            @Override
            public void mouseExited(MouseEvent e) {
              homeButton.setIcon(newDialogButIcon);
            }
          });
    }

    for (int i = 0; i < dialogTabArrayList.size(); i++) {
      if (message.getNickname_From().equals(dialogTabArrayList.get(i).getNickButton().getText())) {
        if (dialogTabArrayList.get(i).equals(currentDialogTab)) {
          dialogPanelArrayList.get(i).showIncomingMessage(message);
        } else {
          dialogPanelArrayList.get(i).showIncomingMessage(message);
          dialogTabArrayList.get(i).getNewMessageLabel().setVisible(true);
        }
        return null;
      }
    }

    final DialogTab dialogTab = new DialogTab(message.getNickname_From());

    dialogTab.setBorder(new LineBorder(Color.WHITE));
    dialogTabArrayList.add(dialogTab);
    dialogTab.getNewMessageLabel().setVisible(true);
    final DialogPanel dialogPanel = new DialogPanel();
    try {
      dialogPanel.updateInfo(myPhoto, friendPhoto);
    } catch (IOException e) {
      e.printStackTrace();
    }
    dialogPanelArrayList.add(dialogPanel);

    repaintDialogTabsPanel();
    repaint();
    revalidate();

    dialogTab
        .getNickButton()
        .addActionListener(
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                for (int i = 0; i < dialogTabArrayList.size(); i++) {
                  dialogTabArrayList.get(i).setBorder(new LineBorder(Color.WHITE));
                }

                dialogTab.setBorder(new LineBorder(Color.RED));

                dialogTab.getNewMessageLabel().setVisible(false);

                currentDialogTab = dialogTab;

                if (!(currentDialogPanel == null)) currentDialogPanel.setVisible(false);
                currentDialogPanel = dialogPanel;
                currentDialogPanel.setBounds(0, 84, 960, 1000);
                bigPanel.add(currentDialogPanel);
                currentDialogPanel.setVisible(true);
                repaintDialogTabsPanel();
                repaint();
                revalidate();
              }
            });
    dialogPanel.showIncomingMessage(message);

    noConversationsPanel.setVisible(false);

    return dialogPanel;
  }
Beispiel #2
0
  public boolean startNewDialog(
      BufferedImage myPhoto, BufferedImage friendPhoto, String friendNick) {
    for (int i = 0; i < dialogTabArrayList.size(); i++) {
      if (dialogTabArrayList.get(i).getNickButton().getText().equals(friendNick)) {
        if (!(currentDialogPanel == null)) {
          currentDialogPanel.setVisible(false);
          currentDialogTab.setBorder(new LineBorder(Color.WHITE));
        }
        currentDialogPanel = dialogPanelArrayList.get(i);
        currentDialogTab = dialogTabArrayList.get(i);
        currentDialogTab.setBorder(new LineBorder(Color.RED));
        currentDialogTab.getNewMessageLabel().setVisible(false);
        currentDialogPanel.setBounds(0, 84, 960, 1000);
        bigPanel.add(currentDialogPanel);
        currentDialogPanel.setVisible(true);
        repaint();
        revalidate();
        return false;
      }
    }

    final DialogTab dialogTab = new DialogTab(friendNick);
    currentDialogTab = dialogTab;

    dialogTab.setBorder(new LineBorder(Color.RED));
    dialogTabArrayList.add(dialogTab);
    final DialogPanel dialogPanel = new DialogPanel();
    try {
      dialogPanel.updateInfo(myPhoto, friendPhoto);
    } catch (IOException e) {
      e.printStackTrace();
    }
    dialogPanelArrayList.add(dialogPanel);

    for (int i = 0; i < dialogTabArrayList.size() - 1; i++) {
      dialogTabArrayList.get(i).setBorder(new LineBorder(Color.WHITE));
    }

    if (!(currentDialogPanel == null)) currentDialogPanel.setVisible(false);
    currentDialogPanel = dialogPanel;
    currentDialogPanel.setBounds(0, 84, 960, 1000);
    bigPanel.add(currentDialogPanel);
    repaintDialogTabsPanel();
    repaint();
    revalidate();

    dialogTab
        .getNickButton()
        .addActionListener(
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                for (int i = 0; i < dialogTabArrayList.size(); i++) {
                  dialogTabArrayList.get(i).setBorder(new LineBorder(Color.WHITE));
                }

                dialogTab.setBorder(new LineBorder(Color.RED));

                dialogTab.getNewMessageLabel().setVisible(false);

                currentDialogTab = dialogTab;

                currentDialogPanel.setVisible(false);
                currentDialogPanel = dialogPanel;
                currentDialogPanel.setBounds(0, 84, 960, 1000);
                bigPanel.add(currentDialogPanel);
                currentDialogPanel.setVisible(true);
                repaintDialogTabsPanel();
                repaint();
                revalidate();
              }
            });

    noConversationsPanel.setVisible(false);

    return true;
  }