Debian Codegraph @

src/dr/app/bss/TableColumnHider.java

raw symbols SCIP
1 /*
2 * TableColumnHider.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.util.HashMap;
29 import java.util.Map;
30
31 import javax.swing.JTable;
32 import javax.swing.table.TableColumn;
33 import javax.swing.table.TableColumnModel;
34
35 /**
36 * @author Filip Bielejec
37 * @version $Id$
38 */
39 public class TableColumnHider {
40
41 private JTable table;
42 private TableColumnModel tcm;
43 private Map<String, IndexedColumn> hidden = new HashMap<String, IndexedColumn>();
44
45 public TableColumnHider(JTable table) {
46 this.table = table;
47 this.tcm = this.table.getColumnModel();
48 }// END: Constructor
49
50 public void hide(String columnName) {
51 int index = tcm.getColumnIndex(columnName);
52 TableColumn column = tcm.getColumn(index);
53 IndexedColumn ic = new IndexedColumn(index, column);
54 if (hidden.put(columnName, ic) != null) {
55 throw new IllegalArgumentException("Duplicate column name.");
56 }
57 tcm.removeColumn(column);
58 }// END: hide
59
60 public void show(String columnName) {
61 IndexedColumn ic = hidden.remove(columnName);
62 if (ic != null) {
63 tcm.addColumn(ic.column);
64 int lastColumn = tcm.getColumnCount() - 1;
65 if (ic.index < lastColumn) {
66 tcm.moveColumn(lastColumn, ic.index);
67 }
68 }
69 }// END: show
70
71 private static class IndexedColumn {
72
73 private Integer index;
74 private TableColumn column;
75
76 public IndexedColumn(Integer index, TableColumn column) {
77 this.index = index;
78 this.column = column;
79 }
80 }// END: IndexedColumn
81
82 }// END: class