/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.geoforge.guillc.dialog;
import com.toedter.calendar.JCalendar;
import java.awt.BorderLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;
import javax.swing.JFrame;
import org.geoforge.guillc.panel.GfrPnl;
/**
*
* @author bantchao
*/
public class GfrDlgCmdCancelOkPicksDate extends GfrDlgCmdCancelOkAbs implements
PropertyChangeListener
{
private JCalendar _cal_ = null;
private Date _datValue_ = null;
public Date getValue() { return this._datValue_; }
public GfrDlgCmdCancelOkPicksDate(
JFrame frmOwner,
Date datSelected,
Date datFirst,
Date datLast)
{
super(frmOwner,
"Picks date");
super._pnlContents = new GfrPnl();
this._cal_ = new JCalendar(datSelected);
this._datValue_ = datSelected; // memo: pointing to valid date
if (datFirst != null)
this._cal_.setMinSelectableDate(datFirst);
if (datLast != null)
this._cal_.setMaxSelectableDate(datLast);
this._cal_.getDayChooser().addPropertyChangeListener("day", (PropertyChangeListener) this);
}
// TODO: destroy
@Override
public boolean init()
{
if (! super.init())
return false;
super._pnlContents.setLayout(new BorderLayout());
super._pnlContents.add(this._cal_, BorderLayout.CENTER);
super.setEnabledOkCommandDialog(true); // memo: pointing to valid date
return true;
}
@Override
protected boolean _okEnableable()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void propertyChange(PropertyChangeEvent evt)
{
if (evt.getPropertyName().equals("day"))
{
if (((Integer)evt.getNewValue()).intValue() > 0)
{
this._datValue_ = this._cal_.getCalendar().getTime();
super.setEnabledOkCommandDialog(true);
}
else
{
this._datValue_ = null;
super.setEnabledOkCommandDialog(false);
}
return;
}
}
}