/*
* 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.popupmenu;
import java.awt.Component;
import java.util.HashMap;
import java.util.logging.Logger;
import javax.swing.JPopupMenu;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.io.handler.IGfrHandlerUnserializedObject;
import org.geoforge.lang.handler.IGfrHandlerImmutableProperties;
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 GfrPmuAbs extends JPopupMenu implements
IGfrHandlerLifeCycleObject,
IGfrHandlerTransitoryObject,
IGfrHandlerUnserializedObject,
IGfrHandlerImmutableProperties
{
// ----
// begin: instantiate logger for this class
final static private Logger _LOGGER_ = Logger.getLogger(GfrPmuAbs.class.getName());
static
{
GfrPmuAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
private HashMap<String, String> _hmp_ = null;
/*
* A property could be assigned only one time
*/
@Override
public void setPropertyImmutable(String strKey, String strValue)
{
if (this._hmp_.containsKey(strKey))
{
throw new UnsupportedOperationException(
"Dev coding error, key already assigned");
}
this._hmp_.put(strKey, strValue);
}
@Override
public String getPropertyImmutable(String strKey)
{
return _hmp_.get(strKey);
}
@Override
abstract public void loadTransient() throws Exception;
@Override
abstract public void releaseTransient() throws Exception;
protected GfrPmuAbs()
{
super();
this._hmp_ = new HashMap<String, String>();
}
@Override
public boolean init()
{
try
{
loadTransient();
}
catch (Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
GfrPmuAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
return false;
}
return true;
}
@Override
public void destroy()
{
if (this._hmp_ != null)
{
this._hmp_.clear();
this._hmp_ = null;
}
}
@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();
}
}
}
}