001: /*
002: * Created on 10/01/2004
003: *
004: * ============================================================================
005: * GNU Lesser General Public License
006: * ============================================================================
007: *
008: * Swing Components - visit http://sf.net/projects/gfd
009: *
010: * Copyright (C) 2004 Igor Regis da Silva Simões
011: *
012: * This library is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU Lesser General Public
014: * License as published by the Free Software Foundation; either
015: * version 2.1 of the License, or (at your option) any later version.
016: *
017: * This library is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
020: * Lesser General Public License for more details.
021: *
022: * You should have received a copy of the GNU Lesser General Public
023: * License along with this library; if not, write to the Free Software
024: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
025: */
026:
027: package br.com.gfpshare.beans;
028:
029: import java.awt.Frame;
030: import java.awt.KeyboardFocusManager;
031: import java.util.Date;
032:
033: import javax.swing.JFormattedTextField;
034: import javax.swing.JWindow;
035: import javax.swing.SwingUtilities;
036: import javax.swing.border.BevelBorder;
037:
038: import br.com.gfpshare.beans.event.CalculatorEvent;
039: import br.com.gfpshare.beans.event.MoneyCalculatorEventListener;
040:
041: /**
042: * Janela que exbibe um calendário para o componete de escolha de datas.<br><br>
043: *
044: * Para usá-la deve-se instanciá-la e passar sua referência para o contrutor de ICalendarTextField <br>
045: * Exemplo: <br>
046: * ICalendarTextField texto = new ICalendarTextField(new ICalendarWindow(owner)); <br>
047: * Onde owner é o frame ao qual deve ser associada a janela que exibe o calendário.
048: *
049: * @author Administrador
050: * @created 20/01/2004
051: * @see br.com.gfpshare.beans.ZCalendarTextField br.com.igor.beans.ICalendarPanel
052: */
053: public class ZMoneyCalculatorWindow extends JWindow implements
054: MoneyCalculatorEventListener {
055: private JFormattedTextField texto = null;
056: private boolean abilitado = false;
057: private MoneyCalculatorPanel painel = null;
058:
059: /**
060: * Cria uma nova instância de ICalendarWindow
061: * @param owner O Frame owner desta janela
062: */
063: public ZMoneyCalculatorWindow(Frame owner) {
064: super (owner == null ? KeyboardFocusManager
065: .getCurrentKeyboardFocusManager().getFocusedWindow()
066: : owner);
067: setVisible(false);
068: painel = new MoneyCalculatorPanel();
069: painel.setBorder(new BevelBorder(BevelBorder.RAISED));
070: setContentPane(painel);
071: painel.addMoneyCalculatorEventListener(this );
072: setSize(190, 180);
073: }
074:
075: /** Cria uma nova instância de ICalendarWindow
076: * @param owner O Frame owner desta janela
077: * @param date A data padrão do calendário
078: * @param texto O componente de texto que receberá o rasultado do calendário
079: */
080: public ZMoneyCalculatorWindow(Frame owner, Date date,
081: JFormattedTextField texto) {
082: this (owner);
083: this .texto = texto;
084: }
085:
086: /**
087: * @param text Seta o componente de edição de texto usado.
088: */
089: public void setTextComponent(JFormattedTextField text) {
090: this .texto = text;
091: }
092:
093: /** Configura a janela passando a data que será exibida por padrão e o ICalendarTextField que
094: * receberá a data selecionada pelo usuário.
095: * @param value valor padrão do calendário
096: */
097: public void setValue(Object value) {
098: ((MoneyCalculatorPanel) getContentPane()).setValue(value);
099: }
100:
101: /** Trata os eventos de fechamento do calendário
102: * @param e Evento de calendário
103: */
104: public void fechandoCalculadora(CalculatorEvent e) {
105: setVisible(false);
106: setAbilitado(false);
107: if (texto != null)
108: texto.requestFocus();
109: }
110:
111: /** Trata os eventos de abertura do calendário
112: * @param e Evento de calendário
113: */
114: public void abrindoCalculadora(CalculatorEvent e) {
115: //Não implementado
116: }
117:
118: /** Indica que o calendário pode ser exibido
119: * @param enabled Booleano indicando se o componente está habilitado para ser exibido
120: */
121: public void setAbilitado(boolean enabled) {
122: if (enabled)
123: SwingUtilities.updateComponentTreeUI(this );
124: abilitado = enabled;
125: painel.setAtivo(enabled);
126: }
127:
128: /**
129: * @see br.com.gfpshare.beans.event.MoneyCalculatorEventListener#isAbilitado()
130: */
131: public boolean isAbilitado() {
132: return abilitado;
133: }
134:
135: /**
136: * @see br.com.gfpshare.beans.event.MoneyCalculatorEventListener#valorAlterado(br.com.gfpshare.beans.event.CalculatorEvent)
137: */
138: public void valorAlterado(CalculatorEvent e) {
139: if (texto != null) {
140: if (((MoneyCalculatorPanel) e.getSource()).getValue() != null
141: && !((MoneyCalculatorPanel) e.getSource())
142: .getValue().equals(""))
143: try {
144: texto.setValue(Double
145: .valueOf(((MoneyCalculatorPanel) e
146: .getSource()).getValue()));
147: } catch (Exception ex) {
148: texto.setValue(null);
149: }
150: else
151: texto.setValue(null);
152: }
153: }
154: }
|