Debian Codegraph @

src/dr/app/bss/PartitionsPanel.java

raw symbols SCIP
1 /*
2 * PartitionsPanel.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 jam.framework.Exportable;
29 import jam.panels.ActionPanel;
30 import jam.table.TableRenderer;
31
32 import java.awt.BorderLayout;
33 import java.awt.Insets;
34 import java.awt.event.ActionEvent;
35
36 import javax.swing.AbstractAction;
37 import javax.swing.Action;
38 import javax.swing.JComponent;
39 import javax.swing.JPanel;
40 import javax.swing.JScrollPane;
41 import javax.swing.JTable;
42 import javax.swing.SwingConstants;
43 import javax.swing.event.TableModelEvent;
44 import javax.swing.event.TableModelListener;
45 import javax.swing.table.TableColumn;
46
47
48 /**
49 * @author Filip Bielejec
50 * @version $Id$
51 */
52 @SuppressWarnings("serial")
53 public class PartitionsPanel extends JPanel implements Exportable {
54
55 private PartitionDataList dataList = null;
56
57 private JTable partitionTable = null;
58 private PartitionTableModel partitionTableModel = null;
59 private JTableComboBoxCellEditor jTableComboBoxCellEditor = null;
60
61 private TableColumnHider hider;
62 private JScrollPane scrollPane;
63 private TableColumn column;
64 private int columnIndex;
65 private int partitionsCount;
66
67 private Action addPartitionAction = new AbstractAction("+") {
68 public void actionPerformed(ActionEvent ae) {
69
70 // partitionTableModel.copyPreviousRow();
71 partitionTableModel.addDefaultRow();
72 setPartitions();
73
74 }// END: actionPerformed
75 };
76
77 private Action removePartitionAction = new AbstractAction("-") {
78 public void actionPerformed(ActionEvent ae) {
79 if (partitionsCount > 1) {
80
81 partitionTableModel.deleteRow(partitionsCount - 1);
82 setPartitions();
83
84 }
85 }// END: actionPerformed
86 };
87
88 public PartitionsPanel(PartitionDataList dataList) {
89
90 this.dataList = dataList;
91
92 partitionTable = new JTable();
93 partitionTable.getTableHeader().setReorderingAllowed(false);
94 partitionTable.addMouseListener(new JTableButtonMouseListener(
95 partitionTable));
96
97 partitionTableModel = new PartitionTableModel(this.dataList);
98 partitionTableModel
99 .addTableModelListener(new PartitionTableModelListener());
100 partitionTable.setModel(partitionTableModel);
101
102 hider = new TableColumnHider(partitionTable);
103
104 setLayout(new BorderLayout());
105
106 scrollPane = new JScrollPane(partitionTable,
107 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
108 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
109 RowNumberTable rowNumberTable = new RowNumberTable(partitionTable);
110 scrollPane.setRowHeaderView(rowNumberTable);
111 scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER,
112 rowNumberTable.getTableHeader());
113
114 scrollPane.getViewport().setOpaque(false);
115
116 add(scrollPane, BorderLayout.CENTER);
117
118 //TODO: Input
119 columnIndex = PartitionTableModel.DATA_INDEX;
120 column = partitionTable.getColumnModel().getColumn(
121 columnIndex);
122 column.setCellRenderer(new JTableComboBoxCellRenderer(columnIndex));
123 jTableComboBoxCellEditor = new JTableComboBoxCellEditor(this.dataList);
124 column.setCellEditor(jTableComboBoxCellEditor);
125 column.setMinWidth(100);
126
127 column = partitionTable.getColumnModel().getColumn(
128 PartitionTableModel.FROM_INDEX);
129 column.setCellRenderer(
130 new TableRenderer(SwingConstants.LEFT, new Insets(0, 2,
131 0, 2)));
132 column.setPreferredWidth(80);
133
134 column = partitionTable.getColumnModel().getColumn(
135 PartitionTableModel.TO_INDEX);
136 column.setCellRenderer(
137 new TableRenderer(SwingConstants.LEFT, new Insets(0, 2,
138 0, 2)));
139 column.setPreferredWidth(80);
140
141 column = partitionTable.getColumnModel().getColumn(
142 PartitionTableModel.EVERY_INDEX);
143 column.setCellRenderer(
144 new TableRenderer(SwingConstants.LEFT, new Insets(0, 2,
145 0, 2)));
146 column.setPreferredWidth(80);
147
148 columnIndex = PartitionTableModel.DATA_TYPE_INDEX;
149 column = partitionTable.getColumnModel().getColumn(
150 columnIndex);
151 column.setCellEditor(new JTableComboBoxCellEditor(this.dataList));
152 column.setCellRenderer(new JTableComboBoxCellRenderer(columnIndex));
153
154 column = partitionTable.getColumnModel().getColumn(
155 PartitionTableModel.DEMOGRAPHIC_MODEL_INDEX);
156 column.setCellRenderer(new JTableButtonCellRenderer());
157 column.setCellEditor(new JTableButtonCellEditor());
158
159 column = partitionTable.getColumnModel().getColumn(
160 PartitionTableModel.BRANCH_SUBSTITUTION_MODEL_INDEX);
161 column.setCellRenderer(new JTableButtonCellRenderer());
162 column.setCellEditor(new JTableButtonCellEditor());
163
164 column = partitionTable.getColumnModel().getColumn(
165 PartitionTableModel.FREQUENCY_MODEL_INDEX);
166 column.setCellRenderer(new JTableButtonCellRenderer());
167 column.setCellEditor(new JTableButtonCellEditor());
168
169 column = partitionTable.getColumnModel().getColumn(
170 PartitionTableModel.SITE_RATE_MODEL_INDEX);
171 column.setCellRenderer(new JTableButtonCellRenderer());
172 column.setCellEditor(new JTableButtonCellEditor());
173
174 column = partitionTable.getColumnModel().getColumn(
175 PartitionTableModel.CLOCK_RATE_MODEL_INDEX);
176 column.setCellRenderer(new JTableButtonCellRenderer());
177 column.setCellEditor(new JTableButtonCellEditor());
178
179 String toolTipText = "Leave this field empty to start from a random root sequence.";
180 column = partitionTable.getColumnModel().getColumn(
181 PartitionTableModel.ROOT_SEQUENCE_INDEX);
182 JTableButtonCellRenderer jTableButtonCellRenderer = new JTableButtonCellRenderer();
183 jTableButtonCellRenderer.setColumnToolTipText(toolTipText);
184 column.setCellRenderer(jTableButtonCellRenderer);
185 column.setCellEditor(new JTableButtonCellEditor());
186
187 ActionPanel actionPanel = new ActionPanel(false);
188 actionPanel.setAddAction(addPartitionAction);
189 actionPanel.setRemoveAction(removePartitionAction);
190 add(actionPanel, BorderLayout.SOUTH);
191
192 setPartitions();
193
194 }// END: Constructor
195
196 private void setPartitions() {
197
198 partitionsCount = dataList.size();
199
200 addPartitionAction.setEnabled(true);
201 if (partitionsCount == 1) {
202 removePartitionAction.setEnabled(false);
203 } else {
204 removePartitionAction.setEnabled(true);
205 }
206
207 ColumnResizer.adjustColumnPreferredWidths(partitionTable);
208 }// END: setPartitions
209
210 // Listen to tree choices, set tree model in partition data
211 private class PartitionTableModelListener implements TableModelListener {
212
213 public void tableChanged(TableModelEvent ev) {
214
215 if (ev.getType() == TableModelEvent.UPDATE) {
216 int row = ev.getFirstRow();
217 int column = ev.getColumn();
218
219 if (column == PartitionTableModel.DATA_INDEX) {
220
221 TreesTableRecord value = (TreesTableRecord) partitionTableModel.getValueAt(row,
222 column);
223
224 dataList.get(row).record = (TreesTableRecord) value;
225
226 }// END: column check
227
228 }// END: event check
229
230 // frame.collectAllSettings();
231
232 }// END: tableChanged
233 }// END: InteractiveTableModelListener
234
235 public void hideTreeColumn() {
236 hider.hide(PartitionTableModel.COLUMN_NAMES[PartitionTableModel.DATA_INDEX]);
237 }
238
239 public void showTreeColumn() {
240 hider.show(PartitionTableModel.COLUMN_NAMES[PartitionTableModel.DATA_INDEX]);
241 }
242
243 public JComponent getExportableComponent() {
244 return this;
245 }// END: getExportableComponent
246
247 public void updatePartitionTable(PartitionDataList dataList) {
248 partitionTableModel.setDataList(dataList);
249 setDataList(dataList);
250 setPartitions();
251 jTableComboBoxCellEditor.setDataList(dataList);
252 partitionTableModel.fireTableDataChanged();
253 }// END: updatePartitionTable
254
255 public void setDataList(PartitionDataList dataList) {
256 this.dataList = dataList;
257 }
258
259 }// END: class