Bug #348267 - Documentation navigation arrows missing
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / histogram / HistogramConstant.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 * William Bourque - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.histogram;
13
8016d660 14import org.eclipse.linuxtools.lttng.LttngConstants;
6e512b93 15import org.eclipse.swt.SWT;
833a21aa
WB
16import org.eclipse.swt.graphics.GC;
17import org.eclipse.swt.widgets.Composite;
6e512b93
ASL
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 */
833a21aa 25public abstract class HistogramConstant {
8016d660 26
6e512b93 27 // Constants relative to requests
8016d660 28// public final static int MAX_EVENTS_PER_READ = LttngConstants.DEFAULT_BLOCK_SIZE;
c1c69938 29 public final static int REDRAW_EVERY_NB_EVENTS = 20000;
7c1540ab 30 public final static Boolean SKIP_EMPTY_INTERVALS_WHEN_CALCULATING_AVERAGE = true;
6e512b93
ASL
31
32
33 // Constant relative to the content
1406f802 34 public final static double DEFAULT_DIFFERENCE_TO_AVERAGE = 1000.0;
6e512b93
ASL
35
36
37
38 // Constants relative to zoom. Factors need to be a percentage ( 0 < factors < 1 )
1406f802
WB
39 public final static double ZOOM_IN_FACTOR = 0.1;
40 public final static double ZOOM_OUT_FACTOR = 0.1;
6e512b93
ASL
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
f05aabed 46 public final static long FULL_WAIT_MS_TIME_BETWEEN_MOUSE_SCROLL = 1000L;
1406f802 47 public final static long INTERVAL_WAIT_MS_TIME_BETWEEN_POLL = 100L;
6e512b93
ASL
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
1406f802
WB
53 public final static int BASIC_DISPLACEMENT_FACTOR = 1;
54 public final static double FAST_DISPLACEMENT_MULTIPLE = 10.0;
6e512b93
ASL
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
1406f802 59 public final static int EMPTY_BACKGROUND_COLOR = SWT.COLOR_WHITE;
1406f802 60 public final static int SELECTED_EVENT_COLOR = SWT.COLOR_RED;
6e512b93
ASL
61
62 // Dimension for the line of the "Selection Window"
1406f802 63 public final static int MINIMUM_WINDOW_WIDTH = 3;
8d5e575e
FC
64 public final static int SELECTION_LINE_WIDTH = 1;
65 public final static int SELECTION_CROSSHAIR_WIDTH = 1;
833a21aa 66
544fe9b7
WB
67
68 /**
1406f802 69 * Method to format a long representing nanosecond into a proper String.<p>
544fe9b7
WB
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 */
1406f802
WB
76 public static String formatNanoSecondsTime(long nanosecTime) {
77 String returnedTime = Long.toString(nanosecTime);
833a21aa 78
544fe9b7 79 // If our number has over 9 digits, just add a dot after the ninth digits
833a21aa 80 if ( returnedTime.length() > 9 ) {
3b38ea61 81 returnedTime = returnedTime.substring(0, returnedTime.length() - 9 ) + "." + returnedTime.substring( returnedTime.length() - 9 ); //$NON-NLS-1$
833a21aa 82 }
544fe9b7 83 // Otherwise, patch missing decimal with 0
833a21aa
WB
84 else {
85 int curSize = returnedTime.length();
86 for (int l=0; (curSize+l)< 9; l++) {
3b38ea61 87 returnedTime = "0" + returnedTime; //$NON-NLS-1$
833a21aa 88 }
3b38ea61 89 returnedTime = "0." + returnedTime; //$NON-NLS-1$
833a21aa
WB
90 }
91
92 return returnedTime;
93 }
94
544fe9b7 95 /**
1406f802 96 * Convert a String representing nanoseconds into a valid long.<p>
544fe9b7
WB
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 *
1406f802 103 * @return The converted nanoseconds time as long
544fe9b7 104 */
1406f802
WB
105 public static long convertStringToNanoseconds( String timeString ) {
106 long returnedNumber = 0L;
088c1d4e
WB
107
108 try {
109 // Avoid simple commat/dot mistake
3b38ea61 110 timeString = timeString.replace(",", "."); //$NON-NLS-1$ //$NON-NLS-2$
088c1d4e
WB
111
112 // If we have a dot, we have a decimal number to convert
3b38ea61 113 int dotPosition = timeString.indexOf("."); //$NON-NLS-1$
088c1d4e
WB
114
115 // If the user begun the line with a dot, we add a zero
116 if ( dotPosition == 0 ) {
3b38ea61 117 timeString = "0" + timeString; //$NON-NLS-1$
088c1d4e
WB
118 dotPosition = 1;
119 }
544fe9b7
WB
120
121 // If we found a dot, verify that we have 9 digits
088c1d4e
WB
122 if ( dotPosition != -1 ) {
123 int decimalNumber = (timeString.length() - dotPosition -1);
124
544fe9b7
WB
125 // If we have less than 9 digits, we fill with 0
126 if ( decimalNumber <= 9 ) {
1155ca9f 127 StringBuffer strBuffer = new StringBuffer(timeString);
088c1d4e 128 for ( int nbDec=decimalNumber; nbDec<9; nbDec++) {
3b38ea61 129 strBuffer.append("0"); //$NON-NLS-1$
088c1d4e 130 }
1155ca9f 131 timeString = strBuffer.toString();
088c1d4e 132 }
544fe9b7
WB
133 // We have OVER 9 digits, skip the useless part
134 else {
135 timeString = timeString.substring(dotPosition, 9);
136 }
088c1d4e
WB
137 }
138
139 // Conversion into decimal seconds
1406f802 140 double dblMaxTimerange = Double.parseDouble(timeString);
088c1d4e
WB
141 // Conversion into nanoseconds
142 returnedNumber = (long)(dblMaxTimerange * 1000000000.0);
143 }
144 catch (NumberFormatException e) {
3b38ea61 145 System.out.println("Warning : Could not convert string into nanoseconds (convertStringToLong)"); //$NON-NLS-1$
088c1d4e
WB
146 }
147
148 return returnedNumber;
149 }
150
544fe9b7
WB
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 */
1406f802 161 public static int getTextSizeInControl(Composite parent, String text) {
833a21aa
WB
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 }
544fe9b7 167 // Add an extra space in case there was trailing whitespace in the message
833a21aa
WB
168 textSize += graphicContext.getAdvanceWidth( ' ' );
169
170 return textSize;
171 }
6e512b93 172}
This page took 0.04562 seconds and 5 git commands to generate.