From ca13a91c80a4e2260e81ec723a07ca673ad260b4 Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Mon, 14 Mar 2011 11:00:26 -0400 Subject: [PATCH] Fix for Bug338155 --- .../META-INF/MANIFEST.MF | 1 + .../plugin.properties | 1 + org.eclipse.linuxtools.tmf.ui/plugin.xml | 9 + .../tmf/ui/views/colors/ColorSetting.java | 145 +++++ .../ui/views/colors/ColorSettingsManager.java | 90 +++ .../tmf/ui/views/colors/ColorSettingsXML.java | 191 ++++++ .../tmf/ui/views/colors/ColorsView.java | 552 ++++++++++++++++++ .../views/colors/IColorSettingsListener.java | 18 + .../tmf/ui/views/colors/TickColorDialog.java | 154 +++++ 9 files changed, 1161 insertions(+) create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSetting.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsManager.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsXML.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/IColorSettingsListener.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index d5e4c6b874..4d77a653ec 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -23,6 +23,7 @@ Export-Package: org.eclipse.linuxtools.tmf.ui, org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model, org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets, org.eclipse.linuxtools.tmf.ui.views, + org.eclipse.linuxtools.tmf.ui.views.colors, org.eclipse.linuxtools.tmf.ui.views.project, org.eclipse.linuxtools.tmf.ui.views.timechart, org.eclipse.linuxtools.tmf.ui.widgets diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.properties b/org.eclipse.linuxtools.tmf.ui/plugin.properties index a479d9bcc2..8ca37b6b44 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.properties +++ b/org.eclipse.linuxtools.tmf.ui/plugin.properties @@ -6,6 +6,7 @@ Bundle-Name = Tracing and Monitoring Framework (TMF) UI (Incubation) views.category.name = TMF project.view.name = Projects events.view.name = Events +colors.view.name = Colors timechart.view.name = Time Chart events.editor.name = Events diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.xml b/org.eclipse.linuxtools.tmf.ui/plugin.xml index 652c159260..acf5a7d5eb 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui/plugin.xml @@ -34,6 +34,15 @@ name="%timechart.view.name" restorable="true"> + + diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSetting.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSetting.java new file mode 100644 index 0000000000..bd6d772e1d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSetting.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.colors; + +import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.themes.ColorUtil; + +public class ColorSetting { + + private RGB fForegroundRGB; + private RGB fBackgroundRGB; + private Color fForegroundColor; + private Color fBackgroundColor; + private Color fDimmedForegroundColor; + private Color fDimmedBackgroundColor; + private int fTickColorIndex; + private ITmfFilterTreeNode fFilter; + + public ColorSetting(RGB foreground, RGB background, int tickColorIndex, ITmfFilterTreeNode filter) { + fForegroundRGB = foreground; + fBackgroundRGB = background; + fTickColorIndex = tickColorIndex; + fFilter = filter; + Display display = Display.getDefault(); + fForegroundColor = new Color(display, fForegroundRGB); + fBackgroundColor = new Color(display, fBackgroundRGB); + fDimmedForegroundColor = new Color(display, ColorUtil.blend( + fForegroundRGB, fBackgroundRGB)); + fDimmedBackgroundColor = new Color(display, ColorUtil.blend( + fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); + } + + /** + * @return the foreground + */ + public RGB getForegroundRGB() { + return fForegroundRGB; + } + + /** + * @param foreground the foreground to set + */ + public void setForegroundRGB(RGB foreground) { + fForegroundRGB = foreground; + fForegroundColor.dispose(); + fDimmedForegroundColor.dispose(); + Display display = Display.getDefault(); + fForegroundColor = new Color(display, fForegroundRGB); + fDimmedForegroundColor = new Color(display, ColorUtil.blend( + fForegroundRGB, fBackgroundRGB)); + } + + /** + * @return the background + */ + public RGB getBackgroundRGB() { + return fBackgroundRGB; + } + + /** + * @param background the background to set + */ + public void setBackgroundRGB(RGB background) { + fBackgroundRGB = background; + fBackgroundColor.dispose(); + fDimmedBackgroundColor.dispose(); + Display display = Display.getDefault(); + fBackgroundColor = new Color(display, fBackgroundRGB); + fDimmedBackgroundColor = new Color(display, ColorUtil.blend( + fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); + } + + /** + * @return the tick color index (0-15) + * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme + */ + public int getTickColorIndex() { + return fTickColorIndex; + } + + /** + * @param tickColorIndex the tick color index to set (0-15) + * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme + */ + public void setTickColorIndex(int tickColorIndex) { + fTickColorIndex = tickColorIndex; + } + + /** + * @return the filter + */ + public ITmfFilterTreeNode getFilter() { + return fFilter; + } + + /** + * @param filter the filter to set + */ + public void setFilter(ITmfFilterTreeNode filter) { + fFilter = filter; + } + + /** + * @return the foreground color + */ + public Color getForegroundColor() { + return fForegroundColor; + } + + /** + * @return the background color + */ + public Color getBackgroundColor() { + return fBackgroundColor; + } + + /** + * @return the dimmed foreground color + */ + public Color getDimmedForegroundColor() { + return fDimmedForegroundColor; + } + + /** + * @return the dimmed background color + */ + public Color getDimmedBackgroundColor() { + return fDimmedBackgroundColor; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsManager.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsManager.java new file mode 100644 index 0000000000..b4c68621a6 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsManager.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.colors; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; +import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; + +public class ColorSettingsManager { + + private static final String COLOR_SETTINGS_FILE_NAME = "color_settings.xml"; //$NON-NLS-1$ + private static final String COLOR_SETTINGS_PATH_NAME = + TmfUiPlugin.getDefault().getStateLocation().addTrailingSeparator().append(COLOR_SETTINGS_FILE_NAME).toString(); + private static final ColorSetting DEFAULT_COLOR_SETTING = new ColorSetting( + Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), + Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), + TraceColorScheme.BLACK_STATE, + null); + public static final int PRIORITY_NONE = Integer.MAX_VALUE; + + private static ColorSetting[] fColorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME); + private static ArrayList fListeners = new ArrayList(); + + public static ColorSetting[] getColorSettings() { + return fColorSettings; + } + + public static void setColorSettings(ColorSetting[] colorSettings) { + fColorSettings = colorSettings; + ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, fColorSettings); + fireColorSettingsChanged(); + } + + public static ColorSetting getColorSetting(TmfEvent event) { + for (int i = 0; i < fColorSettings.length; i++) { + ColorSetting colorSetting = fColorSettings[i]; + if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) { + return colorSetting; + } + } + return DEFAULT_COLOR_SETTING; + } + + public static int getColorSettingPriority(TmfEvent event) { + for (int i = 0; i < fColorSettings.length; i++) { + ColorSetting colorSetting = fColorSettings[i]; + if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) { + return i; + } + } + return PRIORITY_NONE; + } + + public static ColorSetting getColorSetting(int priority) { + if (priority < fColorSettings.length) { + return fColorSettings[priority]; + } + return DEFAULT_COLOR_SETTING; + } + + public static void addColorSettingsListener(IColorSettingsListener listener) { + if (! fListeners.contains(listener)) { + fListeners.add(listener); + } + } + + public static void removeColorSettingsListener(IColorSettingsListener listener) { + fListeners.remove(listener); + } + + private static void fireColorSettingsChanged() { + for (IColorSettingsListener listener : fListeners) { + listener.colorSettingsChanged(fColorSettings); + } + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsXML.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsXML.java new file mode 100644 index 0000000000..3e90113aae --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorSettingsXML.java @@ -0,0 +1,191 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.colors; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.linuxtools.tmf.filter.model.ITmfFilterTreeNode; +import org.eclipse.linuxtools.tmf.filter.xml.TmfFilterContentHandler; +import org.eclipse.linuxtools.tmf.filter.xml.TmfFilterXMLWriter; +import org.eclipse.swt.graphics.RGB; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.DefaultHandler; + +public class ColorSettingsXML { + + private static final String COLOR_SETTINGS_TAG = "COLOR_SETTINGS"; //$NON-NLS-1$ + private static final String COLOR_SETTING_TAG = "COLOR_SETTING"; //$NON-NLS-1$ + private static final String FG_TAG = "FG"; //$NON-NLS-1$ + private static final String BG_TAG = "BG"; //$NON-NLS-1$ + private static final String R_ATTR = "R"; //$NON-NLS-1$ + private static final String G_ATTR = "G"; //$NON-NLS-1$ + private static final String B_ATTR = "B"; //$NON-NLS-1$ + private static final String TICK_COLOR_TAG = "TICK_COLOR"; //$NON-NLS-1$ + private static final String INDEX_ATTR = "INDEX"; //$NON-NLS-1$ + private static final String FILTER_TAG = "FILTER"; //$NON-NLS-1$ + + public static void save(String pathName, ColorSetting[] colorSettings) { + try { + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + Document document = documentBuilder.newDocument(); + + Element rootElement = document.createElement(COLOR_SETTINGS_TAG); + document.appendChild(rootElement); + + for (ColorSetting colorSetting : colorSettings) { + Element colorSettingElement = document.createElement(COLOR_SETTING_TAG); + rootElement.appendChild(colorSettingElement); + + Element fgElement = document.createElement(FG_TAG); + colorSettingElement.appendChild(fgElement); + RGB foreground = colorSetting.getForegroundRGB(); + fgElement.setAttribute(R_ATTR, Integer.toString(foreground.red)); + fgElement.setAttribute(G_ATTR, Integer.toString(foreground.green)); + fgElement.setAttribute(B_ATTR, Integer.toString(foreground.blue)); + + Element bgElement = document.createElement(BG_TAG); + colorSettingElement.appendChild(bgElement); + RGB background = colorSetting.getBackgroundRGB(); + bgElement.setAttribute(R_ATTR, Integer.toString(background.red)); + bgElement.setAttribute(G_ATTR, Integer.toString(background.green)); + bgElement.setAttribute(B_ATTR, Integer.toString(background.blue)); + + Element tickColorElement = document.createElement(TICK_COLOR_TAG); + colorSettingElement.appendChild(tickColorElement); + int index = colorSetting.getTickColorIndex(); + tickColorElement.setAttribute(INDEX_ATTR, Integer.toString(index)); + + if (colorSetting.getFilter() != null) { + Element filterElement = document.createElement(FILTER_TAG); + colorSettingElement.appendChild(filterElement); + TmfFilterXMLWriter.buildXMLTree(document, colorSetting.getFilter(), filterElement); + } + } + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(document); + StreamResult result = new StreamResult(new File(pathName)); + transformer.transform(source, result); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerException e) { + e.printStackTrace(); + } + } + + public static ColorSetting[] load(String pathName) { + if (! new File(pathName).canRead()) { + return new ColorSetting[0]; + } + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + parserFactory.setNamespaceAware(true); + + try { + XMLReader saxReader = parserFactory.newSAXParser().getXMLReader(); + ColorSettingsContentHandler handler = new ColorSettingsContentHandler(); + saxReader.setContentHandler(handler); + saxReader.parse(pathName); + return handler.colorSettings.toArray(new ColorSetting[0]); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return new ColorSetting[0]; + } + + private static class ColorSettingsContentHandler extends DefaultHandler { + + private ArrayList colorSettings = new ArrayList(0); + private RGB fg; + private RGB bg; + private int tickColorIndex; + private ITmfFilterTreeNode filter; + private TmfFilterContentHandler filterContentHandler; + + /* (non-Javadoc) + * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) + */ + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + if (localName.equals(COLOR_SETTINGS_TAG)) { + colorSettings = new ArrayList(); + } else if (localName.equals(COLOR_SETTING_TAG)) { + fg = null; + bg = null; + filter = null; + } else if (localName.equals(FG_TAG)) { + int r = Integer.valueOf(attributes.getValue(R_ATTR)); + int g = Integer.valueOf(attributes.getValue(G_ATTR)); + int b = Integer.valueOf(attributes.getValue(B_ATTR)); + fg = new RGB(r, g, b); + } else if (localName.equals(BG_TAG)) { + int r = Integer.valueOf(attributes.getValue(R_ATTR)); + int g = Integer.valueOf(attributes.getValue(G_ATTR)); + int b = Integer.valueOf(attributes.getValue(B_ATTR)); + bg = new RGB(r, g, b); + } else if (localName.equals(TICK_COLOR_TAG)) { + int index = Integer.valueOf(attributes.getValue(INDEX_ATTR)); + tickColorIndex = index; + } else if (localName.equals(FILTER_TAG)) { + filterContentHandler = new TmfFilterContentHandler(); + } else if (filterContentHandler != null) { + filterContentHandler.startElement(uri, localName, qName, attributes); + } + } + + /* (non-Javadoc) + * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public void endElement(String uri, String localName, String qName) + throws SAXException { + if (localName.equals(COLOR_SETTINGS_TAG)) { + } else if (localName.equals(COLOR_SETTING_TAG)) { + ColorSetting colorSetting = new ColorSetting(fg, bg, tickColorIndex, filter); + colorSettings.add(colorSetting); + } else if (localName.equals(FILTER_TAG)) { + filter = filterContentHandler.getTree(); + filterContentHandler = null; + } else if (filterContentHandler != null) { + filterContentHandler.endElement(uri, localName, qName); + } + } + + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java new file mode 100644 index 0000000000..30bc2862ed --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/ColorsView.java @@ -0,0 +1,552 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.colors; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin; +import org.eclipse.linuxtools.tmf.ui.internal.Messages; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme; +import org.eclipse.linuxtools.tmf.ui.views.TmfView; +import org.eclipse.linuxtools.tmf.ui.views.filter.FilterDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.ColorDialog; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionBars; + +public class ColorsView extends TmfView { + + public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.colors"; //$NON-NLS-1$ + + private static final Image ADD_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$ + private static final Image DELETE_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/delete_button.gif"); //$NON-NLS-1$ + private static final Image MOVE_UP_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/moveup_button.gif"); //$NON-NLS-1$ + private static final Image MOVE_DOWN_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/movedown_button.gif"); //$NON-NLS-1$ + private static final Image IMPORT_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/import_button.gif"); //$NON-NLS-1$ + private static final Image EXPORT_IMAGE = TmfUiPlugin.getDefault().getImageFromPath("/icons/elcl16/export_button.gif"); //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Main data structures + // ------------------------------------------------------------------------ + + protected Shell fShell; + protected ScrolledComposite fScrolledComposite; + protected Composite fListComposite; + protected Composite fFillerComposite; + + private ColorSettingRow fSelectedRow = null; + + private TraceColorScheme traceColorScheme = new TraceColorScheme(); + private TmfTimeAnalysisProvider timeAnalysisProvider = new TmfTimeAnalysisProvider() { + @Override + public StateColor getEventColor(ITimeEvent event) { + return null; + } + @Override + public String getTraceClassName(ITmfTimeAnalysisEntry trace) { + return null; + } + @Override + public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) { + return null; + } + @Override + public Map getEventHoverToolTipInfo(ITimeEvent event) { + return null; + } + @Override + public String getStateName(StateColor color) { + return null; + }}; + + Action fAddAction; + Action fDeleteAction; + Action fMoveUpAction; + Action fMoveDownAction; + Action fImportAction; + Action fExportAction; + + protected List fColorSettings; + + // ------------------------------------------------------------------------ + // Constructor + // ------------------------------------------------------------------------ + + /** + * Default Constructor + */ + public ColorsView() { + super("Colors"); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createPartControl(Composite parent) { + fShell = parent.getShell(); + + fScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); + fScrolledComposite.setExpandHorizontal(true); + fScrolledComposite.setExpandVertical(true); + fListComposite = new Composite(fScrolledComposite, SWT.NONE); + fScrolledComposite.setContent(fListComposite); + + GridLayout gl = new GridLayout(); + gl.marginHeight = 0; + gl.marginWidth = 0; + gl.verticalSpacing = 1; + fListComposite.setLayout(gl); + + fColorSettings = new ArrayList(Arrays.asList(ColorSettingsManager.getColorSettings())); + for (ColorSetting colorSetting : fColorSettings) { + new ColorSettingRow(fListComposite, colorSetting); + } + + fFillerComposite = new Composite(fListComposite, SWT.NONE); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gd.heightHint = 0; + fFillerComposite.setLayoutData(gd); + gl = new GridLayout(); + gl.marginHeight = 1; + gl.marginWidth = 1; + fFillerComposite.setLayout(gl); + Label fillerLabel = new Label(fFillerComposite, SWT.NONE); + fillerLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + fillerLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + fFillerComposite.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + if (fSelectedRow == null) { + Color lineColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + Point p = fFillerComposite.getSize(); + GC gc = e.gc; + gc.setForeground(lineColor); + gc.drawLine(0, 0, p.x - 1, 0); + } + } + }); + + MouseListener mouseListener = new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + fSelectedRow = null; + refresh(); + } + }; + fillerLabel.addMouseListener(mouseListener); + + fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + + fillToolBar(); + } + + public void refresh() { + fListComposite.layout(); + fScrolledComposite.setMinSize(fListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + fListComposite.redraw(0, 0, fListComposite.getBounds().width, fListComposite.getBounds().height, true); + if (fSelectedRow == null) { + fDeleteAction.setEnabled(false); + fMoveUpAction.setEnabled(false); + fMoveDownAction.setEnabled(false); + } else { + fDeleteAction.setEnabled(true); + fMoveUpAction.setEnabled(true); + fMoveDownAction.setEnabled(true); + } + } + + private void fillToolBar() { + + fAddAction = new AddAction(); + fAddAction.setImageDescriptor(ImageDescriptor.createFromImage(ADD_IMAGE)); + fAddAction.setToolTipText(Messages.ColorsView_AddActionToolTipText); + + fDeleteAction = new DeleteAction(); + fDeleteAction.setImageDescriptor(ImageDescriptor.createFromImage(DELETE_IMAGE)); + fDeleteAction.setToolTipText(Messages.ColorsView_DeleteActionToolTipText); + fDeleteAction.setEnabled(false); + + fMoveUpAction = new MoveUpAction(); + fMoveUpAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_UP_IMAGE)); + fMoveUpAction.setToolTipText(Messages.ColorsView_MoveUpActionToolTipText); + fMoveUpAction.setEnabled(false); + + fMoveDownAction = new MoveDownAction(); + fMoveDownAction.setImageDescriptor(ImageDescriptor.createFromImage(MOVE_DOWN_IMAGE)); + fMoveDownAction.setToolTipText(Messages.ColorsView_MoveDownActionToolTipText); + fMoveDownAction.setEnabled(false); + + fExportAction = new ExportAction(); + fExportAction.setImageDescriptor(ImageDescriptor.createFromImage(EXPORT_IMAGE)); + fExportAction.setToolTipText(Messages.ColorsView_ExportActionToolTipText); + + fImportAction = new ImportAction(); + fImportAction.setImageDescriptor(ImageDescriptor.createFromImage(IMPORT_IMAGE)); + fImportAction.setToolTipText(Messages.ColorsView_ImportActionToolTipText); + + IActionBars bars = getViewSite().getActionBars(); + IToolBarManager manager = bars.getToolBarManager(); + manager.add(fAddAction); + manager.add(fDeleteAction); + manager.add(fMoveUpAction); + manager.add(fMoveDownAction); + manager.add(new Separator()); + manager.add(fExportAction); + manager.add(fImportAction); + } + + private class AddAction extends Action { + @Override + public void run() { + ColorSetting colorSetting = new ColorSetting( + Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), + Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), + TraceColorScheme.BLACK_STATE, + null); + ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); + if (fSelectedRow == null) { + fColorSettings.add(colorSetting); + row.moveAbove(fFillerComposite); + } else { + fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting); + row.moveAbove(fSelectedRow); + } + fSelectedRow = row; + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + + private class DeleteAction extends Action { + @Override + public void run() { + if (fSelectedRow != null) { + int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); + fColorSettings.remove(index); + fSelectedRow.dispose(); + if (index < fColorSettings.size()) { + fSelectedRow = (ColorSettingRow) fListComposite.getChildren()[index]; + } else { + fSelectedRow = null; + } + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + } + + private class MoveUpAction extends Action { + @Override + public void run() { + if (fSelectedRow != null) { + int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); + if (index > 0) { + fColorSettings.add(index - 1, fColorSettings.remove(index)); + fSelectedRow.moveAbove(fListComposite.getChildren()[index - 1]); + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + } + } + + private class MoveDownAction extends Action { + @Override + public void run() { + if (fSelectedRow != null) { + int index = fColorSettings.indexOf(fSelectedRow.getColorSetting()); + if (index < fColorSettings.size() - 1) { + fColorSettings.add(index + 1, fColorSettings.remove(index)); + fSelectedRow.moveBelow(fListComposite.getChildren()[index + 1]); + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + } + } + + private class ExportAction extends Action { + @Override + public void run() { + FileDialog fileDialog = new FileDialog(fShell, SWT.SAVE); + fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$ + fileDialog.setOverwrite(true); + String pathName = fileDialog.open(); + if (pathName != null) { + ColorSettingsXML.save(pathName, fColorSettings.toArray(new ColorSetting[0])); + } + } + } + + private class ImportAction extends Action { + @Override + public void run() { + FileDialog fileDialog = new FileDialog(fShell, SWT.OPEN); + fileDialog.setFilterExtensions(new String[] {"*.xml"}); //$NON-NLS-1$ + String pathName = fileDialog.open(); + if (pathName != null) { + ColorSetting[] colorSettings = ColorSettingsXML.load(pathName); + if (colorSettings.length > 0) { + if (fColorSettings.size() > 0) { + boolean overwrite = MessageDialog.openQuestion(fShell, + Messages.ColorsView_ImportOverwriteDialogTitle, + Messages.ColorsView_ImportOverwriteDialogMessage1 + + Messages.ColorsView_ImportOverwriteDialogMessage2); + if (overwrite) { + for (Control control : fListComposite.getChildren()) { + if (control instanceof ColorSettingRow) { + control.dispose(); + } + } + fColorSettings = new ArrayList(); + fSelectedRow = null; + } + } + for (ColorSetting colorSetting : colorSettings) { + ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); + if (fSelectedRow == null) { + fColorSettings.add(colorSetting); + row.moveAbove(fFillerComposite); + } else { + fColorSettings.add(fColorSettings.indexOf(fSelectedRow.getColorSetting()), colorSetting); + row.moveAbove(fSelectedRow); + } + } + refresh(); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + } + } + } + } + + private class ColorSettingRow extends Composite { + + ColorSetting fColorSetting; + + public ColorSettingRow(final Composite parent, final ColorSetting colorSetting) { + super(parent, SWT.NONE); + fColorSetting = colorSetting; + + setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + GridLayout gl = new GridLayout(7, false); + gl.marginHeight = 1; + gl.marginWidth = 1; + gl.horizontalSpacing = 1; + gl.verticalSpacing = 0; + setLayout(gl); + + final Button fgButton = new Button(this, SWT.PUSH); + fgButton.setText(Messages.ColorsView_ForegroundButtonText); + fgButton.setSize(fgButton.computeSize(SWT.DEFAULT, 19)); + fgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + final Button bgButton = new Button(this, SWT.PUSH); + bgButton.setText(Messages.ColorsView_BackgroundButtonText); + bgButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + final Composite labelComposite = new Composite(this, SWT.NONE); + labelComposite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false)); + gl = new GridLayout(); + gl.marginHeight = 0; + gl.marginWidth = 0;; + labelComposite.setLayout(gl); + labelComposite.setBackground(colorSetting.getBackgroundColor()); + + final Label label = new Label(labelComposite, SWT.NONE); + label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true)); + label.setText(" Text "); //$NON-NLS-1$ + label.setForeground(colorSetting.getForegroundColor()); + label.setBackground(colorSetting.getBackgroundColor()); + + fgButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + ColorDialog dialog = new ColorDialog(fShell); + dialog.setRGB(colorSetting.getForegroundRGB()); + dialog.setText(Messages.ColorsView_ForegroundDialogText); + dialog.open(); + colorSetting.setForegroundRGB(dialog.getRGB()); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + label.setForeground(colorSetting.getForegroundColor()); + }}); + + bgButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + ColorDialog dialog = new ColorDialog(fShell); + dialog.setRGB(colorSetting.getBackgroundRGB()); + dialog.setText(Messages.ColorsView_BackgroundDialogText); + dialog.open(); + colorSetting.setBackgroundRGB(dialog.getRGB()); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + labelComposite.setBackground(colorSetting.getBackgroundColor()); + label.setBackground(colorSetting.getBackgroundColor()); + }}); + + final Button tickButton = new Button(this, SWT.PUSH); + tickButton.setText(Messages.ColorsView_TickButtonText); + tickButton.setSize(tickButton.computeSize(SWT.DEFAULT, 19)); + tickButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + final Canvas tickCanvas = new Canvas(this, SWT.NONE); + GridData gd = new GridData(SWT.CENTER, SWT.FILL, false, false); + gd.widthHint = 12; + gd.heightHint = bgButton.getSize().y; + tickCanvas.setLayoutData(gd); + tickCanvas.setBackground(traceColorScheme.getBkColor(false, false, false)); + tickCanvas.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + Rectangle bounds = tickCanvas.getBounds(); + e.gc.setForeground(traceColorScheme.getColor(TraceColorScheme.MID_LINE)); + int midy = bounds.y + bounds.height / 2 - 1; + //int midy = e.y + e.height / 2; + e.gc.drawLine(e.x, midy, e.x + e.width, midy); + Rectangle rect = new Rectangle(e.x + 1, bounds.y + 2, 0, bounds.height - 6); + for (int i = 1; i <= 3; i++) { + rect.x += i; + rect.width = i; + timeAnalysisProvider.drawState(traceColorScheme, fColorSetting.getTickColorIndex(), rect, e.gc, false, false, false); + } + }}); + + tickButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + TickColorDialog dialog = new TickColorDialog(fShell); + dialog.setColorIndex(colorSetting.getTickColorIndex()); + dialog.open(); + if (dialog.getReturnCode() == Dialog.OK) { + if (dialog.getColorIndex() != colorSetting.getTickColorIndex()) { + colorSetting.setTickColorIndex(dialog.getColorIndex()); + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + refresh(); + } + } + }}); + + final Button filterButton = new Button(this, SWT.PUSH); + filterButton.setText(Messages.ColorsView_FilterButtonText); + filterButton.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + final Label filterText = new Label(this, SWT.NONE); + if (colorSetting.getFilter() != null) { + filterText.setText(colorSetting.getFilter().toString()); + filterText.setToolTipText(colorSetting.getFilter().toString()); + } + filterText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + filterButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + FilterDialog dialog = new FilterDialog(fShell); + dialog.setFilter(colorSetting.getFilter()); + dialog.open(); + if (dialog.getReturnCode() == Dialog.OK) { + if (dialog.getFilter() != null) { + colorSetting.setFilter(dialog.getFilter()); + filterText.setText(dialog.getFilter().toString()); + filterText.setToolTipText(dialog.getFilter().toString()); + } else { + colorSetting.setFilter(null); + filterText.setText(""); //$NON-NLS-1$ + filterText.setToolTipText(""); //$NON-NLS-1$ + } + ColorSettingsManager.setColorSettings(fColorSettings.toArray(new ColorSetting[0])); + refresh(); + } + }}); + + addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + if (fSelectedRow == ColorSettingRow.this) { + Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + Point p = ColorSettingRow.this.getSize(); + Rectangle rect = new Rectangle(0, 0, p.x - 1, p.y - 1); + GC gc = e.gc; + gc.setForeground(borderColor); + gc.drawRectangle(rect); + } + } + }); + + MouseListener mouseListener = new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + fSelectedRow = ColorSettingRow.this; + refresh(); + } + }; + addMouseListener(mouseListener); + label.addMouseListener(mouseListener); + tickCanvas.addMouseListener(mouseListener); + filterText.addMouseListener(mouseListener); + } + + /** + * @return the ColorSetting + */ + public ColorSetting getColorSetting() { + return fColorSetting; + } + + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/IColorSettingsListener.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/IColorSettingsListener.java new file mode 100644 index 0000000000..f7fd7feb40 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/IColorSettingsListener.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.colors; + +public interface IColorSettingsListener { + + public void colorSettingsChanged(ColorSetting[] colorSettings); +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java new file mode 100644 index 0000000000..98bf6a3bc9 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/colors/TickColorDialog.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2010 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: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.colors; + +import java.util.Map; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.linuxtools.tmf.ui.internal.Messages; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry; +import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.TraceColorScheme; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +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.Shell; + +public class TickColorDialog extends Dialog { + + int selectedIndex = 0; + Composite colorComposite; + + TraceColorScheme traceColorScheme = new TraceColorScheme(); + private TmfTimeAnalysisProvider timeAnalysisProvider = new TmfTimeAnalysisProvider() { + @Override + public StateColor getEventColor(ITimeEvent event) { + return null; + } + @Override + public String getTraceClassName(ITmfTimeAnalysisEntry trace) { + return null; + } + @Override + public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) { + return null; + } + @Override + public Map getEventHoverToolTipInfo(ITimeEvent event) { + return null; + } + @Override + public String getStateName(StateColor color) { + return null; + }}; + + protected TickColorDialog(Shell shell) { + super(shell); + setShellStyle(getShellStyle() | SWT.MAX); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + getShell().setText(Messages.TickColorDialog_TickColorDialogTitle); + //getShell().setMinimumSize(getShell().computeSize(500, 200)); + Composite composite = (Composite) super.createDialogArea(parent); + colorComposite = new Composite(composite, SWT.NONE); + colorComposite.setLayout(new GridLayout(4, false)); + + for (int i = 0; i < 16; i++) { + TickColorCanvas tickColorCanvas = new TickColorCanvas(colorComposite, SWT.NONE); + tickColorCanvas.setColorIndex(i); + } + + return composite; + } + + public void setColorIndex(int colorIndex) { + selectedIndex = colorIndex; + } + + public int getColorIndex() { + return selectedIndex; + } + + private class TickColorCanvas extends Canvas { + int colorIndex; + + public TickColorCanvas(Composite parent, int style) { + super(parent, style); + + GridData gd = new GridData(SWT.CENTER, SWT.FILL, true, false); + gd.widthHint = 40; + gd.heightHint = 25; + setLayoutData(gd); + setBackground(traceColorScheme.getBkColor(false, false, false)); + + addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + e.gc.setForeground(traceColorScheme.getColor(TraceColorScheme.MID_LINE)); + int midy = e.y + e.height / 2; + e.gc.drawLine(e.x, midy, e.x + e.width, midy); + int midx = e.x + e.width / 2; + Rectangle rect = new Rectangle(midx - 10, e.y + 3, 0, e.height - 6); + for (int i = 1; i <= 3; i++) { + rect.x += i; + rect.width = i; + timeAnalysisProvider.drawState(traceColorScheme, colorIndex, rect, e.gc, false, false, false); + } + for (int i = 3; i > 0; i--) { + rect.x += i + 2; + rect.width = i; + timeAnalysisProvider.drawState(traceColorScheme, colorIndex, rect, e.gc, false, false, false); + } + if (selectedIndex == colorIndex) { + Color borderColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); + Point p = TickColorCanvas.this.getSize(); + rect = new Rectangle(0, 0, p.x - 1, p.y - 1); + GC gc = e.gc; + gc.setForeground(borderColor); + gc.drawRectangle(rect); + } + }}); + + addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + selectedIndex = colorIndex; + colorComposite.redraw(0, 0, colorComposite.getBounds().width, colorComposite.getBounds().height, true); + }}); + } + + public void setColorIndex(int index) { + colorIndex = index; + } + } + + +} -- 2.34.1