Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles')
-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
5 files changed, 564 insertions, 251 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;
}
}

Back to the top