--- a/sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/internal/ui/util/GraphUtils.java Tue Aug 24 12:10:03 2010 +0300
+++ b/sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/internal/ui/util/GraphUtils.java Tue Aug 24 12:16:27 2010 +0300
@@ -15,6 +15,7 @@
*
*/
package com.nokia.s60tools.analyzetool.internal.ui.util;
+
import java.text.DecimalFormat;
import org.eclipse.swt.SWT;
@@ -25,7 +26,7 @@
/**
* Utilities class for the graph
- *
+ *
*/
public final class GraphUtils {
private static final String MILLISECONDS = "ms"; //$NON-NLS-1$
@@ -35,17 +36,17 @@
private static final String DAYS = "d"; //$NON-NLS-1$
private static final String SPACE = " "; //$NON-NLS-1$
private static final int KILOBYTE = 1024;
- private static final int MEGABYTE = 1024*1024;
- private static final int GIGABYTE = 1024*1024*1024;
+ private static final int MEGABYTE = 1024 * 1024;
+ private static final int GIGABYTE = 1024 * 1024 * 1024;
private static final DecimalFormat MB_FORMAT = new DecimalFormat("#####.0");
- private static final DecimalFormat BYTES_FORMAT = new DecimalFormat("#####.##");
-
-
- //make constructor private so class doesn't get instantiated
- private GraphUtils(){
- //do nothing by design
+ private static final DecimalFormat BYTES_FORMAT = new DecimalFormat(
+ "#####.##");
+
+ // make constructor private so class doesn't get instantiated
+ private GraphUtils() {
+ // do nothing by design
}
-
+
/**
*
* @param aBytes
@@ -100,78 +101,88 @@
return bytes;
}
+
/**
* Draws the given String and an arrow on an image and returns it.
- * @param name The string to display
+ *
+ * @param name
+ * The string to display
* @return the newly created image
*/
- public static Image getVerticalLabel(final String name)
- {
+ public static Image getVerticalLabel(final String name) {
final Image image = new Image(Display.getDefault(), 90, 14);
- final GC gc = new GC(image);
- final Font font = new Font(Display.getDefault(), Display.getDefault().getSystemFont().getFontData()[0].getName(), 9, SWT.BOLD);
- gc.setFont(font);
- gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
- gc.fillRectangle(0, 0, 90, 15);
- gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
- gc.drawText(name + " ->", 0, 0, true);
- font.dispose();
- gc.dispose();
- return image;
+ final GC gc = new GC(image);
+ final Font font = new Font(Display.getDefault(), Display.getDefault()
+ .getSystemFont().getFontData()[0].getName(), 9, SWT.BOLD);
+ gc.setFont(font);
+ gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
+ gc.fillRectangle(0, 0, 90, 15);
+ gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+ gc.drawText(name + " ->", 0, 0, true);
+ font.dispose();
+ gc.dispose();
+ return image;
}
+
/**
- * Calculates the next larger or smaller scale. Used typically when zooming in / out.
- * @param scale the current scale
- * @param bigger flag to indicate whether to increase or decrease the scale
+ * Calculates the next larger or smaller scale. Used typically when zooming
+ * in / out.
+ *
+ * @param scale
+ * the current scale
+ * @param bigger
+ * flag to indicate whether to increase or decrease the scale
* @return the new scale
*/
- public static double nextScale(final double scale, final boolean bigger)
- {
- double logScale = Math.log10(scale);
- double floorLogScale = Math.floor(Math.log10(scale));
- double mostSignificantDigit = Math.rint(Math.pow(10, (logScale - floorLogScale)));
- double powerOfTen = Math.pow(10, floorLogScale);
-
- if (bigger) {
- if (mostSignificantDigit < 2) {
- mostSignificantDigit = 2;
- } else if (mostSignificantDigit < 5) {
- mostSignificantDigit = 5;
- } else {
- mostSignificantDigit = 10;
- }
- } else {
- if (mostSignificantDigit > 5) {
- mostSignificantDigit = 5;
- } else if (mostSignificantDigit > 2) {
- mostSignificantDigit = 2;
- } else if (mostSignificantDigit > 1) {
- mostSignificantDigit = 1;
- } else {
- mostSignificantDigit = 0.5;
- }
- }
+ public static double nextScale(final double scale, final boolean bigger) {
+ double logScale = Math.log10(scale);
+ double floorLogScale = Math.floor(Math.log10(scale));
+ double mostSignificantDigit = Math.rint(Math.pow(10,
+ (logScale - floorLogScale)));
+ double powerOfTen = Math.pow(10, floorLogScale);
- double result = mostSignificantDigit * powerOfTen;
-
- if (result < 0.1)
- result = 0.1;
+ if (bigger) {
+ if (mostSignificantDigit < 2) {
+ mostSignificantDigit = 2;
+ } else if (mostSignificantDigit < 5) {
+ mostSignificantDigit = 5;
+ } else {
+ mostSignificantDigit = 10;
+ }
+ } else {
+ if (mostSignificantDigit > 5) {
+ mostSignificantDigit = 5;
+ } else if (mostSignificantDigit > 2) {
+ mostSignificantDigit = 2;
+ } else if (mostSignificantDigit > 1) {
+ mostSignificantDigit = 1;
+ } else {
+ mostSignificantDigit = 0.5;
+ }
+ }
- return result;
- }
+ double result = mostSignificantDigit * powerOfTen;
+
+ if (result < 0.1)
+ result = 0.1;
+
+ return result;
+ }
+
/**
- * Returns the given amount of microseconds as user-friendly formatted string,
- * for example "3d 5h 20min 2d 3ms"
- * The returned string can be quite long. Use {@link #renderTime(double)} for
- * a short version
- * @param aTotalMicroSeconds the given amount of microseconds to convert
+ * Returns the given amount of microseconds as user-friendly formatted
+ * string, for example "3d 5h 20min 2d 3ms" The returned string can be quite
+ * long. Use {@link #renderTime(double)} for a short version
+ *
+ * @param aTotalMicroSeconds
+ * the given amount of microseconds to convert
* @return the formatted time string
*/
@SuppressWarnings("nls")
- public static String renderTime(final double aTotalMicroSeconds) {
+ public static String renderTime(final double aTotalMicroSeconds) {
double totalMicroSeconds = aTotalMicroSeconds;
long days, hours, minutes, seconds, ms;
- days= (long) (totalMicroSeconds / 86400000000L);
+ days = (long) (totalMicroSeconds / 86400000000L);
totalMicroSeconds -= days * 86400000000L;
hours = (long) (totalMicroSeconds / 3600000000L);
totalMicroSeconds -= hours * 3600000000L;
@@ -179,53 +190,55 @@
totalMicroSeconds -= minutes * 60000000;
seconds = (long) totalMicroSeconds / 1000000;
totalMicroSeconds -= seconds * 1000000;
- ms = (long)totalMicroSeconds / 1000;
-
- StringBuilder result= new StringBuilder();
- if(days > 0) {
+ ms = (long) totalMicroSeconds / 1000;
+
+ StringBuilder result = new StringBuilder();
+ if (days > 0) {
result.append(days).append(DAYS);
- }
- if(hours > 0) {
- if (result.length() > 0){
+ }
+ if (hours > 0) {
+ if (result.length() > 0) {
result.append(SPACE);
}
result.append(hours).append(HOURS);
- }
- if(minutes > 0) {
- if (result.length() > 0){
+ }
+ if (minutes > 0) {
+ if (result.length() > 0) {
result.append(SPACE);
}
result.append(minutes).append(MINUTES);
- }
- if(seconds > 0) {
- if (result.length() > 0){
+ }
+ if (seconds > 0) {
+ if (result.length() > 0) {
result.append(SPACE);
}
result.append(seconds).append(SECONDS);
}
- if (ms > 0){
- if (result.length() > 0){
+ if (ms > 0) {
+ if (result.length() > 0) {
result.append(SPACE);
}
result.append(ms).append(MILLISECONDS);
}
-
- if (result.length() == 0){
- result.append(0).append(MILLISECONDS);
+
+ if (result.length() == 0) {
+ result.append(0).append(MILLISECONDS);
}
return result.toString();
}
-
+
/**
- * Formats the given number of bytes into an easily readable format
- * @param bytes The number of bytes to format
- * @return String containing a formatted version of the input data
+ * Formats the given number of bytes into an easily readable format
+ *
+ * @param bytes
+ * The number of bytes to format
+ * @return String containing a formatted version of the input data
*/
public static String formatBytes(final double bytes) {
String scaledY;
if (bytes < 10000) {
- scaledY = BYTES_FORMAT.format((long)bytes) + " B";
+ scaledY = BYTES_FORMAT.format((long) bytes) + " B";
} else if (bytes <= 500 * 1024) {
scaledY = BYTES_FORMAT.format(bytes / 1024) + " KB";
} else {
@@ -235,63 +248,67 @@
}
/**
- * Formats given time value to String with units. The resulting String
- * is formatted quite short, e.g.:
- * <br>"30s"
- * <br>"1m 30s"
- * <br>"40m"
- * <br>"1h 30m"
- * @param aTime Time in microseconds
+ * Formats given time value to String with units. The resulting String is
+ * formatted quite short, e.g.: <br>
+ * "30s" <br>
+ * "1m 30s" <br>
+ * "40m" <br>
+ * "1h 30m"
+ *
+ * @param aTime
+ * Time in microseconds
* @return time String with units
*/
public static String getTimeStringWithUnits(final double aTime) {
- long time = (long) aTime / 1000; //convert from microseconds to milliseconds
- String formatted ;
-
- //If we have only less than 10 seconds, show seconds and milliseconds
- if(time < 6000){
- //"s.S's'"
+ long time = (long) aTime / 1000; // convert from microseconds to
+ // milliseconds
+ String formatted;
+
+ // If we have only less than 10 seconds, show seconds and milliseconds
+ if (time < 6000) {
+ // "s.S's'"
int seconds = (int) time / 1000;
long ms = time - (seconds * 1000);
- if (ms == 0 ){
- formatted = String.format("%ds", seconds);
+ if (ms == 0) {
+ formatted = String.format("%ds", seconds);
} else {
- formatted = String.format("%ds%03d", seconds, ms);
+ formatted = String.format("%ds%03d", seconds, ms);
}
}
- //If we have 10s or more, but less than 1min, show seconds
- else if(time < 60000){
- //"s's'"
+ // If we have 10s or more, but less than 1min, show seconds
+ else if (time < 60000) {
+ // "s's'"
formatted = String.format("%ds", (int) time / 1000);
}
- //If we have more than one minute, but less than one 5min, showing the seconds as well
- else if(time >= 60000 && time < (60000*5)){
- //"m'm' s's'"
+ // If we have more than one minute, but less than one 5min, showing the
+ // seconds as well
+ else if (time >= 60000 && time < (60000 * 5)) {
+ // "m'm' s's'"
long minutes = (int) time / 60000;
long seconds = (time - minutes * 60000) / 1000;
- if (seconds == 0 ){
+ if (seconds == 0) {
formatted = String.format("%dm", minutes);
} else {
formatted = String.format("%dm %ds", minutes, seconds);
}
}
- //If we have more than five minute, but less than one hour, we show only minutes
- else if(time >= (60000*5) && time < (60*60*1000)){
- //"m'm'"
+ // If we have more than five minute, but less than one hour, we show
+ // only minutes
+ else if (time >= (60000 * 5) && time < (60 * 60 * 1000)) {
+ // "m'm'"
formatted = String.format("%dm", (int) time / 60000);
- }
- else{
- //"H'h' m'm'"
+ } else {
+ // "H'h' m'm'"
long hours = (time / 3600000);
long minutes = (time - hours * 3600000) / 60000;
-
- if (minutes == 0){
- formatted = String.format("%dh", hours);
+
+ if (minutes == 0) {
+ formatted = String.format("%dh", hours);
} else {
- formatted = String.format("%dh %dm", hours, minutes);
+ formatted = String.format("%dh %dm", hours, minutes);
}
- }
+ }
return formatted;
}
}