tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / Lifeline.java
CommitLineData
73005152 1/**********************************************************************
c8422608 2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
73005152
BH
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
abbdd66a
AM
7 *
8 * Contributors:
c8422608
AM
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
73005152 11 **********************************************************************/
c8422608 12
73005152
BH
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
14
15import java.util.ArrayList;
16import java.util.List;
17
18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor;
19import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
20import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage;
df0b8ff4 21import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
3145ec83 22import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
73005152
BH
23
24/**
25 * Lifeline is the UML2 lifeline graphical representation.<br>
26 * Each lifeline owns a set of event occurrences. An event occurrence is the base element in UML2 to set an event in a
27 * sequence diagram.<br>
28 * Event occurrence define the drawing order of graph node along a lifeline. In this lifeline implementation, event
29 * occurrences are just integer index. The event occurrences with the same value on different lifelines will correspond
30 * the same y coordinate value.
abbdd66a 31 *
df0b8ff4 32 * @version 1.0
73005152 33 * @author sveyrier
abbdd66a 34 *
73005152
BH
35 */
36public class Lifeline extends GraphNode {
df0b8ff4
BH
37 // ------------------------------------------------------------------------
38 // Constants
39 // ------------------------------------------------------------------------
40 /**
41 * The life line tag.
42 */
43 public static final String LIFELINE_TAG = "Lifeline"; //$NON-NLS-1$
73005152 44
df0b8ff4
BH
45 // ------------------------------------------------------------------------
46 // Attribute
47 // ------------------------------------------------------------------------
73005152
BH
48 /**
49 * The lifeline position in the containing frame
50 */
eb63f5ff 51 protected int fIndexInFrame = 0;
73005152
BH
52 /**
53 * The frame where the lifeline is drawn
54 */
eb63f5ff 55 protected Frame fFrame = null;
73005152
BH
56 /**
57 * The current event occurrence created in the lifeline
58 */
eb63f5ff 59 protected int fEventOccurrence = 0;
df0b8ff4
BH
60 /**
61 * The lifeline category.
62 */
eb63f5ff 63 protected int fCategory = -1;
df0b8ff4
BH
64 /**
65 * Flag whether lifeline has time information available or not
66 */
eb63f5ff 67 protected boolean fHasTimeInfo = false;
73005152 68
df0b8ff4
BH
69 // ------------------------------------------------------------------------
70 // Constructors
71 // ------------------------------------------------------------------------
72 /**
73 * Default constructor
74 */
75 public Lifeline() {
eb63f5ff 76 fPrefId = ISDPreferences.PREF_LIFELINE;
df0b8ff4
BH
77 }
78
79 // ------------------------------------------------------------------------
80 // Methods
81 // ------------------------------------------------------------------------
11252342 82
73005152
BH
83 @Override
84 public int getX() {
eb63f5ff 85 return Metrics.FRAME_H_MARGIN + Metrics.LIFELINE_H_MAGIN + (fIndexInFrame - 1) * Metrics.swimmingLaneWidth();
73005152
BH
86 }
87
88 @Override
89 public int getY() {
90 return 2 * Metrics.FRAME_NAME_H_MARGIN + Metrics.LIFELINE_VT_MAGIN / 2 + Metrics.getFrameFontHeigth() + Metrics.getLifelineHeaderFontHeigth() + Metrics.FRAME_V_MARGIN + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN;
91 }
92
93 @Override
94 public int getWidth() {
95 return Metrics.getLifelineWidth();
96 }
97
98 @Override
99 public int getHeight() {
100 // Set room for two text lines
101 return Metrics.getLifelineFontHeigth()/** 2 */
102 + 2 * Metrics.LIFELINE_NAME_H_MARGIN;
103 }
104
73005152
BH
105 /**
106 * Set the lifeline category for this lifeline.
abbdd66a 107 *
73005152
BH
108 * @param arrayIndex the index of the category to use
109 * @see Frame#setLifelineCategories(LifelineCategories[])
110 */
111 public void setCategory(int arrayIndex) {
eb63f5ff 112 fCategory = arrayIndex;
73005152
BH
113 }
114
115 /**
116 * Returns the tooltip text for the lifeline. It is the combination between the category name(if any) and the
117 * lifeline name
abbdd66a 118 *
73005152
BH
119 * @return the tooltip text
120 */
121 public String getToolTipText() {
eb63f5ff
BH
122 if (fCategory >= 0) {
123 LifelineCategories[] categories = fFrame.getLifelineCategories();
124 if (fCategory < categories.length) {
125 return categories[fCategory].getName() + " " + getName(); //$NON-NLS-1$
df0b8ff4 126 }
df0b8ff4 127 }
abbdd66a 128 return ""; //$NON-NLS-1$
73005152
BH
129 }
130
131 /**
132 * Returns the index of the first visible Execution Occurrence in the execution occurrence array.<br>
133 * Execution Occurrences are Y ordered in this array
abbdd66a 134 *
73005152
BH
135 * @return the first visible Execution Occurrence
136 */
137 public int getExecOccurrenceDrawIndex() {
eb63f5ff 138 if (!fHasChilden) {
73005152 139 return 0;
df0b8ff4 140 }
eb63f5ff 141 if (fIndexes.get(BasicExecutionOccurrence.EXEC_OCC_TAG) != null) {
abbdd66a 142 return fIndexes.get(BasicExecutionOccurrence.EXEC_OCC_TAG).intValue();
df0b8ff4
BH
143 }
144 return 0;
73005152
BH
145 }
146
147 /**
148 * Set the frame on which this lifeline must be drawn
abbdd66a 149 *
73005152 150 * @param parentFrame
a0a88f65 151 * Parent frame
73005152
BH
152 */
153 protected void setFrame(Frame parentFrame) {
eb63f5ff
BH
154 fFrame = parentFrame;
155 if (fHasTimeInfo) {
156 fFrame.setHasTimeInfo(true);
73005152 157 }
eb63f5ff
BH
158 if (fFrame.getMaxEventOccurrence() < getEventOccurrence() + 1) {
159 fFrame.setMaxEventOccurrence(getEventOccurrence() + 1);
df0b8ff4 160 }
73005152
BH
161 }
162
163 /**
164 * Returns the frame which this lifeline is drawn
abbdd66a 165 *
73005152
BH
166 * @return the Frame
167 */
168 protected Frame getFrame() {
eb63f5ff 169 return fFrame;
73005152
BH
170 }
171
172 /**
173 * Set the lifeline position index in the containing frame
abbdd66a 174 *
73005152
BH
175 * @param index the lifeline X position
176 */
73005152 177 protected void setIndex(int index) {
eb63f5ff 178 fIndexInFrame = index;
73005152
BH
179 }
180
181 /**
182 * Returns the lifeline position in de the containing frame
abbdd66a 183 *
73005152
BH
184 * @return the X position
185 */
186 public int getIndex() {
eb63f5ff 187 return fIndexInFrame;
73005152
BH
188 }
189
190 /**
191 * Set the lifeline event occurrence to the value given in parameter This only change the current event occurrence,
192 * greater event created on this lifeline are still valid and usable. This also need to inform the frame of the
193 * operation mostly to store in the frame the greater event found in the diagram (used to determine the frame
194 * height)
abbdd66a 195 *
0d9a6d76 196 * @param eventOcc the new current event occurrence
73005152
BH
197 */
198 public void setCurrentEventOccurrence(int eventOcc) {
eb63f5ff
BH
199 if ((fFrame != null) && (fFrame.getMaxEventOccurrence() < eventOcc)) {
200 fFrame.setMaxEventOccurrence(eventOcc);
df0b8ff4 201 }
eb63f5ff 202 fEventOccurrence = eventOcc;
73005152
BH
203 }
204
205 /**
206 * Returns the last created event occurrence along the lifeline.
abbdd66a 207 *
73005152
BH
208 * @return the current event occurrence
209 */
210 public int getEventOccurrence() {
eb63f5ff 211 return fEventOccurrence;
73005152
BH
212 }
213
214 /**
215 * Creates a new event occurrence along the lifeline.
abbdd66a 216 *
73005152
BH
217 * @return the new created event occurrence
218 */
219 public int getNewEventOccurrence() {
eb63f5ff
BH
220 setCurrentEventOccurrence(fEventOccurrence + 1);
221 return fEventOccurrence;
73005152
BH
222 }
223
224 /**
225 * Adds the execution occurrence given in parameter to the lifeline.<br>
226 * A Execution occurrence is never drawn in the frame instead it is added to a lifeline
abbdd66a 227 *
73005152
BH
228 * @param exec the execution occurrence to add
229 */
230 public void addExecution(BasicExecutionOccurrence exec) {
231 exec.setLifeline(this);
232 addNode(exec);
eb63f5ff
BH
233 if ((fFrame != null) && (fFrame.getMaxEventOccurrence() < exec.fEndEventOccurrence)) {
234 fFrame.setMaxEventOccurrence(exec.fEndEventOccurrence);
df0b8ff4 235 }
73005152
BH
236 }
237
df0b8ff4
BH
238 /**
239 * Set whether lifeline has time information available or not.
240 * @param value The value to set
241 */
73005152 242 protected void setTimeInfo(boolean value) {
eb63f5ff
BH
243 fHasTimeInfo = value;
244 if ((fFrame != null) && value) {
245 fFrame.setHasTimeInfo(value);
df0b8ff4 246 }
73005152
BH
247 }
248
249 /**
df0b8ff4 250 * Returns true if at least one execution occurrence has time info.
abbdd66a 251 *
73005152
BH
252 * @return true if at least one execution occurrence has time info
253 */
254 public boolean hasTimeInfo() {
eb63f5ff 255 return fHasTimeInfo;
73005152
BH
256 }
257
258 /**
df0b8ff4 259 * Returns the list of execution occurrence on this lifeline.
abbdd66a 260 *
73005152
BH
261 * @return the execution occurrence list
262 */
263 public List<GraphNode> getExecutions() {
eb63f5ff 264 if (fHasChilden) {
abbdd66a 265 return fNodes.get(BasicExecutionOccurrence.EXEC_OCC_TAG);
df0b8ff4
BH
266 }
267 return new ArrayList<GraphNode>();
73005152
BH
268 }
269
270 @Override
eb63f5ff 271 public boolean contains(int xValue, int yValue) {
73005152
BH
272 int x = getX();
273 int y = getY();
274 int width = getWidth();
275 int height = getHeight();
276
eb63f5ff 277 if (fFrame == null) {
73005152 278 return false;
df0b8ff4 279 }
abbdd66a 280 if (GraphNode.contains(x, y, width, height, xValue, yValue)) {
73005152
BH
281 return true;
282 }
abbdd66a 283 if (GraphNode.contains(x + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2, y + height, Metrics.EXECUTION_OCCURRENCE_WIDTH, (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fFrame.getMaxEventOccurrence()
eb63f5ff 284 + Metrics.LIFELINE_VB_MAGIN - 4, xValue, yValue)) {
73005152
BH
285 return true;
286 }
287
288 height = Metrics.getLifelineFontHeigth() + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN;
289 int hMargin = (Metrics.LIFELINE_VT_MAGIN - height) / 2;
290
291 if (hMargin >= 2) {
eb63f5ff 292 if (fFrame.getVisibleAreaY() < y - height - hMargin) {
abbdd66a 293 if (GraphNode.contains(x - Metrics.LIFELINE_SPACING / 2 + 1, y - height - hMargin, Metrics.swimmingLaneWidth() - 2, height + 1, xValue, yValue)) {
73005152 294 return true;
df0b8ff4 295 }
73005152 296 } else {
abbdd66a 297 if (GraphNode.contains(x - Metrics.LIFELINE_SPACING / 2 + 1, fFrame.getVisibleAreaY(), Metrics.swimmingLaneWidth() - 2, height, xValue, yValue)) {
73005152 298 return true;
df0b8ff4 299 }
73005152
BH
300 }
301 }
eb63f5ff 302 if (getNodeAt(xValue, yValue) != null) {
73005152 303 return true;
df0b8ff4 304 }
73005152
BH
305 return false;
306 }
307
308 /**
309 * Returns the lifeline visibility for the given visible area
abbdd66a 310 *
df0b8ff4
BH
311 * @param vx The x coordinate of the visible area
312 * @param vy The y coordinate of the visible area
313 * @param vwidth The width of the visible area
314 * @param vheight The height of the visible area
73005152
BH
315 * @return true if visible false otherwise
316 */
317 @Override
318 public boolean isVisible(int vx, int vy, int vwidth, int vheight) {
319 int x = getX();
320 int width = getWidth();
df0b8ff4 321 if (((x >= vx) && (x <= vx + vwidth)) || ((x + width >= vx) && (x <= vx))) {
73005152 322 return true;
df0b8ff4 323 }
73005152
BH
324 return false;
325 }
326
df0b8ff4 327 /**
abbdd66a
AM
328 * Draws the name within the graphical context.
329 *
df0b8ff4
BH
330 * @param context The graphical context.
331 */
73005152 332 protected void drawName(IGC context) {
3145ec83
BH
333 ISDPreferences pref = SDViewPref.getInstance();
334
73005152
BH
335 int x = getX();
336 int y = getY();
337 int height = Metrics.getLifelineHeaderFontHeigth() + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN;
338 int hMargin = Metrics.LIFELINE_VT_MAGIN / 4;// (Metrics.LIFELINE_NAME_H_MARGIN)/2;
339
340 context.setLineStyle(context.getLineSolidStyle());
3145ec83
BH
341 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_LIFELINE_HEADER));
342 context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_LIFELINE_HEADER));
343 context.setFont(pref.getFont(ISDPreferences.PREF_LIFELINE_HEADER));
73005152 344 if (hMargin >= 0) {
eb63f5ff 345 if (fFrame.getVisibleAreaY() < y - height - hMargin) {
73005152
BH
346 context.fillRectangle(x - Metrics.LIFELINE_SPACING / 2 + 1, y - height - hMargin, Metrics.swimmingLaneWidth() - 2, height);
347 context.drawRectangle(x - Metrics.LIFELINE_SPACING / 2 + 1, y - height - hMargin, Metrics.swimmingLaneWidth() - 2, height);
3145ec83 348 context.setForeground(pref.getFontColor(ISDPreferences.PREF_LIFELINE_HEADER));
73005152
BH
349 context.drawTextTruncatedCentred(getName(), x + Metrics.LIFELINE_NAME_V_MARGIN - Metrics.LIFELINE_SPACING / 2 + 1, y - height - hMargin, Metrics.swimmingLaneWidth() - 2 * Metrics.LIFELINE_NAME_V_MARGIN - 2, height, true);
350 } else {
eb63f5ff
BH
351 context.fillRectangle(x - Metrics.LIFELINE_SPACING / 2 + 1, fFrame.getVisibleAreaY(), Metrics.swimmingLaneWidth() - 2, height);
352 context.drawRectangle(x - Metrics.LIFELINE_SPACING / 2 + 1, fFrame.getVisibleAreaY(), Metrics.swimmingLaneWidth() - 2, height);
3145ec83 353 context.setForeground(pref.getFontColor(ISDPreferences.PREF_LIFELINE_HEADER));
eb63f5ff 354 context.drawTextTruncatedCentred(getName(), x - Metrics.LIFELINE_SPACING / 2 + Metrics.LIFELINE_NAME_V_MARGIN + 1, fFrame.getVisibleAreaY(), Metrics.swimmingLaneWidth() - 2 * Metrics.LIFELINE_NAME_V_MARGIN - 2, height, true);
73005152
BH
355 }
356 }
357 }
358
359 /**
360 * Force the lifeline to be drawn at the given coordinate
abbdd66a 361 *
73005152 362 * @param context - the context to draw into
0d9a6d76
FC
363 * @param x - the x coordinate
364 * @param y - the y coordinate
73005152
BH
365 */
366 public void draw(IGC context, int x, int y) {
abbdd66a 367
3145ec83 368 ISDPreferences pref = SDViewPref.getInstance();
abbdd66a 369
73005152
BH
370 // Set the draw color depending if the lifeline must be selected or not
371 context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
372 if (isSelected()) {
3145ec83
BH
373 if (pref.useGradienColor()) {
374 context.setGradientColor(pref.getBackGroundColor(ISDPreferences.PREF_LIFELINE));
73005152 375 }
3145ec83
BH
376 context.setBackground(pref.getBackGroundColorSelection());
377 context.setForeground(pref.getForeGroundColorSelection());
73005152 378 } else {
3145ec83
BH
379 if (pref.useGradienColor()) {
380 context.setGradientColor(pref.getBackGroundColor(ISDPreferences.PREF_LIFELINE));
381 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME));
df0b8ff4 382 } else {
3145ec83 383 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_LIFELINE));
df0b8ff4 384 }
3145ec83 385 context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_LIFELINE));
73005152
BH
386 }
387 // Store the lifeline coordinates to save some calls
388 int width = getWidth();
389 int height = getHeight();
390
391 // Draw the rectangle which contain the lifeline name
3145ec83 392 if (pref.useGradienColor()) {
73005152
BH
393 context.fillGradientRectangle(x, y, width, height / 2 - 7, true);
394 context.fillRectangle(x, y + height / 2 - 8, width, +height / 2 - 5);
395 context.fillGradientRectangle(x, y + height, width, -height / 2 + 6, true);
df0b8ff4 396 } else {
73005152 397 context.fillRectangle(x, y, width, height);
df0b8ff4 398 }
73005152
BH
399 context.drawRectangle(x, y, width, height);
400
eb63f5ff
BH
401 if (fCategory >= 0) {
402 LifelineCategories[] categories = fFrame.getLifelineCategories();
403 if (fCategory < categories.length) {
404 IImage image = categories[fCategory].getImage();
df0b8ff4 405 if (image != null) {
73005152 406 context.drawImage(image, x, y, width, height);
df0b8ff4 407 }
73005152
BH
408 }
409 }
410
411 // Draw the lifeline label into the rectangle
412 // The label is truncated if it cannot fit
413 IColor temp = context.getForeground();
3145ec83
BH
414 context.setFont(pref.getFont(ISDPreferences.PREF_LIFELINE));
415 context.setForeground(pref.getFontColor(ISDPreferences.PREF_LIFELINE));
73005152
BH
416 context.drawTextTruncatedCentred(getName(), x + Metrics.LIFELINE_NAME_V_MARGIN, y, Metrics.getLifelineWidth() - 2 * Metrics.LIFELINE_NAME_V_MARGIN, height, true);
417
418 context.setLineStyle(context.getLineDashStyle());
419 context.setForeground(temp);
420 int oldStyle = context.getLineStyle();
421
422 // Now draw the lifeline vertical line
423 // this line height depends on a stop assignment
424 // if there is no stop the line is drawn to the bottom of the frame
425
426 // by default set the height to reach the frame bottom
eb63f5ff 427 int dashedLineEnd = y + height + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fFrame.getMaxEventOccurrence() + Metrics.LIFELINE_VB_MAGIN;
73005152
BH
428 /*
429 * if (stop != null) { dashedLineEnd = stop.getY(); }
430 */
431
432 if (isSelected()) {
3145ec83 433 context.setForeground(pref.getBackGroundColorSelection());
73005152
BH
434 context.setLineWidth(5);
435 context.drawLine(x + Metrics.getLifelineWidth() / 2, y + height, x + Metrics.getLifelineWidth() / 2, dashedLineEnd - 4);
3145ec83 436 context.setForeground(pref.getForeGroundColorSelection());
73005152
BH
437 }
438
439 context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
440 context.drawLine(x + Metrics.getLifelineWidth() / 2, y + height, x + Metrics.getLifelineWidth() / 2, dashedLineEnd - 4);
441 context.drawLine(x + Metrics.getLifelineWidth() / 2, y + height, x + Metrics.getLifelineWidth() / 2, dashedLineEnd - 4);
442 context.setLineStyle(oldStyle);
443
444 context.setLineStyle(context.getLineSolidStyle());
445
df0b8ff4 446 if (hasFocus()) {
73005152 447 drawFocus(context);
df0b8ff4 448 }
73005152
BH
449
450 super.drawChildenNodes(context);
451 }
452
453 /**
454 * Draws the select execution occurrence region using the given color
abbdd66a 455 *
73005152
BH
456 * @param context the graphical context
457 * @param startEvent the region start
458 * @param nbEvent the region height
459 * @param color the color to use
460 */
461 public void highlightExecOccurrenceRegion(IGC context, int startEvent, int nbEvent, IColor color) {
462 IColor backupColor = context.getBackground();
463 context.setBackground(color);
464 int x = getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
465 int y = getY() + getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEvent;
466 int width = Metrics.EXECUTION_OCCURRENCE_WIDTH;
467 int height = ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * nbEvent;
468 context.fillRectangle(x, y, width, height);
469 context.setBackground(backupColor);
470 }
471
472 @Override
473 public void draw(IGC context) {
474 draw(context, getX(), getY());
475 }
476
477 @Override
478 public String getArrayId() {
479 return LIFELINE_TAG;
480 }
481
482 @Override
483 public boolean positiveDistanceToPoint(int x, int y) {
abbdd66a 484 if (getX() > x - Metrics.swimmingLaneWidth()) {
73005152 485 return true;
abbdd66a 486 }
73005152
BH
487 return false;
488 }
489
490 @Override
491 public GraphNode getNodeAt(int x, int y) {
492 int vy = 0;
493 int vh = 0;
494 if (getFrame() != null) {
495 vy = getFrame().getVisibleAreaY();
496 vh = getFrame().getVisibleAreaHeight();
df0b8ff4 497 } else {
73005152 498 return null;
df0b8ff4
BH
499 }
500 if (getExecutions() == null) {
73005152 501 return null;
df0b8ff4 502 }
73005152 503 for (int i = getExecOccurrenceDrawIndex(); i < getExecutions().size(); i++) {
abbdd66a 504 GraphNode node = getExecutions().get(i);
73005152 505 if (node.getHeight() < 0) {
df0b8ff4 506 if (node.getY() + node.getHeight() > vy + vh) {
73005152 507 break;
df0b8ff4 508 }
73005152 509 } else {
df0b8ff4 510 if (node.getY() > vy + vh) {
73005152 511 break;
df0b8ff4 512 }
73005152
BH
513 }
514 if (node.contains(x, y)) {
515 GraphNode internal = node.getNodeAt(x, y);
df0b8ff4 516 if (internal != null) {
73005152 517 return internal;
df0b8ff4
BH
518 }
519 return node;
73005152
BH
520 }
521 }
522 return null;
523 }
524}
This page took 0.060087 seconds and 5 git commands to generate.