Debian Codegraph @

src/dr/app/treespace/CladePanel.java

raw symbols SCIP
1 /*
2 * CladePanel.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.treespace;
27
28 import dr.app.gui.table.MultiLineTableCellRenderer;
29 import dr.app.gui.table.TableEditorStopper;
30 import jam.panels.OptionsPanel;
31
32 import javax.swing.*;
33 import javax.swing.event.ListSelectionEvent;
34 import javax.swing.event.ListSelectionListener;
35 import javax.swing.table.AbstractTableModel;
36 import javax.swing.table.TableColumn;
37 import java.awt.*;
38 import java.awt.event.MouseAdapter;
39 import java.awt.event.MouseEvent;
40
41 /**
42 * @author Andrew Rambaut
43 * @version $Id$
44 */
45 public class CladePanel extends JPanel {
46
47 private static final long serialVersionUID = -3710586474593827540L;
48
49 private final TreeSpaceFrame frame;
50 private final TreeSpaceDocument document;
51 private final CladeTableModel cladeTableModel;
52 private final JTable cladeTable;
53
54 public CladePanel(final TreeSpaceFrame parent, final TreeSpaceDocument document) {
55
56 this.frame = parent;
57 this.document = document;
58
59 cladeTableModel = new CladeTableModel();
60 cladeTable = new JTable(cladeTableModel);
61
62 cladeTable.getTableHeader().setReorderingAllowed(false);
63
64 TableEditorStopper.ensureEditingStopWhenTableLosesFocus(cladeTable);
65
66 cladeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
67 public void valueChanged(ListSelectionEvent evt) {
68 selectionChanged();
69 }
70 });
71
72 cladeTable.addMouseListener(new MouseAdapter() {
73 public void mouseClicked(MouseEvent e) {
74 if (e.getClickCount() == 2) {
75 editSelection();
76 }
77 }
78 });
79
80 JScrollPane scrollPane = new JScrollPane(cladeTable,
81 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
82 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
83 scrollPane.setOpaque(false);
84
85 setLayout(new BorderLayout());
86
87 JPanel panel = new JPanel(new BorderLayout());
88
89 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPane, panel);
90 splitPane.setDividerLocation(240);
91
92 add(splitPane, BorderLayout.CENTER);
93
94 document.addListener(new TreeSpaceDocument.Listener() {
95 public void dataChanged() {
96 cladeTableModel.fireTableDataChanged();
97 }
98
99 public void settingsChanged() {
100 }
101 });
102
103 }
104
105 private void selectionChanged() {
106 }
107
108 private void editSelection() {
109 }
110
111 class CladeTableModel extends AbstractTableModel {
112
113 String[] columnNames = {"Clade", "Frequency"};
114
115 public CladeTableModel() {
116 }
117
118 public int getColumnCount() {
119 return columnNames.length;
120 }
121
122 public int getRowCount() {
123 return document.getCladeSystem().getClades().size();
124 }
125
126 public Object getValueAt(int row, int col) {
127 CladeSystem.Clade clade = document.getCladeSystem().getClades().get(row);
128 switch (col) {
129 case 0:
130 return row + 1;
131 case 1:
132 return clade.getCredibility();
133 default:
134 throw new IllegalArgumentException("unknown column, " + col);
135 }
136 }
137
138 public boolean isCellEditable(int row, int col) {
139 return false;
140 }
141
142 public String getColumnName(int column) {
143 return columnNames[column];
144 }
145
146 public Class getColumnClass(int c) {
147 if (getRowCount() == 0) {
148 return Object.class;
149 }
150 return getValueAt(0, c).getClass();
151 }
152
153 public String toString() {
154 StringBuffer buffer = new StringBuffer();
155
156 buffer.append(getColumnName(0));
157 for (int j = 1; j < getColumnCount(); j++) {
158 buffer.append("\t");
159 buffer.append(getColumnName(j));
160 }
161 buffer.append("\n");
162
163 for (int i = 0; i < getRowCount(); i++) {
164 buffer.append(getValueAt(i, 0));
165 for (int j = 1; j < getColumnCount(); j++) {
166 buffer.append("\t");
167 buffer.append(getValueAt(i, j));
168 }
169 buffer.append("\n");
170 }
171
172 return buffer.toString();
173 }
174
175 }
176
177 }