1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
;
14 import java
.util
.Collections
;
15 import java
.util
.HashMap
;
18 import org
.eclipse
.swt
.graphics
.RGB
;
19 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEventStyleStrings
;
22 * Class that contains the color of a state and the corresponding state string
26 * @author Bernd Hufmann
28 public class StateItem
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 * Name of state if not known
36 public static final String UNDEFINED_STATE_NAME
= "Undefined"; //$NON-NLS-1$
38 private static final int UNDEFINED_COLOR_VALUE
= 0xff;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 private final Map
<String
, Object
> fStyleMap
;
46 private final Map
<String
, Object
> fReadOnlyStyleMap
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * Creates a state item with given color and unspecified name.
58 public StateItem(RGB stateColor
) {
59 this(stateColor
, UNDEFINED_STATE_NAME
);
63 * Creates a state color - state string pair.
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
);
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
83 * Returns the state color.
85 * @return Returns the state color.
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);
93 * Sets the state color.
96 * A state color to set
98 public void setStateColor(RGB stateColor
) {
99 fStyleMap
.put(ITimeEventStyleStrings
.fillColor(), stateColor
);
103 * Returns the state string.
105 * @return the state string.
107 public String
getStateString() {
108 return String
.valueOf(fStyleMap
.getOrDefault(ITimeEventStyleStrings
.label(), UNDEFINED_STATE_NAME
));
112 * Sets the state string
115 * A state string to set
117 public void setStateString(String stateString
) {
118 fStyleMap
.put(ITimeEventStyleStrings
.label(), stateString
);
122 * Gets the height factor of a given state (how thick it will be when
125 * @return The map of styles
129 public Map
<String
, Object
> getStyleMap() {
130 return fReadOnlyStyleMap
;