| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.beauti.priorspanel; |
| 27 |
|
| 28 |
import dr.app.beauti.options.Parameter; |
| 29 |
|
| 30 |
import javax.swing.table.AbstractTableModel; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class PriorTableModel extends AbstractTableModel { |
| 37 |
|
| 38 |
private static final long serialVersionUID = -8864178122484971872L; |
| 39 |
|
| 40 |
String[] columnNames = {"Parameter", "Prior", "Bound", "Description"}; |
| 41 |
private PriorsPanel priorsPanel; |
| 42 |
|
| 43 |
public PriorTableModel(PriorsPanel priorsPanel) { |
| 44 |
this.priorsPanel = priorsPanel; |
| 45 |
} |
| 46 |
|
| 47 |
public int getColumnCount() { |
| 48 |
return columnNames.length; |
| 49 |
} |
| 50 |
|
| 51 |
public int getRowCount() { |
| 52 |
return priorsPanel.parameters.size(); |
| 53 |
} |
| 54 |
|
| 55 |
public Object getValueAt(int row, int col) { |
| 56 |
Parameter param = priorsPanel.parameters.get(row); |
| 57 |
switch (col) { |
| 58 |
case 0: |
| 59 |
return param.getName(); |
| 60 |
case 1: |
| 61 |
return (param.isLinked ? "Linked as [" + param.linkedName + "]" : param.priorType.getPriorString(param)); |
| 62 |
case 2: |
| 63 |
return param.priorType.getPriorBoundString(param); |
| 64 |
case 3: |
| 65 |
return param.getDescription(); |
| 66 |
} |
| 67 |
return null; |
| 68 |
} |
| 69 |
|
| 70 |
public String getColumnName(int column) { |
| 71 |
return columnNames[column]; |
| 72 |
} |
| 73 |
|
| 74 |
public Class getColumnClass(int c) { |
| 75 |
return getValueAt(0, c).getClass(); |
| 76 |
} |
| 77 |
|
| 78 |
public boolean isCellEditable(int row, int col) { |
| 79 |
Parameter param = priorsPanel.parameters.get(row); |
| 80 |
return col == 1 && !param.isPriorFixed; |
| 81 |
} |
| 82 |
|
| 83 |
public String toString() { |
| 84 |
StringBuffer buffer = new StringBuffer(); |
| 85 |
|
| 86 |
buffer.append(getColumnName(0)); |
| 87 |
for (int j = 1; j < getColumnCount(); j++) { |
| 88 |
buffer.append("\t"); |
| 89 |
buffer.append(getColumnName(j)); |
| 90 |
} |
| 91 |
buffer.append("\n"); |
| 92 |
|
| 93 |
for (int i = 0; i < getRowCount(); i++) { |
| 94 |
buffer.append(getValueAt(i, 0)); |
| 95 |
for (int j = 1; j < getColumnCount(); j++) { |
| 96 |
buffer.append("\t"); |
| 97 |
buffer.append(getValueAt(i, j)); |
| 98 |
} |
| 99 |
buffer.append("\n"); |
| 100 |
} |
| 101 |
|
| 102 |
return buffer.toString(); |
| 103 |
} |
| 104 |
} |