在Eclipse RCP中开发JFreeChart示例
来源:互联网 发布:mac给文件夹加密 编辑:程序博客网 时间:2024/04/29 04:27
RCP,就是Rich Client Platform的缩写,即富客户平台,是Eclipse进化的产物(自3.0版以后出现),是Eclipse组织向用户提供的强大的开放性开发平台,能够使用户方便地创建自己的基于Eclipse的应用程序,并且这些应用程序能够得到Eclipse的底层支持。更重要的是,我们可以利用Java创建象Eclipse这么漂亮的桌面程序。
有人说,RCP一定会变得非常流行。因为RCP,可以开发界面象Eclipse这样漂亮的桌面程序。那就来做一个JFreeChat的示例吧。
一、下载JFreeChart包
1.http://www.jfree.org/jfreechart/
2.用到的包:(注,我的开发环境是eclipse3.2)
jcommon-1.0.10.jar
jfreechart-1.0.6.jar
jfreechart-1.0.6-experimental.jar
jfreechart-1.0.6-swt.jar
swtgraphics2d.jar
二、新建项目
在Eclipse下如何建立plug-in的内容在Google上一搜一大把,有些人会觉得乏味,但是没关系,这只是一个快速的起步。下面大致说一下。有不明白的,可以参考http://www.vogella.de/articles/RichClientPlatform/article.html#using_jars,非常的详细
1、建完项目后记得把上面提到的JFreeChart包加入的项目“Propertires”的“Java Build Path”中。
2、还需要在项目的META-INF/MANIFEST.MF文件的“runtime”中加入以上的包,不然运行时会说找不相关的类,如下图
三、建立View
建View在上面文档http://www.vogella.de/articles/RichClientPlatform/article.html#using_jars中5.2. Add a view to your application有讲,我在这里大致上几个图说明一下。
1.点击配置文件的“extensions”,选择"org.eclipse.views",右键,》"new"》"view",
2.点击右边class*.;链接,来创建新的类
3.此类的代码如下
import java.awt.Font;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.experimental.chart.swt.ChartComposite;
public class MyNewView extends ViewPart {
public MyNewView() {
// TODO Auto-generated constructor stub
}
private static PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("猪肉", new Double(43.2));
dataset.setValue("牛肉", new Double(10.0));
dataset.setValue("猪肉", new Double(27.5));
dataset.setValue("羊肉", new Double(17.5));
dataset.setValue("鸡肉", new Double(11.0));
dataset.setValue("鸭肉", new Double(19.4));
return dataset;
}
/** *//**
* Creates a chart.
*
* @param dataset
* the dataset.
*
* @return A chart.
*/
private static JFreeChart createChart(PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart("肉食品消费统计图示例", // chart
// title
dataset, // data
true, // include legend
true, false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionOutlinesVisible(false);
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("没有统计数据");
plot.setCircular(false);
plot.setLabelGap(0.02);
return chart;
}
public void createPartControl(Composite parent) {
JFreeChart chart = createChart(createDataset());
final ChartComposite frame = new ChartComposite(parent, SWT.NONE,
chart, true);
}
/** *//**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}
}
4.修改Perspective类,使程序能够运行
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class Perspective implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
layout.addView("jfreechatrcp.MyNewView", IPageLayout.TOP,IPageLayout.RATIO_MAX, IPageLayout.ID_EDITOR_AREA);
}
}
5.运行程序
META-INF/MANIFEST.MF》》Launch as Eclipse application
四、结果
源代码jfreechatRCP.rar,请自行下载jfreechart包
参考文献
http://www.vogella.de/articles/RichClientPlatform/article.html#firstplugin
http://www.vogella.de/articles/EclipseJFreeChart/article.html
- 在Eclipse RCP中开发JFreeChart示例
- 在Eclipse RCP中开发JFreeChart示例
- 在Eclipse RCP中使用JFreeChart报表
- RCP开发---在一个ViewPart中添加JFreechart报表
- 在Eclipse RCP开发中使用jMock
- 在Eclipse RCP开发中利用Trim Areas
- 在eclipse rcp 开发中 动态的显示视图
- 在RCP View中显示JFreeChart报表完成的代码
- 在Eclipse RCP中使用ResourceNavigator
- 在eclipse rcp项目中使用jni
- 介绍接个实用Eclipse RCP开发示例
- 使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件
- 使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件
- 使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件
- 使用Eclipse RCP进行桌面程序开发(四):在Windows中使用Active X控件
- Eclipse RCP开发基础
- Eclipse RCP开发基础
- Eclipse RCP开发常见问题
- 时间 + 机会 = ?
- 20071022听力原文
- 2007互联网技术发展趋势全解析
- 用Struts1.1进行模块化开发
- 20071023听力原文
- 在Eclipse RCP中开发JFreeChart示例
- 终于在CSDN买了房安了家住了下来(娶妻生子.......嘻嘻)
- JS与Asp.Net的传值
- 说到就会做到
- PHP之现状
- 浏览器(Browser)刷新页面的三种方式
- include_once,require_once,include,require
- 勾股定理
- 星海之源自我介绍