1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.common
;
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
;
21 * Preserve the time and space width parameters applicable to a particular view
22 * in order to facilitate filtering of events and request handling.
27 public class ParamsUpdater
{
28 // ========================================================================
30 // ========================================================================
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
39 private double pixelsPerNs
= 0;
40 private int eventsDiscarded
= 0;
41 private int eventsDiscardedWrongOrder
= 0;
42 private TmfTimeRange trange
= null;
44 // ========================================================================
46 // ========================================================================
52 public synchronized boolean processTimeScaleEvent(
53 TmfTimeScaleSelectionEvent event
) {
55 boolean updated
= false;
57 long time0
= event
.getTime0();
58 long time1
= event
.getTime1();
59 int dwidth
= event
.getWidth();
61 updated
= update(time0
, time1
, dwidth
);
62 setSelectedTime(event
.getSelectedTime());
70 * Save the selected time
73 public void setSelectedTime(long selTime
) {
74 if (selTime
> startTime
&& selTime
< endTime
) {
75 selectedTime
= selTime
;
82 * May return null, if the selected time is invalid
86 public Long
getSelectedTime() {
91 * Only positive attributes are expected
98 public boolean update(long time0
, long time1
, int dwidth
) {
99 boolean updated
= false;
101 if (time0
== startTime
&& time1
== endTime
&& dwidth
== width
) {
106 // Negatives are invalid
107 time0
= time0
> 0 ? time0
: 0;
108 time1
= time1
> 0 ? time1
: 0;
109 dwidth
= dwidth
> 0 ? dwidth
: 0;
112 // Store the new values as long as they are within range
117 pixelsPerNs
= (double) width
/ (double) (endTime
- startTime
);
118 trange
= new TmfTimeRange(new LttngTimestamp(startTime
),
119 new LttngTimestamp(endTime
));
124 TraceDebug
.debug("Configuration updated to: StartTime: " /* */
129 + width
+ " k: " + pixelsPerNs
); /* */
132 .debug("End time is not greater than start time, start time: "
133 + time0
+ " end time: " + time1
);
142 public long getStartTime() {
149 public long getEndTime() {
156 public int getWidth() {
160 TraceDebug
.debug("Unexpected width value of 0 pixels");
167 * Return the current constant "K" of pixels per nano second used for the
168 * widest time space widget registered in this instance.
172 public double getPixelsPerNs() {
177 * Set the value of pixels per nano second as long as the value is grater
182 public void setPixelsPerNs(double pixperNsec
) {
183 if (pixperNsec
> 0) {
184 pixelsPerNs
= pixperNsec
;
191 public void setEventsDiscarded(int value
) {
192 eventsDiscarded
= value
;
194 eventsDiscardedWrongOrder
= 0;
201 public void incrementEventsDiscarded() {
202 this.eventsDiscarded
++;
208 public int getEventsDiscarded() {
209 return eventsDiscarded
;
213 * increase the number of events discarder since they were not received in a
214 * later time than previous events
216 public void incrementEventsDiscardedWrongOrder() {
217 this.eventsDiscarded
++;
218 this.eventsDiscardedWrongOrder
++;
224 public int getEventsDiscardedWrongOrder() {
225 return eventsDiscardedWrongOrder
;
232 public TmfTimeRange
getTrange() {