-package org.simantics.tests.modelled.ui;\r
-\r
-import java.text.DecimalFormat;\r
-\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.swt.graphics.Image;\r
-import org.eclipse.swt.widgets.Event;\r
-import org.simantics.scl.compiler.module.coverage.Coverage;\r
-\r
-public final class RedGreenBar {\r
-\r
- private static final int BORDER_LEFT = 2;\r
- private static final int BORDER_RIGHT = 10;\r
- private static final int BORDER_TOP = 3;\r
- private static final int BORDER_BOTTOM = 4;\r
-\r
- private static final String MAX_PERCENTAGE_STRING = new DecimalFormat("0.0 %").format(1.0);\r
- \r
- private static final ImageDescriptor redbar = Activator.getImageDescriptor("icons/redbar.gif"); //$NON-NLS-1$\r
- private static final ImageDescriptor greenbar = Activator.getImageDescriptor("icons/greenbar.gif"); //$NON-NLS-1$\r
- private static Image redbarIcon = Activator.createManagedImage(redbar);\r
- private static Image greenbarIcon = Activator.createManagedImage(greenbar);\r
- \r
- private RedGreenBar() {\r
- }\r
-\r
-// public static void draw(Event event, int columnWith, ICounter counter) {\r
-// draw(event, columnWith, counter, counter.getTotalCount());\r
-// }\r
-\r
- public static void draw(Event event, int columnWith, Coverage coverage) {\r
- int maxTotal = coverage.getTotalCodeSize();\r
- if (maxTotal == 0)\r
- return;\r
- final int maxWidth = getMaxWidth(event, columnWith);\r
- final int redLength = maxWidth * coverage.getMissedCodeSize() / maxTotal;\r
- bar(event, redbarIcon, 0, redLength);\r
- final int greenLength = maxWidth * coverage.getCoveredCodeSize() / maxTotal;\r
- bar(event, greenbarIcon, redLength, greenLength);\r
- }\r
-\r
- private static void bar(Event event, Image image, int xOffset, int width) {\r
- final int height = event.getBounds().height - BORDER_TOP - BORDER_BOTTOM;\r
- event.gc.drawImage(image, 0, 0, 1, 10, event.x + xOffset + BORDER_LEFT,\r
- event.y + BORDER_TOP, width, height);\r
- }\r
-\r
- private static int getMaxWidth(Event event, int columnWith) {\r
- final int textWidth = event.gc.textExtent(MAX_PERCENTAGE_STRING).x;\r
- final int max = columnWith - BORDER_LEFT - BORDER_RIGHT - textWidth;\r
- return Math.max(0, max);\r
- }\r
-\r
+package org.simantics.tests.modelled.ui;
+
+import java.text.DecimalFormat;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Event;
+import org.simantics.scl.compiler.module.coverage.Coverage;
+
+public final class RedGreenBar {
+
+ private static final int BORDER_LEFT = 2;
+ private static final int BORDER_RIGHT = 10;
+ private static final int BORDER_TOP = 3;
+ private static final int BORDER_BOTTOM = 4;
+
+ private static final String MAX_PERCENTAGE_STRING = new DecimalFormat("0.0 %").format(1.0);
+
+ private static final ImageDescriptor redbar = Activator.getImageDescriptor("icons/redbar.gif"); //$NON-NLS-1$
+ private static final ImageDescriptor greenbar = Activator.getImageDescriptor("icons/greenbar.gif"); //$NON-NLS-1$
+ private static Image redbarIcon = Activator.createManagedImage(redbar);
+ private static Image greenbarIcon = Activator.createManagedImage(greenbar);
+
+ private RedGreenBar() {
+ }
+
+// public static void draw(Event event, int columnWith, ICounter counter) {
+// draw(event, columnWith, counter, counter.getTotalCount());
+// }
+
+ public static void draw(Event event, int columnWith, Coverage coverage) {
+ int maxTotal = coverage.getTotalCodeSize();
+ if (maxTotal == 0)
+ return;
+ final int maxWidth = getMaxWidth(event, columnWith);
+ final int redLength = maxWidth * coverage.getMissedCodeSize() / maxTotal;
+ bar(event, redbarIcon, 0, redLength);
+ final int greenLength = maxWidth * coverage.getCoveredCodeSize() / maxTotal;
+ bar(event, greenbarIcon, redLength, greenLength);
+ }
+
+ private static void bar(Event event, Image image, int xOffset, int width) {
+ final int height = event.getBounds().height - BORDER_TOP - BORDER_BOTTOM;
+ event.gc.drawImage(image, 0, 0, 1, 10, event.x + xOffset + BORDER_LEFT,
+ event.y + BORDER_TOP, width, height);
+ }
+
+ private static int getMaxWidth(Event event, int columnWith) {
+ final int textWidth = event.gc.textExtent(MAX_PERCENTAGE_STRING).x;
+ final int max = columnWith - BORDER_LEFT - BORDER_RIGHT - textWidth;
+ return Math.max(0, max);
+ }
+
}
\ No newline at end of file