/*
* 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.Component;
import java.util.logging.Logger;
import javax.swing.JPanel;
import javax.swing.plaf.PanelUI;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.io.handler.IGfrHandlerUnserializedObject;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.geoforge.lang.handler.IGfrHandlerTransitoryObject;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
abstract public class PnlAbs extends JPanel implements
IGfrHandlerLifeCycleObject,
IGfrHandlerTransitoryObject,
IGfrHandlerUnserializedObject
{
// ----
// begin: instantiate logger for this class
final static private Logger _LOGGER_ = Logger.getLogger(PnlAbs.class.getName());
static
{
PnlAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
@Override
abstract public void loadTransient() throws Exception;
protected PnlAbs()
{
super();
}
@Override
public void setUI(PanelUI ui)
{
try
{
super.setUI(ui);
}
catch (ClassCastException exc)
{
exc.printStackTrace();
String str = exc.getMessage();
PnlAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
}
}
@Override
public boolean init()
{
try
{
loadTransient();
}
catch (Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
if(str == null ||str.length()<1)
{
str = "";
str += PnlAbs.class.getName();
str += " : ";
str += "failed to load transient";
}
PnlAbs._LOGGER_.severe(str);
return false;
}
return true;
}
@Override
public void destroy()
{
return;
}
@Override
public void loadUnserializedObject() throws Exception
{
this.loadTransient();
for (int i = 0; i < super.getComponentCount(); i++)
{
Component cmpCur = super.getComponent(i);
if (cmpCur instanceof IGfrHandlerUnserializedObject)
{
IGfrHandlerUnserializedObject serCur = (IGfrHandlerUnserializedObject) cmpCur;
serCur.loadUnserializedObject();
}
}
}
@Override
public void releaseUnserializedObject() throws Exception
{
this.releaseTransient();
for (int i = 0; i < super.getComponentCount(); i++)
{
Component cmpCur = super.getComponent(i);
if (cmpCur instanceof IGfrHandlerUnserializedObject)
{
IGfrHandlerUnserializedObject serCur = (IGfrHandlerUnserializedObject) cmpCur;
serCur.releaseUnserializedObject();
}
}
}
}