1 44 45 package org.jfree.data.xy; 46 47 import javax.swing.table.AbstractTableModel ; 48 import javax.swing.table.TableModel ; 49 50 import org.jfree.data.general.DatasetChangeEvent; 51 import org.jfree.data.general.DatasetChangeListener; 52 53 67 public class XYDatasetTableModel extends AbstractTableModel 68 implements TableModel , DatasetChangeListener { 69 70 71 TableXYDataset model = null; 72 73 76 public XYDatasetTableModel() { 77 super(); 78 } 79 80 85 public XYDatasetTableModel(TableXYDataset dataset) { 86 this(); 87 this.model = dataset; 88 this.model.addChangeListener(this); 89 } 90 91 96 public void setModel(TableXYDataset dataset) { 97 this.model = dataset; 98 this.model.addChangeListener(this); 99 fireTableDataChanged(); 100 } 101 102 107 public int getRowCount() { 108 if (this.model == null) { 109 return 0; 110 } 111 return this.model.getItemCount(); 112 } 113 114 119 public int getColumnCount() { 120 if (this.model == null) { 121 return 0; 122 } 123 return this.model.getSeriesCount() + 1; 124 } 125 126 133 public String getColumnName(int column) { 134 if (this.model == null) { 135 return super.getColumnName(column); 136 } 137 if (column < 1) { 138 return "X Value"; 139 } 140 else { 141 return this.model.getSeriesKey(column - 1).toString(); 142 } 143 } 144 145 154 public Object getValueAt(int row, int column) { 155 if (this.model == null) { 156 return null; 157 } 158 if (column < 1) { 159 return this.model.getX(0, row); 160 } 161 else { 162 return this.model.getY(column - 1, row); 163 } 164 } 165 166 173 public void datasetChanged(DatasetChangeEvent event) { 174 fireTableDataChanged(); 175 } 176 177 185 public boolean isCellEditable(int row, int column) { 186 return false; 187 } 188 189 196 public void setValueAt(Object value, int row, int column) { 197 if (isCellEditable(row, column)) { 198 } 200 } 201 202 253 } 254 | Popular Tags |