Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
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 | |
73005152 BH |
9 | * |
10 | * Contributors: | |
11 | * IBM - Initial API and implementation | |
12 | * Bernd Hufmann - Updated for TMF | |
13 | **********************************************************************/ | |
14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd; | |
15 | ||
16 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame; | |
17 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; | |
18 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont; | |
19 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
20 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage; | |
21 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl.ColorImpl; | |
22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; | |
23 | import org.eclipse.swt.SWT; | |
24 | import org.eclipse.swt.graphics.Color; | |
25 | import org.eclipse.swt.graphics.Font; | |
26 | import org.eclipse.swt.graphics.FontData; | |
27 | import org.eclipse.swt.graphics.GC; | |
28 | import org.eclipse.swt.graphics.Image; | |
29 | import org.eclipse.swt.graphics.Point; | |
30 | import org.eclipse.swt.graphics.Rectangle; | |
31 | import org.eclipse.swt.widgets.Display; | |
32 | ||
33 | /** | |
df0b8ff4 BH |
34 | * <p> |
35 | * This class implements the graphical context for the sequence diagram widgets. | |
36 | * </p> | |
73005152 | 37 | * |
df0b8ff4 BH |
38 | * @version 1.0 |
39 | * @author sveyrier | |
73005152 BH |
40 | */ |
41 | public class NGC implements IGC { | |
42 | ||
df0b8ff4 BH |
43 | // ------------------------------------------------------------------------ |
44 | // Attributes | |
45 | // ------------------------------------------------------------------------ | |
46 | ||
47 | /** | |
48 | * The graphical context. | |
49 | */ | |
eb63f5ff | 50 | protected GC fContext; |
df0b8ff4 BH |
51 | /** |
52 | * The reference to the sequence diagram view. | |
53 | */ | |
eb63f5ff | 54 | protected SDWidget fView; |
df0b8ff4 BH |
55 | /** |
56 | * A reference to the last used font. | |
57 | */ | |
eb63f5ff | 58 | protected Font fTempFont = null; |
df0b8ff4 BH |
59 | /** |
60 | * The color of the gradient. | |
61 | */ | |
eb63f5ff | 62 | protected IColor fGradientColor = null; |
df0b8ff4 BH |
63 | /** |
64 | * The color of the background. | |
65 | */ | |
eb63f5ff | 66 | protected IColor fBackground = null; |
df0b8ff4 BH |
67 | /** |
68 | * The color of the foreground. | |
69 | */ | |
eb63f5ff | 70 | protected IColor fForeground = null; |
df0b8ff4 | 71 | /** |
eb63f5ff | 72 | * The current visible y screen bounds |
df0b8ff4 | 73 | */ |
eb63f5ff | 74 | protected int fVisibleY; |
df0b8ff4 | 75 | /** |
eb63f5ff | 76 | * The current visible x screen bound. |
df0b8ff4 | 77 | */ |
eb63f5ff | 78 | protected int fVisibleX; |
df0b8ff4 BH |
79 | /** |
80 | * The current yx value (view visible height - visible screen bounds) | |
81 | */ | |
73005152 | 82 | protected int yx; |
df0b8ff4 BH |
83 | /** |
84 | * The current xx value (view visible width - visible screen bounds) | |
85 | */ | |
73005152 | 86 | protected int xx; |
df0b8ff4 BH |
87 | /** |
88 | * <code>true</code> to draw with focus else <code>false</code>. | |
89 | */ | |
eb63f5ff | 90 | protected boolean fDrawWithFocus = false; |
73005152 | 91 | |
df0b8ff4 BH |
92 | /** |
93 | * The static visible screen bounds. | |
94 | */ | |
eb63f5ff | 95 | private static int fVisibleScreenBounds = 0; |
e6ace8bb | 96 | |
df0b8ff4 BH |
97 | |
98 | // ------------------------------------------------------------------------ | |
99 | // Constructors | |
100 | // ------------------------------------------------------------------------ | |
101 | ||
102 | /** | |
103 | * Default constructor. | |
104 | * | |
105 | * @param scrollView A sequence diagram view reference. | |
106 | * @param gc A graphical context. | |
107 | */ | |
73005152 | 108 | public NGC(SDWidget scrollView, GC gc) { |
eb63f5ff BH |
109 | fContext = gc; |
110 | fView = scrollView; | |
73005152 BH |
111 | } |
112 | ||
df0b8ff4 BH |
113 | // ------------------------------------------------------------------------ |
114 | // Methods | |
115 | // ------------------------------------------------------------------------ | |
116 | ||
117 | /* | |
118 | * (non-Javadoc) | |
119 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setLineStyle(int) | |
120 | */ | |
73005152 BH |
121 | @Override |
122 | public void setLineStyle(int style) { | |
eb63f5ff | 123 | fContext.setLineStyle(style); |
73005152 BH |
124 | } |
125 | ||
df0b8ff4 BH |
126 | /* |
127 | * (non-Javadoc) | |
128 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineStyle() | |
129 | */ | |
73005152 BH |
130 | @Override |
131 | public int getLineStyle() { | |
eb63f5ff | 132 | return fContext.getLineStyle(); |
73005152 BH |
133 | } |
134 | ||
df0b8ff4 BH |
135 | /* |
136 | * (non-Javadoc) | |
137 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getContentsX() | |
138 | */ | |
73005152 BH |
139 | @Override |
140 | public int getContentsX() { | |
eb63f5ff | 141 | return Math.round(fView.getContentsX() / fView.fZoomValue); |
73005152 BH |
142 | } |
143 | ||
df0b8ff4 BH |
144 | /* |
145 | * (non-Javadoc) | |
146 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getContentsY() | |
147 | */ | |
73005152 BH |
148 | @Override |
149 | public int getContentsY() { | |
eb63f5ff | 150 | return Math.round(fView.getContentsY() / fView.fZoomValue); |
73005152 BH |
151 | } |
152 | ||
df0b8ff4 BH |
153 | /* |
154 | * (non-Javadoc) | |
155 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getVisibleWidth() | |
156 | */ | |
73005152 BH |
157 | @Override |
158 | public int getVisibleWidth() { | |
eb63f5ff | 159 | return Math.round(fView.getVisibleWidth() / fView.fZoomValue); |
73005152 BH |
160 | } |
161 | ||
df0b8ff4 BH |
162 | /* |
163 | * (non-Javadoc) | |
164 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getVisibleHeight() | |
165 | */ | |
73005152 BH |
166 | @Override |
167 | public int getVisibleHeight() { | |
eb63f5ff | 168 | return Math.round(fView.getVisibleHeight() / fView.fZoomValue); |
73005152 BH |
169 | } |
170 | ||
df0b8ff4 BH |
171 | /* |
172 | * (non-Javadoc) | |
173 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#contentsToViewX(int) | |
174 | */ | |
73005152 BH |
175 | @Override |
176 | public int contentsToViewX(int x) { | |
eb63f5ff | 177 | return fView.contentsToViewX(x); |
73005152 BH |
178 | } |
179 | ||
df0b8ff4 BH |
180 | /* |
181 | * (non-Javadoc) | |
182 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#contentsToViewY(int) | |
183 | */ | |
73005152 BH |
184 | @Override |
185 | public int contentsToViewY(int y) { | |
eb63f5ff | 186 | return fView.contentsToViewY(y); |
73005152 BH |
187 | } |
188 | ||
df0b8ff4 BH |
189 | /** |
190 | * Get code for drawings at given x and y position. | |
191 | * | |
192 | * @param x The x position | |
193 | * @param y The y position. | |
194 | * @return A code for top, bottom, right and left | |
195 | */ | |
73005152 BH |
196 | protected byte code(int x, int y) { |
197 | byte c = 0; | |
eb63f5ff BH |
198 | fVisibleY = fVisibleScreenBounds; |
199 | fVisibleX = fVisibleScreenBounds; | |
200 | yx = fView.getVisibleHeight() + fVisibleScreenBounds; | |
201 | xx = fView.getVisibleWidth() + fVisibleScreenBounds; | |
df0b8ff4 | 202 | if (y > yx) { |
73005152 | 203 | c |= 0x01; // top |
eb63f5ff | 204 | } else if (y < fVisibleY) { |
73005152 | 205 | c |= 0x02; // bottom |
df0b8ff4 BH |
206 | } |
207 | ||
208 | if (x > xx) { | |
73005152 | 209 | c |= 0x04; // right |
eb63f5ff | 210 | } else if (x < fVisibleX) { |
73005152 | 211 | c |= 0x08; // left |
df0b8ff4 | 212 | } |
73005152 BH |
213 | return c; |
214 | } | |
215 | ||
df0b8ff4 BH |
216 | /* |
217 | * (non-Javadoc) | |
218 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawLine(int, int, int, int) | |
219 | */ | |
73005152 BH |
220 | @Override |
221 | public void drawLine(int x1, int y1, int x2, int y2) { | |
eb63f5ff BH |
222 | int localX1 = x1; |
223 | int localY1 = y1; | |
224 | int localX2 = x2; | |
225 | int localY2 = y2; | |
226 | ||
227 | localX1 = Math.round(localX1 * fView.fZoomValue); | |
228 | localY1 = Math.round(localY1 * fView.fZoomValue); | |
229 | localX2 = Math.round(localX2 * fView.fZoomValue); | |
230 | localY2 = Math.round(localY2 * fView.fZoomValue); | |
231 | localX1 = fView.contentsToViewX(localX1); | |
232 | localY1 = fView.contentsToViewY(localY1); | |
233 | localX2 = fView.contentsToViewX(localX2); | |
234 | localY2 = fView.contentsToViewY(localY2); | |
235 | ||
236 | byte code1 = code(localX1, localY1); | |
237 | byte code2 = code(localX2, localY2); | |
73005152 BH |
238 | byte codex; |
239 | boolean draw = false; | |
240 | boolean end = false; | |
241 | int x = 0, y = 0; | |
242 | ||
243 | do { | |
244 | if (code1 == 0 && code2 == 0) { | |
245 | draw = true; | |
246 | end = true; | |
247 | } else if ((code1 & code2) != 0) { | |
248 | end = true; | |
249 | } else { | |
250 | codex = (code1 != 0) ? code1 : code2; | |
df0b8ff4 | 251 | if ((codex & 0x01) != 0) { // top |
eb63f5ff | 252 | x = localX1 + ((localX2 - localX1) * (yx - localY1)) / (localY2 - localY1); |
73005152 | 253 | y = yx; |
df0b8ff4 | 254 | } else if ((codex & 0x02) != 0) { // bottom |
eb63f5ff BH |
255 | x = localX1 + ((localX2 - localX1) * (fVisibleY - localY1)) / (localY2 - localY1); |
256 | y = fVisibleY; | |
df0b8ff4 | 257 | } else if ((codex & 0x04) != 0) { // right |
eb63f5ff | 258 | y = localY1 + ((localY2 - localY1) * (xx - localX1)) / (localX2 - localX1); |
73005152 | 259 | x = xx; |
df0b8ff4 | 260 | } else if ((codex & 0x08) != 0) { // left |
eb63f5ff BH |
261 | y = localY1 + ((localY2 - localY1) * (fVisibleX - localX1)) / (localX2 - localX1); |
262 | x = fVisibleX; | |
73005152 BH |
263 | } |
264 | ||
265 | if (codex == code1) { | |
eb63f5ff BH |
266 | localX1 = x; |
267 | localY1 = y; | |
268 | code1 = code(localX1, localY1); | |
73005152 | 269 | } else { |
eb63f5ff BH |
270 | localX2 = x; |
271 | localY2 = y; | |
272 | code2 = code(localX2, localY2); | |
73005152 BH |
273 | } |
274 | } | |
275 | } while (!end); | |
df0b8ff4 | 276 | |
73005152 | 277 | if (draw) { |
eb63f5ff | 278 | fContext.drawLine(localX1, localY1, localX2, localY2); |
73005152 BH |
279 | } |
280 | } | |
281 | ||
df0b8ff4 BH |
282 | /* |
283 | * (non-Javadoc) | |
284 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawRectangle(int, int, int, int) | |
285 | */ | |
73005152 BH |
286 | @Override |
287 | public void drawRectangle(int x, int y, int width, int height) { | |
eb63f5ff BH |
288 | int localX = x; |
289 | int localY = y; | |
290 | int localWidth = width; | |
291 | int localHeight = height; | |
292 | ||
293 | localX = Math.round(localX * fView.fZoomValue); | |
73005152 | 294 | // Workaround to avoid problems for some special cases (not very nice) |
eb63f5ff BH |
295 | if (localY != getContentsY()) { |
296 | localY = Math.round(localY * fView.fZoomValue); | |
297 | localY = fView.contentsToViewY(localY); | |
298 | } else { | |
299 | localY = 0; | |
300 | } | |
301 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
302 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
303 | localX = fView.contentsToViewX(localX); | |
304 | ||
305 | if (localX < -fVisibleScreenBounds) { | |
306 | localWidth = localWidth + localX + fVisibleScreenBounds; | |
307 | localX = -fVisibleScreenBounds; | |
308 | } | |
309 | if (localY < -fVisibleScreenBounds) { | |
310 | localHeight = localHeight + localY + fVisibleScreenBounds; | |
311 | localY = -fVisibleScreenBounds; | |
312 | } | |
313 | if ((localWidth < -fVisibleScreenBounds) && (localX + localWidth < -fVisibleScreenBounds)) { | |
314 | localWidth = -fVisibleScreenBounds; | |
315 | } else if (localWidth + localX > fView.getVisibleWidth() + fVisibleScreenBounds) { | |
316 | localWidth = fView.getVisibleWidth() + fVisibleScreenBounds - localX; | |
317 | } | |
318 | if ((localHeight < -fVisibleScreenBounds) && (localY + localHeight < -fVisibleScreenBounds)) { | |
319 | localHeight = -fVisibleScreenBounds; | |
320 | } else if (localHeight + localY > fView.getVisibleHeight() + fVisibleScreenBounds) { | |
321 | localHeight = fView.getVisibleHeight() + fVisibleScreenBounds - localY; | |
322 | } | |
323 | fContext.drawRectangle(localX, localY, localWidth, localHeight); | |
73005152 BH |
324 | } |
325 | ||
df0b8ff4 BH |
326 | /* |
327 | * (non-Javadoc) | |
328 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawFocus(int, int, int, int) | |
329 | */ | |
73005152 BH |
330 | @Override |
331 | public void drawFocus(int x, int y, int width, int height) { | |
eb63f5ff BH |
332 | int localX = x; |
333 | int localY = y; | |
334 | int localWidth = width; | |
335 | int localHeight = height; | |
336 | ||
73005152 BH |
337 | IColor bC = getBackground(); |
338 | IColor fC = getForeground(); | |
339 | ||
eb63f5ff BH |
340 | if (localWidth < 0) { |
341 | localX = localX + localWidth; | |
342 | localWidth = -localWidth; | |
73005152 BH |
343 | } |
344 | ||
eb63f5ff BH |
345 | if (localHeight < 0) { |
346 | localY = localY + localHeight; | |
347 | localHeight = -localHeight; | |
73005152 BH |
348 | } |
349 | ||
eb63f5ff BH |
350 | localX = Math.round(localX * fView.fZoomValue); |
351 | localY = Math.round(localY * fView.fZoomValue); | |
352 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
353 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
73005152 BH |
354 | |
355 | setForeground(Frame.getUserPref().getForeGroundColorSelection()); | |
356 | setBackground(Frame.getUserPref().getBackGroundColorSelection()); | |
357 | ||
eb63f5ff | 358 | fContext.drawFocus(fView.contentsToViewX(localX - 1), fView.contentsToViewY(localY - 1), localWidth + 3, localHeight + 3); |
73005152 BH |
359 | |
360 | setBackground(bC); | |
361 | setForeground(fC); | |
362 | } | |
363 | ||
df0b8ff4 BH |
364 | /* |
365 | * (non-Javadoc) | |
366 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillPolygon(int[]) | |
367 | */ | |
73005152 BH |
368 | @Override |
369 | public void fillPolygon(int[] points) { | |
370 | int len = (points.length / 2) * 2; | |
371 | int[] localPoint = new int[len]; | |
372 | for (int i = 0; i < len; i++) { | |
eb63f5ff | 373 | localPoint[i] = fView.contentsToViewX(Math.round(points[i] * fView.fZoomValue)); |
73005152 | 374 | i++; |
eb63f5ff | 375 | localPoint[i] = fView.contentsToViewY(Math.round(points[i] * fView.fZoomValue)); |
73005152 BH |
376 | } |
377 | ||
378 | if (validatePolygonHeight(localPoint) <= 0) | |
379 | return; | |
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 BH |
396 | } |
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; | |
459 | ||
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 | ||
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) { | |
eb63f5ff | 504 | return ((Point) (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; | |
515 | ||
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; | |
553 | ||
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) | |
657 | * | |
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 BH |
679 | public void drawTextTruncatedCentred(String name, int xValue, int yValue, int width, int height, boolean trans) { |
680 | Point tx = fContext.textExtent(name); | |
681 | xValue = Math.round(xValue * fView.fZoomValue); | |
73005152 BH |
682 | int y = 0; |
683 | // Workaround to avoid round problems for some special cases (not very nice) | |
eb63f5ff BH |
684 | if (yValue != getContentsY()) { |
685 | yValue = Math.round(yValue * fView.fZoomValue); | |
686 | y = fView.contentsToViewY(yValue); | |
73005152 | 687 | } |
eb63f5ff BH |
688 | width = Math.round(width * fView.fZoomValue); |
689 | height = Math.round(height * fView.fZoomValue); | |
690 | int x = fView.contentsToViewX(xValue); | |
df0b8ff4 | 691 | if (tx.y > height) { |
73005152 | 692 | return; |
df0b8ff4 | 693 | } |
73005152 BH |
694 | |
695 | // Adjust height and y | |
eb63f5ff BH |
696 | if (y < -fVisibleScreenBounds) { |
697 | height = height + y + fVisibleScreenBounds; | |
698 | y = -fVisibleScreenBounds; | |
73005152 | 699 | } |
eb63f5ff BH |
700 | if ((height < -fVisibleScreenBounds) && (y + height < -fVisibleScreenBounds)) { |
701 | height = -fVisibleScreenBounds; | |
702 | } else if (height + y > fView.getVisibleHeight() + fVisibleScreenBounds) { | |
703 | height = fView.getVisibleHeight() + fVisibleScreenBounds - y; | |
df0b8ff4 | 704 | } |
73005152 BH |
705 | |
706 | if (tx.x <= width) { | |
707 | localDrawText(name, x + 1 + (width - tx.x) / 2, y + 1 + (height - tx.y) / 2, trans); | |
708 | } else { | |
709 | String nameToDisplay = name; | |
eb63f5ff | 710 | for (int i = name.length() - 1; i >= 0 && fContext.textExtent(nameToDisplay).x >= width; i--) { |
73005152 | 711 | nameToDisplay = name.substring(0, i); |
df0b8ff4 | 712 | } |
73005152 | 713 | int dotCount = 0; |
df0b8ff4 | 714 | for (int i = 1; i <= 3 && nameToDisplay.length() - i > 0; i++) { |
73005152 | 715 | dotCount++; |
df0b8ff4 | 716 | } |
73005152 BH |
717 | nameToDisplay = nameToDisplay.substring(0, nameToDisplay.length() - dotCount); |
718 | StringBuffer buf = new StringBuffer(nameToDisplay); | |
719 | for (int i = 0; i < dotCount; i++) { | |
720 | buf.append("."); //$NON-NLS-1$ | |
73005152 BH |
721 | } |
722 | nameToDisplay = buf.toString(); | |
eb63f5ff | 723 | localDrawText(nameToDisplay, x + 1 + (width - fContext.textExtent(nameToDisplay).x) / 2, y + 1 + (height - fContext.textExtent(nameToDisplay).y) / 2, trans); |
73005152 BH |
724 | } |
725 | } | |
726 | ||
df0b8ff4 BH |
727 | /* |
728 | * (non-Javadoc) | |
729 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawTextTruncated(java.lang.String, int, int, int, int, boolean) | |
730 | */ | |
73005152 | 731 | @Override |
eb63f5ff BH |
732 | public void drawTextTruncated(String name, int xValue, int yValue, int width, int height, boolean trans) { |
733 | int localX = xValue; | |
734 | int localY = yValue; | |
735 | int localWidth = width; | |
736 | int localHeight = height; | |
737 | ||
738 | localX = Math.round(localX * fView.fZoomValue); | |
739 | localY = Math.round(localY * fView.fZoomValue); | |
740 | localWidth = Math.round(localWidth * fView.fZoomValue); | |
741 | localHeight = Math.round(localHeight * fView.fZoomValue); | |
742 | int x = fView.contentsToViewX(localX); | |
743 | int y = fView.contentsToViewY(localY); | |
744 | if (fContext.textExtent(name).x <= localWidth) { | |
745 | localDrawText(name, x + 1, y + 1 + localHeight, trans); | |
73005152 BH |
746 | } else { |
747 | String nameToDisplay = name; | |
eb63f5ff | 748 | for (int i = name.length() - 1; i >= 0 && fContext.textExtent(nameToDisplay).x >= localWidth; i--) { |
73005152 | 749 | nameToDisplay = name.substring(0, i); |
df0b8ff4 | 750 | } |
73005152 | 751 | int dotCount = 0; |
eb63f5ff | 752 | for (int i = 1; i <= 3 && nameToDisplay.length() - i > 0; i++) { |
73005152 | 753 | dotCount++; |
eb63f5ff | 754 | } |
73005152 BH |
755 | nameToDisplay = nameToDisplay.substring(0, nameToDisplay.length() - dotCount); |
756 | ||
757 | StringBuffer buf = new StringBuffer(nameToDisplay); | |
758 | ||
759 | for (int i = 0; i < dotCount; i++) { | |
760 | buf.append("."); //$NON-NLS-1$ | |
73005152 BH |
761 | } |
762 | nameToDisplay = buf.toString(); | |
eb63f5ff | 763 | localDrawText(nameToDisplay, x + 1, y + 1 + localHeight, trans); |
73005152 BH |
764 | } |
765 | } | |
766 | ||
df0b8ff4 BH |
767 | /* |
768 | * (non-Javadoc) | |
769 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawImage(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage, int, int, int, int) | |
770 | */ | |
73005152 | 771 | @Override |
eb63f5ff BH |
772 | public void drawImage(IImage image, int xValue, int yValue, int maxWith, int maxHeight) { |
773 | int localX = xValue; | |
774 | int localY = yValue; | |
775 | ||
73005152 | 776 | Image img = null; |
eb63f5ff | 777 | if (image != null && image.getImage() instanceof Image) { |
73005152 | 778 | img = (Image) image.getImage(); |
eb63f5ff BH |
779 | } else { |
780 | localX = Math.round(localX * fView.fZoomValue); | |
781 | localY = Math.round(localY * fView.fZoomValue); | |
782 | int x = fView.contentsToViewX(localX); | |
783 | int y = fView.contentsToViewY(localY); | |
784 | float tempZoom = fView.fZoomValue; | |
73005152 BH |
785 | int width = Math.round(maxWith * tempZoom); |
786 | int height = Math.round(maxHeight * tempZoom); | |
eb63f5ff BH |
787 | fContext.setBackground(fView.getDisplay().getSystemColor(SWT.COLOR_RED)); |
788 | fContext.fillRectangle(x, y, width, height); | |
73005152 BH |
789 | return; |
790 | } | |
eb63f5ff BH |
791 | localX = Math.round(localX * fView.fZoomValue); |
792 | localY = Math.round(localY * fView.fZoomValue); | |
793 | int x = fView.contentsToViewX(localX); | |
794 | int y = fView.contentsToViewY(localY); | |
73005152 BH |
795 | Rectangle b = ((Image) image.getImage()).getBounds(); |
796 | int width = b.width; | |
797 | int height = b.height; | |
df0b8ff4 | 798 | if (width > maxWith) { |
73005152 | 799 | width = maxWith; |
df0b8ff4 BH |
800 | } |
801 | if (height > maxHeight) { | |
73005152 | 802 | height = maxHeight; |
df0b8ff4 | 803 | } |
eb63f5ff | 804 | float tempZoom = fView.fZoomValue; |
73005152 BH |
805 | width = Math.round(width * tempZoom); |
806 | height = Math.round(height * tempZoom); | |
807 | ||
eb63f5ff BH |
808 | if (fView.fIsPrinting && width > 0 && height > 0) { |
809 | Image dbuffer = new Image(fView.getDisplay(), width, height); | |
73005152 BH |
810 | GC tempgc = new GC(dbuffer); |
811 | tempgc.drawImage(img, 0, 0, b.width, b.height, 0, 0, width, height); | |
eb63f5ff BH |
812 | Image dbuffer2 = new Image(fView.getDisplay(), dbuffer.getImageData()); |
813 | fContext.drawImage(dbuffer2, x, y); | |
73005152 BH |
814 | tempgc.dispose(); |
815 | dbuffer.dispose(); | |
816 | dbuffer2.dispose(); | |
817 | } else { | |
eb63f5ff | 818 | fContext.drawImage(img, 0, 0, b.width, b.height, x, y, width, height); |
73005152 BH |
819 | } |
820 | } | |
821 | ||
df0b8ff4 BH |
822 | /* |
823 | * (non-Javadoc) | |
824 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawArc(int, int, int, int, int, int) | |
825 | */ | |
73005152 BH |
826 | @Override |
827 | public void drawArc(int x, int y, int width, int height, int startAngle, int endAngle) { | |
eb63f5ff BH |
828 | x = Math.round(x * fView.fZoomValue); |
829 | y = Math.round(y * fView.fZoomValue); | |
830 | width = Math.round(width * fView.fZoomValue); | |
831 | height = Math.round(height * fView.fZoomValue); | |
df0b8ff4 | 832 | if (width == 0 || height == 0 || endAngle == 0) { |
73005152 | 833 | return; |
df0b8ff4 | 834 | } |
eb63f5ff | 835 | fContext.drawArc(fView.contentsToViewX(x), fView.contentsToViewY(y), width, height, startAngle, endAngle); |
73005152 BH |
836 | } |
837 | ||
df0b8ff4 BH |
838 | /* |
839 | * (non-Javadoc) | |
840 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setFont(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont) | |
841 | */ | |
73005152 BH |
842 | @Override |
843 | public void setFont(IFont font) { | |
844 | if (font.getFont() != null && ((Font) font.getFont()).getFontData().length > 0) { | |
845 | FontData fontData = ((Font) font.getFont()).getFontData()[0]; | |
eb63f5ff BH |
846 | if (SDViewPref.getInstance().fontLinked() || fView.fIsPrinting) { |
847 | int h = Math.round(fontData.getHeight() * fView.fZoomValue); | |
df0b8ff4 | 848 | if (h > 0) { |
73005152 | 849 | fontData.setHeight(h); |
df0b8ff4 | 850 | } |
73005152 | 851 | } |
eb63f5ff BH |
852 | if (fTempFont != null) { |
853 | fTempFont.dispose(); | |
df0b8ff4 | 854 | } |
eb63f5ff BH |
855 | fTempFont = new Font(Display.getCurrent(), fontData); |
856 | fContext.setFont(fTempFont); | |
73005152 BH |
857 | } |
858 | } | |
859 | ||
df0b8ff4 BH |
860 | /* |
861 | * (non-Javadoc) | |
862 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getFontHeight(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont) | |
863 | */ | |
73005152 BH |
864 | @Override |
865 | public int getFontHeight(IFont font) { | |
866 | if (font.getFont() != null && (font.getFont() instanceof Font) && ((Font) font.getFont()).getFontData().length > 0) { | |
eb63f5ff BH |
867 | Font toRestore = fContext.getFont(); |
868 | fContext.setFont((Font) font.getFont()); | |
869 | int height = fContext.textExtent("lp").y;//$NON-NLS-1$ | |
870 | fContext.setFont(toRestore); | |
73005152 BH |
871 | return height; |
872 | } | |
873 | return 0; | |
874 | } | |
875 | ||
df0b8ff4 BH |
876 | /** |
877 | * Returns the current font height. | |
878 | * | |
879 | * @return the current font height. | |
880 | */ | |
73005152 | 881 | protected int getCurrentFontHeight() { |
eb63f5ff | 882 | return fContext.textExtent("lp").y; //$NON-NLS-1$ |
73005152 BH |
883 | } |
884 | ||
df0b8ff4 BH |
885 | /* |
886 | * (non-Javadoc) | |
887 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getFontWidth(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont) | |
888 | */ | |
73005152 BH |
889 | @Override |
890 | public int getFontWidth(IFont font) { | |
891 | if ((font.getFont() != null) && (font.getFont() instanceof Font)) { | |
eb63f5ff BH |
892 | Font toRestore = fContext.getFont(); |
893 | fContext.setFont((Font) font.getFont()); | |
894 | int width = fContext.getFontMetrics().getAverageCharWidth(); | |
895 | fContext.setFont(toRestore); | |
73005152 BH |
896 | return width; |
897 | } | |
898 | return 0; | |
899 | } | |
900 | ||
df0b8ff4 BH |
901 | /** |
902 | * Disposes all created resources. | |
903 | */ | |
73005152 | 904 | public void dispose() { |
eb63f5ff BH |
905 | if (fTempFont != null) { |
906 | fTempFont.dispose(); | |
df0b8ff4 | 907 | } |
eb63f5ff BH |
908 | fTempFont = null; |
909 | if (fContext != null) { | |
910 | fContext.dispose(); | |
df0b8ff4 | 911 | } |
eb63f5ff | 912 | fContext = null; |
73005152 BH |
913 | } |
914 | ||
df0b8ff4 BH |
915 | /* |
916 | * (non-Javadoc) | |
917 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getZoom() | |
918 | */ | |
73005152 BH |
919 | @Override |
920 | public float getZoom() { | |
eb63f5ff BH |
921 | if (fView != null) { |
922 | return fView.fZoomValue; | |
923 | } | |
924 | return 1; | |
73005152 BH |
925 | } |
926 | ||
df0b8ff4 BH |
927 | /* |
928 | * (non-Javadoc) | |
929 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineDotStyle() | |
930 | */ | |
73005152 BH |
931 | @Override |
932 | public int getLineDotStyle() { | |
933 | return SWT.LINE_DOT; | |
934 | } | |
935 | ||
df0b8ff4 BH |
936 | /* |
937 | * (non-Javadoc) | |
938 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineDashStyle() | |
939 | */ | |
73005152 BH |
940 | @Override |
941 | public int getLineDashStyle() { | |
942 | return SWT.LINE_DASH; | |
943 | } | |
944 | ||
df0b8ff4 BH |
945 | /* |
946 | * (non-Javadoc) | |
947 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineSolidStyle() | |
948 | */ | |
73005152 BH |
949 | @Override |
950 | public int getLineSolidStyle() { | |
951 | return SWT.LINE_SOLID; | |
952 | } | |
953 | ||
df0b8ff4 BH |
954 | /* |
955 | * (non-Javadoc) | |
956 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#createColor(int, int, int) | |
957 | */ | |
73005152 BH |
958 | @Override |
959 | public IColor createColor(int r, int g, int b) { | |
960 | return new ColorImpl(Display.getDefault(), r, g, b); | |
961 | } | |
962 | ||
963 | /* | |
964 | * (non-Javadoc) | |
965 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setDrawTextWithFocusStyle(boolean) | |
966 | */ | |
967 | @Override | |
968 | public void setDrawTextWithFocusStyle(boolean focus) { | |
eb63f5ff | 969 | fDrawWithFocus = focus; |
73005152 | 970 | } |
e6ace8bb | 971 | |
df0b8ff4 BH |
972 | /** |
973 | * Returns the screen bounds. | |
974 | * | |
975 | * @return the screen bounds. | |
976 | */ | |
e6ace8bb | 977 | protected static int getVscreenBounds() { |
eb63f5ff | 978 | return fVisibleScreenBounds; |
e6ace8bb BH |
979 | } |
980 | ||
df0b8ff4 BH |
981 | /** |
982 | * Sets the visible screen bounds. | |
983 | * | |
984 | * @param vBounds the screen bounds. | |
985 | */ | |
e6ace8bb | 986 | protected static void setVscreenBounds(int vBounds) { |
eb63f5ff | 987 | fVisibleScreenBounds = vBounds; |
e6ace8bb | 988 | } |
df0b8ff4 BH |
989 | |
990 | // ------------------------------------------------------------------------ | |
991 | // Helper methods | |
992 | // ------------------------------------------------------------------------ | |
993 | ||
994 | /** | |
995 | * Validates the polygon height | |
996 | * | |
997 | * @param localPoint array of points | |
998 | * @return height | |
999 | */ | |
1000 | private int validatePolygonHeight(int[] localPoint) { | |
1001 | int i = 1; | |
1002 | int max = 0; | |
1003 | int min = Integer.MAX_VALUE; | |
1004 | while (i < localPoint.length) { | |
1005 | max = Math.abs(localPoint[i]) > Math.abs(max) ? localPoint[i] : max; | |
1006 | min = Math.abs(localPoint[i]) < Math.abs(min) ? localPoint[i] : min; | |
1007 | i+=2; | |
1008 | } | |
1009 | int height = max - min; | |
eb63f5ff BH |
1010 | if (min < -fVisibleScreenBounds) { |
1011 | height = height + min + fVisibleScreenBounds; | |
1012 | min = -fVisibleScreenBounds; | |
1013 | } | |
1014 | if ((height < -fVisibleScreenBounds) && (min + height < -fVisibleScreenBounds)) { | |
1015 | height = -fVisibleScreenBounds; | |
1016 | } else if (height + min > fView.getVisibleHeight() + fVisibleScreenBounds) { | |
1017 | height = fView.getVisibleHeight() + fVisibleScreenBounds - min; | |
df0b8ff4 BH |
1018 | } |
1019 | return height; | |
1020 | } | |
73005152 | 1021 | } |