Beispiel #1
0
  /**
   * Prepares Spark for shutting down by first calling all {@link MainWindowListener}s and setting
   * the Agent to be offline.
   *
   * @param sendStatus true if Spark should send a presence with a status message.
   */
  public void logout(boolean sendStatus) {
    final XMPPConnection con = SparkManager.getConnection();
    String status = null;

    if (con.isConnected() && sendStatus) {
      final InputTextAreaDialog inputTextDialog = new InputTextAreaDialog();
      status =
          inputTextDialog.getInput(
              Res.getString("title.status.message"),
              Res.getString("message.current.status"),
              SparkRes.getImageIcon(SparkRes.USER1_MESSAGE_24x24),
              this);
    }

    if (status != null || !sendStatus) {
      // Notify all MainWindowListeners
      try {
        // Set auto-login to false;
        SettingsManager.getLocalPreferences().setAutoLogin(false);
        SettingsManager.saveSettings();

        fireWindowShutdown();
        setVisible(false);
      } finally {
        closeConnectionAndInvoke(status);
      }
    }
  }
Beispiel #2
0
  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);
    }
  }
Beispiel #3
0
 /**
  * Return true if the MainWindow is docked.
  *
  * @return true if the window is docked.
  */
 public boolean isDocked() {
   LocalPreferences preferences = SettingsManager.getLocalPreferences();
   return preferences.isDockingEnabled();
 }
