+ /**
+ * Get the vertical zoom alignment entry and position based on the current
+ * selection. If there is no selection or if the selection is not visible,
+ * return an alignment entry with a null time graph entry.
+ *
+ * @return a map entry where the key is the selection's time graph entry and
+ * the value is the center y-coordinate of that entry, or null
+ */
+ private Entry<ITimeGraphEntry, Integer> getVerticalZoomAlignSelection() {
+ Entry<ITimeGraphEntry, Integer> alignEntry = getVerticalZoomAlignOngoing();
+ if (alignEntry != null) {
+ return alignEntry;
+ }
+ int index = getSelectedIndex();
+ if (index == -1 || index >= getExpandedElementCount()) {
+ return new SimpleEntry<>(null, 0);
+ }
+ Rectangle bounds = getClientArea();
+ Rectangle itemRect = getItemRect(bounds, index);
+ if (itemRect.y < bounds.y || itemRect.y > bounds.y + bounds.height) {
+ /* selection is not visible */
+ return new SimpleEntry<>(null, 0);
+ }
+ ITimeGraphEntry entry = getExpandedElement(index);
+ int y = itemRect.y + itemRect.height / 2;
+ return new SimpleEntry<>(entry, y);
+ }
+
+ /**
+ * Get the vertical zoom alignment entry and position at the specified
+ * cursor position.
+ *
+ * @param y
+ * the cursor y-coordinate
+ * @return a map entry where the key is the time graph entry under the
+ * cursor and the value is the cursor y-coordinate
+ */
+ private Entry<ITimeGraphEntry, Integer> getVerticalZoomAlignCursor(int y) {
+ Entry<ITimeGraphEntry, Integer> alignEntry = getVerticalZoomAlignOngoing();
+ if (alignEntry != null) {
+ return alignEntry;
+ }
+ int index = getItemIndexAtY(y);
+ if (index == -1) {
+ index = getExpandedElementCount() - 1;
+ }
+ ITimeGraphEntry entry = getExpandedElement(index);
+ return new SimpleEntry<>(entry, y);
+ }
+
+ /**
+ * Get the vertical zoom alignment entry and position if there is an ongoing
+ * one and we are within the vertical zoom delay, or otherwise return null.
+ *
+ * @return a map entry where the key is a time graph entry and the value is
+ * a y-coordinate, or null
+ */
+ private Entry<ITimeGraphEntry, Integer> getVerticalZoomAlignOngoing() {
+ long currentTimeMillis = System.currentTimeMillis();
+ if (currentTimeMillis < fVerticalZoomAlignTime + VERTICAL_ZOOM_DELAY) {
+ /*
+ * If the vertical zoom is triggered repeatedly in a short amount of
+ * time, use the initial event's entry and position.
+ */
+ fVerticalZoomAlignTime = currentTimeMillis;
+ return fVerticalZoomAlignEntry;
+ }
+ fVerticalZoomAlignTime = currentTimeMillis;
+ return null;
+ }
+