01: /*
02: * Created on 13/09/2004
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.text.NumberFormat;
29:
30: import javax.swing.text.NumberFormatter;
31:
32: /**
33: * @author Igor Regis da Silva Simoes
34: */
35: public class ZMoneyLabel extends ZLabel {
36:
37: /**
38: *
39: */
40: public ZMoneyLabel() {
41: super ();
42: }
43:
44: /**
45: * @param text
46: */
47: public ZMoneyLabel(String text) {
48: super (text);
49: }
50:
51: /**
52: * Seta o novo valor de moeda a ser exibido.
53: * Caso receba um valor inválido simplesmente não o exibe.
54: * @see javax.swing.JLabel#setText(java.lang.String)
55: */
56: @Override
57: public void setText(String text) {
58: NumberFormatter moedaFormatter = new NumberFormatter(
59: NumberFormat.getCurrencyInstance());
60: moedaFormatter.setAllowsInvalid(false);
61: moedaFormatter.setValueClass(Double.class);
62:
63: try {
64: super .setText(moedaFormatter
65: .valueToString(new Double(text)));
66: } catch (Exception e) {
67: //Nao fazemos nada
68: }
69: }
70: }
|