01: /*
02: * Created on 04/12/2005
03: *
04: * ============================================================================
05: * GNU Lesser General Public License
06: * ============================================================================
07: *
08: * Swing Components - visit http://sf.net/projects/gfd
09: *
10: * Copyright (C) 2004 Igor Regis da Silva Simőes
11: *
12: * This library is free software; you can redistribute it and/or
13: * modify it under the terms of the GNU Lesser General Public
14: * License as published by the Free Software Foundation; either
15: * version 2.1 of the License, or (at your option) any later version.
16: *
17: * This library is distributed in the hope that it will be useful,
18: * but WITHOUT ANY WARRANTY; without even the implied warranty of
19: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20: * Lesser General Public License for more details.
21: *
22: * You should have received a copy of the GNU Lesser General Public
23: * License along with this library; if not, write to the Free Software
24: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25: */
26: package br.com.gfpshare.beans;
27:
28: import java.awt.Component;
29: import java.awt.event.FocusListener;
30: import java.text.ParseException;
31:
32: import javax.swing.JSpinner;
33:
34: /**
35: * Um campo de spin que pode informar ao usuário que ele é de preenchimento obrigatório
36: * @author Igor Regis da Silva Simoes
37: */
38: public class ZSpinner extends JSpinner implements RequiredField {
39:
40: public Object getRequiredValue() {
41: try {
42: commitEdit();
43: } catch (ParseException e) {
44: //Fazemos nada se der erro
45: }
46: return getValue();
47: }
48:
49: /*
50: * @see br.com.igor.beans.RequiredField#isSameComponent(java.awt.Component)
51: */
52: public boolean isSameComponent(Component c) {
53: return c == this ;
54: }
55:
56: /*
57: * @see java.awt.Component#addFocusListener(java.awt.event.FocusListener)
58: */
59: @Override
60: public synchronized void addFocusListener(FocusListener l) {
61: if (this == null
62: || this .getEditor() == null
63: || ((JSpinner.NumberEditor) this .getEditor())
64: .getTextField() == null)
65: return;
66: ((JSpinner.NumberEditor) this.getEditor()).getTextField()
67: .addFocusListener(l);
68: }
69: }
|