/[svn]/jsampler/trunk/src/org/jsampler/view/NumberCellEditor.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/NumberCellEditor.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 911 - (show annotations) (download)
Mon Aug 7 18:25:58 2006 UTC (17 years, 8 months ago) by iliev
File size: 2996 byte(s)
updating to JSampler 0.3a

1 /*
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 * This method implements a cell editor for numbers, using a spinner component.
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 /** Creates a new instance of <code>NumberCellEditor</code>. */
49 public
50 NumberCellEditor() {
51 editor.setBorder(BorderFactory.createEmptyBorder());
52 spinnerModel = (SpinnerNumberModel)editor.getModel();
53 }
54
55 public boolean
56 isCellEditable(EventObject anEvent) {
57 if(anEvent instanceof MouseEvent) {
58 return ((MouseEvent)anEvent).getClickCount() > 1;
59 }
60
61 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
69 getCellEditorValue() { return editor.getValue(); }
70
71 public Component
72 getTableCellEditorComponent (
73 JTable table,
74 Object value,
75 boolean isSelected,
76 int row,
77 int column
78 ) {
79 editor.setValue(value);
80 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
88 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
95 setModel(SpinnerNumberModel model) {
96 spinnerModel = model;
97 editor.setModel(spinnerModel);
98 }
99
100 /**
101 * Sets the minimum value allowed.
102 * @param minimum The new minimum value.
103 */
104 public void
105 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
112 setMaximum(Comparable maximum) { getModel().setMaximum(maximum); }
113 }

  ViewVC Help
Powered by ViewVC