/[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 1327 - (show annotations) (download)
Fri Sep 7 12:09:59 2007 UTC (16 years, 7 months ago) by iliev
File size: 3093 byte(s)
* Implemented more proper retrieval of the MIDI/audio driver settings
* Implemented new table cell editor for editing string list
  parameters with possibilities
* Some javadoc documentation fixes

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>Copyright (C) 2005 Grigor Kirilov Iliev
4 *
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 * This method implements a cell editor for numbers, using a spinner component.
41 * @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 /** Creates a new instance of <code>NumberCellEditor</code>. */
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 /**
64 * Gets the value contained in the editor.
65 * @return Te value contained in the editor.
66 */
67 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 != null ? value : getModel().getMinimum());
79 return editor;
80 }
81
82 /**
83 * Gets the <code>SpinnerNumberModel</code> used by this editor.
84 * @return The <code>SpinnerNumberModel</code> used by this editor.
85 */
86 public SpinnerNumberModel
87 getModel() { return spinnerModel; }
88
89 /**
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 public void
94 setModel(SpinnerNumberModel model) {
95 spinnerModel = model;
96 editor.setModel(spinnerModel);
97 }
98
99 /**
100 * Sets the minimum value allowed.
101 * @param minimum The new minimum value.
102 */
103 public void
104 setMinimum(Comparable minimum) { getModel().setMinimum(minimum); }
105
106 /**
107 * Sets the maximum value allowed.
108 * @param maximum The new maximum value.
109 */
110 public void
111 setMaximum(Comparable maximum) { getModel().setMaximum(maximum); }
112 }

  ViewVC Help
Powered by ViewVC