tmf.ui: make TimeEvents in ControlFlowView have thickness
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / widgets / timegraph / StateItem.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.tracecompass.tmf.ui.widgets.timegraph;
13
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.swt.graphics.RGB;
19 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEventStyleStrings;
20
21 /**
22 * Class that contains the color of a state and the corresponding state string
23 * to display.
24 *
25 * @version 1.0
26 * @author Bernd Hufmann
27 */
28 public class StateItem {
29
30 // ------------------------------------------------------------------------
31 // Constants
32 // ------------------------------------------------------------------------
33 /**
34 * Name of state if not known
35 */
36 public static final String UNDEFINED_STATE_NAME = "Undefined"; //$NON-NLS-1$
37
38 private static final int UNDEFINED_COLOR_VALUE = 0xff;
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43
44 private final Map<String, Object> fStyleMap;
45
46 private final Map<String, Object> fReadOnlyStyleMap;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51
52 /**
53 * Creates a state item with given color and unspecified name.
54 *
55 * @param stateColor
56 * A state color
57 */
58 public StateItem(RGB stateColor) {
59 this(stateColor, UNDEFINED_STATE_NAME);
60 }
61
62 /**
63 * Creates a state color - state string pair.
64 *
65 * @param stateColor
66 * A state color
67 * @param stateString
68 * A state string
69 */
70 public StateItem(RGB stateColor, String stateString) {
71 int stateColorInt = stateColor.red << 24 | stateColor.green << 16 | stateColor.blue << 8 | 0xff;
72 fStyleMap = new HashMap<>();
73 fReadOnlyStyleMap = Collections.unmodifiableMap(fStyleMap);
74 fStyleMap.put(ITimeEventStyleStrings.fillStyle(), ITimeEventStyleStrings.solidColorFillStyle());
75 fStyleMap.put(ITimeEventStyleStrings.fillColor(), stateColorInt);
76 fStyleMap.put(ITimeEventStyleStrings.label(), stateString);
77 }
78
79 // ------------------------------------------------------------------------
80 // Accessors
81 // ------------------------------------------------------------------------
82 /**
83 * Returns the state color.
84 *
85 * @return Returns the state color.
86 */
87 public RGB getStateColor() {
88 int rgbInt = (int) fStyleMap.getOrDefault(ITimeEventStyleStrings.fillColor(), UNDEFINED_COLOR_VALUE);
89 return new RGB((rgbInt >> 24) & 0xff, (rgbInt >> 16) & 0xff, (rgbInt >> 8) & 0xff);
90 }
91
92 /**
93 * Sets the state color.
94 *
95 * @param stateColor
96 * A state color to set
97 */
98 public void setStateColor(RGB stateColor) {
99 fStyleMap.put(ITimeEventStyleStrings.fillColor(), stateColor);
100 }
101
102 /**
103 * Returns the state string.
104 *
105 * @return the state string.
106 */
107 public String getStateString() {
108 return String.valueOf(fStyleMap.getOrDefault(ITimeEventStyleStrings.label(), UNDEFINED_STATE_NAME));
109 }
110
111 /**
112 * Sets the state string
113 *
114 * @param stateString
115 * A state string to set
116 */
117 public void setStateString(String stateString) {
118 fStyleMap.put(ITimeEventStyleStrings.label(), stateString);
119 }
120
121 /**
122 * Gets the height factor of a given state (how thick it will be when
123 * displayed)
124 *
125 * @return The map of styles
126 *
127 * @since 2.4
128 */
129 public Map<String, Object> getStyleMap() {
130 return fReadOnlyStyleMap;
131 }
132 }
This page took 0.0473789999999999 seconds and 6 git commands to generate.