Bug 378401: Implementation of time graph widget.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / dialogs / TimeGraphLegend.java
index c8668b76def2a7580e8757595cca35176514c1ac..8d4cf0165dbf4fb4c4bbfbcd3163a59ce3093064 100644 (file)
@@ -15,19 +15,22 @@ package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs;
 \r
 import org.eclipse.jface.dialogs.IDialogConstants;\r
 import org.eclipse.jface.dialogs.TitleAreaDialog;\r
+import org.eclipse.jface.resource.JFaceResources;\r
+import org.eclipse.jface.resource.LocalResourceManager;\r
 import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphProvider.StateColor;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;\r
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;\r
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.graphics.Color;\r
 import org.eclipse.swt.graphics.GC;\r
+import org.eclipse.swt.graphics.RGB;\r
 import org.eclipse.swt.graphics.Rectangle;\r
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Canvas;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Display;\r
 import org.eclipse.swt.widgets.Event;\r
 import org.eclipse.swt.widgets.Group;\r
 import org.eclipse.swt.widgets.Label;\r
@@ -37,22 +40,17 @@ import org.eclipse.swt.widgets.Shell;
 \r
 public class TimeGraphLegend extends TitleAreaDialog {\r
 \r
-    public static final int interactionColors[] = {\r
-        TimeGraphColorScheme.TI_START_THREAD,\r
-        TimeGraphColorScheme.TI_NOTIFY_JOINED, TimeGraphColorScheme.TI_NOTIFY,\r
-        TimeGraphColorScheme.TI_INTERRUPT, TimeGraphColorScheme.TI_HANDOFF_LOCK };\r
+    private ITimeGraphPresentationProvider provider;\r
+    private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());\r
 \r
