Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
abbdd66a | 4 | * |
73005152 BH |
5 | * All rights reserved. This program and the accompanying materials |
6 | * are made available under the terms of the Eclipse Public License v1.0 | |
7 | * which accompanies this distribution, and is available at | |
8 | * http://www.eclipse.org/legal/epl-v10.html | |
abbdd66a AM |
9 | * |
10 | * Contributors: | |
73005152 BH |
11 | * IBM - Initial API and implementation |
12 | * Bernd Hufmann - Updated for TMF | |
13 | **********************************************************************/ | |
14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd; | |
15 | ||
73005152 BH |
16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; |
17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont; | |
18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl.ColorImpl; | |
21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; | |
22 | import org.eclipse.swt.SWT; | |
23 | import org.eclipse.swt.graphics.Color; | |
24 | import org.eclipse.swt.graphics.Font; | |
25 | import org.eclipse.swt.graphics.FontData; | |
26 | import org.eclipse.swt.graphics.GC; | |
27 | import org.eclipse.swt.graphics.Image; | |
28 | import org.eclipse.swt.graphics.Point; | |
29 | import org.eclipse.swt.graphics.Rectangle; | |
30 | import org.eclipse.swt.widgets.Display; | |
31 | ||
32 | /** | |
df0b8ff4 BH |
33 | * <p> |
34 | * This class implements the graphical context for the sequence diagram widgets. | |
35 | * </p> | |
abbdd66a AM |
36 | * |
37 | * @version 1.0 | |
df0b8ff4 | 38 | * @author sveyrier |
73005152 BH |
39 | */ |
40 | public class NGC implements IGC { | |
41 | ||
df0b8ff4 BH |
42 | // ------------------------------------------------------------------------ |
43 | // Attributes | |
44 | // ------------------------------------------------------------------------ | |
abbdd66a | 45 | |
df0b8ff4 BH |
46 | /** |
47 | * The graphical context. | |
48 | */ | |
eb63f5ff | 49 | protected GC fContext; |
df0b8ff4 BH |
50 | /** |
51 | * The reference to the sequence diagram view. | |
52 | */ | |
eb63f5ff | 53 | protected SDWidget fView; |
df0b8ff4 BH |
54 | /** |
55 | * A reference to the last used font. | |
56 | */ | |
eb63f5ff | 57 | protected Font fTempFont = null; |
df0b8ff4 BH |
58 | /** |
59 | * The color of the gradient. | |
60 | */ | |
eb63f5ff | 61 | protected IColor fGradientColor = null; |
df0b8ff4 BH |
62 | /** |
63 | * The color of the background. | |
64 | */ | |
eb63f5ff | 65 | protected IColor fBackground = null; |
df0b8ff4 BH |
66 | /** |
67 | * The color of the foreground. | |
68 | */ | |
eb63f5ff | 69 | protected IColor fForeground = null; |
df0b8ff4 | 70 | /** |
eb63f5ff | 71 | * The current visible y screen bounds |
df0b8ff4 | 72 | */ |
eb63f5ff | 73 | protected int fVisibleY; |
df0b8ff4 | 74 | /** |
eb63f5ff | 75 | * The current visible x screen bound. |
df0b8ff4 | 76 | */ |
eb63f5ff | 77 | protected int fVisibleX; |
df0b8ff4 | 78 | /** |
abbdd66a | 79 | * The current yx value (view visible height - visible screen bounds) |
df0b8ff4 | 80 | */ |
73005152 | 81 | protected int yx; |
df0b8ff4 | 82 | /** |
abbdd66a | 83 | * The current xx value (view visible width - visible screen bounds) |
df0b8ff4 | 84 | */ |
73005152 | 85 | protected int xx; |
df0b8ff4 | 86 | /** |
abbdd66a | 87 | * <code>true</code> to draw with focus else <code>false</code>. |
df0b8ff4 | 88 | */ |
eb63f5ff | 89 | protected boolean fDrawWithFocus = false; |
73005152 | 90 | |
df0b8ff4 BH |
91 | /** |
92 | * The static visible screen bounds. | |
93 | */ | |
eb63f5ff | 94 | private static int fVisibleScreenBounds = 0; |
abbdd66a AM |
95 | |
96 | ||
df0b8ff4 BH |
97 | // ------------------------------------------------------------------------ |
98 | // Constructors | |
99 | // ------------------------------------------------------------------------ | |
100 | ||
101 | /** | |
102 | * Default constructor. | |
abbdd66a | 103 | * |
df0b8ff4 BH |
104 | * @param scrollView A sequence diagram view reference. |
105 | * @param gc A graphical context. | |
106 | */ | |
73005152 | 107 | public NGC(SDWidget scrollView, GC gc) { |
eb63f5ff BH |
108 | fContext = gc; |
109 | fView = scrollView; | |
73005152 BH |
110 | } |
111 | ||
df0b8ff4 BH |
112 | // ------------------------------------------------------------------------ |
113 | // Methods | |
114 | // ------------------------------------------------------------------------ | |
115 | ||
116 | /* | |
117 | * (non-Javadoc) | |
118 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setLineStyle(int) | |
119 | */ | |
73005152 BH |
120 | @Override |
121 | public void setLineStyle(int style) { | |
eb63f5ff | 122 | fContext.setLineStyle(style); |
73005152 BH |
123 | } |
124 | ||
df0b8ff4 BH |
125 | /* |
126 | * (non-Javadoc) | |
127 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineStyle() | |
128 | */ | |
73005152 BH |
129 | @Override |
130 | public int getLineStyle() { | |
eb63f5ff | 131 | return fContext.getLineStyle(); |
73005152 BH |
132 | } |
133 | ||
df0b8ff4 BH |
134 | /* |
135 | * (non-Javadoc) | |
136 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getContentsX() | |
137 | */ | |
73005152 BH |
138 | @Override |
139 | public int getContentsX() { | |
eb63f5ff | 140 | return Math.round(fView.getContentsX() / fView.fZoomValue); |
73005152 BH |
141 | } |
142 | ||
df0b8ff4 BH |
143 | /* |
144 | * (non-Javadoc) | |
145 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getContentsY() | |
146 | */ | |
73005152 BH |
147 | @Override |
148 | public int getContentsY() { | |
eb63f5ff | 149 | return Math.round(fView.getContentsY() / fView.fZoomValue); |
73005152 BH |
150 | } |
151 | ||
df0b8ff4 BH |
152 | /* |
153 | * (non-Javadoc) | |
154 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getVisibleWidth() | |
155 | */ | |
73005152 BH |
156 | @Override |
157 | public int getVisibleWidth() { | |
eb63f5ff | 158 | return Math.round(fView.getVisibleWidth() / fView.fZoomValue); |
73005152 BH |
159 | } |
160 | ||
df0b8ff4 BH |
161 | /* |
162 | * (non-Javadoc) | |
163 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getVisibleHeight() | |
164 | */ | |
73005152 BH |
165 | @Override |
166 | public int getVisibleHeight() { | |
eb63f5ff | 167 | return Math.round(fView.getVisibleHeight() / fView.fZoomValue); |
73005152 BH |
168 | } |
169 | ||
df0b8ff4 BH |
170 | /* |
171 | * (non-Javadoc) | |
172 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#contentsToViewX(int) | |
173 | */ | |
73005152 BH |
174 | @Override |
175 | public int contentsToViewX(int x) { | |
eb63f5ff | 176 | return fView.contentsToViewX(x); |
73005152 BH |
177 | } |
178 | ||
df0b8ff4 BH |
179 | /* |
180 | * (non-Javadoc) | |
181 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#contentsToViewY(int) | |
182 | */ | |
73005152 BH |
183 | @Override |
184 | public int contentsToViewY(int y) { | |
eb63f5ff | 185 | return fView.contentsToViewY(y); |
73005152 BH |
186 | } |
187 | ||
df0b8ff4 BH |
188 | /** |
189 | * Get code for drawings at given x and y position. | |
abbdd66a | 190 | * |
df0b8ff4 BH |
191 | * @param x The x position |
192 | * @param y The y position. | |
193 | * @return A code for top, bottom, right and left | |
194 | */ | |
73005152 BH |
195 | protected byte code(int x, int y) { |
196 | byte c = 0; | |
eb63f5ff BH |
197 | fVisibleY = fVisibleScreenBounds; |
198 | fVisibleX = fVisibleScreenBounds; | |
199 | yx = fView.getVisibleHeight() + fVisibleScreenBounds; | |
200 | xx = fView.getVisibleWidth() + fVisibleScreenBounds; | |
df0b8ff4 | 201 | if (y > yx) { |
73005152 | 202 | c |= 0x01; // top |
eb63f5ff | 203 | } else if (y < fVisibleY) { |
73005152 | 204 | c |= 0x02; // bottom |
df0b8ff4 | 205 | } |
abbdd66a | 206 | |
df0b8ff4 | 207 | if (x > xx) { |
73005152 | 208 | c |= 0x04; // right |
eb63f5ff | 209 | } else if (x < fVisibleX) { |
73005152 | 210 | c |= 0x08; // left |
df0b8ff4 | 211 | } |
73005152 BH |
212 | return c; |
213 | } | |
214 | ||
df0b8ff4 BH |
215 | /* |
216 | * (non-Javadoc) | |
217 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawLine(int, int, int, int) | |
218 | */ | |
73005152 BH |
219 | @Override |
220 | public void drawLine(int x1, int y1, int x2, int y2) { | |
abbdd66a AM |
221 | int localX1 = x1; |
222 | int localY1 = y1; | |
eb63f5ff BH |
223 | int localX2 = x2; |
224 | int localY2 = y2; | |
abbdd66a | 225 | |
eb63f5ff BH |
226 | localX1 = Math.round(localX1 * fView.fZoomValue); |
227 | localY1 = Math.round(localY1 * fView.fZoomValue); | |
228 | localX2 = Math.round(localX2 * fView.fZoomValue); | |
229 | localY2 = Math.round(localY2 * fView.fZoomValue); | |
230 | localX1 = fView.contentsToViewX(localX1); | |
231 | localY1 = fView.contentsToViewY(localY1); | |
232 | localX2 = fView.contentsToViewX(localX2); | |
233 | localY2 = fView.contentsToViewY(localY2); | |
234 | ||
235 | byte code1 = code(localX1, localY1); | |
236 | byte code2 = code(localX2, localY2); | |
73005152 BH |
237 | byte codex; |
238 | boolean draw = false; | |
239 | boolean end = false; | |
240 | int x = 0, y = 0; | |
241 | ||
242 | do { | |
243 | if (code1 == 0 && code2 == 0) { | |
244 | draw = true; | |
245 | end = true; | |
246 | } else if ((code1 & code2) != 0) { | |
247 | end = true; | |
248 | } else { | |
249 | codex = (code1 != 0) ? code1 : code2; | |
df0b8ff4 | 250 | if ((codex & 0x01) != 0) { // top |
eb63f5ff | 251 | x = localX1 + ((localX2 - localX1) * (yx - localY1)) / (localY2 - localY1); |
73005152 | 252 | y = yx; |
df0b8ff4 | 253 | } else if ((codex & 0x02) != 0) { // bottom |
eb63f5ff BH |
254 | x = localX1 + ((localX2 - localX1) * (fVisibleY - localY1)) / (localY2 - localY1); |
255 | y = fVisibleY; | |
df0b8ff4 | 256 | } else if ((codex & 0x04) != 0) { // right |
eb63f5ff | 257 | y = localY1 + ((localY2 - localY1) * (xx - localX1)) / (localX2 - localX1); |
73005152 | 258 | x = xx; |
df0b8ff4 | 259 | } else if ((codex & 0x08) != 0) { // left |
eb63f5ff BH |
260 | y = localY1 + ((localY2 - localY1) * (fVisibleX - localX1)) / (localX2 - localX1); |
261 | x = fVisibleX; | |
73005152 BH |
262 | } |
263 | ||
264 | if (codex == code1) { | |
eb63f5ff BH |
265 | localX1 = x; |
266 | localY1 = y; | |
267 | code1 = code(localX1, localY1); | |
73005152 | 268 | } else { |
eb63f5ff BH |
269 | localX2 = x; |
270 | localY2 = y; | |
271 | code2 = code(localX2, localY2); | |
73005152 BH |
272 | } |
273 | } | |
274 | } while (!end); | |
df0b8ff4 | 275 | |
73005152 | 276 | if (draw) { |
eb63f5ff | 277 | fContext.drawLine(localX1, localY1, localX2, localY2); |
73005152 BH |
278 | } |
279 | } | |
280 | ||
df0b8ff4 BH |
281 | /* |
282 | * (non-Javadoc) | |
283 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawRectangle(int, int, int, int) | |
284 | */ | |
73005152 BH |
285 | @Override |
286 | public void drawRectangle(int x, int y, int width, int height) { | |
eb63f5ff BH |
287 | int localX = x; |
288 | int localY = y; | |
289 | int localWidth = width; | |
290 | int localHeight = height; | |
abbdd66a | 291 | |
eb63f5ff | 292 | localX = Math.round(localX * fView.fZoomValue); |
73005152 | 293 | // Workaround to avoid problems for some special cases (not very nice) |
eb63f5ff BH |
294 | if (localY != getContentsY()) { |
295 | localY = Math.round(localY * fView.fZoomValue); | |
296 | localY = fView.contentsToViewY(localY); | |
297 | } else { | |
298 | localY = 0; | |
299 | } | |
300 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
301 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
302 | localX = fView.contentsToViewX(localX); | |
303 | ||
304 | if (localX < -fVisibleScreenBounds) { | |
305 | localWidth = localWidth + localX + fVisibleScreenBounds; | |
306 | localX = -fVisibleScreenBounds; | |
307 | } | |
308 | if (localY < -fVisibleScreenBounds) { | |
309 | localHeight = localHeight + localY + fVisibleScreenBounds; | |
310 | localY = -fVisibleScreenBounds; | |
311 | } | |
312 | if ((localWidth < -fVisibleScreenBounds) && (localX + localWidth < -fVisibleScreenBounds)) { | |
313 | localWidth = -fVisibleScreenBounds; | |
314 | } else if (localWidth + localX > fView.getVisibleWidth() + fVisibleScreenBounds) { | |
315 | localWidth = fView.getVisibleWidth() + fVisibleScreenBounds - localX; | |
316 | } | |
317 | if ((localHeight < -fVisibleScreenBounds) && (localY + localHeight < -fVisibleScreenBounds)) { | |
318 | localHeight = -fVisibleScreenBounds; | |
319 | } else if (localHeight + localY > fView.getVisibleHeight() + fVisibleScreenBounds) { | |
320 | localHeight = fView.getVisibleHeight() + fVisibleScreenBounds - localY; | |
321 | } | |
322 | fContext.drawRectangle(localX, localY, localWidth, localHeight); | |
73005152 | 323 | } |
abbdd66a | 324 | |
df0b8ff4 BH |
325 | /* |
326 | * (non-Javadoc) | |
327 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawFocus(int, int, int, int) | |
328 | */ | |
73005152 BH |
329 | @Override |
330 | public void drawFocus(int x, int y, int width, int height) { | |
eb63f5ff BH |
331 | int localX = x; |
332 | int localY = y; | |
333 | int localWidth = width; | |
334 | int localHeight = height; | |
335 | ||
73005152 BH |
336 | IColor bC = getBackground(); |
337 | IColor fC = getForeground(); | |
338 | ||
eb63f5ff BH |
339 | if (localWidth < 0) { |
340 | localX = localX + localWidth; | |
341 | localWidth = -localWidth; | |
73005152 BH |
342 | } |
343 | ||
eb63f5ff BH |
344 | if (localHeight < 0) { |
345 | localY = localY + localHeight; | |
346 | localHeight = -localHeight; | |
73005152 BH |
347 | } |
348 | ||
eb63f5ff BH |
349 | localX = Math.round(localX * fView.fZoomValue); |
350 | localY = Math.round(localY * fView.fZoomValue); | |
351 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
352 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
73005152 | 353 | |
3145ec83 BH |
354 | setForeground(SDViewPref.getInstance().getForeGroundColorSelection()); |
355 | setBackground(SDViewPref.getInstance().getBackGroundColorSelection()); | |
73005152 | 356 | |
eb63f5ff | 357 | fContext.drawFocus(fView.contentsToViewX(localX - 1), fView.contentsToViewY(localY - 1), localWidth + 3, localHeight + 3); |
73005152 BH |
358 | |
359 | setBackground(bC); | |
360 | setForeground(fC); | |
361 | } | |
362 | ||
df0b8ff4 BH |
363 | /* |
364 | * (non-Javadoc) | |
365 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillPolygon(int[]) | |
366 | */ | |
73005152 BH |
367 | @Override |
368 | public void fillPolygon(int[] points) { | |
369 | int len = (points.length / 2) * 2; | |
370 | int[] localPoint = new int[len]; | |
371 | for (int i = 0; i < len; i++) { | |
eb63f5ff | 372 | localPoint[i] = fView.contentsToViewX(Math.round(points[i] * fView.fZoomValue)); |
73005152 | 373 | i++; |
eb63f5ff | 374 | localPoint[i] = fView.contentsToViewY(Math.round(points[i] * fView.fZoomValue)); |
73005152 | 375 | } |
abbdd66a AM |
376 | |
377 | if (validatePolygonHeight(localPoint) <= 0) { | |
73005152 | 378 | return; |
abbdd66a AM |
379 | } |
380 | ||
eb63f5ff | 381 | fContext.fillPolygon(localPoint); |
73005152 BH |
382 | } |
383 | ||
df0b8ff4 BH |
384 | /* |
385 | * (non-Javadoc) | |
386 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawPolygon(int[]) | |
387 | */ | |
73005152 BH |
388 | @Override |
389 | public void drawPolygon(int[] points) { | |
390 | int len = (points.length / 2) * 2; | |
391 | int[] localPoint = new int[len]; | |
392 | for (int i = 0; i < len; i++) { | |
eb63f5ff | 393 | localPoint[i] = fView.contentsToViewX(Math.round(points[i] * fView.fZoomValue)); |
73005152 | 394 | i++; |
eb63f5ff | 395 | localPoint[i] = fView.contentsToViewY(Math.round(points[i] * fView.fZoomValue)); |
73005152 | 396 | } |
abbdd66a | 397 | |
df0b8ff4 | 398 | if (validatePolygonHeight(localPoint) <= 0) { |
73005152 | 399 | return; |
df0b8ff4 | 400 | } |
73005152 | 401 | |
eb63f5ff | 402 | fContext.drawPolygon(localPoint); |
73005152 BH |
403 | } |
404 | ||
df0b8ff4 BH |
405 | /* |
406 | * (non-Javadoc) | |
407 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillRectangle(int, int, int, int) | |
408 | */ | |
73005152 BH |
409 | @Override |
410 | public void fillRectangle(int x, int y, int width, int height) { | |
eb63f5ff BH |
411 | int localX = x; |
412 | int localY = y; | |
413 | int localWidth = width; | |
414 | int localHeight = height; | |
415 | ||
416 | localX = Math.round(localX * fView.fZoomValue); | |
73005152 | 417 | // Workaround to avoid problems for some special cases (not very nice) |
eb63f5ff BH |
418 | if (localY != getContentsY()) { |
419 | localY = Math.round(localY * fView.fZoomValue); | |
420 | localY = fView.contentsToViewY(localY) + 1; | |
df0b8ff4 | 421 | } else { |
eb63f5ff | 422 | localY = 1; |
df0b8ff4 | 423 | } |
eb63f5ff BH |
424 | localWidth = Math.round(localWidth * fView.fZoomValue) - 1; |
425 | localHeight = Math.round(localHeight * fView.fZoomValue) - 1; | |
426 | localX = fView.contentsToViewX(localX) + 1; | |
427 | if (localX < -fVisibleScreenBounds) { | |
428 | localWidth = localWidth + localX + fVisibleScreenBounds; | |
429 | localX = -fVisibleScreenBounds; | |
73005152 | 430 | } |
eb63f5ff BH |
431 | if (localY < -fVisibleScreenBounds) { |
432 | localHeight = localHeight + localY + fVisibleScreenBounds; | |
433 | localY = -fVisibleScreenBounds; | |
73005152 | 434 | } |
eb63f5ff BH |
435 | if ((localWidth < -fVisibleScreenBounds) && (localX + localWidth < -fVisibleScreenBounds)) { |
436 | localWidth = -fVisibleScreenBounds; | |
437 | } else if (localWidth + localX > fView.getVisibleWidth() + fVisibleScreenBounds) { | |
438 | localWidth = fView.getVisibleWidth() + fVisibleScreenBounds - localX; | |
df0b8ff4 | 439 | } |
eb63f5ff BH |
440 | if ((localHeight < -fVisibleScreenBounds) && (localY + localHeight < -fVisibleScreenBounds)) { |
441 | localHeight = -fVisibleScreenBounds; | |
442 | } else if (localHeight + localY > fView.getVisibleHeight() + fVisibleScreenBounds) { | |
443 | localHeight = fView.getVisibleHeight() + fVisibleScreenBounds - localY; | |
df0b8ff4 | 444 | } |
eb63f5ff | 445 | fContext.fillRectangle(localX, localY, localWidth, localHeight); |
73005152 BH |
446 | |
447 | } | |
448 | ||
df0b8ff4 BH |
449 | /* |
450 | * (non-Javadoc) | |
451 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillGradientRectangle(int, int, int, int, boolean) | |
452 | */ | |
73005152 | 453 | @Override |
eb63f5ff BH |
454 | public void fillGradientRectangle(int x, int y, int width, int height, boolean isVertical) { |
455 | int localX = x; | |
456 | int localY = y; | |
457 | int localWidth = width; | |
458 | int localHeight = height; | |
abbdd66a | 459 | |
eb63f5ff BH |
460 | localX = Math.round(localX * fView.fZoomValue); |
461 | localY = Math.round(localY * fView.fZoomValue); | |
462 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
463 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
464 | IColor tempColor = fForeground; | |
465 | setForeground(fGradientColor); | |
466 | localX = fView.contentsToViewX(localX); | |
467 | localY = fView.contentsToViewY(localY); | |
73005152 | 468 | |
eb63f5ff BH |
469 | if (localX < -fVisibleScreenBounds) { |
470 | localWidth = localWidth + localX + fVisibleScreenBounds; | |
471 | localX = -fVisibleScreenBounds; | |
73005152 | 472 | } |
eb63f5ff BH |
473 | if (localY < -fVisibleScreenBounds) { |
474 | localHeight = localHeight + localY + fVisibleScreenBounds; | |
475 | localY = -fVisibleScreenBounds; | |
73005152 | 476 | } |
df0b8ff4 | 477 | |
eb63f5ff BH |
478 | if ((localWidth < -fVisibleScreenBounds) && (localX + localWidth < -fVisibleScreenBounds)) { |
479 | localWidth = -fVisibleScreenBounds; | |
480 | } else if (localWidth + localX > fView.getVisibleWidth() + fVisibleScreenBounds) { | |
481 | localWidth = fView.getVisibleWidth() + fVisibleScreenBounds - localX; | |
df0b8ff4 | 482 | } |
eb63f5ff BH |
483 | if ((localHeight < -fVisibleScreenBounds) && (localY + localHeight < -fVisibleScreenBounds)) { |
484 | localHeight = -fVisibleScreenBounds; | |
485 | } else if (localHeight + localY > fView.getVisibleHeight() + fVisibleScreenBounds) { | |
486 | localHeight = fView.getVisibleHeight() + fVisibleScreenBounds - localY; | |
df0b8ff4 | 487 | } |
eb63f5ff BH |
488 | if (isVertical) { |
489 | fContext.fillGradientRectangle(localX, localY, localWidth, localHeight, isVertical); | |
73005152 BH |
490 | } |
491 | else { | |
eb63f5ff | 492 | fContext.fillGradientRectangle(localX + localWidth, localY, -localWidth, localHeight + 1, isVertical); |
73005152 BH |
493 | } |
494 | setForeground(tempColor); | |
495 | } | |
496 | ||
abbdd66a | 497 | |
df0b8ff4 BH |
498 | /* |
499 | * (non-Javadoc) | |
500 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#textExtent(java.lang.String) | |
501 | */ | |
73005152 BH |
502 | @Override |
503 | public int textExtent(String name) { | |
abbdd66a | 504 | return fContext.textExtent(name).x; |
73005152 BH |
505 | } |
506 | ||
df0b8ff4 BH |
507 | /* |
508 | * (non-Javadoc) | |
509 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawText(java.lang.String, int, int, boolean) | |
510 | */ | |
73005152 | 511 | @Override |
eb63f5ff BH |
512 | public void drawText(String string, int x, int y, boolean isTrans) { |
513 | int localX = x; | |
514 | int localY = y; | |
abbdd66a | 515 | |
eb63f5ff BH |
516 | localX = Math.round(localX * fView.fZoomValue); |
517 | localY = Math.round(localY * fView.fZoomValue); | |
518 | fContext.drawText(string, fView.contentsToViewX(localX), fView.contentsToViewY(localY), isTrans); | |
519 | if (fDrawWithFocus) { | |
520 | Point r = fContext.textExtent(string); | |
521 | fContext.drawFocus(localX - 1, localY - 1, r.x + 2, r.y + 2); | |
73005152 BH |
522 | } |
523 | } | |
524 | ||
df0b8ff4 BH |
525 | /* |
526 | * (non-Javadoc) | |
527 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawText(java.lang.String, int, int) | |
528 | */ | |
73005152 BH |
529 | @Override |
530 | public void drawText(String string, int x, int y) { | |
eb63f5ff BH |
531 | int localX = x; |
532 | int localY = y; | |
533 | ||
534 | localX = Math.round(localX * fView.fZoomValue); | |
535 | localY = Math.round(localY * fView.fZoomValue); | |
536 | fContext.drawText(string, fView.contentsToViewX(localX), fView.contentsToViewY(localY), true); | |
537 | if (fDrawWithFocus) { | |
538 | Point r = fContext.textExtent(string); | |
539 | fContext.drawFocus(localX - 1, localY - 1, r.x + 2, r.y + 2); | |
73005152 BH |
540 | } |
541 | } | |
542 | ||
df0b8ff4 BH |
543 | /* |
544 | * (non-Javadoc) | |
545 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillOval(int, int, int, int) | |
546 | */ | |
73005152 BH |
547 | @Override |
548 | public void fillOval(int x, int y, int width, int height) { | |
eb63f5ff BH |
549 | int localX = x; |
550 | int localY = y; | |
551 | int localWidth = width; | |
552 | int localHeight = height; | |
abbdd66a | 553 | |
eb63f5ff BH |
554 | localX = Math.round(localX * fView.fZoomValue); |
555 | localY = Math.round(localY * fView.fZoomValue); | |
556 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
557 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
558 | fContext.fillOval(fView.contentsToViewX(localX), fView.contentsToViewY(localY), localWidth, localHeight); | |
73005152 BH |
559 | } |
560 | ||
df0b8ff4 BH |
561 | /* |
562 | * (non-Javadoc) | |
563 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getBackground() | |
564 | */ | |
73005152 BH |
565 | @Override |
566 | public IColor getBackground() { | |
eb63f5ff BH |
567 | if ((fBackground != null) && (fBackground.getColor() instanceof Color) && (!((Color) (fBackground.getColor())).isDisposed())) { |
568 | return fBackground; | |
df0b8ff4 | 569 | } |
73005152 BH |
570 | return ColorImpl.getSystemColor(SWT.COLOR_WHITE); |
571 | } | |
572 | ||
df0b8ff4 BH |
573 | /* |
574 | * (non-Javadoc) | |
575 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getForeground() | |
576 | */ | |
73005152 BH |
577 | @Override |
578 | public IColor getForeground() { | |
eb63f5ff BH |
579 | if ((fForeground != null) && (fForeground.getColor() instanceof Color) && (!((Color) (fForeground.getColor())).isDisposed())) { |
580 | return fForeground; | |
df0b8ff4 | 581 | } |
73005152 BH |
582 | return ColorImpl.getSystemColor(SWT.COLOR_WHITE); |
583 | } | |
584 | ||
df0b8ff4 BH |
585 | /* |
586 | * (non-Javadoc) | |
587 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setBackground(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor) | |
588 | */ | |
73005152 BH |
589 | @Override |
590 | public void setBackground(IColor color) { | |
df0b8ff4 | 591 | if (color == null) { |
73005152 | 592 | return; |
df0b8ff4 | 593 | } |
73005152 | 594 | if (color.getColor() instanceof Color) { |
eb63f5ff BH |
595 | fContext.setBackground((Color) color.getColor()); |
596 | fBackground = color; | |
73005152 BH |
597 | } |
598 | } | |
599 | ||
df0b8ff4 BH |
600 | /* |
601 | * (non-Javadoc) | |
602 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setForeground(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor) | |
603 | */ | |
73005152 BH |
604 | @Override |
605 | public void setForeground(IColor color) { | |
df0b8ff4 | 606 | if (color == null) { |
73005152 | 607 | return; |
df0b8ff4 | 608 | } |
73005152 BH |
609 | if (color.getColor() instanceof Color) { |
610 | Color c = (Color) color.getColor(); | |
611 | if (!c.isDisposed()) { | |
eb63f5ff BH |
612 | fContext.setForeground(c); |
613 | fForeground = color; | |
73005152 BH |
614 | } |
615 | } | |
616 | } | |
617 | ||
df0b8ff4 BH |
618 | /* |
619 | * (non-Javadoc) | |
620 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setGradientColor(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor) | |
621 | */ | |
73005152 BH |
622 | @Override |
623 | public void setGradientColor(IColor color) { | |
df0b8ff4 | 624 | if (color == null) { |
73005152 | 625 | return; |
df0b8ff4 BH |
626 | } |
627 | if (color.getColor() instanceof Color) { | |
eb63f5ff | 628 | fGradientColor = color; |
df0b8ff4 | 629 | } |
73005152 BH |
630 | } |
631 | ||
df0b8ff4 BH |
632 | /* |
633 | * (non-Javadoc) | |
634 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setLineWidth(int) | |
635 | */ | |
73005152 BH |
636 | @Override |
637 | public void setLineWidth(int width) { | |
eb63f5ff BH |
638 | if (fView.isPrinting()) { |
639 | fContext.setLineWidth(width * 2); | |
df0b8ff4 BH |
640 | } |
641 | else { | |
eb63f5ff | 642 | fContext.setLineWidth(width); |
df0b8ff4 | 643 | } |
73005152 BH |
644 | } |
645 | ||
df0b8ff4 BH |
646 | /* |
647 | * (non-Javadoc) | |
648 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineWidth() | |
649 | */ | |
73005152 BH |
650 | @Override |
651 | public int getLineWidth() { | |
eb63f5ff | 652 | return fContext.getLineWidth(); |
73005152 BH |
653 | } |
654 | ||
df0b8ff4 BH |
655 | /** |
656 | * Method to draw a text in rectangle. (Linux GTK Workaround) | |
abbdd66a | 657 | * |
df0b8ff4 BH |
658 | * @param string The text to draw. |
659 | * @param x The x position. | |
660 | * @param y The y position. | |
661 | * @param isTransparent true for transparent else false | |
662 | */ | |
663 | protected void localDrawText(String string, int x, int y, boolean isTransparent) { | |
eb63f5ff | 664 | Point r = fContext.textExtent(string); |
df0b8ff4 | 665 | if (!isTransparent) { |
eb63f5ff | 666 | fContext.fillRectangle(x, y, r.x, r.y); |
df0b8ff4 | 667 | } |
eb63f5ff BH |
668 | fContext.drawText(string, x, y, isTransparent); |
669 | if ((fDrawWithFocus) && (string.length() > 1)) { | |
670 | fContext.drawFocus(x - 1, y - 1, r.x + 2, r.y + 2); | |
df0b8ff4 | 671 | } |
73005152 BH |
672 | } |
673 | ||
df0b8ff4 BH |
674 | /* |
675 | * (non-Javadoc) | |
676 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawTextTruncatedCentred(java.lang.String, int, int, int, int, boolean) | |
677 | */ | |
73005152 | 678 | @Override |
eb63f5ff | 679 | public void drawTextTruncatedCentred(String name, int xValue, int yValue, int width, int height, boolean trans) { |
3145ec83 BH |
680 | int localX = xValue; |
681 | int localY = yValue; | |
682 | int localWidth = width; | |
683 | int localHeight = height; | |
684 | ||
eb63f5ff | 685 | Point tx = fContext.textExtent(name); |
3145ec83 | 686 | localX = Math.round(localX * fView.fZoomValue); |
73005152 BH |
687 | int y = 0; |
688 | // Workaround to avoid round problems for some special cases (not very nice) | |
3145ec83 BH |
689 | if (localY != getContentsY()) { |
690 | localY = Math.round(localY * fView.fZoomValue); | |
691 | y = fView.contentsToViewY(localY); | |
692 | } | |
693 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
694 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
695 | int x = fView.contentsToViewX(localX); | |
696 | if (tx.y > localHeight) { | |
73005152 | 697 | return; |
df0b8ff4 | 698 | } |
abbdd66a | 699 | |
73005152 | 700 | // Adjust height and y |
eb63f5ff | 701 | if (y < -fVisibleScreenBounds) { |
3145ec83 | 702 | localHeight = localHeight + y + fVisibleScreenBounds; |
eb63f5ff | 703 | y = -fVisibleScreenBounds; |
73005152 | 704 | } |
3145ec83 BH |
705 | if ((localHeight < -fVisibleScreenBounds) && (y + localHeight < -fVisibleScreenBounds)) { |
706 | localHeight = -fVisibleScreenBounds; | |
707 | } else if (localHeight + y > fView.getVisibleHeight() + fVisibleScreenBounds) { | |
708 | localHeight = fView.getVisibleHeight() + fVisibleScreenBounds - y; | |
df0b8ff4 | 709 | } |
abbdd66a | 710 | |
3145ec83 BH |
711 | if (tx.x <= localWidth) { |
712 | localDrawText(name, x + 1 + (localWidth - tx.x) / 2, y + 1 + (localHeight - tx.y) / 2, trans); | |
73005152 BH |
713 | } else { |
714 | String nameToDisplay = name; | |
3145ec83 | 715 | for (int i = name.length() - 1; i >= 0 && fContext.textExtent(nameToDisplay).x >= localWidth; i--) { |
73005152 | 716 | nameToDisplay = name.substring(0, i); |
df0b8ff4 | 717 | } |
73005152 | 718 | int dotCount = 0; |
df0b8ff4 | 719 | for (int i = 1; i <= 3 && nameToDisplay.length() - i > 0; i++) { |
73005152 | 720 | dotCount++; |
df0b8ff4 | 721 | } |
73005152 BH |
722 | nameToDisplay = nameToDisplay.substring(0, nameToDisplay.length() - dotCount); |
723 | StringBuffer buf = new StringBuffer(nameToDisplay); | |
724 | for (int i = 0; i < dotCount; i++) { | |
725 | buf.append("."); //$NON-NLS-1$ | |
73005152 BH |
726 | } |
727 | nameToDisplay = buf.toString(); | |
3145ec83 | 728 | localDrawText(nameToDisplay, x + 1 + (localWidth - fContext.textExtent(nameToDisplay).x) / 2, y + 1 + (localHeight - fContext.textExtent(nameToDisplay).y) / 2, trans); |
73005152 BH |
729 | } |
730 | } | |
731 | ||
df0b8ff4 BH |
732 | /* |
733 | * (non-Javadoc) | |
734 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawTextTruncated(java.lang.String, int, int, int, int, boolean) | |
735 | */ | |
73005152 | 736 | @Override |
eb63f5ff BH |
737 | public void drawTextTruncated(String name, int xValue, int yValue, int width, int height, boolean trans) { |
738 | int localX = xValue; | |
739 | int localY = yValue; | |
740 | int localWidth = width; | |
741 | int localHeight = height; | |
abbdd66a | 742 | |
eb63f5ff BH |
743 | localX = Math.round(localX * fView.fZoomValue); |
744 | localY = Math.round(localY * fView.fZoomValue); | |
745 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
746 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
747 | int x = fView.contentsToViewX(localX); | |
748 | int y = fView.contentsToViewY(localY); | |
749 | if (fContext.textExtent(name).x <= localWidth) { | |
750 | localDrawText(name, x + 1, y + 1 + localHeight, trans); | |
73005152 BH |
751 | } else { |
752 | String nameToDisplay = name; | |
eb63f5ff | 753 | for (int i = name.length() - 1; i >= 0 && fContext.textExtent(nameToDisplay).x >= localWidth; i--) { |
73005152 | 754 | nameToDisplay = name.substring(0, i); |
df0b8ff4 | 755 | } |
73005152 | 756 | int dotCount = 0; |
eb63f5ff | 757 | for (int i = 1; i <= 3 && nameToDisplay.length() - i > 0; i++) { |
73005152 | 758 | dotCount++; |
eb63f5ff | 759 | } |
73005152 BH |
760 | nameToDisplay = nameToDisplay.substring(0, nameToDisplay.length() - dotCount); |
761 | ||
762 | StringBuffer buf = new StringBuffer(nameToDisplay); | |
763 | ||
764 | for (int i = 0; i < dotCount; i++) { | |
765 | buf.append("."); //$NON-NLS-1$ | |
73005152 BH |
766 | } |
767 | nameToDisplay = buf.toString(); | |
eb63f5ff | 768 | localDrawText(nameToDisplay, x + 1, y + 1 + localHeight, trans); |
73005152 BH |
769 | } |
770 | } | |
771 | ||
df0b8ff4 BH |
772 | /* |
773 | * (non-Javadoc) | |
774 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawImage(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage, int, int, int, int) | |
775 | */ | |
73005152 | 776 | @Override |
eb63f5ff BH |
777 | public void drawImage(IImage image, int xValue, int yValue, int maxWith, int maxHeight) { |
778 | int localX = xValue; | |
779 | int localY = yValue; | |
abbdd66a | 780 | |
73005152 | 781 | Image img = null; |
eb63f5ff | 782 | if (image != null && image.getImage() instanceof Image) { |
73005152 | 783 | img = (Image) image.getImage(); |
eb63f5ff BH |
784 | } else { |
785 | localX = Math.round(localX * fView.fZoomValue); | |
786 | localY = Math.round(localY * fView.fZoomValue); | |
787 | int x = fView.contentsToViewX(localX); | |
788 | int y = fView.contentsToViewY(localY); | |
789 | float tempZoom = fView.fZoomValue; | |
73005152 BH |
790 | int width = Math.round(maxWith * tempZoom); |
791 | int height = Math.round(maxHeight * tempZoom); | |
eb63f5ff BH |
792 | fContext.setBackground(fView.getDisplay().getSystemColor(SWT.COLOR_RED)); |
793 | fContext.fillRectangle(x, y, width, height); | |
73005152 BH |
794 | return; |
795 | } | |
eb63f5ff BH |
796 | localX = Math.round(localX * fView.fZoomValue); |
797 | localY = Math.round(localY * fView.fZoomValue); | |
798 | int x = fView.contentsToViewX(localX); | |
799 | int y = fView.contentsToViewY(localY); | |
73005152 BH |
800 | Rectangle b = ((Image) image.getImage()).getBounds(); |
801 | int width = b.width; | |
802 | int height = b.height; | |
df0b8ff4 | 803 | if (width > maxWith) { |
73005152 | 804 | width = maxWith; |
df0b8ff4 BH |
805 | } |
806 | if (height > maxHeight) { | |
73005152 | 807 | height = maxHeight; |
df0b8ff4 | 808 | } |
eb63f5ff | 809 | float tempZoom = fView.fZoomValue; |
73005152 BH |
810 | width = Math.round(width * tempZoom); |
811 | height = Math.round(height * tempZoom); | |
812 | ||
eb63f5ff BH |
813 | if (fView.fIsPrinting && width > 0 && height > 0) { |
814 | Image dbuffer = new Image(fView.getDisplay(), width, height); | |
73005152 BH |
815 | GC tempgc = new GC(dbuffer); |
816 | tempgc.drawImage(img, 0, 0, b.width, b.height, 0, 0, width, height); | |
eb63f5ff BH |
817 | Image dbuffer2 = new Image(fView.getDisplay(), dbuffer.getImageData()); |
818 | fContext.drawImage(dbuffer2, x, y); | |
73005152 BH |
819 | tempgc.dispose(); |
820 | dbuffer.dispose(); | |
821 | dbuffer2.dispose(); | |
822 | } else { | |
eb63f5ff | 823 | fContext.drawImage(img, 0, 0, b.width, b.height, x, y, width, height); |
73005152 BH |
824 | } |
825 | } | |
826 | ||
df0b8ff4 BH |
827 | /* |
828 | * (non-Javadoc) | |
829 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawArc(int, int, int, int, int, int) | |
830 | */ | |
73005152 BH |
831 | @Override |
832 | public void drawArc(int x, int y, int width, int height, int startAngle, int endAngle) { | |
3145ec83 BH |
833 | int localX = x; |
834 | int localY = y; | |
835 | int localWidth = width; | |
836 | int localHeight = height; | |
837 | ||
838 | localX = Math.round(localX * fView.fZoomValue); | |
839 | localY = Math.round(localY * fView.fZoomValue); | |
840 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
841 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
842 | if (localWidth == 0 || localHeight == 0 || endAngle == 0) { | |
73005152 | 843 | return; |
df0b8ff4 | 844 | } |
3145ec83 | 845 | fContext.drawArc(fView.contentsToViewX(localX), fView.contentsToViewY(localY), localWidth, localHeight, startAngle, endAngle); |
73005152 BH |
846 | } |
847 | ||
df0b8ff4 BH |
848 | /* |
849 | * (non-Javadoc) | |
850 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setFont(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont) | |
851 | */ | |
73005152 BH |
852 | @Override |
853 | public void setFont(IFont font) { | |
854 | if (font.getFont() != null && ((Font) font.getFont()).getFontData().length > 0) { | |
855 | FontData fontData = ((Font) font.getFont()).getFontData()[0]; | |
eb63f5ff BH |
856 | if (SDViewPref.getInstance().fontLinked() || fView.fIsPrinting) { |
857 | int h = Math.round(fontData.getHeight() * fView.fZoomValue); | |
df0b8ff4 | 858 | if (h > 0) { |
73005152 | 859 | fontData.setHeight(h); |
df0b8ff4 | 860 | } |
73005152 | 861 | } |
eb63f5ff BH |
862 | if (fTempFont != null) { |
863 | fTempFont.dispose(); | |
df0b8ff4 | 864 | } |
eb63f5ff BH |
865 | fTempFont = new Font(Display.getCurrent(), fontData); |
866 | fContext.setFont(fTempFont); | |
73005152 BH |
867 | } |
868 | } | |
869 | ||
df0b8ff4 BH |
870 | /* |
871 | * (non-Javadoc) | |
872 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getFontHeight(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont) | |
873 | */ | |
73005152 BH |
874 | @Override |
875 | public int getFontHeight(IFont font) { | |
876 | if (font.getFont() != null && (font.getFont() instanceof Font) && ((Font) font.getFont()).getFontData().length > 0) { | |
eb63f5ff BH |
877 | Font toRestore = fContext.getFont(); |
878 | fContext.setFont((Font) font.getFont()); | |
879 | int height = fContext.textExtent("lp").y;//$NON-NLS-1$ | |
880 | fContext.setFont(toRestore); | |
73005152 BH |
881 | return height; |
882 | } | |
883 | return 0; | |
884 | } | |
885 | ||
df0b8ff4 BH |
886 | /** |
887 | * Returns the current font height. | |
abbdd66a | 888 | * |
df0b8ff4 BH |
889 | * @return the current font height. |
890 | */ | |
73005152 | 891 | protected int getCurrentFontHeight() { |
eb63f5ff | 892 | return fContext.textExtent("lp").y; //$NON-NLS-1$ |
73005152 BH |
893 | } |
894 | ||
df0b8ff4 BH |
895 | /* |
896 | * (non-Javadoc) | |
897 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getFontWidth(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont) | |
898 | */ | |
73005152 BH |
899 | @Override |
900 | public int getFontWidth(IFont font) { | |
901 | if ((font.getFont() != null) && (font.getFont() instanceof Font)) { | |
eb63f5ff BH |
902 | Font toRestore = fContext.getFont(); |
903 | fContext.setFont((Font) font.getFont()); | |
904 | int width = fContext.getFontMetrics().getAverageCharWidth(); | |
905 | fContext.setFont(toRestore); | |
73005152 BH |
906 | return width; |
907 | } | |
908 | return 0; | |
909 | } | |
910 | ||
df0b8ff4 BH |
911 | /** |
912 | * Disposes all created resources. | |
913 | */ | |
73005152 | 914 | public void dispose() { |
eb63f5ff BH |
915 | if (fTempFont != null) { |
916 | fTempFont.dispose(); | |
df0b8ff4 | 917 | } |
eb63f5ff BH |
918 | fTempFont = null; |
919 | if (fContext != null) { | |
920 | fContext.dispose(); | |
df0b8ff4 | 921 | } |
eb63f5ff | 922 | fContext = null; |
73005152 BH |
923 | } |
924 | ||
df0b8ff4 BH |
925 | /* |
926 | * (non-Javadoc) | |
927 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getZoom() | |
928 | */ | |
73005152 BH |
929 | @Override |
930 | public float getZoom() { | |
eb63f5ff BH |
931 | if (fView != null) { |
932 | return fView.fZoomValue; | |
abbdd66a | 933 | } |
eb63f5ff | 934 | return 1; |
73005152 BH |
935 | } |
936 | ||
df0b8ff4 BH |
937 | /* |
938 | * (non-Javadoc) | |
939 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineDotStyle() | |
940 | */ | |
73005152 BH |
941 | @Override |
942 | public int getLineDotStyle() { | |
943 | return SWT.LINE_DOT; | |
944 | } | |
945 | ||
df0b8ff4 BH |
946 | /* |
947 | * (non-Javadoc) | |
948 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineDashStyle() | |
949 | */ | |
73005152 BH |
950 | @Override |
951 | public int getLineDashStyle() { | |
952 | return SWT.LINE_DASH; | |
953 | } | |
954 | ||
df0b8ff4 BH |
955 | /* |
956 | * (non-Javadoc) | |
957 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineSolidStyle() | |
958 | */ | |
73005152 BH |
959 | @Override |
960 | public int getLineSolidStyle() { | |
961 | return SWT.LINE_SOLID; | |
962 | } | |
963 | ||
df0b8ff4 BH |
964 | /* |
965 | * (non-Javadoc) | |
966 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#createColor(int, int, int) | |
967 | */ | |
73005152 BH |
968 | @Override |
969 | public IColor createColor(int r, int g, int b) { | |
970 | return new ColorImpl(Display.getDefault(), r, g, b); | |
971 | } | |
972 | ||
973 | /* | |
974 | * (non-Javadoc) | |
975 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setDrawTextWithFocusStyle(boolean) | |
976 | */ | |
977 | @Override | |
978 | public void setDrawTextWithFocusStyle(boolean focus) { | |
eb63f5ff | 979 | fDrawWithFocus = focus; |
73005152 | 980 | } |
abbdd66a | 981 | |
df0b8ff4 BH |
982 | /** |
983 | * Returns the screen bounds. | |
abbdd66a | 984 | * |
df0b8ff4 BH |
985 | * @return the screen bounds. |
986 | */ | |
e6ace8bb | 987 | protected static int getVscreenBounds() { |
eb63f5ff | 988 | return fVisibleScreenBounds; |
e6ace8bb BH |
989 | } |
990 | ||
df0b8ff4 BH |
991 | /** |
992 | * Sets the visible screen bounds. | |
abbdd66a | 993 | * |
df0b8ff4 BH |
994 | * @param vBounds the screen bounds. |
995 | */ | |
e6ace8bb | 996 | protected static void setVscreenBounds(int vBounds) { |
eb63f5ff | 997 | fVisibleScreenBounds = vBounds; |
e6ace8bb | 998 | } |
abbdd66a | 999 | |
df0b8ff4 BH |
1000 | // ------------------------------------------------------------------------ |
1001 | // Helper methods | |
1002 | // ------------------------------------------------------------------------ | |
abbdd66a | 1003 | |
df0b8ff4 BH |
1004 | /** |
1005 | * Validates the polygon height | |
abbdd66a | 1006 | * |
df0b8ff4 BH |
1007 | * @param localPoint array of points |
1008 | * @return height | |
1009 | */ | |
1010 | private int validatePolygonHeight(int[] localPoint) { | |
1011 | int i = 1; | |
1012 | int max = 0; | |
1013 | int min = Integer.MAX_VALUE; | |
1014 | while (i < localPoint.length) { | |
abbdd66a | 1015 | max = Math.abs(localPoint[i]) > Math.abs(max) ? localPoint[i] : max; |
df0b8ff4 BH |
1016 | min = Math.abs(localPoint[i]) < Math.abs(min) ? localPoint[i] : min; |
1017 | i+=2; | |
1018 | } | |
1019 | int height = max - min; | |
eb63f5ff BH |
1020 | if (min < -fVisibleScreenBounds) { |
1021 | height = height + min + fVisibleScreenBounds; | |
1022 | min = -fVisibleScreenBounds; | |
1023 | } | |
1024 | if ((height < -fVisibleScreenBounds) && (min + height < -fVisibleScreenBounds)) { | |
1025 | height = -fVisibleScreenBounds; | |
1026 | } else if (height + min > fView.getVisibleHeight() + fVisibleScreenBounds) { | |
1027 | height = fView.getVisibleHeight() + fVisibleScreenBounds - min; | |
df0b8ff4 BH |
1028 | } |
1029 | return height; | |
1030 | } | |
73005152 | 1031 | } |