[17365] | 1 | package org.greenstone.gsdl3_extension.mat;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Color;
|
---|
| 4 | import java.awt.Font;
|
---|
| 5 | import java.util.ArrayList;
|
---|
| 6 | import javax.swing.JPanel;
|
---|
| 7 | import org.jfree.chart.ChartPanel;
|
---|
| 8 | import org.jfree.chart.JFreeChart;
|
---|
| 9 | import org.jfree.chart.axis.NumberAxis;
|
---|
| 10 | import org.jfree.chart.axis.NumberTickUnit;
|
---|
| 11 | import org.jfree.chart.axis.SymbolAxis;
|
---|
| 12 | import org.jfree.chart.plot.XYPlot;
|
---|
| 13 | import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
|
---|
| 14 | import org.jfree.data.xy.XYDataset;
|
---|
| 15 | import org.jfree.data.xy.XYSeries;
|
---|
| 16 | import org.jfree.data.xy.XYSeriesCollection;
|
---|
| 17 | import org.jfree.ui.ApplicationFrame;
|
---|
| 18 | import org.jfree.ui.RefineryUtilities;
|
---|
| 19 |
|
---|
| 20 | public 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 | }
|
---|