Debian Codegraph @

src/dr/app/gui/table/DateCellEditor.java

raw symbols SCIP
1 /*
2 * DateCellEditor.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.gui.table;
27
28 import dr.app.gui.components.RealNumberField;
29
30 import javax.swing.*;
31 import java.awt.*;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34
35
36 public class DateCellEditor extends DefaultCellEditor {
37
38 /**
39 *
40 */
41 private static final long serialVersionUID = 5067833373685886590L;
42 private RealNumberField editor;
43
44 public DateCellEditor() {
45 this(false);
46 }
47
48 public DateCellEditor(boolean allowEmpty) {
49 super(new RealNumberField(0.0, Double.MAX_VALUE));
50
51 editor = (RealNumberField) getComponent();
52 editor.setAllowEmpty(allowEmpty);
53
54 setClickCountToStart(2); //This is usually 1 or 2.
55
56 // Must do this so that editing stops when appropriate.
57 editor.addActionListener(new ActionListener() {
58 public void actionPerformed(ActionEvent e) {
59 fireEditingStopped();
60 }
61 });
62 }
63
64 protected void fireEditingStopped() {
65 super.fireEditingStopped();
66 }
67
68 public Object getCellEditorValue() {
69 return editor.getValue();
70 }
71
72 public Component getTableCellEditorComponent(JTable table,
73 Object value,
74 boolean isSelected,
75 int row,
76 int column) {
77 FontMetrics metrics = table.getFontMetrics(table.getFont());
78 int fontHeight = metrics.getHeight();
79 table.setRowHeight(row, fontHeight + fontHeight / 2);
80 // System.out.println(editor.getPreferredSize() + "\t" + table.getRowHeight(row) + "\t" + table.getHeight());
81 editor.setFont(table.getFont());
82 if (value != null) {
83 editor.setValue(((Double) value).doubleValue());
84 }
85 return editor;
86 }
87 }