Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/ControlGC.java214
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/DeviceGC.java153
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GC.java309
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GCDelegate.java61
-rw-r--r--bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/graphics/GCOperation.java78
-rw-r--r--tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java6
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java2
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/ControlGC_Test.java583
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/DeviceGC_Test.java99
-rw-r--r--tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java706
10 files changed, 1278 insertions, 933 deletions
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/ControlGC.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/ControlGC.java
new file mode 100644
index 0000000000..759090f37d
--- /dev/null
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/ControlGC.java
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Rüdiger Herrmann and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Rüdiger Herrmann - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.graphics;
+
+import org.eclipse.rwt.graphics.Graphics;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.internal.graphics.*;
+import org.eclipse.swt.internal.graphics.GCOperation.DrawArc;
+import org.eclipse.swt.internal.graphics.GCOperation.DrawImage;
+import org.eclipse.swt.internal.graphics.GCOperation.DrawLine;
+import org.eclipse.swt.internal.graphics.GCOperation.DrawPoint;
+import org.eclipse.swt.internal.graphics.GCOperation.DrawPolyline;
+import org.eclipse.swt.internal.graphics.GCOperation.DrawRectangle;
+import org.eclipse.swt.internal.graphics.GCOperation.DrawRoundRectangle;
+import org.eclipse.swt.internal.graphics.GCOperation.DrawText;
+import org.eclipse.swt.internal.graphics.GCOperation.FillGradientRectangle;
+import org.eclipse.swt.internal.graphics.GCOperation.SetFont;
+import org.eclipse.swt.internal.graphics.GCOperation.SetProperty;
+import org.eclipse.swt.widgets.Control;
+
+
+class ControlGC extends GCDelegate {
+ private final Control control;
+ private Color background;
+ private Color foreground;
+ private Font font;
+ private int alpha;
+ private int lineWidth;
+ private int lineCap;
+ private int lineJoin;
+
+ ControlGC( final Control control ) {
+ this.control = control;
+ this.background = control.getBackground();
+ this.foreground = control.getForeground();
+ this.font = control.getFont();
+ this.alpha = 255;
+ this.lineWidth = 0;
+ this.lineCap = SWT.CAP_FLAT;
+ this.lineJoin = SWT.JOIN_MITER;
+ }
+
+ void setBackground( final Color color ) {
+ background = color;
+ GCOperation operation = new SetProperty( SetProperty.BACKGROUND, color );
+ addGCOperation( operation );
+ }
+
+ Color getBackground() {
+ return background;
+ }
+
+ void setForeground( final Color color ) {
+ foreground = color;
+ GCOperation operation = new SetProperty( SetProperty.FOREGROUND, color );
+ addGCOperation( operation );
+ }
+
+ Color getForeground() {
+ return foreground;
+ }
+
+ void setFont( final Font font ) {
+ this.font = font;
+ GCOperation operation = new SetFont( copyFont( font ) );
+ addGCOperation( operation );
+ }
+
+ Font getFont() {
+ return font;
+ }
+
+ Font getDefaultFont() {
+ return control.getDisplay().getSystemFont();
+ }
+
+ void setAlpha( final int alpha ) {
+ this.alpha = alpha;
+ GCOperation operation = new SetProperty( SetProperty.ALPHA, alpha );
+ addGCOperation( operation );
+ }
+
+ int getAlpha() {
+ return alpha;
+ }
+
+ void setLineWidth( final int lineWidth ) {
+ this.lineWidth = lineWidth;
+ GCOperation operation
+ = new SetProperty( SetProperty.LINE_WIDTH, lineWidth );
+ addGCOperation( operation );
+ }
+
+ int getLineWidth() {
+ return lineWidth;
+ }
+
+ void setLineCap( final int lineCap ) {
+ this.lineCap = lineCap;
+ GCOperation operation = new SetProperty( SetProperty.LINE_CAP, lineCap );
+ addGCOperation( operation );
+ }
+
+ int getLineCap() {
+ return lineCap;
+ }
+
+ void setLineJoin( final int lineJoin ) {
+ this.lineJoin = lineJoin;
+ GCOperation operation = new SetProperty( SetProperty.LINE_JOIN, lineJoin );
+ addGCOperation( operation );
+ }
+
+ int getLineJoin() {
+ return lineJoin;
+ }
+
+ Rectangle getClipping() {
+ return control.getBounds();
+ }
+
+ Point stringExtent( String string ) {
+ return Graphics.stringExtent( font, string );
+ }
+
+ Point textExtent( String string, int wrapWidth ) {
+ return Graphics.textExtent( font, string, wrapWidth );
+ }
+
+ void drawPoint( final int x, final int y ) {
+ GCOperation operation = new DrawPoint( x, y );
+ addGCOperation( operation );
+ }
+
+ void drawLine( final int x1, final int y1, final int x2, final int y2 ) {
+ GCOperation operation = new DrawLine( x1, y1, x2, y2 );
+ addGCOperation( operation );
+ }
+
+ void drawPolyline( int[] pointArray, boolean close, boolean fill ) {
+ DrawPolyline operation = new DrawPolyline( pointArray, close, fill );
+ addGCOperation( operation );
+ }
+
+ void drawRectangle( final Rectangle bounds, final boolean fill ) {
+ GCOperation operation = new DrawRectangle( bounds, fill );
+ addGCOperation( operation );
+ }
+
+ void drawRoundRectangle( final Rectangle bounds,
+ final int arcWidth,
+ final int arcHeight,
+ final boolean fill )
+ {
+ GCOperation operation
+ = new DrawRoundRectangle( bounds, arcWidth, arcHeight, fill );
+ addGCOperation( operation );
+ }
+
+ void fillGradientRectangle( final Rectangle bounds, final boolean vertical ) {
+ GCOperation operation = new FillGradientRectangle( bounds, vertical );
+ addGCOperation( operation );
+ }
+
+ void drawArc( final Rectangle bounds,
+ final int startAngle,
+ final int arcAngle,
+ final boolean fill )
+ {
+ GCOperation operation = new DrawArc( bounds, startAngle, arcAngle, fill );
+ addGCOperation( operation );
+ }
+
+ void drawImage( final Image image,
+ final Rectangle src,
+ final Rectangle dest,
+ final boolean simple )
+ {
+ GCOperation operation = new DrawImage( image, src, dest, simple );
+ addGCOperation( operation );
+ }
+
+ void drawText( final String string,
+ final int x,
+ final int y,
+ final int flags )
+ {
+ GCOperation operation = new DrawText( string, x, y, flags );
+ addGCOperation( operation );
+ }
+
+ GCAdapter getGCAdapter() {
+ return ( GCAdapter )control.getAdapter( IGCAdapter.class );
+ }
+
+ private void addGCOperation( final GCOperation operation ) {
+ GCAdapter adapter = getGCAdapter();
+ if( adapter != null ) {
+ adapter.addGCOperation( operation );
+ }
+ }
+
+ private Font copyFont( final Font font ) {
+ FontData[] fontData = font.getFontData();
+ return new Font( control.getDisplay(), fontData );
+ }
+}
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/DeviceGC.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/DeviceGC.java
new file mode 100644
index 0000000000..c9f30bcdea
--- /dev/null
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/DeviceGC.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Rüdiger Herrmann and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Rüdiger Herrmann - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.graphics;
+
+import org.eclipse.rwt.graphics.Graphics;
+import org.eclipse.swt.SWT;
+
+
+class DeviceGC extends GCDelegate {
+ private final Device device;
+ private Color background;
+ private Color foreground;
+ private Font font;
+ private int alpha;
+ private int lineWidth;
+ private int lineCap;
+ private int lineJoin;
+
+ DeviceGC( final Device device ) {
+ this.device = device;
+ this.background = device.getSystemColor( SWT.COLOR_WHITE );
+ this.foreground = device.getSystemColor( SWT.COLOR_BLACK );
+ this.font = device.getSystemFont();
+ this.alpha = 255;
+ this.lineWidth = 0;
+ this.lineCap = SWT.CAP_FLAT;
+ this.lineJoin = SWT.JOIN_MITER;
+ }
+
+ void setBackground( final Color color ) {
+ background = color;
+ }
+
+ Color getBackground() {
+ return background;
+ }
+
+ void setForeground( final Color color ) {
+ foreground = color;
+ }
+
+ Color getForeground() {
+ return foreground;
+ }
+
+ void setFont( final Font font ) {
+ this.font = font;
+ }
+
+ Font getFont() {
+ return font;
+ }
+
+ Font getDefaultFont() {
+ return device.getSystemFont();
+ }
+
+ void setAlpha( final int alpha ) {
+ this.alpha = alpha;
+ }
+
+ int getAlpha() {
+ return alpha;
+ }
+
+ void setLineWidth( final int lineWidth ) {
+ this.lineWidth = lineWidth;
+ }
+
+ int getLineWidth() {
+ return lineWidth;
+ }
+
+ void setLineCap( final int lineCap ) {
+ this.lineCap = lineCap;
+ }
+
+ int getLineCap() {
+ return lineCap;
+ }
+
+ void setLineJoin( final int lineJoin ) {
+ this.lineJoin = lineJoin;
+ }
+
+ int getLineJoin() {
+ return lineJoin;
+ }
+
+ Rectangle getClipping() {
+ return device.getBounds();
+ }
+
+ Point stringExtent( final String string ) {
+ return Graphics.stringExtent( font, string );
+ }
+
+ Point textExtent( final String string, final int wrapWidth ) {
+ return Graphics.textExtent( font, string, wrapWidth );
+ }
+
+ void drawPoint( final int x, final int y ) {
+ }
+
+ void drawLine( final int x1, final int y1, final int x2, final int y2 ) {
+ }
+
+ void drawPolyline( final int[] pointArray,
+ final boolean close,
+ final boolean fill ) {
+ }
+
+ void drawRectangle( final Rectangle bounds, final boolean fill ) {
+ }
+
+ void drawRoundRectangle( final Rectangle bounds,
+ final int arcWidth,
+ final int arcHeight,
+ final boolean fill )
+ {
+ }
+
+ void fillGradientRectangle( final Rectangle bounds, final boolean vertical ) {
+ }
+
+ void drawArc( final Rectangle boundsx,
+ final int startAngle,
+ final int arcAngle,
+ final boolean fill )
+ {
+ }
+
+ void drawImage( final Image image,
+ final Rectangle src,
+ final Rectangle dest,
+ final boolean simple )
+ {
+ }
+
+ void drawText( final String string,
+ final int x,
+ final int y,
+ final int flags )
+ {
+ }
+}
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GC.java
index 85e7b11b5f..d2a0440157 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GC.java
@@ -9,12 +9,8 @@
******************************************************************************/
package org.eclipse.swt.graphics;
-import org.eclipse.rwt.graphics.Graphics;
import org.eclipse.swt.*;
-import org.eclipse.swt.internal.graphics.*;
-import org.eclipse.swt.internal.graphics.GCOperation.*;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
/**
* Class <code>GC</code> is provided to ease single-sourcing SWT and RWT code.
@@ -66,17 +62,8 @@ import org.eclipse.swt.widgets.Display;
* -->
* @since 1.3
*/
-
public class GC extends Resource {
- private final Control control;
- private Font font;
- private Color background;
- private Color foreground;
- private int alpha;
- private int lineWidth;
- private int lineCap;
- private int lineJoin;
- private int style;
+ private final GCDelegate delegate;
/**
* Constructs a new instance of this class which has been
@@ -134,19 +121,7 @@ public class GC extends Resource {
if( drawable == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
- // Assume that Drawable is either a Control or a Device
- if( drawable instanceof Control ) {
- control = ( Control )drawable;
- } else {
- control = null;
- }
- this.style = checkStyle( style );
- font = determineFont( drawable );
- background = determineBackground( drawable );
- foreground = determineForeground( drawable );
- alpha = 255;
- lineCap = SWT.CAP_FLAT;
- lineJoin = SWT.JOIN_MITER;
+ delegate = determineDelegate( drawable );
}
/**
@@ -169,13 +144,11 @@ public class GC extends Resource {
if( font != null && font.isDisposed() ) {
SWT.error( SWT.ERROR_INVALID_ARGUMENT );
}
- Font newFont = font != null ? font : getDevice().getSystemFont();
- if( !newFont.equals( this.font ) ) {
- this.font = newFont;
- SetFont operation
- = new SetFont( new Font( getDevice(), newFont.getFontData() ) );
- addGCOperation( operation );
+ Font newFont = font != null ? font : delegate.getDefaultFont();
+ if( !newFont.equals( delegate.getFont() ) ) {
+ delegate.setFont( newFont );
}
+
}
/**
@@ -190,7 +163,7 @@ public class GC extends Resource {
*/
public Font getFont() {
checkDisposed();
- return font;
+ return delegate.getFont();
}
/**
@@ -211,7 +184,7 @@ public class GC extends Resource {
*/
public int getCharWidth( final char ch ) {
checkDisposed();
- return Graphics.stringExtent( font, Character.toString( ch ) ).x;
+ return delegate.stringExtent( Character.toString( ch ) ).x;
}
/**
@@ -234,11 +207,11 @@ public class GC extends Resource {
* </ul>
*/
public Point stringExtent( final String string ) {
+ checkDisposed();
if( string == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
- checkDisposed();
- return Graphics.stringExtent( font, string );
+ return delegate.stringExtent( string );
}
/**
@@ -261,11 +234,11 @@ public class GC extends Resource {
* </ul>
*/
public Point textExtent( final String string ) {
+ checkDisposed();
if( string == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
- checkDisposed();
- return Graphics.textExtent( font, string, 0 );
+ return delegate.textExtent( string, 0 );
}
/**
@@ -281,7 +254,7 @@ public class GC extends Resource {
*/
public FontMetrics getFontMetrics() {
checkDisposed();
- return new FontMetrics( font );
+ return new FontMetrics( delegate.getFont() );
}
/**
@@ -307,11 +280,8 @@ public class GC extends Resource {
if( color.isDisposed() ) {
SWT.error( SWT.ERROR_INVALID_ARGUMENT );
}
- if( !color.equals( background ) ) {
- background = color;
- SetProperty operation
- = new SetProperty( SetProperty.BACKGROUND, background );
- addGCOperation( operation );
+ if( !delegate.getBackground().equals( color ) ) {
+ delegate.setBackground( color );
}
}
@@ -326,7 +296,7 @@ public class GC extends Resource {
*/
public Color getBackground() {
checkDisposed();
- return background;
+ return delegate.getBackground();
}
/**
@@ -351,11 +321,8 @@ public class GC extends Resource {
if( color.isDisposed() ) {
SWT.error( SWT.ERROR_INVALID_ARGUMENT );
}
- if( !color.equals( foreground ) ) {
- foreground = color;
- SetProperty operation
- = new SetProperty( SetProperty.FOREGROUND, foreground );
- addGCOperation( operation );
+ if( !delegate.getForeground().equals( color ) ) {
+ delegate.setForeground( color );
}
}
@@ -370,7 +337,7 @@ public class GC extends Resource {
*/
public Color getForeground() {
checkDisposed();
- return foreground;
+ return delegate.getForeground();
}
/**
@@ -387,13 +354,7 @@ public class GC extends Resource {
*/
public Rectangle getClipping() {
checkDisposed();
- Rectangle result;
- if( control != null ) {
- result = control.getBounds();
- } else {
- result = device.getBounds();
- }
- return result;
+ return delegate.getClipping();
}
/**
@@ -413,11 +374,8 @@ public class GC extends Resource {
*/
public void setAlpha( final int alpha ) {
checkDisposed();
- if( alpha >= 0 && alpha <= 255 && this.alpha != alpha ) {
- this.alpha = alpha;
- SetProperty operation
- = new SetProperty( SetProperty.ALPHA, new Integer( alpha ) );
- addGCOperation( operation );
+ if( alpha >= 0 && alpha <= 255 && delegate.getAlpha() != alpha ) {
+ delegate.setAlpha( alpha );
}
}
@@ -433,7 +391,7 @@ public class GC extends Resource {
*/
public int getAlpha() {
checkDisposed();
- return alpha;
+ return delegate.getAlpha();
}
/**
@@ -450,11 +408,8 @@ public class GC extends Resource {
*/
public void setLineWidth( final int lineWidth ) {
checkDisposed();
- if( this.lineWidth != lineWidth ) {
- this.lineWidth = lineWidth;
- SetProperty operation
- = new SetProperty( SetProperty.LINE_WIDTH, new Integer( lineWidth ) );
- addGCOperation( operation );
+ if( delegate.getLineWidth() != lineWidth ) {
+ delegate.setLineWidth( lineWidth );
}
}
@@ -472,7 +427,7 @@ public class GC extends Resource {
*/
public int getLineWidth() {
checkDisposed();
- return lineWidth;
+ return delegate.getLineWidth();
}
/**
@@ -491,7 +446,7 @@ public class GC extends Resource {
*/
public void setLineCap( final int lineCap ) {
checkDisposed();
- if( this.lineCap != lineCap ) {
+ if( delegate.getLineCap() != lineCap ) {
switch( lineCap ) {
case SWT.CAP_ROUND:
case SWT.CAP_FLAT:
@@ -500,10 +455,7 @@ public class GC extends Resource {
default:
SWT.error( SWT.ERROR_INVALID_ARGUMENT );
}
- this.lineCap = lineCap;
- SetProperty operation
- = new SetProperty( SetProperty.LINE_CAP, new Integer( lineCap ) );
- addGCOperation( operation );
+ delegate.setLineCap( lineCap );
}
}
@@ -520,7 +472,7 @@ public class GC extends Resource {
*/
public int getLineCap() {
checkDisposed();
- return lineCap;
+ return delegate.getLineCap();
}
/**
@@ -539,7 +491,7 @@ public class GC extends Resource {
*/
public void setLineJoin( final int lineJoin ) {
checkDisposed();
- if( this.lineJoin != lineJoin ) {
+ if( delegate.getLineJoin() != lineJoin ) {
switch( lineJoin ) {
case SWT.JOIN_MITER:
case SWT.JOIN_ROUND:
@@ -548,10 +500,7 @@ public class GC extends Resource {
default:
SWT.error( SWT.ERROR_INVALID_ARGUMENT );
}
- this.lineJoin = lineJoin;
- SetProperty operation
- = new SetProperty( SetProperty.LINE_JOIN, new Integer( lineJoin ) );
- addGCOperation( operation );
+ delegate.setLineJoin( lineJoin );
}
}
@@ -568,7 +517,7 @@ public class GC extends Resource {
*/
public int getLineJoin() {
checkDisposed();
- return lineJoin;
+ return delegate.getLineJoin();
}
/**
@@ -612,6 +561,9 @@ public class GC extends Resource {
*/
public LineAttributes getLineAttributes() {
checkDisposed();
+ int lineWidth = delegate.getLineWidth();
+ int lineCap = delegate.getLineCap();
+ int lineJoin = delegate.getLineJoin();
return new LineAttributes( lineWidth, lineCap, lineJoin );
}
@@ -631,8 +583,7 @@ public class GC extends Resource {
public void drawLine( final int x1, final int y1, final int x2, final int y2 )
{
checkDisposed();
- DrawLine operation = new DrawLine( x1, y1, x2, y2 );
- addGCOperation( operation );
+ delegate.drawLine( x1, y1, x2, y2 );
}
/**
@@ -678,6 +629,7 @@ public class GC extends Resource {
final int width,
final int height )
{
+ checkDisposed();
drawRectangle( x, y, width, height, 0, 0, false );
}
@@ -748,6 +700,7 @@ public class GC extends Resource {
final int width,
final int height )
{
+ checkDisposed();
drawRectangle( x, y, width, height, 0, 0, true );
}
@@ -779,12 +732,10 @@ public class GC extends Resource {
{
checkDisposed();
if( width != 0 && height != 0 ) {
- if( background.equals( foreground ) ) {
+ if( delegate.getBackground().equals( delegate.getForeground() ) ) {
fillRectangle( x, y, width, height );
} else {
- FillGradientRectangle operation
- = new FillGradientRectangle( x, y, width, height, vertical );
- addGCOperation( operation );
+ fillGradientRect( x, y, width, height, vertical );
}
}
}
@@ -817,6 +768,7 @@ public class GC extends Resource {
final int arcWidth,
final int arcHeight )
{
+ checkDisposed();
drawRectangle( x, y, width, height, arcWidth, arcHeight, false );
}
@@ -844,6 +796,7 @@ public class GC extends Resource {
final int arcWidth,
final int arcHeight )
{
+ checkDisposed();
drawRectangle( x, y, width, height, arcWidth, arcHeight, true );
}
@@ -873,6 +826,7 @@ public class GC extends Resource {
final int width,
final int height )
{
+ checkDisposed();
drawArc( x, y, width, height, 0, 360, false );
}
@@ -897,6 +851,7 @@ public class GC extends Resource {
final int width,
final int height )
{
+ checkDisposed();
drawArc( x, y, width, height, 0, 360, true );
}
@@ -936,6 +891,7 @@ public class GC extends Resource {
final int startAngle,
final int arcAngle )
{
+ checkDisposed();
drawArc( x, y, width, height, startAngle, arcAngle, false );
}
@@ -978,6 +934,7 @@ public class GC extends Resource {
final int startAngle,
final int arcAngle )
{
+ checkDisposed();
drawArc( x, y, width, height, startAngle, arcAngle, true );
}
@@ -1003,8 +960,7 @@ public class GC extends Resource {
if( pointArray == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
- DrawPolyline operation = new DrawPolyline( pointArray, true, false );
- addGCOperation( operation );
+ delegate.drawPolyline( pointArray, true, false );
}
/**
@@ -1031,8 +987,7 @@ public class GC extends Resource {
if( pointArray == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
- DrawPolyline operation = new DrawPolyline( pointArray, true, true );
- addGCOperation( operation );
+ delegate.drawPolyline( pointArray, true, true );
}
/**
@@ -1057,8 +1012,7 @@ public class GC extends Resource {
if( pointArray == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
- DrawPolyline operation = new DrawPolyline( pointArray, false, false );
- addGCOperation( operation );
+ delegate.drawPolyline( pointArray, false, false );
}
/**
@@ -1078,8 +1032,7 @@ public class GC extends Resource {
*/
public void drawPoint( final int x, final int y ) {
checkDisposed();
- DrawPoint operation = new DrawPoint( x, y );
- addGCOperation( operation );
+ delegate.drawPoint( x, y );
}
/**
@@ -1109,9 +1062,9 @@ public class GC extends Resource {
if( image.isDisposed() ) {
SWT.error( SWT.ERROR_INVALID_ARGUMENT );
}
- DrawImage operation
- = new DrawImage( image, 0, 0, -1, -1, x, y, -1, -1, true );
- addGCOperation( operation );
+ Rectangle src = new Rectangle( 0, 0, -1, -1 );
+ Rectangle dest = new Rectangle( x, y, -1, -1 );
+ delegate.drawImage( image, src, dest, true );
}
/**
@@ -1165,7 +1118,7 @@ public class GC extends Resource {
|| destWidth < 0
|| destHeight < 0 )
{
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ SWT.error( SWT.ERROR_INVALID_ARGUMENT );
}
if( image == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
@@ -1178,17 +1131,9 @@ public class GC extends Resource {
if( srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight ) {
SWT.error( SWT.ERROR_INVALID_ARGUMENT );
}
- DrawImage operation = new DrawImage( image,
- srcX,
- srcY,
- srcWidth,
- srcHeight,
- destX,
- destY,
- destWidth,
- destHeight,
- false );
- addGCOperation( operation );
+ Rectangle src = new Rectangle( srcX, srcY, srcWidth, srcHeight );
+ Rectangle dest = new Rectangle( destX, destY, destWidth, destHeight );
+ delegate.drawImage( image, src, dest, false );
}
}
@@ -1341,8 +1286,7 @@ public class GC extends Resource {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
if( string.length() != 0 ) {
- DrawText operation = new DrawText( string, x, y, flags );
- addGCOperation( operation );
+ delegate.drawText( string, x, y, flags );
}
}
@@ -1364,7 +1308,34 @@ public class GC extends Resource {
*/
public int getStyle() {
checkDisposed();
- return style;
+ return SWT.LEFT_TO_RIGHT;
+ }
+
+ GCDelegate getGCDelegate() {
+ return delegate;
+ }
+
+ static Rectangle checkBounds( final int x,
+ final int y,
+ final int width,
+ final int height )
+ {
+ Rectangle result = new Rectangle( x, y, width, height );
+ if( width < 0 ) {
+ result.x = x + width;
+ result.width = -width;
+ }
+ if( height < 0 ) {
+ result.y = y + height;
+ result.height = -height;
+ }
+ return result;
+ }
+
+ private void checkDisposed() {
+ if( isDisposed() ) {
+ SWT.error( SWT.ERROR_GRAPHIC_DISPOSED );
+ }
}
private void drawArc( final int x,
@@ -1375,17 +1346,9 @@ public class GC extends Resource {
final int arcAngle,
final boolean fill )
{
- checkDisposed();
Rectangle bounds = checkBounds( x, y, width, height );
if( bounds.width != 0 && bounds.height != 0 && arcAngle != 0 ) {
- DrawArc operation = new DrawArc( bounds.x,
- bounds.y,
- bounds.width,
- bounds.height,
- startAngle,
- arcAngle,
- fill );
- addGCOperation( operation );
+ delegate.drawArc( bounds, startAngle, arcAngle, fill );
}
}
@@ -1397,71 +1360,39 @@ public class GC extends Resource {
final int arcHeight,
final boolean fill )
{
- checkDisposed();
Rectangle bounds = checkBounds( x, y, width, height );
if( bounds.width != 0 && bounds.height != 0 ) {
- GCOperation operation;
if( arcWidth == 0 || arcHeight == 0 ) {
- operation = new DrawRectangle( bounds.x,
- bounds.y,
- bounds.width,
- bounds.height,
- fill );
+ delegate.drawRectangle( bounds, fill );
} else {
- operation = new DrawRoundRectangle( bounds.x,
- bounds.y,
- bounds.width,
- bounds.height,
- Math.abs( arcWidth ),
- Math.abs( arcHeight ),
- fill );
+ int absArcWidth = Math.abs( arcWidth );
+ int absArcHeight = Math.abs( arcHeight );
+ delegate.drawRoundRectangle( bounds, absArcWidth, absArcHeight, fill );
}
- addGCOperation( operation );
}
}
- static Rectangle checkBounds( final int x,
- final int y,
- final int width,
- final int height )
+ private void fillGradientRect( final int x,
+ final int y,
+ final int width,
+ final int height,
+ final boolean vertical )
{
- Rectangle result = new Rectangle( x, y, width, height );
- if( width < 0 ) {
- result.x = x + width;
- result.width = -width;
- }
- if( height < 0 ) {
- result.y = y + height;
- result.height = -height;
- }
- return result;
- }
-
- private void checkDisposed() {
- if( isDisposed() ) {
- SWT.error( SWT.ERROR_GRAPHIC_DISPOSED );
- }
- }
-
- private static int checkStyle( final int style ) {
- return SWT.LEFT_TO_RIGHT;
+ Rectangle bounds = new Rectangle( x, y, width, height );
+ delegate.fillGradientRectangle( bounds, vertical );
}
- GCAdapter getGCAdapter() {
- GCAdapter result = null;
- if( control != null ) {
- result = ( GCAdapter )control.getAdapter( IGCAdapter.class );
+ private static GCDelegate determineDelegate( final Drawable drawable ) {
+ GCDelegate result = null;
+ // Assume that Drawable is either a Control or a Device
+ if( drawable instanceof Control ) {
+ result = new ControlGC( ( Control )drawable );
+ } else if( drawable instanceof Device ) {
+ result = new DeviceGC( ( Device )drawable );
}
return result;
}
- private void addGCOperation( final GCOperation operation ) {
- GCAdapter adapter = getGCAdapter();
- if( adapter != null ) {
- adapter.addGCOperation( operation );
- }
- }
-
private static Device determineDevice( final Drawable drawable ) {
Device result = null;
if( drawable instanceof Control ) {
@@ -1471,34 +1402,4 @@ public class GC extends Resource {
}
return result;
}
-
- private static Font determineFont( final Drawable drawable ) {
- Font result = null;
- if( drawable instanceof Control ) {
- result = ( ( Control )drawable ).getFont();
- } else if( drawable instanceof Display ) {
- result = ( ( Display )drawable ).getSystemFont();
- }
- return result;
- }
-
- private static Color determineBackground( final Drawable drawable ) {
- Color result = null;
- if( drawable instanceof Control ) {
- result = ( ( Control )drawable ).getBackground();
- } else if( drawable instanceof Display ) {
- result = ( ( Display )drawable ).getSystemColor( SWT.COLOR_WHITE );
- }
- return result;
- }
-
- private static Color determineForeground( final Drawable drawable ) {
- Color result = null;
- if( drawable instanceof Control ) {
- result = ( ( Control )drawable ).getForeground();
- } else if( drawable instanceof Display ) {
- result = ( ( Display )drawable ).getSystemColor( SWT.COLOR_BLACK );
- }
- return result;
- }
}
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GCDelegate.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GCDelegate.java
new file mode 100644
index 0000000000..83fc35c19e
--- /dev/null
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/graphics/GCDelegate.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Rüdiger Herrmann and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Rüdiger Herrmann - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.graphics;
+
+
+
+abstract class GCDelegate {
+
+ abstract void setBackground( Color color );
+ abstract Color getBackground();
+
+ abstract void setForeground( Color color );
+ abstract Color getForeground();
+
+ abstract void setFont( Font font );
+ abstract Font getFont();
+
+ abstract Font getDefaultFont();
+ abstract void setAlpha( int alpha );
+ abstract int getAlpha();
+
+ abstract void setLineWidth( int lineWidth );
+ abstract int getLineWidth();
+ abstract void setLineCap( int lineCap );
+ abstract int getLineCap();
+ abstract void setLineJoin( int lineJoin );
+ abstract int getLineJoin();
+
+ abstract Rectangle getClipping();
+
+ abstract Point stringExtent( String string );
+ abstract Point textExtent( String string , int wrapWidth );
+
+ abstract void drawPoint( int x, int y );
+ abstract void drawLine( int x1, int y1, int x2, int y2 );
+ abstract void drawPolyline( int[] pointArray, boolean close, boolean fill );
+ abstract void drawRectangle( Rectangle bounds, boolean fill );
+ abstract void drawRoundRectangle( Rectangle bounds,
+ int arcWidth,
+ int arcHeight,
+ boolean fill );
+ abstract void fillGradientRectangle( Rectangle bounds, boolean vertical );
+ abstract void drawArc( Rectangle bounds,
+ int startAngle,
+ int arcAngle,
+ boolean fill );
+
+ abstract void drawImage( Image image,
+ Rectangle src,
+ Rectangle dest,
+ boolean simple );
+
+ abstract void drawText( String string, int x, int y, int flags );
+}
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/graphics/GCOperation.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/graphics/GCOperation.java
index 6842ada25b..de0469f108 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/graphics/GCOperation.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/internal/graphics/GCOperation.java
@@ -9,8 +9,7 @@
******************************************************************************/
package org.eclipse.swt.internal.graphics;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.*;
public abstract class GCOperation {
@@ -26,10 +25,15 @@ public abstract class GCOperation {
public final int id;
public final Object value;
- public SetProperty( final int id, final Object value ) {
+ public SetProperty( final int id, final Color value ) {
this.id = id;
this.value = value;
}
+
+ public SetProperty( final int id, final int value ) {
+ this.id = id;
+ this.value = new Integer( value );
+ }
}
public static final class SetFont extends GCOperation {
@@ -75,16 +79,11 @@ public abstract class GCOperation {
public final int height;
public final boolean fill;
- public DrawRectangle( final int x,
- final int y,
- final int width,
- final int height,
- final boolean fill )
- {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
+ public DrawRectangle( final Rectangle bounds, final boolean fill ) {
+ this.x = bounds.x;
+ this.y = bounds.y;
+ this.width = bounds.width;
+ this.height = bounds.height;
this.fill = fill;
}
}
@@ -94,15 +93,12 @@ public abstract class GCOperation {
public final int arcWidth;
public final int arcHeight;
- public DrawRoundRectangle( final int x,
- final int y,
- final int width,
- final int height,
+ public DrawRoundRectangle( final Rectangle bounds,
final int arcWidth,
final int arcHeight,
final boolean fill )
{
- super( x, y, width, height, fill );
+ super( bounds, fill );
this.arcWidth = arcWidth;
this.arcHeight = arcHeight;
}
@@ -112,13 +108,10 @@ public abstract class GCOperation {
public final boolean vertical;
- public FillGradientRectangle( final int x,
- final int y,
- final int width,
- final int height,
+ public FillGradientRectangle( final Rectangle bounds,
final boolean vertical )
{
- super( x, y, width, height, true );
+ super( bounds, true );
this.vertical = vertical;
}
}
@@ -133,18 +126,15 @@ public abstract class GCOperation {
public final int arcAngle;
public final boolean fill;
- public DrawArc( final int x,
- final int y,
- final int width,
- final int height,
+ public DrawArc( final Rectangle bounds,
final int startAngle,
final int arcAngle,
final boolean fill )
{
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
+ this.x = bounds.x;
+ this.y = bounds.y;
+ this.width = bounds.width;
+ this.height = bounds.height;
this.startAngle = startAngle;
this.arcAngle = arcAngle;
this.fill = fill;
@@ -182,25 +172,19 @@ public abstract class GCOperation {
public final boolean simple;
public DrawImage( final Image image,
- final int srcX,
- final int srcY,
- final int srcWidth,
- final int srcHeight,
- final int destX,
- final int destY,
- final int destWidth,
- final int destHeight,
+ final Rectangle src,
+ final Rectangle dest,
final boolean simple )
{
this.image = image;
- this.srcX = srcX;
- this.srcY = srcY;
- this.srcWidth = srcWidth;
- this.srcHeight = srcHeight;
- this.destX = destX;
- this.destY = destY;
- this.destWidth = destWidth;
- this.destHeight = destHeight;
+ this.srcX = src.x;
+ this.srcY = src.y;
+ this.srcWidth = src.width;
+ this.srcHeight = src.height;
+ this.destX = dest.x;
+ this.destY = dest.y;
+ this.destWidth = dest.width;
+ this.destHeight = dest.height;
this.simple = simple;
}
}
diff --git a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java
index baf4969970..7780c95992 100644
--- a/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java
+++ b/tests/org.eclipse.rap.rwt.q07.test/src/org/eclipse/swt/internal/widgets/canvaskit/CanvasLCA_Test.java
@@ -119,8 +119,7 @@ public class CanvasLCA_Test extends TestCase {
adapter.addGCOperation( new DrawLine( 5, 6, 7, 8 ) );
Font font = new Font( display, "Arial", 15, SWT.NORMAL );
adapter.addGCOperation( new SetFont( font ) );
- SetProperty operation
- = new SetProperty( SetProperty.LINE_WIDTH, new Integer( 5 ) );
+ SetProperty operation = new SetProperty( SetProperty.LINE_WIDTH, 5 );
adapter.addGCOperation( operation );
new CanvasLCA().renderChanges( canvas );
String expected
@@ -146,8 +145,7 @@ public class CanvasLCA_Test extends TestCase {
GCAdapter adapter = ( GCAdapter )canvas.getAdapter( IGCAdapter.class );
Font font = new Font( display, "Arial", 15, SWT.NORMAL );
adapter.addGCOperation( new SetFont( font ) );
- SetProperty operation
- = new SetProperty( SetProperty.LINE_WIDTH, new Integer( 5 ) );
+ SetProperty operation = new SetProperty( SetProperty.LINE_WIDTH, 5 );
adapter.addGCOperation( operation );
new CanvasLCA().renderChanges( canvas );
assertEquals( "", Fixture.getAllMarkup() );
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java
index b8c0d97c0d..95dfbe291a 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/RWTHostTestSuite.java
@@ -189,6 +189,8 @@ public class RWTHostTestSuite {
suite.addTestSuite( Cursor_Test.class );
suite.addTestSuite( Device_Test.class );
suite.addTestSuite( GC_Test.class );
+ suite.addTestSuite( ControlGC_Test.class );
+ suite.addTestSuite( DeviceGC_Test.class );
suite.addTestSuite( FontMetrics_Test.class );
suite.addTestSuite( TextSizeEstimation_Test.class );
suite.addTestSuite( TextSizeDetermination_Test.class );
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/ControlGC_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/ControlGC_Test.java
new file mode 100644
index 0000000000..bc4e87d736
--- /dev/null
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/ControlGC_Test.java
@@ -0,0 +1,583 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Rüdiger Herrmann and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Rüdiger Herrmann - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.graphics;
+
+import java.util.Arrays;
+
+import org.eclipse.rwt.Fixture;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.internal.graphics.*;
+import org.eclipse.swt.internal.graphics.GCOperation.*;
+import org.eclipse.swt.widgets.*;
+
+import junit.framework.TestCase;
+
+
+public class ControlGC_Test extends TestCase {
+ private Display display;
+ private Canvas canvas;
+ private GC gc;
+
+ public void testInitialValues() {
+ assertEquals( canvas.getFont(), gc.getFont() );
+ assertEquals( canvas.getBackground(), gc.getBackground() );
+ assertEquals( canvas.getForeground(), gc.getForeground() );
+ }
+
+
+ public void testSetFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetFont operation = ( SetFont )gcOperations[ 0 ];
+ assertEquals( font, operation.font );
+ }
+
+ public void testSetFontWithNullFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ gc.setFont( null );
+ assertEquals( display.getSystemFont(), gc.getFont() );
+ }
+
+ public void testSetFontWithSameFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ IGCAdapter adapter = getGCAdapter( gc );
+ adapter.clearGCOperations();
+ gc.setFont( font );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testSetBackground() {
+ Color color = createColor();
+ gc.setBackground( color );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.BACKGROUND, operation.id );
+ assertEquals( color, operation.value );
+ }
+
+ public void testSetForeground() {
+ Shell shell = new Shell( display );
+ GC gc = new GC( shell );
+ Color color = createColor();
+ gc.setForeground( color );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.FOREGROUND, operation.id );
+ assertEquals( color, operation.value );
+ }
+
+ public void testGetGCAdapterForCanvasWidget() {
+ IGCAdapter adapter1 = getGCAdapter( gc );
+ assertNotNull( adapter1 );
+ IGCAdapter adapter2 = getGCAdapter( gc );
+ assertSame( adapter2, adapter1 );
+ }
+
+ public void testGetGCAdapterForNonCanvasWidget() {
+ Shell shell = new Shell( display );
+ Button button = new Button( shell, SWT.NONE );
+ GC gc = new GC( button );
+ assertNull( getGCAdapter( gc ) );
+ }
+
+ public void testDrawOperationWithNonCanvas() {
+ gc.drawLine( 1, 2, 3, 4 );
+ // This test has no assert. Ensures that no NPE is thrown.
+ }
+
+ public void testSetAlpha() {
+ gc.setAlpha( 123 );
+ assertEquals( 123, gc.getAlpha() );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.ALPHA, operation.id );
+ assertEquals( new Integer( 123 ), operation.value );
+ }
+
+ public void testSetAlphaWithSameValue() {
+ gc.setAlpha( 123 );
+ getGCAdapter( gc ).clearGCOperations();
+ gc.setAlpha( 123 );
+ assertEquals( 0, getGCOperations( gc ).length );
+ }
+
+ public void testSetAlphaWithInvalidValue() {
+ gc.setAlpha( 777 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testSetLineWidth() {
+ gc.setLineWidth( 5 );
+ assertEquals( 5, gc.getLineWidth() );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.LINE_WIDTH, operation.id );
+ assertEquals( new Integer( 5 ), operation.value );
+ }
+
+ public void testSetLineCap() {
+ gc.setLineCap( SWT.CAP_ROUND );
+ assertEquals( SWT.CAP_ROUND, gc.getLineCap() );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.LINE_CAP, operation.id );
+ assertEquals( new Integer( SWT.CAP_ROUND ), operation.value );
+ }
+
+ public void testSetLineCapWithUnchangeValue() {
+ gc.setLineCap( SWT.CAP_ROUND );
+ getGCAdapter( gc ).clearGCOperations();
+ gc.setLineCap( SWT.CAP_ROUND );
+ assertEquals( 0, getGCOperations( gc ).length );
+ }
+
+ public void testSetLineJoin() {
+ gc.setLineJoin( SWT.JOIN_ROUND );
+ assertEquals( SWT.JOIN_ROUND, gc.getLineJoin() );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.LINE_JOIN, operation.id );
+ assertEquals( new Integer( SWT.JOIN_ROUND ), operation.value );
+ }
+
+ public void testSetLineJoinWithUnchangedValue() {
+ gc.setLineJoin( SWT.JOIN_ROUND );
+ getGCAdapter( gc ).clearGCOperations();
+ gc.setLineJoin( SWT.JOIN_ROUND );
+ assertEquals( 0, getGCOperations( gc ).length );
+ }
+
+ public void testSetLineAttributes() {
+ LineAttributes attributes
+ = new LineAttributes( 5, SWT.CAP_ROUND, SWT.JOIN_BEVEL );
+ gc.setLineAttributes( attributes );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ SetProperty operation = ( SetProperty )gcOperations[ 0 ];
+ assertEquals( SetProperty.LINE_WIDTH, operation.id );
+ assertEquals( new Integer( 5 ), operation.value );
+ operation = ( SetProperty )gcOperations[ 1 ];
+ assertEquals( SetProperty.LINE_CAP, operation.id );
+ assertEquals( new Integer( SWT.CAP_ROUND ), operation.value );
+ operation = ( SetProperty )gcOperations[ 2 ];
+ assertEquals( SetProperty.LINE_JOIN, operation.id );
+ assertEquals( new Integer( SWT.JOIN_BEVEL ), operation.value );
+ }
+
+ public void testDrawLine() {
+ gc.drawLine( 1, 2, 3, 4 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawLine operation = ( DrawLine )gcOperations[ 0 ];
+ assertEquals( 1, operation.x1 );
+ assertEquals( 2, operation.y1 );
+ assertEquals( 3, operation.x2 );
+ assertEquals( 4, operation.y2 );
+ }
+
+ public void testDrawPoint() {
+ gc.drawPoint( 1, 2 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawPoint operation = ( DrawPoint )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ }
+
+ public void testDrawRectangle() {
+ gc.drawRectangle( 1, 2, 3, 4 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawRectangleWithZeroWidthAndHeight() {
+ gc.drawRectangle( 1, 2, 0, 0 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawFocus() {
+ gc.drawFocus( 1, 2, 3, 4 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertFalse( operation.fill );
+ }
+
+ public void testFillRectangle() {
+ gc.fillRectangle( 1, 2, 3, 4 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertTrue( operation.fill );
+ }
+
+ public void testFillGradientRectangle() {
+ gc.fillGradientRectangle( 1, 2, 3, 4, true );
+ gc.fillGradientRectangle( 5, 6, 7, 8, false );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ FillGradientRectangle operation
+ = ( FillGradientRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertTrue( operation.vertical );
+ assertTrue( operation.fill );
+ operation = ( FillGradientRectangle )gcOperations[ 1 ];
+ assertEquals( 5, operation.x );
+ assertEquals( 6, operation.y );
+ assertEquals( 7, operation.width );
+ assertEquals( 8, operation.height );
+ assertFalse( operation.vertical );
+ assertTrue( operation.fill );
+ }
+
+ public void testDrawRoundRectangle() {
+ gc.drawRoundRectangle( 1, 2, 3, 4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawRoundRectangle operation = ( DrawRoundRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.arcWidth );
+ assertEquals( 6, operation.arcHeight );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawRoundRectangleWithZeroArcWidth() {
+ gc.drawRoundRectangle( 1, 2, 3, 4, 0, 6 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawRoundRectangleWithZeroArcHeight() {
+ gc.drawRoundRectangle( 1, 2, 3, 4, 5, 0 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertFalse( operation.fill );
+ }
+
+ public void testFillRoundRectangle() {
+ gc.fillRoundRectangle( 1, 2, 3, 4, 5, 6 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRoundRectangle operation = ( DrawRoundRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.arcWidth );
+ assertEquals( 6, operation.arcHeight );
+ assertTrue( operation.fill );
+ }
+
+ public void testFillRoundRectangleWithZeroArcWidth() {
+ gc.fillRoundRectangle( 1, 2, 3, 4, 0, 6 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertTrue( operation.fill );
+ }
+
+ public void testFillRoundRectangleWithZeroArcHeight() {
+ gc.fillRoundRectangle( 1, 2, 3, 4, 5, 0 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertTrue( operation.fill );
+ }
+
+ public void testDrawArc() {
+ gc.drawArc( 1, 2, 3, 4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.startAngle );
+ assertEquals( 6, operation.arcAngle );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawArcWithZeroWidth() {
+ gc.drawArc( 1, 2, 0, 5, 5, 5 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawArcWithZeroHeight() {
+ gc.drawArc( 1, 2, 3, 0, 5, 5 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawArcWithZeroArcAngle() {
+ gc.drawArc( 1, 2, 3, 4, 5, 0 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillArc() {
+ gc.fillArc( 1, 2, 3, 4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.startAngle );
+ assertEquals( 6, operation.arcAngle );
+ }
+
+ public void testFillArcWithNegativeWidthAndHeight() {
+ gc.fillArc( 1, 2, -3, -4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( -2, operation.x );
+ assertEquals( -2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 5, operation.startAngle );
+ assertEquals( 6, operation.arcAngle );
+ assertTrue( operation.fill );
+ }
+
+ public void testFillArcWithZeroWidth() {
+ gc.fillArc( 1, 2, 0, 4, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillArcWithZeroHeight() {
+ gc.fillArc( 1, 2, 3, 0, 5, 6 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillArcWithZeroArcAngle() {
+ gc.fillArc( 1, 2, 3, 4, 5, 0 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillPolygon() {
+ Control control = new Shell( display );
+ GC gc = new GC( control );
+ int[] pointArray = new int[] { 1, 2, 3, 4 };
+ gc.fillPolygon( pointArray );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
+ assertTrue( Arrays.equals( pointArray, operation.points ) );
+ assertTrue( operation.close );
+ assertTrue( operation.fill );
+ }
+
+ public void testDrawPolyline() {
+ Control control = new Shell( display );
+ GC gc = new GC( control );
+ int[] pointArray = new int[] { 1, 2, 3, 4 };
+ gc.drawPolyline( pointArray );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
+ assertTrue( Arrays.equals( pointArray, operation.points ) );
+ assertFalse( operation.close );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawOval() {
+ gc.drawOval( 1, 2, 3, 4 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 0, operation.startAngle );
+ assertEquals( 360, operation.arcAngle );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawOvalWithZeroWidthAndHeight() {
+ gc.drawOval( 1, 2, 0, 0 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testFillOval() {
+ gc.fillOval( 1, 2, 3, 4 );
+ IGCAdapter adapter = getGCAdapter( gc );
+ GCOperation[] gcOperations = adapter.getGCOperations();
+ DrawArc operation = ( DrawArc )gcOperations[ 0 ];
+ assertEquals( 1, operation.x );
+ assertEquals( 2, operation.y );
+ assertEquals( 3, operation.width );
+ assertEquals( 4, operation.height );
+ assertEquals( 0, operation.startAngle );
+ assertEquals( 360, operation.arcAngle );
+ assertTrue( operation.fill );
+ adapter.clearGCOperations();
+ }
+
+ public void testDrawPolygon() {
+ int[] pointArray = new int[] { 1, 2, 3, 4 };
+ gc.drawPolygon( pointArray );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
+ assertTrue( Arrays.equals( pointArray, operation.points ) );
+ assertTrue( operation.close );
+ assertFalse( operation.fill );
+ }
+
+ public void testDrawStringWithEmptyString() {
+ gc.drawString( "", 10, 10, false );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawImage() {
+ Image image = display.getSystemImage( SWT.ICON_INFORMATION );
+ gc.drawImage( image, 1, 2 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawImage operation = ( DrawImage )gcOperations[ 0 ];
+ assertSame( image, operation.image );
+ assertEquals( 0, operation.srcX );
+ assertEquals( 0, operation.srcY );
+ assertEquals( -1, operation.srcWidth );
+ assertEquals( -1, operation.srcHeight );
+ assertEquals( 1, operation.destX );
+ assertEquals( 2, operation.destY );
+ assertEquals( -1, operation.destWidth );
+ assertEquals( -1, operation.destHeight );
+ assertTrue( operation.simple );
+ }
+
+ public void testDrawImageCopy() {
+ Image image = display.getSystemImage( SWT.ICON_INFORMATION );
+ gc.drawImage( image, 1, 2, 3, 4, 5, 6, 7, 8 );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawImage operation = ( DrawImage )gcOperations[ 0 ];
+ assertSame( image, operation.image );
+ assertEquals( 1, operation.srcX );
+ assertEquals( 2, operation.srcY );
+ assertEquals( 3, operation.srcWidth );
+ assertEquals( 4, operation.srcHeight );
+ assertEquals( 5, operation.destX );
+ assertEquals( 6, operation.destY );
+ assertEquals( 7, operation.destWidth );
+ assertEquals( 8, operation.destHeight );
+ assertFalse( operation.simple );
+ }
+
+ public void testDrawText() {
+ gc.drawText( "text", 10, 10, SWT.DRAW_TRANSPARENT );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawText operation = ( DrawText )gcOperations[ 0 ];
+ assertEquals( "text", operation.text );
+ assertEquals( 10, operation.x );
+ assertEquals( 10, operation.y );
+ assertEquals( SWT.DRAW_TRANSPARENT, operation.flags );
+ }
+
+ public void testDrawTextWithEmptyString() {
+ gc.drawText( "", 10, 10, SWT.DRAW_TRANSPARENT );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ assertEquals( 0, gcOperations.length );
+ }
+
+ public void testDrawString() {
+ gc.drawString( "text", 10, 10, true );
+ GCOperation[] gcOperations = getGCOperations( gc );
+ DrawText operation = ( DrawText )gcOperations[ 0 ];
+ assertEquals( "text", operation.text );
+ assertEquals( 10, operation.x );
+ assertEquals( 10, operation.y );
+ assertEquals( SWT.DRAW_TRANSPARENT, operation.flags );
+ }
+
+ public void testGetClipping() {
+ canvas.setSize( 100, 100 );
+ GC gc = new GC( canvas );
+ Rectangle clipping = gc.getClipping();
+ assertEquals( new Rectangle( 0, 0, 100, 100 ), clipping );
+ }
+
+ protected void setUp() throws Exception {
+ Fixture.setUp();
+ display = new Display();
+ Shell shell = new Shell( display );
+ canvas = new Canvas( shell, SWT.NONE );
+ gc = new GC( canvas );
+ }
+
+ protected void tearDown() throws Exception {
+ Fixture.tearDown();
+ }
+
+ private static GCOperation[] getGCOperations( final GC gc ) {
+ GCAdapter adapter = getGCAdapter( gc );
+ return adapter.getGCOperations();
+ }
+
+ private static GCAdapter getGCAdapter( GC gc ) {
+ GCAdapter result = null;
+ GCDelegate delegate = gc.getGCDelegate();
+ if( delegate instanceof ControlGC ) {
+ result = ( ( ControlGC )delegate ).getGCAdapter();
+ }
+ return result;
+ }
+
+ private Font createFont() {
+ return new Font( display, "font-name", 11, SWT.NORMAL );
+ }
+
+ private Color createColor() {
+ return new Color( display, 1, 2, 3 );
+ }
+}
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/DeviceGC_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/DeviceGC_Test.java
new file mode 100644
index 0000000000..7c1694c5cd
--- /dev/null
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/DeviceGC_Test.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Rüdiger Herrmann and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Rüdiger Herrmann - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.swt.graphics;
+
+import junit.framework.TestCase;
+
+import org.eclipse.rwt.Fixture;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+
+
+public class DeviceGC_Test extends TestCase {
+
+ private Display display;
+ private GC gc;
+
+ public void testInitialValues() {
+ assertEquals( display.getSystemFont(), gc.getFont() );
+ Color white = display.getSystemColor( SWT.COLOR_WHITE );
+ assertEquals( white, gc.getBackground() );
+ Color black = display.getSystemColor( SWT.COLOR_BLACK );
+ assertEquals( black, gc.getForeground() );
+ }
+
+ public void testSetAlpha() {
+ gc.setAlpha( 123 );
+ assertEquals( 123, gc.getAlpha() );
+ }
+
+ public void testSetLineWidth() {
+ gc.setLineWidth( 5 );
+ assertEquals( 5, gc.getLineWidth() );
+ }
+
+ public void testSetLineJoin() {
+ gc.setLineJoin( SWT.JOIN_ROUND );
+ assertEquals( SWT.JOIN_ROUND, gc.getLineJoin() );
+ }
+
+ public void testSetLineCap() {
+ gc.setLineCap( SWT.CAP_ROUND );
+ assertEquals( SWT.CAP_ROUND, gc.getLineCap() );
+ }
+
+ public void testSetFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ assertEquals( font, gc.getFont() );
+ }
+
+ public void testSetFontWithNullFont() {
+ Font font = createFont();
+ gc.setFont( font );
+ gc.setFont( null );
+ assertEquals( display.getSystemFont(), gc.getFont() );
+ }
+
+ public void testSetBackground() {
+ Color color = createColor();
+ gc.setBackground( color );
+ assertEquals( color, gc.getBackground() );
+ }
+
+ public void testSetForeground() {
+ Color color = createColor();
+ gc.setForeground( color );
+ assertEquals( color, gc.getForeground() );
+ }
+
+ public void testGetClipping() {
+ Rectangle clipping = gc.getClipping();
+ assertEquals( display.getBounds(), clipping );
+ }
+
+ protected void setUp() throws Exception {
+ Fixture.setUp();
+ display = new Display();
+ gc = new GC( display );
+ }
+
+ protected void tearDown() throws Exception {
+ Fixture.tearDown();
+ }
+
+ private Font createFont() {
+ return new Font( display, "font-name", 11, SWT.NORMAL );
+ }
+
+ private Color createColor() {
+ return new Color( display, 1, 2, 3 );
+ }
+}
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java
index 53b671660c..0dfa11d219 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/graphics/GC_Test.java
@@ -10,7 +10,6 @@
package org.eclipse.swt.graphics;
import java.io.InputStream;
-import java.util.Arrays;
import junit.framework.TestCase;
@@ -18,14 +17,13 @@ import org.eclipse.rwt.Fixture;
import org.eclipse.rwt.graphics.Graphics;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
-import org.eclipse.swt.internal.graphics.*;
-import org.eclipse.swt.internal.graphics.GCOperation.*;
import org.eclipse.swt.widgets.*;
public class GC_Test extends TestCase {
private Display display;
+ private GC gc;
public void testConstructorWithNullArgument() {
try {
@@ -37,7 +35,6 @@ public class GC_Test extends TestCase {
}
public void testInitialValues() {
- GC gc = new GC( display );
assertEquals( 255, gc.getAlpha() );
assertEquals( SWT.CAP_FLAT, gc.getLineCap() );
assertEquals( SWT.JOIN_MITER, gc.getLineJoin() );
@@ -48,66 +45,7 @@ public class GC_Test extends TestCase {
assertEquals( 0, ( int )lineAttributes.width );
}
- public void testControlGCFont() {
- Shell shell = new Shell( display );
- Control control = new Label( shell, SWT.NONE );
- GC gc = new GC( control );
- assertEquals( control.getFont(), gc.getFont() );
- }
-
- public void testDisplayGCFont() {
- GC gc = new GC( display );
- assertEquals( display.getSystemFont(), gc.getFont() );
- }
-
- public void testDisplayGCSetFont() {
- GC gc = new GC( display );
- Font font = createFont();
- gc.setFont( font );
- assertEquals( font, gc.getFont() );
- }
-
- public void testDisplayGCSetFontWithNullFont() {
- GC gc = new GC( display );
- Font font = createFont();
- gc.setFont( font );
- gc.setFont( null );
- assertEquals( display.getSystemFont(), gc.getFont() );
- }
-
- public void testControlGCSetFont() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Font font = createFont();
- gc.setFont( font );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetFont operation = ( SetFont )gcOperations[ 0 ];
- assertEquals( font, operation.font );
- }
-
- public void testControlGCSetFontWithNullFont() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Font font = createFont();
- gc.setFont( font );
- gc.setFont( null );
- assertEquals( display.getSystemFont(), gc.getFont() );
- }
-
- public void testControlGCSetFontWithSameFont() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Font font = createFont();
- gc.setFont( font );
- IGCAdapter adapter = gc.getGCAdapter();
- adapter.clearGCOperations();
- gc.setFont( font );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testSetFontWithDisposedFoont() {
- GC gc = new GC( display );
+ public void testSetFontWithDisposedFont() {
Font disposedFont = createFont();
disposedFont.dispose();
try {
@@ -117,7 +55,6 @@ public class GC_Test extends TestCase {
}
public void testDisposedGC() {
- GC gc = new GC( display );
gc.dispose();
assertTrue( gc.isDisposed() );
try {
@@ -345,7 +282,6 @@ public class GC_Test extends TestCase {
}
public void testTextExtentWithNullArgument() {
- GC gc = new GC( display );
try {
gc.textExtent( null );
fail( "textExtent must not allow null-argument" );
@@ -355,7 +291,6 @@ public class GC_Test extends TestCase {
}
public void testTextExtent() {
- GC gc = new GC( display );
String string = "foo";
Font systemFont = display.getSystemFont();
Point gcTextExtent = gc.textExtent( string );
@@ -364,7 +299,6 @@ public class GC_Test extends TestCase {
}
public void testStringExtent() {
- GC gc = new GC( display );
String string = "foo";
Font systemFont = display.getSystemFont();
Point gcStringExtent = gc.stringExtent( string );
@@ -373,54 +307,19 @@ public class GC_Test extends TestCase {
}
public void testGetCharWidth() {
- GC gc = new GC( display );
int width = gc.getCharWidth( 'A' );
assertTrue( width > 0 );
}
- public void testControlGCBackground() {
- Shell shell = new Shell( display );
- Control control = new Label( shell, SWT.NONE );
- GC gc = new GC( control );
- assertEquals( control.getBackground(), gc.getBackground() );
- }
-
- public void testDisplayGCBackground() {
- GC gc = new GC( display );
- assertEquals( display.getSystemColor( SWT.COLOR_WHITE ),
- gc.getBackground() );
- }
-
- public void testDisplayGCSetBackground() {
- GC gc = new GC( display );
- Color color = createColor();
- gc.setBackground( color );
- assertEquals( color, gc.getBackground() );
- }
-
- public void testControlGCSetBackground() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Color color = createColor();
- gc.setBackground( color );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.BACKGROUND, operation.id );
- assertEquals( color, operation.value );
- }
-
- public void testSetBackgroundNullArgument() {
- GC gc = new GC( display );
+ public void testSetBackgroundWithNullArgument() {
try {
gc.setBackground( null );
fail( "null not allowed on setBackground" );
- } catch( IllegalArgumentException e ) {
- // expected
+ } catch( IllegalArgumentException expected ) {
}
}
public void testSetBackgroundWithDisposedColor() {
- GC gc = new GC( display );
Color color = createColor();
color.dispose();
try {
@@ -431,39 +330,7 @@ public class GC_Test extends TestCase {
}
}
- public void testControlGCForeground() {
- Shell shell = new Shell( display );
- Control control = new Label( shell, SWT.NONE );
- GC gc = new GC( control );
- assertEquals( control.getForeground(), gc.getForeground() );
- }
-
- public void testDisplayGCForeground() {
- GC gc = new GC( display );
- Color black = display.getSystemColor( SWT.COLOR_BLACK );
- assertEquals( black, gc.getForeground() );
- }
-
- public void testDisplayGCSetForeground() {
- GC gc = new GC( display );
- Color color = createColor();
- gc.setForeground( color );
- assertEquals( color, gc.getForeground() );
- }
-
- public void testControlGCSetForeground() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- Color color = createColor();
- gc.setForeground( color );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.FOREGROUND, operation.id );
- assertEquals( color, operation.value );
- }
-
- public void testSetForegroundNullArgument() {
- GC gc = new GC( display );
+ public void testSetForegroundWithNullArgument() {
try {
gc.setForeground( null );
fail( "null not allowed on setForeground" );
@@ -473,7 +340,6 @@ public class GC_Test extends TestCase {
}
public void testSetForegroundWithDisposedColor() {
- GC gc = new GC( display );
Color color = createColor();
color.dispose();
try {
@@ -484,119 +350,45 @@ public class GC_Test extends TestCase {
}
}
- public void testControlGCGetGCAdapterForCanvasWidget() {
- Shell shell = new Shell( display );
- GC gc = new GC( shell );
- IGCAdapter adapter1 = gc.getGCAdapter();
- assertNotNull( adapter1 );
- IGCAdapter adapter2 = gc.getGCAdapter();
- assertSame( adapter2, adapter1 );
- }
-
- public void testControlGCGetGCAdapterForNonCanvasWidget() {
- Shell shell = new Shell( display );
- Button button = new Button( shell, SWT.NONE );
- GC gc = new GC( button );
- assertNull( gc.getGCAdapter() );
- }
-
- public void testDisplayGCGetGCAdapter() {
- GC gc = new GC( display );
- assertNull( gc.getGCAdapter() );
- }
-
- public void testDrawOperationWithNonCanvas() {
- Shell shell = new Shell( display );
- Button button = new Button( shell, SWT.NONE );
- GC gc = new GC( button );
- gc.drawLine( 1, 2, 3, 4 );
- // This test has no assert. Ensures that no NPE is thrown.
- }
-
public void testSetAlpha() {
- Control control = new Shell( display );
- GC gc = new GC( control );
gc.setAlpha( 123 );
assertEquals( 123, gc.getAlpha() );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.ALPHA, operation.id );
- assertEquals( new Integer( 123 ), operation.value );
}
public void testSetAlphaWithInvalidValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
gc.setAlpha( 777 );
assertEquals( 255, gc.getAlpha() );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
}
-
+
public void testSetLineWidth() {
- Control control = new Shell( display );
- GC gc = new GC( control );
gc.setLineWidth( 5 );
assertEquals( 5, gc.getLineWidth() );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.LINE_WIDTH, operation.id );
- assertEquals( new Integer( 5 ), operation.value );
}
- public void testSetLineCap() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.setLineCap( SWT.CAP_ROUND );
- assertEquals( SWT.CAP_ROUND, gc.getLineCap() );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.LINE_CAP, operation.id );
- assertEquals( new Integer( SWT.CAP_ROUND ), operation.value );
+ public void testSetLineWidthWithNegativeValue() {
+ gc.setLineWidth( -2 );
+ assertEquals( -2, gc.getLineWidth() );
}
- public void testSetLineCapWithUnchangeValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.setLineCap( SWT.CAP_ROUND );
- gc.getGCAdapter().clearGCOperations();
+ public void testSetLineCap() {
gc.setLineCap( SWT.CAP_ROUND );
- assertEquals( 0, getGCOperations( gc ).length );
+ assertEquals( SWT.CAP_ROUND, gc.getLineCap() );
}
public void testSetLineCapWithInvalidValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
try {
gc.setLineCap( 500 );
fail( "value not allowed" );
} catch( IllegalArgumentException expected ) {
}
}
-
+
public void testSetLineJoin() {
- Control control = new Shell( display );
- GC gc = new GC( control );
gc.setLineJoin( SWT.JOIN_ROUND );
assertEquals( SWT.JOIN_ROUND, gc.getLineJoin() );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.LINE_JOIN, operation.id );
- assertEquals( new Integer( SWT.JOIN_ROUND ), operation.value );
- }
-
- public void testSetLineJoinWithUnchangedValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.setLineJoin( SWT.JOIN_ROUND );
- gc.getGCAdapter().clearGCOperations();
- gc.setLineJoin( SWT.JOIN_ROUND );
- assertEquals( 0, getGCOperations( gc ).length );
}
public void testSetLineJoinWithInvalidValue() {
- Control control = new Shell( display );
- GC gc = new GC( control );
try {
gc.setLineCap( 500 );
fail( "value not allowed" );
@@ -605,8 +397,6 @@ public class GC_Test extends TestCase {
}
public void testSetLineAttributes() {
- Control control = new Shell( display );
- GC gc = new GC( control );
LineAttributes attributes
= new LineAttributes( 5, SWT.CAP_ROUND, SWT.JOIN_BEVEL );
gc.setLineAttributes( attributes );
@@ -616,50 +406,27 @@ public class GC_Test extends TestCase {
assertEquals( 5, gc.getLineAttributes().width, 0 );
assertEquals( SWT.CAP_ROUND, gc.getLineAttributes().cap );
assertEquals( SWT.JOIN_BEVEL, gc.getLineAttributes().join );
- GCOperation[] gcOperations = getGCOperations( gc );
- SetProperty operation = ( SetProperty )gcOperations[ 0 ];
- assertEquals( SetProperty.LINE_WIDTH, operation.id );
- assertEquals( new Integer( 5 ), operation.value );
- operation = ( SetProperty )gcOperations[ 1 ];
- assertEquals( SetProperty.LINE_CAP, operation.id );
- assertEquals( new Integer( SWT.CAP_ROUND ), operation.value );
- operation = ( SetProperty )gcOperations[ 2 ];
- assertEquals( SetProperty.LINE_JOIN, operation.id );
- assertEquals( new Integer( SWT.JOIN_BEVEL ), operation.value );
}
public void testSetLineAttributesWithNullArgument() {
- GC gc = new GC( display );
try {
gc.setLineAttributes( null );
fail( "null value not allowed" );
- } catch( IllegalArgumentException e ) {
- // expected
+ } catch( IllegalArgumentException expected ) {
}
}
- public void testDrawLine() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawLine( 1, 2, 3, 4 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawLine operation = ( DrawLine )gcOperations[ 0 ];
- assertEquals( 1, operation.x1 );
- assertEquals( 2, operation.y1 );
- assertEquals( 3, operation.x2 );
- assertEquals( 4, operation.y2 );
- }
-
- public void testDrawPoint() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawPoint( 1, 2 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawPoint operation = ( DrawPoint )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
+ public void testGetLineAttributes() {
+ LineAttributes attributes
+ = new LineAttributes( 5, SWT.CAP_ROUND, SWT.JOIN_BEVEL );
+ gc.setLineAttributes( attributes );
+ LineAttributes returnedAttributes = gc.getLineAttributes();
+ assertNotSame( attributes, returnedAttributes );
+ assertEquals( attributes.cap, returnedAttributes.cap );
+ assertEquals( attributes.join, returnedAttributes.join );
+ assertEquals( attributes.width, returnedAttributes.width, 0 );
}
-
+
public void testCheckBounds() {
Rectangle rectangle = GC.checkBounds( 1, 2, 3, 4 );
assertEquals( 1, rectangle.x );
@@ -676,29 +443,7 @@ public class GC_Test extends TestCase {
assertEquals( 4, rectangle.height );
}
- public void testDrawRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRectangle( 1, 2, 3, 4 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertFalse( operation.fill );
- }
-
- public void testControlGCDrawRectangleWithZeroWidthAndHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRectangle( 1, 2, 0, 0 );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
public void testDrawRectangeWithNullArgument() {
- GC gc = new GC( display );
try {
gc.drawRectangle( null );
fail( "null argument is not allowed on drawRectangle" );
@@ -707,34 +452,7 @@ public class GC_Test extends TestCase {
}
}
- public void testDrawFocus() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawFocus( 1, 2, 3, 4 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertFalse( operation.fill );
- }
-
- public void testFillRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillRectangle( 1, 2, 3, 4 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertTrue( operation.fill );
- }
-
public void testFillRectangleWithNullArgument() {
- GC gc = new GC( display );
try {
gc.fillRectangle( null );
fail( "null argument is not allowed on fillRectangle" );
@@ -742,309 +460,28 @@ public class GC_Test extends TestCase {
}
}
- public void testFillGradientRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillGradientRectangle( 1, 2, 3, 4, true );
- gc.fillGradientRectangle( 5, 6, 7, 8, false );
- GCOperation[] gcOperations = getGCOperations( gc );
- FillGradientRectangle operation
- = ( FillGradientRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertTrue( operation.vertical );
- assertTrue( operation.fill );
- operation = ( FillGradientRectangle )gcOperations[ 1 ];
- assertEquals( 5, operation.x );
- assertEquals( 6, operation.y );
- assertEquals( 7, operation.width );
- assertEquals( 8, operation.height );
- assertFalse( operation.vertical );
- assertTrue( operation.fill );
- }
-
- public void testDrawRoundRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRoundRectangle( 1, 2, 3, 4, 5, 6 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawRoundRectangle operation = ( DrawRoundRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.arcWidth );
- assertEquals( 6, operation.arcHeight );
- assertFalse( operation.fill );
- }
-
- public void testDrawRoundRectangleWithZeroArcWidth() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRoundRectangle( 1, 2, 3, 4, 0, 6 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertFalse( operation.fill );
- }
-
- public void testDrawRoundRectangleWithZeroArcHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawRoundRectangle( 1, 2, 3, 4, 5, 0 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertFalse( operation.fill );
- }
-
- public void testFillRoundRectangle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillRoundRectangle( 1, 2, 3, 4, 5, 6 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRoundRectangle operation = ( DrawRoundRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.arcWidth );
- assertEquals( 6, operation.arcHeight );
- assertTrue( operation.fill );
- }
-
- public void testFillRoundRectangleWithZeroArcWidth() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillRoundRectangle( 1, 2, 3, 4, 0, 6 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertTrue( operation.fill );
- }
-
- public void testFillRoundRectangleWithZeroArcHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillRoundRectangle( 1, 2, 3, 4, 5, 0 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawRectangle operation = ( DrawRectangle )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertTrue( operation.fill );
- }
-
- public void testDrawArc() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawArc( 1, 2, 3, 4, 5, 6 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawArc operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.startAngle );
- assertEquals( 6, operation.arcAngle );
- assertFalse( operation.fill );
- }
-
- public void testDrawArcWithZeroWidth() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawArc( 1, 2, 0, 5, 5, 5 );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testDrawArcWithZeroHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawArc( 1, 2, 3, 0, 5, 5 );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testDrawArcWithZeroArcAngle() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawArc( 1, 2, 3, 4, 5, 0 );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testFillArc() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillArc( 1, 2, 3, 4, 5, 6 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawArc operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.startAngle );
- assertEquals( 6, operation.arcAngle );
- adapter.clearGCOperations();
-
- gc.fillArc( 1, 2, -3, -4, 5, 6 );
- gcOperations = adapter.getGCOperations();
- operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( -2, operation.x );
- assertEquals( -2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 5, operation.startAngle );
- assertEquals( 6, operation.arcAngle );
- assertTrue( operation.fill );
- adapter.clearGCOperations();
-
- gc.fillArc( 1, 2, 0, 4, 5, 6 );
- gcOperations = adapter.getGCOperations();
- assertEquals( 0, gcOperations.length );
-
- gc.fillArc( 1, 2, 3, 0, 5, 6 );
- gcOperations = adapter.getGCOperations();
- assertEquals( 0, gcOperations.length );
-
- gc.fillArc( 1, 2, 3, 4, 5, 0 );
- gcOperations = adapter.getGCOperations();
- assertEquals( 0, gcOperations.length );
- }
-
- public void testDrawOval() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawOval( 1, 2, 3, 4 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawArc operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 0, operation.startAngle );
- assertEquals( 360, operation.arcAngle );
- assertFalse( operation.fill );
- }
-
- public void testDrawOvalWithZeroWidthAndHeight() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawOval( 1, 2, 0, 0 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- assertEquals( 0, gcOperations.length );
- }
-
- public void testFillOval() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.fillOval( 1, 2, 3, 4 );
- IGCAdapter adapter = gc.getGCAdapter();
- GCOperation[] gcOperations = adapter.getGCOperations();
- DrawArc operation = ( DrawArc )gcOperations[ 0 ];
- assertEquals( 1, operation.x );
- assertEquals( 2, operation.y );
- assertEquals( 3, operation.width );
- assertEquals( 4, operation.height );
- assertEquals( 0, operation.startAngle );
- assertEquals( 360, operation.arcAngle );
- assertTrue( operation.fill );
- adapter.clearGCOperations();
- }
-
- public void testDrawPolygon() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- int[] pointArray = new int[] { 1, 2, 3, 4 };
- gc.drawPolygon( pointArray );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
- assertTrue( Arrays.equals( pointArray, operation.points ) );
- assertTrue( operation.close );
- assertFalse( operation.fill );
- }
-
public void testDrawPolygonWithNullArgument() {
- GC gc = new GC( display );
try {
gc.drawPolygon( null );
} catch( IllegalArgumentException expected ) {
}
}
- public void testFillPolygon() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- int[] pointArray = new int[] { 1, 2, 3, 4 };
- gc.fillPolygon( pointArray );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
- assertTrue( Arrays.equals( pointArray, operation.points ) );
- assertTrue( operation.close );
- assertTrue( operation.fill );
- }
-
public void testFillPolygonWithNullArgument() {
- GC gc = new GC( display );
try {
gc.fillPolygon( null );
} catch( IllegalArgumentException expected ) {
}
}
- public void testDrawPolyline() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- int[] pointArray = new int[] { 1, 2, 3, 4 };
- gc.drawPolyline( pointArray );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawPolyline operation = ( DrawPolyline )gcOperations[ 0 ];
- assertTrue( Arrays.equals( pointArray, operation.points ) );
- assertFalse( operation.close );
- assertFalse( operation.fill );
- }
-
public void testDrawPolylineWithNullArgument() {
- GC gc = new GC( display );
try {
gc.drawPolyline( null );
} catch( IllegalArgumentException expected ) {
}
}
- public void testDrawText() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawText( "text", 10, 10, SWT.DRAW_TRANSPARENT );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawText operation = ( DrawText )gcOperations[ 0 ];
- assertEquals( "text", operation.text );
- assertEquals( 10, operation.x );
- assertEquals( 10, operation.y );
- assertEquals( SWT.DRAW_TRANSPARENT, operation.flags );
- }
-
public void testDrawTextWithNullString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
try {
gc.drawText( null, 10, 10, SWT.DRAW_TRANSPARENT );
fail( "null argument is not allowed on drawText" );
@@ -1053,29 +490,7 @@ public class GC_Test extends TestCase {
}
}
- public void testDrawTextWithEmptyString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawText( "", 10, 10, SWT.DRAW_TRANSPARENT );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
- public void testDrawString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawString( "text", 10, 10, true );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawText operation = ( DrawText )gcOperations[ 0 ];
- assertEquals( "text", operation.text );
- assertEquals( 10, operation.x );
- assertEquals( 10, operation.y );
- assertEquals( SWT.DRAW_TRANSPARENT, operation.flags );
- }
-
public void testDrawStringWithNullString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
try {
gc.drawString( null, 10, 10, true );
fail( "null argument is not allowed on drawText" );
@@ -1083,14 +498,6 @@ public class GC_Test extends TestCase {
}
}
- public void testDrawStringWithEmptyString() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- gc.drawString( "", 10, 10, false );
- GCOperation[] gcOperations = getGCOperations( gc );
- assertEquals( 0, gcOperations.length );
- }
-
public void testDrawImageWithNullImage() {
Control control = new Shell( display );
GC gc = new GC( control );
@@ -1103,8 +510,6 @@ public class GC_Test extends TestCase {
}
public void testDrawImageWithDisposedImage() {
- Control control = new Shell( display );
- GC gc = new GC( control );
Image disposedImage = createImage();
disposedImage.dispose();
try {
@@ -1115,73 +520,22 @@ public class GC_Test extends TestCase {
}
}
- public void testDrawImage() {
- Control control = new Shell( display );
- GC gc = new GC( control );
- Image image = display.getSystemImage( SWT.ICON_INFORMATION );
- gc.drawImage( image, 1, 2 );
- GCOperation[] gcOperations = getGCOperations( gc );
- DrawImage operation = ( DrawImage )gcOperations[ 0 ];
- assertSame( image, operation.image );
- assertEquals( 0, operation.srcX );
- assertEquals( 0, operation.srcY );
- assertEquals( -1, operation.srcWidth );
- assertEquals( -1, operation.srcHeight );
- assertEquals( 1, operation.destX );
- assertEquals( 2, operation.destY );
- assertEquals( -1, operation.destWidth );
- assertEquals( -1, operation.destHeight );
- assertTrue( operation.simple );
- gc.drawImage( image, 1, 2, 3, 4, 5, 6, 7, 8 );
- gcOperations = getGCOperations( gc );
- operation = ( DrawImage )gcOperations[ 1 ];
- assertSame( image, operation.image );
- assertEquals( 1, operation.srcX );
- assertEquals( 2, operation.srcY );
- assertEquals( 3, operation.srcWidth );
- assertEquals( 4, operation.srcHeight );
- assertEquals( 5, operation.destX );
- assertEquals( 6, operation.destY );
- assertEquals( 7, operation.destWidth );
- assertEquals( 8, operation.destHeight );
- assertFalse( operation.simple );
- }
-
public void testDrawImageWithInvalidSourceRegion() {
- Control control = new Shell( display );
- GC gc = new GC( control );
Image image = display.getSystemImage( SWT.ICON_INFORMATION );
- assertTrue( image.getBounds().width < 40 );
- assertTrue( image.getBounds().height < 40 );
+ assertTrue( image.getBounds().width < 40 ); // precondition
+ assertTrue( image.getBounds().height < 40 ); // precondition
try {
gc.drawImage( image, 10, 0, 50, 16, 0, 0, 100, 100 );
fail( "srcWidth larger than srcX + image.width is not allowed" );
- } catch( IllegalArgumentException e ) {
- // expected
+ } catch( IllegalArgumentException expected ) {
}
try {
gc.drawImage( image, 0, 10, 16, 50, 0, 0, 100, 100 );
fail( "srcHeight larger than srcY + image.height is not allowed" );
- } catch( IllegalArgumentException e ) {
- // expected
+ } catch( IllegalArgumentException expected ) {
}
}
- public void testControlGCGetClipping() {
- Shell shell = new Shell( display );
- Canvas canvas = new Canvas( shell, SWT.NONE );
- canvas.setSize( 100, 100 );
- GC gc = new GC( canvas );
- Rectangle clipping = gc.getClipping();
- assertEquals( new Rectangle( 0, 0, 100, 100), clipping );
- }
-
- public void testDisplayGCGetClipping() {
- GC gc = new GC( display );
- Rectangle clipping = gc.getClipping();
- assertEquals( display.getBounds(), clipping );
- }
-
public void testStyle() {
GC gc = new GC( display, SWT.NONE );
assertEquals( SWT.LEFT_TO_RIGHT, gc.getStyle() );
@@ -1194,17 +548,13 @@ public class GC_Test extends TestCase {
protected void setUp() throws Exception {
Fixture.setUp();
display = new Display();
+ gc = new GC( display );
}
protected void tearDown() throws Exception {
Fixture.tearDown();
}
- private static GCOperation[] getGCOperations( final GC gc ) {
- GCAdapter adapter = gc.getGCAdapter();
- return adapter.getGCOperations();
- }
-
private Image createImage() {
ClassLoader loader = Fixture.class.getClassLoader();
InputStream stream = loader.getResourceAsStream( Fixture.IMAGE1 );

Back to the top