| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DurationEditor |
|
| 1.0;1 |
| 1 | package org.jtheque.films.view.impl.editors; | |
| 2 | ||
| 3 | /* | |
| 4 | * This file is part of JTheque. | |
| 5 | * | |
| 6 | * JTheque is free software: you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation, either version 3 of the License. | |
| 9 | * | |
| 10 | * JTheque is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | * GNU General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | import javax.swing.JSpinner; | |
| 20 | import javax.swing.JTextField; | |
| 21 | import javax.swing.SpinnerModel; | |
| 22 | import javax.swing.event.ChangeEvent; | |
| 23 | import javax.swing.event.ChangeListener; | |
| 24 | ||
| 25 | /** | |
| 26 | * An editor for JSpinner. This editor can display an int value for a duration. | |
| 27 | * | |
| 28 | * @author Baptiste Wicht | |
| 29 | */ | |
| 30 | public final class DurationEditor extends JTextField implements ChangeListener { | |
| 31 | private static final long serialVersionUID = 3650128325330736407L; | |
| 32 | ||
| 33 | /** | |
| 34 | * Construct a new DurationEditor for a specific spinner. | |
| 35 | * | |
| 36 | * @param spinner The spinner associated to this editor. | |
| 37 | */ | |
| 38 | public DurationEditor(JSpinner spinner) { | |
| 39 | 0 | super(); |
| 40 | ||
| 41 | 0 | setOpaque(true); |
| 42 | ||
| 43 | 0 | SpinnerModel model = spinner.getModel(); |
| 44 | 0 | setText((String) model.getValue()); |
| 45 | 0 | spinner.addChangeListener(this); |
| 46 | ||
| 47 | 0 | setColumns(5); |
| 48 | 0 | setEnabled(false); |
| 49 | 0 | } |
| 50 | ||
| 51 | @Override | |
| 52 | public void stateChanged(ChangeEvent event) { | |
| 53 | 0 | JSpinner spinner = (JSpinner) event.getSource(); |
| 54 | 0 | SpinnerModel model = spinner.getModel(); |
| 55 | 0 | setText((String) model.getValue()); |
| 56 | 0 | } |
| 57 | } |