Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
11252342 | 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 | |
c8422608 AM |
7 | * |
8 | * Contributors: | |
9 | * IBM - Initial API and implementation | |
10 | * Bernd Hufmann - Updated for TMF | |
73005152 | 11 | **********************************************************************/ |
c8422608 | 12 | |
73005152 BH |
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; | |
df0b8ff4 | 17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences; |
3145ec83 | 18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; |
73005152 | 19 | |
df0b8ff4 BH |
20 | /** |
21 | * Class to draw Ellipsis Message. | |
c8422608 | 22 | * |
df0b8ff4 BH |
23 | * @version 1.0 |
24 | * @author sveyrier | |
c8422608 | 25 | * |
df0b8ff4 | 26 | */ |
eb63f5ff | 27 | public class EllipsisMessage extends AsyncMessage { |
73005152 BH |
28 | |
29 | @Override | |
30 | public int getX() { | |
cab6c8ff | 31 | if (getStartLifeline() == null) { |
73005152 | 32 | return super.getX() + super.getWidth() - 16; |
c8422608 | 33 | } |
df0b8ff4 | 34 | return super.getX(); |
73005152 BH |
35 | } |
36 | ||
37 | @Override | |
38 | public int getY() { | |
39 | return super.getY() + 3; | |
40 | } | |
41 | ||
42 | @Override | |
43 | public int getWidth() { | |
44 | return 16; | |
45 | } | |
46 | ||
47 | @Override | |
48 | protected void drawMessage(IGC context) { | |
df0b8ff4 | 49 | // temporary store the coordinates to avoid more methods calls |
73005152 BH |
50 | int x = super.getX(); |
51 | int y = getY(); | |
52 | int width = super.getWidth(); | |
53 | int height = getHeight(); | |
54 | ||
55 | // UML2 found message (always drawn from left to right) | |
cab6c8ff | 56 | if (getStartLifeline() == null && getEndLifeline() != null) { |
73005152 BH |
57 | // Draw the message label above the message and centered |
58 | // The label is truncated if it cannot fit between the two message end | |
59 | // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label | |
60 | context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected()); | |
61 | ||
62 | int currentStyle = context.getLineStyle(); | |
63 | context.setLineStyle(context.getLineSolidStyle()); | |
64 | // Draw the message main line | |
65 | context.drawRectangle(x + width - 5, y, x + width - 6, y + height); | |
66 | context.drawRectangle(x + width - 10, y, x + width - 11, y + height); | |
67 | context.drawRectangle(x + width - 15, y, x + width - 16, y + height); | |
68 | context.setLineStyle(currentStyle); | |
69 | ||
70 | IColor storedColor = context.getBackground(); | |
71 | context.setBackground(context.getForeground()); | |
72 | context.fillRectangle(x + width - 5, y, x + width - 6, y + height); | |
73 | context.fillRectangle(x + width - 10, y, x + width - 11, y + height); | |
74 | context.fillRectangle(x + width - 15, y, x + width - 16, y + height); | |
75 | context.setBackground(storedColor); | |
76 | } | |
77 | // UML2 lost message (always drawn from left to right) | |
cab6c8ff | 78 | else if (getEndLifeline() == null && getStartLifeline() != null) { |
73005152 BH |
79 | // Draw the message label above the message and centered |
80 | // The label is truncated if it cannot fit between the two message end | |
81 | // 2*Metrics.MESSAGES_NAME_SPACING = space above the label + space below the label | |
82 | context.drawTextTruncatedCentred(getName(), x, y - Metrics.getMessageFontHeigth() - 2 * Metrics.MESSAGES_NAME_SPACING, width, 2 * Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth(), !isSelected()); | |
83 | ||
84 | int currentStyle = context.getLineStyle(); | |
85 | context.setLineStyle(context.getLineSolidStyle()); | |
86 | // Draw the message main line | |
87 | context.drawRectangle(x + 5, y, 1, 1); | |
88 | context.drawRectangle(x + 10, y, 1, 1); | |
89 | context.drawRectangle(x + 15, y, 1, 1); | |
90 | ||
91 | context.setLineStyle(currentStyle); | |
92 | ||
93 | IColor storedColor = context.getBackground(); | |
94 | context.setBackground(context.getForeground()); | |
95 | context.fillRectangle(x + 5, y, 1, 1); | |
96 | context.fillRectangle(x + 10, y, 1, 1); | |
97 | context.fillRectangle(x + 15, y, 1, 1); | |
98 | ||
99 | context.setBackground(storedColor); | |
100 | ||
df0b8ff4 | 101 | } else { |
73005152 | 102 | super.draw(context); |
df0b8ff4 | 103 | } |
73005152 BH |
104 | } |
105 | ||
106 | @Override | |
107 | public void draw(IGC context) { | |
df0b8ff4 | 108 | if (!isVisible()) { |
73005152 | 109 | return; |
df0b8ff4 | 110 | } |
3145ec83 BH |
111 | |
112 | ISDPreferences pref = SDViewPref.getInstance(); | |
113 | ||
73005152 BH |
114 | // Draw it selected?*/ |
115 | if (isSelected()) { | |
3145ec83 | 116 | |
73005152 BH |
117 | /* |
118 | * Draw it twice First time, bigger inverting selection colors Second time, regular drawing using selection | |
119 | * colors This create the highlight effect | |
120 | */ | |
3145ec83 | 121 | context.setForeground(pref.getBackGroundColorSelection()); |
73005152 BH |
122 | context.setLineWidth(Metrics.SELECTION_LINE_WIDTH); |
123 | drawMessage(context); | |
3145ec83 BH |
124 | context.setBackground(pref.getBackGroundColorSelection()); |
125 | context.setForeground(pref.getForeGroundColorSelection()); | |
73005152 BH |
126 | // Second drawing is done after the else |
127 | } else { | |
3145ec83 BH |
128 | context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_ASYNC_MESS)); |
129 | context.setForeground(pref.getForeGroundColor(ISDPreferences.PREF_ASYNC_MESS)); | |
73005152 BH |
130 | } |
131 | if (hasFocus()) { | |
132 | context.setDrawTextWithFocusStyle(true); | |
133 | } | |
134 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
135 | drawMessage(context); | |
136 | context.setLineWidth(Metrics.NORMAL_LINE_WIDTH); | |
137 | if (hasFocus()) { | |
138 | context.setDrawTextWithFocusStyle(false); | |
139 | } | |
140 | } | |
141 | } |