Debian Codegraph @

src/dr/app/bss/TaxaEditorTableModel.java

raw symbols SCIP
1 /*
2 * TaxaEditorTableModel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.bss;
27
28 import javax.swing.table.AbstractTableModel;
29
30 import dr.evolution.util.Taxa;
31 import dr.evolution.util.Taxon;
32
33 @SuppressWarnings("serial")
34 public class TaxaEditorTableModel extends AbstractTableModel {
35
36 private String[] COLUMN_NAMES = { "Name", "Height" };
37 public final static int NAME_INDEX = 0;
38 public final static int HEIGHT_INDEX = 1;
39
40 private Taxa taxaSet;
41
42 public TaxaEditorTableModel() {
43
44 taxaSet = new Taxa();
45
46 }// END: Constructor
47
48 public void addEmptyRow() {
49 String name = "";
50 Taxon taxon = new Taxon(name);
51 taxon.setAttribute(Utils.ABSOLUTE_HEIGHT, (Double) 0.0);
52 taxaSet.addTaxon(taxon);
53 this.fireTableDataChanged();
54 }// END: addEmptyRow
55
56 public void removeLastRow() {
57 int lastIndex = taxaSet.getTaxonCount() - 1;
58 Taxon taxon = taxaSet.getTaxon(lastIndex);
59 taxaSet.removeTaxon(taxon);
60 this.fireTableDataChanged();
61 }// END: removeLastRow
62
63 public String getColumnName(int column) {
64 return COLUMN_NAMES[column];
65 }
66
67 @Override
68 public int getColumnCount() {
69 return COLUMN_NAMES.length;
70 }// END: getColumnCount
71
72 @Override
73 public int getRowCount() {
74 return taxaSet.getTaxonCount();
75 }// END: getRowCount
76
77 public boolean isCellEditable(int row, int col) {
78 return true;
79 }
80
81 public Class<? extends Object> getColumnClass(int c) {
82 return getValueAt(0, c).getClass();
83 }
84
85 @Override
86 public Object getValueAt(int row, int col) {
87
88 switch (col) {
89
90 case NAME_INDEX:
91
92 return taxaSet.getTaxonId(row);
93
94 case HEIGHT_INDEX:
95
96 return taxaSet.getTaxon(row).getAttribute(Utils.ABSOLUTE_HEIGHT);
97
98 default:
99 return null;
100
101 }// END: switch
102
103 }// END: getValueAt
104
105 public void setValueAt(Object value, int row, int col) {
106
107 switch (col) {
108
109 case NAME_INDEX:
110 taxaSet.setTaxonId(row, (String) value);
111 break;
112
113 case HEIGHT_INDEX:
114 taxaSet.setTaxonAttribute(row, Utils.ABSOLUTE_HEIGHT,
115 (Double) value);
116 break;
117
118 default:
119 break;
120
121 }// END: switch
122 }// END: setValueAt
123
124 public String toString(boolean header) {
125 StringBuffer buffer = new StringBuffer();
126
127 if (header) {
128 buffer.append(getColumnName(0));
129 for (int j = 1; j < getColumnCount(); j++) {
130 buffer.append("\t");
131 buffer.append(getColumnName(j));
132 }
133 buffer.append("\n");
134 }
135
136 for (int i = 0; i < getRowCount(); i++) {
137 buffer.append(getValueAt(i, 0));
138 for (int j = 1; j < getColumnCount(); j++) {
139 buffer.append("\t");
140 buffer.append(getValueAt(i, j));
141 }
142 buffer.append("\n");
143 }
144
145 return buffer.toString();
146 }// END: toString
147
148 public void fireTaxonListChanged() {
149 this.fireTableDataChanged();
150 }// END: fireTaxaChanged
151
152 public void setTaxaSet(Taxa taxaSet) {
153 this.taxaSet = taxaSet;
154 }// END: setTaxonList
155
156 public Taxa getTaxaSet() {
157 return taxaSet;
158 }// END: getTaxonList
159
160 }// END: TaxaEditorTableModel class