private RemoteDesktopServerEvent createUpdateEvent(List selectedEvents) {
    Rectangle r = null;
    RemoteDesktopServerEvent e = null;
    long time = 0;
    int p1, p2;

    for (int i = 0; selectedEvents != null && i < selectedEvents.size(); i++) {
      e = (RemoteDesktopServerEvent) selectedEvents.get(i);
      if (e.getMessageType() == RemoteDesktopServerEvent.SERVER_UPDATE_EVENT) {
        time = Math.max(time, e.getWhen());
        if (r == null) {
          r = new Rectangle(e.getUpdateRect());
        } else {
          r.x = Math.min(r.x, e.getUpdateRect().x);
          r.y = Math.min(r.y, e.getUpdateRect().y);
          p1 = r.x + r.width;
          p2 = e.getUpdateRect().x + e.getUpdateRect().width;
          if (p2 > p1) {
            r.width = p2 - r.x;
          }
          p1 = r.y + r.height;
          p2 = e.getUpdateRect().y + e.getUpdateRect().height;
          if (p2 > p1) {
            r.height = p2 - r.y;
          }
        }
      }
    }
    if (r == null) {
      return null;
    }
    //            System.out.println("Resulting rect: "+r);
    e = new RemoteDesktopServerEvent(e.getClient(), r);
    e.setWhen(time);
    return e;
  }
  public void serverMessageReceived(RemoteDesktopServerEvent e) {
    //        if (enabled) {
    if (e.getMessageType() == RemoteDesktopServerEvent.SERVER_UPDATE_EVENT) {
      RemoteDesktopClient rfb = e.getClient();
      if (rfb.isConnected() && rfb.getDesktopWidth() > 0 && rfb.getDesktopHeight() > 0) {
        Rectangle r = e.getUpdateRect();

        int cw = rfb.getDesktopWidth();
        int ch = rfb.getDesktopHeight();
        float ratio = 100 * (r.width * r.height) / (cw * ch);
        if (ratio >= RFB_SIZE_LIMIT) {
          synchronized (rfbEvents) {
            rfbEvents.add(0, e);
            filterRfbEvents();
          }
        }
      }
    } else if (e.getMessageType() == RemoteDesktopServerEvent.SERVER_BELL_EVENT) {
      synchronized (rfbEvents) {
        rfbEvents.add(0, e);
        filterRfbEvents();
      }
    }
  }