46f0d49db77d29a5c63b696a3709a90761879a96
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / common / ParamsUpdater.java
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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.views.common;
13
14 import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
15 import org.eclipse.linuxtools.lttng.ui.TraceDebug;
16 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
17 import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent;
18
19 /**
20 *
21 * Preserve the time and space width parameters applicable to a particular view
22 * in order to facilitate filtering of events and request handling.
23 *
24 * @author alvaro
25 *
26 */
27 public class ParamsUpdater {
28 // ========================================================================
29 // Data
30 // ========================================================================
31
32 private long startTime = 0;
33 private long endTime = Long.MAX_VALUE;
34 private Long selectedTime = null;
35 private final int defaultWidth = 2000; // number of estimated pixels that
36 // can hold the time range space
37 private int width = defaultWidth; // width in pixels used to represent the
38 // time interval
39 private double pixelsPerNs = 0;
40 private int eventsDiscarded = 0;
41 private int eventsDiscardedWrongOrder = 0;
42 private TmfTimeRange trange = null;
43
44 // ========================================================================
45 // Methods
46 // ========================================================================
47
48 /**
49 * @param event
50 * @return
51 */
52 public synchronized boolean processTimeScaleEvent(
53 TmfTimeScaleSelectionEvent event) {
54
55 boolean updated = false;
56 if (event != null) {
57 long time0 = event.getTime0();
58 long time1 = event.getTime1();
59 int dwidth = event.getWidth();
60
61 updated = update(time0, time1, dwidth);
62 setSelectedTime(event.getSelectedTime());
63 }
64
65 return updated;
66
67 }
68
69 /**
70 * Save the selected time
71 * @param selTime
72 */
73 public void setSelectedTime(long selTime) {
74 if (selTime > startTime && selTime < endTime) {
75 selectedTime = selTime;
76 } else {
77 selectedTime = null;
78 }
79 }
80
81 /**
82 * May return null, if the selected time is invalid
83 *
84 * @return
85 */
86 public Long getSelectedTime() {
87 return selectedTime;
88 }
89
90 /**
91 * Only positive attributes are expected
92 *
93 * @param time0
94 * @param time1
95 * @param dwidth
96 * @return
97 */
98 public boolean update(long time0, long time1, int dwidth) {
99 boolean updated = false;
100
101 if (time0 == startTime && time1 == endTime && dwidth == width) {
102 // No updated needed
103 return updated;
104 }
105
106 // Negatives are invalid
107 time0 = time0 > 0 ? time0 : 0;
108 time1 = time1 > 0 ? time1 : 0;
109 dwidth = dwidth > 0 ? dwidth : 0;
110
111 if (time1 > time0) {
112 // Store the new values as long as they are within range
113 startTime = time0;
114 endTime = time1;
115 width = dwidth;
116
117 pixelsPerNs = (double) width / (double) (endTime - startTime);
118 trange = new TmfTimeRange(new LttngTimestamp(startTime),
119 new LttngTimestamp(endTime));
120
121 // update succeeded
122 updated = true;
123
124 TraceDebug.debug("Configuration updated to: StartTime: " /* */
125 + startTime /* */
126 + " endTime: " /* */
127 + endTime /* */
128 + " width: " /* */
129 + width + " k: " + pixelsPerNs); /* */
130 } else {
131 TraceDebug
132 .debug("End time is not greater than start time, start time: "
133 + time0 + " end time: " + time1);
134 }
135
136 return updated;
137 }
138
139 /**
140 * @return
141 */
142 public long getStartTime() {
143 return startTime;
144 }
145
146 /**
147 * @return
148 */
149 public long getEndTime() {
150 return endTime;
151 }
152
153 /**
154 * @return
155 */
156 public int getWidth() {
157 if (width == 0) {
158 return defaultWidth;
159 } else {
160 TraceDebug.debug("Unexpected width value of 0 pixels");
161 }
162
163 return width;
164 }
165
166 /**
167 * Return the current constant "K" of pixels per nano second used for the
168 * widest time space widget registered in this instance.
169 *
170 * @return
171 */
172 public double getPixelsPerNs() {
173 return pixelsPerNs;
174 }
175
176 /**
177 * Set the value of pixels per nano second as long as the value is grater
178 * positive
179 *
180 * @return
181 */
182 public void setPixelsPerNs(double pixperNsec) {
183 if (pixperNsec > 0) {
184 pixelsPerNs = pixperNsec;
185 }
186 }
187
188 /**
189 * @param value
190 */
191 public void setEventsDiscarded(int value) {
192 eventsDiscarded = value;
193 if (value == 0) {
194 eventsDiscardedWrongOrder = 0;
195 }
196 }
197
198 /**
199 *
200 */
201 public void incrementEventsDiscarded() {
202 this.eventsDiscarded++;
203 }
204
205 /**
206 * @return
207 */
208 public int getEventsDiscarded() {
209 return eventsDiscarded;
210 }
211
212 /**
213 * increase the number of events discarder since they were not received in a
214 * later time than previous events
215 */
216 public void incrementEventsDiscardedWrongOrder() {
217 this.eventsDiscarded++;
218 this.eventsDiscardedWrongOrder++;
219 }
220
221 /**
222 * @return
223 */
224 public int getEventsDiscardedWrongOrder() {
225 return eventsDiscardedWrongOrder;
226
227 }
228
229 /**
230 * @return
231 */
232 public TmfTimeRange getTrange() {
233 return trange;
234 }
235
236 }
This page took 0.036077 seconds and 4 git commands to generate.