Commit | Line | Data |
---|---|---|
378e7718 WB |
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 | *******************************************************************************/ | |
6e512b93 ASL |
12 | package org.eclipse.linuxtools.lttng.ui.views.histogram; |
13 | ||
050df4a5 WB |
14 | /** |
15 | * <b><u>HistogramSelectedWindow</u></b> | |
16 | * <p> | |
17 | * Selection window represent the selected section of the trace in the HistogramCanvas. | |
18 | * <p> | |
19 | * The selected window have 3 important attributes : | |
20 | * <ul> | |
21 | * <li>Its central position | |
22 | * <li>Its time width | |
23 | * <li>Its visibility (to determine if we should draw it or not) | |
24 | * </ul> | |
25 | * The dimension are then deduced from the first 2 values. | |
26 | * This mean the window is always a perfectly symetrical rectangle. | |
27 | */ | |
6e512b93 | 28 | public class HistogramSelectedWindow { |
ecfd1d41 | 29 | |
088c1d4e WB |
30 | |
31 | ||
833a21aa | 32 | private int windowCenterPosition = 0; |
ecfd1d41 WB |
33 | private long windowTimeWidth = 0; |
34 | ||
35 | private boolean isSelectedWindowVisible = false; | |
36 | ||
37 | private HistogramContent histogramContent = null; | |
050df4a5 WB |
38 | |
39 | /** | |
40 | * Default constructor for HistogramSelectedWindow.<p> | |
41 | * Position and TimeWidth are both set to 0 | |
42 | * | |
43 | * @param newTraceContent HistogramContent to read window's data from | |
44 | */ | |
ecfd1d41 | 45 | public HistogramSelectedWindow(HistogramContent newTraceContent) { |
6cf16d22 | 46 | histogramContent = newTraceContent; |
ecfd1d41 WB |
47 | } |
48 | ||
050df4a5 WB |
49 | /** |
50 | * Default constructor for HistogramSelectedWindow.<p> | |
51 | * Position and TimeWidth are set to given value. | |
52 | * | |
53 | * @param newTraceContent HistogramContent to read window's data from | |
54 | * @param centralPosition Central X Position of the selection window in the canvas (0 to canvasWidth) | |
55 | * @param newWindowWidth Time width (size) of the window. (0 or greater) | |
56 | */ | |
ecfd1d41 | 57 | public HistogramSelectedWindow(HistogramContent newTraceContent, int centralPosition, long newWindowWidth) { |
6cf16d22 | 58 | histogramContent = newTraceContent; |
833a21aa | 59 | windowCenterPosition = centralPosition; |
ecfd1d41 WB |
60 | windowTimeWidth = newWindowWidth; |
61 | } | |
62 | ||
050df4a5 WB |
63 | /** |
64 | * Getter for the HistogramContent used by the window.<p> | |
65 | * | |
66 | * @return HistogramContent tied to this selection window. | |
67 | */ | |
68 | public HistogramContent getTraceContent() { | |
69 | return histogramContent; | |
70 | } | |
71 | ||
72 | /** | |
73 | * Setter for the HistogramContent used by the window.<p> | |
74 | * This need to be a valid, initialized HistogramContent; | |
75 | * the data in the content are needed for positionning the window. | |
76 | * | |
77 | * @param newTraceContent A new HistogramContent | |
78 | */ | |
79 | public void setTraceContent(HistogramContent newTraceContent) { | |
80 | this.histogramContent = newTraceContent; | |
81 | } | |
82 | ||
83 | ||
84 | /** | |
85 | * Getter for the window visibility.<p> | |
86 | * | |
87 | * @return true if the window is visible (will be draw), false otherwise | |
88 | */ | |
ecfd1d41 WB |
89 | public boolean getSelectedWindowVisible() { |
90 | return isSelectedWindowVisible; | |
91 | } | |
92 | ||
050df4a5 WB |
93 | /** |
94 | * Setter for the window visibility.<p> | |
95 | * True means the window will be draw, false that it will be hidden. | |
96 | * | |
97 | * @param newIsSelectedWindowVisible The visibility value | |
98 | */ | |
ecfd1d41 WB |
99 | public void setSelectedWindowVisible(boolean newIsSelectedWindowVisible) { |
100 | this.isSelectedWindowVisible = newIsSelectedWindowVisible; | |
101 | } | |
ecfd1d41 | 102 | |
050df4a5 WB |
103 | |
104 | /** | |
105 | * Getter for the window time width (size) | |
106 | * | |
107 | * @return Window time width (size) | |
108 | */ | |
ecfd1d41 WB |
109 | public long getWindowTimeWidth() { |
110 | return windowTimeWidth; | |
111 | } | |
112 | ||
050df4a5 WB |
113 | /** |
114 | * Setter for the window time width (size).<p> | |
115 | * Width need to be a time (in nanoseconds) that's coherent to the data we are looking at. | |
116 | * | |
117 | * @param newWindowTimeWidth The new time width | |
118 | */ | |
ecfd1d41 WB |
119 | public void setWindowTimeWidth(long newWindowTimeWidth) { |
120 | this.windowTimeWidth = newWindowTimeWidth; | |
121 | } | |
122 | ||
ecfd1d41 | 123 | |
050df4a5 WB |
124 | /** |
125 | * Getter for the central position of the window.<p> | |
126 | * | |
127 | * @return Center X position of this window on the canvas. | |
128 | */ | |
833a21aa WB |
129 | public int getWindowXPositionCenter() { |
130 | return windowCenterPosition; | |
ecfd1d41 WB |
131 | } |
132 | ||
050df4a5 WB |
133 | /** |
134 | * Setter for the central position of the window.<p> | |
135 | * The new position need to be valid on the canvas (0 to canvasWidth). | |
136 | * | |
137 | * @param newPosCenter The new central position. | |
138 | */ | |
833a21aa WB |
139 | public void setWindowXPositionCenter(int newPosCenter) { |
140 | this.windowCenterPosition = newPosCenter; | |
ecfd1d41 WB |
141 | } |
142 | ||
050df4a5 WB |
143 | /** |
144 | * Getter for the left border of the window.<p> | |
145 | * Compute the position from the HistogramContent data; may return 0 if the content data are wrong. | |
146 | * | |
147 | * @return The left position of the window, or 0 if it cannot compute it. | |
148 | */ | |
833a21aa WB |
149 | public Integer getWindowXPositionLeft() { |
150 | return histogramContent.getXPositionByPositionAndTimeInterval(windowCenterPosition, -(windowTimeWidth / 2) ); | |
ecfd1d41 WB |
151 | } |
152 | ||
050df4a5 WB |
153 | /** |
154 | * Getter for the right border of the window.<p> | |
155 | * Compute the position from the HistogramContent data; may return 0 if the content data are wrong. | |
156 | * | |
157 | * @return The right position of the window, or 0 if it cannot compute it. | |
158 | */ | |
833a21aa WB |
159 | public Integer getWindowXPositionRight() { |
160 | return histogramContent.getXPositionByPositionAndTimeInterval(windowCenterPosition, +(windowTimeWidth / 2) ); | |
ecfd1d41 WB |
161 | } |
162 | ||
050df4a5 WB |
163 | /** |
164 | * Getter for the timestamp of left border of the window.<p> | |
165 | * Compute the timestamp from the HistogramContent data; may return 0 if the content data are wrong. | |
166 | * | |
167 | * @return The left timestamp of the window, or 0 if it cannot compute it. | |
168 | */ | |
833a21aa WB |
169 | public Long getTimestampLeft() { |
170 | return histogramContent.getClosestElementFromXPosition( getWindowXPositionLeft() ).firstIntervalTimestamp; | |
171 | } | |
172 | ||
173 | /** | |
174 | * Getter for the timestamp of the center of the window.<p> | |
175 | * Compute the timestamp from the HistogramContent data; may return 0 if the content data are wrong. | |
176 | * | |
177 | * @return The center timestamp of the window, or 0 if it cannot compute it. | |
178 | */ | |
179 | public Long getTimestampCenter() { | |
180 | return histogramContent.getClosestElementFromXPosition( getWindowXPositionCenter() ).firstIntervalTimestamp; | |
ecfd1d41 WB |
181 | } |
182 | ||
050df4a5 WB |
183 | /** |
184 | * Getter for the timestamp of right border of the window.<p> | |
185 | * Compute the timestamp from the HistogramContent data; may return 0 if the content data are wrong. | |
186 | * | |
187 | * @return The right timestamp of the window, or 0 if it cannot compute it. | |
188 | */ | |
833a21aa WB |
189 | public Long getTimestampRight() { |
190 | return histogramContent.getClosestElementFromXPosition( getWindowXPositionRight() ).firstIntervalTimestamp; | |
ecfd1d41 | 191 | } |
6e512b93 | 192 | } |