source: other-projects/trunk/greenstone3-extension/mat/org/greenstone/gsdl3_extension/mat/DrawSymbolAxis.java@ 17356

Last change on this file since 17356 was 17356, checked in by cc108, 16 years ago

Updating Mat Source Code

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