Beispiel #4
0
  /** Setup the Main Toolbar with File, Tools and Help. */
  private void buildMenu() {

    // setup file menu
    final JMenuItem exitMenuItem = new JMenuItem();

    // Setup ResourceUtils
    ResourceUtils.resButton(connectMenu, "&" + Default.getString(Default.APPLICATION_NAME));
    ResourceUtils.resButton(contactsMenu, Res.getString("menuitem.contacts"));
    ResourceUtils.resButton(actionsMenu, Res.getString("menuitem.actions"));
    ResourceUtils.resButton(exitMenuItem, Res.getString("menuitem.exit"));
    ResourceUtils.resButton(pluginsMenu, Res.getString("menuitem.plugins"));

    exitMenuItem.setIcon(null);

    mainWindowBar.add(connectMenu);
    mainWindowBar.add(contactsMenu);
    mainWindowBar.add(actionsMenu);
    // mainWindowBar.add(pluginsMenu);
    mainWindowBar.add(helpMenu);

    preferenceMenuItem = new JMenuItem(SparkRes.getImageIcon(SparkRes.PREFERENCES_IMAGE));
    preferenceMenuItem.setText(Res.getString("title.spark.preferences"));
    preferenceMenuItem.addActionListener(this);
    connectMenu.add(preferenceMenuItem);

    alwaysOnTopItem = new JCheckBoxMenuItem();
    ResourceUtils.resButton(alwaysOnTopItem, Res.getString("menuitem.always.on.top"));
    alwaysOnTopItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (alwaysOnTopItem.isSelected()) {
              SettingsManager.getLocalPreferences().setMainWindowAlwaysOnTop(true);
              MainWindow.getInstance().setAlwaysOnTop(true);
            } else {
              SettingsManager.getLocalPreferences().setMainWindowAlwaysOnTop(false);
              MainWindow.getInstance().setAlwaysOnTop(false);
            }
          }
        });

    if (SettingsManager.getLocalPreferences().isMainWindowAlwaysOnTop()) {
      alwaysOnTopItem.setSelected(true);
      this.setAlwaysOnTop(true);
    }
    connectMenu.add(alwaysOnTopItem);

    if (!Default.getBoolean("DISABLE_EXIT")) connectMenu.addSeparator();

    // EventQueue.invokeLater(new Runnable() {
    //	public void run() {

    JMenuItem logoutMenuItem = new JMenuItem();
    ResourceUtils.resButton(logoutMenuItem, Res.getString("menuitem.logout.no.status"));
    logoutMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            logout(false);
          }
        });

    JMenuItem logoutWithStatus = new JMenuItem();
    ResourceUtils.resButton(logoutWithStatus, Res.getString("menuitem.logout.with.status"));
    logoutWithStatus.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            logout(true);
          }
        });

    if ((Spark.isWindows() || Spark.isLinux() || Spark.isMac())
        && !Default.getBoolean("DISABLE_EXIT")) {
      connectMenu.add(logoutMenuItem);
      connectMenu.add(logoutWithStatus);
      connectMenu.addSeparator();
    }

    if (!Default.getBoolean("DISABLE_EXIT")) {
      connectMenu.add(exitMenuItem);
    }

    JMenuItem updateMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.DOWNLOAD_16x16));
    ResourceUtils.resButton(updateMenu, Res.getString("menuitem.check.for.updates"));
    updateMenu.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            checkForUpdates(true);
          }
        });

    // Add Error Dialog Viewer
    final Action viewErrors =
        new AbstractAction() {
          private static final long serialVersionUID = -420926784631340112L;

          public void actionPerformed(ActionEvent e) {
            File logDir = new File(Spark.getLogDirectory(), "errors.log");
            if (!logDir.exists()) {
              JOptionPane.showMessageDialog(
                  SparkManager.getMainWindow(),
                  "No error logs found.",
                  "Error Log",
                  JOptionPane.INFORMATION_MESSAGE);
            } else {
              showErrorLog();
            }
          }
        };

    viewErrors.putValue(Action.NAME, Res.getString("menuitem.view.logs"));

    final Action viewHelpGuideAction =
        new AbstractAction() {

          final String url = Default.getString(Default.HELP_USER_GUIDE);
          private static final long serialVersionUID = 2680369963282231348L;

          public void actionPerformed(ActionEvent actionEvent) {
            try {

              BrowserLauncher.openURL(url);
            } catch (Exception e) {
              Log.error("Unable to load online help.", e);
            }
          }
        };

    if (!Default.getBoolean("HELP_USER_GUIDE_DISABLED")) {
      viewHelpGuideAction.putValue(Action.NAME, Res.getString("menuitem.user.guide"));
      viewHelpGuideAction.putValue(
          Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
      helpMenu.add(viewHelpGuideAction);
    }
    if (!Default.getBoolean("HELP_FORUM_DISABLED")) {
      helpMenu.add(sparkforumItem);
    }

    // Build Help Menu
    if (!Default.getBoolean(Default.DISABLE_UPDATES)) {
      helpMenu.add(updateMenu);
    }
    helpMenu.addSeparator();
    helpMenu.add(viewErrors);
    helpMenu.add(menuAbout);

    // ResourceUtils - Adds mnemonics
    ResourceUtils.resButton(preferenceMenuItem, Res.getString("menuitem.preferences"));
    ResourceUtils.resButton(helpMenu, Res.getString("menuitem.help"));
    ResourceUtils.resButton(menuAbout, Res.getString("menuitem.about"));

    if (Default.getString("HELP_FORUM_TEXT").length() > 0) {
      ResourceUtils.resButton(sparkforumItem, Default.getString("HELP_FORUM_TEXT"));
    } else {
      ResourceUtils.resButton(sparkforumItem, Res.getString("menuitem.online.help"));
    }
    // Register shutdown with the exit menu.
    exitMenuItem.addActionListener(
        new AbstractAction() {
          private static final long serialVersionUID = -2301236575241532698L;

          public void actionPerformed(ActionEvent e) {
            shutdown();
          }
        });

    sparkforumItem.addActionListener(
        new AbstractAction() {
          private static final long serialVersionUID = -1423433460333010339L;

          final String url = Default.getString("HELP_FORUM");

          public void actionPerformed(ActionEvent e) {
            try {
              BrowserLauncher.openURL(url);
            } catch (Exception browserException) {
              Log.error("Error launching browser:", browserException);
            }
          }
        });

    // Show About Box
    menuAbout.addActionListener(
        new AbstractAction() {
          private static final long serialVersionUID = -7173666373051354502L;

          public void actionPerformed(ActionEvent e) {
            showAboutBox();
          }
        });

    if (!Default.getBoolean("DISABLE_UPDATES")) {
      // Execute spark update checker after one minute.
      final TimerTask task =
          new SwingTimerTask() {
            public void doRun() {
              checkForUpdates(false);
            }
          };

      TaskEngine.getInstance().schedule(task, 60000);
    }

    if (SettingsManager.getLocalPreferences().isDebuggerEnabled()) {
      JMenuItem rawPackets = new JMenuItem(SparkRes.getImageIcon(SparkRes.TRAY_IMAGE));
      rawPackets.setText("Send Packets");
      rawPackets.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              new RawPacketSender();
            }
          });

      connectMenu.add(rawPackets, 2);
    }
  }
  /**
   * Fired when call state changes
   *
   * @param evt CallStateEvent
   */
  public void callStateChanged(CallStateEvent evt) {
    try {

      for (SoftPhoneListener sfl : softPhoneListeners) {
        sfl.callStateChanged(evt);
      }

      Call call = evt.getSourceCall();
      Log.debug("callStateChanged", evt.getOldState() + " -> " + evt.getNewState());
      if (evt.getNewState() == Call.CONNECTED) {
        // sipManager.setBusy(true);

        if (call.getAudioReceiverChannel() != null) call.getAudioReceiverChannel().stop();

        if (evt.getOldState() == Call.MOVING_REMOTELY) {
          AudioMediaSession audioMediaSession = evt.getSourceCall().getAudioMediaSession();
          if (call.getAudioReceiverChannel() != null) call.getAudioReceiverChannel().stop();

          if (audioMediaSession != null) {
            audioMediaSession.stopTrasmit();
            audioMediaSession.stopReceive();
          }
          VideoMediaSession videoMediaSession = evt.getSourceCall().getVideoMediaSession();
          if (videoMediaSession != null) {
            videoMediaSession.stopTrasmit();
            videoMediaSession.stopReceive();
          }
          PhoneManager.setUsingMediaLocator(false);
        }

        int localAudioPort = -1;
        int localVideoPort = -1;

        Vector<MediaDescription> mediaDescriptions =
            call.getLocalSdpDescription().getMediaDescriptions(true);
        for (MediaDescription mediaDescription : mediaDescriptions) {
          if (mediaDescription.getMedia().getMediaType().equals("audio"))
            localAudioPort = mediaDescription.getMedia().getMediaPort();
          else if (mediaDescription.getMedia().getMediaType().equals("video"))
            localVideoPort = mediaDescription.getMedia().getMediaPort();
        }

        AudioMediaSession audioMediaSession =
            mediaManager.createAudioMediaSession(
                call.getRemoteSdpDescription().toString(), localAudioPort);
        call.setAudioMediaSession(audioMediaSession);

        if (audioMediaSession != null) {
          audioMediaSession.startTrasmit();
          audioMediaSession.startReceive();
        }

        // If remote client have video
        if (localVideoPort > 0) {
          if (SettingsManager.getLocalPreferences().getVideoDevice() != null
              && !"".equals(SettingsManager.getLocalPreferences().getVideoDevice())) {
            VideoMediaSession videoMediaSession =
                mediaManager.createVideoMediaSession(
                    call.getRemoteSdpDescription().toString(), localVideoPort);
            if (videoMediaSession != null) {
              videoMediaSession.startTrasmit();
              videoMediaSession.startReceive();
              call.setVideoMediaSession(videoMediaSession);
            }
          }
        }

        evt.getSourceCall().start();

        Log.debug("MEDIA STREAMS OPENED");

      } else if (evt.getNewState() == Call.RINGING) {

        if (call.getRemoteSdpDescription() != null && !call.getRemoteSdpDescription().equals("")) {

          Log.debug("STATE", call.getRemoteSdpDescription().toString());

          int localPort =
              ((MediaDescription) (call.getLocalSdpDescription().getMediaDescriptions(true).get(0)))
                  .getMedia()
                  .getMediaPort();
          int destPort =
              ((MediaDescription)
                      (call.getRemoteSdpDescription().getMediaDescriptions(true).get(0)))
                  .getMedia()
                  .getMediaPort();
          String destIp = call.getRemoteSdpDescription().getConnection().getAddress();

          AudioReceiverChannel audioReceiverChannel =
              mediaManager.createAudioReceiverChannel(localPort, destIp, destPort, (destPort + 1));
          call.setAudioReceiverChannel(audioReceiverChannel);

          if (audioReceiverChannel != null) audioReceiverChannel.start();
        }

      } else if (evt.getNewState() == Call.DISCONNECTED) {
        sipManager.setBusy(false);

        AudioMediaSession audioMediaSession = evt.getSourceCall().getAudioMediaSession();
        if (audioMediaSession != null) {
          audioMediaSession.stopTrasmit();
          audioMediaSession.stopReceive();
        }
        if (call.getAudioReceiverChannel() != null) call.getAudioReceiverChannel().stop();
        VideoMediaSession videoMediaSession = evt.getSourceCall().getVideoMediaSession();
        if (videoMediaSession != null) {
          videoMediaSession.stopTrasmit();
          videoMediaSession.stopReceive();
        }

        PhoneManager.setUsingMediaLocator(false);

      } else if (evt.getNewState() == Call.FAILED) {
        call.setState(Call.DISCONNECTED);
        if (call.getAudioReceiverChannel() != null) call.getAudioReceiverChannel().stop();

        CallRejectedEvent rejectEvt =
            new CallRejectedEvent("Disconnected", call.getLastRequest(), call);

        for (SoftPhoneListener softPhoneListener : softPhoneListeners) {
          softPhoneListener.callRejectedRemotely(rejectEvt);
        }

        PhoneManager.setUsingMediaLocator(false);
      }
    } catch (Exception e) {
      Log.error("callStateChanged", e);
    }
  }
