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.JWindow;
034: import javax.swing.SwingUtilities;
035: import javax.swing.border.BevelBorder;
036:
037: import br.com.gfpshare.beans.event.ICalendarEvent;
038: import br.com.gfpshare.beans.event.ICalendarEventListener;
039:
040: /**
041: * Janela que exbibe um calendário para o componete de escolha de datas.<br><br>
042: *
043: * Para usá-la deve-se instanciá-la e passar sua referência para o contrutor de ICalendarTextField <br>
044: * Exemplo: <br>
045: * ICalendarTextField texto = new ICalendarTextField(new ICalendarWindow(owner)); <br>
046: * Onde owner é o frame ao qual deve ser associada a janela que exibe o calendário.
047: *
048: * @author Administrador
049: * @created 20/01/2004
050: * @see br.com.gfpshare.beans.ZCalendarTextField br.com.igor.beans.ICalendarPanel
051: */
052: public class ZCalendarWindow extends JWindow implements ICalendar,
053: ICalendarEventListener {
054: private ICalendarField texto = null;
055: private boolean abilitado = false;
056:
057: /**
058: * Cria uma nova instância de ICalendarWindow
059: * @param owner O Frame owner desta janela
060: */
061: public ZCalendarWindow(Frame owner) {
062: super (owner == null ? KeyboardFocusManager
063: .getCurrentKeyboardFocusManager().getFocusedWindow()
064: : owner);
065: setVisible(false);
066: ZCalendarPanel painel = new ZCalendarPanel();
067: painel.setBorder(new BevelBorder(BevelBorder.RAISED));
068: setContentPane(painel);
069: painel.addCalendarListener(this );
070: setSize(180, 150);
071: }
072:
073: /** Cria uma nova instância de ICalendarWindow
074: * @param owner O Frame owner desta janela
075: * @param date A data padrão do calendário
076: * @param texto O componente de texto que receberá o rasultado do calendário
077: */
078: public ZCalendarWindow(Frame owner, Date date, ICalendarField texto) {
079: this (owner);
080: this .texto = texto;
081: }
082:
083: /**
084: * @see br.com.gfpshare.beans.ICalendar#setTextComponent(br.com.gfpshare.beans.ICalendarField)
085: */
086: public void setTextComponent(ICalendarField text) {
087: this .texto = text;
088: }
089:
090: /** Configura a janela passando a data que será exibida por padrão e o ICalendarTextField que
091: * receberá a data selecionada pelo usuário.
092: * @param data A data padrão do calendário
093: */
094: public void setDate(final Date data) {
095: ((ZCalendarPanel) getContentPane()).setDate(data);
096: }
097:
098: /** Trata os eventos de mudança de dia no calendário
099: * @param e Evento de calendário
100: */
101: public void diaSelecionado(ICalendarEvent e) {
102: if (texto != null)
103: texto.setCalendar(((ZCalendarPanel) e.getSource())
104: .getCalendar());
105: }
106:
107: /** Trata os eventos de mudança de mês no calendário
108: * @param e Evento de calendário
109: */
110: public void mesSelecionado(ICalendarEvent e) {
111: if (texto != null)
112: texto.setCalendar(((ZCalendarPanel) e.getSource())
113: .getCalendar());
114: }
115:
116: /** Trata os eventos de mudança de ano no calendário
117: * @param e Evento de calendário
118: */
119: public void anoSelecionado(ICalendarEvent e) {
120: if (texto != null)
121: texto.setCalendar(((ZCalendarPanel) e.getSource())
122: .getCalendar());
123: }
124:
125: /** Trata os eventos de fechamento do calendário
126: * @param e Evento de calendário
127: */
128: public void fechandoCalendario(ICalendarEvent e) {
129: setVisible(false);
130: setAbilitado(false);
131: texto.requestFocus();
132: texto = null;
133: }
134:
135: /** Trata os eventos de abertura do calendário
136: * @param e Evento de calendário
137: */
138: public void abrindoCalendario(ICalendarEvent e) {
139: //Não implementado
140: }
141:
142: /** Indica que o calendário pode ser exibido
143: * @param enabled Booleano indicando se o componente está habilitado para ser exibido
144: */
145: public void setAbilitado(boolean enabled) {
146: if (enabled)
147: SwingUtilities.updateComponentTreeUI(this );
148: abilitado = enabled;
149: }
150:
151: /**
152: * @see br.com.gfpshare.beans.ICalendar#isAbilitado()
153: */
154: public boolean isAbilitado() {
155: return abilitado;
156: }
157: }
|