Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » New RWT graphic widget GCCanvas
New RWT graphic widget GCCanvas [message #118476] Thu, 15 January 2009 10:44 Go to next message
Mirko Solazzi is currently offline Mirko SolazziFriend
Messages: 1
Registered: July 2009
Junior Member
I've developed a new RWT widget to emulate the SWT GC graphics on a
canvas. The new widget extends the Composite component and allows to draw
figures and graph inside RAP dialogs.
The widget is compatible both with Firefox/Mozilla (use the canvas tag)
and MSIE browsers (includes the google excanvas extension script).

This is a list of the GCCanvas methods:

public class GCCanvas extends Composite
(construnctor)
public GCCanvas(final Composite parent,final int style)

public String drawArc(int x, int y, int width, int height, int startAngle,
int arcAngle)
public String drawImage(String sImagePath, int x, int y)
public String drawImage(String sImagePath, int x, int y,int width , int
height)
public String drawLine(int x1, int y1, int x2, int y2)
public String drawOval(int x, int y, int width, int height)
public String drawPoint(int x, int y)
public String drawPolygon(int[] pointArray)
public String drawPolyline(int[] pointArray)
public String drawRectangle(int x, int y, int width, int height)
public String drawRectangle(Rectangle rect)
public String drawRoundRectangle(int x, int y, int width, int height, int
arcWidth, int arcHeight)
public String drawString(String string, int x, int y)
public String drawText(String string, int x, int y)
public String fillArc(int x, int y, int width, int height, int startAngle,
int arcAngle)
public String fillGradientRectangle(int x, int y, int width, int
height,boolean vertical)
public String fillOval(int x, int y, int width, int height)
public String fillPolygon(int[] pointArray)
public String fillRectangle(int x, int y, int width, int height)
public String fillRoundRectangle(int x, int y, int width, int height, int
arcWidth, int arcHeight)
public void removePath(String pathId)
public void removeAll()
public void setSize(int width, int height)
public void setLineWidth(int width)
public int getLineWidth()
public void setCanvasColor(Color color)
public Color getCanvasColor()
public void setForeground(Color color)
public Color getForeground()
public void setBackground(Color color)
public Color getBackground()
public void setAlpha(int alpha)
public int getAlpha()
public void setGradientBackground(LinearGradient gradient)
public void setGradientBackground(RadialGradient gradient)
public void setFont(Font font)
public Font getFont()

--------------------------------
Notes:
- The GCCanvas can listen to all mouse/key Composite events.
- Each drawing function return the pathID; for MSIE a path with a specific
PathId can be removed from the canvas.

UGAGE EXAMPLE:


package org.eclipse.rwt.widgets ;

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.rwt.graphics.*;
import org.eclipse.swt.SWT;
import org.eclipse.rwt.lifecycle.IEntryPoint;
import org.eclipse.swt.custom.ScrolledComposite;

public class GCCanvasDemo implements IEntryPoint {

GCCanvas canvas;
String sPath;

public int createUI() {
Display display = new Display();
Shell shell = new Shell( display, SWT.SHELL_TRIM );
shell.setLayout( new FillLayout() );
shell.setText( "GCCanvas - RAP element - Demo" );
shell.setSize( 500, 500 );

// Scrolled composite container
ScrolledComposite sccomp= new ScrolledComposite( shell, SWT.V_SCROLL
| SWT.H_SCROLL);

canvas = new GCCanvas( sccomp, SWT.NONE);
canvas.setSize(600,800);
sccomp.setContent(canvas);

canvas.setCanvasColor(Graphics.getColor(new RGB(255,255,255)));
// Set the stroke color (RED)
canvas.setForeground(Graphics.getColor(new RGB(255,0,0)));
canvas.drawLine(180,16,260,150);
// Set canvas cursor
canvas.setCursor(Graphics.getCursor(SWT.CURSOR_CROSS));

// Draw an Image
canvas.drawImage("images/EclipseBannerPic.jpg", 10, 10);
// Draw an Image resized
canvas.drawImage("images/EclipseBannerPic.jpg", 15, 70, 150 , 80);

canvas.drawPolygon(new int[]{
255,18,247,85,290,120,372,106,375,53,322,52 });

// Set the stroke color (GREEN)
canvas.setForeground(Graphics.getColor(new RGB(0,255,0)));

canvas.drawOval(25,180,166,270);

// Change the Line width
canvas.setLineWidth(3);

canvas.drawArc(333,129,367,152,90,200);

canvas.drawPolyline(new int[]{ 180,205,240,180,290,210,300,190});

// Set the stroke color (BLUE)
canvas.setForeground(Graphics.getColor(new RGB(0,0,255)));

canvas.drawRectangle(55,265,116,66);

canvas.setLineWidth(2);
canvas.drawRectangle(new Rectangle(65, 275, 100, 50));

canvas.drawRoundRectangle(215,227,120,150,15,8);

canvas.setForeground(Graphics.getColor(new RGB(0,150,155)));
canvas.setFont(Graphics.getFont("Times New Roman",16,SWT.BOLD));
canvas.drawString("Hello World-16",45,330);

canvas.setForeground(Graphics.getColor(new RGB(0,100,125)));
canvas.setFont(Graphics.getFont("Serif",14,SWT.ITALIC));
canvas.drawString("Hello World-14",55,350);

canvas.setForeground(Graphics.getColor(new RGB(0,250,105)));
canvas.setFont(Graphics.getFont("Verdana",12,SWT.NORMAL));
canvas.drawString("Hello World-12",65,370);

canvas.fillGradientRectangle(410, 15, 100, 50, true);
canvas.setForeground(Graphics.getColor(new RGB(255,50,105)));
canvas.fillGradientRectangle(520, 15, 60, 180, false);


// set the solid Fill color (PURPLE)
canvas.setBackground(Graphics.getColor(new RGB(225,0,225)));

canvas.fillArc(300,350,100,125,-160,220);

canvas.setBackground(Graphics.getColor(new RGB(225,225,0)));

canvas.fillRectangle(444, 315, 80, 120);

// Linear gradient example
GCCanvas.LinearGradient gradient = canvas.new
LinearGradient(0,200,0,405);
gradient.addColorStop(0, "#00ABEB");
gradient.addColorStop((float)0.25, "#ff00ff");
gradient.addColorStop((float)0.5, "#0000ff");
gradient.addColorStop((float)0.7, "#26C000");
gradient.addColorStop(1, "#ffffff");
canvas.setGradientBackground(gradient);

// Set the Opacity: 50%
canvas.setAlpha(50);
sPath = canvas.fillRoundRectangle(105,105,230,205,10,30);

// Radial gradient example
GCCanvas.RadialGradient rgradient = canvas.new
RadialGradient(1,45,10,52,50,150);
gradient.addColorStop(0, "#00ABEB");
gradient.addColorStop((float)0.5001, "#26C000");
gradient.addColorStop(1, "#ffffff");
canvas.setGradientBackground(rgradient);

canvas.fillPolygon(new int[]{ 450,160,400,250,550,200});

canvas.setAlpha(100);
canvas.setGradientBackground(rgradient);
canvas.fillOval(250,250,77,105);


// Add a double click Mouse listener
canvas.addMouseListener( new MouseListener() {
public void mouseDoubleClick(MouseEvent event) {
removePathAndChangeCanvasColor();
}
public void mouseDown(MouseEvent event) {
};
public void mouseUp(MouseEvent event) {
};
});


shell.open();
while( !shell.isDisposed() ) {
if( !display.readAndDispatch() ) {
display.sleep();
}
}
return 0;
}

public void removePathAndChangeCanvasColor() {
// Change the canvas background color and remove an element (only IE)
canvas.setCanvasColor(Graphics.getColor(new RGB(155,155,155)));
canvas.removePath(sPath);
}
}
Re: New RWT graphic widget GCCanvas [message #118808 is a reply to message #118476] Mon, 19 January 2009 21:22 Go to previous message
Benjamin Muskalla is currently offline Benjamin MuskallaFriend
Messages: 237
Registered: July 2009
Senior Member
Just for your information:

Implementation, demos and possible discussions can be found at
https://bugs.eclipse.org/bugs/show_bug.cgi?id=261355

Greets
Benny

Mirko Solazzi wrote:
> I've developed a new RWT widget to emulate the SWT GC graphics on a
> canvas. The new widget extends the Composite component and allows to
> draw figures and graph inside RAP dialogs. The widget is compatible both
> with Firefox/Mozilla (use the canvas tag) and MSIE browsers (includes
> the google excanvas extension script).
> This is a list of the GCCanvas methods:
> public class GCCanvas extends Composite (construnctor)
> public GCCanvas(final Composite parent,final int style)
> public String drawArc(int x, int y, int width, int height, int
> startAngle, int arcAngle) public String drawImage(String sImagePath, int
> x, int y) public String drawImage(String sImagePath, int x, int y,int
> width , int height) public String drawLine(int x1, int y1, int x2, int
> y2) public String drawOval(int x, int y, int width, int height) public
> String drawPoint(int x, int y) public String drawPolygon(int[]
> pointArray) public String drawPolyline(int[] pointArray) public String
> drawRectangle(int x, int y, int width, int height) public String
> drawRectangle(Rectangle rect) public String drawRoundRectangle(int x,
> int y, int width, int height, int arcWidth, int arcHeight) public String
> drawString(String string, int x, int y) public String drawText(String
> string, int x, int y) public String fillArc(int x, int y, int width, int
> height, int startAngle, int arcAngle) public String
> fillGradientRectangle(int x, int y, int width, int height,boolean
> vertical) public String fillOval(int x, int y, int width, int height)
> public String fillPolygon(int[] pointArray) public String
> fillRectangle(int x, int y, int width, int height) public String
> fillRoundRectangle(int x, int y, int width, int height, int arcWidth,
> int arcHeight) public void removePath(String pathId) public void
> removeAll() public void setSize(int width, int height) public void
> setLineWidth(int width)
> public int getLineWidth()
> public void setCanvasColor(Color color)
> public Color getCanvasColor()
> public void setForeground(Color color)
> public Color getForeground()
> public void setBackground(Color color)
> public Color getBackground()
> public void setAlpha(int alpha)
> public int getAlpha()
> public void setGradientBackground(LinearGradient gradient) public void
> setGradientBackground(RadialGradient gradient) public void setFont(Font
> font)
> public Font getFont()
> --------------------------------
> Notes:
> - The GCCanvas can listen to all mouse/key Composite events.
> - Each drawing function return the pathID; for MSIE a path with a
> specific PathId can be removed from the canvas.
>
> UGAGE EXAMPLE:
>
>
> package org.eclipse.rwt.widgets ;
>
> import org.eclipse.swt.widgets.*;
> import org.eclipse.swt.layout.*; import org.eclipse.swt.events.MouseEvent;
> import org.eclipse.swt.events.MouseListener;
> import org.eclipse.swt.graphics.Rectangle;
> import org.eclipse.swt.graphics.RGB;
> import org.eclipse.rwt.graphics.*;
> import org.eclipse.swt.SWT;
> import org.eclipse.rwt.lifecycle.IEntryPoint;
> import org.eclipse.swt.custom.ScrolledComposite;
>
> public class GCCanvasDemo implements IEntryPoint {
>
> GCCanvas canvas;
> String sPath;
> public int createUI() {
> Display display = new Display();
> Shell shell = new Shell( display, SWT.SHELL_TRIM );
> shell.setLayout( new FillLayout() );
> shell.setText( "GCCanvas - RAP element - Demo" );
> shell.setSize( 500, 500 );
> // Scrolled composite container ScrolledComposite sccomp=
> new ScrolledComposite( shell, SWT.V_SCROLL | SWT.H_SCROLL);
> canvas = new GCCanvas( sccomp, SWT.NONE);
> canvas.setSize(600,800);
> sccomp.setContent(canvas);
> canvas.setCanvasColor(Graphics.getColor(new RGB(255,255,255)));
> // Set the stroke color (RED)
> canvas.setForeground(Graphics.getColor(new RGB(255,0,0)));
> canvas.drawLine(180,16,260,150);
> // Set canvas cursor
> canvas.setCursor(Graphics.getCursor(SWT.CURSOR_CROSS));
> // Draw an Image
> canvas.drawImage("images/EclipseBannerPic.jpg", 10, 10); //
> Draw an Image resized
> canvas.drawImage("images/EclipseBannerPic.jpg", 15, 70, 150 , 80);
> canvas.drawPolygon(new int[]{
> 255,18,247,85,290,120,372,106,375,53,322,52 });
> // Set the stroke color (GREEN)
> canvas.setForeground(Graphics.getColor(new RGB(0,255,0)));
> canvas.drawOval(25,180,166,270); // Change the Line
> width
> canvas.setLineWidth(3);
> canvas.drawArc(333,129,367,152,90,200);
> canvas.drawPolyline(new int[]{ 180,205,240,180,290,210,300,190});
> // Set the stroke color (BLUE)
> canvas.setForeground(Graphics.getColor(new RGB(0,0,255)));
> canvas.drawRectangle(55,265,116,66);
> canvas.setLineWidth(2);
> canvas.drawRectangle(new Rectangle(65, 275, 100, 50));
> canvas.drawRoundRectangle(215,227,120,150,15,8);
> canvas.setForeground(Graphics.getColor(new RGB(0,150,155)));
> canvas.setFont(Graphics.getFont("Times New Roman",16,SWT.BOLD));
> canvas.drawString("Hello World-16",45,330);
> canvas.setForeground(Graphics.getColor(new RGB(0,100,125)));
> canvas.setFont(Graphics.getFont("Serif",14,SWT.ITALIC));
> canvas.drawString("Hello World-14",55,350);
> canvas.setForeground(Graphics.getColor(new RGB(0,250,105)));
> canvas.setFont(Graphics.getFont("Verdana",12,SWT.NORMAL));
> canvas.drawString("Hello World-12",65,370);
> canvas.fillGradientRectangle(410, 15, 100, 50, true);
> canvas.setForeground(Graphics.getColor(new RGB(255,50,105)));
> canvas.fillGradientRectangle(520, 15, 60, 180, false);
> // set the solid Fill color (PURPLE)
> canvas.setBackground(Graphics.getColor(new RGB(225,0,225)));
> canvas.fillArc(300,350,100,125,-160,220);
> canvas.setBackground(Graphics.getColor(new RGB(225,225,0)));
> canvas.fillRectangle(444, 315, 80, 120);
> // Linear gradient example
> GCCanvas.LinearGradient gradient = canvas.new
> LinearGradient(0,200,0,405);
> gradient.addColorStop(0, "#00ABEB");
> gradient.addColorStop((float)0.25, "#ff00ff");
> gradient.addColorStop((float)0.5, "#0000ff");
> gradient.addColorStop((float)0.7, "#26C000");
> gradient.addColorStop(1, "#ffffff");
> canvas.setGradientBackground(gradient);
> // Set the Opacity: 50%
> canvas.setAlpha(50);
> sPath = canvas.fillRoundRectangle(105,105,230,205,10,30);
> // Radial gradient example
> GCCanvas.RadialGradient rgradient = canvas.new
> RadialGradient(1,45,10,52,50,150);
> gradient.addColorStop(0, "#00ABEB");
> gradient.addColorStop((float)0.5001, "#26C000");
> gradient.addColorStop(1, "#ffffff");
> canvas.setGradientBackground(rgradient);
> canvas.fillPolygon(new int[]{ 450,160,400,250,550,200});
> canvas.setAlpha(100);
> canvas.setGradientBackground(rgradient);
> canvas.fillOval(250,250,77,105); // Add a double
> click Mouse listener
> canvas.addMouseListener( new MouseListener() {
> public void mouseDoubleClick(MouseEvent event) {
> removePathAndChangeCanvasColor();
> }
> public void mouseDown(MouseEvent event) {
> };
> public void mouseUp(MouseEvent event) {
> };
> });
> shell.open();
> while( !shell.isDisposed() ) {
> if( !display.readAndDispatch() ) {
> display.sleep();
> }
> }
> return 0;
> }
> public void removePathAndChangeCanvasColor() {
> // Change the canvas background color and remove an element (only
> IE)
> canvas.setCanvasColor(Graphics.getColor(new RGB(155,155,155)));
> canvas.removePath(sPath); }
> }
>
>
>
Previous Topic:the supposed uploaded file doesn't exist on disk after successful upload process
Next Topic:KeyListener and VerifyText on Text can't co-exist ?
Goto Forum:
  


Current Time: Fri Nov 08 23:55:47 GMT 2024

Powered by FUDForum. Page generated in 0.02779 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top