/*******************************************************************************
- * Copyright (c) 2015 Ericsson
+ * Copyright (c) 2015, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGBA;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.tracecompass.internal.tmf.ui.Messages;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
private static final String LOST_EVENTS = Messages.MarkerEvent_LostEvents;
- private static final Color COLOR = new Color(Display.getDefault(), new RGBA(255, 0, 0, 50));
+ private static final RGBA COLOR = new RGBA(255, 0, 0, 50);
private final @NonNull ITmfTrace fTrace;
private long[] fLastRequest;
/*******************************************************************************
- * Copyright (c) 2012, 2015 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2012, 2016 Ericsson, École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGBA;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Tree;
private int fAutoExpandLevel = ALL_LEVELS;
- /** The list of color resources created by this view */
- private final List<Color> fColors = new ArrayList<>();
-
/** The default column index for sorting */
private int fInitialSortColumn = 0;
NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTime,
new TmfNanoTimestamp(bookmark.getTime())));
}
- marker.setAttribute(ITmfMarker.MARKER_COLOR, bookmark.getColor().getRGBA().toString());
+ marker.setAttribute(ITmfMarker.MARKER_COLOR, bookmark.getColor().toString());
}
}, null);
} catch (CoreException e) {
if (bookmark.getLabel().equals(marker.getAttribute(IMarker.MESSAGE)) &&
Long.toString(bookmark.getTime()).equals(marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null)) &&
Long.toString(bookmark.getDuration()).equals(marker.getAttribute(ITmfMarker.MARKER_DURATION, Long.toString(0))) &&
- bookmark.getColor().getRGBA().toString().equals(marker.getAttribute(ITmfMarker.MARKER_COLOR))) {
+ bookmark.getColor().toString().equals(marker.getAttribute(ITmfMarker.MARKER_COLOR))) {
marker.delete();
break;
}
}
}
- private List<IMarkerEvent> refreshBookmarks(final IFile editorFile) {
+ private static List<IMarkerEvent> refreshBookmarks(final IFile editorFile) {
List<IMarkerEvent> bookmarks = new ArrayList<>();
- for (Color color : fColors) {
- color.dispose();
- }
- fColors.clear();
if (editorFile == null || !editorFile.exists()) {
return bookmarks;
}
int green = Integer.valueOf(matcher.group(2));
int blue = Integer.valueOf(matcher.group(3));
int alpha = Integer.valueOf(matcher.group(4));
- Color color = new Color(Display.getDefault(), red, green, blue, alpha);
- fColors.add(color);
+ RGBA color = new RGBA(red, green, blue, alpha);
bookmarks.add(new MarkerEvent(null, Long.valueOf(time), Long.valueOf(duration), IMarkerEvent.BOOKMARKS, color, label, true));
} catch (NumberFormatException e) {
Activator.getDefault().logError(e.getMessage());
/*****************************************************************************
- * Copyright (c) 2007, 2015 Intel Corporation, Ericsson, others
+ * Copyright (c) 2007, 2016 Intel Corporation, Ericsson, others
* 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
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGBA;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
/** The list of markers */
private final List<IMarkerEvent> fMarkers = new ArrayList<>();
- /** The list of color resources created by this viewer */
- private final List<Color> fColors = new ArrayList<>();
-
private ListenerNotifier fListenerNotifier;
private Composite fTimeAlignedComposite;
fDataViewer.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
- for (Color color : fColors) {
- color.dispose();
- }
if (fMarkersMenu != null) {
fMarkersMenu.dispose();
}
* @since 2.0
*/
public void setBookmarks(List<IMarkerEvent> bookmarks) {
- for (IMarkerEvent bookmark : fBookmarks) {
- checkDisposeColor(bookmark.getColor());
- }
fBookmarks.clear();
if (bookmarks != null) {
fBookmarks.addAll(bookmarks);
return Collections.unmodifiableList(fMarkers);
}
- /**
- * Dispose the color resource if and only if it was created by this viewer.
- *
- * @param color
- * the color
- */
- private void checkDisposeColor(Color color) {
- for (int i = 0; i < fColors.size(); i++) {
- /* check for identity, not equality */
- if (fColors.get(i) == color) {
- color.dispose();
- fColors.remove(i);
- break;
- }
- }
- }
-
/**
* Callback to set a selected event in the view
*
if (dialog.open() == Window.OK) {
final String label = dialog.getValue();
final RGBA rgba = dialog.getColorValue();
- Color color = new Color(Display.getDefault(), rgba.rgb.red, rgba.rgb.green, rgba.rgb.blue, rgba.alpha);
- fColors.add(color);
- IMarkerEvent bookmark = new MarkerEvent(null, time, duration, IMarkerEvent.BOOKMARKS, color, label, true);
+ IMarkerEvent bookmark = new MarkerEvent(null, time, duration, IMarkerEvent.BOOKMARKS, rgba, label, true);
fBookmarks.add(bookmark);
updateMarkerList();
updateMarkerActions();
fireBookmarkAdded(bookmark);
}
} else {
- checkDisposeColor(selectedBookmark.getColor());
fBookmarks.remove(selectedBookmark);
updateMarkerList();
updateMarkerActions();
/*******************************************************************************
- * Copyright (c) 2015 Ericsson
+ * Copyright (c) 2015, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGBA;
import org.eclipse.tracecompass.internal.tmf.ui.Messages;
/**
*
* @return The color
*/
- Color getColor();
+ RGBA getColor();
/**
* Returns true if the marker is drawn in foreground, and false otherwise.
/*******************************************************************************
- * Copyright (c) 2015 Ericsson
+ * Copyright (c) 2015, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model;
-import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGBA;
/**
* TimeEvent implementation for marker events
public class MarkerEvent extends TimeEvent implements IMarkerEvent {
private final String fCategory;
- private final Color fColor;
+ private final RGBA fColor;
private final String fLabel;
private final boolean fForeground;
* @param foreground
* true if the marker is drawn in foreground, and false otherwise
*/
- public MarkerEvent(ITimeGraphEntry entry, long time, long duration, String category, Color color, String label, boolean foreground) {
+ public MarkerEvent(ITimeGraphEntry entry, long time, long duration, String category, RGBA color, String label, boolean foreground) {
super(entry, time, duration);
fCategory = category;
fColor = color;
* @param value
* The value of the marker
*/
- public MarkerEvent(ITimeGraphEntry entry, long time, long duration, String category, Color color, String label, boolean foreground, int value) {
+ public MarkerEvent(ITimeGraphEntry entry, long time, long duration, String category, RGBA color, String label, boolean foreground, int value) {
super(entry, time, duration, value);
fCategory = category;
fColor = color;
}
@Override
- public Color getColor() {
+ public RGBA getColor() {
return fColor;
}
/*****************************************************************************
- * Copyright (c) 2008, 2014 Intel Corporation, Ericsson
+ * Copyright (c) 2008, 2016 Intel Corporation, 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
package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGBA;
+import org.eclipse.swt.widgets.Display;
/**
* Color theme used by the timegraph view
new Mix(new SysCol(SWT.COLOR_GRAY), new SysCol(SWT.COLOR_WIDGET_BACKGROUND), 1, 6), // BACKGROUND_NAME_SEL_NOFOCUS
};
+ /** Fixed scheme colors */
private final Color fColors[];
+ /** Dynamic RGBA to Color map */
+ private final Map<RGBA, Color> fColorMap;
/**
* Default constructor
*/
public TimeGraphColorScheme() {
fColors = new Color[PROVIDERS_MAP.length];
+ fColorMap = new HashMap<>();
}
/**
Utils.dispose(fColors[i]);
fColors[i] = null;
}
+ for (Color color : fColorMap.values()) {
+ color.dispose();
+ }
}
/**
}
return getColor(GR_FOREGROUND);
}
+
+ /**
+ * Get a color resource for the specified RGBA color descriptor
+ *
+ * @param rgba
+ * the color descriptor
+ * @return a color resource
+ * @since 2.0
+ */
+ public Color getColor(RGBA rgba) {
+ Color color = fColorMap.get(rgba);
+ if (color == null) {
+ color = new Color(Display.getDefault(), rgba);
+ fColorMap.put(rgba, color);
+ }
+ return color;
+ }
+
}
/*****************************************************************************
- * Copyright (c) 2007, 2015 Intel Corporation and others
+ * Copyright (c) 2007, 2016 Intel Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
rect.x = Math.max(nameSpace, Math.min(bounds.width, x0));
rect.width = Math.max(1, Math.min(bounds.width, x1) - rect.x);
- gc.setBackground(marker.getColor());
- gc.setAlpha(marker.getColor().getAlpha());
+ Color color = getColorScheme().getColor(marker.getColor());
+ gc.setBackground(color);
+ gc.setAlpha(color.getAlpha());
gc.fillRectangle(rect);
gc.setAlpha(255);
String label = marker.getLabel();
if (label != null && marker.getEntry() != null) {
label = label.substring(0, Math.min(label.indexOf('\n') != -1 ? label.indexOf('\n') : label.length(), MAX_LABEL_LENGTH));
- gc.setForeground(marker.getColor());
+ gc.setForeground(color);
Utils.drawText(gc, label, rect.x - gc.textExtent(label).x, rect.y, true);
}
}
/*****************************************************************************
- * Copyright (c) 2007, 2015 Intel Corporation, Ericsson
+ * Copyright (c) 2007, 2016 Intel Corporation, 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
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
}
}
- private static void drawMarkerLabels(List<IMarkerEvent> markerEvents, Rectangle rect, GC gc, long time0, int leftSpace, double pixelsPerNanoSec) {
+ private void drawMarkerLabels(List<IMarkerEvent> markerEvents, Rectangle rect, GC gc, long time0, int leftSpace, double pixelsPerNanoSec) {
if (markerEvents == null) {
return;
}
label = label.substring(0, Math.min(label.indexOf('\n') != -1 ? label.indexOf('\n') : label.length(), MAX_LABEL_LENGTH));
int x = rect.x + leftSpace + (int) (Math.floor((markerEvent.getTime() - time0) * pixelsPerNanoSec));
int y = rect.y + rect.height - gc.stringExtent(" ").y + 2; //$NON-NLS-1$
- gc.setForeground(markerEvent.getColor());
+ Color color = getColorScheme().getColor(markerEvent.getColor());
+ gc.setForeground(color);
Utils.drawText(gc, label, x, y, true);
}
}