Contribution for Bug352466: [TMF] Implement UML2 Sequence Diagram
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / Stop.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2006, 2011 IBM Corporation and others.
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 * $Id: Stop.java,v 1.2 2006/09/20 20:56:25 ewchan Exp $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
14
15 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
16 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences;
17
18 /**
19 * It is the UML2 stop graphical representation in the sequence diagram viewer.<br>
20 * This draw a cross on the lifeline. The stop y coordinate depend on the event occurrence when it appears.<br>
21 * A stop is never drawn it is assigned to a lifeline.<br>
22 * <br>
23 *
24 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline#setStop(Stop)
25 * @author sveyrier
26 *
27 */
28 public class Stop extends GraphNode {
29
30 /**
31 * The owning lifeline on which the stop appears
32 */
33 protected Lifeline lifeline = null;
34
35 /**
36 * The graphNode ID
37 */
38 public static final String STOP = "STOP"; //$NON-NLS-1$
39
40 /**
41 * This basically represents the time when the stop occurs on the owning Lifeline
42 *
43 * @see Lifeline Lifeline for more event occurence details
44 */
45 protected int eventOccurrence = 0;
46
47 @Override
48 public int getX() {
49 if (lifeline == null)
50 return 0;
51 return lifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.STOP_WIDTH / 2;
52 }
53
54 @Override
55 public int getY() {
56 if (lifeline == null)
57 return 0;
58 return lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * eventOccurrence - Metrics.STOP_WIDTH / 2;
59 }
60
61 @Override
62 public int getWidth() {
63 if (lifeline == null)
64 return 0;
65 return Metrics.STOP_WIDTH;
66 }
67
68 @Override
69 public int getHeight() {
70 if (lifeline == null)
71 return 0;
72 return Metrics.STOP_WIDTH;
73 }
74
75 /**
76 * Set the lifeline on which the stop must be draw
77 *
78 * @param theLifeline The the stop owing lifeline
79 */
80 public void setLifeline(Lifeline theLifeline) {
81 lifeline = theLifeline;
82 }
83
84 /**
85 * Set the event occurrence when this stop appears
86 *
87 * @param occurrence the eventOccurence to assign to the stop
88 */
89 public void setEventOccurrence(int occurrence) {
90 eventOccurrence = occurrence;
91 }
92
93 @Override
94 public void draw(IGC context) {
95 // Set the appropriate color depending if the graph node if selected or not
96 if (lifeline.isSelected()) {
97 context.setForeground(Frame.getUserPref().getBackGroundColorSelection());
98 context.setLineWidth(Metrics.SELECTION_LINE_WIDTH);
99 int lastWidth = context.getLineWidth();
100 context.setLineWidth(9);
101 // Draw a cross on the lifeline
102 context.drawLine(getX(), getY(), getX() + getWidth(), getY() + getHeight());
103 context.drawLine(getX() + getWidth(), getY(), getX(), getY() + getHeight());
104 // restore the context
105 context.setLineWidth(lastWidth);
106 context.setBackground(Frame.getUserPref().getBackGroundColorSelection());
107 context.setForeground(Frame.getUserPref().getForeGroundColorSelection());
108 } else {
109 context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_LIFELINE));
110 context.setForeground(Frame.getUserPref().getForeGroundColor(ISDPreferences.PREF_LIFELINE));
111 }
112 int lastWidth = context.getLineWidth();
113 context.setLineWidth(3);
114 // Draw a cross on the lifeline
115 context.drawLine(getX(), getY(), getX() + getWidth(), getY() + getHeight());
116 context.drawLine(getX() + getWidth(), getY(), getX(), getY() + getHeight());
117 // restore the context
118 context.setLineWidth(lastWidth);
119 }
120
121 /*
122 * (non-Javadoc)
123 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
124 */
125 @Override
126 public String getArrayId() {
127 return STOP;
128 }
129
130 /*
131 * (non-Javadoc)
132 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
133 */
134 @Override
135 public boolean contains(int x, int y) {
136 // TODO Auto-generated method stub
137 return false;
138 }
139 }
This page took 0.033051 seconds and 5 git commands to generate.