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