Debian Codegraph @

src/dr/app/bss/TaxaTableModel.java

raw symbols SCIP
1 /*
2 * TaxaTableModel.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 /**
31 * @author Filip Bielejec
32 * @version $Id$
33 */
34 @SuppressWarnings("serial")
35 public class TaxaTableModel extends AbstractTableModel {
36
37 private PartitionDataList dataList;
38
39 private String[] COLUMN_NAMES = { "Name", "Height", "Data-set" };
40 private double[] heights = null;
41 private String[] trees = null;
42
43 public final static int NAME_INDEX = 0;
44 public final static int HEIGHT_INDEX = 1;
45 public final static int TAXA_SET_INDEX = 2;
46
47 public TaxaTableModel(PartitionDataList dataList) {
48 this.dataList = dataList;
49 }// END: Constructor
50
51 public int getColumnCount() {
52 return COLUMN_NAMES.length;
53 }
54
55 public int getRowCount() {
56 return this.dataList.allTaxa.getTaxonCount();
57 }
58
59 public Class<? extends Object> getColumnClass(int c) {
60 return getValueAt(0, c).getClass();
61 }
62
63 public boolean isCellEditable(int row, int col) {
64 return false;
65 }
66
67 public String getColumnName(int column) {
68 return COLUMN_NAMES[column];
69 }
70
71 public Object getValueAt(int row, int col) {
72 switch (col) {
73
74 case NAME_INDEX:
75 return this.dataList.allTaxa.getTaxonId(row);
76
77 case HEIGHT_INDEX:
78
79 if (heights != null) {
80 return heights[row];
81 } else {
82 return 0.0;
83 }
84
85 case TAXA_SET_INDEX:
86
87 if (trees != null) {
88 return trees[row];
89 } else {
90 return "";
91 }
92
93 default:
94 return null;
95
96 }// END: switch
97 }// END: getValueAt
98
99 private void getHeights() {
100
101 heights = new double[dataList.allTaxa.getTaxonCount()];
102 for (int i = 0; i < dataList.allTaxa.getTaxonCount(); i++) {
103
104 heights[i] = (Double) dataList.allTaxa.getTaxon(i).getAttribute(
105 Utils.ABSOLUTE_HEIGHT);
106
107 }// END: taxon loop
108
109 }// END: getHeights
110
111 private void getTrees() {
112
113 trees = new String[dataList.allTaxa.getTaxonCount()];
114 for (int i = 0; i < dataList.allTaxa.getTaxonCount(); i++) {
115
116 trees[i] = (String) dataList.allTaxa.getTaxon(i).getAttribute(
117 Utils.TREE_FILENAME);
118
119 }// END: taxon loop
120
121 }// END: getHeights
122
123 public String toString() {
124 StringBuffer buffer = new StringBuffer();
125
126 buffer.append(getColumnName(0));
127 for (int j = 1; j < getColumnCount(); j++) {
128 buffer.append("\t");
129 buffer.append(getColumnName(j));
130 }
131 buffer.append("\n");
132
133 for (int i = 0; i < getRowCount(); i++) {
134 buffer.append(getValueAt(i, 0));
135 for (int j = 1; j < getColumnCount(); j++) {
136 buffer.append("\t");
137 buffer.append(getValueAt(i, j));
138 }
139 buffer.append("\n");
140 }
141
142 return buffer.toString();
143 }// END: toString
144
145 public void fireTaxaChanged() {
146 getHeights();
147 getTrees();
148 fireTableDataChanged();
149 }// END: fireTaxaChanged
150
151 public void setDataList(PartitionDataList dataList) {
152 this.dataList = dataList;
153 }// END: setDataList
154
155 }// END: TaxaTableModel class