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