/*
* 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.panel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.awt.image.GfrFactoryIconAbs;
import org.geoforge.io.awt.image.GfrFactoryIconAppGfr;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
/**
*
* @author bantchao
*/
abstract public class PnlSelAbs extends PnlAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(PnlSelAbs.class.getName());
static
{
PnlSelAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
protected boolean _blnFieldRequired = false;
protected GfrPnl _pnl = null;
protected ImageIcon _iinReqFieldSet = null;
protected ImageIcon _iinReqFieldUnset = null;
protected JLabel _lblIcon = null;
protected PnlSelAbs(boolean blnFieldRequired)
{
super();
this._blnFieldRequired = blnFieldRequired;
// TEMPO setLayout(new MigLayout("fill, ins 0"));
this._pnl = new GfrPnl();
this._pnl.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
this._lblIcon = new JLabel("");
}
@Override
public void destroy()
{
if (this._pnl != null)
{
for (int i = 0; i < this._pnl.getComponentCount(); i++)
{
Component cmpCur = this._pnl.getComponent(i);
if (cmpCur instanceof IGfrHandlerLifeCycleObject)
{
IGfrHandlerLifeCycleObject obj = (IGfrHandlerLifeCycleObject) cmpCur;
if (obj != null)
{
obj.destroy();
obj = null;
}
}
}
this._pnl = null;
this._lblIcon = null;
}
this._iinReqFieldSet = null;
this._iinReqFieldUnset = null;
}
// !!!
public void setFieldRequired() // may be changed to private
{
if (this._blnFieldRequired)
{
this._lblIcon.setToolTipText("required field");
this._iinReqFieldUnset =
GfrFactoryIconAppGfr.s_getUnsetMandatoryNotOk(GfrFactoryIconAbs.INT_SIZE_XXSMALL); // 11
this._iinReqFieldSet =
GfrFactoryIconAppGfr.s_getTickGreen(GfrFactoryIconAbs.INT_SIZE_XXSMALL // 11
);
if (this._iinReqFieldUnset == null)
{
String str = "this._iinReqFieldWrong_ == null";
PnlSelAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
System.exit(1);
}
if (this._iinReqFieldSet == null)
{
String str = "this._iinReqFieldOk_ == null";
PnlSelAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
System.exit(1);
}
this._lblIcon.setIcon(this._iinReqFieldUnset);
}
else
{
this._lblIcon.setToolTipText("optional field");
ImageIcon iin =
GfrFactoryIconAppGfr.s_getTransparent(GfrFactoryIconAbs.INT_SIZE_XXSMALL);
if (iin == null)
{
String str = "iin == null";
PnlSelAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
System.exit(1);
}
this._lblIcon.setIcon(iin);
}
}
@Override
public boolean init()
{
if (!super.init())
return false;
if(!this._pnl.init())
return false;
setFieldRequired();
this._lblIcon.setHorizontalTextPosition(SwingConstants.RIGHT);
this.setAlignmentX(LEFT_ALIGNMENT);
this._pnl.add(this._lblIcon);
super.setLayout(new BorderLayout());
super.add(this._pnl, BorderLayout.CENTER);
// ending
return true;
}
@Override
public void loadTransient() throws Exception
{
}
@Override
public void releaseTransient() throws Exception
{
}
}