1 /**********************************************************************
2 * Copyright (c) 2005, 2014 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
.tracecompass
.tmf
.ui
.views
.uml2sd
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.graphics
.Color
;
17 import org
.eclipse
.swt
.graphics
.Font
;
18 import org
.eclipse
.swt
.graphics
.FontData
;
19 import org
.eclipse
.swt
.graphics
.GC
;
20 import org
.eclipse
.swt
.graphics
.Image
;
21 import org
.eclipse
.swt
.graphics
.Point
;
22 import org
.eclipse
.swt
.graphics
.Rectangle
;
23 import org
.eclipse
.swt
.widgets
.Display
;
24 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.drawings
.IFont
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.drawings
.IImage
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.drawings
.impl
.ColorImpl
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
33 * This class implements the graphical context for the sequence diagram widgets.
39 public class NGC
implements IGC
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * The graphical context.
50 * The reference to the sequence diagram view.
52 private SDWidget fView
;
54 * A reference to the last used font.
56 private Font fTempFont
= null;
58 * The color of the gradient.
60 private IColor fGradientColor
= null;
62 * The color of the background.
64 private IColor fBackground
= null;
66 * The color of the foreground.
68 private IColor fForeground
= null;
70 * The current visible y screen bounds
72 private int fVisibleY
;
74 * The current visible x screen bound.
76 private 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 private 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 // ------------------------------------------------------------------------
116 public void setLineStyle(int style
) {
117 fContext
.setLineStyle(style
);
121 public int getLineStyle() {
122 return fContext
.getLineStyle();
126 public int getContentsX() {
127 return Math
.round(fView
.getContentsX() / fView
.getZoomValue());
131 public int getContentsY() {
132 return Math
.round(fView
.getContentsY() / fView
.getZoomValue());
136 public int getVisibleWidth() {
137 return Math
.round(fView
.getVisibleWidth() / fView
.getZoomValue());
141 public int getVisibleHeight() {
142 return Math
.round(fView
.getVisibleHeight() / fView
.getZoomValue());
146 * Returns the current visible y screen bounds.
148 * @return the current visible y screen bounds
150 protected int getVisibleY() {
155 * Sets the current visible y screen bounds.
158 * the current visible y screen bounds
160 protected void setVisibleY(int visibleY
) {
161 fVisibleY
= visibleY
;
165 * Returns the current visible x screen bound.
167 * @return the current visible x screen bound.
169 protected int getfVisibleX() {
174 * Sets the current visible x screen bound.
177 * the current visible x screen bound.
179 protected void setVisibleX(int visibleX
) {
180 fVisibleX
= visibleX
;
184 * Returns current yx value (view visible height - visible screen bounds).
186 * @return current yx value
188 protected int getYx() {
193 * Sets current yx value (view visible height - visible screen bounds).
198 protected void setYx(int yx
) {
203 * Returns the current xx value (view visible width - visible screen bounds)
205 * @return the current xx value
207 protected int getXx() {
212 * Sets the current xx value (view visible width - visible screen bounds)
215 * the current xx value
217 protected void setXx(int xx
) {
222 public int contentsToViewX(int x
) {
223 return fView
.contentsToViewX(x
);
227 public int contentsToViewY(int y
) {
228 return fView
.contentsToViewY(y
);
232 * Get code for drawings at given x and y position.
234 * @param x The x position
235 * @param y The y position.
236 * @return A code for top, bottom, right and left
238 protected byte code(int x
, int y
) {
240 fVisibleY
= fVisibleScreenBounds
;
241 fVisibleX
= fVisibleScreenBounds
;
242 yx
= fView
.getVisibleHeight() + fVisibleScreenBounds
;
243 xx
= fView
.getVisibleWidth() + fVisibleScreenBounds
;
246 } else if (y
< fVisibleY
) {
252 } else if (x
< fVisibleX
) {
259 public void drawLine(int x1
, int y1
, int x2
, int y2
) {
265 localX1
= Math
.round(localX1
* fView
.getZoomValue());
266 localY1
= Math
.round(localY1
* fView
.getZoomValue());
267 localX2
= Math
.round(localX2
* fView
.getZoomValue());
268 localY2
= Math
.round(localY2
* fView
.getZoomValue());
269 localX1
= fView
.contentsToViewX(localX1
);
270 localY1
= fView
.contentsToViewY(localY1
);
271 localX2
= fView
.contentsToViewX(localX2
);
272 localY2
= fView
.contentsToViewY(localY2
);
274 byte code1
= code(localX1
, localY1
);
275 byte code2
= code(localX2
, localY2
);
277 boolean draw
= false;
282 if (code1
== 0 && code2
== 0) {
285 } else if ((code1
& code2
) != 0) {
288 codex
= (code1
!= 0) ? code1
: code2
;
289 if ((codex
& 0x01) != 0) { // top
290 x
= localX1
+ ((localX2
- localX1
) * (yx
- localY1
)) / (localY2
- localY1
);
292 } else if ((codex
& 0x02) != 0) { // bottom
293 x
= localX1
+ ((localX2
- localX1
) * (fVisibleY
- localY1
)) / (localY2
- localY1
);
295 } else if ((codex
& 0x04) != 0) { // right
296 y
= localY1
+ ((localY2
- localY1
) * (xx
- localX1
)) / (localX2
- localX1
);
298 } else if ((codex
& 0x08) != 0) { // left
299 y
= localY1
+ ((localY2
- localY1
) * (fVisibleX
- localX1
)) / (localX2
- localX1
);
303 if (codex
== code1
) {
306 code1
= code(localX1
, localY1
);
310 code2
= code(localX2
, localY2
);
316 fContext
.drawLine(localX1
, localY1
, localX2
, localY2
);
321 public void drawRectangle(int x
, int y
, int width
, int height
) {
324 int localWidth
= width
;
325 int localHeight
= height
;
327 localX
= Math
.round(localX
* fView
.getZoomValue());
328 // Workaround to avoid problems for some special cases (not very nice)
329 if (localY
!= getContentsY()) {
330 localY
= Math
.round(localY
* fView
.getZoomValue());
331 localY
= fView
.contentsToViewY(localY
);
335 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
336 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
337 localX
= fView
.contentsToViewX(localX
);
339 if (localX
< -fVisibleScreenBounds
) {
340 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
341 localX
= -fVisibleScreenBounds
;
343 if (localY
< -fVisibleScreenBounds
) {
344 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
345 localY
= -fVisibleScreenBounds
;
347 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
348 localWidth
= -fVisibleScreenBounds
;
349 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
350 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
352 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
353 localHeight
= -fVisibleScreenBounds
;
354 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
355 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
357 fContext
.drawRectangle(localX
, localY
, localWidth
, localHeight
);
361 public void drawFocus(int x
, int y
, int width
, int height
) {
364 int localWidth
= width
;
365 int localHeight
= height
;
367 IColor bC
= getBackground();
368 IColor fC
= getForeground();
370 if (localWidth
< 0) {
371 localX
= localX
+ localWidth
;
372 localWidth
= -localWidth
;
375 if (localHeight
< 0) {
376 localY
= localY
+ localHeight
;
377 localHeight
= -localHeight
;
380 localX
= Math
.round(localX
* fView
.getZoomValue());
381 localY
= Math
.round(localY
* fView
.getZoomValue());
382 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
383 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
385 setForeground(SDViewPref
.getInstance().getForeGroundColorSelection());
386 setBackground(SDViewPref
.getInstance().getBackGroundColorSelection());
388 fContext
.drawFocus(fView
.contentsToViewX(localX
- 1), fView
.contentsToViewY(localY
- 1), localWidth
+ 3, localHeight
+ 3);
395 public void fillPolygon(int[] points
) {
396 int len
= (points
.length
/ 2) * 2;
397 int[] localPoint
= new int[len
];
398 for (int i
= 0; i
< len
; i
++) {
399 localPoint
[i
] = fView
.contentsToViewX(Math
.round(points
[i
] * fView
.getZoomValue()));
401 localPoint
[i
] = fView
.contentsToViewY(Math
.round(points
[i
] * fView
.getZoomValue()));
404 if (validatePolygonHeight(localPoint
) <= 0) {
408 fContext
.fillPolygon(localPoint
);
412 public void drawPolygon(int[] points
) {
413 int len
= (points
.length
/ 2) * 2;
414 int[] localPoint
= new int[len
];
415 for (int i
= 0; i
< len
; i
++) {
416 localPoint
[i
] = fView
.contentsToViewX(Math
.round(points
[i
] * fView
.getZoomValue()));
418 localPoint
[i
] = fView
.contentsToViewY(Math
.round(points
[i
] * fView
.getZoomValue()));
421 if (validatePolygonHeight(localPoint
) <= 0) {
425 fContext
.drawPolygon(localPoint
);
429 public void fillRectangle(int x
, int y
, int width
, int height
) {
432 int localWidth
= width
;
433 int localHeight
= height
;
435 localX
= Math
.round(localX
* fView
.getZoomValue());
436 // Workaround to avoid problems for some special cases (not very nice)
437 if (localY
!= getContentsY()) {
438 localY
= Math
.round(localY
* fView
.getZoomValue());
439 localY
= fView
.contentsToViewY(localY
) + 1;
443 localWidth
= Math
.round(localWidth
* fView
.getZoomValue()) - 1;
444 localHeight
= Math
.round(localHeight
* fView
.getZoomValue()) - 1;
445 localX
= fView
.contentsToViewX(localX
) + 1;
446 if (localX
< -fVisibleScreenBounds
) {
447 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
448 localX
= -fVisibleScreenBounds
;
450 if (localY
< -fVisibleScreenBounds
) {
451 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
452 localY
= -fVisibleScreenBounds
;
454 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
455 localWidth
= -fVisibleScreenBounds
;
456 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
457 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
459 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
460 localHeight
= -fVisibleScreenBounds
;
461 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
462 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
464 fContext
.fillRectangle(localX
, localY
, localWidth
, localHeight
);
468 public void fillGradientRectangle(int x
, int y
, int width
, int height
, boolean isVertical
) {
471 int localWidth
= width
;
472 int localHeight
= height
;
474 localX
= Math
.round(localX
* fView
.getZoomValue());
475 localY
= Math
.round(localY
* fView
.getZoomValue());
476 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
477 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
478 IColor tempColor
= fForeground
;
479 setForeground(fGradientColor
);
480 localX
= fView
.contentsToViewX(localX
);
481 localY
= fView
.contentsToViewY(localY
);
483 if (localX
< -fVisibleScreenBounds
) {
484 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
485 localX
= -fVisibleScreenBounds
;
487 if (localY
< -fVisibleScreenBounds
) {
488 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
489 localY
= -fVisibleScreenBounds
;
492 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
493 localWidth
= -fVisibleScreenBounds
;
494 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
495 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
497 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
498 localHeight
= -fVisibleScreenBounds
;
499 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
500 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
503 fContext
.fillGradientRectangle(localX
, localY
, localWidth
, localHeight
, isVertical
);
506 fContext
.fillGradientRectangle(localX
+ localWidth
, localY
, -localWidth
, localHeight
+ 1, isVertical
);
508 setForeground(tempColor
);
512 public int textExtent(String name
) {
513 return fContext
.textExtent(name
).x
;
517 public void drawText(String string
, int x
, int y
, boolean isTrans
) {
521 localX
= Math
.round(localX
* fView
.getZoomValue());
522 localY
= Math
.round(localY
* fView
.getZoomValue());
523 fContext
.drawText(string
, fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), isTrans
);
524 if (fDrawWithFocus
) {
525 Point r
= fContext
.textExtent(string
);
526 fContext
.drawFocus(localX
- 1, localY
- 1, r
.x
+ 2, r
.y
+ 2);
531 public void drawText(String string
, int x
, int y
) {
535 localX
= Math
.round(localX
* fView
.getZoomValue());
536 localY
= Math
.round(localY
* fView
.getZoomValue());
537 fContext
.drawText(string
, fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), true);
538 if (fDrawWithFocus
) {
539 Point r
= fContext
.textExtent(string
);
540 fContext
.drawFocus(localX
- 1, localY
- 1, r
.x
+ 2, r
.y
+ 2);
545 public void fillOval(int x
, int y
, int width
, int height
) {
548 int localWidth
= width
;
549 int localHeight
= height
;
551 localX
= Math
.round(localX
* fView
.getZoomValue());
552 localY
= Math
.round(localY
* fView
.getZoomValue());
553 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
554 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
555 fContext
.fillOval(fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), localWidth
, localHeight
);
559 public IColor
getBackground() {
560 if ((fBackground
!= null) && (fBackground
.getColor() instanceof Color
) && (!((Color
) (fBackground
.getColor())).isDisposed())) {
563 return ColorImpl
.getSystemColor(SWT
.COLOR_WHITE
);
567 public IColor
getForeground() {
568 if ((fForeground
!= null) && (fForeground
.getColor() instanceof Color
) && (!((Color
) (fForeground
.getColor())).isDisposed())) {
571 return ColorImpl
.getSystemColor(SWT
.COLOR_WHITE
);
575 public void setBackground(IColor color
) {
579 if (color
.getColor() instanceof Color
) {
580 fContext
.setBackground((Color
) color
.getColor());
586 public void setForeground(IColor color
) {
590 if (color
.getColor() instanceof Color
) {
591 Color c
= (Color
) color
.getColor();
592 if (!c
.isDisposed()) {
593 fContext
.setForeground(c
);
600 public void setGradientColor(IColor color
) {
604 if (color
.getColor() instanceof Color
) {
605 fGradientColor
= color
;
610 public void setLineWidth(int width
) {
611 if (fView
.isPrinting()) {
612 fContext
.setLineWidth(width
* 2);
615 fContext
.setLineWidth(width
);
620 public int getLineWidth() {
621 return fContext
.getLineWidth();
625 * Method to draw a text in rectangle. (Linux GTK Workaround)
627 * @param string The text to draw.
628 * @param x The x position.
629 * @param y The y position.
630 * @param isTransparent true for transparent else false
632 protected void localDrawText(String string
, int x
, int y
, boolean isTransparent
) {
633 Point r
= fContext
.textExtent(string
);
634 if (!isTransparent
) {
635 fContext
.fillRectangle(x
, y
, r
.x
, r
.y
);
637 fContext
.drawText(string
, x
, y
, isTransparent
);
638 if ((fDrawWithFocus
) && (string
.length() > 1)) {
639 fContext
.drawFocus(x
- 1, y
- 1, r
.x
+ 2, r
.y
+ 2);
644 public void drawTextTruncatedCentred(String name
, int xValue
, int yValue
, int width
, int height
, boolean trans
) {
647 int localWidth
= width
;
648 int localHeight
= height
;
650 Point tx
= fContext
.textExtent(name
);
651 localX
= Math
.round(localX
* fView
.getZoomValue());
653 // Workaround to avoid round problems for some special cases (not very nice)
654 if (localY
!= getContentsY()) {
655 localY
= Math
.round(localY
* fView
.getZoomValue());
656 y
= fView
.contentsToViewY(localY
);
658 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
659 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
660 int x
= fView
.contentsToViewX(localX
);
661 if (tx
.y
> localHeight
) {
665 // Adjust height and y
666 if (y
< -fVisibleScreenBounds
) {
667 localHeight
= localHeight
+ y
+ fVisibleScreenBounds
;
668 y
= -fVisibleScreenBounds
;
670 if ((localHeight
< -fVisibleScreenBounds
) && (y
+ localHeight
< -fVisibleScreenBounds
)) {
671 localHeight
= -fVisibleScreenBounds
;
672 } else if (localHeight
+ y
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
673 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- y
;
676 if (tx
.x
<= localWidth
) {
677 localDrawText(name
, x
+ 1 + (localWidth
- tx
.x
) / 2, y
+ 1 + (localHeight
- tx
.y
) / 2, trans
);
679 String nameToDisplay
= name
;
680 for (int i
= name
.length() - 1; i
>= 0 && fContext
.textExtent(nameToDisplay
).x
>= localWidth
; i
--) {
681 nameToDisplay
= name
.substring(0, i
);
684 for (int i
= 1; i
<= 3 && nameToDisplay
.length() - i
> 0; i
++) {
687 nameToDisplay
= nameToDisplay
.substring(0, nameToDisplay
.length() - dotCount
);
688 StringBuffer buf
= new StringBuffer(nameToDisplay
);
689 for (int i
= 0; i
< dotCount
; i
++) {
690 buf
.append("."); //$NON-NLS-1$
692 nameToDisplay
= buf
.toString();
693 localDrawText(nameToDisplay
, x
+ 1 + (localWidth
- fContext
.textExtent(nameToDisplay
).x
) / 2, y
+ 1 + (localHeight
- fContext
.textExtent(nameToDisplay
).y
) / 2, trans
);
698 public void drawTextTruncated(String name
, int xValue
, int yValue
, int width
, int height
, boolean trans
) {
701 int localWidth
= width
;
702 int localHeight
= height
;
704 localX
= Math
.round(localX
* fView
.getZoomValue());
705 localY
= Math
.round(localY
* fView
.getZoomValue());
706 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
707 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
708 int x
= fView
.contentsToViewX(localX
);
709 int y
= fView
.contentsToViewY(localY
);
710 if (fContext
.textExtent(name
).x
<= localWidth
) {
711 localDrawText(name
, x
+ 1, y
+ 1 + localHeight
, 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
);
723 StringBuffer buf
= new StringBuffer(nameToDisplay
);
725 for (int i
= 0; i
< dotCount
; i
++) {
726 buf
.append("."); //$NON-NLS-1$
728 nameToDisplay
= buf
.toString();
729 localDrawText(nameToDisplay
, x
+ 1, y
+ 1 + localHeight
, trans
);
734 public void drawImage(IImage image
, int xValue
, int yValue
, int maxWith
, int maxHeight
) {
739 if (image
!= null && image
.getImage() instanceof Image
) {
740 img
= (Image
) image
.getImage();
742 localX
= Math
.round(localX
* fView
.getZoomValue());
743 localY
= Math
.round(localY
* fView
.getZoomValue());
744 int x
= fView
.contentsToViewX(localX
);
745 int y
= fView
.contentsToViewY(localY
);
746 float tempZoom
= fView
.getZoomValue();
747 int width
= Math
.round(maxWith
* tempZoom
);
748 int height
= Math
.round(maxHeight
* tempZoom
);
749 fContext
.setBackground(fView
.getDisplay().getSystemColor(SWT
.COLOR_RED
));
750 fContext
.fillRectangle(x
, y
, width
, height
);
753 localX
= Math
.round(localX
* fView
.getZoomValue());
754 localY
= Math
.round(localY
* fView
.getZoomValue());
755 int x
= fView
.contentsToViewX(localX
);
756 int y
= fView
.contentsToViewY(localY
);
757 Rectangle b
= ((Image
) image
.getImage()).getBounds();
759 int height
= b
.height
;
760 if (width
> maxWith
) {
763 if (height
> maxHeight
) {
766 float tempZoom
= fView
.getZoomValue();
767 width
= Math
.round(width
* tempZoom
);
768 height
= Math
.round(height
* tempZoom
);
770 if (fView
.isPrinting() && width
> 0 && height
> 0) {
771 Image dbuffer
= new Image(fView
.getDisplay(), width
, height
);
772 GC tempgc
= new GC(dbuffer
);
773 tempgc
.drawImage(img
, 0, 0, b
.width
, b
.height
, 0, 0, width
, height
);
774 Image dbuffer2
= new Image(fView
.getDisplay(), dbuffer
.getImageData());
775 fContext
.drawImage(dbuffer2
, x
, y
);
780 fContext
.drawImage(img
, 0, 0, b
.width
, b
.height
, x
, y
, width
, height
);
785 public void drawArc(int x
, int y
, int width
, int height
, int startAngle
, int endAngle
) {
788 int localWidth
= width
;
789 int localHeight
= height
;
791 localX
= Math
.round(localX
* fView
.getZoomValue());
792 localY
= Math
.round(localY
* fView
.getZoomValue());
793 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
794 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
795 if (localWidth
== 0 || localHeight
== 0 || endAngle
== 0) {
798 fContext
.drawArc(fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), localWidth
, localHeight
, startAngle
, endAngle
);
802 public void setFont(IFont font
) {
803 if (font
.getFont() != null && ((Font
) font
.getFont()).getFontData().length
> 0) {
804 FontData fontData
= ((Font
) font
.getFont()).getFontData()[0];
805 if (SDViewPref
.getInstance().fontLinked() || fView
.isPrinting()) {
806 int h
= Math
.round(fontData
.getHeight() * fView
.getZoomValue());
808 fontData
.setHeight(h
);
811 if (fTempFont
!= null) {
814 fTempFont
= new Font(Display
.getCurrent(), fontData
);
815 fContext
.setFont(fTempFont
);
820 public int getFontHeight(IFont font
) {
821 if (font
.getFont() != null && (font
.getFont() instanceof Font
) && ((Font
) font
.getFont()).getFontData().length
> 0) {
822 Font toRestore
= fContext
.getFont();
823 fContext
.setFont((Font
) font
.getFont());
824 int height
= fContext
.textExtent("lp").y
;//$NON-NLS-1$
825 fContext
.setFont(toRestore
);
832 * Returns the current font height.
834 * @return the current font height.
836 protected int getCurrentFontHeight() {
837 return fContext
.textExtent("lp").y
; //$NON-NLS-1$
841 public int getFontWidth(IFont font
) {
842 if ((font
.getFont() != null) && (font
.getFont() instanceof Font
)) {
843 Font toRestore
= fContext
.getFont();
844 fContext
.setFont((Font
) font
.getFont());
845 int width
= fContext
.getFontMetrics().getAverageCharWidth();
846 fContext
.setFont(toRestore
);
853 * Disposes all created resources.
855 public void dispose() {
856 if (fTempFont
!= null) {
860 if (fContext
!= null) {
867 public float getZoom() {
869 return fView
.getZoomValue();
875 public int getLineDotStyle() {
880 public int getLineDashStyle() {
881 return SWT
.LINE_DASH
;
885 public int getLineSolidStyle() {
886 return SWT
.LINE_SOLID
;
890 public IColor
createColor(int r
, int g
, int b
) {
891 return new ColorImpl(Display
.getDefault(), r
, g
, b
);
895 public void setDrawTextWithFocusStyle(boolean focus
) {
896 fDrawWithFocus
= focus
;
900 * Returns the screen bounds.
902 * @return the screen bounds.
904 protected static int getVscreenBounds() {
905 return fVisibleScreenBounds
;
909 * Sets the visible screen bounds.
911 * @param vBounds the screen bounds.
913 protected static void setVscreenBounds(int vBounds
) {
914 fVisibleScreenBounds
= vBounds
;
918 * Returns the graphical context.
920 * @return the graphical context
922 protected GC
getGc() {
927 * Returns the SD widget.
929 * @return the SD widget
931 protected SDWidget
getSDWidget() {
936 * Returns the gradient color.
938 * @return the gradient color
940 protected IColor
setGradientColor() {
941 return fGradientColor
;
944 // ------------------------------------------------------------------------
946 // ------------------------------------------------------------------------
949 * Validates the polygon height
951 * @param localPoint array of points
954 private int validatePolygonHeight(int[] localPoint
) {
957 int min
= Integer
.MAX_VALUE
;
958 while (i
< localPoint
.length
) {
959 max
= Math
.abs(localPoint
[i
]) > Math
.abs(max
) ? localPoint
[i
] : max
;
960 min
= Math
.abs(localPoint
[i
]) < Math
.abs(min
) ? localPoint
[i
] : min
;
963 int height
= max
- min
;
964 if (min
< -fVisibleScreenBounds
) {
965 height
= height
+ min
+ fVisibleScreenBounds
;
966 min
= -fVisibleScreenBounds
;
968 if ((height
< -fVisibleScreenBounds
) && (min
+ height
< -fVisibleScreenBounds
)) {
969 height
= -fVisibleScreenBounds
;
970 } else if (height
+ min
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
971 height
= fView
.getVisibleHeight() + fVisibleScreenBounds
- min
;
This page took 0.054238 seconds and 5 git commands to generate.