| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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); |
| 55 |
|
| 56 |
|
| 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 |
|
| 81 |
editor.setFont(table.getFont()); |
| 82 |
if (value != null) { |
| 83 |
editor.setValue(((Double) value).doubleValue()); |
| 84 |
} |
| 85 |
return editor; |
| 86 |
} |
| 87 |
} |