Debian Codegraph @

src/dr/app/bss/PartitionTableModel.java

raw symbols SCIP
1 /*
2 * PartitionTableModel.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 java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30
31 import javax.swing.JButton;
32 import javax.swing.JComboBox;
33 import javax.swing.table.AbstractTableModel;
34 import javax.swing.text.BadLocationException;
35
36 /**
37 * @author Filip Bielejec
38 * @version $Id$
39 */
40 @SuppressWarnings("serial")
41 public class PartitionTableModel extends AbstractTableModel {
42
43 private PartitionDataList dataList;
44
45 public final static int DATA_INDEX = 0;
46 public final static int FROM_INDEX = 1;
47 public final static int TO_INDEX = 2;
48 public final static int EVERY_INDEX = 3;
49 public final static int DATA_TYPE_INDEX = 4;
50
51 public final static int DEMOGRAPHIC_MODEL_INDEX = 5;
52 public final static int BRANCH_SUBSTITUTION_MODEL_INDEX = 6;
53 public final static int FREQUENCY_MODEL_INDEX = 7;
54
55 public final static int SITE_RATE_MODEL_INDEX = 8;
56 public final static int CLOCK_RATE_MODEL_INDEX = 9;
57 public final static int ROOT_SEQUENCE_INDEX = 10;
58
59 public static String[] COLUMN_NAMES = { "Input", //
60 "From", //
61 "To", //
62 "Every", //
63 "Data Type", //
64 "Tree model", //
65 "Substitution Model", //
66 "Frequencies", //
67 "Site Rate Model", //
68 "Clock Rate Model", //
69 "Root Sequence" //
70 };
71
72 private static final Class<?>[] COLUMN_TYPES = new Class<?>[] {
73 JComboBox.class, // Input
74 Integer.class, // From
75 Integer.class, // To
76 Integer.class, // Every
77 JComboBox.class, // Data type
78 JButton.class, // Demographic model
79 JButton.class, // Substitution Model
80 JButton.class, // Frequencies
81 JButton.class, // Site Rate Model
82 JButton.class, // Clock Rate Model
83 JButton.class // Ancestral Sequence
84 };
85
86 private DemographicModelEditor demographicModelEditor;
87 private BranchSubstitutionModelEditor branchSubstitutionModelEditor;
88 private SiteRateModelEditor siteRateModelEditor;
89 private ClockRateModelEditor clockRateModelEditor;
90 private FrequencyModelEditor frequencyModelEditor;
91 private RootSequenceEditor rootSequenceEditor;
92
93 public PartitionTableModel(PartitionDataList dataList) {
94 this.dataList = dataList;
95 }// END: Constructor
96
97 public void addRow(PartitionData row) {
98 dataList.add(row);
99 fireTableRowsInserted(dataList.size() - 1, dataList.size() - 1);
100 }
101
102 public void addDefaultRow() {
103 dataList.add(new PartitionData());
104 fireTableRowsInserted(dataList.size() - 1, dataList.size() - 1);
105 }
106
107 public void deleteRow(int row) {
108 dataList.remove(row);
109 fireTableDataChanged();
110 }
111
112 @Override
113 public int getColumnCount() {
114 return COLUMN_NAMES.length;
115 }// END: getColumnCount
116
117 @Override
118 public int getRowCount() {
119 return dataList.size();
120 }// END: getRowCount
121
122 @Override
123 public Class<?> getColumnClass(int columnIndex) {
124 return COLUMN_TYPES[columnIndex];
125 }// END: getColumnClass
126
127 public boolean isCellEditable(int row, int column) {
128 switch (column) {
129 case DATA_INDEX:
130 return true;
131 case DEMOGRAPHIC_MODEL_INDEX:
132 return false;
133 case DATA_TYPE_INDEX:
134 return true;
135 case FROM_INDEX:
136 return true;
137 case TO_INDEX:
138 return true;
139 case EVERY_INDEX:
140 return true;
141 case BRANCH_SUBSTITUTION_MODEL_INDEX:
142 return false;
143 case SITE_RATE_MODEL_INDEX:
144 return false;
145 case CLOCK_RATE_MODEL_INDEX:
146 return false;
147 case FREQUENCY_MODEL_INDEX:
148 return false;
149 case ROOT_SEQUENCE_INDEX:
150 return false;
151 default:
152 return false;
153 }
154 }// END: isCellEditable
155
156 public String getColumnName(int column) {
157 return COLUMN_NAMES[column];
158 }// END: getColumnName
159
160 @Override
161 public Object getValueAt(final int row, final int column) {
162 switch (column) {
163
164 case DATA_INDEX:
165
166 return dataList.get(row).record == null ? new TreesTableRecord() : dataList
167 .get(row).record;
168
169 case DEMOGRAPHIC_MODEL_INDEX:
170
171 final JButton topologyButton = new JButton(COLUMN_NAMES[column]);
172 topologyButton
173 .addActionListener(new ListenOpenDemographicModelEditor(row));
174 return topologyButton;
175
176 case DATA_TYPE_INDEX:
177 return PartitionData.dataTypes[dataList.get(row).dataTypeIndex];
178
179 case FROM_INDEX:
180 return dataList.get(row).from;
181
182 case TO_INDEX:
183 return dataList.get(row).to;
184
185 case EVERY_INDEX:
186 return dataList.get(row).every;
187
188 case BRANCH_SUBSTITUTION_MODEL_INDEX:
189
190 final JButton branchSubstModelButton = new JButton(
191 COLUMN_NAMES[column]);
192 branchSubstModelButton
193 .addActionListener(new ListenOpenBranchSubstitutionModelEditor(
194 row));
195 return branchSubstModelButton;
196
197 case SITE_RATE_MODEL_INDEX:
198
199 final JButton siteRateModelButton = new JButton(
200 COLUMN_NAMES[column]);
201 siteRateModelButton
202 .addActionListener(new ListenOpenSiteRateModelEditor(row));
203
204 return siteRateModelButton;
205
206 case CLOCK_RATE_MODEL_INDEX:
207
208 final JButton clockRateModelButton = new JButton(
209 COLUMN_NAMES[column]);
210 clockRateModelButton
211 .addActionListener(new ListenOpenClockRateModelEditor(row));
212 return clockRateModelButton;
213
214 case FREQUENCY_MODEL_INDEX:
215
216 final JButton frequencyModelButton = new JButton(
217 COLUMN_NAMES[column]);
218 frequencyModelButton
219 .addActionListener(new ListenOpenFrequencyModelEditor(row));
220 return frequencyModelButton;
221
222 case ROOT_SEQUENCE_INDEX:
223
224 final JButton ancestralSequenceButton = new JButton(COLUMN_NAMES[column]);
225 ancestralSequenceButton.addActionListener(new ListenOpenRootSequenceEditor(row));
226 return ancestralSequenceButton;
227
228 default:
229 return "Error";
230 }
231
232 }// END: getValueAt
233
234 public void setValueAt(Object value, int row, int column) {
235
236 switch (column) {
237
238 case DATA_INDEX:
239 dataList.get(row).record = (TreesTableRecord) value;
240 break;
241
242 case DATA_TYPE_INDEX:
243 dataList.get(row).dataTypeIndex = (Integer) Utils.arrayIndex(
244 PartitionData.dataTypes, (String) value);
245 break;
246
247 case FROM_INDEX:
248 dataList.get(row).from = (Integer) value;
249 break;
250
251 case TO_INDEX:
252 dataList.get(row).to = (Integer) value;
253 break;
254
255 case EVERY_INDEX:
256 dataList.get(row).every = (Integer) value;
257 break;
258
259 case BRANCH_SUBSTITUTION_MODEL_INDEX:
260 dataList.get(row).substitutionModelIndex = (Integer) value;
261 break;
262
263 case SITE_RATE_MODEL_INDEX:
264 dataList.get(row).siteRateModelIndex = (Integer) value;
265 break;
266
267 case CLOCK_RATE_MODEL_INDEX:
268 dataList.get(row).clockModelIndex = (Integer) value;
269 break;
270
271 case FREQUENCY_MODEL_INDEX:
272 dataList.get(row).frequencyModelIndex = (Integer) value;
273 break;
274
275 default:
276 throw new RuntimeException("Invalid index.");
277 }
278
279 fireTableCellUpdated(row, column);
280
281 }// END: setValueAt
282
283 private class ListenOpenDemographicModelEditor implements ActionListener {
284
285 private int row;
286
287 public ListenOpenDemographicModelEditor(int row) {
288 this.row = row;
289 }// END: Constructor
290
291 public void actionPerformed(ActionEvent ev) {
292
293 demographicModelEditor = new DemographicModelEditor(dataList, row);
294 demographicModelEditor.launch();
295
296 }// END: actionPerformed
297 }// END: ListenOpenDemographicModelEditor
298
299 private class ListenOpenBranchSubstitutionModelEditor implements
300 ActionListener {
301
302 private int row;
303
304 public ListenOpenBranchSubstitutionModelEditor(int row) {
305 this.row = row;
306 }// END: Constructor
307
308 public void actionPerformed(ActionEvent ev) {
309
310 branchSubstitutionModelEditor = new BranchSubstitutionModelEditor(
311 dataList, row);
312 branchSubstitutionModelEditor.launch();
313
314 }// END: actionPerformed
315 }// END: ListenOpenBranchSubstitutionModelEditor
316
317 private class ListenOpenSiteRateModelEditor implements ActionListener {
318 private int row;
319
320 public ListenOpenSiteRateModelEditor(int row) {
321 this.row = row;
322 }
323
324 public void actionPerformed(ActionEvent ev) {
325
326 try {
327 siteRateModelEditor = new SiteRateModelEditor(dataList, row);
328 siteRateModelEditor.launch();
329 } catch (NumberFormatException e) {
330 Utils.handleException(e);
331 } catch (BadLocationException e) {
332 Utils.handleException(e);
333 }
334
335 }// END: actionPerformed
336 }// END: ListenOpenSiteRateModelEditor
337
338 private class ListenOpenClockRateModelEditor implements ActionListener {
339 private int row;
340
341 public ListenOpenClockRateModelEditor(int row) {
342 this.row = row;
343 }
344
345 public void actionPerformed(ActionEvent ev) {
346
347 clockRateModelEditor = new ClockRateModelEditor(dataList, row);
348 clockRateModelEditor.launch();
349
350 }// END: actionPerformed
351 }// END: ListenOpenSiteRateModelEditor
352
353 private class ListenOpenFrequencyModelEditor implements ActionListener {
354 private int row;
355
356 public ListenOpenFrequencyModelEditor(int row) {
357 this.row = row;
358 }
359
360 public void actionPerformed(ActionEvent ev) {
361
362 frequencyModelEditor = new FrequencyModelEditor(dataList, row);
363 frequencyModelEditor.launch();
364
365 }// END: actionPerformed
366 }// END: ListenOpenSiteRateModelEditor
367
368
369 private class ListenOpenRootSequenceEditor implements ActionListener {
370 private int row;
371
372 public ListenOpenRootSequenceEditor(int row) {
373 this.row = row;
374 }
375
376 public void actionPerformed(ActionEvent ev) {
377
378 rootSequenceEditor = new RootSequenceEditor(dataList, row);
379 rootSequenceEditor.launch();
380
381 }// END: actionPerformed
382 }// END: ListenOpenAncestralSequenceEditor
383
384 public void setDataList(PartitionDataList dataList) {
385 this.dataList = dataList;
386 }
387
388 }// END: class