1 |
iliev |
787 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
iliev |
1143 |
*Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>Copyright (C) 2005 Grigor Kirilov Iliev |
4 |
iliev |
787 |
* |
5 |
|
|
* This file is part of JSampler. |
6 |
|
|
* |
7 |
|
|
* JSampler is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License version 2 |
9 |
|
|
* as published by the Free Software Foundation. |
10 |
|
|
* |
11 |
|
|
* JSampler is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with JSampler; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
19 |
|
|
* MA 02111-1307 USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
package org.jsampler.view; |
23 |
|
|
|
24 |
|
|
import java.awt.Component; |
25 |
|
|
|
26 |
|
|
import java.awt.event.MouseEvent; |
27 |
|
|
|
28 |
|
|
import java.util.EventObject; |
29 |
|
|
|
30 |
|
|
import javax.swing.AbstractCellEditor; |
31 |
|
|
import javax.swing.BorderFactory; |
32 |
|
|
import javax.swing.JSpinner; |
33 |
|
|
import javax.swing.JTable; |
34 |
|
|
import javax.swing.SpinnerNumberModel; |
35 |
|
|
|
36 |
|
|
import javax.swing.table.TableCellEditor; |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
/** |
40 |
iliev |
911 |
* This method implements a cell editor for numbers, using a spinner component. |
41 |
iliev |
787 |
* @author Grigor Iliev |
42 |
|
|
*/ |
43 |
|
|
public class NumberCellEditor extends AbstractCellEditor implements TableCellEditor { |
44 |
|
|
private final JSpinner editor = new JSpinner(); |
45 |
|
|
private SpinnerNumberModel spinnerModel; |
46 |
|
|
|
47 |
iliev |
911 |
/** Creates a new instance of <code>NumberCellEditor</code>. */ |
48 |
iliev |
787 |
public |
49 |
|
|
NumberCellEditor() { |
50 |
|
|
editor.setBorder(BorderFactory.createEmptyBorder()); |
51 |
|
|
spinnerModel = (SpinnerNumberModel)editor.getModel(); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
public boolean |
55 |
|
|
isCellEditable(EventObject anEvent) { |
56 |
|
|
if(anEvent instanceof MouseEvent) { |
57 |
|
|
return ((MouseEvent)anEvent).getClickCount() > 1; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
return false; |
61 |
|
|
} |
62 |
|
|
|
63 |
iliev |
911 |
/** |
64 |
|
|
* Gets the value contained in the editor. |
65 |
|
|
* @return Te value contained in the editor. |
66 |
|
|
*/ |
67 |
iliev |
787 |
public Object |
68 |
|
|
getCellEditorValue() { return editor.getValue(); } |
69 |
|
|
|
70 |
|
|
public Component |
71 |
|
|
getTableCellEditorComponent ( |
72 |
|
|
JTable table, |
73 |
|
|
Object value, |
74 |
|
|
boolean isSelected, |
75 |
|
|
int row, |
76 |
|
|
int column |
77 |
|
|
) { |
78 |
|
|
editor.setValue(value); |
79 |
|
|
return editor; |
80 |
|
|
} |
81 |
|
|
|
82 |
iliev |
911 |
/** |
83 |
|
|
* Gets the <code>SpinnerNumberModel</code> used by this editor. |
84 |
|
|
* @return The <code>SpinnerNumberModel</code> used by this editor. |
85 |
|
|
*/ |
86 |
iliev |
787 |
public SpinnerNumberModel |
87 |
|
|
getModel() { return spinnerModel; } |
88 |
|
|
|
89 |
iliev |
911 |
/** |
90 |
|
|
* Sets the <code>SpinnerNumberModel</code> to be used by this editor. |
91 |
|
|
* @param model The <code>SpinnerNumberModel</code> to be used by this editor. |
92 |
|
|
*/ |
93 |
iliev |
787 |
public void |
94 |
|
|
setModel(SpinnerNumberModel model) { |
95 |
|
|
spinnerModel = model; |
96 |
|
|
editor.setModel(spinnerModel); |
97 |
|
|
} |
98 |
|
|
|
99 |
iliev |
911 |
/** |
100 |
|
|
* Sets the minimum value allowed. |
101 |
|
|
* @param minimum The new minimum value. |
102 |
|
|
*/ |
103 |
iliev |
787 |
public void |
104 |
|
|
setMinimum(Comparable minimum) { getModel().setMinimum(minimum); } |
105 |
|
|
|
106 |
iliev |
911 |
/** |
107 |
|
|
* Sets the maximum value allowed. |
108 |
|
|
* @param maximum The new maximum value. |
109 |
|
|
*/ |
110 |
iliev |
787 |
public void |
111 |
|
|
setMaximum(Comparable maximum) { getModel().setMaximum(maximum); } |
112 |
|
|
} |