38 |
|
|
39 |
|
|
40 |
/** |
/** |
41 |
* |
* This method implements a cell editor for numbers, using a spinner component. |
42 |
* @author Grigor Iliev |
* @author Grigor Iliev |
43 |
*/ |
*/ |
44 |
public class NumberCellEditor extends AbstractCellEditor implements TableCellEditor { |
public class NumberCellEditor extends AbstractCellEditor implements TableCellEditor { |
45 |
private final JSpinner editor = new JSpinner(); |
private final JSpinner editor = new JSpinner(); |
46 |
private SpinnerNumberModel spinnerModel; |
private SpinnerNumberModel spinnerModel; |
47 |
|
|
48 |
|
/** Creates a new instance of <code>NumberCellEditor</code>. */ |
49 |
public |
public |
50 |
NumberCellEditor() { |
NumberCellEditor() { |
51 |
editor.setBorder(BorderFactory.createEmptyBorder()); |
editor.setBorder(BorderFactory.createEmptyBorder()); |
61 |
return false; |
return false; |
62 |
} |
} |
63 |
|
|
64 |
|
/** |
65 |
|
* Gets the value contained in the editor. |
66 |
|
* @return Te value contained in the editor. |
67 |
|
*/ |
68 |
public Object |
public Object |
69 |
getCellEditorValue() { return editor.getValue(); } |
getCellEditorValue() { return editor.getValue(); } |
70 |
|
|
80 |
return editor; |
return editor; |
81 |
} |
} |
82 |
|
|
83 |
|
/** |
84 |
|
* Gets the <code>SpinnerNumberModel</code> used by this editor. |
85 |
|
* @return The <code>SpinnerNumberModel</code> used by this editor. |
86 |
|
*/ |
87 |
public SpinnerNumberModel |
public SpinnerNumberModel |
88 |
getModel() { return spinnerModel; } |
getModel() { return spinnerModel; } |
89 |
|
|
90 |
|
/** |
91 |
|
* Sets the <code>SpinnerNumberModel</code> to be used by this editor. |
92 |
|
* @param model The <code>SpinnerNumberModel</code> to be used by this editor. |
93 |
|
*/ |
94 |
public void |
public void |
95 |
setModel(SpinnerNumberModel model) { |
setModel(SpinnerNumberModel model) { |
96 |
spinnerModel = model; |
spinnerModel = model; |
97 |
editor.setModel(spinnerModel); |
editor.setModel(spinnerModel); |
98 |
} |
} |
99 |
|
|
100 |
|
/** |
101 |
|
* Sets the minimum value allowed. |
102 |
|
* @param minimum The new minimum value. |
103 |
|
*/ |
104 |
public void |
public void |
105 |
setMinimum(Comparable minimum) { getModel().setMinimum(minimum); } |
setMinimum(Comparable minimum) { getModel().setMinimum(minimum); } |
106 |
|
|
107 |
|
/** |
108 |
|
* Sets the maximum value allowed. |
109 |
|
* @param maximum The new maximum value. |
110 |
|
*/ |
111 |
public void |
public void |
112 |
setMaximum(Comparable maximum) { getModel().setMaximum(maximum); } |
setMaximum(Comparable maximum) { getModel().setMaximum(maximum); } |
113 |
} |
} |