Debian Codegraph @

src/dr/app/treespace/TreePanel.java

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