source: gs3-extensions/mat/trunk/src/org/greenstone/mat/DrawSymbolAxis.java@ 21927

Last change on this file since 21927 was 21927, checked in by sjm84, 14 years ago

Renamed package to org.greenstone.mat from org.greenstone.gsdl3_extension.mat

File size: 2.9 KB
Line 
1package org.greenstone.mat;
2
3import java.awt.Color;
4import java.awt.Font;
5import java.util.ArrayList;
6import javax.swing.JPanel;
7
8import org.jfree.chart.ChartPanel;
9import org.jfree.chart.JFreeChart;
10import org.jfree.chart.axis.NumberAxis;
11import org.jfree.chart.axis.NumberTickUnit;
12import org.jfree.chart.axis.SymbolAxis;
13import org.jfree.chart.plot.XYPlot;
14import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
15import org.jfree.data.xy.XYDataset;
16import org.jfree.data.xy.XYSeries;
17import org.jfree.data.xy.XYSeriesCollection;
18import org.jfree.ui.ApplicationFrame;
19import org.jfree.ui.RefineryUtilities;
20
21public 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}
Note: See TracBrowser for help on using the repository browser.