`
soleegn
  • 浏览: 142683 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论
阅读更多
  1package com.glnpu.dmp.test;
  2
  3import java.awt.Color;
  4import java.awt.Font;
  5import java.awt.Frame;
  6import java.util.Calendar;
  7import java.util.Date;
  8
  9import org.eclipse.jface.window.ApplicationWindow;
 10import org.eclipse.swt.SWT;
 11import org.eclipse.swt.awt.SWT_AWT;
 12import org.eclipse.swt.graphics.Point;
 13import org.eclipse.swt.widgets.Composite;
 14import org.eclipse.swt.widgets.Control;
 15import org.eclipse.swt.widgets.Display;
 16import org.eclipse.swt.widgets.Shell;
 17import org.eclipse.swt.widgets.TabFolder;
 18import org.eclipse.swt.widgets.TabItem;
 19import org.jfree.chart.ChartFactory;
 20import org.jfree.chart.ChartPanel;
 21import org.jfree.chart.JFreeChart;
 22import org.jfree.chart.plot.PiePlot;
 23import org.jfree.chart.title.TextTitle;
 24import org.jfree.data.category.IntervalCategoryDataset;
 25import org.jfree.data.gantt.Task;
 26import org.jfree.data.gantt.TaskSeries;
 27import org.jfree.data.gantt.TaskSeriesCollection;
 28import org.jfree.data.general.DefaultPieDataset;
 29
 30public class Test extends ApplicationWindow {
 31
 32    /** *//**
 33     * Create the application window
 34     */

 35    public Test() {
 36        super(null);
 37        addToolBar(SWT.FLAT | SWT.WRAP);
 38        addMenuBar();
 39        addStatusLine();
 40    }

 41
 42    /** *//**
 43     * Create contents of the application window
 44     * 
 45     * @param parent
 46     */

 47    @Override
 48    protected Control createContents(Composite parent) {
 49        TabFolder tf = new TabFolder(parent, SWT.TOP);
 50        TabItem ti = new TabItem(tf, SWT.NULL);
 51        ti.setText("分类");
 52        Composite composite = new Composite(tf, SWT.NO_BACKGROUND
 53                | SWT.EMBEDDED);
 54        Frame frame = SWT_AWT.new_Frame(composite);
 55        frame.add(new ChartPanel(createBarChart()));
 56        ti.setControl(composite);
 57        TabItem ti1 = new TabItem(tf, SWT.NULL);
 58        ti1.setText("项目组");
 59        Composite composite1 = new Composite(tf, SWT.NO_BACKGROUND
 60                | SWT.EMBEDDED);
 61        Frame frame1 = SWT_AWT.new_Frame(composite1);
 62        frame1.add(new ChartPanel(createGanttChart()));
 63        ti1.setControl(composite1);
 64        tf.setSelection(0);
 65        return tf;
 66    }

 67
 68    /** *//**
 69     * 方法名称: 内容摘要:
 70     * 
 71     * @return
 72     * @return JFreeChart
 73     * @throws
 74     */

 75    private JFreeChart createGanttChart() {
 76        String title = "Gantt测试";
 77        IntervalCategoryDataset dataset = createSampleDataset();
 78
 79        JFreeChart jfc = ChartFactory.createGanttChart(title, "项目各阶段详细实施计划",
 80                "项目周期", dataset, falsefalsefalse);
 81
 82        return jfc;
 83    }

 84
 85    /** *//**
 86      * 方法名称:
 87      * 内容摘要:创建gantt内容
 88      *
 89      * @return
 90      * @return IntervalCategoryDataset
 91      * @throws
 92     */

 93    private IntervalCategoryDataset createSampleDataset() {
 94        TaskSeries s1 = new TaskSeries("日程表");
 95
 96        Task t1 = new Task("项目立项", date(1, Calendar.APRIL, 2001), date(5,
 97                Calendar.APRIL, 2001));
 98        t1.setPercentComplete(1.00);
 99        
100        Task t2 = new Task("项目立项讨论", date(6, Calendar.APRIL, 2001), date(19,
101                Calendar.APRIL, 2001));
102        
103        s1.add(t1);
104        s1.add(t2);
105        
106        
107        final Task t3 = new Task(
108                "需求分析"
109                date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001)
110            );
111            final Task st31 = new Task(
112                "需求1"
113                date(10, Calendar.APRIL, 2001), date(25, Calendar.APRIL, 2001)
114            );
115            st31.setPercentComplete(1.0);
116            final Task st32 = new Task(
117                "需求2"
118                date(1, Calendar.MAY, 2001), date(5, Calendar.MAY, 2001)
119            );
120            st32.setPercentComplete(1.0);
121            t3.addSubtask(st31);
122            t3.addSubtask(st32);
123            s1.add(t3);
124        
125        
126        
127        final TaskSeriesCollection collection = new TaskSeriesCollection();
128        collection.add(s1);
129
130        return collection;
131    }

132
133    /** *//** */
134    /** *//**
135     * Utility method for creating <code>Date</code> objects.
136     * 
137     * @param day
138     *            日
139     * @param month
140     *            月
141     * @param year
142     *            年
143     * 
144     * @return a date.
145     */

146    private static Date date(final int day, final int month, final int year) {
147
148        final Calendar calendar = Calendar.getInstance();
149        calendar.set(year, month, day);
150
151        final Date result = calendar.getTime();
152        return result;
153
154    }

155
156    /** *//**
157     * 方法名称: 内容摘要:饼图测试
158     * 
159     * @return
160     * @return JFreeChart
161     * @throws
162     */

163    private JFreeChart createBarChart() {
164        String title = "空调2002年市场占有率";
165        DefaultPieDataset piedata = new DefaultPieDataset();
166        piedata.setValue("联想"27.3);
167    
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics