Esempio n. 1
0
 /**
  * Update the hoverEntry with the currently hovered entry, or none if none is hovered. Repaints
  * and informs listeners if something has changed.
  *
  * @param p Where the mouse is currently.
  */
 private void updateHoverEntry(Point p) {
   long hoverEntryBefore = hoverEntry;
   hoverEntry = findHoverEntry(p);
   // If something has changed, then redraw.
   if (hoverEntry != hoverEntryBefore) {
     repaint();
     if (listener != null) {
       if (hoverEntry == -1) {
         listener.noItemSelected();
       } else {
         StreamInfoHistoryItem item = history.get(hoverEntry);
         if (item == null) {
           /**
            * This shouldn't happen, because the hover entry is set just before and selected from
            * the current data (and it should all be in the EDT), but apparently it still happens
            * on rare occasions.
            */
           LOGGER.warning("Hovered Entry " + hoverEntry + " was null");
           hoverEntry = -1;
         } else {
           listener.itemSelected(item.getViewers(), item.getTitle(), item.getGame());
         }
       }
     }
   }
 }
Esempio n. 2
0
  /**
   * Update the start/end/duration/min/max variables which can be changed when the data changes as
   * well when the displayed range changes.
   */
  private void updateVars() {
    long startAt = getStartAt(currentRange);
    long endAt = getEndAt();
    int max = 0;
    int min = -1;
    long start = -1;
    long end = -1;
    for (Long time : history.keySet()) {
      if (time < startAt) {
        continue;
      }
      if (endAt > startAt && time > endAt) {
        continue;
      }
      // Start/End time
      if (start == -1) {
        start = time;
      }
      end = time;
      // Max/min value
      StreamInfoHistoryItem historyObj = history.get(time);
      int viewerCount = historyObj.getViewers();
      if (viewerCount < min || min == -1) {
        min = viewerCount;
      }
      if (viewerCount == -1) {
        min = 0;
      }
      if (viewerCount > max) {
        max = viewerCount;
      }
    }

    maxValue = max;
    minValue = min;
    startTime = start;
    endTime = end;
    duration = end - start;
  }