-/*******************************************************************************\r
- * Copyright (c) 2009, 2012 Ericsson.\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Alvaro Sanchez-Leon - Initial API and implementation\r
- * Patrick Tasse - Refactoring\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs;\r
-\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.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
-import org.eclipse.swt.widgets.Listener;\r
-import org.eclipse.swt.widgets.Shell;\r
-\r
-/**\r
- * Legend for the colors used in the time graph view\r
- *\r
- * @version 1.0\r
- * @author Alvaro Sanchez-Leon\r
- * @author Patrick Tasse\r
- */\r
-public class TimeGraphLegend extends TitleAreaDialog {\r
-\r
- private final ITimeGraphPresentationProvider provider;\r
- private final LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());\r
-\r
- /**\r
- * Open the time graph legend window\r
- *\r
- * @param parent\r
- * The parent shell\r
- * @param provider\r
- * The presentation provider\r
- */\r
- public static void open(Shell parent, ITimeGraphPresentationProvider provider) {\r
- (new TimeGraphLegend(parent, provider)).open();\r
- }\r
-\r
- /**\r
- * Standard constructor\r
- *\r
- * @param parent\r
- * The parent shell\r
- * @param provider\r
- * The presentation provider\r
- */\r
- public TimeGraphLegend(Shell parent, ITimeGraphPresentationProvider provider) {\r
- super(parent);\r
- this.provider = provider;\r
- this.setShellStyle(getShellStyle());\r
- }\r
-\r
- @Override\r
- protected Control createDialogArea(Composite parent) {\r
- Composite dlgArea = (Composite) super.createDialogArea(parent);\r
- Composite composite = new Composite(dlgArea, SWT.NONE);\r
-\r
- GridLayout layout = new GridLayout();\r
- layout.numColumns = 2;\r
- composite.setLayout(layout);\r
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
- composite.setLayoutData(gd);\r
-\r
- createStatesGroup(composite);\r
-\r
- setTitle(Messages.TmfTimeLegend_LEGEND);\r
- setDialogHelpAvailable(false);\r
- setHelpAvailable(false);\r
-\r
- return composite;\r
- }\r
-\r
- private void createStatesGroup(Composite composite) {\r
- Group gs = new Group(composite, SWT.NONE);\r
- gs.setText(provider.getStateTypeName() + " " + Messages.TmfTimeLegend_StateTypeName); //$NON-NLS-1$\r
- GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);\r
- gs.setLayoutData(gd);\r
-\r
- GridLayout layout = new GridLayout();\r
- layout.numColumns = 2;\r
- layout.marginWidth = 20;\r
- layout.marginBottom = 10;\r
- gs.setLayout(layout);\r
-\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 = 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_TRACE_STATES_TITLE);\r
- }\r
-\r
- @Override\r
- protected void createButtonsForButtonBar(Composite parent) {\r
- createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,\r
- true);\r
- }\r
-\r
- class Bar extends Canvas {\r
- private final Color color;\r
-\r
- public Bar(Composite parent, RGB rgb) {\r
- super(parent, SWT.NONE);\r
-\r
- color = fResourceManager.createColor(rgb);\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
- gc.fillRectangle(r);\r
- gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));\r
- gc.drawRectangle(0, 0, r.width - 1, r.height - 1);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- super.dispose();\r
- color.dispose();\r
- }\r
-\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2009, 2012 Ericsson.
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alvaro Sanchez-Leon - Initial API and implementation
+ * Patrick Tasse - Refactoring
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Legend for the colors used in the time graph view
+ *
+ * @version 1.0
+ * @author Alvaro Sanchez-Leon
+ * @author Patrick Tasse
+ */
+public class TimeGraphLegend extends TitleAreaDialog {
+
+ private final ITimeGraphPresentationProvider provider;
+ private final LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
+
+ /**
+ * Open the time graph legend window
+ *
+ * @param parent
+ * The parent shell
+ * @param provider
+ * The presentation provider
+ */
+ public static void open(Shell parent, ITimeGraphPresentationProvider provider) {
+ (new TimeGraphLegend(parent, provider)).open();
+ }
+
+ /**
+ * Standard constructor
+ *
+ * @param parent
+ * The parent shell
+ * @param provider
+ * The presentation provider
+ */
+ public TimeGraphLegend(Shell parent, ITimeGraphPresentationProvider provider) {
+ super(parent);
+ this.provider = provider;
+ this.setShellStyle(getShellStyle());
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite dlgArea = (Composite) super.createDialogArea(parent);
+ Composite composite = new Composite(dlgArea, SWT.NONE);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite.setLayoutData(gd);
+
+ createStatesGroup(composite);
+
+ setTitle(Messages.TmfTimeLegend_LEGEND);
+ setDialogHelpAvailable(false);
+ setHelpAvailable(false);
+
+ return composite;
+ }
+
+ private void createStatesGroup(Composite composite) {
+ Group gs = new Group(composite, SWT.NONE);
+ String stateTypeName = provider.getStateTypeName();
+ StringBuffer buffer = new StringBuffer();
+ if (!stateTypeName.isEmpty()) {
+ buffer.append(stateTypeName);
+ buffer.append(" "); //$NON-NLS-1$
+ }
+ buffer.append(Messages.TmfTimeLegend_StateTypeName);
+ gs.setText(buffer.toString());
+
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gs.setLayoutData(gd);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginWidth = 20;
+ layout.marginBottom = 10;
+ gs.setLayout(layout);
+
+ // Go through all the defined pairs of state color and state name and display them.
+ StateItem[] stateItems = provider.getStateTable();
+ for (int i = 0; i < stateItems.length; i++) {
+ //Get the color related to the index
+ RGB rgb = stateItems[i].getStateColor();
+
+ //Get the given name, provided by the interface to the application
+ String stateName = stateItems[i].getStateString();
+
+ // draw color with name
+ Bar bar = new Bar(gs, rgb);
+ gd = new GridData();
+ gd.widthHint = 40;
+ gd.heightHint = 20;
+ gd.verticalIndent = 8;
+ bar.setLayoutData(gd);
+ Label name = new Label(gs, SWT.NONE);
+ name.setText(stateName);
+ gd = new GridData();
+ gd.horizontalIndent = 10;
+ gd.verticalIndent = 8;
+ name.setLayoutData(gd);
+ }
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(Messages.TmfTimeLegend_TRACE_STATES_TITLE);
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
+ true);
+ }
+
+ class Bar extends Canvas {
+ private final Color color;
+
+ public Bar(Composite parent, RGB rgb) {
+ super(parent, SWT.NONE);
+
+ color = fResourceManager.createColor(rgb);
+ addListener(SWT.Paint, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ draw(event.gc);
+ }
+ });
+ }
+
+ private void draw(GC gc) {
+ Rectangle r = getClientArea();
+ gc.setBackground(color);
+ gc.fillRectangle(r);
+ gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+ gc.drawRectangle(0, 0, r.width - 1, r.height - 1);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ color.dispose();
+ }
+
+ }
+
+}