diff options
author | Patrick Tasse | 2015-03-12 17:40:26 +0000 |
---|---|---|
committer | Patrick Tasse | 2015-03-19 18:14:43 +0000 |
commit | 9b840a86473b45d052691aa66eaee848c2440e53 (patch) | |
tree | 4d479406bf61ce19e8e54137e72452651e0567e1 /org.eclipse.tracecompass.tmf.ui | |
parent | 04f0148f69e6ab7ab6fe12862c7a7cc0c9ac02ea (diff) | |
download | org.eclipse.tracecompass-9b840a86473b45d052691aa66eaee848c2440e53.tar.gz org.eclipse.tracecompass-9b840a86473b45d052691aa66eaee848c2440e53.tar.xz org.eclipse.tracecompass-9b840a86473b45d052691aa66eaee848c2440e53.zip |
tmf: Support nullable colors in ColorSetting
A null Color in a ColorSetting indicates that the default system color
should be used.
Change-Id: I01f129ac30ba4c6589229b19851e15cc93362622
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/44173
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Diffstat (limited to 'org.eclipse.tracecompass.tmf.ui')
4 files changed, 157 insertions, 103 deletions
diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSetting.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSetting.java index d456133bb3..8dd345298f 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSetting.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSetting.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -13,6 +13,10 @@ package org.eclipse.tracecompass.tmf.ui.views.colors; +import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; @@ -23,49 +27,51 @@ import org.eclipse.ui.themes.ColorUtil; /** * Class for storing color settings of a TMF filter. * - * Application code must explicitly invoke the ColorSetting.dispose() method to release the operating system - * resources managed by each instance when those instances are no longer required. + * Application code must explicitly invoke the ColorSetting.dispose() method to + * release the operating system resources managed by each instance when those + * instances are no longer required. * - * @version 1.0 - * @author Patrick Tasse + * @version 1.0 + * @author Patrick Tasse */ public class ColorSetting { - private RGB fForegroundRGB; - private RGB fBackgroundRGB; - private RGB fTickColorRGB; - private Color fForegroundColor; - private Color fBackgroundColor; - private Color fDimmedForegroundColor; - private Color fDimmedBackgroundColor; - private Color fTickColor; - private ITmfFilterTreeNode fFilter; - - /** + private @Nullable RGB fForegroundRGB; + private @Nullable RGB fBackgroundRGB; + private @NonNull RGB fTickColorRGB; + private @Nullable Color fForegroundColor; + private @Nullable Color fBackgroundColor; + private @Nullable Color fDimmedForegroundColor; + private @Nullable Color fDimmedBackgroundColor; + private @NonNull Color fTickColor; + private @Nullable ITmfFilterTreeNode fFilter; + + /** * Constructor * * You must dispose the color setting when it is no longer required. * * @param foreground - * The foreground color + * The foreground color, or null to use the default system color * @param background - * The background color + * The background color, or null to use the default system color * @param tickColorRGB - * The color for the checkbox ticks + * The color for the time graph ticks, or null to use the default system color * @param filter - * The filter tree node + * The filter tree node, or null */ - public ColorSetting(RGB foreground, RGB background, RGB tickColorRGB, ITmfFilterTreeNode filter) { + public ColorSetting(@Nullable RGB foreground, @Nullable RGB background, @Nullable RGB tickColorRGB, @Nullable ITmfFilterTreeNode filter) { fForegroundRGB = foreground; fBackgroundRGB = background; - fTickColorRGB = tickColorRGB; + fTickColorRGB = (tickColorRGB != null) ? tickColorRGB : checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()); fFilter = filter; Display display = Display.getDefault(); - fForegroundColor = new Color(display, fForegroundRGB); - fBackgroundColor = new Color(display, fBackgroundRGB); + fForegroundColor = (fForegroundRGB != null) ? new Color(display, fForegroundRGB) : null; + fBackgroundColor = (fBackgroundRGB != null) ? new Color(display, fBackgroundRGB) : null; fDimmedForegroundColor = new Color(display, ColorUtil.blend( - fForegroundRGB, fBackgroundRGB)); - fDimmedBackgroundColor = new Color(display, ColorUtil.blend( + (fForegroundRGB != null) ? fForegroundRGB : display.getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), + (fBackgroundRGB != null) ? fBackgroundRGB : display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); + fDimmedBackgroundColor = (fBackgroundRGB == null) ? null : new Color(display, ColorUtil.blend( fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); fTickColor = new Color(display, fTickColorRGB); } @@ -74,59 +80,88 @@ public class ColorSetting { * Dispose the color setting resources */ public void dispose() { - fForegroundColor.dispose(); - fBackgroundColor.dispose(); - fDimmedForegroundColor.dispose(); - fDimmedBackgroundColor.dispose(); + if (fForegroundColor != null) { + fForegroundColor.dispose(); + } + if (fBackgroundColor != null) { + fBackgroundColor.dispose(); + } + if (fDimmedForegroundColor != null) { + fDimmedForegroundColor.dispose(); + } + if (fDimmedBackgroundColor != null) { + fDimmedBackgroundColor.dispose(); + } fTickColor.dispose(); } /** - * Returns foreground RGB value. + * Returns foreground RGB value, or null if the default system color is + * used. * - * @return the foreground RGB + * @return the foreground RGB, or null */ - public RGB getForegroundRGB() { + public @Nullable RGB getForegroundRGB() { return fForegroundRGB; } /** - * Sets the foreground RGB value + * Sets the foreground RGB value. If the argument is null the default system + * color will be used. * - * @param foreground the foreground to set + * @param foreground + * the foreground to set, or null */ - public void setForegroundRGB(RGB foreground) { + public void setForegroundRGB(@Nullable RGB foreground) { fForegroundRGB = foreground; - fForegroundColor.dispose(); - fDimmedForegroundColor.dispose(); + if (fForegroundColor != null) { + fForegroundColor.dispose(); + } + if (fDimmedForegroundColor != null) { + fDimmedForegroundColor.dispose(); + } Display display = Display.getDefault(); - fForegroundColor = new Color(display, fForegroundRGB); + fForegroundColor = (fForegroundRGB != null) ? new Color(display, fForegroundRGB) : null; fDimmedForegroundColor = new Color(display, ColorUtil.blend( - fForegroundRGB, fBackgroundRGB)); + (fForegroundRGB != null) ? fForegroundRGB : display.getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), + (fBackgroundRGB != null) ? fBackgroundRGB : display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); } /** - * Returns the background RGB value. + * Returns the background RGB value, or null if the default system color is + * used. * - * @return the background RGB + * @return the background RGB, or null */ - public RGB getBackgroundRGB() { + public @Nullable RGB getBackgroundRGB() { return fBackgroundRGB; } /** - * Sets the background RGB value. + * Sets the background RGB value. If the argument is null the default system + * color will be used. * - * @param background the background to set + * @param background + * the background to set, or null */ - public void setBackgroundRGB(RGB background) { + public void setBackgroundRGB(@Nullable RGB background) { fBackgroundRGB = background; - fBackgroundColor.dispose(); - fDimmedBackgroundColor.dispose(); + if (fBackgroundColor != null) { + fBackgroundColor.dispose(); + } + if (fDimmedBackgroundColor != null) { + fDimmedBackgroundColor.dispose(); + } + if (fDimmedForegroundColor != null) { + fDimmedForegroundColor.dispose(); + } Display display = Display.getDefault(); - fBackgroundColor = new Color(display, fBackgroundRGB); - fDimmedBackgroundColor = new Color(display, ColorUtil.blend( + fBackgroundColor = (fBackgroundRGB != null) ? new Color(display, fBackgroundRGB) : null; + fDimmedBackgroundColor = (fBackgroundRGB == null) ? null : new Color(display, ColorUtil.blend( fBackgroundRGB, display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); + fDimmedForegroundColor = new Color(display, ColorUtil.blend( + (fForegroundRGB != null) ? fForegroundRGB : display.getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), + (fBackgroundRGB != null) ? fBackgroundRGB : display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB())); } /** @@ -134,72 +169,79 @@ public class ColorSetting { * * @return the RGB of the tick color */ - public RGB getTickColorRGB() { + public @NonNull RGB getTickColorRGB() { return fTickColorRGB; } /** * Sets the RGB of the tick color * - * @param tickColorRGB the tick color TGB + * @param tickColorRGB + * the tick color TGB */ - public void setTickColorRGB(RGB tickColorRGB) { - fTickColorRGB = tickColorRGB; - fTickColor.dispose(); - Display display = Display.getDefault(); - fTickColor = new Color(display, fTickColorRGB); + public void setTickColorRGB(@NonNull RGB tickColorRGB) { + fTickColorRGB = tickColorRGB; + fTickColor.dispose(); + Display display = Display.getDefault(); + fTickColor = new Color(display, fTickColorRGB); } /** * Returns the filter implementation. - * @return the filter + * + * @return the filter, or null */ - public ITmfFilterTreeNode getFilter() { + public @Nullable ITmfFilterTreeNode getFilter() { return fFilter; } /** * Sets the filter implementation. * - * @param filter the filter to set + * @param filter + * the filter to set, or null */ - public void setFilter(ITmfFilterTreeNode filter) { + public void setFilter(@Nullable ITmfFilterTreeNode filter) { fFilter = filter; } /** - * Returns the foreground color. + * Returns the foreground color, or null if the default system color is + * used. * - * @return the foreground color + * @return the foreground color, or null */ - public Color getForegroundColor() { + public @Nullable Color getForegroundColor() { return fForegroundColor; } /** - * Returns the background color. + * Returns the background color, or null if the default system color is + * used. * - * @return the background color + * @return the background color, or null */ - public Color getBackgroundColor() { + public @Nullable Color getBackgroundColor() { return fBackgroundColor; } /** - * Returns the dimmed foreground color. + * Returns the dimmed foreground color, or null if the default system color + * is used. * - * @return the dimmed foreground color + * @return the dimmed foreground color, or null */ - public Color getDimmedForegroundColor() { + public @Nullable Color getDimmedForegroundColor() { return fDimmedForegroundColor; } /** - * Returns the dimmed background color. + * Returns the dimmed background color, or null if the default system color + * is used. * - * @return the dimmed background color + * @return the dimmed background color, or null */ - public Color getDimmedBackgroundColor() { + public @Nullable Color getDimmedBackgroundColor() { return fDimmedBackgroundColor; } diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java index cf83e11fa2..eaef6568e3 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java @@ -19,10 +19,9 @@ import java.util.Arrays; import java.util.List; import org.eclipse.core.runtime.IPath; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; import org.eclipse.tracecompass.internal.tmf.ui.Activator; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter; /** * Static class for managing color settings. @@ -51,9 +50,9 @@ public class ColorSettingsManager { // The default color setting 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(), - Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), + null, + null, + null, null); /** @@ -119,7 +118,8 @@ public class ColorSettingsManager { public static ColorSetting getColorSetting(ITmfEvent event) { for (int i = 0; i < fColorSettings.length; i++) { ColorSetting colorSetting = fColorSettings[i]; - if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) { + ITmfFilter filter = colorSetting.getFilter(); + if (filter != null && filter.matches(event)) { return colorSetting; } } @@ -135,7 +135,8 @@ public class ColorSettingsManager { public static int getColorSettingPriority(ITmfEvent event) { for (int i = 0; i < fColorSettings.length; i++) { ColorSetting colorSetting = fColorSettings[i]; - if (colorSetting.getFilter() != null && colorSetting.getFilter().matches(event)) { + ITmfFilter filter = colorSetting.getFilter(); + if (filter != null && filter.matches(event)) { return i; } } diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsXML.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsXML.java index a123b25c6c..6cc580a434 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsXML.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsXML.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -31,6 +31,7 @@ import javax.xml.transform.stream.StreamResult; import org.eclipse.swt.graphics.RGB; import org.eclipse.tracecompass.internal.tmf.ui.Activator; +import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter; import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode; import org.eclipse.tracecompass.tmf.core.filter.xml.TmfFilterContentHandler; import org.eclipse.tracecompass.tmf.core.filter.xml.TmfFilterXMLWriter; @@ -82,19 +83,23 @@ public class ColorSettingsXML { 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)); + if (foreground != null) { + Element fgElement = document.createElement(FG_TAG); + colorSettingElement.appendChild(fgElement); + 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)); + if (background != null) { + Element bgElement = document.createElement(BG_TAG); + colorSettingElement.appendChild(bgElement); + 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_TAG); colorSettingElement.appendChild(tickColorElement); @@ -103,10 +108,11 @@ public class ColorSettingsXML { tickColorElement.setAttribute(G_ATTR, Integer.toString(tickColor.green)); tickColorElement.setAttribute(B_ATTR, Integer.toString(tickColor.blue)); - if (colorSetting.getFilter() != null) { + ITmfFilter filter = colorSetting.getFilter(); + if (filter instanceof ITmfFilterTreeNode) { Element filterElement = document.createElement(FILTER_TAG); colorSettingElement.appendChild(filterElement); - TmfFilterXMLWriter.buildXMLTree(document, colorSetting.getFilter(), filterElement); + TmfFilterXMLWriter.buildXMLTree(document, (ITmfFilterTreeNode) filter, filterElement); } } @@ -164,9 +170,9 @@ public class ColorSettingsXML { private static class ColorSettingsContentHandler extends DefaultHandler { private List<ColorSetting> colorSettings = new ArrayList<>(0); - private RGB fg = new RGB(0, 0, 0); - private RGB bg = new RGB(255, 255, 255); - private RGB tickColor = new RGB(0, 0, 0); + private RGB fg; + private RGB bg; + private RGB tickColor; private ITmfFilterTreeNode filter; private TmfFilterContentHandler filterContentHandler; @@ -178,6 +184,7 @@ public class ColorSettingsXML { } else if (localName.equals(COLOR_SETTING_TAG)) { fg = null; bg = null; + tickColor = null; filter = null; } else if (localName.equals(FG_TAG)) { int r = Integer.parseInt(attributes.getValue(R_ATTR)); diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorsView.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorsView.java index 4d0078ac20..43ef060972 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorsView.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorsView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -13,6 +13,8 @@ package org.eclipse.tracecompass.tmf.ui.views.colors; +import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -52,6 +54,7 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.tracecompass.internal.tmf.ui.Activator; import org.eclipse.tracecompass.internal.tmf.ui.Messages; +import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter; import org.eclipse.tracecompass.tmf.ui.views.TmfView; import org.eclipse.tracecompass.tmf.ui.views.filter.FilterDialog; import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; @@ -271,9 +274,9 @@ public class ColorsView extends TmfView { @Override public void run() { ColorSetting colorSetting = new ColorSetting( - Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), - Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(), - Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(), + checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()), + checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()), + checkNotNull(Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()), null); ColorSettingRow row = new ColorSettingRow(fListComposite, colorSetting); if (fSelectedRow == null) { @@ -520,9 +523,10 @@ public class ColorsView extends TmfView { 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()); + ITmfFilter filter = colorSetting.getFilter(); + if (filter != null) { + filterText.setText(filter.toString()); + filterText.setToolTipText(filter.toString()); } filterText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); filterText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |