Debian Codegraph @

src/dr/app/mapper/application/MeasurementsPanel.java

raw symbols SCIP
1 /*
2 * MeasurementsPanel.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.mapper.application;
27
28 import dr.app.gui.FileDrop;
29 import dr.app.gui.table.DateCellEditor;
30 import dr.app.gui.table.TableEditorStopper;
31 import dr.app.gui.table.TableSorter;
32 import dr.evolution.util.Taxa;
33 import dr.evolution.util.Taxon;
34 import dr.util.DataTable;
35 import jam.framework.Exportable;
36 import jam.table.HeaderRenderer;
37 import jam.table.TableRenderer;
38
39 import javax.swing.*;
40 import javax.swing.border.Border;
41 import javax.swing.event.ListSelectionEvent;
42 import javax.swing.event.ListSelectionListener;
43 import javax.swing.plaf.BorderUIResource;
44 import javax.swing.table.AbstractTableModel;
45 import java.awt.*;
46 import java.util.*;
47 import java.util.List;
48
49 /**
50 * @author Andrew Rambaut
51 * @version $Id: StrainsPanel.java,v 1.17 2006/09/05 13:29:34 rambaut Exp $
52 */
53 public class MeasurementsPanel extends JPanel implements Exportable, MapperDocument.Listener {
54
55 private JScrollPane scrollPane = new JScrollPane();
56 private JTable dataTable = null;
57 private DataTableModel dataTableModel = null;
58
59 private final MapperFrame frame;
60 private final MapperDocument document;
61
62
63 public MeasurementsPanel(final MapperFrame parent, final MapperDocument document) {
64
65 this.frame = parent;
66 this.document = document;
67
68 dataTableModel = new DataTableModel();
69 TableSorter sorter = new TableSorter(dataTableModel);
70 dataTable = new JTable(sorter);
71
72 sorter.setTableHeader(dataTable.getTableHeader());
73
74 dataTable.getTableHeader().setReorderingAllowed(false);
75 dataTable.getTableHeader().setDefaultRenderer(
76 new HeaderRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
77
78 dataTable.getColumnModel().getColumn(0).setCellRenderer(
79 new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
80 dataTable.getColumnModel().getColumn(0).setPreferredWidth(80);
81
82 dataTable.getColumnModel().getColumn(1).setCellRenderer(
83 new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
84 dataTable.getColumnModel().getColumn(1).setPreferredWidth(80);
85 dataTable.getColumnModel().getColumn(1).setCellEditor(
86 new DateCellEditor());
87
88 dataTable.getColumnModel().getColumn(2).setCellRenderer(
89 new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));
90 dataTable.getColumnModel().getColumn(2).setPreferredWidth(80);
91
92 TableEditorStopper.ensureEditingStopWhenTableLosesFocus(dataTable);
93
94 dataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
95 public void valueChanged(ListSelectionEvent evt) {
96 selectionChanged();
97 }
98 });
99
100 scrollPane = new JScrollPane(dataTable,
101 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
102 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
103 scrollPane.setOpaque(false);
104
105 JToolBar toolBar1 = new JToolBar();
106 toolBar1.setFloatable(false);
107 toolBar1.setOpaque(false);
108
109 // toolBar1.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
110 // JButton button = new JButton(clearDatesAction);
111 // PanelUtils.setupComponent(button);
112 // toolBar1.add(button);
113 // button = new JButton(guessDatesAction);
114 // PanelUtils.setupComponent(button);
115 // toolBar1.add(button);
116 // toolBar1.add(new JToolBar.Separator(new Dimension(12, 12)));
117 // final JLabel unitsLabel = new JLabel("Dates specified as ");
118 // toolBar1.add(unitsLabel);
119 // toolBar1.add(unitsCombo);
120 // toolBar1.add(directionCombo);
121
122 setOpaque(false);
123 setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12)));
124 setLayout(new BorderLayout(0, 0));
125
126 add(toolBar1, "North");
127 add(scrollPane, "Center");
128
129 Color focusColor = UIManager.getColor("Focus.color");
130 Border focusBorder = BorderFactory.createMatteBorder(2, 2, 2, 2, focusColor);
131 scrollPane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
132 new FileDrop(null, scrollPane, focusBorder, new FileDrop.Listener() {
133 public void filesDropped(java.io.File[] files) {
134 frame.importMeasurementFiles(files);
135 } // end filesDropped
136 }); // end FileDrop.Listener
137
138 }
139
140 @Override
141 public void taxaChanged() {
142 dataTableModel.fireTableDataChanged();
143 }
144
145 public JComponent getExportableComponent() {
146 return dataTable;
147 }
148
149 public void selectionChanged() {
150 // nothing to do
151 }
152
153 class DataTableModel extends AbstractTableModel {
154
155 String[] columnNames = {"Serum", "Virus", "Titre", "Table"};
156
157 public DataTableModel() {
158 }
159
160 public int getColumnCount() {
161 return columnNames.length;
162 }
163
164 public int getRowCount() {
165 java.util.List<MapperDocument.Measurement> measurementList = document.getMeasurements();
166 return measurementList.size();
167 }
168
169 public Object getValueAt(int row, int col) {
170 MapperDocument.Measurement measurement = document.getMeasurements().get(row);
171
172 switch (col) {
173 case 0:
174 return measurement.columnStrain.getId();
175 case 1:
176 return measurement.rowStrain.getId();
177 case 2:
178 // if (measurement.type == MapperDocument.MeasurementType.THRESHOLD) {
179 // return "<" + measurement.titre;
180 // }
181 return measurement.titre;
182 case 3:
183 return measurement.column;
184 }
185 return null;
186 }
187
188 public void setValueAt(Object aValue, int row, int col) {
189 // java.util.List<Taxon> taxonList = document.getTaxa();
190 //
191 // if (col == 0) {
192 // taxonList.get(row).setId(aValue.toString());
193 // } else if (col == 1) {
194 // Date date = taxonList.get(row).getDate();
195 // if (date != null) {
196 // double d = (Double) aValue;
197 // Date newDate = createDate(d, date.getUnits(), date.isBackwards(), date.getOrigin());
198 // taxonList.get(row).setDate(newDate);
199 // }
200 // }
201 //
202 // timeScaleChanged();
203 }
204
205 public boolean isCellEditable(int row, int col) {
206 // if (col == 0) return true;
207 // if (col == 1) {
208 // Date date = document.getTaxa().get(row).getDate();
209 // return (date != null);
210 // }
211 return false;
212 }
213
214 public String getColumnName(int column) {
215 return columnNames[column];
216 }
217
218 public Class getColumnClass(int c) {
219 return getValueAt(0, c).getClass();
220 }
221
222 public String toString() {
223 StringBuffer buffer = new StringBuffer();
224
225 buffer.append(getColumnName(0));
226 for (int j = 1; j < getColumnCount(); j++) {
227 buffer.append("\t");
228 buffer.append(getColumnName(j));
229 }
230 buffer.append("\n");
231
232 for (int i = 0; i < getRowCount(); i++) {
233 buffer.append(getValueAt(i, 0));
234 for (int j = 1; j < getColumnCount(); j++) {
235 buffer.append("\t");
236 buffer.append(getValueAt(i, j));
237 }
238 buffer.append("\n");
239 }
240
241 return buffer.toString();
242 }
243 }
244 }