/*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.geoforge.guillc.panel;
import java.awt.event.ActionListener;
import javax.swing.AbstractButton;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.geoforge.guillc.radiobutton.GfrRbnSettingsChoiceRandomNo;
import org.geoforge.guillc.radiobutton._temp.IGfrRbn;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
/**
*
* @author bantchao
*/
abstract public class GfrPnlCustomAbs extends GfrPnl implements
ChangeListener,
IGfrRbn
{
protected IGfrHandlerLifeCycleObject _objCustom = null;
protected GfrRbnSettingsChoiceRandomNo _rbn = null;
protected GfrPnlCustomAbs(
ActionListener[] alrsParent,
Object objInit)
{
super();
boolean blnSetSelected = false;
if (objInit != null)
blnSetSelected = true;
this._rbn = new GfrRbnSettingsChoiceRandomNo(alrsParent, blnSetSelected);
this._rbn.addChangeListener((ChangeListener) this);
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._rbn.init())
return false;
if (!this._objCustom.init())
return false;
super.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
super.add(this._rbn);
super.add(((JComponent) this._objCustom));
return true;
}
@Override
public void destroy()
{
if (this._objCustom != null)
{
this._objCustom.destroy();
this._objCustom = null;
}
if (this._rbn != null)
{
this._rbn.destroy();
this._rbn = null;
}
super.destroy();
}
@Override
public AbstractButton getAbstractButton()
{
return this._rbn;
}
@Override
public void setSelected(boolean bln)
{
this._rbn.setSelected(bln);
}
/*
* TODO: optimize this method
*/
@Override
public void stateChanged(ChangeEvent e)
{
if (e.getSource() instanceof GfrRbnSettingsChoiceRandomNo)
{
GfrRbnSettingsChoiceRandomNo rbn = (GfrRbnSettingsChoiceRandomNo) e.getSource();
if (rbn.isSelected())
{
if (((JComponent) this._objCustom).isEnabled())
return;
((JComponent) this._objCustom).setEnabled(true);
return;
}
else
{
if (! ((JComponent) this._objCustom).isEnabled())
return;
((JComponent) this._objCustom).setEnabled(false);
}
return;
}
System.err.println("!!!! GfrPnlCustomAbs.stateChanged(...): Uncaught instanceof e.getSource().getClass().toString(): " + e.getSource().getClass().toString());
System.exit(1);
}
}