/**
 * Allows users to place activity listeners on individual users. This class notifies users when
 * other users come from away or offline to available.
 *
 * @author Derek DeMoro
 */
public class PresenceChangePlugin implements Plugin {

  private final Set<String> sparkContacts = new HashSet<String>();
  private LocalPreferences localPref = SettingsManager.getLocalPreferences();

  public void initialize() {
    // Listen for right-clicks on ContactItem
    final ContactList contactList = SparkManager.getWorkspace().getContactList();

    final Action listenAction =
        new AbstractAction() {
          private static final long serialVersionUID = 7705539667621148816L;

          public void actionPerformed(ActionEvent e) {

            for (ContactItem item : contactList.getSelectedUsers()) {
              String bareAddress = StringUtils.parseBareAddress(item.getJID());
              sparkContacts.add(bareAddress);
            }
          }
        };

    listenAction.putValue(Action.NAME, Res.getString("menuitem.alert.when.online"));
    listenAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_ALARM_CLOCK));

    final Action removeAction =
        new AbstractAction() {
          private static final long serialVersionUID = -8726129089417116105L;

          public void actionPerformed(ActionEvent e) {

            for (ContactItem item : contactList.getSelectedUsers()) {
              String bareAddress = StringUtils.parseBareAddress(item.getJID());
              sparkContacts.remove(bareAddress);
            }
          }
        };

    removeAction.putValue(Action.NAME, Res.getString("menuitem.remove.alert.when.online"));
    removeAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DELETE));

    contactList.addContextMenuListener(
        new ContextMenuListener() {
          public void poppingUp(Object object, JPopupMenu popup) {
            if (object instanceof ContactItem) {
              ContactItem item = (ContactItem) object;
              String bareAddress = StringUtils.parseBareAddress(item.getJID());
              if (!item.getPresence().isAvailable() || item.getPresence().isAway()) {
                if (sparkContacts.contains(bareAddress)) {
                  popup.add(removeAction);
                } else {
                  popup.add(listenAction);
                }
              }
            }
          }

          public void poppingDown(JPopupMenu popup) {}

          public boolean handleDefaultAction(MouseEvent e) {
            return false;
          }
        });

    // Check presence changes
    SparkManager.getConnection()
        .addPacketListener(
            new PacketListener() {
              public void processPacket(final Packet packet) {
                try {
                  EventQueue.invokeAndWait(
                      new Runnable() {
                        public void run() {
                          Presence presence = (Presence) packet;
                          if (!presence.isAvailable() || presence.isAway()) {
                            return;
                          }
                          String from = presence.getFrom();

                          ArrayList<String> removelater = new ArrayList<String>();

                          for (final String jid : sparkContacts) {
                            if (jid.equals(StringUtils.parseBareAddress(from))) {
                              removelater.add(jid);
                              // sparkContacts.remove(jid);

                              String nickname =
                                  SparkManager.getUserManager().getUserNicknameFromJID(jid);
                              String time = SparkManager.DATE_SECOND_FORMATTER.format(new Date());
                              String infoText =
                                  Res.getString(
                                      "message.user.now.available.to.chat", nickname, time);

                              if (localPref.getShowToasterPopup()) {
                                SparkToaster toaster = new SparkToaster();
                                toaster.setDisplayTime(5000);
                                toaster.setBorder(BorderFactory.createBevelBorder(0));

                                toaster.setToasterHeight(150);
                                toaster.setToasterWidth(200);

                                toaster.setTitle(nickname);
                                toaster.showToaster(null, infoText);

                                toaster.setCustomAction(
                                    new AbstractAction() {
                                      private static final long serialVersionUID =
                                          4827542713848133369L;

                                      @Override
                                      public void actionPerformed(ActionEvent e) {
                                        SparkManager.getChatManager().getChatRoom(jid);
                                      }
                                    });
                              }

                              ChatRoom room = SparkManager.getChatManager().getChatRoom(jid);

                              if (localPref.getWindowTakesFocus()) {
                                SparkManager.getChatManager().activateChat(jid, nickname);
                              }

                              room.getTranscriptWindow()
                                  .insertNotificationMessage(
                                      infoText, ChatManager.NOTIFICATION_COLOR);
                            }
                          }
                          for (String s : removelater) {
                            sparkContacts.remove(s);
                          }
                        }
                      });
                } catch (Exception ex) {
                  ex.printStackTrace();
                }
              }
            },
            new PacketTypeFilter(Presence.class));
  }

  public void shutdown() {}

  public boolean canShutDown() {
    return true;
  }

  public void uninstall() {
    // Do nothing.
  }

  public void addWatch(String user) {
    String bareAddress = StringUtils.parseBareAddress(user);
    sparkContacts.add(bareAddress);
  }

  public void removeWatch(String user) {
    String bareAddress = StringUtils.parseBareAddress(user);
    sparkContacts.remove(bareAddress);
  }

  public boolean getWatched(String user) {
    String bareAddress = StringUtils.parseBareAddress(user);
    return sparkContacts.contains(bareAddress);
  }
}
public class SysTrayPlugin
    implements Plugin, NativeHandler, ChatManagerListener, ChatStateListener {
  private JPopupMenu popupMenu = new JPopupMenu();

  private JMenu statusMenu;

  private LocalPreferences pref = SettingsManager.getLocalPreferences();
  private ImageIcon availableIcon;
  private ImageIcon dndIcon;
  private ImageIcon awayIcon;
  private ImageIcon offlineIcon;
  private ImageIcon connectingIcon;
  private ImageIcon newMessageIcon;
  private ImageIcon typingIcon;
  private TrayIcon trayIcon;
  private boolean newMessage = false;
  ChatMessageHandlerImpl chatMessageHandler = new ChatMessageHandlerImpl();

  @Override
  public boolean canShutDown() {
    return true;
  }

  @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.");
    }
  }

  public void addStatusMessages() {
    StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
    for (Object o : statusBar.getStatusList()) {
      final StatusItem statusItem = (StatusItem) o;

      final AbstractAction action =
          new AbstractAction() {
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {

              StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();

              SparkManager.getSessionManager().changePresence(statusItem.getPresence());
              statusBar.setStatus(statusItem.getText());
            }
          };
      action.putValue(Action.NAME, statusItem.getText());
      action.putValue(Action.SMALL_ICON, statusItem.getIcon());

      boolean hasChildren = false;
      for (Object aCustom : SparkManager.getWorkspace().getStatusBar().getCustomStatusList()) {
        final CustomStatusItem cItem = (CustomStatusItem) aCustom;
        String type = cItem.getType();
        if (type.equals(statusItem.getText())) {
          hasChildren = true;
        }
      }

      if (!hasChildren) {
        JMenuItem status = new JMenuItem(action);
        statusMenu.add(status);
      } else {
        final JMenu status = new JMenu(action);
        statusMenu.add(status);

        status.addMouseListener(
            new MouseAdapter() {
              @Override
              public void mouseClicked(MouseEvent mouseEvent) {
                action.actionPerformed(null);
                popupMenu.setVisible(false);
              }
            });

        for (Object aCustom : SparkManager.getWorkspace().getStatusBar().getCustomStatusList()) {
          final CustomStatusItem customItem = (CustomStatusItem) aCustom;
          String type = customItem.getType();
          if (type.equals(statusItem.getText())) {
            AbstractAction customAction =
                new AbstractAction() {
                  private static final long serialVersionUID = 1L;

                  @Override
                  public void actionPerformed(ActionEvent e) {
                    StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();

                    Presence oldPresence = statusItem.getPresence();
                    Presence presence = StatusBar.copyPresence(oldPresence);
                    presence.setStatus(customItem.getStatus());
                    presence.setPriority(customItem.getPriority());
                    SparkManager.getSessionManager().changePresence(presence);

                    statusBar.setStatus(statusItem.getName() + " - " + customItem.getStatus());
                  }
                };
            customAction.putValue(Action.NAME, customItem.getStatus());
            customAction.putValue(Action.SMALL_ICON, statusItem.getIcon());
            JMenuItem menuItem = new JMenuItem(customAction);
            status.add(menuItem);
          }
        }
      }
    }
  }

  @Override
  public void shutdown() {
    if (SystemTray.isSupported()) {
      SystemTray tray = SystemTray.getSystemTray();
      tray.remove(trayIcon);
    }
    ChatManager.getInstance().removeChatMessageHandler(chatMessageHandler);
  }

  @Override
  public void uninstall() {
    ChatManager.getInstance().removeChatMessageHandler(chatMessageHandler);
  }

  // Info on new Messages
  @Override
  public void flashWindow(Window window) {
    if (pref.isSystemTrayNotificationEnabled()) {
      trayIcon.setImage(newMessageIcon.getImage());
      if (window instanceof JFrame) {
        ((JFrame) window)
            .setTitle(
                getCounteredTitle(
                    ((JFrame) window).getTitle(), chatMessageHandler.getUnreadMessages()));
      }
      newMessage = true;
    }
  }

  private String getCounteredTitle(String title, int counter) {
    String stringCounter = String.format("[%s] ", counter);
    String MESSAGE_COUNTER_REG_EXP = "\\[\\d+\\] ";
    return counter > 0
        ? stringCounter + title.replaceFirst(MESSAGE_COUNTER_REG_EXP, "")
        : title.replaceFirst(MESSAGE_COUNTER_REG_EXP, "");
  }

  @Override
  public void flashWindowStopWhenFocused(Window window) {
    trayIcon.setImage(availableIcon.getImage());
    newMessage = false;
    chatMessageHandler.clearUnreadMessages();
  }

  @Override
  public boolean handleNotification() {
    return true;
  }

  @Override
  public void stopFlashing(Window window) {
    trayIcon.setImage(availableIcon.getImage());
    newMessage = false;
    chatMessageHandler.clearUnreadMessages();
  }

  // For Typing
  @Override
  public void processMessage(Chat arg0, Message arg1) {
    // Do nothing - stateChanged is in charge

  }

  @Override
  public void stateChanged(Chat chat, ChatState state) {
    if (ChatState.composing.equals(state)) {
      changeSysTrayIcon();
    } else {
      if (!newMessage) trayIcon.setImage(availableIcon.getImage());
      else {
        trayIcon.setImage(newMessageIcon.getImage());
      }
    }
  }

  @Override
  public void chatCreated(Chat chat, boolean isLocal) {
    chat.addMessageListener(this);
  }

  private void changeSysTrayIcon() {
    if (pref.isTypingNotificationShown()) {
      trayIcon.setImage(typingIcon.getImage());
    }
  }
}
Beispiel #8
0
  /**
   * Creates a new instance of a contact.
   *
   * @param alias the alias of the contact
   * @param nickname the nickname of the contact.
   * @param fullyQualifiedJID the fully-qualified jid of the contact (ex. [email protected])
   */
  public ContactItem(String alias, String nickname, String fullyQualifiedJID, boolean initUi) {
    setLayout(new GridBagLayout());

    // Set Default Font
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    fontSize = pref.getContactListFontSize();
    iconSize = pref.getContactListIconSize();
    avatarsShowing = pref.areAvatarsVisible();

    // Set default presence
    presence = new Presence(Presence.Type.unavailable);

    contactsDir = new File(SparkManager.getUserDirectory(), "contacts");

    this.alias = alias;
    this.nickname = nickname;
    this.fullyQualifiedJID = fullyQualifiedJID;

    if (initUi) {
      displayNameLabel = new JLabel();
      descriptionLabel = new JLabel();
      imageLabel = new JLabel();
      specialImageLabel = new JLabel();
      sideIcon = new JLabel();
      if (avatarsShowing) {
        sideIcon.setMinimumSize(new Dimension(iconSize, iconSize));
        sideIcon.setMaximumSize(new Dimension(iconSize, iconSize));
        sideIcon.setPreferredSize(new Dimension(iconSize, iconSize));
      }

      displayNameLabel.setHorizontalTextPosition(JLabel.LEFT);
      displayNameLabel.setHorizontalAlignment(JLabel.LEFT);
      // displayNameLabel.setText(nickname);

      descriptionLabel.setFont(new Font("Dialog", Font.PLAIN, fontSize));
      descriptionLabel.setForeground((Color) UIManager.get("ContactItemDescription.foreground"));
      descriptionLabel.setHorizontalTextPosition(JLabel.LEFT);
      descriptionLabel.setHorizontalAlignment(JLabel.LEFT);

      this.setOpaque(true);

      add(
          imageLabel,
          new GridBagConstraints(
              0,
              0,
              1,
              2,
              0.0,
              0.0,
              GridBagConstraints.NORTH,
              GridBagConstraints.HORIZONTAL,
              new Insets(0, 15, 0, 0),
              0,
              0));
      add(
          displayNameLabel,
          new GridBagConstraints(
              1,
              0,
              1,
              1,
              0.0,
              0.0,
              GridBagConstraints.WEST,
              GridBagConstraints.HORIZONTAL,
              new Insets(0, 5, 0, 0),
              0,
              0));
      add(
          descriptionLabel,
          new GridBagConstraints(
              2,
              0,
              1,
              1,
              1.0,
              0.0,
              GridBagConstraints.WEST,
              GridBagConstraints.HORIZONTAL,
              new Insets(0, 5, 2, 0),
              0,
              0));
      add(
          specialImageLabel,
          new GridBagConstraints(
              3,
              0,
              1,
              2,
              0.0,
              0.0,
              GridBagConstraints.WEST,
              GridBagConstraints.HORIZONTAL,
              new Insets(0, 5, 0, 0),
              0,
              0));
      add(
          sideIcon,
          new GridBagConstraints(
              4,
              0,
              1,
              2,
              0.0,
              0.0,
              GridBagConstraints.WEST,
              GridBagConstraints.HORIZONTAL,
              new Insets(0, 5, 0, 0),
              0,
              0));

      setDisplayName();
    }
  }
