| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2005, 2013 IBM Corporation, Ericsson |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM - Initial API and implementation |
| 10 | * Bernd Hufmann - Updated for TMF |
| 11 | **********************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; |
| 14 | |
| 15 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
| 16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; |
| 17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; |
| 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; |
| 19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
| 20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; |
| 21 | |
| 22 | /** |
| 23 | * ExecutionOccurrence is the UML2 execution occurrence graphical representation. It is a BasicExecutionOccurrence on |
| 24 | * which you can customize fill and/or. |
| 25 | * |
| 26 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details |
| 27 | * @version 1.0 |
| 28 | * @author sveyrier |
| 29 | * |
| 30 | */ |
| 31 | public class ExecutionOccurrence extends BasicExecutionOccurrence implements ITimeRange { |
| 32 | |
| 33 | // ------------------------------------------------------------------------ |
| 34 | // Attributes |
| 35 | // ------------------------------------------------------------------------ |
| 36 | /** |
| 37 | * Set the red, green and blue value of the optional color to be used for filling the execution occurrence. |
| 38 | */ |
| 39 | protected int[] fFillRGB; |
| 40 | /** |
| 41 | * Set the red, green and blue value of the optional color to be used for drawing the execution occurrence |
| 42 | */ |
| 43 | protected int[] fStrokeRGB; |
| 44 | /** |
| 45 | * The occurrence image. |
| 46 | */ |
| 47 | protected IImage fImage; |
| 48 | /** |
| 49 | * The top ellipses image. |
| 50 | */ |
| 51 | protected IImage fEllipsesImage; |
| 52 | /** |
| 53 | * The start time stamp. |
| 54 | */ |
| 55 | protected ITmfTimestamp fStartTime; |
| 56 | /** |
| 57 | * The end time stamp; |
| 58 | */ |
| 59 | protected ITmfTimestamp fEndTime; |
| 60 | /** |
| 61 | * Flag to indicate whether time information is available or not. |
| 62 | */ |
| 63 | protected boolean fHasTimeInfo; |
| 64 | |
| 65 | // ------------------------------------------------------------------------ |
| 66 | // Methods |
| 67 | // ------------------------------------------------------------------------ |
| 68 | /* |
| 69 | * (non-Javadoc) |
| 70 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setLifeline(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline) |
| 71 | */ |
| 72 | @Override |
| 73 | public void setLifeline(Lifeline theLifeline) { |
| 74 | super.setLifeline(theLifeline); |
| 75 | if (fLifeline != null && fHasTimeInfo) { |
| 76 | fLifeline.fHasTimeInfo = true; |
| 77 | if (fLifeline.getFrame() != null) { |
| 78 | fLifeline.getFrame().setHasTimeInfo(true); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Set the red, green and blue value of the optional color to be used for filling the execution occurrence. |
| 85 | * |
| 86 | * @param red A value for red. |
| 87 | * @param green A green value for green. |
| 88 | * @param blue A value blue. |
| 89 | */ |
| 90 | public void setFillColor(int red, int green, int blue) { |
| 91 | fFillRGB = new int[3]; |
| 92 | fFillRGB[0] = red; |
| 93 | fFillRGB[1] = green; |
| 94 | fFillRGB[2] = blue; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Set the red, green and blue value of the optional color to be used for drawing the execution occurrence |
| 99 | * |
| 100 | * @param red A value for red. |
| 101 | * @param green A green value for green. |
| 102 | * @param blue A value blue. |
| 103 | */ |
| 104 | public void setStrokeColor(int red, int green, int blue) { |
| 105 | fStrokeRGB = new int[3]; |
| 106 | fStrokeRGB[0] = red; |
| 107 | fStrokeRGB[1] = green; |
| 108 | fStrokeRGB[2] = blue; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Set the corresponding image. |
| 113 | * |
| 114 | * @param image A image to set. |
| 115 | */ |
| 116 | public void setImage(IImage image) { |
| 117 | fImage = image; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Set the top ellipses image. |
| 122 | * |
| 123 | * @param image A image to set. |
| 124 | */ |
| 125 | public void setTopEllipsesImage(IImage image) { |
| 126 | fEllipsesImage = image; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Set the time when the execution occurrence starts. |
| 131 | * |
| 132 | * @param time the time when the execution occurrence starts |
| 133 | * @since 2.0 |
| 134 | */ |
| 135 | public void setStartTime(ITmfTimestamp time) { |
| 136 | fStartTime = time; |
| 137 | fHasTimeInfo = true; |
| 138 | if (fLifeline != null) { |
| 139 | fLifeline.setTimeInfo(true); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Set the time when the execution occurrence ends. |
| 145 | * |
| 146 | * @param time the time when the execution occurrence ends |
| 147 | * @since 2.0 |
| 148 | */ |
| 149 | public void setEndTime(ITmfTimestamp time) { |
| 150 | fEndTime = time; |
| 151 | fHasTimeInfo = true; |
| 152 | if (fLifeline != null) { |
| 153 | fLifeline.setTimeInfo(true); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * @since 2.0 |
| 159 | */ |
| 160 | @Override |
| 161 | public ITmfTimestamp getStartTime() { |
| 162 | return fStartTime; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @since 2.0 |
| 167 | */ |
| 168 | @Override |
| 169 | public ITmfTimestamp getEndTime() { |
| 170 | return fEndTime; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * (non-Javadoc) |
| 175 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#hasTimeInfo() |
| 176 | */ |
| 177 | @Override |
| 178 | public boolean hasTimeInfo() { |
| 179 | return fHasTimeInfo; |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * (non-Javadoc) |
| 184 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) |
| 185 | */ |
| 186 | @Override |
| 187 | public void draw(IGC context) { |
| 188 | super.draw(context); |
| 189 | int x = getX(); |
| 190 | int y = getY(); |
| 191 | int width = getWidth(); |
| 192 | int height = getHeight(); |
| 193 | if (fImage != null) { |
| 194 | context.drawImage(fImage, x + width - 4, y + height - 11, 8, 11); |
| 195 | } |
| 196 | if (fEllipsesImage != null) { |
| 197 | context.drawImage(fEllipsesImage, x + width, y, 40, 10); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * (non-Javadoc) |
| 203 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setUnselectedFillColor(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) |
| 204 | */ |
| 205 | @Override |
| 206 | protected IColor setUnselectedFillColor(IGC context) { |
| 207 | ISDPreferences pref = SDViewPref.getInstance(); |
| 208 | if (fFillRGB != null) { |
| 209 | IColor tempFillColor = context.createColor(fFillRGB[0], fFillRGB[1], fFillRGB[2]); |
| 210 | if (pref.useGradienColor()) { |
| 211 | context.setGradientColor(tempFillColor); |
| 212 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_EXEC)); |
| 213 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME)); |
| 214 | } else { |
| 215 | context.setBackground(tempFillColor); |
| 216 | } |
| 217 | return tempFillColor; |
| 218 | } |
| 219 | return super.setUnselectedFillColor(context); |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * (non-Javadoc) |
| 224 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence#setUnselectedStrokeColor(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) |
| 225 | */ |
| 226 | @Override |
| 227 | protected IColor setUnselectedStrokeColor(IGC context) { |
| 228 | if (fStrokeRGB != null) { |
| 229 | IColor tempStrokeColor = context.createColor(fStrokeRGB[0], fStrokeRGB[1], fStrokeRGB[2]); |
| 230 | context.setForeground(tempStrokeColor); |
| 231 | return tempStrokeColor; |
| 232 | } |
| 233 | return super.setUnselectedStrokeColor(context); |
| 234 | } |
| 235 | } |