1 34 35 package org.jfree.data; 36 37 import javax.swing.table.AbstractTableModel ; 38 import javax.swing.table.TableModel ; 39 40 52 53 public class XYDatasetTableModel extends AbstractTableModel 54 implements TableModel , DatasetChangeListener { 55 56 57 XYDataset model = null; 58 59 62 public XYDatasetTableModel() { 63 super(); 64 } 65 66 71 public XYDatasetTableModel(XYDataset dataset) { 72 this(); 73 setModel(dataset); 74 } 75 76 81 public void setModel(XYDataset dataset) { 82 this.model = dataset; 83 this.model.addChangeListener(this); 84 fireTableDataChanged(); 85 } 86 87 92 public int getRowCount() { 93 if (this.model == null) { 94 return 0; 95 } 96 return this.model.getItemCount(0); 97 } 98 99 104 public int getColumnCount() { 105 if (this.model == null) { 106 return 0; 107 } 108 return this.model.getSeriesCount() + 1; 109 } 110 111 118 public String getColumnName(int column) { 119 if (this.model == null) { 120 return super.getColumnName(column); 121 } 122 if (column < 1) { 123 return "X Value"; 124 } 125 else { 126 return this.model.getSeriesName(column - 1); 127 } 128 } 129 130 139 public Object getValueAt(int row, int column) { 140 if (this.model == null) { 141 return null; 142 } 143 if (column < 1) { 144 return this.model.getXValue(0, row); 145 } 146 else { 147 return model.getYValue(row, column - 1); 148 } 149 } 150 151 158 public void datasetChanged(DatasetChangeEvent datasetChangeEvent) { 159 fireTableDataChanged(); 160 } 161 162 170 public boolean isCellEditable(int row, int column) { 171 return false; 172 } 173 174 181 public void setValueAt(Object value, int row, int column) { 182 if (this.isCellEditable(row, column)) { 183 } 185 } 186 187 228 } 229 | Popular Tags |