1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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
.tracecompass
.tmf
.ui
.widgets
.timegraph
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
21 import org
.eclipse
.swt
.graphics
.GC
;
22 import org
.eclipse
.swt
.graphics
.Image
;
23 import org
.eclipse
.swt
.graphics
.Rectangle
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.ITmfTimeGraphDrawingHelper
;
30 * Provider class for the time graph provider
32 * @author Patrick Tasse
35 public class TimeGraphPresentationProvider
implements ITimeGraphPresentationProvider2
{
37 private ITmfTimeGraphDrawingHelper fDrawingHelper
;
38 private final String fStateTypeName
;
40 // The list of listeners for graph color changes
41 private final List
<ITimeGraphColorListener
> fListeners
= new ArrayList
<>();
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
46 private static final int DEFAULT_ITEM_HEIGHT
= 19;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
55 * @param stateTypeName The state type name
57 public TimeGraphPresentationProvider(String stateTypeName
) {
58 fStateTypeName
= stateTypeName
;
64 public TimeGraphPresentationProvider() {
65 this(Messages
.TmfTimeLegend_TRACE_STATES
);
69 public String
getStateTypeName() {
70 return fStateTypeName
;
74 public String
getStateTypeName(ITimeGraphEntry entry
) {
79 public StateItem
[] getStateTable() {
84 public int getStateTableIndex(ITimeEvent event
) {
89 public ITmfTimeGraphDrawingHelper
getDrawingHelper() {
90 return fDrawingHelper
;
94 public void setDrawingHelper(ITmfTimeGraphDrawingHelper helper
) {
95 fDrawingHelper
= helper
;
99 public void postDrawControl(Rectangle bounds
, GC gc
) {
100 // Override to add own drawing code
104 public void postDrawEntry(ITimeGraphEntry entry
, Rectangle bounds
, GC gc
) {
105 // Override to add own drawing code
109 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
110 // Override to add own drawing code
114 public int getItemHeight(ITimeGraphEntry entry
) {
115 return DEFAULT_ITEM_HEIGHT
;
119 public Image
getItemImage(ITimeGraphEntry entry
) {
124 public String
getEventName(ITimeEvent event
) {
129 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
134 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
, long hoverTime
) {
135 return getEventHoverToolTipInfo(event
);
139 public boolean displayTimesInTooltip() {
144 public void addColorListener(ITimeGraphColorListener listener
) {
145 if (!fListeners
.contains(listener
)) {
146 fListeners
.add(listener
);
151 public void removeColorListener(ITimeGraphColorListener listener
) {
152 fListeners
.remove(listener
);
156 * Notifies listeners of the state table change
158 protected void fireColorSettingsChanged() {
159 for (ITimeGraphColorListener listener
: fListeners
) {
160 listener
.colorSettingsChanged(getStateTable());