1 |
iliev |
787 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005 Grigor Kirilov Iliev |
5 |
|
|
* |
6 |
|
|
* This file is part of JSampler. |
7 |
|
|
* |
8 |
|
|
* JSampler is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License version 2 |
10 |
|
|
* as published by the Free Software Foundation. |
11 |
|
|
* |
12 |
|
|
* JSampler is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with JSampler; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
|
|
* MA 02111-1307 USA |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
package org.jsampler.view; |
24 |
|
|
|
25 |
|
|
import java.awt.Component; |
26 |
|
|
|
27 |
|
|
import java.awt.event.MouseEvent; |
28 |
|
|
|
29 |
|
|
import java.util.EventObject; |
30 |
|
|
|
31 |
|
|
import javax.swing.AbstractCellEditor; |
32 |
|
|
import javax.swing.BorderFactory; |
33 |
|
|
import javax.swing.JSpinner; |
34 |
|
|
import javax.swing.JTable; |
35 |
|
|
import javax.swing.SpinnerNumberModel; |
36 |
|
|
|
37 |
|
|
import javax.swing.table.TableCellEditor; |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* |
42 |
|
|
* @author Grigor Iliev |
43 |
|
|
*/ |
44 |
|
|
public class NumberCellEditor extends AbstractCellEditor implements TableCellEditor { |
45 |
|
|
private final JSpinner editor = new JSpinner(); |
46 |
|
|
private SpinnerNumberModel spinnerModel; |
47 |
|
|
|
48 |
|
|
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 |
|
|
public Object |
64 |
|
|
getCellEditorValue() { return editor.getValue(); } |
65 |
|
|
|
66 |
|
|
public Component |
67 |
|
|
getTableCellEditorComponent ( |
68 |
|
|
JTable table, |
69 |
|
|
Object value, |
70 |
|
|
boolean isSelected, |
71 |
|
|
int row, |
72 |
|
|
int column |
73 |
|
|
) { |
74 |
|
|
editor.setValue(value); |
75 |
|
|
return editor; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
public SpinnerNumberModel |
79 |
|
|
getModel() { return spinnerModel; } |
80 |
|
|
|
81 |
|
|
public void |
82 |
|
|
setModel(SpinnerNumberModel model) { |
83 |
|
|
spinnerModel = model; |
84 |
|
|
editor.setModel(spinnerModel); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
public void |
88 |
|
|
setMinimum(Comparable minimum) { getModel().setMinimum(minimum); } |
89 |
|
|
|
90 |
|
|
public void |
91 |
|
|
setMaximum(Comparable maximum) { getModel().setMaximum(maximum); } |
92 |
|
|
} |