tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / EllipsisMessage.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2012 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.ui.views.uml2sd.drawings.IColor;
16 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
17 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
18 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
19
20 /**
21 * Class to draw Ellipsis Message.
22 *
23 * @version 1.0
24 * @author sveyrier
25 *
26 */
27 public class EllipsisMessage extends AsyncMessage {
28
29 /*
30 * (non-Javadoc)
31 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#getX()
32 */
33 @Override
34 public int getX() {
35 if (fStartLifeline == null) {
36 return super.getX() + super.getWidth() - 16;
37 }
38 return super.getX();
39 }
40
41 /*
42 * (non-Javadoc)
43 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#getY()
44 */
45 @Override
46 public int getY() {
47 return super.getY() + 3;
48 }
49
50 /*
51 * (non-Javadoc)
52 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#getWidth()
53 */
54 @Override
55 public int getWidth() {
56 return 16;
57 }
58
59 /*
60 * (non-Javadoc)
61 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#drawMessage(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
62 */
63 @Override
64 protected void drawMessage(IGC context) {
65 // temporary store the coordinates to avoid more methods calls
66 int x = super.getX();
67 int y = getY();
68 int width = super.getWidth();
69 int height = getHeight();
70
71 // UML2 found message (always drawn from left to right)
72 if (fStartLifeline == null && fEndLifeline != null) {
73 // Draw the message label above the message and centered
74 // The label is truncated if it cannot fit between the two message end
75 // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
76 context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected());
77
78 int currentStyle = context.getLineStyle();
79 context.setLineStyle(context.getLineSolidStyle());
80 // Draw the message main line
81 context.drawRectangle(x + width - 5, y, x + width - 6, y + height);
82 context.drawRectangle(x + width - 10, y, x + width - 11, y + height);
83 context.drawRectangle(x + width - 15, y, x + width - 16, y + height);
84 context.setLineStyle(currentStyle);
85
86 IColor storedColor = context.getBackground();
87 context.setBackground(context.getForeground());
88 context.fillRectangle(x + width - 5, y, x + width - 6, y + height);
89 context.fillRectangle(x + width - 10, y, x + width - 11, y + height);
90 context.fillRectangle(x + width - 15, y, x + width - 16, y + height);
91 context.setBackground(storedColor);
92 }
93 // UML2 lost message (always drawn from left to right)
94 else if (fEndLifeline == null && fStartLifeline != null) {
95 // Draw the message label above the message and centered
96 // The label is truncated if it cannot fit between the two message end
97 // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label
98 context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected());
99
100 int currentStyle = context.getLineStyle();
101 context.setLineStyle(context.getLineSolidStyle());
102 // Draw the message main line
103 context.drawRectangle(x + 5, y, 1, 1);
104 context.drawRectangle(x + 10, y, 1, 1);
105 context.drawRectangle(x + 15, y, 1, 1);
106
107 context.setLineStyle(currentStyle);
108
109 IColor storedColor = context.getBackground();
110 context.setBackground(context.getForeground());
111 context.fillRectangle(x + 5, y, 1, 1);
112 context.fillRectangle(x + 10, y, 1, 1);
113 context.fillRectangle(x + 15, y, 1, 1);
114
115 context.setBackground(storedColor);
116
117 } else {
118 super.draw(context);
119 }
120 }
121
122 /*
123 * (non-Javadoc)
124 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
125 */
126 @Override
127 public void draw(IGC context) {
128 if (!isVisible()) {
129 return;
130 }
131
132 ISDPreferences pref = SDViewPref.getInstance();
133
134 // Draw it selected?*/
135 if (isSelected()) {
136
137 /*
138 * Draw it twice First time, bigger inverting selection colors Second time, regular drawing using selection
139 * colors This create the highlight effect
140 */
141 context.setForeground(pref.getBackGroundColorSelection());
142 context.setLineWidth(Metrics.SELECTION_LINE_WIDTH);
143 drawMessage(context);
144 context.setBackground(pref.getBackGroundColorSelection());
145 context.setForeground(pref.getForeGroundColorSelection());
146 // Second drawing is done after the else
147 } else {
148 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_ASYNC_MESS));
149 context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_ASYNC_MESS));
150 }
151 if (hasFocus()) {
152 context.setDrawTextWithFocusStyle(true);
153 }
154 context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
155 drawMessage(context);
156 context.setLineWidth(Metrics.NORMAL_LINE_WIDTH);
157 if (hasFocus()) {
158 context.setDrawTextWithFocusStyle(false);
159 }
160 }
161 }
This page took 0.033716 seconds and 5 git commands to generate.