Getting Started with Eclipse RCP Developer Study Notes - 05.2D Drawing
Advertisements
Study: http://www.blogjava.net/youxia/archive/2006/12/01/84855.html
-------------------------------------------------- --------------------------------------------------
1. New View CanvasView:
package hellorcp.canvas;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
public class CanvasView extends ViewPart {
public Canvas canvas;
@Override
public void createPartControl(Composite parent) {
// TODO Automatically generate method stub
canvas = new Canvas(parent, SWT.NONE);
}
@Override
public void setFocus() {
// TODO Automatically generate method stub
}
}
2. Draw an oval menu DrawOvalAction:
package hellorcp.canvas;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.graphics.GC;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class DrawOvalAction implements IWorkbenchWindowActionDelegate {
IWorkbenchWindow window;
public void dispose() {
// TODO Auto-generated method stub
}
public void init(IWorkbenchWindow arg0) {
this.window = arg0;
}
public void run(IAction arg0) {
IViewReference[] vfs = window.getActivePage().getViewReferences();
IViewPart vw;
for (int i = 0; i < vfs.length; i++) {
vw = vfs[i].getView(false);
if (vw.getTitle().equals(" Paint ")) {
GC gc = new GC(((CanvasView) vw).canvas);
gc.drawOval(80, 50, 100, 100);
gc.dispose();
}
}
}
public void selectionChanged(IAction arg0, ISelection arg1) {
// TODO Auto-generated method stub
}
}
3. Perspective.java amended as follows:
package hellorcp;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class Perspective implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
// FirstView
String editorArea = layout.getEditorArea();
// layout.addView("hellorcp.view.FirstView", IPageLayout.RIGHT, 0.2f,
// editorArea);
// SecondView
// layout.setEditorAreaVisible(false);
// layout.addView("hellorcp.view.SecondView", IPageLayout.RIGHT, 0.5f,
// editorArea);
// OleView
// layout.addView("hellorcp.ole.OleView", IPageLayout.RIGHT, 0.5f,
// editorArea);
// CanvasView
layout.addView("hellorcp.canvas.CanvasView", IPageLayout.RIGHT, 0.5f,
editorArea);
}
}
4. Configuration plugin.xml, fragments are as follows:
1) action:
<action
class ="hellorcp.canvas.DrawOvalAction"
icon ="icons/alt_window_16.gif"
id ="hellorcp.canvas.DrawOvalAction"
label =" Drawing an ellipse "
menubarPath ="hellorcp.firstmenu/additions"
style ="push"
toolbarPath ="additions"
tooltip =" Drawing an ellipse " />
2) view:
<view
name=" Paint " />
5. To save, run, the effect is as follows:
6. Draw a rectangle, gradient rectangle, Photo:
1) Rectangular action:
package hellorcp.canvas;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.graphics.GC;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class DrawRectAction implements IWorkbenchWindowActionDelegate {
IWorkbenchWindow window;
public void dispose() {
// TODO Auto-generated method stub
}
public void init(IWorkbenchWindow arg0) {
this.window = arg0;
}
public void run(IAction arg0) {
IViewReference[] vfs = window.getActivePage().getViewReferences();
IViewPart vw;
for (int i = 0; i < vfs.length; i++) {
vw = vfs[i].getView(false);
if (vw.getTitle().equals(" Paint ")) {
GC gc = new GC(((CanvasView) vw).canvas);
gc.drawRectangle(280, 50, 100, 100);
gc.dispose();
}
}
}
public void selectionChanged(IAction arg0, ISelection arg1) {
// TODO Auto-generated method stub
}
}
2) The gradient rectangle action:
package hellorcp.canvas;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class DrawGradientAction implements IWorkbenchWindowActionDelegate {
IWorkbenchWindow window;
public void dispose() {
// TODO Auto-generated method stub
}
public void init(IWorkbenchWindow arg0) {
this.window = arg0;
}
public void run(IAction arg0) {
IViewReference[] vfs = window.getActivePage().getViewReferences();
IViewPart vw;
for (int i = 0; i < vfs.length; i++) {
vw = vfs[i].getView(false);
if (vw.getTitle().equals(" Paint ")) {
GC gc = new GC(((CanvasView) vw).canvas);
gc.setBackground(window.getShell().getDisplay().getSystemColor(
SWT.COLOR_BLUE));
gc.fillGradientRectangle(80, 200, 100, 100, false);
gc.dispose();
}
}
}
public void selectionChanged(IAction arg0, ISelection arg1) {
// TODO Auto-generated method stub
}
}
3) Picture action:
package hellorcp.canvas;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
public class DrawImageAction implements IWorkbenchWindowActionDelegate {
IWorkbenchWindow window;
public void dispose() {
// TODO Auto-generated method stub
}
public void init(IWorkbenchWindow arg0) {
this.window = arg0;
}
public void run(IAction arg0) {
IViewReference[] vfs = window.getActivePage().getViewReferences();
IViewPart vw;
for (int i = 0; i < vfs.length; i++) {
vw = vfs[i].getView(false);
if (vw.getTitle().equals(" Paint ")) {
GC gc = new GC(((CanvasView) vw).canvas);
Image img = new Image(window.getShell().getDisplay(), "E:\\develop\\RCP\\HelloRCP\\splash.bmp");
gc.drawImage(img, 280, 200);
gc.dispose();
}
}
}
public void selectionChanged(IAction arg0, ISelection arg1) {
// TODO Auto-generated method stub
}
}
4) action configuration:
<action
class ="hellorcp.canvas.DrawRectAction"
icon ="icons/alt_window_16.gif"
id ="hellorcp.canvas.DrawRectAction"
label =" Draw a rectangle "
menubarPath ="hellorcp.firstmenu/additions"
style ="push"
toolbarPath ="additions"
tooltip =" Draw a rectangle " />
<action
class ="hellorcp.canvas.DrawGradientAction"
icon ="icons/alt_window_16.gif"
id ="hellorcp.canvas.DrawGradientAction"
label =" Draw a gradient rectangles "
menubarPath ="hellorcp.firstmenu/additions"
style ="push"
toolbarPath ="additions"
tooltip =" Draw a gradient rectangles " />
<action
class ="hellorcp.canvas.DrawImageAction"
icon ="icons/alt_window_16.gif"
id ="hellorcp.canvas.DrawImageAction"
label =" Drawn pictures "
menubarPath ="hellorcp.firstmenu/additions"
style ="push"
toolbarPath ="additions"
tooltip =" Drawn pictures " />
5) Save and run, the effect is as follows:
7. Add the Paint event listener (settlement of the window minimized or obscured by another window, the graphics will go away), the modified CanvasView:
package hellorcp.canvas;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
public class CanvasView extends ViewPart {
public Canvas canvas;
@Override
public void createPartControl(Composite parent) {
// TODO Automatically generate method stub
canvas = new Canvas(parent, SWT.NONE);
// Increase Paint listener , Avoid window changes disappear after drawing
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
// Draws an ellipse
e.gc.drawOval(80, 50, 100, 100);
// Draw a rectangle
e.gc.drawRectangle(280, 50, 100, 100);
// To draw a gradient rectangles
e.gc.setBackground(PlatformUI.getWorkbench().getDisplay()
.getSystemColor(SWT.COLOR_BLUE));
e.gc.fillGradientRectangle(80, 200, 100, 100, false);
// Draw graphics
Image img = new Image(PlatformUI.getWorkbench().getDisplay(),
"E:\\develop\\RCP\\HelloRCP\\splash.bmp");
e.gc.drawImage(img, 280, 200);
}
});
}
@Override
public void setFocus() {
// TODO Automatically generate method stub
}
}
Related Posts of Getting Started with Eclipse RCP Developer Study Notes - 05.2D Drawing
-
Getting Started with Eclipse RCP Developer Study Notes - 06.OpenGL
-------------------------------------------------- ------------------------------------------------- Study: http://www.blogjava.net/youxia/archive/2006/12/09/86513.html -------------------------------------------------- -----------------------------------
-
Getting Started with Eclipse RCP Developer Study Notes - 01.Hello RCP
Recent eager to want to learn all aspects of the desktop client development, in addition to work is only beginning to learn a bit of time outside of Delphi, as well as U read a little bit of time VB, VC contacts, in this area can be called super do not qu
-
Getting Started with Eclipse RCP development study notes - 03. View
-------------------------------------------------- ---------------------------------------------- Study: http://www.blogjava.net/youxia/archive/2006/11/24/83377.html -------------------------------------------------- --------------------------------- ...
-
Getting Started with Eclipse RCP development study notes - 02. Menus and dialog boxes
-------------------------------------------------- -------------------------------------------- Study: http://www.blogjava.net/youxia/archive/2006/11/20/82388.html -------------------------------------------------- ----------------------------------------
-
Getting Started with Eclipse RCP development study notes - 04. In Windows, use the Active X control
-------------------------------------------------- ------------------------------------------------- Study: http://www.blogjava.net/youxia/archive/2006/11/28/84013.html -------------------------------------------------- ------------------------------ ...
-
Android drawing study summary (5) - Paint
Android drawing study summary (5) - Paint Previous drawing study concluded a series of Android , we were learning a Bitmap , Drawable , Aniamtion , in addition to the drawing elements, the development of applications using the most or the String (str
-
Android Study Notes (2) - build Android development platform
Eclipse + Android SDK First, download the Eclipse http://www.eclipse.org/downloads/ Select Eclipse IDE for Java Developers (85 MB) version Second, download the Android SDK http://developer.android.com/sdk/download.html?v=android-sdk-windows-1.1_r1.zip I c
-
Getting Started with Eclipse RCP development study notes - 07. Summary
Follow the "Seaside Momo" series of articles had started studying the development of the RCP has been a general understanding of the increasing interest in this area, of course, if you really want to develop a practical small Dongdong years, Lea
-
android study notes -1 - environment to build
1. Install JDK1.6, Eclipse3.6 2. Installing android SDK http://developer.android.com.nyud.net/sdk/index.html 3. Install Eclipse plug-in ADT (android development tool) 1. Start Eclipse, then select Help> Install New Software .... 2. Click Add, in t
-
Oracle study notes (5) in PLSQL cursor to obtain the data used in
This is the fifth chapter of the study notes, study complete database of Chapter IV of the operation and affairs, began to learn the use of a cursor ... ..., I hope that we can give some support ah! Programming tools is PLSQL Developer 7.1.4 Implicit curs












