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
.linuxtools
.lttng
.LttngConstants
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.graphics
.GC
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
20 * <b><u>HistogramConstant</u></b>
22 * Empty interface class to hold the different constants needed by the histogram.
25 public abstract class HistogramConstant
{
27 // Constants relative to requests
28 // public final static int MAX_EVENTS_PER_READ = LttngConstants.DEFAULT_BLOCK_SIZE;
29 public final static int REDRAW_EVERY_NB_EVENTS
= 20000;
30 public final static Boolean SKIP_EMPTY_INTERVALS_WHEN_CALCULATING_AVERAGE
= true;
33 // Constant relative to the content
34 public final static double DEFAULT_DIFFERENCE_TO_AVERAGE
= 1000.0;
38 // Constants relative to zoom. Factors need to be a percentage ( 0 < factors < 1 )
39 public final static double ZOOM_IN_FACTOR
= 0.1;
40 public final static double ZOOM_OUT_FACTOR
= 0.1;
43 // Constants relative to wait time while listening for scroll events
44 // "FULL" is time to wait to stop "to count" mouse scroll click events
45 // "INTERVAL" is time to wait between polling for scroll click events
46 public final static long FULL_WAIT_MS_TIME_BETWEEN_MOUSE_SCROLL
= 1000L;
47 public final static long INTERVAL_WAIT_MS_TIME_BETWEEN_POLL
= 100L;
50 // Constants relative to the displacement in the trace
51 // Factor represent a number of HistogramContent interval
52 // Multiple is the factor to multiply to basic during "fast" displacement
53 public final static int BASIC_DISPLACEMENT_FACTOR
= 1;
54 public final static double FAST_DISPLACEMENT_MULTIPLE
= 10.0;
57 // Constants relative to the drawing of the Histogram
58 // Colors for the histogram. Background should be the same as the background in use
59 public final static int EMPTY_BACKGROUND_COLOR
= SWT
.COLOR_WHITE
;
60 public final static int SELECTED_EVENT_COLOR
= SWT
.COLOR_RED
;
62 // Dimension for the line of the "Selection Window"
63 public final static int MINIMUM_WINDOW_WIDTH
= 3;
64 public final static int SELECTION_LINE_WIDTH
= 1;
65 public final static int SELECTION_CROSSHAIR_WIDTH
= 1;
69 * Method to format a long representing nanosecond into a proper String.<p>
70 * The returned String will always be like "0.000000000", missing decimal will be added.
72 * @param nanosecTime This time to format
74 * @return The formatted string
76 public static String
formatNanoSecondsTime(long nanosecTime
) {
77 String returnedTime
= Long
.toString(nanosecTime
);
79 // If our number has over 9 digits, just add a dot after the ninth digits
80 if ( returnedTime
.length() > 9 ) {
81 returnedTime
= returnedTime
.substring(0, returnedTime
.length() - 9 ) + "." + returnedTime
.substring( returnedTime
.length() - 9 ); //$NON-NLS-1$
83 // Otherwise, patch missing decimal with 0
85 int curSize
= returnedTime
.length();
86 for (int l
=0; (curSize
+l
)< 9; l
++) {
87 returnedTime
= "0" + returnedTime
; //$NON-NLS-1$
89 returnedTime
= "0." + returnedTime
; //$NON-NLS-1$
96 * Convert a String representing nanoseconds into a valid long.<p>
97 * This can handle number like "0.5", "0.123456789" as well as plain number like "12".<p>
99 * Note : This function ALWAYS return a number, if conversion failed, 0 will be returned.<p>
101 * @param timeString The string to convert
103 * @return The converted nanoseconds time as long
105 public static long convertStringToNanoseconds( String timeString
) {
106 long returnedNumber
= 0L;
109 // Avoid simple commat/dot mistake
110 timeString
= timeString
.replace(",", "."); //$NON-NLS-1$ //$NON-NLS-2$
112 // If we have a dot, we have a decimal number to convert
113 int dotPosition
= timeString
.indexOf("."); //$NON-NLS-1$
115 // If the user begun the line with a dot, we add a zero
116 if ( dotPosition
== 0 ) {
117 timeString
= "0" + timeString
; //$NON-NLS-1$
121 // If we found a dot, verify that we have 9 digits
122 if ( dotPosition
!= -1 ) {
123 int decimalNumber
= (timeString
.length() - dotPosition
-1);
125 // If we have less than 9 digits, we fill with 0
126 if ( decimalNumber
<= 9 ) {
127 StringBuffer strBuffer
= new StringBuffer(timeString
);
128 for ( int nbDec
=decimalNumber
; nbDec
<9; nbDec
++) {
129 strBuffer
.append("0"); //$NON-NLS-1$
131 timeString
= strBuffer
.toString();
133 // We have OVER 9 digits, skip the useless part
135 timeString
= timeString
.substring(dotPosition
, 9);
139 // Conversion into decimal seconds
140 double dblMaxTimerange
= Double
.parseDouble(timeString
);
141 // Conversion into nanoseconds
142 returnedNumber
= (long)(dblMaxTimerange
* 1000000000.0);
144 catch (NumberFormatException e
) {
145 System
.out
.println("Warning : Could not convert string into nanoseconds (convertStringToLong)"); //$NON-NLS-1$
148 return returnedNumber
;
152 * Calculate the correcte width of a String.<p>
153 * Useful to set a control to its maximum size; since the size depends on characters,
154 * this will calculate the correct sum... should be platform independant (we hope).
156 * @param parent Parent control we will use as a reference. Could be any composite.
157 * @param text The Text to measure the size from
159 * @return The size calculated.
161 public static int getTextSizeInControl(Composite parent
, String text
) {
162 GC graphicContext
= new GC(parent
);
164 for ( int pos
=0; pos
<text
.length(); pos
++ ) {
165 textSize
+= graphicContext
.getAdvanceWidth( text
.charAt(pos
) );
167 // Add an extra space in case there was trailing whitespace in the message
168 textSize
+= graphicContext
.getAdvanceWidth( ' ' );