1 | package org.greenstone.mat;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.awt.Font;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import javax.swing.JPanel;
|
---|
7 |
|
---|
8 | import org.jfree.chart.ChartPanel;
|
---|
9 | import org.jfree.chart.JFreeChart;
|
---|
10 | import org.jfree.chart.axis.NumberAxis;
|
---|
11 | import org.jfree.chart.axis.NumberTickUnit;
|
---|
12 | import org.jfree.chart.axis.SymbolAxis;
|
---|
13 | import org.jfree.chart.plot.XYPlot;
|
---|
14 | import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
---|
15 | import org.jfree.data.xy.XYDataset;
|
---|
16 | import org.jfree.data.xy.XYSeries;
|
---|
17 | import org.jfree.data.xy.XYSeriesCollection;
|
---|
18 | import org.jfree.ui.ApplicationFrame;
|
---|
19 | import org.jfree.ui.RefineryUtilities;
|
---|
20 |
|
---|
21 | public class DrawSymbolAxis extends ApplicationFrame
|
---|
22 | {
|
---|
23 |
|
---|
24 | private static String[] metadataName;
|
---|
25 | private static String[] documentIDs;
|
---|
26 | private static ArrayList dataset;
|
---|
27 |
|
---|
28 | public DrawSymbolAxis(String string, String[] metadata, String[] ids, ArrayList set) {
|
---|
29 | super(string);
|
---|
30 | metadataName = metadata;
|
---|
31 | documentIDs = ids;
|
---|
32 | dataset = set;
|
---|
33 |
|
---|
34 | JPanel jpanel = createDemoPanel();
|
---|
35 | setContentPane(jpanel);
|
---|
36 |
|
---|
37 | pack();
|
---|
38 | RefineryUtilities.centerFrameOnScreen(this);
|
---|
39 | setVisible(true);
|
---|
40 | }
|
---|
41 |
|
---|
42 | private static JFreeChart createChart(XYDataset xydataset) {
|
---|
43 | SymbolAxis symbolaxis = new SymbolAxis("Document ID", documentIDs);
|
---|
44 | SymbolAxis symbolaxis_0_ = new SymbolAxis("Indexes", metadataName);
|
---|
45 |
|
---|
46 | XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(false, true);
|
---|
47 |
|
---|
48 | XYPlot xyplot = new XYPlot(xydataset,symbolaxis_0_,symbolaxis,
|
---|
49 | xylineandshaperenderer);
|
---|
50 | xyplot.setDomainGridlinePaint(Color.black);
|
---|
51 | xyplot.setRangeGridlinePaint(Color.black);
|
---|
52 |
|
---|
53 | NumberAxis domainAxis = (NumberAxis)xyplot.getDomainAxis();
|
---|
54 | domainAxis.setAutoTickUnitSelection(true);
|
---|
55 | double rangetick = 1;
|
---|
56 | domainAxis.setTickUnit(new NumberTickUnit(rangetick));
|
---|
57 |
|
---|
58 | xyplot.getRenderer().setSeriesPaint(0,Color.blue);
|
---|
59 | xyplot.getRenderer().setSeriesShape(0, xyplot.DEFAULT_LEGEND_ITEM_BOX);
|
---|
60 | JFreeChart jfreechart = new JFreeChart("",new Font("", Font.PLAIN, 12),xyplot,false);
|
---|
61 | return jfreechart;
|
---|
62 | }
|
---|
63 |
|
---|
64 | private static XYDataset createDataset() {
|
---|
65 |
|
---|
66 | XYSeries xyseries = new XYSeries("Series");
|
---|
67 |
|
---|
68 | for(int a= 0; a<dataset.size(); a++){
|
---|
69 | int[] row = (int[])dataset.get(a);
|
---|
70 | for(int b = 0; b<row.length; b++){
|
---|
71 | if(row[b]==1){xyseries.add(a,b);}
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | XYSeriesCollection xyseriescollection = new XYSeriesCollection();
|
---|
76 | xyseriescollection.addSeries(xyseries);
|
---|
77 | return xyseriescollection;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public static JPanel createDemoPanel() {
|
---|
81 | return new ChartPanel(createChart(createDataset()));
|
---|
82 | }
|
---|
83 | public static void main(String[] strings) {
|
---|
84 | DrawSymbolAxis symbolaxisdemo1 = new DrawSymbolAxis("Symbolic Axis Demo", null, null, null);
|
---|
85 |
|
---|
86 | }
|
---|
87 | public void windowClosing(java.awt.event.WindowEvent event){
|
---|
88 | this.dispose();
|
---|
89 | }
|
---|
90 | }
|
---|