1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson, École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alvaro Sanchez-Leon - Initial API and implementation
11 * Patrick Tasse - Refactoring
12 * Geneviève Bastien - Add drawing helper methods
13 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
21 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Messages
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.ITmfTimeGraphDrawingHelper
;
25 import org
.eclipse
.swt
.graphics
.GC
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.swt
.graphics
.Rectangle
;
30 * Provider class for the time graph provider
33 * @author Patrick Tasse
36 public class TimeGraphPresentationProvider
implements ITimeGraphPresentationProvider2
{
38 private ITmfTimeGraphDrawingHelper fDrawingHelper
;
39 private final String fStateTypeName
;
41 // The list of listeners for graph color changes
42 private final List
<ITimeGraphColorListener
> fListeners
= new ArrayList
<>();
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
47 private static final int DEFAULT_ITEM_HEIGHT
= 19;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
55 * @param stateTypeName The state type name
58 public TimeGraphPresentationProvider(String stateTypeName
) {
59 fStateTypeName
= stateTypeName
;
66 public TimeGraphPresentationProvider() {
67 this(Messages
.TmfTimeLegend_TRACE_STATES
);
71 public String
getStateTypeName() {
72 return fStateTypeName
;
76 * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider#getStateTypeName(org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)
80 public String
getStateTypeName(ITimeGraphEntry entry
) {
85 public StateItem
[] getStateTable() {
90 public int getStateTableIndex(ITimeEvent event
) {
98 public ITmfTimeGraphDrawingHelper
getDrawingHelper() {
99 return fDrawingHelper
;
106 public void setDrawingHelper(ITmfTimeGraphDrawingHelper helper
) {
107 fDrawingHelper
= helper
;
111 public void postDrawControl(Rectangle bounds
, GC gc
) {
112 // Override to add own drawing code
116 public void postDrawEntry(ITimeGraphEntry entry
, Rectangle bounds
, GC gc
) {
117 // Override to add own drawing code
121 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
122 // Override to add own drawing code
126 public int getItemHeight(ITimeGraphEntry entry
) {
127 return DEFAULT_ITEM_HEIGHT
;
131 public Image
getItemImage(ITimeGraphEntry entry
) {
136 public String
getEventName(ITimeEvent event
) {
141 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
149 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
, long hoverTime
) {
150 return getEventHoverToolTipInfo(event
);
157 public boolean displayTimesInTooltip() {
165 public void addColorListener(ITimeGraphColorListener listener
) {
166 if (!fListeners
.contains(listener
)) {
167 fListeners
.add(listener
);
175 public void removeColorListener(ITimeGraphColorListener listener
) {
176 fListeners
.remove(listener
);
180 * Notifies listeners of the state table change
183 protected void fireColorSettingsChanged() {
184 for (ITimeGraphColorListener listener
: fListeners
) {
185 listener
.colorSettingsChanged(getStateTable());