db6a21348371baff4b14df30355d81e37ad31280
1 /**********************************************************************
2 * Copyright (c) 2005, 2012 IBM Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
;
15 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IFont
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IImage
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.impl
.ColorImpl
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.graphics
.Color
;
23 import org
.eclipse
.swt
.graphics
.Font
;
24 import org
.eclipse
.swt
.graphics
.FontData
;
25 import org
.eclipse
.swt
.graphics
.GC
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.swt
.graphics
.Point
;
28 import org
.eclipse
.swt
.graphics
.Rectangle
;
29 import org
.eclipse
.swt
.widgets
.Display
;
33 * This class implements the graphical context for the sequence diagram widgets.
39 public class NGC
implements IGC
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * The graphical context.
48 protected GC fContext
;
50 * The reference to the sequence diagram view.
52 protected SDWidget fView
;
54 * A reference to the last used font.
56 protected Font fTempFont
= null;
58 * The color of the gradient.
60 protected IColor fGradientColor
= null;
62 * The color of the background.
64 protected IColor fBackground
= null;
66 * The color of the foreground.
68 protected IColor fForeground
= null;
70 * The current visible y screen bounds
72 protected int fVisibleY
;
74 * The current visible x screen bound.
76 protected int fVisibleX
;
78 * The current yx value (view visible height - visible screen bounds)
82 * The current xx value (view visible width - visible screen bounds)
86 * <code>true</code> to draw with focus else <code>false</code>.
88 protected boolean fDrawWithFocus
= false;
91 * The static visible screen bounds.
93 private static int fVisibleScreenBounds
= 0;
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 * Default constructor.
103 * @param scrollView A sequence diagram view reference.
104 * @param gc A graphical context.
106 public NGC(SDWidget scrollView
, GC gc
) {
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
117 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setLineStyle(int)
120 public void setLineStyle(int style
) {
121 fContext
.setLineStyle(style
);
126 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineStyle()
129 public int getLineStyle() {
130 return fContext
.getLineStyle();
135 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getContentsX()
138 public int getContentsX() {
139 return Math
.round(fView
.getContentsX() / fView
.fZoomValue
);
144 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getContentsY()
147 public int getContentsY() {
148 return Math
.round(fView
.getContentsY() / fView
.fZoomValue
);
153 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getVisibleWidth()
156 public int getVisibleWidth() {
157 return Math
.round(fView
.getVisibleWidth() / fView
.fZoomValue
);
162 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getVisibleHeight()
165 public int getVisibleHeight() {
166 return Math
.round(fView
.getVisibleHeight() / fView
.fZoomValue
);
171 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#contentsToViewX(int)
174 public int contentsToViewX(int x
) {
175 return fView
.contentsToViewX(x
);
180 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#contentsToViewY(int)
183 public int contentsToViewY(int y
) {
184 return fView
.contentsToViewY(y
);
188 * Get code for drawings at given x and y position.
190 * @param x The x position
191 * @param y The y position.
192 * @return A code for top, bottom, right and left
194 protected byte code(int x
, int y
) {
196 fVisibleY
= fVisibleScreenBounds
;
197 fVisibleX
= fVisibleScreenBounds
;
198 yx
= fView
.getVisibleHeight() + fVisibleScreenBounds
;
199 xx
= fView
.getVisibleWidth() + fVisibleScreenBounds
;
202 } else if (y
< fVisibleY
) {
208 } else if (x
< fVisibleX
) {
216 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawLine(int, int, int, int)
219 public void drawLine(int x1
, int y1
, int x2
, int y2
) {
225 localX1
= Math
.round(localX1
* fView
.fZoomValue
);
226 localY1
= Math
.round(localY1
* fView
.fZoomValue
);
227 localX2
= Math
.round(localX2
* fView
.fZoomValue
);
228 localY2
= Math
.round(localY2
* fView
.fZoomValue
);
229 localX1
= fView
.contentsToViewX(localX1
);
230 localY1
= fView
.contentsToViewY(localY1
);
231 localX2
= fView
.contentsToViewX(localX2
);
232 localY2
= fView
.contentsToViewY(localY2
);
234 byte code1
= code(localX1
, localY1
);
235 byte code2
= code(localX2
, localY2
);
237 boolean draw
= false;
242 if (code1
== 0 && code2
== 0) {
245 } else if ((code1
& code2
) != 0) {
248 codex
= (code1
!= 0) ? code1
: code2
;
249 if ((codex
& 0x01) != 0) { // top
250 x
= localX1
+ ((localX2
- localX1
) * (yx
- localY1
)) / (localY2
- localY1
);
252 } else if ((codex
& 0x02) != 0) { // bottom
253 x
= localX1
+ ((localX2
- localX1
) * (fVisibleY
- localY1
)) / (localY2
- localY1
);
255 } else if ((codex
& 0x04) != 0) { // right
256 y
= localY1
+ ((localY2
- localY1
) * (xx
- localX1
)) / (localX2
- localX1
);
258 } else if ((codex
& 0x08) != 0) { // left
259 y
= localY1
+ ((localY2
- localY1
) * (fVisibleX
- localX1
)) / (localX2
- localX1
);
263 if (codex
== code1
) {
266 code1
= code(localX1
, localY1
);
270 code2
= code(localX2
, localY2
);
276 fContext
.drawLine(localX1
, localY1
, localX2
, localY2
);
282 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawRectangle(int, int, int, int)
285 public void drawRectangle(int x
, int y
, int width
, int height
) {
288 int localWidth
= width
;
289 int localHeight
= height
;
291 localX
= Math
.round(localX
* fView
.fZoomValue
);
292 // Workaround to avoid problems for some special cases (not very nice)
293 if (localY
!= getContentsY()) {
294 localY
= Math
.round(localY
* fView
.fZoomValue
);
295 localY
= fView
.contentsToViewY(localY
);
299 localWidth
= Math
.round(localWidth
* fView
.fZoomValue
);
300 localHeight
= Math
.round(localHeight
* fView
.fZoomValue
);
301 localX
= fView
.contentsToViewX(localX
);
303 if (localX
< -fVisibleScreenBounds
) {
304 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
305 localX
= -fVisibleScreenBounds
;
307 if (localY
< -fVisibleScreenBounds
) {
308 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
309 localY
= -fVisibleScreenBounds
;
311 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
312 localWidth
= -fVisibleScreenBounds
;
313 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
314 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
316 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
317 localHeight
= -fVisibleScreenBounds
;
318 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
319 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
321 fContext
.drawRectangle(localX
, localY
, localWidth
, localHeight
);
326 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawFocus(int, int, int, int)
329 public void drawFocus(int x
, int y
, int width
, int height
) {
332 int localWidth
= width
;
333 int localHeight
= height
;
335 IColor bC
= getBackground();
336 IColor fC
= getForeground();
338 if (localWidth
< 0) {
339 localX
= localX
+ localWidth
;
340 localWidth
= -localWidth
;
343 if (localHeight
< 0) {
344 localY
= localY
+ localHeight
;
345 localHeight
= -localHeight
;
348 localX
= Math
.round(localX
* fView
.fZoomValue
);
349 localY
= Math
.round(localY
* fView
.fZoomValue
);
350 localWidth
= Math
.round(localWidth
* fView
.fZoomValue
);
351 localHeight
= Math
.round(localHeight
* fView
.fZoomValue
);
353 setForeground(SDViewPref
.getInstance().getForeGroundColorSelection());
354 setBackground(SDViewPref
.getInstance().getBackGroundColorSelection());
356 fContext
.drawFocus(fView
.contentsToViewX(localX
- 1), fView
.contentsToViewY(localY
- 1), localWidth
+ 3, localHeight
+ 3);
364 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillPolygon(int[])
367 public void fillPolygon(int[] points
) {
368 int len
= (points
.length
/ 2) * 2;
369 int[] localPoint
= new int[len
];
370 for (int i
= 0; i
< len
; i
++) {
371 localPoint
[i
] = fView
.contentsToViewX(Math
.round(points
[i
] * fView
.fZoomValue
));
373 localPoint
[i
] = fView
.contentsToViewY(Math
.round(points
[i
] * fView
.fZoomValue
));
376 if (validatePolygonHeight(localPoint
) <= 0) {
380 fContext
.fillPolygon(localPoint
);
385 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawPolygon(int[])
388 public void drawPolygon(int[] points
) {
389 int len
= (points
.length
/ 2) * 2;
390 int[] localPoint
= new int[len
];
391 for (int i
= 0; i
< len
; i
++) {
392 localPoint
[i
] = fView
.contentsToViewX(Math
.round(points
[i
] * fView
.fZoomValue
));
394 localPoint
[i
] = fView
.contentsToViewY(Math
.round(points
[i
] * fView
.fZoomValue
));
397 if (validatePolygonHeight(localPoint
) <= 0) {
401 fContext
.drawPolygon(localPoint
);
406 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillRectangle(int, int, int, int)
409 public void fillRectangle(int x
, int y
, int width
, int height
) {
412 int localWidth
= width
;
413 int localHeight
= height
;
415 localX
= Math
.round(localX
* fView
.fZoomValue
);
416 // Workaround to avoid problems for some special cases (not very nice)
417 if (localY
!= getContentsY()) {
418 localY
= Math
.round(localY
* fView
.fZoomValue
);
419 localY
= fView
.contentsToViewY(localY
) + 1;
423 localWidth
= Math
.round(localWidth
* fView
.fZoomValue
) - 1;
424 localHeight
= Math
.round(localHeight
* fView
.fZoomValue
) - 1;
425 localX
= fView
.contentsToViewX(localX
) + 1;
426 if (localX
< -fVisibleScreenBounds
) {
427 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
428 localX
= -fVisibleScreenBounds
;
430 if (localY
< -fVisibleScreenBounds
) {
431 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
432 localY
= -fVisibleScreenBounds
;
434 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
435 localWidth
= -fVisibleScreenBounds
;
436 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
437 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
439 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
440 localHeight
= -fVisibleScreenBounds
;
441 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
442 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
444 fContext
.fillRectangle(localX
, localY
, localWidth
, localHeight
);
450 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillGradientRectangle(int, int, int, int, boolean)
453 public void fillGradientRectangle(int x
, int y
, int width
, int height
, boolean isVertical
) {
456 int localWidth
= width
;
457 int localHeight
= height
;
459 localX
= Math
.round(localX
* fView
.fZoomValue
);
460 localY
= Math
.round(localY
* fView
.fZoomValue
);
461 localWidth
= Math
.round(localWidth
* fView
.fZoomValue
);
462 localHeight
= Math
.round(localHeight
* fView
.fZoomValue
);
463 IColor tempColor
= fForeground
;
464 setForeground(fGradientColor
);
465 localX
= fView
.contentsToViewX(localX
);
466 localY
= fView
.contentsToViewY(localY
);
468 if (localX
< -fVisibleScreenBounds
) {
469 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
470 localX
= -fVisibleScreenBounds
;
472 if (localY
< -fVisibleScreenBounds
) {
473 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
474 localY
= -fVisibleScreenBounds
;
477 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
478 localWidth
= -fVisibleScreenBounds
;
479 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
480 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
482 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
483 localHeight
= -fVisibleScreenBounds
;
484 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
485 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
488 fContext
.fillGradientRectangle(localX
, localY
, localWidth
, localHeight
, isVertical
);
491 fContext
.fillGradientRectangle(localX
+ localWidth
, localY
, -localWidth
, localHeight
+ 1, isVertical
);
493 setForeground(tempColor
);
499 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#textExtent(java.lang.String)
502 public int textExtent(String name
) {
503 return fContext
.textExtent(name
).x
;
508 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawText(java.lang.String, int, int, boolean)
511 public void drawText(String string
, int x
, int y
, boolean isTrans
) {
515 localX
= Math
.round(localX
* fView
.fZoomValue
);
516 localY
= Math
.round(localY
* fView
.fZoomValue
);
517 fContext
.drawText(string
, fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), isTrans
);
518 if (fDrawWithFocus
) {
519 Point r
= fContext
.textExtent(string
);
520 fContext
.drawFocus(localX
- 1, localY
- 1, r
.x
+ 2, r
.y
+ 2);
526 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawText(java.lang.String, int, int)
529 public void drawText(String string
, int x
, int y
) {
533 localX
= Math
.round(localX
* fView
.fZoomValue
);
534 localY
= Math
.round(localY
* fView
.fZoomValue
);
535 fContext
.drawText(string
, fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), true);
536 if (fDrawWithFocus
) {
537 Point r
= fContext
.textExtent(string
);
538 fContext
.drawFocus(localX
- 1, localY
- 1, r
.x
+ 2, r
.y
+ 2);
544 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#fillOval(int, int, int, int)
547 public void fillOval(int x
, int y
, int width
, int height
) {
550 int localWidth
= width
;
551 int localHeight
= height
;
553 localX
= Math
.round(localX
* fView
.fZoomValue
);
554 localY
= Math
.round(localY
* fView
.fZoomValue
);
555 localWidth
= Math
.round(localWidth
* fView
.fZoomValue
);
556 localHeight
= Math
.round(localHeight
* fView
.fZoomValue
);
557 fContext
.fillOval(fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), localWidth
, localHeight
);
562 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getBackground()
565 public IColor
getBackground() {
566 if ((fBackground
!= null) && (fBackground
.getColor() instanceof Color
) && (!((Color
) (fBackground
.getColor())).isDisposed())) {
569 return ColorImpl
.getSystemColor(SWT
.COLOR_WHITE
);
574 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getForeground()
577 public IColor
getForeground() {
578 if ((fForeground
!= null) && (fForeground
.getColor() instanceof Color
) && (!((Color
) (fForeground
.getColor())).isDisposed())) {
581 return ColorImpl
.getSystemColor(SWT
.COLOR_WHITE
);
586 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setBackground(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor)
589 public void setBackground(IColor color
) {
593 if (color
.getColor() instanceof Color
) {
594 fContext
.setBackground((Color
) color
.getColor());
601 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setForeground(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor)
604 public void setForeground(IColor color
) {
608 if (color
.getColor() instanceof Color
) {
609 Color c
= (Color
) color
.getColor();
610 if (!c
.isDisposed()) {
611 fContext
.setForeground(c
);
619 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setGradientColor(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor)
622 public void setGradientColor(IColor color
) {
626 if (color
.getColor() instanceof Color
) {
627 fGradientColor
= color
;
633 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setLineWidth(int)
636 public void setLineWidth(int width
) {
637 if (fView
.isPrinting()) {
638 fContext
.setLineWidth(width
* 2);
641 fContext
.setLineWidth(width
);
647 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineWidth()
650 public int getLineWidth() {
651 return fContext
.getLineWidth();
655 * Method to draw a text in rectangle. (Linux GTK Workaround)
657 * @param string The text to draw.
658 * @param x The x position.
659 * @param y The y position.
660 * @param isTransparent true for transparent else false
662 protected void localDrawText(String string
, int x
, int y
, boolean isTransparent
) {
663 Point r
= fContext
.textExtent(string
);
664 if (!isTransparent
) {
665 fContext
.fillRectangle(x
, y
, r
.x
, r
.y
);
667 fContext
.drawText(string
, x
, y
, isTransparent
);
668 if ((fDrawWithFocus
) && (string
.length() > 1)) {
669 fContext
.drawFocus(x
- 1, y
- 1, r
.x
+ 2, r
.y
+ 2);
675 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawTextTruncatedCentred(java.lang.String, int, int, int, int, boolean)
678 public void drawTextTruncatedCentred(String name
, int xValue
, int yValue
, int width
, int height
, boolean trans
) {
681 int localWidth
= width
;
682 int localHeight
= height
;
684 Point tx
= fContext
.textExtent(name
);
685 localX
= Math
.round(localX
* fView
.fZoomValue
);
687 // Workaround to avoid round problems for some special cases (not very nice)
688 if (localY
!= getContentsY()) {
689 localY
= Math
.round(localY
* fView
.fZoomValue
);
690 y
= fView
.contentsToViewY(localY
);
692 localWidth
= Math
.round(localWidth
* fView
.fZoomValue
);
693 localHeight
= Math
.round(localHeight
* fView
.fZoomValue
);
694 int x
= fView
.contentsToViewX(localX
);
695 if (tx
.y
> localHeight
) {
699 // Adjust height and y
700 if (y
< -fVisibleScreenBounds
) {
701 localHeight
= localHeight
+ y
+ fVisibleScreenBounds
;
702 y
= -fVisibleScreenBounds
;
704 if ((localHeight
< -fVisibleScreenBounds
) && (y
+ localHeight
< -fVisibleScreenBounds
)) {
705 localHeight
= -fVisibleScreenBounds
;
706 } else if (localHeight
+ y
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
707 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- y
;
710 if (tx
.x
<= localWidth
) {
711 localDrawText(name
, x
+ 1 + (localWidth
- tx
.x
) / 2, y
+ 1 + (localHeight
- tx
.y
) / 2, trans
);
713 String nameToDisplay
= name
;
714 for (int i
= name
.length() - 1; i
>= 0 && fContext
.textExtent(nameToDisplay
).x
>= localWidth
; i
--) {
715 nameToDisplay
= name
.substring(0, i
);
718 for (int i
= 1; i
<= 3 && nameToDisplay
.length() - i
> 0; i
++) {
721 nameToDisplay
= nameToDisplay
.substring(0, nameToDisplay
.length() - dotCount
);
722 StringBuffer buf
= new StringBuffer(nameToDisplay
);
723 for (int i
= 0; i
< dotCount
; i
++) {
724 buf
.append("."); //$NON-NLS-1$
726 nameToDisplay
= buf
.toString();
727 localDrawText(nameToDisplay
, x
+ 1 + (localWidth
- fContext
.textExtent(nameToDisplay
).x
) / 2, y
+ 1 + (localHeight
- fContext
.textExtent(nameToDisplay
).y
) / 2, trans
);
733 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawTextTruncated(java.lang.String, int, int, int, int, boolean)
736 public void drawTextTruncated(String name
, int xValue
, int yValue
, int width
, int height
, boolean trans
) {
739 int localWidth
= width
;
740 int localHeight
= height
;
742 localX
= Math
.round(localX
* fView
.fZoomValue
);
743 localY
= Math
.round(localY
* fView
.fZoomValue
);
744 localWidth
= Math
.round(localWidth
* fView
.fZoomValue
);
745 localHeight
= Math
.round(localHeight
* fView
.fZoomValue
);
746 int x
= fView
.contentsToViewX(localX
);
747 int y
= fView
.contentsToViewY(localY
);
748 if (fContext
.textExtent(name
).x
<= localWidth
) {
749 localDrawText(name
, x
+ 1, y
+ 1 + localHeight
, trans
);
751 String nameToDisplay
= name
;
752 for (int i
= name
.length() - 1; i
>= 0 && fContext
.textExtent(nameToDisplay
).x
>= localWidth
; i
--) {
753 nameToDisplay
= name
.substring(0, i
);
756 for (int i
= 1; i
<= 3 && nameToDisplay
.length() - i
> 0; i
++) {
759 nameToDisplay
= nameToDisplay
.substring(0, nameToDisplay
.length() - dotCount
);
761 StringBuffer buf
= new StringBuffer(nameToDisplay
);
763 for (int i
= 0; i
< dotCount
; i
++) {
764 buf
.append("."); //$NON-NLS-1$
766 nameToDisplay
= buf
.toString();
767 localDrawText(nameToDisplay
, x
+ 1, y
+ 1 + localHeight
, trans
);
773 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawImage(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IImage, int, int, int, int)
776 public void drawImage(IImage image
, int xValue
, int yValue
, int maxWith
, int maxHeight
) {
781 if (image
!= null && image
.getImage() instanceof Image
) {
782 img
= (Image
) image
.getImage();
784 localX
= Math
.round(localX
* fView
.fZoomValue
);
785 localY
= Math
.round(localY
* fView
.fZoomValue
);
786 int x
= fView
.contentsToViewX(localX
);
787 int y
= fView
.contentsToViewY(localY
);
788 float tempZoom
= fView
.fZoomValue
;
789 int width
= Math
.round(maxWith
* tempZoom
);
790 int height
= Math
.round(maxHeight
* tempZoom
);
791 fContext
.setBackground(fView
.getDisplay().getSystemColor(SWT
.COLOR_RED
));
792 fContext
.fillRectangle(x
, y
, width
, height
);
795 localX
= Math
.round(localX
* fView
.fZoomValue
);
796 localY
= Math
.round(localY
* fView
.fZoomValue
);
797 int x
= fView
.contentsToViewX(localX
);
798 int y
= fView
.contentsToViewY(localY
);
799 Rectangle b
= ((Image
) image
.getImage()).getBounds();
801 int height
= b
.height
;
802 if (width
> maxWith
) {
805 if (height
> maxHeight
) {
808 float tempZoom
= fView
.fZoomValue
;
809 width
= Math
.round(width
* tempZoom
);
810 height
= Math
.round(height
* tempZoom
);
812 if (fView
.fIsPrinting
&& width
> 0 && height
> 0) {
813 Image dbuffer
= new Image(fView
.getDisplay(), width
, height
);
814 GC tempgc
= new GC(dbuffer
);
815 tempgc
.drawImage(img
, 0, 0, b
.width
, b
.height
, 0, 0, width
, height
);
816 Image dbuffer2
= new Image(fView
.getDisplay(), dbuffer
.getImageData());
817 fContext
.drawImage(dbuffer2
, x
, y
);
822 fContext
.drawImage(img
, 0, 0, b
.width
, b
.height
, x
, y
, width
, height
);
828 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#drawArc(int, int, int, int, int, int)
831 public void drawArc(int x
, int y
, int width
, int height
, int startAngle
, int endAngle
) {
834 int localWidth
= width
;
835 int localHeight
= height
;
837 localX
= Math
.round(localX
* fView
.fZoomValue
);
838 localY
= Math
.round(localY
* fView
.fZoomValue
);
839 localWidth
= Math
.round(localWidth
* fView
.fZoomValue
);
840 localHeight
= Math
.round(localHeight
* fView
.fZoomValue
);
841 if (localWidth
== 0 || localHeight
== 0 || endAngle
== 0) {
844 fContext
.drawArc(fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), localWidth
, localHeight
, startAngle
, endAngle
);
849 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setFont(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont)
852 public void setFont(IFont font
) {
853 if (font
.getFont() != null && ((Font
) font
.getFont()).getFontData().length
> 0) {
854 FontData fontData
= ((Font
) font
.getFont()).getFontData()[0];
855 if (SDViewPref
.getInstance().fontLinked() || fView
.fIsPrinting
) {
856 int h
= Math
.round(fontData
.getHeight() * fView
.fZoomValue
);
858 fontData
.setHeight(h
);
861 if (fTempFont
!= null) {
864 fTempFont
= new Font(Display
.getCurrent(), fontData
);
865 fContext
.setFont(fTempFont
);
871 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getFontHeight(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont)
874 public int getFontHeight(IFont font
) {
875 if (font
.getFont() != null && (font
.getFont() instanceof Font
) && ((Font
) font
.getFont()).getFontData().length
> 0) {
876 Font toRestore
= fContext
.getFont();
877 fContext
.setFont((Font
) font
.getFont());
878 int height
= fContext
.textExtent("lp").y
;//$NON-NLS-1$
879 fContext
.setFont(toRestore
);
886 * Returns the current font height.
888 * @return the current font height.
890 protected int getCurrentFontHeight() {
891 return fContext
.textExtent("lp").y
; //$NON-NLS-1$
896 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getFontWidth(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IFont)
899 public int getFontWidth(IFont font
) {
900 if ((font
.getFont() != null) && (font
.getFont() instanceof Font
)) {
901 Font toRestore
= fContext
.getFont();
902 fContext
.setFont((Font
) font
.getFont());
903 int width
= fContext
.getFontMetrics().getAverageCharWidth();
904 fContext
.setFont(toRestore
);
911 * Disposes all created resources.
913 public void dispose() {
914 if (fTempFont
!= null) {
918 if (fContext
!= null) {
926 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getZoom()
929 public float getZoom() {
931 return fView
.fZoomValue
;
938 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineDotStyle()
941 public int getLineDotStyle() {
947 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineDashStyle()
950 public int getLineDashStyle() {
951 return SWT
.LINE_DASH
;
956 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#getLineSolidStyle()
959 public int getLineSolidStyle() {
960 return SWT
.LINE_SOLID
;
965 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#createColor(int, int, int)
968 public IColor
createColor(int r
, int g
, int b
) {
969 return new ColorImpl(Display
.getDefault(), r
, g
, b
);
974 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC#setDrawTextWithFocusStyle(boolean)
977 public void setDrawTextWithFocusStyle(boolean focus
) {
978 fDrawWithFocus
= focus
;
982 * Returns the screen bounds.
984 * @return the screen bounds.
986 protected static int getVscreenBounds() {
987 return fVisibleScreenBounds
;
991 * Sets the visible screen bounds.
993 * @param vBounds the screen bounds.
995 protected static void setVscreenBounds(int vBounds
) {
996 fVisibleScreenBounds
= vBounds
;
999 // ------------------------------------------------------------------------
1001 // ------------------------------------------------------------------------
1004 * Validates the polygon height
1006 * @param localPoint array of points
1009 private int validatePolygonHeight(int[] localPoint
) {
1012 int min
= Integer
.MAX_VALUE
;
1013 while (i
< localPoint
.length
) {
1014 max
= Math
.abs(localPoint
[i
]) > Math
.abs(max
) ? localPoint
[i
] : max
;
1015 min
= Math
.abs(localPoint
[i
]) < Math
.abs(min
) ? localPoint
[i
] : min
;
1018 int height
= max
- min
;
1019 if (min
< -fVisibleScreenBounds
) {
1020 height
= height
+ min
+ fVisibleScreenBounds
;
1021 min
= -fVisibleScreenBounds
;
1023 if ((height
< -fVisibleScreenBounds
) && (min
+ height
< -fVisibleScreenBounds
)) {
1024 height
= -fVisibleScreenBounds
;
1025 } else if (height
+ min
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
1026 height
= fView
.getVisibleHeight() + fVisibleScreenBounds
- min
;
This page took 0.052898 seconds and 5 git commands to generate.