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 * William Bourque - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.histogram
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.graphics
.GC
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
19 * <b><u>HistogramConstant</u></b>
21 * Empty interface class to hold the different constants needed by the histogram.
24 public abstract class HistogramConstant
{
25 // Constants relative to requests
26 public final static int MAX_EVENTS_PER_READ
= 1;
27 public final static int REDRAW_EVERY_NB_EVENTS
= 20000;
28 public final static Boolean SKIP_EMPTY_INTERVALS_WHEN_CALCULATING_AVERAGE
= true;
31 // Constant relative to the content
32 public final static double DEFAULT_DIFFERENCE_TO_AVERAGE
= 1000.0;
36 // Constants relative to zoom. Factors need to be a percentage ( 0 < factors < 1 )
37 public final static double ZOOM_IN_FACTOR
= 0.1;
38 public final static double ZOOM_OUT_FACTOR
= 0.1;
41 // Constants relative to wait time while listening for scroll events
42 // "FULL" is time to wait to stop "to count" mouse scroll click events
43 // "INTERVAL" is time to wait between polling for scroll click events
44 public final static long FULL_WAIT_MS_TIME_BETWEEN_MOUSE_SCROLL
= 1000L;
45 public final static long INTERVAL_WAIT_MS_TIME_BETWEEN_POLL
= 100L;
48 // Constants relative to the displacement in the trace
49 // Factor represent a number of HistogramContent interval
50 // Multiple is the factor to multiply to basic during "fast" displacement
51 public final static int BASIC_DISPLACEMENT_FACTOR
= 1;
52 public final static double FAST_DISPLACEMENT_MULTIPLE
= 10.0;
55 // Constants relative to the drawing of the Histogram
56 // Colors for the histogram. Background should be the same as the background in use
57 public final static int EMPTY_BACKGROUND_COLOR
= SWT
.COLOR_WHITE
;
58 public final static int SELECTED_EVENT_COLOR
= SWT
.COLOR_RED
;
60 // Dimension for the line of the "Selection Window"
61 public final static int MINIMUM_WINDOW_WIDTH
= 3;
62 public final static int SELECTION_LINE_WIDTH
= 1;
63 public final static int SELECTION_CROSSHAIR_WIDTH
= 1;
67 * Method to format a long representing nanosecond into a proper String.<p>
68 * The returned String will always be like "0.000000000", missing decimal will be added.
70 * @param nanosecTime This time to format
72 * @return The formatted string
74 public static String
formatNanoSecondsTime(long nanosecTime
) {
75 String returnedTime
= Long
.toString(nanosecTime
);
77 // If our number has over 9 digits, just add a dot after the ninth digits
78 if ( returnedTime
.length() > 9 ) {
79 returnedTime
= returnedTime
.substring(0, returnedTime
.length() - 9 ) + "." + returnedTime
.substring( returnedTime
.length() - 9 ); //$NON-NLS-1$
81 // Otherwise, patch missing decimal with 0
83 int curSize
= returnedTime
.length();
84 for (int l
=0; (curSize
+l
)< 9; l
++) {
85 returnedTime
= "0" + returnedTime
; //$NON-NLS-1$
87 returnedTime
= "0." + returnedTime
; //$NON-NLS-1$
94 * Convert a String representing nanoseconds into a valid long.<p>
95 * This can handle number like "0.5", "0.123456789" as well as plain number like "12".<p>
97 * Note : This function ALWAYS return a number, if conversion failed, 0 will be returned.<p>
99 * @param timeString The string to convert
101 * @return The converted nanoseconds time as long
103 public static long convertStringToNanoseconds( String timeString
) {
104 long returnedNumber
= 0L;
107 // Avoid simple commat/dot mistake
108 timeString
= timeString
.replace(",", "."); //$NON-NLS-1$ //$NON-NLS-2$
110 // If we have a dot, we have a decimal number to convert
111 int dotPosition
= timeString
.indexOf("."); //$NON-NLS-1$
113 // If the user begun the line with a dot, we add a zero
114 if ( dotPosition
== 0 ) {
115 timeString
= "0" + timeString
; //$NON-NLS-1$
119 // If we found a dot, verify that we have 9 digits
120 if ( dotPosition
!= -1 ) {
121 int decimalNumber
= (timeString
.length() - dotPosition
-1);
123 // If we have less than 9 digits, we fill with 0
124 if ( decimalNumber
<= 9 ) {
125 StringBuffer strBuffer
= new StringBuffer(timeString
);
126 for ( int nbDec
=decimalNumber
; nbDec
<9; nbDec
++) {
127 strBuffer
.append("0"); //$NON-NLS-1$
129 timeString
= strBuffer
.toString();
131 // We have OVER 9 digits, skip the useless part
133 timeString
= timeString
.substring(dotPosition
, 9);
137 // Conversion into decimal seconds
138 double dblMaxTimerange
= Double
.parseDouble(timeString
);
139 // Conversion into nanoseconds
140 returnedNumber
= (long)(dblMaxTimerange
* 1000000000.0);
142 catch (NumberFormatException e
) {
143 System
.out
.println("Warning : Could not convert string into nanoseconds (convertStringToLong)"); //$NON-NLS-1$
146 return returnedNumber
;
150 * Calculate the correcte width of a String.<p>
151 * Useful to set a control to its maximum size; since the size depends on characters,
152 * this will calculate the correct sum... should be platform independant (we hope).
154 * @param parent Parent control we will use as a reference. Could be any composite.
155 * @param text The Text to measure the size from
157 * @return The size calculated.
159 public static int getTextSizeInControl(Composite parent
, String text
) {
160 GC graphicContext
= new GC(parent
);
162 for ( int pos
=0; pos
<text
.length(); pos
++ ) {
163 textSize
+= graphicContext
.getAdvanceWidth( text
.charAt(pos
) );
165 // Add an extra space in case there was trailing whitespace in the message
166 textSize
+= graphicContext
.getAdvanceWidth( ' ' );