Bug #348267 - Documentation navigation arrows missing
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / histogram / HistogramConstant.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 * William Bourque - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.views.histogram;
13
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;
18
19 /**
20 * <b><u>HistogramConstant</u></b>
21 * <p>
22 * Empty interface class to hold the different constants needed by the histogram.
23 * <p>
24 */
25 public abstract class HistogramConstant {
26
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;
31
32
33 // Constant relative to the content
34 public final static double DEFAULT_DIFFERENCE_TO_AVERAGE = 1000.0;
35
36
37
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;
41
42
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;
48
49
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;
55
56
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;
61
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;
66
67
68 /**
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.
71 *
72 * @param nanosecTime This time to format
73 *
74 * @return The formatted string
75 */
76 public static String formatNanoSecondsTime(long nanosecTime) {
77 String returnedTime = Long.toString(nanosecTime);
78
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$
82 }
83 // Otherwise, patch missing decimal with 0
84 else {
85 int curSize = returnedTime.length();
86 for (int l=0; (curSize+l)< 9; l++) {
87 returnedTime = "0" + returnedTime; //$NON-NLS-1$
88 }
89 returnedTime = "0." + returnedTime; //$NON-NLS-1$
90 }
91
92 return returnedTime;
93 }
94
95 /**
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>
98 *
99 * Note : This function ALWAYS return a number, if conversion failed, 0 will be returned.<p>
100 *
101 * @param timeString The string to convert
102 *
103 * @return The converted nanoseconds time as long
104 */
105 public static long convertStringToNanoseconds( String timeString ) {
106 long returnedNumber = 0L;
107
108 try {
109 // Avoid simple commat/dot mistake
110 timeString = timeString.replace(",", "."); //$NON-NLS-1$ //$NON-NLS-2$
111
112 // If we have a dot, we have a decimal number to convert
113 int dotPosition = timeString.indexOf("."); //$NON-NLS-1$
114
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$
118 dotPosition = 1;
119 }
120
121 // If we found a dot, verify that we have 9 digits
122 if ( dotPosition != -1 ) {
123 int decimalNumber = (timeString.length() - dotPosition -1);
124
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$
130 }
131 timeString = strBuffer.toString();
132 }
133 // We have OVER 9 digits, skip the useless part
134 else {
135 timeString = timeString.substring(dotPosition, 9);
136 }
137 }
138
139 // Conversion into decimal seconds
140 double dblMaxTimerange = Double.parseDouble(timeString);
141 // Conversion into nanoseconds
142 returnedNumber = (long)(dblMaxTimerange * 1000000000.0);
143 }
144 catch (NumberFormatException e) {
145 System.out.println("Warning : Could not convert string into nanoseconds (convertStringToLong)"); //$NON-NLS-1$
146 }
147
148 return returnedNumber;
149 }
150
151 /**
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).
155 *
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
158 *
159 * @return The size calculated.
160 */
161 public static int getTextSizeInControl(Composite parent, String text) {
162 GC graphicContext = new GC(parent);
163 int textSize = 0;
164 for ( int pos=0; pos<text.length(); pos++ ) {
165 textSize += graphicContext.getAdvanceWidth( text.charAt(pos) );
166 }
167 // Add an extra space in case there was trailing whitespace in the message
168 textSize += graphicContext.getAdvanceWidth( ' ' );
169
170 return textSize;
171 }
172 }
This page took 0.033833 seconds and 5 git commands to generate.