1 /**********************************************************************
2 * Copyright (c) 2005, 2013 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.
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
151 protected int getVisibleY() {
156 * Sets the current visible y screen bounds.
159 * the current visible y screen bounds
162 protected void setVisibleY(int visibleY
) {
163 fVisibleY
= visibleY
;
167 * Returns the current visible x screen bound.
169 * @return the current visible x screen bound.
173 protected int getfVisibleX() {
178 * Sets the current visible x screen bound.
181 * the current visible x screen bound.
185 protected void setVisibleX(int visibleX
) {
186 fVisibleX
= visibleX
;
190 * Returns current yx value (view visible height - visible screen bounds).
192 * @return current yx value
195 protected int getYx() {
200 * Sets current yx value (view visible height - visible screen bounds).
206 protected void setYx(int yx
) {
211 * Returns the current xx value (view visible width - visible screen bounds)
213 * @return the current xx value
216 protected int getXx() {
221 * Sets the current xx value (view visible width - visible screen bounds)
224 * the current xx value
227 protected void setXx(int xx
) {
232 public int contentsToViewX(int x
) {
233 return fView
.contentsToViewX(x
);
237 public int contentsToViewY(int y
) {
238 return fView
.contentsToViewY(y
);
242 * Get code for drawings at given x and y position.
244 * @param x The x position
245 * @param y The y position.
246 * @return A code for top, bottom, right and left
248 protected byte code(int x
, int y
) {
250 fVisibleY
= fVisibleScreenBounds
;
251 fVisibleX
= fVisibleScreenBounds
;
252 yx
= fView
.getVisibleHeight() + fVisibleScreenBounds
;
253 xx
= fView
.getVisibleWidth() + fVisibleScreenBounds
;
256 } else if (y
< fVisibleY
) {
262 } else if (x
< fVisibleX
) {
269 public void drawLine(int x1
, int y1
, int x2
, int y2
) {
275 localX1
= Math
.round(localX1
* fView
.getZoomValue());
276 localY1
= Math
.round(localY1
* fView
.getZoomValue());
277 localX2
= Math
.round(localX2
* fView
.getZoomValue());
278 localY2
= Math
.round(localY2
* fView
.getZoomValue());
279 localX1
= fView
.contentsToViewX(localX1
);
280 localY1
= fView
.contentsToViewY(localY1
);
281 localX2
= fView
.contentsToViewX(localX2
);
282 localY2
= fView
.contentsToViewY(localY2
);
284 byte code1
= code(localX1
, localY1
);
285 byte code2
= code(localX2
, localY2
);
287 boolean draw
= false;
292 if (code1
== 0 && code2
== 0) {
295 } else if ((code1
& code2
) != 0) {
298 codex
= (code1
!= 0) ? code1
: code2
;
299 if ((codex
& 0x01) != 0) { // top
300 x
= localX1
+ ((localX2
- localX1
) * (yx
- localY1
)) / (localY2
- localY1
);
302 } else if ((codex
& 0x02) != 0) { // bottom
303 x
= localX1
+ ((localX2
- localX1
) * (fVisibleY
- localY1
)) / (localY2
- localY1
);
305 } else if ((codex
& 0x04) != 0) { // right
306 y
= localY1
+ ((localY2
- localY1
) * (xx
- localX1
)) / (localX2
- localX1
);
308 } else if ((codex
& 0x08) != 0) { // left
309 y
= localY1
+ ((localY2
- localY1
) * (fVisibleX
- localX1
)) / (localX2
- localX1
);
313 if (codex
== code1
) {
316 code1
= code(localX1
, localY1
);
320 code2
= code(localX2
, localY2
);
326 fContext
.drawLine(localX1
, localY1
, localX2
, localY2
);
331 public void drawRectangle(int x
, int y
, int width
, int height
) {
334 int localWidth
= width
;
335 int localHeight
= height
;
337 localX
= Math
.round(localX
* fView
.getZoomValue());
338 // Workaround to avoid problems for some special cases (not very nice)
339 if (localY
!= getContentsY()) {
340 localY
= Math
.round(localY
* fView
.getZoomValue());
341 localY
= fView
.contentsToViewY(localY
);
345 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
346 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
347 localX
= fView
.contentsToViewX(localX
);
349 if (localX
< -fVisibleScreenBounds
) {
350 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
351 localX
= -fVisibleScreenBounds
;
353 if (localY
< -fVisibleScreenBounds
) {
354 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
355 localY
= -fVisibleScreenBounds
;
357 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
358 localWidth
= -fVisibleScreenBounds
;
359 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
360 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
362 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
363 localHeight
= -fVisibleScreenBounds
;
364 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
365 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
367 fContext
.drawRectangle(localX
, localY
, localWidth
, localHeight
);
371 public void drawFocus(int x
, int y
, int width
, int height
) {
374 int localWidth
= width
;
375 int localHeight
= height
;
377 IColor bC
= getBackground();
378 IColor fC
= getForeground();
380 if (localWidth
< 0) {
381 localX
= localX
+ localWidth
;
382 localWidth
= -localWidth
;
385 if (localHeight
< 0) {
386 localY
= localY
+ localHeight
;
387 localHeight
= -localHeight
;
390 localX
= Math
.round(localX
* fView
.getZoomValue());
391 localY
= Math
.round(localY
* fView
.getZoomValue());
392 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
393 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
395 setForeground(SDViewPref
.getInstance().getForeGroundColorSelection());
396 setBackground(SDViewPref
.getInstance().getBackGroundColorSelection());
398 fContext
.drawFocus(fView
.contentsToViewX(localX
- 1), fView
.contentsToViewY(localY
- 1), localWidth
+ 3, localHeight
+ 3);
405 public void fillPolygon(int[] points
) {
406 int len
= (points
.length
/ 2) * 2;
407 int[] localPoint
= new int[len
];
408 for (int i
= 0; i
< len
; i
++) {
409 localPoint
[i
] = fView
.contentsToViewX(Math
.round(points
[i
] * fView
.getZoomValue()));
411 localPoint
[i
] = fView
.contentsToViewY(Math
.round(points
[i
] * fView
.getZoomValue()));
414 if (validatePolygonHeight(localPoint
) <= 0) {
418 fContext
.fillPolygon(localPoint
);
422 public void drawPolygon(int[] points
) {
423 int len
= (points
.length
/ 2) * 2;
424 int[] localPoint
= new int[len
];
425 for (int i
= 0; i
< len
; i
++) {
426 localPoint
[i
] = fView
.contentsToViewX(Math
.round(points
[i
] * fView
.getZoomValue()));
428 localPoint
[i
] = fView
.contentsToViewY(Math
.round(points
[i
] * fView
.getZoomValue()));
431 if (validatePolygonHeight(localPoint
) <= 0) {
435 fContext
.drawPolygon(localPoint
);
439 public void fillRectangle(int x
, int y
, int width
, int height
) {
442 int localWidth
= width
;
443 int localHeight
= height
;
445 localX
= Math
.round(localX
* fView
.getZoomValue());
446 // Workaround to avoid problems for some special cases (not very nice)
447 if (localY
!= getContentsY()) {
448 localY
= Math
.round(localY
* fView
.getZoomValue());
449 localY
= fView
.contentsToViewY(localY
) + 1;
453 localWidth
= Math
.round(localWidth
* fView
.getZoomValue()) - 1;
454 localHeight
= Math
.round(localHeight
* fView
.getZoomValue()) - 1;
455 localX
= fView
.contentsToViewX(localX
) + 1;
456 if (localX
< -fVisibleScreenBounds
) {
457 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
458 localX
= -fVisibleScreenBounds
;
460 if (localY
< -fVisibleScreenBounds
) {
461 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
462 localY
= -fVisibleScreenBounds
;
464 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
465 localWidth
= -fVisibleScreenBounds
;
466 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
467 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
469 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
470 localHeight
= -fVisibleScreenBounds
;
471 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
472 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
474 fContext
.fillRectangle(localX
, localY
, localWidth
, localHeight
);
478 public void fillGradientRectangle(int x
, int y
, int width
, int height
, boolean isVertical
) {
481 int localWidth
= width
;
482 int localHeight
= height
;
484 localX
= Math
.round(localX
* fView
.getZoomValue());
485 localY
= Math
.round(localY
* fView
.getZoomValue());
486 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
487 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
488 IColor tempColor
= fForeground
;
489 setForeground(fGradientColor
);
490 localX
= fView
.contentsToViewX(localX
);
491 localY
= fView
.contentsToViewY(localY
);
493 if (localX
< -fVisibleScreenBounds
) {
494 localWidth
= localWidth
+ localX
+ fVisibleScreenBounds
;
495 localX
= -fVisibleScreenBounds
;
497 if (localY
< -fVisibleScreenBounds
) {
498 localHeight
= localHeight
+ localY
+ fVisibleScreenBounds
;
499 localY
= -fVisibleScreenBounds
;
502 if ((localWidth
< -fVisibleScreenBounds
) && (localX
+ localWidth
< -fVisibleScreenBounds
)) {
503 localWidth
= -fVisibleScreenBounds
;
504 } else if (localWidth
+ localX
> fView
.getVisibleWidth() + fVisibleScreenBounds
) {
505 localWidth
= fView
.getVisibleWidth() + fVisibleScreenBounds
- localX
;
507 if ((localHeight
< -fVisibleScreenBounds
) && (localY
+ localHeight
< -fVisibleScreenBounds
)) {
508 localHeight
= -fVisibleScreenBounds
;
509 } else if (localHeight
+ localY
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
510 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- localY
;
513 fContext
.fillGradientRectangle(localX
, localY
, localWidth
, localHeight
, isVertical
);
516 fContext
.fillGradientRectangle(localX
+ localWidth
, localY
, -localWidth
, localHeight
+ 1, isVertical
);
518 setForeground(tempColor
);
522 public int textExtent(String name
) {
523 return fContext
.textExtent(name
).x
;
527 public void drawText(String string
, int x
, int y
, boolean isTrans
) {
531 localX
= Math
.round(localX
* fView
.getZoomValue());
532 localY
= Math
.round(localY
* fView
.getZoomValue());
533 fContext
.drawText(string
, fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), isTrans
);
534 if (fDrawWithFocus
) {
535 Point r
= fContext
.textExtent(string
);
536 fContext
.drawFocus(localX
- 1, localY
- 1, r
.x
+ 2, r
.y
+ 2);
541 public void drawText(String string
, int x
, int y
) {
545 localX
= Math
.round(localX
* fView
.getZoomValue());
546 localY
= Math
.round(localY
* fView
.getZoomValue());
547 fContext
.drawText(string
, fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), true);
548 if (fDrawWithFocus
) {
549 Point r
= fContext
.textExtent(string
);
550 fContext
.drawFocus(localX
- 1, localY
- 1, r
.x
+ 2, r
.y
+ 2);
555 public void fillOval(int x
, int y
, int width
, int height
) {
558 int localWidth
= width
;
559 int localHeight
= height
;
561 localX
= Math
.round(localX
* fView
.getZoomValue());
562 localY
= Math
.round(localY
* fView
.getZoomValue());
563 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
564 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
565 fContext
.fillOval(fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), localWidth
, localHeight
);
569 public IColor
getBackground() {
570 if ((fBackground
!= null) && (fBackground
.getColor() instanceof Color
) && (!((Color
) (fBackground
.getColor())).isDisposed())) {
573 return ColorImpl
.getSystemColor(SWT
.COLOR_WHITE
);
577 public IColor
getForeground() {
578 if ((fForeground
!= null) && (fForeground
.getColor() instanceof Color
) && (!((Color
) (fForeground
.getColor())).isDisposed())) {
581 return ColorImpl
.getSystemColor(SWT
.COLOR_WHITE
);
585 public void setBackground(IColor color
) {
589 if (color
.getColor() instanceof Color
) {
590 fContext
.setBackground((Color
) color
.getColor());
596 public void setForeground(IColor color
) {
600 if (color
.getColor() instanceof Color
) {
601 Color c
= (Color
) color
.getColor();
602 if (!c
.isDisposed()) {
603 fContext
.setForeground(c
);
610 public void setGradientColor(IColor color
) {
614 if (color
.getColor() instanceof Color
) {
615 fGradientColor
= color
;
620 public void setLineWidth(int width
) {
621 if (fView
.isPrinting()) {
622 fContext
.setLineWidth(width
* 2);
625 fContext
.setLineWidth(width
);
630 public int getLineWidth() {
631 return fContext
.getLineWidth();
635 * Method to draw a text in rectangle. (Linux GTK Workaround)
637 * @param string The text to draw.
638 * @param x The x position.
639 * @param y The y position.
640 * @param isTransparent true for transparent else false
642 protected void localDrawText(String string
, int x
, int y
, boolean isTransparent
) {
643 Point r
= fContext
.textExtent(string
);
644 if (!isTransparent
) {
645 fContext
.fillRectangle(x
, y
, r
.x
, r
.y
);
647 fContext
.drawText(string
, x
, y
, isTransparent
);
648 if ((fDrawWithFocus
) && (string
.length() > 1)) {
649 fContext
.drawFocus(x
- 1, y
- 1, r
.x
+ 2, r
.y
+ 2);
654 public void drawTextTruncatedCentred(String name
, int xValue
, int yValue
, int width
, int height
, boolean trans
) {
657 int localWidth
= width
;
658 int localHeight
= height
;
660 Point tx
= fContext
.textExtent(name
);
661 localX
= Math
.round(localX
* fView
.getZoomValue());
663 // Workaround to avoid round problems for some special cases (not very nice)
664 if (localY
!= getContentsY()) {
665 localY
= Math
.round(localY
* fView
.getZoomValue());
666 y
= fView
.contentsToViewY(localY
);
668 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
669 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
670 int x
= fView
.contentsToViewX(localX
);
671 if (tx
.y
> localHeight
) {
675 // Adjust height and y
676 if (y
< -fVisibleScreenBounds
) {
677 localHeight
= localHeight
+ y
+ fVisibleScreenBounds
;
678 y
= -fVisibleScreenBounds
;
680 if ((localHeight
< -fVisibleScreenBounds
) && (y
+ localHeight
< -fVisibleScreenBounds
)) {
681 localHeight
= -fVisibleScreenBounds
;
682 } else if (localHeight
+ y
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
683 localHeight
= fView
.getVisibleHeight() + fVisibleScreenBounds
- y
;
686 if (tx
.x
<= localWidth
) {
687 localDrawText(name
, x
+ 1 + (localWidth
- tx
.x
) / 2, y
+ 1 + (localHeight
- tx
.y
) / 2, trans
);
689 String nameToDisplay
= name
;
690 for (int i
= name
.length() - 1; i
>= 0 && fContext
.textExtent(nameToDisplay
).x
>= localWidth
; i
--) {
691 nameToDisplay
= name
.substring(0, i
);
694 for (int i
= 1; i
<= 3 && nameToDisplay
.length() - i
> 0; i
++) {
697 nameToDisplay
= nameToDisplay
.substring(0, nameToDisplay
.length() - dotCount
);
698 StringBuffer buf
= new StringBuffer(nameToDisplay
);
699 for (int i
= 0; i
< dotCount
; i
++) {
700 buf
.append("."); //$NON-NLS-1$
702 nameToDisplay
= buf
.toString();
703 localDrawText(nameToDisplay
, x
+ 1 + (localWidth
- fContext
.textExtent(nameToDisplay
).x
) / 2, y
+ 1 + (localHeight
- fContext
.textExtent(nameToDisplay
).y
) / 2, trans
);
708 public void drawTextTruncated(String name
, int xValue
, int yValue
, int width
, int height
, boolean trans
) {
711 int localWidth
= width
;
712 int localHeight
= height
;
714 localX
= Math
.round(localX
* fView
.getZoomValue());
715 localY
= Math
.round(localY
* fView
.getZoomValue());
716 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
717 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
718 int x
= fView
.contentsToViewX(localX
);
719 int y
= fView
.contentsToViewY(localY
);
720 if (fContext
.textExtent(name
).x
<= localWidth
) {
721 localDrawText(name
, x
+ 1, y
+ 1 + localHeight
, trans
);
723 String nameToDisplay
= name
;
724 for (int i
= name
.length() - 1; i
>= 0 && fContext
.textExtent(nameToDisplay
).x
>= localWidth
; i
--) {
725 nameToDisplay
= name
.substring(0, i
);
728 for (int i
= 1; i
<= 3 && nameToDisplay
.length() - i
> 0; i
++) {
731 nameToDisplay
= nameToDisplay
.substring(0, nameToDisplay
.length() - dotCount
);
733 StringBuffer buf
= new StringBuffer(nameToDisplay
);
735 for (int i
= 0; i
< dotCount
; i
++) {
736 buf
.append("."); //$NON-NLS-1$
738 nameToDisplay
= buf
.toString();
739 localDrawText(nameToDisplay
, x
+ 1, y
+ 1 + localHeight
, trans
);
744 public void drawImage(IImage image
, int xValue
, int yValue
, int maxWith
, int maxHeight
) {
749 if (image
!= null && image
.getImage() instanceof Image
) {
750 img
= (Image
) image
.getImage();
752 localX
= Math
.round(localX
* fView
.getZoomValue());
753 localY
= Math
.round(localY
* fView
.getZoomValue());
754 int x
= fView
.contentsToViewX(localX
);
755 int y
= fView
.contentsToViewY(localY
);
756 float tempZoom
= fView
.getZoomValue();
757 int width
= Math
.round(maxWith
* tempZoom
);
758 int height
= Math
.round(maxHeight
* tempZoom
);
759 fContext
.setBackground(fView
.getDisplay().getSystemColor(SWT
.COLOR_RED
));
760 fContext
.fillRectangle(x
, y
, width
, height
);
763 localX
= Math
.round(localX
* fView
.getZoomValue());
764 localY
= Math
.round(localY
* fView
.getZoomValue());
765 int x
= fView
.contentsToViewX(localX
);
766 int y
= fView
.contentsToViewY(localY
);
767 Rectangle b
= ((Image
) image
.getImage()).getBounds();
769 int height
= b
.height
;
770 if (width
> maxWith
) {
773 if (height
> maxHeight
) {
776 float tempZoom
= fView
.getZoomValue();
777 width
= Math
.round(width
* tempZoom
);
778 height
= Math
.round(height
* tempZoom
);
780 if (fView
.isPrinting() && width
> 0 && height
> 0) {
781 Image dbuffer
= new Image(fView
.getDisplay(), width
, height
);
782 GC tempgc
= new GC(dbuffer
);
783 tempgc
.drawImage(img
, 0, 0, b
.width
, b
.height
, 0, 0, width
, height
);
784 Image dbuffer2
= new Image(fView
.getDisplay(), dbuffer
.getImageData());
785 fContext
.drawImage(dbuffer2
, x
, y
);
790 fContext
.drawImage(img
, 0, 0, b
.width
, b
.height
, x
, y
, width
, height
);
795 public void drawArc(int x
, int y
, int width
, int height
, int startAngle
, int endAngle
) {
798 int localWidth
= width
;
799 int localHeight
= height
;
801 localX
= Math
.round(localX
* fView
.getZoomValue());
802 localY
= Math
.round(localY
* fView
.getZoomValue());
803 localWidth
= Math
.round(localWidth
* fView
.getZoomValue());
804 localHeight
= Math
.round(localHeight
* fView
.getZoomValue());
805 if (localWidth
== 0 || localHeight
== 0 || endAngle
== 0) {
808 fContext
.drawArc(fView
.contentsToViewX(localX
), fView
.contentsToViewY(localY
), localWidth
, localHeight
, startAngle
, endAngle
);
812 public void setFont(IFont font
) {
813 if (font
.getFont() != null && ((Font
) font
.getFont()).getFontData().length
> 0) {
814 FontData fontData
= ((Font
) font
.getFont()).getFontData()[0];
815 if (SDViewPref
.getInstance().fontLinked() || fView
.isPrinting()) {
816 int h
= Math
.round(fontData
.getHeight() * fView
.getZoomValue());
818 fontData
.setHeight(h
);
821 if (fTempFont
!= null) {
824 fTempFont
= new Font(Display
.getCurrent(), fontData
);
825 fContext
.setFont(fTempFont
);
830 public int getFontHeight(IFont font
) {
831 if (font
.getFont() != null && (font
.getFont() instanceof Font
) && ((Font
) font
.getFont()).getFontData().length
> 0) {
832 Font toRestore
= fContext
.getFont();
833 fContext
.setFont((Font
) font
.getFont());
834 int height
= fContext
.textExtent("lp").y
;//$NON-NLS-1$
835 fContext
.setFont(toRestore
);
842 * Returns the current font height.
844 * @return the current font height.
846 protected int getCurrentFontHeight() {
847 return fContext
.textExtent("lp").y
; //$NON-NLS-1$
851 public int getFontWidth(IFont font
) {
852 if ((font
.getFont() != null) && (font
.getFont() instanceof Font
)) {
853 Font toRestore
= fContext
.getFont();
854 fContext
.setFont((Font
) font
.getFont());
855 int width
= fContext
.getFontMetrics().getAverageCharWidth();
856 fContext
.setFont(toRestore
);
863 * Disposes all created resources.
865 public void dispose() {
866 if (fTempFont
!= null) {
870 if (fContext
!= null) {
877 public float getZoom() {
879 return fView
.getZoomValue();
885 public int getLineDotStyle() {
890 public int getLineDashStyle() {
891 return SWT
.LINE_DASH
;
895 public int getLineSolidStyle() {
896 return SWT
.LINE_SOLID
;
900 public IColor
createColor(int r
, int g
, int b
) {
901 return new ColorImpl(Display
.getDefault(), r
, g
, b
);
905 public void setDrawTextWithFocusStyle(boolean focus
) {
906 fDrawWithFocus
= focus
;
910 * Returns the screen bounds.
912 * @return the screen bounds.
914 protected static int getVscreenBounds() {
915 return fVisibleScreenBounds
;
919 * Sets the visible screen bounds.
921 * @param vBounds the screen bounds.
923 protected static void setVscreenBounds(int vBounds
) {
924 fVisibleScreenBounds
= vBounds
;
928 * Returns the graphical context.
930 * @return the graphical context
933 protected GC
getGc() {
938 * Returns the SD widget.
940 * @return the SD widget
943 protected SDWidget
getSDWidget() {
948 * Returns the gradient color.
950 * @return the gradient color
953 protected IColor
setGradientColor() {
954 return fGradientColor
;
957 // ------------------------------------------------------------------------
959 // ------------------------------------------------------------------------
962 * Validates the polygon height
964 * @param localPoint array of points
967 private int validatePolygonHeight(int[] localPoint
) {
970 int min
= Integer
.MAX_VALUE
;
971 while (i
< localPoint
.length
) {
972 max
= Math
.abs(localPoint
[i
]) > Math
.abs(max
) ? localPoint
[i
] : max
;
973 min
= Math
.abs(localPoint
[i
]) < Math
.abs(min
) ? localPoint
[i
] : min
;
976 int height
= max
- min
;
977 if (min
< -fVisibleScreenBounds
) {
978 height
= height
+ min
+ fVisibleScreenBounds
;
979 min
= -fVisibleScreenBounds
;
981 if ((height
< -fVisibleScreenBounds
) && (min
+ height
< -fVisibleScreenBounds
)) {
982 height
= -fVisibleScreenBounds
;
983 } else if (height
+ min
> fView
.getVisibleHeight() + fVisibleScreenBounds
) {
984 height
= fView
.getVisibleHeight() + fVisibleScreenBounds
- min
;
This page took 0.054221 seconds and 5 git commands to generate.