Beispiel #9
0
  /**
   * Updates the icon of the user based on their presence.
   *
   * @param presence the users presence.
   */
  public void updatePresenceIcon(Presence presence) {
    ChatManager chatManager = SparkManager.getChatManager();
    boolean handled = chatManager.fireContactItemPresenceChanged(this, presence);
    if (handled) {
      return;
    }

    String status = presence.getStatus();
    Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
    boolean isAvailable = false;
    if (status == null && presence.isAvailable()) {
      Presence.Mode mode = presence.getMode();
      if (mode == Presence.Mode.available) {
        status = Res.getString("status.online");
        isAvailable = true;
      } else if (mode == Presence.Mode.away) {
        status = Res.getString("status.away");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      } else if (mode == Presence.Mode.chat) {
        status = Res.getString("status.free.to.chat");
      } else if (mode == Presence.Mode.dnd) {
        status = Res.getString("status.do.not.disturb");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      } else if (mode == Presence.Mode.xa) {
        status = Res.getString("status.extended.away");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      }
    }

    if (presence.isAvailable()
        && (presence.getMode() == Presence.Mode.dnd
            || presence.getMode() == Presence.Mode.away
            || presence.getMode() == Presence.Mode.xa)) {
      statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
    } else if (presence.isAvailable()) {
      isAvailable = true;
    } else if (!presence.isAvailable()) {
      getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
      getNicknameLabel().setForeground((Color) UIManager.get("ContactItemOffline.color"));

      RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getJID());
      if (entry != null
          && (entry.getType() == RosterPacket.ItemType.none
              || entry.getType() == RosterPacket.ItemType.from)
          && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
        // Do not move out of group.
        setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        setStatusText(Res.getString("status.pending"));
      } else {
        // We should keep the offline bullet (not available) instead of putting icon null.
        setIcon(SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON));
        setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        setAvailable(false);
        if (ModelUtil.hasLength(status)) {
          setStatusText(status);
        } else {
          setStatusText("");
        }
      }

      sideIcon.setIcon(null);
      setAvailable(false);
      return;
    }

    Icon sIcon = PresenceManager.getIconFromPresence(presence);
    if (sIcon != null) {
      setIcon(sIcon);
    } else {
      setIcon(statusIcon);
    }
    if (status != null) {
      setStatus(status);
    }

    if (PresenceManager.isOnPhone(presence)) {
      statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE);
      setIcon(statusIcon);
    }

    // Always change nickname label to black.
    getNicknameLabel().setForeground((Color) UIManager.get("ContactItemNickname.foreground"));

    if (isAvailable) {
      getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
      if (Res.getString("status.online").equals(status)
          || Res.getString("available").equalsIgnoreCase(status)) {
        setStatusText("");
      } else {
        setStatusText(status);
      }
    } else if (presence.isAvailable()) {
      LocalPreferences pref = SettingsManager.getLocalPreferences();
      if (pref.isGrayingOutEnabled()) {
        getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, fontSize));
        getNicknameLabel().setForeground(Color.gray);
      } else {
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setForeground(Color.black);
      }
      if (status != null) {
        setStatusText(status);
      }
    }

    setAvailable(true);
  }
  private void createUI() {
    setLayout(new VerticalFlowLayout());
    timeFormat.add(format24);
    timeFormat.add(format12);
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    if (pref.getTimeFormat().equals("HH:mm")) {
      format24.setSelected(true);
    } else {
      format12.setSelected(true);
    }
    // Setup Mnemonics
    ResourceUtils.resButton(showTimeBox, Res.getString("checkbox.show.time.in.chat.window"));
    ResourceUtils.resLabel(
        passwordLabel, passwordField, Res.getString("label.change.password.to") + ":");
    ResourceUtils.resLabel(
        confirmationPasswordLabel,
        confirmationPasswordField,
        Res.getString("label.confirm.password") + ":");
    ResourceUtils.resButton(
        groupChatNotificationBox, Res.getString("checkbox.show.notifications.in.conference"));
    ResourceUtils.resButton(hideChatHistory, Res.getString("checkbox.disable.chat.history"));
    ResourceUtils.resButton(
        hidePrevChatHistory, Res.getString("checkbox.disable.prev.chat.history"));
    ResourceUtils.resButton(tabsOnTopBox, Res.getString("checkbox.tabs.on.top"));
    ResourceUtils.resButton(buzzBox, Res.getString("checkbox.allow.buzz"));

    generalPanel.setBorder(
        BorderFactory.createTitledBorder(Res.getString("group.general.information")));
    chatWindowPanel.setBorder(
        BorderFactory.createTitledBorder(Res.getString("group.chat.window.information")));

    if (!Default.getBoolean(Default.CHANGE_PASSWORD_DISABLED)) {
      add(generalPanel);
    }
    add(chatWindowPanel);

    generalPanel.setLayout(new GridBagLayout());
    chatWindowPanel.setLayout(new GridBagLayout());

    // Chat Window Panel settings
    chatWindowPanel.add(
        showTimeBox,
        new GridBagConstraints(
            0,
            0,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    chatWindowPanel.add(
        format24,
        new GridBagConstraints(
            1,
            0,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    chatWindowPanel.add(
        format12,
        new GridBagConstraints(
            2,
            0,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));

    chatWindowPanel.add(
        groupChatNotificationBox,
        new GridBagConstraints(
            0,
            1,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    chatWindowPanel.add(
        hideChatHistory,
        new GridBagConstraints(
            0,
            2,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    chatWindowPanel.add(
        hidePrevChatHistory,
        new GridBagConstraints(
            0,
            3,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    chatWindowPanel.add(
        tabsOnTopBox,
        new GridBagConstraints(
            0,
            4,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    chatWindowPanel.add(
        buzzBox,
        new GridBagConstraints(
            0,
            5,
            2,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));

    JLabel chatTimeoutLabel = new JLabel();
    ResourceUtils.resLabel(
        chatTimeoutLabel, chatTimeoutField, Res.getString("label.minutes.before.stale.chat") + ":");
    chatWindowPanel.add(
        chatTimeoutLabel,
        new GridBagConstraints(
            0,
            6,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    chatWindowPanel.add(
        chatTimeoutField,
        new GridBagConstraints(
            1,
            6,
            2,
            1,
            1.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            50,
            0));

    generalPanel.add(
        passwordLabel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    generalPanel.add(
        passwordField,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            100,
            0));
    generalPanel.add(
        confirmationPasswordLabel,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    generalPanel.add(
        confirmationPasswordField,
        new GridBagConstraints(
            1,
            2,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            100,
            0));

    showTimeBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (showTimeBox.isSelected()) {
              format12.setEnabled(true);
              format24.setEnabled(true);
            } else {
              format12.setEnabled(false);
              format24.setEnabled(false);
            }
          }
        });

    hideChatHistory.addActionListener(this);
  }