| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * William Bourque - Initial API and implementation |
| 11 | * |
| 12 | * Modifications: |
| 13 | * 2010-07-16 Yuriy Vashchuk - Heritage correction and selection window |
| 14 | * optimisations. |
| 15 | *******************************************************************************/ |
| 16 | package org.eclipse.linuxtools.lttng.ui.views.histogram; |
| 17 | |
| 18 | /** |
| 19 | * <b><u>HistogramSelectedWindow</u></b> |
| 20 | * <p> |
| 21 | * Selection window represent the selected section of the trace in the HistogramCanvas. |
| 22 | * <p> |
| 23 | * The selected window have 3 important attributes : |
| 24 | * <ul> |
| 25 | * <li>Its central position |
| 26 | * <li>Its time width |
| 27 | * <li>Its visibility (to determine if we should draw it or not) |
| 28 | * </ul> |
| 29 | * The dimension are then deduced from the first 2 values. |
| 30 | * This mean the window is always a perfectly symetrical rectangle. |
| 31 | */ |
| 32 | public class HistogramSelectedWindow { |
| 33 | |
| 34 | private long timestampOfLeftPosition = 0; |
| 35 | private long timestampOfCenterPosition = 0; |
| 36 | private long timestampOfRightPosition = 0; |
| 37 | private long windowTimeWidth = 0L; |
| 38 | private int windowXPositionLeft = 0; |
| 39 | private int windowXPositionCenter = 0; |
| 40 | private int windowXPositionRight = 0; |
| 41 | private Boolean isSelectedWindowVisible = false; |
| 42 | |
| 43 | /** |
| 44 | * Default constructor for HistogramSelectedWindow.<p> |
| 45 | * Position and TimeWidth are set to given value. |
| 46 | * |
| 47 | * @param newTraceContent HistogramContent to read window's data from |
| 48 | * @param centralPosition Central X Position of the selection window in the canvas (0 to canvasWidth) |
| 49 | * @param newWindowWidth Time width (size) of the window. (0 or greater) |
| 50 | */ |
| 51 | public HistogramSelectedWindow(HistogramContent newTraceContent, long timestampOfLeftPosition, long newWindowWidth) { |
| 52 | if(newTraceContent != null) { |
| 53 | setWindowTimeWidth(newWindowWidth); |
| 54 | setTimestampOfLeftPosition(timestampOfLeftPosition); |
| 55 | setTimestampOfRightPosition(timestampOfLeftPosition + newWindowWidth); |
| 56 | setTimestampOfCenterPosition(timestampOfLeftPosition + newWindowWidth / 2); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Getter for the window visibility.<p> |
| 62 | * |
| 63 | * @return true if the window is visible (will be draw), false otherwise |
| 64 | */ |
| 65 | public boolean getSelectedWindowVisible() { |
| 66 | return isSelectedWindowVisible; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Setter for the window visibility.<p> |
| 71 | * True means the window will be draw, false that it will be hidden. |
| 72 | * |
| 73 | * @param newIsSelectedWindowVisible The visibility value |
| 74 | */ |
| 75 | public void setSelectedWindowVisible(Boolean newIsSelectedWindowVisible) { |
| 76 | this.isSelectedWindowVisible = newIsSelectedWindowVisible; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * Getter for the window time width (size) |
| 82 | * |
| 83 | * @return Window time width (size) |
| 84 | */ |
| 85 | public long getWindowTimeWidth() { |
| 86 | return windowTimeWidth; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Setter for the window time width (size).<p> |
| 91 | * Width need to be a time (in nanoseconds) that's coherent to the data we are looking at. |
| 92 | * |
| 93 | * @param newWindowTimeWidth The new time width |
| 94 | */ |
| 95 | public void setWindowTimeWidth(long newWindowTimeWidth) { |
| 96 | this.windowTimeWidth = newWindowTimeWidth; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Getter for the timestamp of left border of the window.<p> |
| 101 | * Compute the timestamp from the HistogramContent data; may return 0 if the content data are wrong. |
| 102 | * |
| 103 | * @return The left timestamp of the window, or 0 if it cannot compute it. |
| 104 | */ |
| 105 | public long getTimestampOfLeftPosition() { |
| 106 | return timestampOfLeftPosition; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Setter for the timestamp of left border of the window.<p> |
| 111 | * @param timestampOfLeftPosition The left timestamp of the window. |
| 112 | */ |
| 113 | public void setTimestampOfLeftPosition(long timestampOfLeftPosition) { |
| 114 | this.timestampOfLeftPosition = timestampOfLeftPosition; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Getter for the timestamp of the center of the window.<p> |
| 119 | * Compute the timestamp from the HistogramContent data; may return 0 if the content data are wrong. |
| 120 | * |
| 121 | * @return The center timestamp of the window, or 0 if it cannot compute it. |
| 122 | */ |
| 123 | public long getTimestampOfCenterPosition() { |
| 124 | return timestampOfCenterPosition; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Setter for the timestamp of center border of the window.<p> |
| 129 | */ |
| 130 | public void setTimestampOfCenterPosition(long timestampOfCenterPosition) { |
| 131 | this.timestampOfCenterPosition = timestampOfCenterPosition; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Setter for the timestamp of center border of the window.<p> |
| 136 | */ |
| 137 | public void setTimestampOfLeftCenterRightPositions(long timestampOfCenterPosition) { |
| 138 | this.timestampOfLeftPosition = timestampOfCenterPosition - windowTimeWidth / 2; |
| 139 | this.timestampOfCenterPosition = timestampOfCenterPosition; |
| 140 | this.timestampOfRightPosition = timestampOfCenterPosition + windowTimeWidth / 2; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Getter for the timestamp of right border of the window.<p> |
| 145 | * Compute the timestamp from the HistogramContent data; may return 0 if the content data are wrong. |
| 146 | * |
| 147 | * @return The right timestamp of the window, or 0 if it cannot compute it. |
| 148 | */ |
| 149 | public long getTimestampOfRightPosition() { |
| 150 | return timestampOfRightPosition; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Setter for the timestamp of right border of the window.<p> |
| 155 | * @param timestampOfRightPosition The right timestamp of the window. |
| 156 | */ |
| 157 | public void setTimestampOfRightPosition(long timestampOfRightPosition) { |
| 158 | this.timestampOfRightPosition = timestampOfRightPosition; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Getter for the coordinate of left border of the window.<p> |
| 163 | * |
| 164 | * @return The left coordinate. |
| 165 | */ |
| 166 | public int getWindowXPositionLeft() { |
| 167 | return windowXPositionLeft; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Setter for the coordinate of left border of the window.<p> |
| 172 | * @param windowXPositionLeft The left coordinate of the window. |
| 173 | */ |
| 174 | public void setWindowXPositionLeft(int windowXPositionLeft) { |
| 175 | this.windowXPositionLeft = windowXPositionLeft; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Getter for the coordinate of center border of the window.<p> |
| 180 | * |
| 181 | * @return The center coordinate. |
| 182 | */ |
| 183 | public int getWindowXPositionCenter() { |
| 184 | return windowXPositionCenter; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Setter for the coordinate of center of the window.<p> |
| 189 | * @param windowXPositionCenter The center coordinate of the window. |
| 190 | */ |
| 191 | public void setWindowXPositionCenter(int windowXPositionCenter) { |
| 192 | this.windowXPositionCenter = windowXPositionCenter; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Getter for the coordinate of right border of the window.<p> |
| 197 | * |
| 198 | * @return The right coordinate. |
| 199 | */ |
| 200 | public int getWindowXPositionRight() { |
| 201 | return windowXPositionRight; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Setter for the coordinate of right border of the window.<p> |
| 206 | * @param windowXPositionRight The right coordinate of the window. |
| 207 | */ |
| 208 | public void setWindowXPositionRight(int windowXPositionRight) { |
| 209 | this.windowXPositionRight = windowXPositionRight; |
| 210 | } |
| 211 | } |