-    protected TimeGraphColorScheme colors;\r
-    private ITimeGraphProvider ifUtil;\r
-\r
-    public static void open(Shell parent, ITimeGraphProvider rifUtil) {\r
-        (new TimeGraphLegend(parent, rifUtil)).open();\r
+    public static void open(Shell parent, ITimeGraphPresentationProvider provider) {\r
+        (new TimeGraphLegend(parent, provider)).open();\r
     }\r
 \r
-    public TimeGraphLegend(Shell parent, ITimeGraphProvider rifUtil) {\r
+    public TimeGraphLegend(Shell parent, ITimeGraphPresentationProvider provider) {\r
         super(parent);\r
-        colors = new TimeGraphColorScheme();\r
-        this.ifUtil = rifUtil;\r
+        this.provider = provider;\r
+        this.setShellStyle(getShellStyle());\r
     }\r
 \r
     @Override\r
@@ -66,19 +64,18 @@ public class TimeGraphLegend extends TitleAreaDialog {
         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
         composite.setLayoutData(gd);\r
 \r
-        createThreadStatesGroup(composite);\r
+        createStatesGroup(composite);\r
 \r
-        setMessage(Messages.TmfTimeLegend_LEGEND);\r
-        setTitle(Messages.TmfTimeLegend_TRACE_STATES_TITLE);\r
+        setTitle(Messages.TmfTimeLegend_LEGEND);\r
         setDialogHelpAvailable(false);\r
         setHelpAvailable(false);\r
 \r
         return composite;\r
     }\r
 \r
-    private void createThreadStatesGroup(Composite composite) {\r
+    private void createStatesGroup(Composite composite) {\r
         Group gs = new Group(composite, SWT.NONE);\r
-        gs.setText(Messages.TmfTimeLegend_TRACE_STATES);\r
+        gs.setText(provider.getStateTypeName());\r
         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
         gs.setLayoutData(gd);\r
 \r
@@ -88,35 +85,35 @@ public class TimeGraphLegend extends TitleAreaDialog {
         layout.marginBottom = 10;\r
         gs.setLayout(layout);\r
 \r
-        // Go through all the defined colors and only add the ones you need\r
-        // This will not handle several colors assigned to a color, we have \r
-        // 16 mil colors, and should not pick two to mean the same thing. \r
-        for (int i = 0; i <  TimeGraphColorScheme.getStateColors().length; i++) {\r
-            //Get the color enum related to the index\r
-            StateColor stateColor = TimeGraphColorScheme.getStateColors()[i];\r
+        // Go through all the defined pairs of state color and state name and display them\r
+        StateItem[] stateItems = provider.getStateTable();\r
+        for (int i = 0; i < stateItems.length; i++) {\r
+            //Get the color related to the index\r
+            RGB rgb = stateItems[i].getStateColor();\r
+\r
             //Get the given name, provided by the interface to the application\r
-            String stateName = ifUtil.getStateName(stateColor);\r
-            if( stateName != "Not mapped" ) { //$NON-NLS-1$\r
-                Bar bar = new Bar(gs, i);\r
-                gd = new GridData();\r
-                gd.widthHint = 40;\r
-                gd.heightHint = 20;\r
-                gd.verticalIndent = 8;\r
-                bar.setLayoutData(gd);\r
-                Label name = new Label(gs, SWT.NONE);\r
-                name.setText(stateName);\r
-                gd = new GridData();\r
-                gd.horizontalIndent = 10;\r
-                gd.verticalIndent = 8;\r
-                name.setLayoutData(gd);\r
-            }\r
+            String stateName = stateItems[i].getStateString();\r
+\r
+            // draw color with name\r
+            Bar bar = new Bar(gs, rgb);\r
+            gd = new GridData();\r
+            gd.widthHint = 40;\r
+            gd.heightHint = 20;\r
+            gd.verticalIndent = 8;\r
+            bar.setLayoutData(gd);\r
+            Label name = new Label(gs, SWT.NONE);\r
+            name.setText(stateName);\r
+            gd = new GridData();\r
+            gd.horizontalIndent = 10;\r
+            gd.verticalIndent = 8;\r
+            name.setLayoutData(gd);\r
         }\r
     }\r
 \r
     @Override\r
     protected void configureShell(Shell shell) {\r
         super.configureShell(shell);\r
-        shell.setText(Messages.TmfTimeLegend_WINDOW_TITLE);\r
+        shell.setText(Messages.TmfTimeLegend_TRACE_STATES_TITLE);\r
     }\r
 \r
     @Override\r
@@ -128,10 +125,10 @@ public class TimeGraphLegend extends TitleAreaDialog {
     class Bar extends Canvas {\r
         private Color color;\r
 \r
-        public Bar(Composite parent, int colorIdx) {\r
+        public Bar(Composite parent, RGB rgb) {\r
             super(parent, SWT.NONE);\r
 \r
-            color = colors.getColor(colorIdx);\r
+            color = fResourceManager.createColor(rgb);\r
             addListener(SWT.Paint, new Listener() {\r
                 @Override\r
                 public void handleEvent(Event event) {\r
@@ -144,73 +141,16 @@ public class TimeGraphLegend extends TitleAreaDialog {
             Rectangle r = getClientArea();\r
             gc.setBackground(color);\r
             gc.fillRectangle(r);\r
-            gc.setForeground(colors.getColor(TimeGraphColorScheme.BLACK));\r
+            gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));\r
             gc.drawRectangle(0, 0, r.width - 1, r.height - 1);\r
         }\r
-    }\r
-\r
-    class Arrow extends Canvas {\r
-        public final static int HEIGHT = 12;\r
-        public final static int DX = 3;\r
-\r
-        private Color color;\r
-\r
-        public Arrow(Composite parent, int colorIdx) {\r
-            super(parent, SWT.NONE);\r
 \r
-            color = colors.getColor(colorIdx);\r
-            addListener(SWT.Paint, new Listener() {\r
-                @Override\r
-                public void handleEvent(Event event) {\r
-                    draw(event.gc);\r
-                }\r
-            });\r
+        @Override\r
+        public void dispose() {\r
+            super.dispose();\r
+            color.dispose();\r
         }\r
 \r
-        private void draw(GC gc) {\r
-            Rectangle r = getClientArea();\r
-            gc.setForeground(color);\r
-\r
-            int y0, y1;\r
-            if (r.height > HEIGHT) {\r
-                y0 = (r.height - HEIGHT) / 2;\r
-                y1 = y0 + HEIGHT;\r
-            } else {\r
-                y0 = 0;\r
-                y1 = r.height;\r
-            }\r
-\r
-            gc.drawLine(DX, y0, DX, y1);\r
-\r
-            gc.drawLine(0, y0 + 3, DX, y0);\r
-            gc.drawLine(2 * DX, y0 + 3, DX, y0);\r
-        }\r
     }\r
 \r
-    class Mark extends Canvas {\r
-        public final static int DX = 3;\r
-\r
-        private Color color;\r
-\r
-        public Mark(Composite parent, int colorIdx) {\r
-            super(parent, SWT.NONE);\r
-\r
-            color = colors.getColor(colorIdx);\r
-            addListener(SWT.Paint, new Listener() {\r
-                @Override\r
-                public void handleEvent(Event event) {\r
-                    draw(event.gc);\r
-                }\r
-            });\r
-        }\r
-\r
-        private void draw(GC gc) {\r
-            Rectangle r = getClientArea();\r
-            gc.setBackground(color);\r
-\r
-            int y = (r.height - DX) / 2;\r
-            int c[] = { 0, y, DX, y + DX, 2 * DX, y };\r
-            gc.fillPolygon(c);\r
-        }\r
-    }\r
 }\r
This page took 0.028508 seconds and 5 git commands to generate.